PdnToolBar.cs 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  1. using SmartCoalApplication.Base;
  2. using SmartCoalApplication.Base.CommTool;
  3. using SmartCoalApplication.Base.Enum;
  4. using SmartCoalApplication.Base.SettingModel;
  5. using SmartCoalApplication.Core;
  6. using SmartCoalApplication.Core.DbOpreate.DbBll;
  7. using SmartCoalApplication.Core.DbOpreate.DbModel;
  8. using SmartCoalApplication.Menus;
  9. using SmartCoalApplication.SystemLayer;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Drawing;
  13. using System.Drawing.Drawing2D;
  14. using System.IO;
  15. using System.Windows.Forms;
  16. using static SmartCoalApplication.Base.SettingModel.ToolbarModel;
  17. namespace SmartCoalApplication
  18. {
  19. internal class PdnToolBar : Control, IPaintBackground
  20. {
  21. private AppWorkspace appWorkspace;
  22. /// <summary>
  23. /// 主菜单
  24. /// </summary>
  25. private PdnMainMenu mainMenu;
  26. /// <summary>
  27. /// 自定义工具栏
  28. /// </summary>
  29. private ToolStripContainer toolStripContainer1;
  30. /// <summary>
  31. /// 自定义工具栏上的右键菜单
  32. /// </summary>
  33. private ContextMenuStrip contextMenuStrip;
  34. public ToolStrip[] toolStrips;
  35. private List<ToolStripComboBox> rulersComboBox = new List<ToolStripComboBox>();
  36. /// <summary>
  37. /// 工具栏
  38. /// </summary>
  39. private ToolbarModel toolbarModel = Program.instance.toolbarModel;
  40. private int toolStripInitLayout = 10;
  41. /// <summary>
  42. /// 目前被改成tab的菜单了
  43. /// </summary>
  44. private OurDocumentStrip documentStrip;
  45. private OurToolStripRenderer otsr = new OurToolStripRenderer();
  46. private Bitmap copyedBitmap;//复制的图片
  47. private int nameNum = 0;//命名使用
  48. private class OurToolStripRenderer :
  49. ToolStripProfessionalRenderer
  50. {
  51. public OurToolStripRenderer()
  52. {
  53. RoundedEdges = false;
  54. }
  55. private void PaintBackground(Graphics g, Control control, Rectangle clipRect)
  56. {
  57. Control parent = control;
  58. IPaintBackground asIpb = null;
  59. while (true)
  60. {
  61. parent = parent.Parent;
  62. if (parent == null)
  63. {
  64. break;
  65. }
  66. asIpb = parent as IPaintBackground;
  67. if (asIpb != null)
  68. {
  69. break;
  70. }
  71. }
  72. if (asIpb != null)
  73. {
  74. Rectangle screenRect = control.RectangleToScreen(clipRect);
  75. Rectangle parentRect = parent.RectangleToClient(screenRect);
  76. int dx = parentRect.Left - clipRect.Left;
  77. int dy = parentRect.Top - clipRect.Top;
  78. g.TranslateTransform(-dx, -dy, MatrixOrder.Append);
  79. asIpb.PaintBackground(g, parentRect);
  80. g.TranslateTransform(dx, dy, MatrixOrder.Append);
  81. }
  82. }
  83. protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e)
  84. {
  85. PaintBackground(e.Graphics, e.ToolStripPanel, new Rectangle(new Point(0, 0), e.ToolStripPanel.Size));
  86. e.Handled = true;
  87. }
  88. protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
  89. {
  90. if (e.ToolStrip.GetType() != typeof(ToolStrip) &&
  91. e.ToolStrip.GetType() != typeof(ToolStripEx) &&
  92. e.ToolStrip.GetType() != typeof(PdnMainMenu))
  93. {
  94. base.OnRenderToolStripBackground(e);
  95. }
  96. else
  97. {
  98. PaintBackground(e.Graphics, e.ToolStrip, e.AffectedBounds);
  99. }
  100. }
  101. }
  102. private class OurDocumentStrip : DocumentStrip, IPaintBackground
  103. {
  104. public OurDocumentStrip(AppWorkspace appWorkspace) : base(appWorkspace)
  105. {
  106. }
  107. protected override void DrawItemBackground(Graphics g, Item item, Rectangle itemRect)
  108. {
  109. PaintBackground(g, itemRect);
  110. /**
  111. if (item.Image != null)
  112. {
  113. g.DrawImage(item.Image, new Point(0, 0));
  114. }
  115. else
  116. {
  117. PaintBackground(g, itemRect);
  118. }**/
  119. }
  120. public void PaintBackground(Graphics g, Rectangle clipRect)
  121. {
  122. IPaintBackground asIpb = this.Parent as IPaintBackground;
  123. if (asIpb != null)
  124. {
  125. Rectangle newClipRect = new Rectangle(
  126. clipRect.Left + Left, clipRect.Top + Top,
  127. clipRect.Width, clipRect.Height);
  128. g.TranslateTransform(-Left, -Top, MatrixOrder.Append);
  129. asIpb.PaintBackground(g, newClipRect);
  130. g.TranslateTransform(Left, Top, MatrixOrder.Append);
  131. }
  132. }
  133. }
  134. public void PaintBackground(Graphics g, Rectangle clipRect)
  135. {
  136. if (clipRect.Width > 0 && clipRect.Height > 0)
  137. {
  138. Color backColor = ProfessionalColors.MenuStripGradientEnd;
  139. using (SolidBrush brush = new SolidBrush(backColor))
  140. {
  141. g.FillRectangle(brush, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
  142. }
  143. }
  144. }
  145. public AppWorkspace AppWorkspace
  146. {
  147. get
  148. {
  149. return this.appWorkspace;
  150. }
  151. set
  152. {
  153. this.appWorkspace = value;
  154. this.mainMenu.AppWorkspace = value;
  155. }
  156. }
  157. public PdnMainMenu MainMenu
  158. {
  159. get
  160. {
  161. return this.mainMenu;
  162. }
  163. }
  164. public DocumentStrip DocumentStrip
  165. {
  166. get
  167. {
  168. return this.documentStrip;
  169. }
  170. }
  171. public PdnToolBar(AppWorkspace appWorkspace)
  172. {
  173. this.appWorkspace = appWorkspace;
  174. SuspendLayout();
  175. InitializeComponent();
  176. InitializeContextMenuStrip();
  177. this.otsr = new OurToolStripRenderer();
  178. this.mainMenu.Renderer = otsr;
  179. ResumeLayout(true);
  180. }
  181. public void InitializeContextMenuStrip()
  182. {
  183. this.contextMenuStrip.Items.Clear();
  184. foreach (Flow flow in Program.instance.toolbarModel.Flows)
  185. {
  186. ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
  187. toolStripMenuItem.Text = flow.Name;
  188. toolStripMenuItem.Checked = flow.Show;
  189. this.contextMenuStrip.Items.Add(toolStripMenuItem);
  190. }
  191. }
  192. private void contextMenuStripItem_Click(object sender, ToolStripItemClickedEventArgs e)
  193. {
  194. bool ShowFlag = !((ToolStripMenuItem)e.ClickedItem).Checked;
  195. ((ToolStripMenuItem)e.ClickedItem).Checked = ShowFlag;
  196. Flow flow = Program.instance.toolbarModel.Flows.Find(a => a.Name.Equals(e.ClickedItem.Text));
  197. if (flow != null)
  198. {
  199. flow.Show = ShowFlag;
  200. string userInfoXml = XmlSerializeHelper.XmlSerialize<ToolbarModel>(Program.instance.toolbarModel);
  201. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Toolbar.xml";
  202. FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
  203. Control[] control = this.toolStripContainer1.TopToolStripPanel.Controls.Find(flow.Key, true);
  204. if (control != null && control.Length > 0)
  205. {
  206. control[0].Visible = ShowFlag;
  207. }
  208. }
  209. }
  210. /// <summary>
  211. /// 刷新自定义工具栏的列表内容-标尺标定
  212. /// </summary>
  213. public void refreshRulersComboBoxList()//###2
  214. {
  215. List<mic_rulers> list = Program.instance.mic_rulersAll;
  216. string rulerName = "";
  217. if (list != null)
  218. {
  219. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  220. {
  221. mic_rulers rule = list[ruleI];
  222. int rulid = rule.id;
  223. if (rulid == Program.instance.configModel.RulerId)
  224. {
  225. rulerName = rule.ruler_name;
  226. break;
  227. }
  228. }
  229. }
  230. foreach (ToolStripComboBox comboBox in rulersComboBox)
  231. {
  232. comboBox.Items.Clear();
  233. if (list != null)
  234. {
  235. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  236. {
  237. mic_rulers rule = list[ruleI];
  238. comboBox.Items.Add(rule.ruler_name);
  239. //if (Program.instance.configModel != null)
  240. //{
  241. // if (Program.instance.configModel.RulerId == rule.id)
  242. // {
  243. // zoomComboBox.Text = rule.ruler_name;// "newText";
  244. // }
  245. //}
  246. }
  247. }
  248. else
  249. continue;
  250. for (int i = 0; i < comboBox.Items.Count; i++)
  251. {
  252. if (rulerName.Equals(comboBox.Items[i].ToString()))
  253. {
  254. comboBox.SelectedIndex = i;
  255. }
  256. }
  257. }
  258. }
  259. /// <summary>
  260. /// 刷新自定义工具栏的激活标尺-标尺标定
  261. /// </summary>
  262. public void refreshRulersComboBoxActive()//###1
  263. {
  264. foreach (ToolStripComboBox comboBox in rulersComboBox)
  265. {
  266. string rulerName = "";
  267. List<mic_rulers> list = Program.instance.mic_rulersAll;
  268. if (list != null)
  269. {
  270. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  271. {
  272. mic_rulers rule = list[ruleI];
  273. int rulid = rule.id;
  274. if (rulid == Program.instance.configModel.RulerId)
  275. {
  276. rulerName = rule.ruler_name;
  277. break;
  278. }
  279. }
  280. }
  281. for (int i = 0; i < comboBox.Items.Count; i++)
  282. {
  283. if (rulerName.Equals(comboBox.Items[i].ToString()))
  284. {
  285. comboBox.SelectedIndex = i;
  286. }
  287. }
  288. this.AppWorkspace.Widgets.RuleListForm.MenuSubApplyCurrent();
  289. }
  290. }
  291. /// <summary>
  292. /// 布局自定义工具栏
  293. /// </summary>
  294. /// <param name="toReset"></param>
  295. /// <param name="refreshFlag">1 添加 2删除 3移出 4向上移动 5向下移动 6添加分割线【 7添加新的节点】</param>
  296. public void test1(bool toReset, int refreshFlag = 0, string toolStripContrainerName = null, int toolStripItemIndex = 0, string nodeName = null, string nodeText = null, int nodeTag = 0)
  297. {
  298. if (toReset && refreshFlag > 0 && refreshFlag < 7)
  299. {
  300. this.toolbarModel = Program.instance.toolbarModel;
  301. if (toolbarModel == null || toolbarModel.Flows.Count == 0)
  302. {
  303. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  304. return;
  305. }
  306. int toolCount = toolbarModel.Flows.Count;
  307. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  308. {
  309. Flow flowJ = toolbarModel.Flows[j];
  310. if (flowJ.Menus.Count == 0)
  311. {
  312. toolCount -= 1;
  313. }
  314. }
  315. if (toolCount == 0)
  316. {
  317. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  318. return;
  319. }
  320. bool addSuccess = false;
  321. foreach (ToolStrip toolStripContrainer in this.toolStripContainer1.TopToolStripPanel.Controls)
  322. {
  323. if (toolStripContrainer.Name.Equals(toolStripContrainerName))
  324. {
  325. if (refreshFlag == 6)// 6添加分割线
  326. {
  327. ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count + 1];
  328. for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
  329. {
  330. if (itemIndex < toolStripItemIndex)
  331. buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
  332. else if (itemIndex == toolStripItemIndex)
  333. {
  334. buttons[itemIndex] = new ToolStripSeparator();
  335. buttons[itemIndex + 1] = toolStripContrainer.Items[itemIndex];
  336. }
  337. else
  338. buttons[itemIndex + 1] = toolStripContrainer.Items[itemIndex];
  339. }
  340. toolStripContrainer.Items.Clear();
  341. toolStripContrainer.Items.AddRange(buttons);
  342. }
  343. else if (refreshFlag == 1)// 1 添加
  344. {
  345. addSuccess = true;
  346. //this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripContrainer);
  347. int toAddCount = 1;
  348. if (nodeName.Equals("Script"))//脚本列表
  349. {
  350. List<mic_script> list = mic_script_BLL.FindAll();
  351. toAddCount += (list.Count - 1);
  352. }
  353. else if (nodeName.Equals("SubRulerCalibration"))
  354. {
  355. toAddCount += 1;
  356. }
  357. ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count + toAddCount];
  358. for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
  359. {
  360. buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
  361. }
  362. int i = toolStripContrainer.Items.Count;
  363. int index = toolStripContrainer.Items.Count;// 0;
  364. {
  365. ToolStripButton button = new ToolStripButton();
  366. int imageIndex = -1;
  367. //if (flowJ.Menus[i].Description.Equals("SeparateLine"))
  368. //{
  369. // ToolStripSeparator separator0 = new ToolStripSeparator();
  370. // buttons[index] = separator0;
  371. // continue;
  372. //}
  373. ToolStripItem[] items = this.MainMenu.Items.Find(nodeName, true);
  374. if (items != null && items.Length > 0)
  375. {
  376. if (((PdnMenuItem)(items[0])).Image != null)
  377. imageIndex = toolStripContrainer.ImageList.Images.Add(((PdnMenuItem)(items[0])).Image, toolStripContrainer.ImageList.TransparentColor);
  378. else
  379. imageIndex = toolStripContrainer.ImageList.Images.Add(new Bitmap(16, 16), toolStripContrainer.ImageList.TransparentColor);
  380. }
  381. else
  382. {
  383. imageIndex = toolStripContrainer.ImageList.Images.Add(new Bitmap(16, 16), toolStripContrainer.ImageList.TransparentColor);
  384. }
  385. button.ImageIndex = imageIndex;
  386. button.Tag = nodeName;// flowJ.Menus[i].Description;
  387. button.ToolTipText = nodeText;// flowJ.Menus[i].Name;
  388. button.Text = nodeText;// flowJ.Menus[i].Name;
  389. button.TextImageRelation = TextImageRelation.ImageAboveText;
  390. //..Script
  391. if (nodeName.Equals("Script"))//脚本列表
  392. {
  393. List<mic_script> list = mic_script_BLL.FindAll();
  394. for (int itemI = 0; itemI < list.Count - 1; itemI++)
  395. {
  396. var itemSS = list[itemI];
  397. ToolStripButton unitLabel = new ToolStripButton();
  398. unitLabel.Text = itemSS.name;
  399. unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  400. unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
  401. //unitLabel.Tag = "Script_" + itemSS.id;
  402. unitLabel.Name = "" + itemSS.id;
  403. buttons[index] = unitLabel;
  404. index++;
  405. }
  406. //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  407. var item = list[list.Count - 1];
  408. ToolStripButton unitsLabel = new ToolStripButton();
  409. unitsLabel.Text = item.name;
  410. unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  411. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  412. unitsLabel.Name = "" + item.id;
  413. buttons[index] = unitsLabel;
  414. }
  415. else if (nodeName.Equals("SubRulerCalibration"))
  416. {
  417. ToolStripLabel unitsLabel = new ToolStripLabel();
  418. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  419. unitsLabel.Text = "标尺:";
  420. buttons[index] = unitsLabel;
  421. index++;
  422. ToolStripComboBox zoomComboBox = new ToolStripComboBox();
  423. zoomComboBox.Tag = i;
  424. zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
  425. zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
  426. zoomComboBox.MaxDropDownItems = 99;
  427. zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
  428. List<mic_rulers> list = mic_rulers_BLL.FindAll();
  429. if (list != null)
  430. {
  431. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  432. {
  433. mic_rulers rule = list[ruleI];
  434. zoomComboBox.Items.Add(rule.ruler_name);
  435. if (Program.instance.configModel != null)
  436. {
  437. if (Program.instance.configModel.RulerId == rule.id)
  438. {
  439. zoomComboBox.Text = rule.ruler_name;// "newText";
  440. }
  441. }
  442. }
  443. }
  444. //if (zoomComboBox.Text == null || zoomComboBox.Text.Equals(""))
  445. //{
  446. // zoomComboBox.Text = "请选择";
  447. //}
  448. rulersComboBox.Add(zoomComboBox);
  449. buttons[index] = zoomComboBox;
  450. zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  451. zoomComboBox.BackColor = SystemColors.Window;
  452. }
  453. else
  454. {
  455. buttons[index] = button;
  456. }
  457. }
  458. //toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
  459. //toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
  460. //toolStripEx.EndDrag += ToolStripEx_DragDrop1;
  461. //toolStripEx.AllowDrop = false;
  462. //toolStripEx.AllowMerge = false;
  463. //toolStripEx.Height = 40;
  464. //toolStripEx.Items.AddRange(buttons);
  465. toolStripContrainer.Items.Clear();
  466. toolStripContrainer.Items.AddRange(buttons);
  467. appWorkspace.SetTopLeftCheckState();
  468. }
  469. else if (refreshFlag == 2)// 2删除
  470. {
  471. this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripContrainer);
  472. }
  473. else if (refreshFlag == 3)// 3移出
  474. {
  475. if (toolStripItemIndex > 0 && toolStripContrainer.Items.Count > toolStripItemIndex)
  476. {
  477. for (int itemIndex = 0; itemIndex < toolStripItemIndex/*toolStripContrainer.Items.Count*/; itemIndex++)
  478. {
  479. //#######################################
  480. }
  481. }
  482. //int toAddCount = 1;
  483. //if (nodeName.Equals("Script"))//脚本列表
  484. //{
  485. // List<mic_script> list = mic_script_BLL.FindAll();
  486. // toAddCount += (list.Count - 1);
  487. //}
  488. //else if (nodeName.Equals("SubRulerCalibration"))
  489. //{
  490. // toAddCount += 1;
  491. //}
  492. //ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count + toAddCount];
  493. if (toolStripContrainer.Items.Count > toolStripItemIndex)
  494. toolStripContrainer.Items.RemoveAt(toolStripItemIndex);
  495. if (toolStripContrainer.Items.Count == 0)
  496. this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripContrainer);
  497. }
  498. else if (refreshFlag == 4)// 4向上移动
  499. {
  500. //if (toolStripContrainer.Items.Count > toolStripItemIndex)
  501. // toolStripContrainer.Items.RemoveAt(toolStripItemIndex);
  502. if (toolStripItemIndex > 0 && toolStripContrainer.Items.Count > toolStripItemIndex)
  503. {
  504. ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count];
  505. for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
  506. {
  507. if (itemIndex == toolStripItemIndex)
  508. {
  509. buttons[toolStripItemIndex] = toolStripContrainer.Items[toolStripItemIndex - 1];
  510. }
  511. else if (itemIndex == toolStripItemIndex - 1)
  512. {
  513. buttons[toolStripItemIndex - 1] = toolStripContrainer.Items[toolStripItemIndex];
  514. }
  515. else
  516. {
  517. buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
  518. }
  519. }
  520. //ToolStripItem preStripItem = toolStripContrainer.Items[toolStripItemIndex - 1];
  521. //toolStripContrainer.Items.Insert(toolStripItemIndex + 1, preStripItem);
  522. //toolStripContrainer.Items.RemoveAt(toolStripItemIndex - 1);
  523. toolStripContrainer.Items.Clear();
  524. toolStripContrainer.Items.AddRange(buttons);
  525. }
  526. //int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  527. //if (index > 0)
  528. //{
  529. // TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.PrevNode.Clone();
  530. // this.treeViewLeft.SelectedNode.Parent.Nodes.Insert(index + 1, prenode);
  531. // this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.PrevNode);
  532. //}
  533. }
  534. else if (refreshFlag == 5)// 5向下移动
  535. {
  536. if (toolStripItemIndex < toolStripContrainer.Items.Count - 1 && toolStripContrainer.Items.Count > toolStripItemIndex)
  537. {
  538. ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count];
  539. for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
  540. {
  541. if (itemIndex == toolStripItemIndex)
  542. {
  543. buttons[toolStripItemIndex] = toolStripContrainer.Items[toolStripItemIndex + 1];
  544. }
  545. else if (itemIndex == toolStripItemIndex + 1)
  546. {
  547. buttons[toolStripItemIndex + 1] = toolStripContrainer.Items[toolStripItemIndex];
  548. }
  549. else
  550. {
  551. buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
  552. }
  553. }
  554. toolStripContrainer.Items.Clear();
  555. toolStripContrainer.Items.AddRange(buttons);
  556. }
  557. }
  558. break;
  559. }
  560. }
  561. if (!addSuccess && refreshFlag == 1)// 1 添加
  562. {
  563. addSuccess = true;
  564. }
  565. else
  566. return;
  567. }
  568. if (toReset)
  569. {
  570. this.toolStripContainer1.TopToolStripPanel.ControlRemoved -= TopToolStripPanel_ControlRemoved;
  571. this.toolStripContainer1.TopToolStripPanel.DragDrop -= TopToolStripPanel_DragDrop;
  572. this.toolStripContainer1.TopToolStripPanel.DragLeave -= TopToolStripPanel_DragLeave;
  573. toolbarModel = Program.instance.toolbarModel;
  574. }
  575. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  576. this.toolStripContainer1.SuspendLayout();
  577. this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
  578. this.toolStripContainer1.LeftToolStripPanel.SuspendLayout();
  579. this.toolStripContainer1.RightToolStripPanel.SuspendLayout();
  580. this.toolStripContainer1.BottomToolStripPanel.SuspendLayout();
  581. if (this.toolStripContainer1.TopToolStripPanel.Controls.Count == 0)
  582. SetCustomizeTools();
  583. //先将location值不为-100的菜单显示出来(初始值设置-100)
  584. int heightRow = 0;// -1;// 0;
  585. int widthRow1 = 0;// -1;// 0;
  586. //for (int j = 0; j < Program.instance.toolbarLocationModel.Flows.Count; j++)
  587. for (int j = 0; j < Program.instance.toolbarModel.Flows.Count; j++)
  588. {
  589. //ToolbarLocationModel.Flow flowJ = Program.instance.toolbarLocationModel.Flows[j];
  590. ToolbarModel.Flow flowJ = Program.instance.toolbarModel.Flows[j];
  591. if (flowJ.X > -100 && flowJ.Y > -100)
  592. {
  593. if (flowJ.Y > heightRow || (flowJ.Y == heightRow && flowJ.X >= widthRow1))
  594. {
  595. Control[] toolStripTemp = /*(ToolStrip[])*/this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true);
  596. //ToolStrip toolStripEx = (ToolStrip)this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true)[0];
  597. if (toolStripTemp != null && toolStripTemp.Length > 0/*toolStripEx == null*/)
  598. {
  599. ToolStrip toolStripEx = (ToolStrip)toolStripTemp[0];
  600. heightRow = flowJ.Y;
  601. widthRow1 = flowJ.X + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
  602. }
  603. else
  604. {
  605. if (toolStrips != null && toolStrips.Length > 0)
  606. {
  607. ToolStrip toolStripEx = new List<ToolStrip>(toolStrips).Find(a => a.Name.Equals(flowJ.Key));// toolStrips.Find(a => a.Key.Equals(toolStripEx.Name));
  608. if (toolStripEx != null)
  609. {
  610. heightRow = flowJ.Y;
  611. widthRow1 = flowJ.X + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
  612. continue;
  613. }
  614. }
  615. heightRow = flowJ.Y;
  616. widthRow1 = flowJ.X + 1;
  617. }
  618. }
  619. }
  620. }
  621. if (toolStrips != null && toolStrips.Length > 0)
  622. {
  623. for (int j = 0; j < toolStrips.Length; j++)
  624. {
  625. //Base.SettingModel.ToolbarLocationModel.Flow flowJ = toolbarLocationModel.Flows.Find(a => a.Key.Equals(toolStrips[j].Name));
  626. Base.SettingModel.ToolbarModel.Flow flowJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStrips[j].Name));
  627. if (flowJ.X == -100 || flowJ.Y == -100)
  628. {
  629. if (widthRow1 < ClientSize.Width || ClientSize.Width == 0)
  630. {
  631. toolStrips[j].Location = new Point(widthRow1/*lastToolStripEx.Right + 1*/, heightRow/*lastToolStripEx.Top*/);
  632. widthRow1 = widthRow1 + toolStrips[j].PreferredSize.Width + toolStrips[j].Margin.Horizontal + 1;
  633. }
  634. else
  635. {
  636. heightRow += 40;// 38;// 39;
  637. toolStrips[j].Location = new Point(0, heightRow/*lastToolStripEx.Bottom*/);
  638. widthRow1 = 0/*toolStripEx.Left*/ + toolStrips[j].PreferredSize.Width + toolStrips[j].Margin.Horizontal;
  639. }
  640. }
  641. else
  642. {
  643. toolStrips[j].Location = new Point(flowJ.X, flowJ.Y);
  644. }
  645. }
  646. }
  647. if (this.toolStripContainer1.TopToolStripPanel.Controls.Count == 0 && toolStrips != null)//数组的判定条件为后添加,不确定是否正确8.12
  648. this.toolStripContainer1.TopToolStripPanel.Controls.AddRange(toolStrips);
  649. this.toolStripContainer1.TopToolStripPanel.ResumeLayout();
  650. this.toolStripContainer1.LeftToolStripPanel.ResumeLayout();
  651. this.toolStripContainer1.RightToolStripPanel.ResumeLayout();
  652. this.toolStripContainer1.BottomToolStripPanel.ResumeLayout();
  653. this.toolStripContainer1.ResumeLayout();
  654. }
  655. protected override void OnLayout(LayoutEventArgs e)
  656. {
  657. bool plentyWidthBefore = (this.mainMenu.Width >= this.mainMenu.PreferredSize.Width);
  658. if (!plentyWidthBefore)
  659. {
  660. UI.SuspendControlPainting(this);
  661. }
  662. else
  663. {
  664. UI.SuspendControlPainting(this.documentStrip);
  665. }
  666. this.mainMenu.Location = new Point(0, 0);
  667. this.mainMenu.Height = this.mainMenu.PreferredSize.Height;
  668. this.toolStripContainer1.Location = new Point(0, this.mainMenu.Bottom);
  669. this.toolStripContainer1.Margin = new Padding(-5);
  670. this.toolStripContainer1.TopToolStripPanel.Margin = new Padding(-5);
  671. this.toolStripContainer1.TopToolStripPanel.RowMargin = new Padding(0/*-1*/);
  672. this.mainMenu.Padding = new Padding(0, this.mainMenu.Padding.Top, 0, this.mainMenu.Padding.Bottom);
  673. this.documentStrip.Width = ClientSize.Width;
  674. this.documentStrip.Anchor = AnchorStyles.Left | AnchorStyles.Right;
  675. this.documentStrip.Location = new Point(0, this.toolStripContainer1.Bottom);
  676. // Finish setting up widths and heights
  677. int oldDsHeight = this.documentStrip.Height;
  678. this.documentStrip.Height = 25;
  679. int tsWidth = ClientSize.Width;
  680. this.mainMenu.Width = tsWidth;
  681. if (tsWidth > 0)
  682. {
  683. this.toolStripContainer1.TopToolStripPanel.Width = tsWidth;
  684. this.toolStripContainer1.Width = tsWidth;
  685. }
  686. this.Height = this.documentStrip.Bottom;
  687. this.documentStrip.PerformLayout();
  688. if (!plentyWidthBefore)
  689. {
  690. UI.ResumeControlPainting(this);
  691. Invalidate(true);
  692. }
  693. else
  694. {
  695. UI.ResumeControlPainting(this.documentStrip);
  696. this.documentStrip.Invalidate(true);
  697. }
  698. if (this.documentStrip.Width == 0)
  699. {
  700. this.mainMenu.Invalidate();
  701. }
  702. if (oldDsHeight != this.documentStrip.Height)
  703. {
  704. this.documentStrip.RefreshAllThumbnails();
  705. }
  706. base.OnLayout(e);
  707. }
  708. protected override void OnResize(EventArgs e)
  709. {
  710. PerformLayout();
  711. base.OnResize(e);
  712. }
  713. private void InitializeComponent()
  714. {
  715. this.SuspendLayout();
  716. this.mainMenu = new PdnMainMenu();
  717. this.toolStripContainer1 = new ToolStripContainer();
  718. this.documentStrip = new OurDocumentStrip(this.appWorkspace);
  719. this.toolStripContainer1.SuspendLayout();
  720. this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
  721. //
  722. // mainMenu
  723. //
  724. this.mainMenu.Name = "mainMenu";
  725. this.mainMenu.ContextMenuStrip = this.contextMenuStrip;
  726. this.mainMenu.MouseClick += new System.Windows.Forms.MouseEventHandler(this.frmContextmenu_MouseClick);
  727. //
  728. // 右键菜单
  729. //
  730. this.contextMenuStrip = new ContextMenuStrip();
  731. this.contextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(this.contextMenuStripItem_Click);
  732. //
  733. // toolStripContainer1.TopToolStripPanel
  734. //
  735. this.toolStripContainer1.AllowDrop = true;
  736. this.toolStripContainer1.BottomToolStripPanelVisible = false;
  737. this.toolStripContainer1.LeftToolStripPanelVisible = false;
  738. this.toolStripContainer1.RightToolStripPanelVisible = false;
  739. this.toolStripContainer1.TopToolStripPanel.Padding = new Padding(0, -20/*Top*/, 0, -2/*Bottom*/);
  740. this.toolStripContainer1.TopToolStripPanel.AllowDrop = true;
  741. this.toolStripContainer1.Name = "toolStripContainer1";
  742. this.toolStripContainer1.TabIndex = 13;
  743. this.toolStripContainer1.Text = "toolStripContainer1";
  744. this.toolStripContainer1.TopToolStripPanel.SizeChanged += new System.EventHandler(this.panel1_SizeChanged);
  745. this.toolStripContainer1.ContextMenuStrip = this.contextMenuStrip;
  746. this.toolStripContainer1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.frmContextmenu_MouseClick);
  747. //
  748. // documentStrip
  749. //
  750. this.documentStrip.AutoSize = false;
  751. this.documentStrip.Name = "documentStrip";
  752. this.documentStrip.TabIndex = 5;
  753. this.documentStrip.ShowScrollButtons = true;
  754. this.documentStrip.DocumentListChanged += new EventHandler(DocumentStrip_DocumentListChanged);
  755. this.documentStrip.DocumentClicked += DocumentStrip_DocumentClicked;
  756. this.documentStrip.ManagedFocus = true;
  757. //
  758. // PdnToolBar
  759. //
  760. this.Controls.Add(this.documentStrip);
  761. //this.Controls.Add(this.toolStripPanel);
  762. this.Controls.Add(this.toolStripContainer1);
  763. this.Controls.Add(this.mainMenu);
  764. this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false);
  765. this.toolStripContainer1.TopToolStripPanel.PerformLayout();
  766. this.toolStripContainer1.ResumeLayout(false);
  767. this.toolStripContainer1.PerformLayout();
  768. this.ResumeLayout(false);
  769. }
  770. private void frmContextmenu_MouseClick(object sender, MouseEventArgs e)
  771. {
  772. if (e.Button == MouseButtons.Right)
  773. {
  774. this.contextMenuStrip.Show(MousePosition.X, MousePosition.Y);
  775. }
  776. }
  777. public void SetCustomizeTools()
  778. {
  779. if (toolbarModel == null || toolbarModel.Flows.Count == 0)
  780. {
  781. return;
  782. }
  783. int toolCount = toolbarModel.Flows.Count;
  784. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  785. {
  786. Flow flowJ = toolbarModel.Flows[j];
  787. if (flowJ.Menus.Count == 0)// || !flowJ.Show
  788. {
  789. toolCount -= 1;
  790. }
  791. }
  792. if (toolCount == 0)
  793. {
  794. return;
  795. }
  796. toolStrips = new ToolStrip[toolCount];
  797. int t = 0;
  798. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  799. {
  800. Flow flowJ = toolbarModel.Flows[j];
  801. /*if(!flowJ.Show)
  802. {
  803. continue;
  804. }*/
  805. if (flowJ.Menus.Count == 0)
  806. {
  807. continue;
  808. }
  809. ToolStrip toolStripEx = new ToolStrip();//Ex
  810. ImageList imageList = new ImageList();
  811. imageList.ColorDepth = ColorDepth.Depth32Bit;
  812. imageList.TransparentColor = Utility.TransparentKey;
  813. toolStripEx.ImageList = imageList;
  814. toolStripEx.Name = flowJ.Key;// "key_" + j;
  815. //Base.SettingModel.ToolbarLocationModel.Flow flow = toolbarLocationModel.Flows.Find(a => a.Key.Equals(flowJ.Key/*"targetProcess"*/));
  816. ////ToolbarLocationModel.Flows.Find();
  817. //int locationX = flow.X;
  818. //int locationY = flow.Y;
  819. int buttonsCount = flowJ.Menus.Count;
  820. foreach (Flow.Item item in flowJ.Menus)
  821. {
  822. //..Script
  823. if (item.Description.Equals("Script"))//脚本列表
  824. {
  825. List<mic_script> list = mic_script_BLL.FindAll();
  826. //foreach (var item in list)
  827. //{
  828. // this.listBox1.Items.Add(item.name);
  829. //}
  830. buttonsCount += (list.Count - 1);
  831. }
  832. if (item.Description.Equals("SubRulerCalibration"))//标尺标定,标尺列表
  833. {
  834. buttonsCount += 1;
  835. }
  836. }
  837. ToolStripItem[] buttons = new ToolStripItem[buttonsCount/*flowJ.Menus.Count*/];
  838. int index = 0;
  839. for (int i = 0; i < flowJ.Menus.Count; i++, index++)
  840. {
  841. ToolStripButton button = new ToolStripButton();
  842. int imageIndex = -1;
  843. if (flowJ.Menus[i].Description.Equals("SeparateLine"))
  844. {
  845. ToolStripSeparator separator0 = new ToolStripSeparator();
  846. buttons[index] = separator0;
  847. continue;
  848. }
  849. ToolStripItem[] items = this.MainMenu.Items.Find(flowJ.Menus[i].Description, true);
  850. if (items != null && items.Length > 0)
  851. {
  852. if (((PdnMenuItem)(items[0])).Image != null)
  853. imageIndex = imageList.Images.Add(((PdnMenuItem)(items[0])).Image, imageList.TransparentColor);
  854. else
  855. imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  856. button.ToolTipText = ((PdnMenuItem)(items[0])).Text;
  857. button.Text = ((PdnMenuItem)(items[0])).Text;
  858. }
  859. else
  860. {
  861. imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  862. button.ToolTipText = flowJ.Menus[i].Name;// getShowName(Program.instance.configModel.Language);
  863. button.Text = flowJ.Menus[i].Name;// getShowName(Program.instance.configModel.Language);
  864. }
  865. button.ImageIndex = imageIndex;
  866. button.Tag = flowJ.Menus[i].Description;
  867. button.TextImageRelation = TextImageRelation.ImageAboveText;
  868. //..Script
  869. if (flowJ.Menus[i].Description.Equals("Script"))//脚本列表
  870. {
  871. List<mic_script> list = mic_script_BLL.FindAll();
  872. for (int itemI = 0; itemI < list.Count - 1; itemI++)
  873. {
  874. var itemSS = list[itemI];
  875. ToolStripButton unitLabel = new ToolStripButton();
  876. unitLabel.Text = itemSS.name;
  877. unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  878. unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
  879. //unitLabel.Tag = "Script_" + itemSS.id;
  880. unitLabel.Name = "" + itemSS.id;
  881. unitLabel.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
  882. buttons[index] = unitLabel;
  883. index++;
  884. }
  885. //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  886. var item = list[list.Count - 1];
  887. ToolStripButton unitsLabel = new ToolStripButton();
  888. unitsLabel.Text = item.name;
  889. unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  890. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  891. unitsLabel.Name = "" + item.id;
  892. unitsLabel.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
  893. buttons[index] = unitsLabel;
  894. }
  895. else if (flowJ.Menus[i].Description.Equals("SubRulerCalibration"))
  896. {
  897. ToolStripLabel unitsLabel = new ToolStripLabel();
  898. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  899. unitsLabel.Text = "标尺:";
  900. unitsLabel.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
  901. buttons[index] = unitsLabel;
  902. index++;
  903. ToolStripComboBox zoomComboBox = new ToolStripComboBox();
  904. zoomComboBox.Tag = i;
  905. zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
  906. zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
  907. zoomComboBox.MaxDropDownItems = 99;
  908. zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
  909. List<mic_rulers> list = mic_rulers_BLL.FindAll();
  910. if (list != null)
  911. {
  912. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  913. {
  914. mic_rulers rule = list[ruleI];
  915. zoomComboBox.Items.Add(rule.ruler_name);
  916. if (Program.instance.configModel != null)
  917. {
  918. if (Program.instance.configModel.RulerId == rule.id)
  919. {
  920. zoomComboBox.Text = rule.ruler_name;// "newText";
  921. }
  922. }
  923. }
  924. }
  925. //if (zoomComboBox.Text == null || zoomComboBox.Text.Equals(""))
  926. //{
  927. // zoomComboBox.Text = "请选择";
  928. //}
  929. rulersComboBox.Add(zoomComboBox);
  930. zoomComboBox.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
  931. buttons[index] = zoomComboBox;
  932. zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  933. zoomComboBox.BackColor = SystemColors.Window;
  934. }
  935. else
  936. {
  937. button.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
  938. buttons[index] = button;
  939. }
  940. }
  941. toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
  942. toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
  943. toolStripEx.EndDrag += ToolStripEx_DragDrop1;
  944. toolStripEx.AllowDrop = false;
  945. toolStripEx.AllowMerge = false;
  946. toolStripEx.Height = 40;
  947. toolStripEx.Items.AddRange(buttons);
  948. toolStrips[t] = toolStripEx;
  949. toolStripEx.Visible = flowJ.Show;
  950. t++;
  951. }
  952. this.toolStripContainer1.TopToolStripPanel.ControlRemoved += TopToolStripPanel_ControlRemoved;
  953. this.toolStripContainer1.TopToolStripPanel.DragDrop += TopToolStripPanel_DragDrop;
  954. this.toolStripContainer1.TopToolStripPanel.DragLeave += TopToolStripPanel_DragLeave;
  955. }
  956. private void ZoomComboBox_SelectedIndexChanged(object sender, EventArgs e)
  957. {
  958. if (((ToolStripComboBox)sender).SelectedItem != null)
  959. {
  960. List<mic_rulers> list = Program.instance.mic_rulersAll;
  961. if (list != null)
  962. {
  963. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  964. {
  965. mic_rulers rule = list[ruleI];
  966. if (rule.ruler_name.Equals(((ToolStripComboBox)sender).SelectedItem.ToString()))
  967. {
  968. int rulid = rule.id;
  969. string rulerName2 = rule.ruler_name;
  970. if (rulid != Program.instance.configModel.RulerId)
  971. {
  972. //设置当前选中标尺
  973. this.appWorkspace.SetActiveRulerIndex(((ToolStripComboBox)sender).SelectedIndex);
  974. //int oldId = Program.instance.configModel.RulerId;
  975. ////激活当前标尺到configModel
  976. //Program.instance.configModel.RulerId = rulid;
  977. ////保存xml文件
  978. //string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(Program.instance.configModel);
  979. //string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml";
  980. //if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  981. //{
  982. // //调用startup的方法
  983. // Program.instance.InitRulerInfo();
  984. // Program.instance.InitUnitInfo();
  985. // foreach (ToolStripComboBox comboBox in rulersComboBox)
  986. // {
  987. // if (((ToolStripComboBox)sender) == comboBox)
  988. // {
  989. // continue;
  990. // }
  991. // for (int i = 0; i < comboBox.Items.Count; i++)
  992. // {
  993. // if (rulerName2.Equals(comboBox.Items[i].ToString()))
  994. // {
  995. // comboBox.SelectedIndex = i;
  996. // }
  997. // }
  998. // }
  999. // //this.appWorkspace.RefreshActiveRuler();
  1000. //}
  1001. //else
  1002. //{
  1003. // Program.instance.configModel.RulerId = oldId;
  1004. // MessageBox.Show("标尺激活失败");
  1005. //}
  1006. }
  1007. break;
  1008. }
  1009. }
  1010. }
  1011. }
  1012. }
  1013. private void ToolStripEx_DragDrop1(object sender, EventArgs e)
  1014. {
  1015. if (toolStripInitLayout < 3)//to 完善
  1016. {
  1017. return;
  1018. }
  1019. for (int i = 0; i < this.toolStripContainer1.TopToolStripPanel.Controls.Count; i++)
  1020. {
  1021. ToolStrip toolStripEx = (ToolStrip)this.toolStripContainer1.TopToolStripPanel.Controls[i];
  1022. Point point = toolStripEx.Location;
  1023. //Base.SettingModel.ToolbarLocationModel.Flow flowJ = toolbarLocationModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
  1024. Base.SettingModel.ToolbarModel.Flow flowJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
  1025. flowJ.X = point.X;
  1026. flowJ.Y = point.Y;
  1027. }
  1028. //string userInfoXml = XmlSerializeHelper.XmlSerialize(toolbarLocationModel);
  1029. string userInfoXml = XmlSerializeHelper.XmlSerialize(toolbarModel);
  1030. //string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\ToolbarLocation.xml";
  1031. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Toolbar.xml";
  1032. if (FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create))
  1033. {
  1034. //Program.instance.toolbarLocationModel = toolbarLocationModel;
  1035. Program.instance.toolbarModel = toolbarModel;
  1036. }
  1037. else
  1038. {
  1039. MessageBox.Show("工具栏坐标保存失败");
  1040. }
  1041. }
  1042. ToolStrip toolStripEx = new ToolStrip();
  1043. /// <summary>
  1044. /// 重置工具栏
  1045. /// </summary>
  1046. public void ResetCustomizeTools()
  1047. {
  1048. this.toolbarModel = Program.instance.toolbarModel;
  1049. if (toolbarModel == null || toolbarModel.Flows.Count == 0)
  1050. {
  1051. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  1052. return;
  1053. }
  1054. int toolCount = toolbarModel.Flows.Count;
  1055. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  1056. {
  1057. Flow flowJ = toolbarModel.Flows[j];
  1058. if (flowJ.Menus.Count == 0)
  1059. {
  1060. toolCount -= 1;
  1061. }
  1062. }
  1063. if (toolCount == 0)
  1064. {
  1065. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  1066. return;
  1067. }
  1068. toolStrips = new ToolStrip[toolCount];
  1069. int t = 0;
  1070. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  1071. {
  1072. Flow flowJ = toolbarModel.Flows[j];
  1073. if (flowJ.Menus.Count == 0)
  1074. {
  1075. continue;
  1076. }
  1077. ToolStrip toolStripEx = new ToolStrip();
  1078. ImageList imageList = new ImageList();
  1079. imageList.ColorDepth = ColorDepth.Depth32Bit;
  1080. imageList.TransparentColor = Utility.TransparentKey;
  1081. toolStripEx.ImageList = imageList;
  1082. toolStripEx.Name = flowJ.Key;
  1083. int buttonsCount = flowJ.Menus.Count;
  1084. foreach (Flow.Item item in flowJ.Menus)
  1085. {
  1086. if (item.Description.Equals("Script"))//脚本列表
  1087. {
  1088. List<mic_script> list = mic_script_BLL.FindAll();
  1089. buttonsCount += (list.Count - 1);
  1090. }
  1091. if (item.Description.Equals("SubRulerCalibration"))//标尺标定,标尺列表
  1092. {
  1093. buttonsCount += 1;
  1094. }
  1095. }
  1096. ToolStripItem[] buttons = new ToolStripItem[buttonsCount/*flowJ.Menus.Count*/];
  1097. int index = 0;
  1098. for (int i = 0; i < flowJ.Menus.Count; i++, index++)
  1099. {
  1100. ToolStripButton button = new ToolStripButton();
  1101. int imageIndex = -1;
  1102. if (flowJ.Menus[i].Description.Equals("SeparateLine"))
  1103. {
  1104. ToolStripSeparator separator0 = new ToolStripSeparator();
  1105. buttons[index] = separator0;
  1106. continue;
  1107. }
  1108. ToolStripItem[] items = this.MainMenu.Items.Find(flowJ.Menus[i].Description, true);
  1109. if (items != null && items.Length > 0)
  1110. {
  1111. if (((PdnMenuItem)(items[0])).Image != null)
  1112. imageIndex = imageList.Images.Add(((PdnMenuItem)(items[0])).Image, imageList.TransparentColor);
  1113. else
  1114. imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  1115. button.ToolTipText = ((PdnMenuItem)(items[0])).Text;
  1116. button.Text = ((PdnMenuItem)(items[0])).Text;
  1117. }
  1118. else
  1119. {
  1120. imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  1121. button.ToolTipText = flowJ.Menus[i].Name;// .getShowName(Program.instance.configModel.Language);
  1122. button.Text = flowJ.Menus[i].Name;// .getShowName(Program.instance.configModel.Language);
  1123. }
  1124. button.ImageIndex = imageIndex;
  1125. button.Tag = flowJ.Menus[i].Description;
  1126. button.TextImageRelation = TextImageRelation.ImageAboveText;
  1127. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  1128. {
  1129. if (button.Tag.ToString().Equals(this.type))
  1130. button.Checked = this.check;
  1131. }
  1132. //..Script
  1133. if (flowJ.Menus[i].Description.Equals("Script"))//脚本列表
  1134. {
  1135. List<mic_script> list = mic_script_BLL.FindAll();
  1136. for (int itemI = 0; itemI < list.Count - 1; itemI++)
  1137. {
  1138. var itemSS = list[itemI];
  1139. ToolStripButton unitLabel = new ToolStripButton();
  1140. unitLabel.Text = itemSS.name;
  1141. unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  1142. unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
  1143. //unitLabel.Tag = "Script_" + itemSS.id;
  1144. unitLabel.Name = "" + itemSS.id;
  1145. buttons[index] = unitLabel;
  1146. index++;
  1147. }
  1148. //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  1149. var item = list[list.Count - 1];
  1150. ToolStripButton unitsLabel = new ToolStripButton();
  1151. unitsLabel.Text = item.name;
  1152. unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  1153. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  1154. unitsLabel.Name = "" + item.id;
  1155. buttons[index] = unitsLabel;
  1156. }
  1157. else if (flowJ.Menus[i].Description.Equals("SubRulerCalibration"))
  1158. {
  1159. ToolStripLabel unitsLabel = new ToolStripLabel();
  1160. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  1161. unitsLabel.Text = "标尺:";
  1162. buttons[index] = unitsLabel;
  1163. index++;
  1164. ToolStripComboBox zoomComboBox = new ToolStripComboBox();
  1165. zoomComboBox.Tag = i;
  1166. zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
  1167. zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
  1168. zoomComboBox.MaxDropDownItems = 99;
  1169. zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
  1170. List<mic_rulers> list = mic_rulers_BLL.FindAll();
  1171. if (list != null)
  1172. {
  1173. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  1174. {
  1175. mic_rulers rule = list[ruleI];
  1176. zoomComboBox.Items.Add(rule.ruler_name);
  1177. if (Program.instance.configModel != null)
  1178. {
  1179. if (Program.instance.configModel.RulerId == rule.id)
  1180. {
  1181. zoomComboBox.Text = rule.ruler_name;// "newText";
  1182. }
  1183. }
  1184. }
  1185. }
  1186. rulersComboBox.Add(zoomComboBox);
  1187. buttons[index] = zoomComboBox;
  1188. zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  1189. zoomComboBox.BackColor = SystemColors.Window;
  1190. }
  1191. else
  1192. {
  1193. buttons[index] = button;
  1194. }
  1195. }
  1196. toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
  1197. toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
  1198. toolStripEx.EndDrag += ToolStripEx_DragDrop1;
  1199. toolStripEx.AllowDrop = false;
  1200. toolStripEx.AllowMerge = false;
  1201. toolStripEx.Height = 40;
  1202. toolStripEx.Items.AddRange(buttons);
  1203. toolStrips[t] = toolStripEx;
  1204. toolStripEx.Visible = flowJ.Show;
  1205. t++;
  1206. }
  1207. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  1208. this.toolStripContainer1.TopToolStripPanel.Controls.AddRange(toolStrips);
  1209. }
  1210. private string type;
  1211. private bool check;
  1212. /// <summary>
  1213. /// 连续绘制联动
  1214. /// </summary>
  1215. /// <param name="check">是否选择</param>
  1216. /// <param name="type">0:标注 1:测量</param>
  1217. public void RefreshBtnSelect(bool check, string type)
  1218. {
  1219. this.type = type;
  1220. this.check = check;
  1221. if (toolStrips == null)
  1222. return;
  1223. for (int i = 0; i < toolStrips.Length; i++)
  1224. {
  1225. for (int j = 0; j < toolStrips[i].Items.Count; j++)
  1226. {
  1227. if (toolStrips[i].Items[j] is ToolStripButton && ((ToolStripButton)toolStrips[i].Items[j]).Tag != null && ((ToolStripButton)toolStrips[i].Items[j]).Tag.ToString().Equals(type))
  1228. ((ToolStripButton)toolStrips[i].Items[j]).Checked = check;
  1229. }
  1230. }
  1231. this.Refresh();
  1232. }
  1233. private void TopToolStripPanel_DragLeave(object sender, EventArgs e)
  1234. {
  1235. //throw new NotImplementedException();
  1236. }
  1237. private void TopToolStripPanel_DragDrop(object sender, DragEventArgs e)
  1238. {
  1239. //throw new NotImplementedException();
  1240. }
  1241. private void TopToolStripPanel_ControlRemoved(object sender, ControlEventArgs e)
  1242. {
  1243. //throw new NotImplementedException();
  1244. }
  1245. private void ToolStripEx_ItemRemoved(object sender, ToolStripItemEventArgs e)
  1246. {
  1247. //throw new NotImplementedException();
  1248. }
  1249. /// <summary>
  1250. /// 递归查找菜单,暂时不用,改成直接用name查找
  1251. /// </summary>
  1252. /// <param name="collection"></param>
  1253. /// <param name="step"></param>
  1254. private void RecursiveData(ToolStripItemCollection collection, mic_script_step step)
  1255. {
  1256. for (int i = 0; i < collection.Count; i++)
  1257. {
  1258. if (!collection[i].Name.Equals("OpenRecent") && !collection[i].Name.Equals("CameraSelection"))
  1259. {
  1260. if (collection[i].GetType() != typeof(ToolStripSeparator))
  1261. {
  1262. if (step.menu_id == ((PdnMenuItem)collection[i]).MenuId)
  1263. {
  1264. ((PdnMenuItem)collection[i]).PerformClick();
  1265. }
  1266. RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, step);
  1267. }
  1268. }
  1269. }
  1270. }
  1271. /// <summary>
  1272. /// 脚本按钮点击方法
  1273. /// </summary>
  1274. /// <param name="sender"></param>
  1275. /// <param name="e"></param>
  1276. private void ToolStripEx_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  1277. {
  1278. if (e.ClickedItem.GetType() != typeof(ToolStripButton))
  1279. {
  1280. return;
  1281. }
  1282. //if (e.ClickedItem.Tag == null)
  1283. //{
  1284. // //获取当前选中的脚本步骤
  1285. // List<mic_script_step> steps = mic_script_step_BLL.FindAllByScripId(int.Parse(e.ClickedItem.Name)/*list[this.listBox1.SelectedIndex].id*/);
  1286. // //this.WindowState = FormWindowState.Minimized;
  1287. // //循环脚本步骤
  1288. // foreach (mic_script_step step in steps)
  1289. // {
  1290. // //递归的方式
  1291. // this.RecursiveData(this.appWorkspace.ToolBar.MainMenu.Items/*this.collection*/, step);
  1292. // }
  1293. // return;
  1294. //}
  1295. //e.ClickedItem.Visible = false;
  1296. ToolStripItem[] menu = this.appWorkspace.ToolBar.MainMenu.Items.Find(e.ClickedItem.Tag.ToString(), true);
  1297. if (menu != null && menu.Length > 0)
  1298. {
  1299. if (((PdnMenuItem)menu[0]).canChecked)
  1300. ((ToolStripButton)e.ClickedItem).Checked = !((ToolStripButton)e.ClickedItem).Checked;
  1301. ((PdnMenuItem)menu[0]).PerformClick();
  1302. appWorkspace.UpdateBottomButtonSelectionStatus();
  1303. }
  1304. }
  1305. private void panel1_SizeChanged(object sender, EventArgs e)
  1306. {
  1307. this.toolStripContainer1.Height = this.toolStripContainer1.TopToolStripPanel.Height + 1;
  1308. }
  1309. private void DocumentStrip_DocumentClicked(object sender, EventArgs<Pair<DocumentWorkspace, DocumentClickAction>> e)
  1310. {
  1311. if (e.Data.Second == DocumentClickAction.Select)
  1312. {
  1313. PerformLayout();
  1314. }
  1315. }
  1316. private void DocumentStrip_DocumentListChanged(object sender, EventArgs e)
  1317. {
  1318. PerformLayout();
  1319. if (this.documentStrip.DocumentCount == 0)
  1320. {
  1321. //this.viewConfigStrip.Enabled = false;
  1322. //this.toolChooserStrip.Enabled = false;
  1323. }
  1324. else
  1325. {
  1326. //this.viewConfigStrip.Enabled = true;
  1327. //this.toolChooserStrip.Enabled = true;
  1328. }
  1329. }
  1330. /// <summary>
  1331. /// 用于ctrl+双击复制
  1332. /// </summary>
  1333. public void CopyAndPasteByControlAndDoubleClick()
  1334. {
  1335. //ToolStripItem[] menu = this.MainMenu.Items.Find(PdnMenuItem.GetDescription(ActionType.Copy), true);
  1336. //ToolStripItem[] menu1 = this.MainMenu.Items.Find(PdnMenuItem.GetDescription(ActionType.Paste), true);
  1337. //if (menu != null && menu1 != null && menu.Length > 0 && menu1.Length > 0)
  1338. //{
  1339. // ((PdnMenuItem)menu[0]).PerformClick();
  1340. // ((PdnMenuItem)menu1[0]).PerformClick();
  1341. //}
  1342. ControlAnd(CopyAndPasteBy());
  1343. }
  1344. /// <summary>
  1345. /// 复制剪裁图片
  1346. /// </summary>
  1347. /// <returns></returns>
  1348. public Bitmap CopyAndPasteBy()
  1349. {
  1350. if (AppWorkspace.ActiveDocumentWorkspace != null && AppWorkspace.ActiveDocumentWorkspace.CompositionSurface != null)
  1351. {
  1352. Bitmap temp = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  1353. copyedBitmap = new Bitmap(temp.Width, temp.Height);
  1354. Graphics graphics = Graphics.FromImage(copyedBitmap);
  1355. graphics.DrawImage(temp, 0, 0, temp.Width, temp.Height);
  1356. //if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList.IsExsitSpecificObject(DrawToolType.ImageCut))
  1357. //{
  1358. // //获取裁剪的矩形区域
  1359. // List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.ImageCut);
  1360. // ImageCutDraw imageCutDraw = (ImageCutDraw)objList[0];
  1361. // RectangleF cutRectangle = imageCutDraw.Rectangle;
  1362. // copyedBitmap = DrawRulerHelper.KiCut(copyedBitmap, (int)cutRectangle.X, (int)cutRectangle.Y, (int)cutRectangle.Width, (int)cutRectangle.Height);
  1363. //}
  1364. }
  1365. return copyedBitmap;
  1366. }
  1367. /// <summary>
  1368. /// 粘贴剪裁图片
  1369. /// </summary>
  1370. /// <param name="copyedBitmap"></param>
  1371. public void ControlAnd(Bitmap copyedBitmap)
  1372. {
  1373. //if (copyedBitmap != null)
  1374. //{
  1375. // DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  1376. // Document document = Document.FromImage(copyedBitmap);
  1377. // dw.Document = document;
  1378. // dw.xmlSaveModel = AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  1379. // dw.rules = AppWorkspace.ActiveDocumentWorkspace.rules;
  1380. // //图片命名
  1381. // nameNum++;
  1382. // int numLength = nameNum.ToString().Length;
  1383. // string joinName = "";
  1384. // switch (numLength)
  1385. // {
  1386. // case 1:
  1387. // joinName = "00" + nameNum;
  1388. // break;
  1389. // case 2:
  1390. // joinName = "0" + nameNum;
  1391. // break;
  1392. // default:
  1393. // joinName = nameNum.ToString();
  1394. // break;
  1395. // }
  1396. // dw.fileText = PdnResources.GetString("Menu.Copythepicture.Text") + "-" + joinName;
  1397. // AppWorkspace.ActiveDocumentWorkspace = dw;
  1398. //}
  1399. }
  1400. }
  1401. }