Ejemplo n.º 1
0
        private void zoomDb(Autodesk.AutoCAD.DatabaseServices.Database db, Extents3d ext)
        {
            using (var switcher = new AcadLib.WorkingDatabaseSwitcher(db))
            {
                //db.UpdateExt(true);
                using (ViewportTable vTab = db.ViewportTableId.GetObject(OpenMode.ForRead) as ViewportTable)
                {
                    ObjectId acVptId = vTab["*Active"];
                    using (ViewportTableRecord vpTabRec = acVptId.GetObject(OpenMode.ForWrite) as ViewportTableRecord)
                    {
                        double scrRatio = (vpTabRec.Width / vpTabRec.Height);
                        //Matrix3d matWCS2DCS = Matrix3d.PlaneToWorld(vpTabRec.ViewDirection);
                        //matWCS2DCS = Matrix3d.Displacement(vpTabRec.Target - Point3d.Origin) * matWCS2DCS;
                        //matWCS2DCS = Matrix3d.Rotation(-vpTabRec.ViewTwist,
                        //                                vpTabRec.ViewDirection,
                        //                                vpTabRec.Target)
                        //                                * matWCS2DCS;
                        //matWCS2DCS = matWCS2DCS.Inverse();
                        //Extents3d extents = new Extents3d(db.Extmin, db.Extmax);
                        //extents.TransformBy(matWCS2DCS);
                        //double width = (extents.MaxPoint.X - extents.MinPoint.X);
                        //double height = (extents.MaxPoint.Y - extents.MinPoint.Y);
                        //Point2d center = new Point2d((extents.MaxPoint.X + extents.MinPoint.X) * 0.5,
                        //                             (extents.MaxPoint.Y + extents.MinPoint.Y) * 0.5);

                        double width  = (ext.MaxPoint.X - ext.MinPoint.X);
                        double height = (ext.MaxPoint.Y - ext.MinPoint.Y);
                        if (width > (height * scrRatio))
                        {
                            height = width / scrRatio;
                        }
                        vpTabRec.Height      = ext.MaxPoint.Y - ext.MinPoint.Y;
                        vpTabRec.Width       = height * scrRatio;
                        vpTabRec.CenterPoint = ext.Center().Convert2d();
                    }
                }
            }
        }