123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WWPipeLine.MapBasic.Conditions;
- using Sunny.UI;
- using WeifenLuo.WinFormsUI.Docking;
- using SuperMap.Mapping;
- using WWPipeLine.MapBasic;
- using SuperMap.Data.Conversion;
- using SuperMap.Data;
- using static SuperMap.Data.StandardMargin;
- namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi
- {
- public partial class OutDWGcj : ConditionPanel
- {
- private LayerWithDataListPanel LayerPanel;
- private string fileName = string.Empty;
- private string fileType = string.Empty;
- private string dviName = string.Empty;
- private GeoRegion m_geo = null;
- public OutDWGcj()
- {
- this.ConditionPanelName = "裁剪地图输出CAD文件";
- InitializeComponent();
- }
- protected override void OnLoad(EventArgs e)
- {
- LayerPanel = new LayerWithDataListPanel();
- LayerPanel.LoadToVector(true);
- uiGBlayer.Controls.Add(LayerPanel);
- foreach (string v in Enum.GetNames(typeof(CADVersion)))
- { uiRBGlx.Items.Add((object)v); }
- }
- private void uiButton1_Click(object sender, EventArgs e)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
- sfd.Title = "请选择要保存的文件路径";
- sfd.Filter = "所有文件|*.*";
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- fileName = sfd.FileName;
- uiTextBox1.Text = fileName;
- }
- }
- public override object Do(DockPanel dockPanel = null)
- {
- this.IsShowResultWindow = false;
- if (string.IsNullOrEmpty(fileName))
- { UIMessageTip.ShowError("请选择要保存文件的路径"); return false; }
- if (string.IsNullOrEmpty(fileType))
- { UIMessageTip.ShowError("请选择要保存文件的格式"); return false; }
- if (LayerPanel.SelectLayers.Count == 0)
- { UIMessageTip.ShowError("请选择要保存文件的图层"); return false; }
- if (m_geo is null)
- { Sunny.UI.UIMessageTip.ShowError("请绘制导出CAD的区域"); return false; }
- ExportSettingDWG exSetting = new ExportSettingDWG();
- exSetting.TargetFileType = FileType.DWG;
- exSetting.TargetFilePath = fileName;
- exSetting.ExportingXRecord = true;//是否将用户自定义的字段以及属性字段作为扩展记录导出
- exSetting.ExportPolylineWidth = true;//brief 多段线线宽
- exSetting.ExportingBorder = true;//导出cad面对象或矩形对象时是否导出边界
- exSetting.IsOverwrite = true;//导出目录中存在同名文件时,是否强制覆盖
- switch (fileType)
- {
- case "CAD12": exSetting.Version = CADVersion.CAD12; break;
- case "CAD13": exSetting.Version = CADVersion.CAD13; break;
- case "CAD14": exSetting.Version = CADVersion.CAD14; break;
- case "CAD2000": exSetting.Version = CADVersion.CAD2000; break;
- case "CAD2004": exSetting.Version = CADVersion.CAD2004; break;
- case "CAD2007": exSetting.Version = CADVersion.CAD2007; break;
- default: exSetting.Version = CADVersion.CAD12; break;
- }
- #region 设置ExportSettingDWG SourceData
- // 设置矢量数据集的信息
- dviName = ComsStatic.Datasource.Datasets.GetAvailableDatasetName("OutDWG_dvName");
- DatasetVectorInfo datasetVectorInfo = new DatasetVectorInfo() { Name = dviName, Type = DatasetType.CAD };
- // 创建矢量数据集
- DatasetVector dvFinal = ComsStatic.Datasource.Datasets.Create(datasetVectorInfo);
- DatasetVector dv = null;
- foreach (Layer lyr in LayerPanel.SelectLayers.ToArray())
- {
- dv = lyr.Dataset as DatasetVector;
- dvFinal.Append(dv.Query(m_geo, 2, CursorType.Static));
- }
- exSetting.SourceData = dvFinal;
- #endregion
- #region 设置ExportSettingDWG StyleMappingTableFile
- //string sttPath = Commons.Paths.ApplicationConfigDir + "\\StyleMappingTableFile\\OutDWGStyleFile.stt";
- //if (System.IO.File.Exists(sttPath))
- // exSetting.StyleMappingTableFile = sttPath;
- #endregion
- #region 构造标注图幅
- //// 构造标准图幅图框对象,设置标准图幅图框基本属性,使所有图幅元素均可见
- //StandardMargin standardMargin = new StandardMargin();
- //standardMargin.ShowAllElements();//使所有的标准图幅元素可见。
- //standardMargin.Annotation = new String[] { "此为自定义图幅" };//图幅附注文本数组。
- //standardMargin.Information = new String[] { "图示", "坐标系" };//图幅信息,通常放置在图幅的右下角,包括图式,坐标系,高程基准,航摄,出版等信息。
- //standardMargin.KilometerGridType = MarginKilometerGridType.Cross;//公里网网格类型。
- //standardMargin.LargeScaleCoordSysType = MarginLargeScaleCoordSysType.National;//大比例尺图幅的坐标系类型。
- //standardMargin.LargeScaleSheetType = MarginLargeScaleSheetType.Sheet40x50;//大比例尺(1:500 - 1:2000)图幅分幅类型。
- //// 得到标准图幅图框的偏移设置并对其属性进行设置
- //MarginOffset marginOffset = standardMargin.Offset;//所有的偏移量都是向右上角偏移的量,如果要向左下角偏移则要设置负数。 所有的偏移量都是相对于默认位置的偏移,默认位置为(0,0)。
- //marginOffset.Annotation = new Size2D(0, -5);//附注距离图幅默认位置的偏移。
- //marginOffset.BasicScale = new Size2D(0, -15);//基本比例尺字样距离图幅默认位置的偏移。
- //marginOffset.BottomLeftSheetName = new Size2D(0, -30);//左下角图幅名距离图幅默认位置的偏移。
- //marginOffset.BottomRightSheetName = new Size2D(90, -30);//右下角地图名距离图幅默认位置的偏移。
- //marginOffset.Information = new Size2D(8, 0);//地图信息注记距离图幅默认位置的偏移。
- //marginOffset.Publisher = new Size2D(0, -5);//出版单位文字距离图幅默认位置的偏移。
- //// 得到标准图幅图框的文本样式并对其进行设置
- //MarginStyle marginStyle = standardMargin.Style;
- //TextStyle textStyle = new TextStyle() { FontName = "黑体", FontHeight = 5, FontWidth = 2, ForeColor = Color.White };
- //// 此处的参数可以为不同的 TextStyle 对象
- //marginStyle.Annotation = textStyle;//附注文本风格。
- //marginStyle.BasicScale = textStyle;//基本比例尺字样风格。
- //marginStyle.CornerMapName = textStyle;//四周图副名风格。
- //marginStyle.CornerSheetName = textStyle;//四角图幅号风格。
- //// 创建标准图幅图框,并将标准图幅图框以CAD数据集的形式保存到指定的数据源中
- //DatasetVector marginCAD = CreateStandardMarginDataset(ComsStatic.Datasource, ComsStatic.Datasource.Datasets.GetAvailableDatasetName("marginExample"), standardMargin);
- //exSetting.SourceData = marginCAD;
- #endregion
- DataExport ex = new DataExport();
- ex.ExportSettings.Add(exSetting);
- ExportResult exResult = ex.Run();
- if (ex.ExportSettings.Count == exResult.SucceedSettings.Length)
- ComsStatic.ShowOKLog(string.Format("地图导出dwg格式,应导出{0}条,共导出{1}条", ex.ExportSettings.Count, exResult.SucceedSettings.Length));
- else
- ComsStatic.ShowErrorLog(string.Format("地图导出dwg格式,应导出{0}条,失败导出{1}条", ex.ExportSettings.Count, exResult.FailedSettings.Length));
- if (ComsStatic.Datasource.Datasets.Contains(dviName))
- ComsStatic.Datasource.Datasets.Delete(dviName);
- return true;
- }
- public override void AfterClose()
- {
- MapControl.Tracked -= MapControl_Tracked;
- base.AfterClose();
- }
- private void uiRBGlx_ValueChanged(object sender, int index, string text)
- {
- fileType = text;
- }
- private void uiButton3_Click(object sender, EventArgs e)
- {
- MapControl.Action = SuperMap.UI.Action.Pan;
- MapControl.Map.TrackingLayer.Clear();
- MapControl.Map.RefreshEx(MapControl.Map.ViewBounds);
- }
- private void uiButton2_Click(object sender, EventArgs e)
- {
- MapControl.Action = SuperMap.UI.Action.CreatePolygon;
- MapControl.Tracked += MapControl_Tracked;
- }
- private void MapControl_Tracked(object sender, SuperMap.UI.TrackedEventArgs e)
- {
- if (e.Geometry is null) return;
- m_geo = e.Geometry.Clone() as GeoRegion;
- if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("区域绘制失败"); return; }
- m_geo.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
- MapControl.Map.TrackingLayer.Clear();
- MapControl.Map.TrackingLayer.Add(m_geo, "GeoRectangle");
- MapControl.Map.Refresh();
- }
- }
- }
|