OutPrintcj.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 SuperMap.UI;
  18. using SuperMap.Layout;
  19. namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi
  20. {
  21. public partial class OutPrintcj : ConditionPanel
  22. {
  23. private MapLayoutControl m_MapLayoutControl;
  24. private MapLayout m_MapLayout;
  25. private Point2D addPoint = new Point2D(0, 0);
  26. private Map m_Map;
  27. /// <summary>
  28. /// 纸张大小
  29. /// </summary>
  30. private PaperSize paperSize = PaperSize.A4;
  31. /// <summary>
  32. /// 纸张方向 Landscape横向 Portrait纵向
  33. /// </summary>
  34. private PaperOrientation paperOrientation = PaperOrientation.Landscape;
  35. public OutPrintcj()
  36. {
  37. this.ConditionPanelName = "裁剪区域打印";
  38. this.IsShowPanelFooter = false;
  39. this.SetSize(Screen.PrimaryScreen.Bounds.Width - 300, Screen.PrimaryScreen.Bounds.Height - 200);
  40. InitializeComponent();
  41. m_Map = MapControl.Map;
  42. foreach (Layer lyr in m_Map.Layers)
  43. {
  44. Layer PrintLayer = MapControl.Map.Layers.FindLayer(lyr.Name);
  45. if (PrintLayer is null) continue;
  46. lyr.IsVisible = PrintLayer.IsVisible;
  47. }
  48. m_Map.Workspace.Maps.SetMapXML(m_Map.Name, m_Map.ToXML());
  49. m_MapLayoutControl = new MapLayoutControl();
  50. m_MapLayoutControl.Dock = DockStyle.Fill;
  51. m_MapLayoutControl.MapLayout.Workspace = ComsStatic.Workspace;
  52. m_MapLayoutControl.IsHorizontalScrollbarVisible = false;
  53. m_MapLayoutControl.IsVerticalScrollbarVisible = false;
  54. uiPlayout.Controls.Add(m_MapLayoutControl);
  55. uiPlayout.Controls.SetChildIndex(m_MapLayoutControl, 0);
  56. }
  57. protected override void OnLoad(EventArgs e)
  58. {
  59. int index = MapControl.Map.TrackingLayer.IndexOf("ControlToolAddGeoRegion");
  60. if (index == -1)
  61. {
  62. Sunny.UI.UIMessageTip.ShowError("请先绘制打印区域");
  63. this.FindForm().Close(); return;
  64. }
  65. GeoRegion geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion;
  66. if (geo is null || geo.PartCount != 1)
  67. {
  68. ComsStatic.ShowErrorLog("绘制区域PartCount参数发生错误");
  69. this.FindForm().Close(); return;
  70. }
  71. m_MapLayout = m_MapLayoutControl.MapLayout;
  72. m_MapLayout.Paper.Grid = new GridSetting() { IsVisible = false };
  73. m_MapLayout.Paper.Size = paperSize;
  74. m_MapLayout.Paper.Orientation = paperOrientation;
  75. m_MapLayout.ZoomToPaper();
  76. GeoMap geoMap = new GeoMap();
  77. geoMap.MapName = m_Map.Name;
  78. geoMap.MapCenter = geo.InnerPoint;
  79. geoMap.MapScale = m_Map.Scale;
  80. Point2Ds ps = new Point2Ds();
  81. foreach (Point2D p in geo[0])
  82. {
  83. Point2D p1 = MapControl.Map.MapToLogical(p);
  84. ps.Add(new Point2D(p1.X * 10, p1.Y * 10));
  85. }
  86. geoMap.Shape = new GeoRegion(ps);
  87. m_MapLayout.Elements.AddNew(geoMap);
  88. foreach (String printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
  89. {
  90. toolStripCBdayinji.Items.Add(printer);
  91. }
  92. toolStripCBdayinji.SelectedIndex = 0;
  93. toolStripComboBoxPapersize.ComboBox.ValueMember = "sizekey";
  94. toolStripComboBoxPapersize.ComboBox.DisplayMember = "sizedesc";
  95. toolStripComboBoxPapersize.ComboBox.DataSource = ComsStatic.getPaperSize();
  96. }
  97. //public override bool ShowModal() { return true; }
  98. private int GetGeoMapID()
  99. {
  100. int mapID = -1;
  101. LayoutElements les = m_MapLayout.Elements;
  102. les.MoveFirst();
  103. while (!les.IsEOF)
  104. {
  105. if (les.GetGeometry().Type == GeometryType.GeoMap)
  106. {
  107. mapID = les.GetID(); break;
  108. }
  109. les.MoveNext();
  110. }
  111. return mapID;
  112. }
  113. private void toolStripButtonNorthArrow_Click(object sender, EventArgs e)
  114. {
  115. GeoNorthArrow geoNorthArrow = new GeoNorthArrow();
  116. geoNorthArrow.StyleType = NorthArrowStyleType.ArrowInsideCircle;
  117. geoNorthArrow.BindingGeoMapID = GetGeoMapID();
  118. geoNorthArrow.SetGeoReference(new Rectangle2D(addPoint, new Size2D(100, 100)));
  119. bool result = m_MapLayout.Elements.AddNew(geoNorthArrow);
  120. ComsStatic.ShowUIMessageTipOKorError(result, "添加指南针");
  121. }
  122. private void toolStripButtonScale_Click(object sender, EventArgs e)
  123. {
  124. GeoMapScale geoMapScale = new GeoMapScale(GetGeoMapID(), addPoint, 500, 20);
  125. geoMapScale.ScaleType = GeoMapScaleType.RailwayMidSplit;
  126. geoMapScale.ScaleUnit = Unit.Meter;
  127. geoMapScale.LeftDivisionCount = 4;
  128. geoMapScale.SegmentCount = 4;
  129. bool result = m_MapLayout.Elements.AddNew(geoMapScale);
  130. ComsStatic.ShowUIMessageTipOKorError(result, "添加比例尺");
  131. }
  132. private void toolSBLegend_Click(object sender, EventArgs e)
  133. {
  134. GeoLegend geoLegend = new GeoLegend(MapControl.Map.Name, MapControl.Map.Workspace);
  135. geoLegend.Center = addPoint;
  136. bool result = m_MapLayout.Elements.AddNew(geoLegend);
  137. ComsStatic.ShowUIMessageTipOKorError(result, "添加图例");
  138. }
  139. private void toolStripButton1_Click(object sender, EventArgs e)
  140. {
  141. if (string.IsNullOrEmpty(toolStripTextBoxBiaoti.Text))
  142. { Sunny.UI.UIMessageTip.ShowError("请先输入需要添加的标题内容"); return; }
  143. TextStyle textStyle = new TextStyle();
  144. textStyle.Alignment = SuperMap.Data.TextAlignment.TopCenter;
  145. textStyle.Bold = true;
  146. textStyle.IsSizeFixed = true;
  147. textStyle.FontHeight = 5.0;
  148. TextPart textPart = new TextPart(toolStripTextBoxBiaoti.Text, addPoint, 0);
  149. GeoText geoText = new GeoText(textPart, textStyle);
  150. bool result = m_MapLayout.Elements.AddNew(geoText);
  151. ComsStatic.ShowUIMessageTipOKorError(result, "添加标题内容");
  152. toolStripTextBoxBiaoti.Text = "";
  153. }
  154. private void toolStripButton2_Click(object sender, EventArgs e)
  155. {
  156. if (string.IsNullOrEmpty(toolStripTextBoxBiaozhu.Text))
  157. { Sunny.UI.UIMessageTip.ShowError("请先输入需要添加的标注内容"); return; }
  158. TextStyle textStyle = new TextStyle();
  159. textStyle.Alignment = SuperMap.Data.TextAlignment.TopCenter;
  160. textStyle.IsSizeFixed = true;
  161. textStyle.FontHeight = 3.0;
  162. TextPart textPart = new TextPart(toolStripTextBoxBiaozhu.Text, addPoint, 0);
  163. GeoText geoText = new GeoText(textPart, textStyle);
  164. bool result = m_MapLayout.Elements.AddNew(geoText);
  165. ComsStatic.ShowUIMessageTipOKorError(result, "添加标注内容");
  166. toolStripTextBoxBiaozhu.Text = "";
  167. }
  168. private void toolStripButtonPrint_Click(object sender, EventArgs e)
  169. {
  170. string printerName = toolStripCBdayinji.SelectedItem as String; //toolStripCBdayinji.ComboBox.SelectedValue
  171. if (string.IsNullOrEmpty(printerName)) { Sunny.UI.UIMessageTip.ShowError("请先选择打印机"); return; }
  172. Printer printer = m_MapLayout.Printer;
  173. printer.PaperSize = paperSize;
  174. printer.Orientation = paperOrientation;
  175. printer.PrinterName = printerName;
  176. if (printer.IsValidPrinter)
  177. {
  178. WaitingForm wf = new WaitingForm((obj, args) =>
  179. {
  180. m_MapLayout.Printer.Print();
  181. }, "正在打印,请等待!");
  182. wf.ShowDialog(this);
  183. ComsStatic.ShowOKLog("打印完成");
  184. }
  185. else
  186. {
  187. ComsStatic.ShowErrorLog("当前打印机\"" + printerName + "\"无法打印"); return;
  188. }
  189. }
  190. private void toolStripButtonZoomIn_Click(object sender, EventArgs e)
  191. {
  192. m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.ZoomIn;
  193. }
  194. private void toolStripButtonZoomOut_Click(object sender, EventArgs e)
  195. {
  196. m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.ZoomOut;
  197. }
  198. private void toolStripButtonPan_Click(object sender, EventArgs e)
  199. {
  200. m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.Pan;
  201. }
  202. private void toolStripComboBoxPapersize_SelectedIndexChanged(object sender, EventArgs e)
  203. {
  204. string sizeStr = toolStripComboBoxPapersize.ComboBox.SelectedValue.ToString();
  205. paperSize = ComsStatic.getPaperSize(sizeStr);
  206. m_MapLayout.Paper.Size = paperSize;
  207. m_MapLayout.ZoomToPaper();
  208. addPoint = new Point2D(m_MapLayout.Paper.Margin.Left, ComsStatic.StringToInt(m_MapLayout.Paper.Height) - m_MapLayout.Paper.Margin.Top - m_MapLayout.Paper.Margin.Bottom);
  209. }
  210. private void toolStripButtonQuantu_Click(object sender, EventArgs e)
  211. {
  212. m_MapLayout.Paper.Size = paperSize;
  213. m_MapLayout.ZoomToPaper();
  214. }
  215. }
  216. }