OutPrint.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. private Map m_Map;
  24. private MapLayoutControl m_MapLayoutControl;
  25. private MapLayout m_MapLayout;
  26. private Point2D addPoint = new Point2D(0, 0);
  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 OutPrint()
  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. m_MapLayout = m_MapLayoutControl.MapLayout;
  60. m_MapLayout.Paper.Grid = new GridSetting() { IsVisible = false };
  61. m_MapLayout.Paper.Size = paperSize;
  62. m_MapLayout.Paper.Orientation = paperOrientation;
  63. m_MapLayout.ZoomToPaper();
  64. GeoMap geoMap = new GeoMap();
  65. geoMap.MapName = m_Map.Name;
  66. geoMap.MapCenter = m_Map.ViewBounds.Center;
  67. geoMap.MapScale = m_Map.Scale;
  68. Double width = m_Map.ViewBounds.Width * m_Map.Scale * 10000;//将地图范围转换为逻辑坐标
  69. Double height = m_Map.ViewBounds.Height * m_Map.Scale * 10000;
  70. geoMap.Shape = new GeoRectangle(m_MapLayout.Center, width, height, 0);
  71. //if (paperOrientation == PaperOrientation.Landscape) //横向
  72. // geoMap.Shape = new GeoRectangle(m_MapLayout.Center, m_MapLayout.Printer.PaperHeight * 0.8, m_MapLayout.Printer.PaperWidth * 0.8, 0);
  73. //else
  74. // geoMap.Shape = new GeoRectangle(m_MapLayout.Center, m_MapLayout.Printer.PaperWidth * 0.8, m_MapLayout.Printer.PaperHeight * 0.8, 0);
  75. geoMap.IsGridVisible = false;//是否显示网格
  76. geoMap.IsBorderVisible = false;//地图几何对象的边框是否显示
  77. m_MapLayout.Elements.AddNew(geoMap);
  78. //m_MapLayout.Refresh();
  79. //Bitmap bitmap = new Bitmap(m_MapLayoutControl.Width, m_MapLayoutControl.Height);
  80. //m_MapLayoutControl.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
  81. //GeoMap addedGeoMap = m_MapLayout.Elements.GetGeometry() as GeoMap;
  82. //addedGeoMap.MapCenter = m_Map.ViewBounds.Center;
  83. //m_MapLayout.Elements.SetGeometry(addedGeoMap);
  84. foreach (String printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
  85. {
  86. toolStripCBdayinji.Items.Add(printer);
  87. }
  88. toolStripCBdayinji.SelectedIndex = 0;
  89. toolStripComboBoxPapersize.ComboBox.ValueMember = "sizekey";
  90. toolStripComboBoxPapersize.ComboBox.DisplayMember = "sizedesc";
  91. toolStripComboBoxPapersize.ComboBox.DataSource = ComsStatic.getPaperSize();
  92. }
  93. //public override bool ShowModal() { return true; }
  94. private int GetGeoMapID()
  95. {
  96. int mapID = -1;
  97. LayoutElements les = m_MapLayout.Elements;
  98. les.MoveFirst();
  99. while (!les.IsEOF)
  100. {
  101. if (les.GetGeometry().Type == GeometryType.GeoMap)
  102. {
  103. mapID = les.GetID(); break;
  104. }
  105. les.MoveNext();
  106. }
  107. return mapID;
  108. }
  109. private void toolStripButtonNorthArrow_Click(object sender, EventArgs e)
  110. {
  111. GeoNorthArrow geoNorthArrow = new GeoNorthArrow();
  112. geoNorthArrow.StyleType = NorthArrowStyleType.ArrowInsideCircle;
  113. geoNorthArrow.BindingGeoMapID = GetGeoMapID();
  114. geoNorthArrow.SetGeoReference(new Rectangle2D(addPoint, new Size2D(100, 100)));
  115. bool result = m_MapLayout.Elements.AddNew(geoNorthArrow);
  116. ComsStatic.ShowUIMessageTipOKorError(result, "添加指南针");
  117. }
  118. private void toolStripButtonScale_Click(object sender, EventArgs e)
  119. {
  120. GeoMapScale geoMapScale = new GeoMapScale(GetGeoMapID(), addPoint, 500, 20);
  121. geoMapScale.ScaleType = GeoMapScaleType.RailwayMidSplit;
  122. geoMapScale.ScaleUnit = Unit.Meter;
  123. geoMapScale.LeftDivisionCount = 4;
  124. geoMapScale.SegmentCount = 4;
  125. bool result = m_MapLayout.Elements.AddNew(geoMapScale);
  126. ComsStatic.ShowUIMessageTipOKorError(result, "添加比例尺");
  127. }
  128. private void toolSBLegend_Click(object sender, EventArgs e)
  129. {
  130. GeoLegend geoLegend = new GeoLegend(MapControl.Map.Name, MapControl.Map.Workspace);
  131. geoLegend.Center = addPoint;
  132. bool result = m_MapLayout.Elements.AddNew(geoLegend);
  133. ComsStatic.ShowUIMessageTipOKorError(result, "添加图例");
  134. }
  135. private void toolStripButton1_Click(object sender, EventArgs e)
  136. {
  137. if (string.IsNullOrEmpty(toolStripTextBoxBiaoti.Text))
  138. { Sunny.UI.UIMessageTip.ShowError("请先输入需要添加的标题内容"); return; }
  139. TextStyle textStyle = new TextStyle();
  140. textStyle.Alignment = SuperMap.Data.TextAlignment.TopCenter;
  141. textStyle.Bold = true;
  142. textStyle.IsSizeFixed = true;
  143. textStyle.FontHeight = 5.0;
  144. TextPart textPart = new TextPart(toolStripTextBoxBiaoti.Text, addPoint, 0);
  145. GeoText geoText = new GeoText(textPart, textStyle);
  146. bool result = m_MapLayout.Elements.AddNew(geoText);
  147. ComsStatic.ShowUIMessageTipOKorError(result, "添加标题内容");
  148. toolStripTextBoxBiaoti.Text = "";
  149. }
  150. private void toolStripButton2_Click(object sender, EventArgs e)
  151. {
  152. if (string.IsNullOrEmpty(toolStripTextBoxBiaozhu.Text))
  153. { Sunny.UI.UIMessageTip.ShowError("请先输入需要添加的标注内容"); return; }
  154. TextStyle textStyle = new TextStyle();
  155. textStyle.Alignment = SuperMap.Data.TextAlignment.TopCenter;
  156. textStyle.IsSizeFixed = true;
  157. textStyle.FontHeight = 3.0;
  158. TextPart textPart = new TextPart(toolStripTextBoxBiaozhu.Text, addPoint, 0);
  159. GeoText geoText = new GeoText(textPart, textStyle);
  160. bool result = m_MapLayout.Elements.AddNew(geoText);
  161. ComsStatic.ShowUIMessageTipOKorError(result, "添加标注内容");
  162. toolStripTextBoxBiaozhu.Text = "";
  163. }
  164. private void toolStripButtonPrint_Click(object sender, EventArgs e)
  165. {
  166. string printerName = toolStripCBdayinji.SelectedItem as String; //toolStripCBdayinji.ComboBox.SelectedValue
  167. if (string.IsNullOrEmpty(printerName)) { Sunny.UI.UIMessageTip.ShowError("请先选择打印机"); return; }
  168. Printer printer = m_MapLayout.Printer;
  169. printer.PaperSize = paperSize;
  170. printer.Orientation = paperOrientation;
  171. printer.PrinterName = printerName;
  172. if (printer.IsValidPrinter)
  173. {
  174. WaitingForm wf = new WaitingForm((obj, args) =>
  175. {
  176. m_MapLayout.Printer.Print();
  177. }, "正在打印,请等待!");
  178. wf.ShowDialog(this);
  179. ComsStatic.ShowOKLog("打印完成");
  180. }
  181. else
  182. {
  183. ComsStatic.ShowErrorLog("当前打印机\"" + printerName + "\"无法打印"); return;
  184. }
  185. }
  186. private void toolStripButtonZoomIn_Click(object sender, EventArgs e)
  187. {
  188. m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.ZoomIn;
  189. }
  190. private void toolStripButtonZoomOut_Click(object sender, EventArgs e)
  191. {
  192. m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.ZoomOut;
  193. }
  194. private void toolStripButtonPan_Click(object sender, EventArgs e)
  195. {
  196. m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.Pan;
  197. }
  198. private void toolStripComboBoxPapersize_SelectedIndexChanged(object sender, EventArgs e)
  199. {
  200. string sizeStr = toolStripComboBoxPapersize.ComboBox.SelectedValue.ToString();
  201. paperSize = ComsStatic.getPaperSize(sizeStr);
  202. m_MapLayout.Paper.Size = paperSize;
  203. m_MapLayout.ZoomToPaper();
  204. addPoint = new Point2D(m_MapLayout.Paper.Margin.Left, ComsStatic.StringToInt(m_MapLayout.Paper.Height) - m_MapLayout.Paper.Margin.Top - m_MapLayout.Paper.Margin.Bottom);
  205. }
  206. private void toolStripButtonQuantu_Click(object sender, EventArgs e)
  207. {
  208. m_MapLayout.Paper.Size = paperSize;
  209. m_MapLayout.ZoomToPaper();
  210. }
  211. }
  212. }