Exemplo n.º 1
0
 public static void ZoomToExtents(this Database database)
 {
     using (DBObject dbObj = GetActiveViewportId(database).GetObject(OpenMode.ForWrite))
     {
         // using protocol extensions we handle PS and MS viewports in the same manner
         using (AbstractViewportData viewportData = new AbstractViewportData(dbObj))
         {
             using (Teigha.GraphicsSystem.View view = viewportData.GsView)
             {
                 // do actual zooming - change GS view
                 using (AbstractViewPE viewPE = new AbstractViewPE(view))
                 {
                     BoundBlock3d boundBlock = new BoundBlock3d();
                     bool         bBboxValid = viewPE.GetViewExtents(boundBlock);
                     // paper space overall view
                     if (dbObj is Viewport && ((Viewport)dbObj).Number == 1)
                     {
                         if (!bBboxValid || !(boundBlock.GetMinimumPoint().X < boundBlock.GetMaximumPoint().X&& boundBlock.GetMinimumPoint().Y < boundBlock.GetMaximumPoint().Y))
                         {
                             bBboxValid = GetLayoutExtents(database, view, ref boundBlock);
                         }
                     }
                     else if (!bBboxValid) // model space viewport
                     {
                         bBboxValid = GetLayoutExtents(database, view, ref boundBlock);
                     }
                     if (!bBboxValid)
                     {
                         // set to somewhat reasonable (e.g. paper size)
                         if (database.Measurement == MeasurementValue.Metric)
                         {
                             boundBlock.Set(Point3d.Origin, new Point3d(297.0, 210.0, 0.0)); // set to papersize ISO A4 (portrait)
                         }
                         else
                         {
                             boundBlock.Set(Point3d.Origin, new Point3d(11.0, 8.5, 0.0)); // ANSI A (8.50 x 11.00) (landscape)
                         }
                         boundBlock.TransformBy(view.ViewingMatrix);
                     }
                     viewPE.ZoomExtents(boundBlock);
                     boundBlock.Dispose();
                 }
                 // save changes to database
                 viewportData.SetView(view);
             }
         }
     }
 }
Exemplo n.º 2
0
        public static void Zoom(this Database database, Point3d minPoint, Point3d maxPoint)
        {
            BoundBlock3d box = new BoundBlock3d();

            box.Set(minPoint, maxPoint);
            Zoom(database, box);
        }
Exemplo n.º 3
0
        public static void Zoom(this Database database, Extents3d ext)
        {
            BoundBlock3d box = new BoundBlock3d();

            box.Set(ext.MinPoint, ext.MaxPoint);
            Zoom(database, box);
        }
Exemplo n.º 4
0
        public static BoundBlock3d PixelToWorld(this Database database, Rectangle srcRectangle)
        {
            Point        bl               = new Point(srcRectangle.Left, srcRectangle.Bottom);
            Point        tr               = new Point(srcRectangle.Right, srcRectangle.Top);
            var          bottomLeft       = PixelToWorld(database, bl);
            var          topRight         = PixelToWorld(database, tr);
            BoundBlock3d destBoundBlock3D = new BoundBlock3d();

            destBoundBlock3D.Set(bottomLeft, topRight);
            return(destBoundBlock3D);
        }
Exemplo n.º 5
0
        void zoom_extents(Teigha.GraphicsSystem.View pView, DBObject pVpObj)
        {
            // here protocol extension is used again, that provides some helpful functions
            using (AbstractViewPE pVpPE = new AbstractViewPE(pView))
            {
                BoundBlock3d bbox       = new BoundBlock3d();
                bool         bBboxValid = pVpPE.GetViewExtents(bbox);

                // paper space overall view
                if (pVpObj is Teigha.DatabaseServices.Viewport && ((Teigha.DatabaseServices.Viewport)pVpObj).Number == 1)
                {
                    if (!bBboxValid || !(bbox.GetMinimumPoint().X < bbox.GetMaximumPoint().X&& bbox.GetMinimumPoint().Y < bbox.GetMaximumPoint().Y))
                    {
                        bBboxValid = get_layout_extents(database, pView, ref bbox);
                    }
                }
                else if (!bBboxValid) // model space viewport
                {
                    bBboxValid = get_layout_extents(database, pView, ref bbox);
                }

                if (!bBboxValid)
                {
                    // set to somewhat reasonable (e.g. paper size)
                    if (database.Measurement == MeasurementValue.Metric)
                    {
                        bbox.Set(Point3d.Origin, new Point3d(297.0, 210.0, 0.0)); // set to papersize ISO A4 (portrait)
                    }
                    else
                    {
                        bbox.Set(Point3d.Origin, new Point3d(11.0, 8.5, 0.0)); // ANSI A (8.50 x 11.00) (landscape)
                    }
                    bbox.TransformBy(pView.ViewingMatrix);
                }

                pVpPE.ZoomExtents(bbox);
            }
        }
Exemplo n.º 6
0
        public static bool GetLayoutExtents(Database db, Teigha.GraphicsSystem.View pView, ref BoundBlock3d bbox)
        {
            Extents3d ext = new Extents3d();

            using (BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead))
            {
                using (BlockTableRecord pSpace = (BlockTableRecord)bt[BlockTableRecord.PaperSpace].GetObject(OpenMode.ForRead))
                {
                    using (Layout pLayout = (Layout)pSpace.LayoutId.GetObject(OpenMode.ForRead))
                    {
                        if (pLayout.GetViewports().Count > 0)
                        {
                            bool bOverall = true;
                            foreach (ObjectId id in pLayout.GetViewports())
                            {
                                if (bOverall)
                                {
                                    bOverall = false;
                                    continue;
                                }
                                //Viewport pVp = (Viewport)id.GetObject(OpenMode.ForRead);
                            }
                            ext.TransformBy(pView.ViewingMatrix);
                            bbox.Set(ext.MinPoint, ext.MaxPoint);
                        }
                        else
                        {
                            ext = pLayout.Extents;
                        }
                        bbox.Set(ext.MinPoint, ext.MaxPoint);
                    }
                }
            }

            return(ext.MinPoint != ext.MaxPoint);
        }
Exemplo n.º 7
0
        public static BoundBlock3d GetLayoutExtents(this LayoutHelperDevice helperDevice)
        {
            BoundBlock3d boundBlock3D = new BoundBlock3d();

            using (View pView = helperDevice.ActiveView)
            {
                // camera position in world coordinates
                Point3d pos        = pView.Position;
                double  halfWidth  = pView.FieldWidth / 2;
                double  halfHeight = pView.FieldHeight / 2;
                double  xMin       = pos.X - halfWidth;
                double  xMax       = pos.X + halfWidth;
                double  yMin       = pos.Y - halfHeight;
                double  yMax       = pos.Y + halfHeight;
                boundBlock3D.Set(new Point3d(xMin, yMin, 0), new Point3d(xMax, yMax, 0));
            }
            return(boundBlock3D);
        }