Exemple #1
0
        // Helper functions to zoom using different techniques


        // Zoom using a view object


        private static void ZoomWin(

            _AcEd.Editor ed, _AcGe.Point3d min, _AcGe.Point3d max

            )
        {
            _AcGe.Point2d min2d = new _AcGe.Point2d(min.X, min.Y);

            _AcGe.Point2d max2d = new _AcGe.Point2d(max.X, max.Y);


            _AcDb.ViewTableRecord view =

                new _AcDb.ViewTableRecord();


            view.CenterPoint =

                min2d + ((max2d - min2d) / 2.0);

            view.Height = max2d.Y - min2d.Y;

            view.Width = max2d.X - min2d.X;

            ed.SetCurrentView(view);
        }
Exemple #2
0
        public static void Zoom(AcGe.Point3d pMin, AcGe.Point3d pMax, AcGe.Point3d pCenter, double dFactor)
        {
            int nCurVport = System.Convert.ToInt32(AcApp.GetSystemVariable("CVPORT"));

            if (db.TileMode == true)
            {
                if (pMin.Equals(new AcGe.Point3d()) == true &&
                    pMax.Equals(new AcGe.Point3d()) == true)
                {
                    pMin = db.Extmin;
                    pMax = db.Extmax;
                }
            }
            else
            {
                // Check to see if Paper space is current
                if (nCurVport == 1)
                {
                    // Get the extents of Paper space
                    if (pMin.Equals(new AcGe.Point3d()) == true &&
                        pMax.Equals(new AcGe.Point3d()) == true)
                    {
                        pMin = db.Pextmin;
                        pMax = db.Pextmax;
                    }
                }
                else
                {
                    // Get the extents of Model space
                    if (pMin.Equals(new AcGe.Point3d()) == true &&
                        pMax.Equals(new AcGe.Point3d()) == true)
                    {
                        pMin = db.Extmin;
                        pMax = db.Extmax;
                    }
                }
            }

            using (AcDb.Transaction acTrans = db.TransactionManager.StartTransaction())
            {
                using (AcDb.ViewTableRecord acView = ed.GetCurrentView())
                {
                    AcDb.Extents3d eExtents;

                    AcGe.Matrix3d matWCS2DCS;
                    matWCS2DCS = AcGe.Matrix3d.PlaneToWorld(acView.ViewDirection);
                    matWCS2DCS = AcGe.Matrix3d.Displacement(acView.Target - AcGe.Point3d.Origin) * matWCS2DCS;
                    matWCS2DCS = AcGe.Matrix3d.Rotation(-acView.ViewTwist,
                                                        acView.ViewDirection,
                                                        acView.Target) * matWCS2DCS;

                    if (pCenter.DistanceTo(AcGe.Point3d.Origin) != 0)
                    {
                        pMin = new AcGe.Point3d(pCenter.X - (acView.Width / 2),
                                                pCenter.Y - (acView.Height / 2), 0);

                        pMax = new AcGe.Point3d((acView.Width / 2) + pCenter.X,
                                                (acView.Height / 2) + pCenter.Y, 0);
                    }

                    using (AcDb.Line acLine = new AcDb.Line(pMin, pMax))
                    {
                        eExtents = new AcDb.Extents3d(acLine.Bounds.Value.MinPoint,
                                                      acLine.Bounds.Value.MaxPoint);
                    }

                    double dViewRatio;
                    dViewRatio = (acView.Width / acView.Height);

                    matWCS2DCS = matWCS2DCS.Inverse();
                    eExtents.TransformBy(matWCS2DCS);

                    double       dWidth;
                    double       dHeight;
                    AcGe.Point2d pNewCentPt;

                    if (pCenter.DistanceTo(AcGe.Point3d.Origin) != 0)
                    {
                        dWidth  = acView.Width;
                        dHeight = acView.Height;

                        if (dFactor == 0)
                        {
                            pCenter = pCenter.TransformBy(matWCS2DCS);
                        }

                        pNewCentPt = new AcGe.Point2d(pCenter.X, pCenter.Y);
                    }
                    else
                    {
                        dWidth  = eExtents.MaxPoint.X - eExtents.MinPoint.X;
                        dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y;

                        pNewCentPt = new AcGe.Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5),
                                                      ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5));
                    }

                    if (dWidth > (dHeight * dViewRatio))
                    {
                        dHeight = dWidth / dViewRatio;
                    }

                    if (dFactor != 0)
                    {
                        acView.Height = dHeight * dFactor;
                        acView.Width  = dWidth * dFactor;
                    }
                    acView.CenterPoint = pNewCentPt;
                    ed.SetCurrentView(acView);
                }
                acTrans.Commit();
            }
        }