ZoomToWindow doesn't scale?

ZoomToWindow doesn't scale?

463017170
Advocate Advocate
266 Views
1 Reply
Message 1 of 2

ZoomToWindow doesn't scale?

463017170
Advocate
Advocate
acedCommandS(RTSTR, _T("ZOOM"), RTSTR, _T("_W"), RTPOINT, asDblArray(ptMin), RTPOINT, asDblArray(ptMax), RTNONE);	


static void ZoomToWindow(const AcGePoint3d& ptMin, const AcGePoint3d& ptMax, double scale)
	{
		acdbUcs2Wcs(asDblArray(ptMin), asDblArray(ptMin), false);
		acdbUcs2Wcs(asDblArray(ptMax), asDblArray(ptMax), false);
		AcDbViewTableRecord view;
		view.setCenterPoint(AcGePoint2d((ptMax.x + ptMin.x) / 2, (ptMin.y + ptMax.y) / 2));
		view.setHeight(fabs(ptMin.y - ptMax.y) * scale);
		view.setWidth(fabs(ptMin.x - ptMax.y) * scale);
		AcGePoint3d origin(0, 0, 0);
		AcGeVector3d xAxis(1, 0, 0);
		AcGeVector3d yAxis(0, 1, 0);
		AcGeMatrix3d mat;
		acedGetCurrentUCS(mat);
		origin.transformBy(mat);
		xAxis.transformBy(mat);
		yAxis.transformBy(mat);
		view.setUcs(origin, xAxis, yAxis);
		Acad::ErrorStatus es = acedSetCurrentView(&view, NULL);
		acdbHostApplicationServices()->workingDatabase()->updateExt(TRUE);
	}

ZoomToWindow doesn't scale?
Can the function of acedDmmandS be implemented?

 

0 Likes
267 Views
1 Reply
Reply (1)
Message 2 of 2

1127204185
Advocate
Advocate
	static Acad::ErrorStatus ZoomToWindow(AcGePoint3d ptCorner1UCS, AcGePoint3d ptCorner2UCS, double zoomFactor)
	{
		Acad::ErrorStatus es = Acad::eInvalidInput;
		acdbUcs2Wcs(asDblArray(ptCorner1UCS), asDblArray(ptCorner1UCS), false);
		acdbUcs2Wcs(asDblArray(ptCorner2UCS), asDblArray(ptCorner2UCS), false);
		if (Acad::eOk != (es = acedVports2VportTableRecords())) return es;
		AcDbViewportTable* pVpT = NULL;
		AcDbViewportTableRecord* pActVp = NULL;
		if (Acad::eOk != (es = acdbHostApplicationServices()->workingDatabase()->getViewportTable(pVpT, AcDb::kForRead))) return es;
		es = pVpT->getAt(_T("*Active"), pActVp, AcDb::kForWrite);
		pVpT->close();
		if (Acad::eOk != es) { return es; }

		AcGeMatrix3d matWCS2DCS;
		matWCS2DCS.setToPlaneToWorld(pActVp->viewDirection());
		matWCS2DCS = AcGeMatrix3d::translation(pActVp->target() - AcGePoint3d::kOrigin) * matWCS2DCS;
		matWCS2DCS = AcGeMatrix3d::rotation(-pActVp->viewTwist(), pActVp->viewDirection(), pActVp->target()) * matWCS2DCS;
		matWCS2DCS = matWCS2DCS.inverse();

		ptCorner1UCS.transformBy(matWCS2DCS);
		ptCorner2UCS.transformBy(matWCS2DCS);
		AcGePoint3d ptCenter = ptCorner1UCS + (ptCorner2UCS - ptCorner1UCS) / 2.0;
		double newHeight = fabs(ptCorner2UCS.y - ptCorner1UCS.y) * zoomFactor;
		double newWidth = fabs(ptCorner2UCS.x - ptCorner1UCS.x) * zoomFactor;
		double screenRatio = pActVp->width() / pActVp->height();

		pActVp->setCenterPoint(AcGePoint2d(ptCenter.x, ptCenter.y));
		if (newHeight * screenRatio > newWidth)
		{
			pActVp->setHeight(newHeight);
			pActVp->setWidth(newHeight * screenRatio);
		}
		else
		{
			pActVp->setHeight(newWidth / screenRatio);
			pActVp->setWidth(newWidth);
		}

		pActVp->close();
		es = acedVportTableRecords2Vports();
		return es;
	}
0 Likes