Beispiel #1
0
 public override void OnClick()
 {
     try
     {
         IGeometry geometry = null;
         if (this._context.FocusMap.SelectionCount >= 1)
         {
             IEnumFeature enumFeature = this._context.FocusMap.FeatureSelection as IEnumFeature;
             enumFeature.Reset();
             IFeature             feature             = enumFeature.Next();
             ITopologicalOperator topologicalOperator = null;
             while (feature != null)
             {
                 if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                 {
                     if (topologicalOperator == null)
                     {
                         topologicalOperator = (feature.ShapeCopy as ITopologicalOperator);
                     }
                     else
                     {
                         topologicalOperator = (topologicalOperator.Union(feature.Shape) as ITopologicalOperator);
                         topologicalOperator.Simplify();
                     }
                 }
                 feature = enumFeature.Next();
             }
             geometry = (topologicalOperator as IGeometry);
         }
         else
         {
             ITopologicalOperator topologicalOperator = null;
             IGraphicsContainer   graphicsContainer   = this._context.FocusMap as IGraphicsContainer;
             graphicsContainer.Reset();
             IElement element = graphicsContainer.Next();
             if (element != null)
             {
                 if (element is IPolygonElement)
                 {
                     if (topologicalOperator == null)
                     {
                         topologicalOperator = (element.Geometry as ITopologicalOperator);
                     }
                     else
                     {
                         topologicalOperator =
                             (topologicalOperator.Union(element.Geometry) as ITopologicalOperator);
                         topologicalOperator.Simplify();
                     }
                 }
                 element = graphicsContainer.Next();
             }
             geometry = (topologicalOperator as IGeometry);
         }
         if (geometry == null && this._context.Hook is IApplication)
         {
             geometry = (this._context.Hook as IApplication).BufferGeometry;
         }
         if (geometry != null && !geometry.IsEmpty)
         {
             geometry.SpatialReference = this._context.FocusMap.SpatialReference;
             int num = this._subType;
             if (num != 0)
             {
                 string str  = System.IO.Path.GetTempPath() + "TempPersonGDB";
                 int    num2 = 1;
                 string path = str + ".mdb";
                 while (File.Exists(path))
                 {
                     try
                     {
                         File.Delete(path);
                         break;
                     }
                     catch
                     {
                     }
                     num2++;
                     path = str + " (" + num2.ToString() + ").mdb";
                 }
                 IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory();
                 IWorkspaceName    iworkspaceName_  = workspaceFactory.Create(System.IO.Path.GetDirectoryName(path),
                                                                              System.IO.Path.GetFileNameWithoutExtension(path), null, 0);
                 IMap imap_ = new Map();
                 Clip.ClipMapByRegion(iworkspaceName_, this._context.FocusMap, geometry, imap_);
                 new FormPrinterSetup();
                 CMapPrinter cMapPrinter;
                 if (this._context.Hook is IApplication)
                 {
                     cMapPrinter = new CMapPrinter(imap_, ApplicationBase.StyleGallery);
                 }
                 else
                 {
                     cMapPrinter = new CMapPrinter(imap_);
                 }
                 cMapPrinter.showPrintUI("打印地图");
             }
             else
             {
                 new frmDir
                 {
                     FocusMap     = this._context.FocusMap,
                     ClipGeometry = geometry
                 }.ShowDialog();
             }
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message);
     }
 }