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 SuperMap.UI; using SuperMap.Layout; namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi { public partial class OutPrintcj : ConditionPanel { private MapLayoutControl m_MapLayoutControl; private MapLayout m_MapLayout; private Point2D addPoint = new Point2D(0, 0); private Map m_Map; /// /// 纸张大小 /// private PaperSize paperSize = PaperSize.A4; /// /// 纸张方向 Landscape横向 Portrait纵向 /// private PaperOrientation paperOrientation = PaperOrientation.Landscape; public OutPrintcj() { this.ConditionPanelName = "裁剪区域打印"; this.IsShowPanelFooter = false; this.SetSize(Screen.PrimaryScreen.Bounds.Width - 300, Screen.PrimaryScreen.Bounds.Height - 200); InitializeComponent(); m_Map = MapControl.Map; foreach (Layer lyr in m_Map.Layers) { Layer PrintLayer = MapControl.Map.Layers.FindLayer(lyr.Name); if (PrintLayer is null) continue; lyr.IsVisible = PrintLayer.IsVisible; } m_Map.Workspace.Maps.SetMapXML(m_Map.Name, m_Map.ToXML()); m_MapLayoutControl = new MapLayoutControl(); m_MapLayoutControl.Dock = DockStyle.Fill; m_MapLayoutControl.MapLayout.Workspace = ComsStatic.Workspace; m_MapLayoutControl.IsHorizontalScrollbarVisible = false; m_MapLayoutControl.IsVerticalScrollbarVisible = false; uiPlayout.Controls.Add(m_MapLayoutControl); uiPlayout.Controls.SetChildIndex(m_MapLayoutControl, 0); } protected override void OnLoad(EventArgs e) { int index = MapControl.Map.TrackingLayer.IndexOf("ControlToolAddGeoRegion"); if (index == -1) { Sunny.UI.UIMessageTip.ShowError("请先绘制打印区域"); this.FindForm().Close(); return; } GeoRegion geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion; if (geo is null || geo.PartCount != 1) { ComsStatic.ShowErrorLog("绘制区域PartCount参数发生错误"); this.FindForm().Close(); return; } m_MapLayout = m_MapLayoutControl.MapLayout; m_MapLayout.Paper.Grid = new GridSetting() { IsVisible = false }; m_MapLayout.Paper.Size = paperSize; m_MapLayout.Paper.Orientation = paperOrientation; m_MapLayout.ZoomToPaper(); GeoMap geoMap = new GeoMap(); geoMap.MapName = m_Map.Name; geoMap.MapCenter = geo.InnerPoint; geoMap.MapScale = m_Map.Scale; Point2Ds ps = new Point2Ds(); foreach (Point2D p in geo[0]) { Point2D p1 = MapControl.Map.MapToLogical(p); ps.Add(new Point2D(p1.X * 10, p1.Y * 10)); } geoMap.Shape = new GeoRegion(ps); m_MapLayout.Elements.AddNew(geoMap); foreach (String printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { toolStripCBdayinji.Items.Add(printer); } toolStripCBdayinji.SelectedIndex = 0; toolStripComboBoxPapersize.ComboBox.ValueMember = "sizekey"; toolStripComboBoxPapersize.ComboBox.DisplayMember = "sizedesc"; toolStripComboBoxPapersize.ComboBox.DataSource = ComsStatic.getPaperSize(); } //public override bool ShowModal() { return true; } private int GetGeoMapID() { int mapID = -1; LayoutElements les = m_MapLayout.Elements; les.MoveFirst(); while (!les.IsEOF) { if (les.GetGeometry().Type == GeometryType.GeoMap) { mapID = les.GetID(); break; } les.MoveNext(); } return mapID; } private void toolStripButtonNorthArrow_Click(object sender, EventArgs e) { GeoNorthArrow geoNorthArrow = new GeoNorthArrow(); geoNorthArrow.StyleType = NorthArrowStyleType.ArrowInsideCircle; geoNorthArrow.BindingGeoMapID = GetGeoMapID(); geoNorthArrow.SetGeoReference(new Rectangle2D(addPoint, new Size2D(100, 100))); bool result = m_MapLayout.Elements.AddNew(geoNorthArrow); ComsStatic.ShowUIMessageTipOKorError(result, "添加指南针"); } private void toolStripButtonScale_Click(object sender, EventArgs e) { GeoMapScale geoMapScale = new GeoMapScale(GetGeoMapID(), addPoint, 500, 20); geoMapScale.ScaleType = GeoMapScaleType.RailwayMidSplit; geoMapScale.ScaleUnit = Unit.Meter; geoMapScale.LeftDivisionCount = 4; geoMapScale.SegmentCount = 4; bool result = m_MapLayout.Elements.AddNew(geoMapScale); ComsStatic.ShowUIMessageTipOKorError(result, "添加比例尺"); } private void toolSBLegend_Click(object sender, EventArgs e) { GeoLegend geoLegend = new GeoLegend(MapControl.Map.Name, MapControl.Map.Workspace); geoLegend.Center = addPoint; bool result = m_MapLayout.Elements.AddNew(geoLegend); ComsStatic.ShowUIMessageTipOKorError(result, "添加图例"); } private void toolStripButton1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(toolStripTextBoxBiaoti.Text)) { Sunny.UI.UIMessageTip.ShowError("请先输入需要添加的标题内容"); return; } TextStyle textStyle = new TextStyle(); textStyle.Alignment = SuperMap.Data.TextAlignment.TopCenter; textStyle.Bold = true; textStyle.IsSizeFixed = true; textStyle.FontHeight = 5.0; TextPart textPart = new TextPart(toolStripTextBoxBiaoti.Text, addPoint, 0); GeoText geoText = new GeoText(textPart, textStyle); bool result = m_MapLayout.Elements.AddNew(geoText); ComsStatic.ShowUIMessageTipOKorError(result, "添加标题内容"); toolStripTextBoxBiaoti.Text = ""; } private void toolStripButton2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(toolStripTextBoxBiaozhu.Text)) { Sunny.UI.UIMessageTip.ShowError("请先输入需要添加的标注内容"); return; } TextStyle textStyle = new TextStyle(); textStyle.Alignment = SuperMap.Data.TextAlignment.TopCenter; textStyle.IsSizeFixed = true; textStyle.FontHeight = 3.0; TextPart textPart = new TextPart(toolStripTextBoxBiaozhu.Text, addPoint, 0); GeoText geoText = new GeoText(textPart, textStyle); bool result = m_MapLayout.Elements.AddNew(geoText); ComsStatic.ShowUIMessageTipOKorError(result, "添加标注内容"); toolStripTextBoxBiaozhu.Text = ""; } private void toolStripButtonPrint_Click(object sender, EventArgs e) { string printerName = toolStripCBdayinji.SelectedItem as String; //toolStripCBdayinji.ComboBox.SelectedValue if (string.IsNullOrEmpty(printerName)) { Sunny.UI.UIMessageTip.ShowError("请先选择打印机"); return; } Printer printer = m_MapLayout.Printer; printer.PaperSize = paperSize; printer.Orientation = paperOrientation; printer.PrinterName = printerName; if (printer.IsValidPrinter) { WaitingForm wf = new WaitingForm((obj, args) => { m_MapLayout.Printer.Print(); }, "正在打印,请等待!"); wf.ShowDialog(this); ComsStatic.ShowOKLog("打印完成"); } else { ComsStatic.ShowErrorLog("当前打印机\"" + printerName + "\"无法打印"); return; } } private void toolStripButtonZoomIn_Click(object sender, EventArgs e) { m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.ZoomIn; } private void toolStripButtonZoomOut_Click(object sender, EventArgs e) { m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.ZoomOut; } private void toolStripButtonPan_Click(object sender, EventArgs e) { m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.Pan; } private void toolStripComboBoxPapersize_SelectedIndexChanged(object sender, EventArgs e) { string sizeStr = toolStripComboBoxPapersize.ComboBox.SelectedValue.ToString(); paperSize = ComsStatic.getPaperSize(sizeStr); m_MapLayout.Paper.Size = paperSize; m_MapLayout.ZoomToPaper(); addPoint = new Point2D(m_MapLayout.Paper.Margin.Left, ComsStatic.StringToInt(m_MapLayout.Paper.Height) - m_MapLayout.Paper.Margin.Top - m_MapLayout.Paper.Margin.Bottom); } private void toolStripButtonQuantu_Click(object sender, EventArgs e) { m_MapLayout.Paper.Size = paperSize; m_MapLayout.ZoomToPaper(); } } }