OutPrint.cs 9.3 KB

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