在视口中缩放对象以填充屏幕

时间:2017-05-09 19:41:46

标签: c# .net autocad autocad-plugin

我有一个要求,我必须在视口中旋转一个对象(仅),然后缩放对象以填充整个屏幕大小。我使用以下方法在Autodesk Map 3d 2015中旋转和缩放对象

public void RotateZoomStakingGrid(Viewport vp, double mRotation, Point2d ptCenter, double aspectEnt,ObjectId Arg_oSelectedObjects,Transaction tr)
{
AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
Document myDoc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = myDoc.Editor;
Database db = HostApplicationServices.WorkingDatabase; 
vp.UpgradeOpen();
mRotation = -Math.PI * 2.0 - mRotation;
vp.TwistAngle += mRotation;
vp.On = true;
vp.ViewTarget = new Point3d(ptCenter.X, ptCenter.Y, 0);

double mScrRatio;
// width/height
mScrRatio = (vp.Width / vp.Height);

Point3d mMaxExt = db.Extmax;
Point3d mMinExt = db.Extmin;

Extents3d mExtents = new Extents3d();
mExtents.Set(mMinExt, mMaxExt);

// prepare Matrix for DCS to WCS transformation
Matrix3d matWCS2DCS;
matWCS2DCS = Matrix3d.PlaneToWorld(vp.ViewDirection);
matWCS2DCS = Matrix3d.Displacement(
vp.ViewTarget - Point3d.Origin)
* matWCS2DCS;
matWCS2DCS = Matrix3d.Rotation(
-vp.TwistAngle, vp.ViewDirection,
vp.ViewTarget) * matWCS2DCS;
matWCS2DCS = matWCS2DCS.Inverse();

// tranform the extents to the DCS
// defined by the viewdir
mExtents.TransformBy(matWCS2DCS);
Entity gridEnt = tr.GetObject(Arg_oSelectedObjects, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead) as Entity;
Extents3d entityExtent = gridEnt.GeometricExtents;
entityExtent.TransformBy(matWCS2DCS);
Point2d ptCenterTemp = new Point2d(
(entityExtent.MaxPoint.X + entityExtent.MinPoint.X) * 0.5,
(entityExtent.MaxPoint.Y + entityExtent.MinPoint.Y) * 0.5);

// width of the entity extents in current view 
double mWidth;
mWidth = (entityExtent.MaxPoint.X - entityExtent.MinPoint.X);

//height of the entity extents in current view
double mHeight;
mHeight = (entityExtent.MaxPoint.Y - entityExtent.MinPoint.Y);

//get the view center point
Point2d mCentPt = new Point2d(((entityExtent.MaxPoint.X + entityExtent.MinPoint.X) * 0.5), ((entityExtent.MaxPoint.Y + entityExtent.MinPoint.Y) * 0.5));

//check if the width 'fits' in current window,if not then get the new height as per the viewports aspect ratio
if (mWidth > (mHeight * mScrRatio)) mHeight = mWidth / mScrRatio; 


vp.ViewHeight = mHeight * 0.55; //set the ; height - adjusted by 0.7% 
vp.ViewCenter = mCentPt; //set the view center 

vp.DowngradeOpen();
vp.UpdateDisplay();
ed.SwitchToModelSpace(); 

} 

我担心的是上面的代码在我的系统上工作正常但是当我将DLL部署到其他系统时,对象没有完全缩放到适合屏幕。我玩过zoomfactor,但我猜它会改变屏幕分辨率。你能指出我哪里出错吗?

0 个答案:

没有答案