OutDWGcj.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using WWPipeLine.MapBasic.Conditions;
  11. using Sunny.UI;
  12. using WeifenLuo.WinFormsUI.Docking;
  13. using SuperMap.Mapping;
  14. using WWPipeLine.MapBasic;
  15. using SuperMap.Data.Conversion;
  16. using SuperMap.Data;
  17. using static SuperMap.Data.StandardMargin;
  18. namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi
  19. {
  20. public partial class OutDWGcj : ConditionPanel
  21. {
  22. private LayerWithDataListPanel LayerPanel;
  23. private string fileName = string.Empty;
  24. private string fileType = string.Empty;
  25. private string dviName = string.Empty;
  26. private GeoRegion m_geo = null;
  27. public OutDWGcj()
  28. {
  29. this.ConditionPanelName = "裁剪地图输出CAD文件";
  30. InitializeComponent();
  31. }
  32. protected override void OnLoad(EventArgs e)
  33. {
  34. LayerPanel = new LayerWithDataListPanel();
  35. LayerPanel.LoadToVector(true);
  36. uiGBlayer.Controls.Add(LayerPanel);
  37. foreach (string v in Enum.GetNames(typeof(CADVersion)))
  38. { uiRBGlx.Items.Add((object)v); }
  39. }
  40. private void uiButton1_Click(object sender, EventArgs e)
  41. {
  42. SaveFileDialog sfd = new SaveFileDialog();
  43. sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
  44. sfd.Title = "请选择要保存的文件路径";
  45. sfd.Filter = "所有文件|*.*";
  46. if (sfd.ShowDialog() == DialogResult.OK)
  47. {
  48. fileName = sfd.FileName;
  49. uiTextBox1.Text = fileName;
  50. }
  51. }
  52. public override object Do(DockPanel dockPanel = null)
  53. {
  54. this.IsShowResultWindow = false;
  55. if (string.IsNullOrEmpty(fileName))
  56. { UIMessageTip.ShowError("请选择要保存文件的路径"); return false; }
  57. if (string.IsNullOrEmpty(fileType))
  58. { UIMessageTip.ShowError("请选择要保存文件的格式"); return false; }
  59. if (LayerPanel.SelectLayers.Count == 0)
  60. { UIMessageTip.ShowError("请选择要保存文件的图层"); return false; }
  61. if (m_geo is null)
  62. { Sunny.UI.UIMessageTip.ShowError("请绘制导出CAD的区域"); return false; }
  63. ExportSettingDWG exSetting = new ExportSettingDWG();
  64. exSetting.TargetFileType = FileType.DWG;
  65. exSetting.TargetFilePath = fileName;
  66. exSetting.ExportingXRecord = true;//是否将用户自定义的字段以及属性字段作为扩展记录导出
  67. exSetting.ExportPolylineWidth = true;//brief 多段线线宽
  68. exSetting.ExportingBorder = true;//导出cad面对象或矩形对象时是否导出边界
  69. exSetting.IsOverwrite = true;//导出目录中存在同名文件时,是否强制覆盖
  70. switch (fileType)
  71. {
  72. case "CAD12": exSetting.Version = CADVersion.CAD12; break;
  73. case "CAD13": exSetting.Version = CADVersion.CAD13; break;
  74. case "CAD14": exSetting.Version = CADVersion.CAD14; break;
  75. case "CAD2000": exSetting.Version = CADVersion.CAD2000; break;
  76. case "CAD2004": exSetting.Version = CADVersion.CAD2004; break;
  77. case "CAD2007": exSetting.Version = CADVersion.CAD2007; break;
  78. default: exSetting.Version = CADVersion.CAD12; break;
  79. }
  80. #region 设置ExportSettingDWG SourceData
  81. // 设置矢量数据集的信息
  82. dviName = ComsStatic.Datasource.Datasets.GetAvailableDatasetName("OutDWG_dvName");
  83. DatasetVectorInfo datasetVectorInfo = new DatasetVectorInfo() { Name = dviName, Type = DatasetType.CAD };
  84. // 创建矢量数据集
  85. DatasetVector dvFinal = ComsStatic.Datasource.Datasets.Create(datasetVectorInfo);
  86. DatasetVector dv = null;
  87. foreach (Layer lyr in LayerPanel.SelectLayers.ToArray())
  88. {
  89. dv = lyr.Dataset as DatasetVector;
  90. dvFinal.Append(dv.Query(m_geo, 2, CursorType.Static));
  91. }
  92. exSetting.SourceData = dvFinal;
  93. #endregion
  94. #region 设置ExportSettingDWG StyleMappingTableFile
  95. //string sttPath = Commons.Paths.ApplicationConfigDir + "\\StyleMappingTableFile\\OutDWGStyleFile.stt";
  96. //if (System.IO.File.Exists(sttPath))
  97. // exSetting.StyleMappingTableFile = sttPath;
  98. #endregion
  99. #region 构造标注图幅
  100. //// 构造标准图幅图框对象,设置标准图幅图框基本属性,使所有图幅元素均可见
  101. //StandardMargin standardMargin = new StandardMargin();
  102. //standardMargin.ShowAllElements();//使所有的标准图幅元素可见。
  103. //standardMargin.Annotation = new String[] { "此为自定义图幅" };//图幅附注文本数组。
  104. //standardMargin.Information = new String[] { "图示", "坐标系" };//图幅信息,通常放置在图幅的右下角,包括图式,坐标系,高程基准,航摄,出版等信息。
  105. //standardMargin.KilometerGridType = MarginKilometerGridType.Cross;//公里网网格类型。
  106. //standardMargin.LargeScaleCoordSysType = MarginLargeScaleCoordSysType.National;//大比例尺图幅的坐标系类型。
  107. //standardMargin.LargeScaleSheetType = MarginLargeScaleSheetType.Sheet40x50;//大比例尺(1:500 - 1:2000)图幅分幅类型。
  108. //// 得到标准图幅图框的偏移设置并对其属性进行设置
  109. //MarginOffset marginOffset = standardMargin.Offset;//所有的偏移量都是向右上角偏移的量,如果要向左下角偏移则要设置负数。 所有的偏移量都是相对于默认位置的偏移,默认位置为(0,0)。
  110. //marginOffset.Annotation = new Size2D(0, -5);//附注距离图幅默认位置的偏移。
  111. //marginOffset.BasicScale = new Size2D(0, -15);//基本比例尺字样距离图幅默认位置的偏移。
  112. //marginOffset.BottomLeftSheetName = new Size2D(0, -30);//左下角图幅名距离图幅默认位置的偏移。
  113. //marginOffset.BottomRightSheetName = new Size2D(90, -30);//右下角地图名距离图幅默认位置的偏移。
  114. //marginOffset.Information = new Size2D(8, 0);//地图信息注记距离图幅默认位置的偏移。
  115. //marginOffset.Publisher = new Size2D(0, -5);//出版单位文字距离图幅默认位置的偏移。
  116. //// 得到标准图幅图框的文本样式并对其进行设置
  117. //MarginStyle marginStyle = standardMargin.Style;
  118. //TextStyle textStyle = new TextStyle() { FontName = "黑体", FontHeight = 5, FontWidth = 2, ForeColor = Color.White };
  119. //// 此处的参数可以为不同的 TextStyle 对象
  120. //marginStyle.Annotation = textStyle;//附注文本风格。
  121. //marginStyle.BasicScale = textStyle;//基本比例尺字样风格。
  122. //marginStyle.CornerMapName = textStyle;//四周图副名风格。
  123. //marginStyle.CornerSheetName = textStyle;//四角图幅号风格。
  124. //// 创建标准图幅图框,并将标准图幅图框以CAD数据集的形式保存到指定的数据源中
  125. //DatasetVector marginCAD = CreateStandardMarginDataset(ComsStatic.Datasource, ComsStatic.Datasource.Datasets.GetAvailableDatasetName("marginExample"), standardMargin);
  126. //exSetting.SourceData = marginCAD;
  127. #endregion
  128. DataExport ex = new DataExport();
  129. ex.ExportSettings.Add(exSetting);
  130. ExportResult exResult = ex.Run();
  131. if (ex.ExportSettings.Count == exResult.SucceedSettings.Length)
  132. ComsStatic.ShowOKLog(string.Format("地图导出dwg格式,应导出{0}条,共导出{1}条", ex.ExportSettings.Count, exResult.SucceedSettings.Length));
  133. else
  134. ComsStatic.ShowErrorLog(string.Format("地图导出dwg格式,应导出{0}条,失败导出{1}条", ex.ExportSettings.Count, exResult.FailedSettings.Length));
  135. if (ComsStatic.Datasource.Datasets.Contains(dviName))
  136. ComsStatic.Datasource.Datasets.Delete(dviName);
  137. return true;
  138. }
  139. public override void AfterClose()
  140. {
  141. MapControl.Tracked -= MapControl_Tracked;
  142. base.AfterClose();
  143. }
  144. private void uiRBGlx_ValueChanged(object sender, int index, string text)
  145. {
  146. fileType = text;
  147. }
  148. private void uiButton3_Click(object sender, EventArgs e)
  149. {
  150. MapControl.Action = SuperMap.UI.Action.Pan;
  151. MapControl.Map.TrackingLayer.Clear();
  152. MapControl.Map.RefreshEx(MapControl.Map.ViewBounds);
  153. }
  154. private void uiButton2_Click(object sender, EventArgs e)
  155. {
  156. MapControl.Action = SuperMap.UI.Action.CreatePolygon;
  157. MapControl.Tracked += MapControl_Tracked;
  158. }
  159. private void MapControl_Tracked(object sender, SuperMap.UI.TrackedEventArgs e)
  160. {
  161. if (e.Geometry is null) return;
  162. m_geo = e.Geometry.Clone() as GeoRegion;
  163. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("区域绘制失败"); return; }
  164. m_geo.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  165. MapControl.Map.TrackingLayer.Clear();
  166. MapControl.Map.TrackingLayer.Add(m_geo, "GeoRectangle");
  167. MapControl.Map.Refresh();
  168. }
  169. }
  170. }