|
使用 ObjectARX 缩放、平移和环绕当前 AutoCAD 视图
我们的学院 Kean 制作了一个关于在 .NET 中缩放、平移和环绕当前视图的博客。我正在ObjectARX中编写代码。缩放、平移、轨道化的基本工作流程类似:
1.获取他当前的视图记录
2.调整其参数。例如
缩放:使用系数调整高度和宽度
平移:调整视图中心
轨道:沿轴调整视图方向。
3. 使用更新的视图记录更新当前视图。
[code]static void panView()
{
AcDbDatabase *pDb =
acdbHostApplicationServices()->workingDatabase();
acedVports2VportTableRecords();
//get the active viewport object
AcDbViewportTable *pVpT = NULL;
AcDbViewportTableRecord *pActVp = NULL;
//get the *Active view port
pDb->getViewportTable(pVpT,AcDb::kForRead);
pVpT->getAt(_T("*Active"),pActVp,AcDb::kForWrite);
pVpT->close();
//get the view center point
//assume we need to pan the view along X & Y in 10
double panStep = 10;
AcGePoint2d mCentPt = pActVp->centerPoint();
mCentPt.x += panStep;
mCentPt.y += panStep;
//set the view center
pActVp->setCenterPoint(mCentPt);
//close the Active viewport
pActVp->close();
//update the viewport
acedVportTableRecords2Vports();
}
static void zoomView()
{
AcDbDatabase *pDb =
acdbHostApplicationServices()->workingDatabase();
acedVports2VportTableRecords();
//get the active viewport object
AcDbViewportTable *pVpT = NULL;
AcDbViewportTableRecord *pActVp = NULL;
//get the *Active view port
pDb->getViewportTable(pVpT,AcDb::kForRead);
pVpT->getAt(_T("*Active"),pActVp,AcDb::kForWrite);
pVpT->close();
//assume we need to zoom the view out in scaling 10
double zoomFactor = 10;
pActVp->setHeight(pActVp->height() * zoomFactor);
pActVp->setWidth(pActVp->width() * zoomFactor);
//close the Active viewport
pActVp->close();
//update the viewport
acedVportTableRecords2Vports();
}
static void orbitView()
{
AcDbDatabase *pDb =
acdbHostApplicationServices()->workingDatabase();
acedVports2VportTableRecords();
//get the active viewport object
AcDbViewportTable *pVpT = NULL;
AcDbViewportTableRecord *pActVp = NULL;
//get the *Active view port
pDb->getViewportTable(pVpT,AcDb::kForRead);
pVpT->getAt(_T("*Active"),pActVp,AcDb::kForWrite);
pVpT->close();
//assume we need to orbit the view direction
// along (1,0,0) in angle 30 degree.
AcGeVector3d oOldDir = pActVp->viewDirection();
AcGeMatrix3d oM;
oM.setToRotation(30 * 3.1415926 / 180,AcGeVector3d(1,0,0),AcGePoint3d::kOrigin);
oOldDir.transformBy(oM);
pActVp->setViewDirection(oOldDir);
//close the Active viewport
pActVp->close();
//update the viewport
acedVportTableRecords2Vports();
}[/code] |
|