| 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;
- namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi
- {
- public partial class OutDWG : ConditionPanel
- {
- private LayerWithDataListPanel LayerPanel;
- private string fileName = string.Empty;
- private string fileType = string.Empty;
- public bool isGeo = false;
- private GeoRegion geo = null;
- public OutDWG()
- {
- this.ConditionPanelName = "地图输出CAD文件";
- this.IsShowResultWindow = false;
- InitializeComponent();
- this.SetSize(500, 485);
- }
- protected override void OnLoad(EventArgs e)
- {
- LayerPanel = new LayerWithDataListPanel();
- LayerPanel.LoadToVector(true, true, true);
- uiGBlayer.Controls.Add(LayerPanel);
- foreach (string v in Enum.GetNames(typeof(CADVersion)))
- { uiRBGlx.Items.Add((object)v); }
- if (isGeo)
- {
- MapControl.Action = SuperMap.UI.Action.CreatePolygon;
- MapControl.Tracked += ComsStatic.MapControl_Tracked_TrackingName;
- }
- }
- 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 = "所有文件|*.*";
- sfd.RestoreDirectory = true;
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- fileName = sfd.FileName;
- uiTextBox1.Text = fileName;
- }
- }
- public override object Do(DockPanel dockPanel = null)
- {
- if (isGeo)
- {
- int index = MapControl.Map.TrackingLayer.IndexOf(ComsStatic.ControlToolsTrackingName);
- if (index == -1)
- {
- Sunny.UI.UIMessageTip.ShowError("请先绘制区域"); return false;
- }
- geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion;
- }
- 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; }
- UIWaitFormService.ShowWaitForm();
- ExportSettingDWG exSetting = new ExportSettingDWG();
- exSetting.TargetFileType = FileType.DWG;
- exSetting.TargetFilePath = fileName;
- exSetting.ExportingExternalData = true;
- exSetting.ExportingXRecord = true;
- 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 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
- string dviName = ComsStatic.DatasourceMemory.Datasets.GetAvailableDatasetName("OutDWG_dvName");
- DatasetVector dvFinal = ComsStatic.DatasourceMemory.Datasets.Create(new DatasetVectorInfo() { Name = dviName, Type = DatasetType.CAD });
- DatasetVector dv = null;
- if (isGeo)
- {
- foreach (Layer lyr in LayerPanel.SelectLayers.ToArray())
- {
- dv = lyr.Dataset as DatasetVector;
- //dvFinal.AppendFields(dv, "SmUserID", "smuserid", ComsStatic.GetFieldInfos(dv));
- dvFinal.Append(dv.Query(geo, 2, CursorType.Static));
- }
- }
- else
- {
- foreach (Layer lyr in LayerPanel.SelectLayers.ToArray())
- {
- dv = lyr.Dataset as DatasetVector;
- //dvFinal.AppendFields(dv, "SmUserID", "smuserid", ComsStatic.GetFieldInfos(dv));
- dvFinal.Append(dv.GetRecordset(false, CursorType.Static));
- }
- }
- exSetting.SourceData = dvFinal;
- DataExport ex = new DataExport();
- ex.ExportSettings.Add(exSetting);
- ExportResult exResult = ex.Run();
- UIWaitFormService.HideWaitForm();
- 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));
- return true;
- }
- private void uiRBGlx_ValueChanged(object sender, int index, string text)
- {
- fileType = text;
- }
- }
- }
|