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);
             }
         }
     }
 }