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