12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526 |
- using SmartCoalApplication.Base;
- using SmartCoalApplication.Base.CommTool;
- using SmartCoalApplication.Base.Enum;
- using SmartCoalApplication.Base.SettingModel;
- using SmartCoalApplication.Core;
- using SmartCoalApplication.Core.DbOpreate.DbBll;
- using SmartCoalApplication.Core.DbOpreate.DbModel;
- using SmartCoalApplication.Menus;
- using SmartCoalApplication.SystemLayer;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Windows.Forms;
- using static SmartCoalApplication.Base.SettingModel.ToolbarModel;
- namespace SmartCoalApplication
- {
- internal class PdnToolBar : Control, IPaintBackground
- {
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 主菜单
- /// </summary>
- private PdnMainMenu mainMenu;
- /// <summary>
- /// 自定义工具栏
- /// </summary>
- private ToolStripContainer toolStripContainer1;
- /// <summary>
- /// 自定义工具栏上的右键菜单
- /// </summary>
- private ContextMenuStrip contextMenuStrip;
- public ToolStrip[] toolStrips;
- private List<ToolStripComboBox> rulersComboBox = new List<ToolStripComboBox>();
- /// <summary>
- /// 工具栏
- /// </summary>
- private ToolbarModel toolbarModel = Program.instance.toolbarModel;
- private int toolStripInitLayout = 10;
- /// <summary>
- /// 目前被改成tab的菜单了
- /// </summary>
- private OurDocumentStrip documentStrip;
- private OurToolStripRenderer otsr = new OurToolStripRenderer();
- private Bitmap copyedBitmap;//复制的图片
- private int nameNum = 0;//命名使用
- private class OurToolStripRenderer :
- ToolStripProfessionalRenderer
- {
- public OurToolStripRenderer()
- {
- RoundedEdges = false;
- }
- private void PaintBackground(Graphics g, Control control, Rectangle clipRect)
- {
- Control parent = control;
- IPaintBackground asIpb = null;
- while (true)
- {
- parent = parent.Parent;
- if (parent == null)
- {
- break;
- }
- asIpb = parent as IPaintBackground;
- if (asIpb != null)
- {
- break;
- }
- }
- if (asIpb != null)
- {
- Rectangle screenRect = control.RectangleToScreen(clipRect);
- Rectangle parentRect = parent.RectangleToClient(screenRect);
- int dx = parentRect.Left - clipRect.Left;
- int dy = parentRect.Top - clipRect.Top;
- g.TranslateTransform(-dx, -dy, MatrixOrder.Append);
- asIpb.PaintBackground(g, parentRect);
- g.TranslateTransform(dx, dy, MatrixOrder.Append);
- }
- }
- protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e)
- {
- PaintBackground(e.Graphics, e.ToolStripPanel, new Rectangle(new Point(0, 0), e.ToolStripPanel.Size));
- e.Handled = true;
- }
- protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
- {
- if (e.ToolStrip.GetType() != typeof(ToolStrip) &&
- e.ToolStrip.GetType() != typeof(ToolStripEx) &&
- e.ToolStrip.GetType() != typeof(PdnMainMenu))
- {
- base.OnRenderToolStripBackground(e);
- }
- else
- {
- PaintBackground(e.Graphics, e.ToolStrip, e.AffectedBounds);
- }
- }
- }
- private class OurDocumentStrip : DocumentStrip, IPaintBackground
- {
- public OurDocumentStrip(AppWorkspace appWorkspace) : base(appWorkspace)
- {
- }
- protected override void DrawItemBackground(Graphics g, Item item, Rectangle itemRect)
- {
- PaintBackground(g, itemRect);
- /**
- if (item.Image != null)
- {
- g.DrawImage(item.Image, new Point(0, 0));
- }
- else
- {
- PaintBackground(g, itemRect);
- }**/
- }
- public void PaintBackground(Graphics g, Rectangle clipRect)
- {
- IPaintBackground asIpb = this.Parent as IPaintBackground;
- if (asIpb != null)
- {
- Rectangle newClipRect = new Rectangle(
- clipRect.Left + Left, clipRect.Top + Top,
- clipRect.Width, clipRect.Height);
- g.TranslateTransform(-Left, -Top, MatrixOrder.Append);
- asIpb.PaintBackground(g, newClipRect);
- g.TranslateTransform(Left, Top, MatrixOrder.Append);
- }
- }
- }
- public void PaintBackground(Graphics g, Rectangle clipRect)
- {
- if (clipRect.Width > 0 && clipRect.Height > 0)
- {
- Color backColor = ProfessionalColors.MenuStripGradientEnd;
- using (SolidBrush brush = new SolidBrush(backColor))
- {
- g.FillRectangle(brush, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
- }
- }
- }
- public AppWorkspace AppWorkspace
- {
- get
- {
- return this.appWorkspace;
- }
- set
- {
- this.appWorkspace = value;
- this.mainMenu.AppWorkspace = value;
- }
- }
- public PdnMainMenu MainMenu
- {
- get
- {
- return this.mainMenu;
- }
- }
- public DocumentStrip DocumentStrip
- {
- get
- {
- return this.documentStrip;
- }
- }
- public PdnToolBar(AppWorkspace appWorkspace)
- {
- this.appWorkspace = appWorkspace;
- SuspendLayout();
- InitializeComponent();
- InitializeContextMenuStrip();
- this.otsr = new OurToolStripRenderer();
- this.mainMenu.Renderer = otsr;
- ResumeLayout(true);
- }
- public void InitializeContextMenuStrip()
- {
- this.contextMenuStrip.Items.Clear();
- foreach (Flow flow in Program.instance.toolbarModel.Flows)
- {
- ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
- toolStripMenuItem.Text = flow.Name;
- toolStripMenuItem.Checked = flow.Show;
- this.contextMenuStrip.Items.Add(toolStripMenuItem);
- }
- }
- private void contextMenuStripItem_Click(object sender, ToolStripItemClickedEventArgs e)
- {
- bool ShowFlag = !((ToolStripMenuItem)e.ClickedItem).Checked;
- ((ToolStripMenuItem)e.ClickedItem).Checked = ShowFlag;
- Flow flow = Program.instance.toolbarModel.Flows.Find(a => a.Name.Equals(e.ClickedItem.Text));
- if (flow != null)
- {
- flow.Show = ShowFlag;
- string userInfoXml = XmlSerializeHelper.XmlSerialize<ToolbarModel>(Program.instance.toolbarModel);
- string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Toolbar.xml";
- FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
- Control[] control = this.toolStripContainer1.TopToolStripPanel.Controls.Find(flow.Key, true);
- if (control != null && control.Length > 0)
- {
- control[0].Visible = ShowFlag;
- }
- }
- }
- /// <summary>
- /// 刷新自定义工具栏的列表内容-标尺标定
- /// </summary>
- public void refreshRulersComboBoxList()//###2
- {
- List<mic_rulers> list = Program.instance.mic_rulersAll;
- string rulerName = "";
- if (list != null)
- {
- for (int ruleI = 0; ruleI < list.Count; ruleI++)
- {
- mic_rulers rule = list[ruleI];
- int rulid = rule.id;
- if (rulid == Program.instance.configModel.RulerId)
- {
- rulerName = rule.ruler_name;
- break;
- }
- }
- }
- foreach (ToolStripComboBox comboBox in rulersComboBox)
- {
- comboBox.Items.Clear();
- if (list != null)
- {
- for (int ruleI = 0; ruleI < list.Count; ruleI++)
- {
- mic_rulers rule = list[ruleI];
- comboBox.Items.Add(rule.ruler_name);
- //if (Program.instance.configModel != null)
- //{
- // if (Program.instance.configModel.RulerId == rule.id)
- // {
- // zoomComboBox.Text = rule.ruler_name;// "newText";
- // }
- //}
- }
- }
- else
- continue;
- for (int i = 0; i < comboBox.Items.Count; i++)
- {
- if (rulerName.Equals(comboBox.Items[i].ToString()))
- {
- comboBox.SelectedIndex = i;
- }
- }
- }
- }
- /// <summary>
- /// 刷新自定义工具栏的激活标尺-标尺标定
- /// </summary>
- public void refreshRulersComboBoxActive()//###1
- {
- foreach (ToolStripComboBox comboBox in rulersComboBox)
- {
- string rulerName = "";
- List<mic_rulers> list = Program.instance.mic_rulersAll;
- if (list != null)
- {
- for (int ruleI = 0; ruleI < list.Count; ruleI++)
- {
- mic_rulers rule = list[ruleI];
- int rulid = rule.id;
- if (rulid == Program.instance.configModel.RulerId)
- {
- rulerName = rule.ruler_name;
- break;
- }
- }
- }
- for (int i = 0; i < comboBox.Items.Count; i++)
- {
- if (rulerName.Equals(comboBox.Items[i].ToString()))
- {
- comboBox.SelectedIndex = i;
- }
- }
- this.AppWorkspace.Widgets.RuleListForm.MenuSubApplyCurrent();
- }
- }
- /// <summary>
- /// 布局自定义工具栏
- /// </summary>
- /// <param name="toReset"></param>
- /// <param name="refreshFlag">1 添加 2删除 3移出 4向上移动 5向下移动 6添加分割线【 7添加新的节点】</param>
- public void test1(bool toReset, int refreshFlag = 0, string toolStripContrainerName = null, int toolStripItemIndex = 0, string nodeName = null, string nodeText = null, int nodeTag = 0)
- {
- if (toReset && refreshFlag > 0 && refreshFlag < 7)
- {
- this.toolbarModel = Program.instance.toolbarModel;
- if (toolbarModel == null || toolbarModel.Flows.Count == 0)
- {
- this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
- return;
- }
- int toolCount = toolbarModel.Flows.Count;
- for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
- {
- Flow flowJ = toolbarModel.Flows[j];
- if (flowJ.Menus.Count == 0)
- {
- toolCount -= 1;
- }
- }
- if (toolCount == 0)
- {
- this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
- return;
- }
- bool addSuccess = false;
- foreach (ToolStrip toolStripContrainer in this.toolStripContainer1.TopToolStripPanel.Controls)
- {
- if (toolStripContrainer.Name.Equals(toolStripContrainerName))
- {
- if (refreshFlag == 6)// 6添加分割线
- {
- ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count + 1];
- for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
- {
- if (itemIndex < toolStripItemIndex)
- buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
- else if (itemIndex == toolStripItemIndex)
- {
- buttons[itemIndex] = new ToolStripSeparator();
- buttons[itemIndex + 1] = toolStripContrainer.Items[itemIndex];
- }
- else
- buttons[itemIndex + 1] = toolStripContrainer.Items[itemIndex];
- }
- toolStripContrainer.Items.Clear();
- toolStripContrainer.Items.AddRange(buttons);
- }
- else if (refreshFlag == 1)// 1 添加
- {
- addSuccess = true;
- //this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripContrainer);
- int toAddCount = 1;
- if (nodeName.Equals("Script"))//脚本列表
- {
- List<mic_script> list = mic_script_BLL.FindAll();
- toAddCount += (list.Count - 1);
- }
- else if (nodeName.Equals("SubRulerCalibration"))
- {
- toAddCount += 1;
- }
- ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count + toAddCount];
- for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
- {
- buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
- }
- int i = toolStripContrainer.Items.Count;
- int index = toolStripContrainer.Items.Count;// 0;
- {
- ToolStripButton button = new ToolStripButton();
- int imageIndex = -1;
- //if (flowJ.Menus[i].Description.Equals("SeparateLine"))
- //{
- // ToolStripSeparator separator0 = new ToolStripSeparator();
- // buttons[index] = separator0;
- // continue;
- //}
- ToolStripItem[] items = this.MainMenu.Items.Find(nodeName, true);
- if (items != null && items.Length > 0)
- {
- if (((PdnMenuItem)(items[0])).Image != null)
- imageIndex = toolStripContrainer.ImageList.Images.Add(((PdnMenuItem)(items[0])).Image, toolStripContrainer.ImageList.TransparentColor);
- else
- imageIndex = toolStripContrainer.ImageList.Images.Add(new Bitmap(16, 16), toolStripContrainer.ImageList.TransparentColor);
- }
- else
- {
- imageIndex = toolStripContrainer.ImageList.Images.Add(new Bitmap(16, 16), toolStripContrainer.ImageList.TransparentColor);
- }
- button.ImageIndex = imageIndex;
- button.Tag = nodeName;// flowJ.Menus[i].Description;
- button.ToolTipText = nodeText;// flowJ.Menus[i].Name;
- button.Text = nodeText;// flowJ.Menus[i].Name;
- button.TextImageRelation = TextImageRelation.ImageAboveText;
- //..Script
- if (nodeName.Equals("Script"))//脚本列表
- {
- List<mic_script> list = mic_script_BLL.FindAll();
- for (int itemI = 0; itemI < list.Count - 1; itemI++)
- {
- var itemSS = list[itemI];
- ToolStripButton unitLabel = new ToolStripButton();
- unitLabel.Text = itemSS.name;
- unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
- unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
- //unitLabel.Tag = "Script_" + itemSS.id;
- unitLabel.Name = "" + itemSS.id;
- buttons[index] = unitLabel;
- index++;
- }
- //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
- var item = list[list.Count - 1];
- ToolStripButton unitsLabel = new ToolStripButton();
- unitsLabel.Text = item.name;
- unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
- unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
- unitsLabel.Name = "" + item.id;
- buttons[index] = unitsLabel;
- }
- else if (nodeName.Equals("SubRulerCalibration"))
- {
- ToolStripLabel unitsLabel = new ToolStripLabel();
- unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
- unitsLabel.Text = "标尺:";
- buttons[index] = unitsLabel;
- index++;
- ToolStripComboBox zoomComboBox = new ToolStripComboBox();
- zoomComboBox.Tag = i;
- zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
- zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
- zoomComboBox.MaxDropDownItems = 99;
- zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
- List<mic_rulers> list = mic_rulers_BLL.FindAll();
- if (list != null)
- {
- for (int ruleI = 0; ruleI < list.Count; ruleI++)
- {
- mic_rulers rule = list[ruleI];
- zoomComboBox.Items.Add(rule.ruler_name);
- if (Program.instance.configModel != null)
- {
- if (Program.instance.configModel.RulerId == rule.id)
- {
- zoomComboBox.Text = rule.ruler_name;// "newText";
- }
- }
- }
- }
- //if (zoomComboBox.Text == null || zoomComboBox.Text.Equals(""))
- //{
- // zoomComboBox.Text = "请选择";
- //}
- rulersComboBox.Add(zoomComboBox);
- buttons[index] = zoomComboBox;
- zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- zoomComboBox.BackColor = SystemColors.Window;
- }
- else
- {
- buttons[index] = button;
- }
- }
- //toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
- //toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
- //toolStripEx.EndDrag += ToolStripEx_DragDrop1;
- //toolStripEx.AllowDrop = false;
- //toolStripEx.AllowMerge = false;
- //toolStripEx.Height = 40;
- //toolStripEx.Items.AddRange(buttons);
- toolStripContrainer.Items.Clear();
- toolStripContrainer.Items.AddRange(buttons);
- appWorkspace.SetTopLeftCheckState();
- }
- else if (refreshFlag == 2)// 2删除
- {
- this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripContrainer);
- }
- else if (refreshFlag == 3)// 3移出
- {
- if (toolStripItemIndex > 0 && toolStripContrainer.Items.Count > toolStripItemIndex)
- {
- for (int itemIndex = 0; itemIndex < toolStripItemIndex/*toolStripContrainer.Items.Count*/; itemIndex++)
- {
- //#######################################
- }
- }
- //int toAddCount = 1;
- //if (nodeName.Equals("Script"))//脚本列表
- //{
- // List<mic_script> list = mic_script_BLL.FindAll();
- // toAddCount += (list.Count - 1);
- //}
- //else if (nodeName.Equals("SubRulerCalibration"))
- //{
- // toAddCount += 1;
- //}
- //ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count + toAddCount];
- if (toolStripContrainer.Items.Count > toolStripItemIndex)
- toolStripContrainer.Items.RemoveAt(toolStripItemIndex);
- if (toolStripContrainer.Items.Count == 0)
- this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripContrainer);
- }
- else if (refreshFlag == 4)// 4向上移动
- {
- //if (toolStripContrainer.Items.Count > toolStripItemIndex)
- // toolStripContrainer.Items.RemoveAt(toolStripItemIndex);
- if (toolStripItemIndex > 0 && toolStripContrainer.Items.Count > toolStripItemIndex)
- {
- ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count];
- for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
- {
- if (itemIndex == toolStripItemIndex)
- {
- buttons[toolStripItemIndex] = toolStripContrainer.Items[toolStripItemIndex - 1];
- }
- else if (itemIndex == toolStripItemIndex - 1)
- {
- buttons[toolStripItemIndex - 1] = toolStripContrainer.Items[toolStripItemIndex];
- }
- else
- {
- buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
- }
- }
- //ToolStripItem preStripItem = toolStripContrainer.Items[toolStripItemIndex - 1];
- //toolStripContrainer.Items.Insert(toolStripItemIndex + 1, preStripItem);
- //toolStripContrainer.Items.RemoveAt(toolStripItemIndex - 1);
- toolStripContrainer.Items.Clear();
- toolStripContrainer.Items.AddRange(buttons);
- }
- //int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
- //if (index > 0)
- //{
- // TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.PrevNode.Clone();
- // this.treeViewLeft.SelectedNode.Parent.Nodes.Insert(index + 1, prenode);
- // this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.PrevNode);
- //}
- }
- else if (refreshFlag == 5)// 5向下移动
- {
- if (toolStripItemIndex < toolStripContrainer.Items.Count - 1 && toolStripContrainer.Items.Count > toolStripItemIndex)
- {
- ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count];
- for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
- {
- if (itemIndex == toolStripItemIndex)
- {
- buttons[toolStripItemIndex] = toolStripContrainer.Items[toolStripItemIndex + 1];
- }
- else if (itemIndex == toolStripItemIndex + 1)
- {
- buttons[toolStripItemIndex + 1] = toolStripContrainer.Items[toolStripItemIndex];
- }
- else
- {
- buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
- }
- }
- toolStripContrainer.Items.Clear();
- toolStripContrainer.Items.AddRange(buttons);
- }
- }
- break;
- }
- }
- if (!addSuccess && refreshFlag == 1)// 1 添加
- {
- addSuccess = true;
- }
- else
- return;
- }
- if (toReset)
- {
- this.toolStripContainer1.TopToolStripPanel.ControlRemoved -= TopToolStripPanel_ControlRemoved;
- this.toolStripContainer1.TopToolStripPanel.DragDrop -= TopToolStripPanel_DragDrop;
- this.toolStripContainer1.TopToolStripPanel.DragLeave -= TopToolStripPanel_DragLeave;
- toolbarModel = Program.instance.toolbarModel;
- }
- this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
- this.toolStripContainer1.SuspendLayout();
- this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
- this.toolStripContainer1.LeftToolStripPanel.SuspendLayout();
- this.toolStripContainer1.RightToolStripPanel.SuspendLayout();
- this.toolStripContainer1.BottomToolStripPanel.SuspendLayout();
- if (this.toolStripContainer1.TopToolStripPanel.Controls.Count == 0)
- SetCustomizeTools();
- //先将location值不为-100的菜单显示出来(初始值设置-100)
- int heightRow = 0;// -1;// 0;
- int widthRow1 = 0;// -1;// 0;
- //for (int j = 0; j < Program.instance.toolbarLocationModel.Flows.Count; j++)
- for (int j = 0; j < Program.instance.toolbarModel.Flows.Count; j++)
- {
- //ToolbarLocationModel.Flow flowJ = Program.instance.toolbarLocationModel.Flows[j];
- ToolbarModel.Flow flowJ = Program.instance.toolbarModel.Flows[j];
- if (flowJ.X > -100 && flowJ.Y > -100)
- {
- if (flowJ.Y > heightRow || (flowJ.Y == heightRow && flowJ.X >= widthRow1))
- {
- Control[] toolStripTemp = /*(ToolStrip[])*/this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true);
- //ToolStrip toolStripEx = (ToolStrip)this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true)[0];
- if (toolStripTemp != null && toolStripTemp.Length > 0/*toolStripEx == null*/)
- {
- ToolStrip toolStripEx = (ToolStrip)toolStripTemp[0];
- heightRow = flowJ.Y;
- widthRow1 = flowJ.X + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
- }
- else
- {
- if (toolStrips != null && toolStrips.Length > 0)
- {
- ToolStrip toolStripEx = new List<ToolStrip>(toolStrips).Find(a => a.Name.Equals(flowJ.Key));// toolStrips.Find(a => a.Key.Equals(toolStripEx.Name));
- if (toolStripEx != null)
- {
- heightRow = flowJ.Y;
- widthRow1 = flowJ.X + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
- continue;
- }
- }
- heightRow = flowJ.Y;
- widthRow1 = flowJ.X + 1;
- }
- }
- }
- }
- if (toolStrips != null && toolStrips.Length > 0)
- {
- for (int j = 0; j < toolStrips.Length; j++)
- {
- //Base.SettingModel.ToolbarLocationModel.Flow flowJ = toolbarLocationModel.Flows.Find(a => a.Key.Equals(toolStrips[j].Name));
- Base.SettingModel.ToolbarModel.Flow flowJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStrips[j].Name));
- if (flowJ.X == -100 || flowJ.Y == -100)
- {
- if (widthRow1 < ClientSize.Width || ClientSize.Width == 0)
- {
- toolStrips[j].Location = new Point(widthRow1/*lastToolStripEx.Right + 1*/, heightRow/*lastToolStripEx.Top*/);
- widthRow1 = widthRow1 + toolStrips[j].PreferredSize.Width + toolStrips[j].Margin.Horizontal + 1;
- }
- else
- {
- heightRow += 40;// 38;// 39;
- toolStrips[j].Location = new Point(0, heightRow/*lastToolStripEx.Bottom*/);
- widthRow1 = 0/*toolStripEx.Left*/ + toolStrips[j].PreferredSize.Width + toolStrips[j].Margin.Horizontal;
- }
- }
- else
- {
- toolStrips[j].Location = new Point(flowJ.X, flowJ.Y);
- }
- }
- }
- if (this.toolStripContainer1.TopToolStripPanel.Controls.Count == 0 && toolStrips != null)//数组的判定条件为后添加,不确定是否正确8.12
- this.toolStripContainer1.TopToolStripPanel.Controls.AddRange(toolStrips);
- this.toolStripContainer1.TopToolStripPanel.ResumeLayout();
- this.toolStripContainer1.LeftToolStripPanel.ResumeLayout();
- this.toolStripContainer1.RightToolStripPanel.ResumeLayout();
- this.toolStripContainer1.BottomToolStripPanel.ResumeLayout();
- this.toolStripContainer1.ResumeLayout();
- }
- protected override void OnLayout(LayoutEventArgs e)
- {
- bool plentyWidthBefore = (this.mainMenu.Width >= this.mainMenu.PreferredSize.Width);
- if (!plentyWidthBefore)
- {
- UI.SuspendControlPainting(this);
- }
- else
- {
- UI.SuspendControlPainting(this.documentStrip);
- }
- this.mainMenu.Location = new Point(0, 0);
- this.mainMenu.Height = this.mainMenu.PreferredSize.Height;
- this.toolStripContainer1.Location = new Point(0, this.mainMenu.Bottom);
- this.toolStripContainer1.Margin = new Padding(-5);
- this.toolStripContainer1.TopToolStripPanel.Margin = new Padding(-5);
- this.toolStripContainer1.TopToolStripPanel.RowMargin = new Padding(0/*-1*/);
- this.mainMenu.Padding = new Padding(0, this.mainMenu.Padding.Top, 0, this.mainMenu.Padding.Bottom);
- this.documentStrip.Width = ClientSize.Width;
- this.documentStrip.Anchor = AnchorStyles.Left | AnchorStyles.Right;
- this.documentStrip.Location = new Point(0, this.toolStripContainer1.Bottom);
- // Finish setting up widths and heights
- int oldDsHeight = this.documentStrip.Height;
- this.documentStrip.Height = 25;
- int tsWidth = ClientSize.Width;
- this.mainMenu.Width = tsWidth;
- if (tsWidth > 0)
- {
- this.toolStripContainer1.TopToolStripPanel.Width = tsWidth;
- this.toolStripContainer1.Width = tsWidth;
- }
- this.Height = this.documentStrip.Bottom;
- this.documentStrip.PerformLayout();
- if (!plentyWidthBefore)
- {
- UI.ResumeControlPainting(this);
- Invalidate(true);
- }
- else
- {
- UI.ResumeControlPainting(this.documentStrip);
- this.documentStrip.Invalidate(true);
- }
- if (this.documentStrip.Width == 0)
- {
- this.mainMenu.Invalidate();
- }
- if (oldDsHeight != this.documentStrip.Height)
- {
- this.documentStrip.RefreshAllThumbnails();
- }
- base.OnLayout(e);
- }
- protected override void OnResize(EventArgs e)
- {
- PerformLayout();
- base.OnResize(e);
- }
- private void InitializeComponent()
- {
- this.SuspendLayout();
- this.mainMenu = new PdnMainMenu();
- this.toolStripContainer1 = new ToolStripContainer();
- this.documentStrip = new OurDocumentStrip(this.appWorkspace);
- this.toolStripContainer1.SuspendLayout();
- this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
- //
- // mainMenu
- //
- this.mainMenu.Name = "mainMenu";
- this.mainMenu.ContextMenuStrip = this.contextMenuStrip;
- this.mainMenu.MouseClick += new System.Windows.Forms.MouseEventHandler(this.frmContextmenu_MouseClick);
- //
- // 右键菜单
- //
- this.contextMenuStrip = new ContextMenuStrip();
- this.contextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(this.contextMenuStripItem_Click);
- //
- // toolStripContainer1.TopToolStripPanel
- //
- this.toolStripContainer1.AllowDrop = true;
- this.toolStripContainer1.BottomToolStripPanelVisible = false;
- this.toolStripContainer1.LeftToolStripPanelVisible = false;
- this.toolStripContainer1.RightToolStripPanelVisible = false;
- this.toolStripContainer1.TopToolStripPanel.Padding = new Padding(0, -20/*Top*/, 0, -2/*Bottom*/);
- this.toolStripContainer1.TopToolStripPanel.AllowDrop = true;
- this.toolStripContainer1.Name = "toolStripContainer1";
- this.toolStripContainer1.TabIndex = 13;
- this.toolStripContainer1.Text = "toolStripContainer1";
- this.toolStripContainer1.TopToolStripPanel.SizeChanged += new System.EventHandler(this.panel1_SizeChanged);
- this.toolStripContainer1.ContextMenuStrip = this.contextMenuStrip;
- this.toolStripContainer1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.frmContextmenu_MouseClick);
- //
- // documentStrip
- //
- this.documentStrip.AutoSize = false;
- this.documentStrip.Name = "documentStrip";
- this.documentStrip.TabIndex = 5;
- this.documentStrip.ShowScrollButtons = true;
- this.documentStrip.DocumentListChanged += new EventHandler(DocumentStrip_DocumentListChanged);
- this.documentStrip.DocumentClicked += DocumentStrip_DocumentClicked;
- this.documentStrip.ManagedFocus = true;
- //
- // PdnToolBar
- //
- this.Controls.Add(this.documentStrip);
- //this.Controls.Add(this.toolStripPanel);
- this.Controls.Add(this.toolStripContainer1);
- this.Controls.Add(this.mainMenu);
- this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false);
- this.toolStripContainer1.TopToolStripPanel.PerformLayout();
- this.toolStripContainer1.ResumeLayout(false);
- this.toolStripContainer1.PerformLayout();
- this.ResumeLayout(false);
- }
- private void frmContextmenu_MouseClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right)
- {
- this.contextMenuStrip.Show(MousePosition.X, MousePosition.Y);
- }
- }
- public void SetCustomizeTools()
- {
- if (toolbarModel == null || toolbarModel.Flows.Count == 0)
- {
- return;
- }
- int toolCount = toolbarModel.Flows.Count;
- for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
- {
- Flow flowJ = toolbarModel.Flows[j];
- if (flowJ.Menus.Count == 0)// || !flowJ.Show
- {
- toolCount -= 1;
- }
- }
- if (toolCount == 0)
- {
- return;
- }
- toolStrips = new ToolStrip[toolCount];
- int t = 0;
- for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
- {
- Flow flowJ = toolbarModel.Flows[j];
- /*if(!flowJ.Show)
- {
- continue;
- }*/
- if (flowJ.Menus.Count == 0)
- {
- continue;
- }
- ToolStrip toolStripEx = new ToolStrip();//Ex
- ImageList imageList = new ImageList();
- imageList.ColorDepth = ColorDepth.Depth32Bit;
- imageList.TransparentColor = Utility.TransparentKey;
- toolStripEx.ImageList = imageList;
- toolStripEx.Name = flowJ.Key;// "key_" + j;
- //Base.SettingModel.ToolbarLocationModel.Flow flow = toolbarLocationModel.Flows.Find(a => a.Key.Equals(flowJ.Key/*"targetProcess"*/));
- ////ToolbarLocationModel.Flows.Find();
- //int locationX = flow.X;
- //int locationY = flow.Y;
- int buttonsCount = flowJ.Menus.Count;
- foreach (Flow.Item item in flowJ.Menus)
- {
- //..Script
- if (item.Description.Equals("Script"))//脚本列表
- {
- List<mic_script> list = mic_script_BLL.FindAll();
- //foreach (var item in list)
- //{
- // this.listBox1.Items.Add(item.name);
- //}
- buttonsCount += (list.Count - 1);
- }
- if (item.Description.Equals("SubRulerCalibration"))//标尺标定,标尺列表
- {
- buttonsCount += 1;
- }
- }
- ToolStripItem[] buttons = new ToolStripItem[buttonsCount/*flowJ.Menus.Count*/];
- int index = 0;
- for (int i = 0; i < flowJ.Menus.Count; i++, index++)
- {
- ToolStripButton button = new ToolStripButton();
- int imageIndex = -1;
- if (flowJ.Menus[i].Description.Equals("SeparateLine"))
- {
- ToolStripSeparator separator0 = new ToolStripSeparator();
- buttons[index] = separator0;
- continue;
- }
- ToolStripItem[] items = this.MainMenu.Items.Find(flowJ.Menus[i].Description, true);
- if (items != null && items.Length > 0)
- {
- if (((PdnMenuItem)(items[0])).Image != null)
- imageIndex = imageList.Images.Add(((PdnMenuItem)(items[0])).Image, imageList.TransparentColor);
- else
- imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
- button.ToolTipText = ((PdnMenuItem)(items[0])).Text;
- button.Text = ((PdnMenuItem)(items[0])).Text;
- }
- else
- {
- imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
- button.ToolTipText = flowJ.Menus[i].Name;// getShowName(Program.instance.configModel.Language);
- button.Text = flowJ.Menus[i].Name;// getShowName(Program.instance.configModel.Language);
- }
- button.ImageIndex = imageIndex;
- button.Tag = flowJ.Menus[i].Description;
- button.TextImageRelation = TextImageRelation.ImageAboveText;
- //..Script
- if (flowJ.Menus[i].Description.Equals("Script"))//脚本列表
- {
- List<mic_script> list = mic_script_BLL.FindAll();
- for (int itemI = 0; itemI < list.Count - 1; itemI++)
- {
- var itemSS = list[itemI];
- ToolStripButton unitLabel = new ToolStripButton();
- unitLabel.Text = itemSS.name;
- unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
- unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
- //unitLabel.Tag = "Script_" + itemSS.id;
- unitLabel.Name = "" + itemSS.id;
- unitLabel.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
- buttons[index] = unitLabel;
- index++;
- }
- //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
- var item = list[list.Count - 1];
- ToolStripButton unitsLabel = new ToolStripButton();
- unitsLabel.Text = item.name;
- unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
- unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
- unitsLabel.Name = "" + item.id;
- unitsLabel.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
- buttons[index] = unitsLabel;
- }
- else if (flowJ.Menus[i].Description.Equals("SubRulerCalibration"))
- {
- ToolStripLabel unitsLabel = new ToolStripLabel();
- unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
- unitsLabel.Text = "标尺:";
- unitsLabel.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
- buttons[index] = unitsLabel;
- index++;
- ToolStripComboBox zoomComboBox = new ToolStripComboBox();
- zoomComboBox.Tag = i;
- zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
- zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
- zoomComboBox.MaxDropDownItems = 99;
- zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
- List<mic_rulers> list = mic_rulers_BLL.FindAll();
- if (list != null)
- {
- for (int ruleI = 0; ruleI < list.Count; ruleI++)
- {
- mic_rulers rule = list[ruleI];
- zoomComboBox.Items.Add(rule.ruler_name);
- if (Program.instance.configModel != null)
- {
- if (Program.instance.configModel.RulerId == rule.id)
- {
- zoomComboBox.Text = rule.ruler_name;// "newText";
- }
- }
- }
- }
- //if (zoomComboBox.Text == null || zoomComboBox.Text.Equals(""))
- //{
- // zoomComboBox.Text = "请选择";
- //}
- rulersComboBox.Add(zoomComboBox);
- zoomComboBox.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
- buttons[index] = zoomComboBox;
- zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- zoomComboBox.BackColor = SystemColors.Window;
- }
- else
- {
- button.Enabled = Program.getMenuIdVisible(flowJ.Menus[i].Id);
- buttons[index] = button;
- }
- }
- toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
- toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
- toolStripEx.EndDrag += ToolStripEx_DragDrop1;
- toolStripEx.AllowDrop = false;
- toolStripEx.AllowMerge = false;
- toolStripEx.Height = 40;
- toolStripEx.Items.AddRange(buttons);
- toolStrips[t] = toolStripEx;
- toolStripEx.Visible = flowJ.Show;
- t++;
- }
- this.toolStripContainer1.TopToolStripPanel.ControlRemoved += TopToolStripPanel_ControlRemoved;
- this.toolStripContainer1.TopToolStripPanel.DragDrop += TopToolStripPanel_DragDrop;
- this.toolStripContainer1.TopToolStripPanel.DragLeave += TopToolStripPanel_DragLeave;
- }
- private void ZoomComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (((ToolStripComboBox)sender).SelectedItem != null)
- {
- List<mic_rulers> list = Program.instance.mic_rulersAll;
- if (list != null)
- {
- for (int ruleI = 0; ruleI < list.Count; ruleI++)
- {
- mic_rulers rule = list[ruleI];
- if (rule.ruler_name.Equals(((ToolStripComboBox)sender).SelectedItem.ToString()))
- {
- int rulid = rule.id;
- string rulerName2 = rule.ruler_name;
- if (rulid != Program.instance.configModel.RulerId)
- {
- //设置当前选中标尺
- this.appWorkspace.SetActiveRulerIndex(((ToolStripComboBox)sender).SelectedIndex);
- //int oldId = Program.instance.configModel.RulerId;
- ////激活当前标尺到configModel
- //Program.instance.configModel.RulerId = rulid;
- ////保存xml文件
- //string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(Program.instance.configModel);
- //string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml";
- //if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- //{
- // //调用startup的方法
- // Program.instance.InitRulerInfo();
- // Program.instance.InitUnitInfo();
- // foreach (ToolStripComboBox comboBox in rulersComboBox)
- // {
- // if (((ToolStripComboBox)sender) == comboBox)
- // {
- // continue;
- // }
- // for (int i = 0; i < comboBox.Items.Count; i++)
- // {
- // if (rulerName2.Equals(comboBox.Items[i].ToString()))
- // {
- // comboBox.SelectedIndex = i;
- // }
- // }
- // }
- // //this.appWorkspace.RefreshActiveRuler();
- //}
- //else
- //{
- // Program.instance.configModel.RulerId = oldId;
- // MessageBox.Show("标尺激活失败");
- //}
- }
- break;
- }
- }
- }
- }
- }
- private void ToolStripEx_DragDrop1(object sender, EventArgs e)
- {
- if (toolStripInitLayout < 3)//to 完善
- {
- return;
- }
- for (int i = 0; i < this.toolStripContainer1.TopToolStripPanel.Controls.Count; i++)
- {
- ToolStrip toolStripEx = (ToolStrip)this.toolStripContainer1.TopToolStripPanel.Controls[i];
- Point point = toolStripEx.Location;
- //Base.SettingModel.ToolbarLocationModel.Flow flowJ = toolbarLocationModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
- Base.SettingModel.ToolbarModel.Flow flowJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
- flowJ.X = point.X;
- flowJ.Y = point.Y;
- }
- //string userInfoXml = XmlSerializeHelper.XmlSerialize(toolbarLocationModel);
- string userInfoXml = XmlSerializeHelper.XmlSerialize(toolbarModel);
- //string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\ToolbarLocation.xml";
- string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Toolbar.xml";
- if (FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create))
- {
- //Program.instance.toolbarLocationModel = toolbarLocationModel;
- Program.instance.toolbarModel = toolbarModel;
- }
- else
- {
- MessageBox.Show("工具栏坐标保存失败");
- }
- }
- ToolStrip toolStripEx = new ToolStrip();
- /// <summary>
- /// 重置工具栏
- /// </summary>
- public void ResetCustomizeTools()
- {
- this.toolbarModel = Program.instance.toolbarModel;
- if (toolbarModel == null || toolbarModel.Flows.Count == 0)
- {
- this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
- return;
- }
- int toolCount = toolbarModel.Flows.Count;
- for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
- {
- Flow flowJ = toolbarModel.Flows[j];
- if (flowJ.Menus.Count == 0)
- {
- toolCount -= 1;
- }
- }
- if (toolCount == 0)
- {
- this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
- return;
- }
- toolStrips = new ToolStrip[toolCount];
- int t = 0;
- for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
- {
- Flow flowJ = toolbarModel.Flows[j];
- if (flowJ.Menus.Count == 0)
- {
- continue;
- }
- ToolStrip toolStripEx = new ToolStrip();
- ImageList imageList = new ImageList();
- imageList.ColorDepth = ColorDepth.Depth32Bit;
- imageList.TransparentColor = Utility.TransparentKey;
- toolStripEx.ImageList = imageList;
- toolStripEx.Name = flowJ.Key;
- int buttonsCount = flowJ.Menus.Count;
- foreach (Flow.Item item in flowJ.Menus)
- {
- if (item.Description.Equals("Script"))//脚本列表
- {
- List<mic_script> list = mic_script_BLL.FindAll();
- buttonsCount += (list.Count - 1);
- }
- if (item.Description.Equals("SubRulerCalibration"))//标尺标定,标尺列表
- {
- buttonsCount += 1;
- }
- }
- ToolStripItem[] buttons = new ToolStripItem[buttonsCount/*flowJ.Menus.Count*/];
- int index = 0;
- for (int i = 0; i < flowJ.Menus.Count; i++, index++)
- {
- ToolStripButton button = new ToolStripButton();
- int imageIndex = -1;
- if (flowJ.Menus[i].Description.Equals("SeparateLine"))
- {
- ToolStripSeparator separator0 = new ToolStripSeparator();
- buttons[index] = separator0;
- continue;
- }
- ToolStripItem[] items = this.MainMenu.Items.Find(flowJ.Menus[i].Description, true);
- if (items != null && items.Length > 0)
- {
- if (((PdnMenuItem)(items[0])).Image != null)
- imageIndex = imageList.Images.Add(((PdnMenuItem)(items[0])).Image, imageList.TransparentColor);
- else
- imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
- button.ToolTipText = ((PdnMenuItem)(items[0])).Text;
- button.Text = ((PdnMenuItem)(items[0])).Text;
- }
- else
- {
- imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
- button.ToolTipText = flowJ.Menus[i].Name;// .getShowName(Program.instance.configModel.Language);
- button.Text = flowJ.Menus[i].Name;// .getShowName(Program.instance.configModel.Language);
- }
- button.ImageIndex = imageIndex;
- button.Tag = flowJ.Menus[i].Description;
- button.TextImageRelation = TextImageRelation.ImageAboveText;
- if (this.appWorkspace.ActiveDocumentWorkspace != null)
- {
- if (button.Tag.ToString().Equals(this.type))
- button.Checked = this.check;
- }
- //..Script
- if (flowJ.Menus[i].Description.Equals("Script"))//脚本列表
- {
- List<mic_script> list = mic_script_BLL.FindAll();
- for (int itemI = 0; itemI < list.Count - 1; itemI++)
- {
- var itemSS = list[itemI];
- ToolStripButton unitLabel = new ToolStripButton();
- unitLabel.Text = itemSS.name;
- unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
- unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
- //unitLabel.Tag = "Script_" + itemSS.id;
- unitLabel.Name = "" + itemSS.id;
- buttons[index] = unitLabel;
- index++;
- }
- //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
- var item = list[list.Count - 1];
- ToolStripButton unitsLabel = new ToolStripButton();
- unitsLabel.Text = item.name;
- unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
- unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
- unitsLabel.Name = "" + item.id;
- buttons[index] = unitsLabel;
- }
- else if (flowJ.Menus[i].Description.Equals("SubRulerCalibration"))
- {
- ToolStripLabel unitsLabel = new ToolStripLabel();
- unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
- unitsLabel.Text = "标尺:";
- buttons[index] = unitsLabel;
- index++;
- ToolStripComboBox zoomComboBox = new ToolStripComboBox();
- zoomComboBox.Tag = i;
- zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
- zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
- zoomComboBox.MaxDropDownItems = 99;
- zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
- List<mic_rulers> list = mic_rulers_BLL.FindAll();
- if (list != null)
- {
- for (int ruleI = 0; ruleI < list.Count; ruleI++)
- {
- mic_rulers rule = list[ruleI];
- zoomComboBox.Items.Add(rule.ruler_name);
- if (Program.instance.configModel != null)
- {
- if (Program.instance.configModel.RulerId == rule.id)
- {
- zoomComboBox.Text = rule.ruler_name;// "newText";
- }
- }
- }
- }
- rulersComboBox.Add(zoomComboBox);
- buttons[index] = zoomComboBox;
- zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- zoomComboBox.BackColor = SystemColors.Window;
- }
- else
- {
- buttons[index] = button;
- }
- }
- toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
- toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
- toolStripEx.EndDrag += ToolStripEx_DragDrop1;
- toolStripEx.AllowDrop = false;
- toolStripEx.AllowMerge = false;
- toolStripEx.Height = 40;
- toolStripEx.Items.AddRange(buttons);
- toolStrips[t] = toolStripEx;
- toolStripEx.Visible = flowJ.Show;
- t++;
- }
- this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
- this.toolStripContainer1.TopToolStripPanel.Controls.AddRange(toolStrips);
- }
- private string type;
- private bool check;
- /// <summary>
- /// 连续绘制联动
- /// </summary>
- /// <param name="check">是否选择</param>
- /// <param name="type">0:标注 1:测量</param>
- public void RefreshBtnSelect(bool check, string type)
- {
- this.type = type;
- this.check = check;
- if (toolStrips == null)
- return;
- for (int i = 0; i < toolStrips.Length; i++)
- {
- for (int j = 0; j < toolStrips[i].Items.Count; j++)
- {
- if (toolStrips[i].Items[j] is ToolStripButton && ((ToolStripButton)toolStrips[i].Items[j]).Tag != null && ((ToolStripButton)toolStrips[i].Items[j]).Tag.ToString().Equals(type))
- ((ToolStripButton)toolStrips[i].Items[j]).Checked = check;
- }
- }
- this.Refresh();
- }
- private void TopToolStripPanel_DragLeave(object sender, EventArgs e)
- {
- //throw new NotImplementedException();
- }
- private void TopToolStripPanel_DragDrop(object sender, DragEventArgs e)
- {
- //throw new NotImplementedException();
- }
- private void TopToolStripPanel_ControlRemoved(object sender, ControlEventArgs e)
- {
- //throw new NotImplementedException();
- }
- private void ToolStripEx_ItemRemoved(object sender, ToolStripItemEventArgs e)
- {
- //throw new NotImplementedException();
- }
- /// <summary>
- /// 递归查找菜单,暂时不用,改成直接用name查找
- /// </summary>
- /// <param name="collection"></param>
- /// <param name="step"></param>
- private void RecursiveData(ToolStripItemCollection collection, mic_script_step step)
- {
- for (int i = 0; i < collection.Count; i++)
- {
- if (!collection[i].Name.Equals("OpenRecent") && !collection[i].Name.Equals("CameraSelection"))
- {
- if (collection[i].GetType() != typeof(ToolStripSeparator))
- {
- if (step.menu_id == ((PdnMenuItem)collection[i]).MenuId)
- {
- ((PdnMenuItem)collection[i]).PerformClick();
- }
- RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, step);
- }
- }
- }
- }
- /// <summary>
- /// 脚本按钮点击方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ToolStripEx_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- if (e.ClickedItem.GetType() != typeof(ToolStripButton))
- {
- return;
- }
- //if (e.ClickedItem.Tag == null)
- //{
- // //获取当前选中的脚本步骤
- // List<mic_script_step> steps = mic_script_step_BLL.FindAllByScripId(int.Parse(e.ClickedItem.Name)/*list[this.listBox1.SelectedIndex].id*/);
- // //this.WindowState = FormWindowState.Minimized;
- // //循环脚本步骤
- // foreach (mic_script_step step in steps)
- // {
- // //递归的方式
- // this.RecursiveData(this.appWorkspace.ToolBar.MainMenu.Items/*this.collection*/, step);
- // }
- // return;
- //}
- //e.ClickedItem.Visible = false;
- ToolStripItem[] menu = this.appWorkspace.ToolBar.MainMenu.Items.Find(e.ClickedItem.Tag.ToString(), true);
- if (menu != null && menu.Length > 0)
- {
- if (((PdnMenuItem)menu[0]).canChecked)
- ((ToolStripButton)e.ClickedItem).Checked = !((ToolStripButton)e.ClickedItem).Checked;
- ((PdnMenuItem)menu[0]).PerformClick();
- appWorkspace.UpdateBottomButtonSelectionStatus();
- }
- }
- private void panel1_SizeChanged(object sender, EventArgs e)
- {
- this.toolStripContainer1.Height = this.toolStripContainer1.TopToolStripPanel.Height + 1;
- }
- private void DocumentStrip_DocumentClicked(object sender, EventArgs<Pair<DocumentWorkspace, DocumentClickAction>> e)
- {
- if (e.Data.Second == DocumentClickAction.Select)
- {
- PerformLayout();
- }
- }
- private void DocumentStrip_DocumentListChanged(object sender, EventArgs e)
- {
- PerformLayout();
- if (this.documentStrip.DocumentCount == 0)
- {
- //this.viewConfigStrip.Enabled = false;
- //this.toolChooserStrip.Enabled = false;
- }
- else
- {
- //this.viewConfigStrip.Enabled = true;
- //this.toolChooserStrip.Enabled = true;
- }
- }
- /// <summary>
- /// 用于ctrl+双击复制
- /// </summary>
- public void CopyAndPasteByControlAndDoubleClick()
- {
- //ToolStripItem[] menu = this.MainMenu.Items.Find(PdnMenuItem.GetDescription(ActionType.Copy), true);
- //ToolStripItem[] menu1 = this.MainMenu.Items.Find(PdnMenuItem.GetDescription(ActionType.Paste), true);
- //if (menu != null && menu1 != null && menu.Length > 0 && menu1.Length > 0)
- //{
- // ((PdnMenuItem)menu[0]).PerformClick();
- // ((PdnMenuItem)menu1[0]).PerformClick();
- //}
- ControlAnd(CopyAndPasteBy());
- }
- /// <summary>
- /// 复制剪裁图片
- /// </summary>
- /// <returns></returns>
- public Bitmap CopyAndPasteBy()
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null && AppWorkspace.ActiveDocumentWorkspace.CompositionSurface != null)
- {
- Bitmap temp = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
- copyedBitmap = new Bitmap(temp.Width, temp.Height);
- Graphics graphics = Graphics.FromImage(copyedBitmap);
- graphics.DrawImage(temp, 0, 0, temp.Width, temp.Height);
- //if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList.IsExsitSpecificObject(DrawToolType.ImageCut))
- //{
- // //获取裁剪的矩形区域
- // List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.ImageCut);
- // ImageCutDraw imageCutDraw = (ImageCutDraw)objList[0];
- // RectangleF cutRectangle = imageCutDraw.Rectangle;
- // copyedBitmap = DrawRulerHelper.KiCut(copyedBitmap, (int)cutRectangle.X, (int)cutRectangle.Y, (int)cutRectangle.Width, (int)cutRectangle.Height);
- //}
- }
- return copyedBitmap;
- }
- /// <summary>
- /// 粘贴剪裁图片
- /// </summary>
- /// <param name="copyedBitmap"></param>
- public void ControlAnd(Bitmap copyedBitmap)
- {
- //if (copyedBitmap != null)
- //{
- // DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
- // Document document = Document.FromImage(copyedBitmap);
- // dw.Document = document;
- // dw.xmlSaveModel = AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
- // dw.rules = AppWorkspace.ActiveDocumentWorkspace.rules;
- // //图片命名
- // nameNum++;
- // int numLength = nameNum.ToString().Length;
- // string joinName = "";
- // switch (numLength)
- // {
- // case 1:
- // joinName = "00" + nameNum;
- // break;
- // case 2:
- // joinName = "0" + nameNum;
- // break;
- // default:
- // joinName = nameNum.ToString();
- // break;
- // }
- // dw.fileText = PdnResources.GetString("Menu.Copythepicture.Text") + "-" + joinName;
- // AppWorkspace.ActiveDocumentWorkspace = dw;
- //}
- }
- }
- }
|