1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786 |
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.Menus;
- using PaintDotNet.SystemLayer;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Linq;
- using System.Windows.Forms;
- using System.Windows.Forms.Layout;
- using static PaintDotNet.Base.SettingModel.ToolbarModel;
- using PaintDotNet.Data.Param;
- using PaintDotNet.Annotation;
- using PaintDotNet.Annotation.Label;
- using PaintDotNet.Annotation.Enum;
- namespace PaintDotNet
- {
- 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 = Startup.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 Startup.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 = Startup.instance.toolbarModel.Flows.Find(a => a.Name.Equals(e.ClickedItem.Text));
- if(flow!=null)
- {
- flow.Show = ShowFlag;
- string userInfoXml = XmlSerializeHelper.XmlSerialize<ToolbarModel>(Startup.instance.toolbarModel);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.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 = Startup.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 == Startup.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 (Startup.instance.configModel != null)
- //{
- // if (Startup.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 = Startup.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 == Startup.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;
- }
- }
- }
- }
- /// <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 = Startup.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 (Startup.instance.configModel != null)
- {
- if (Startup.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 = Startup.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 < Startup.instance.toolbarLocationModel.Flows.Count; j++)
- for (int j = 0; j < Startup.instance.toolbarModel.Flows.Count; j++)
- {
- //ToolbarLocationModel.Flow flowJ = Startup.instance.toolbarLocationModel.Flows[j];
- ToolbarModel.Flow flowJ = Startup.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(Startup.instance.configModel.Language);
- button.Text = flowJ.Menus[i].Name;// getShowName(Startup.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 = Startup.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 = Startup.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 = Startup.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 (Startup.instance.configModel != null)
- {
- if (Startup.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 = Startup.getMenuIdVisible(flowJ.Menus[i].Id);
- buttons[index] = zoomComboBox;
- zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- zoomComboBox.BackColor = SystemColors.Window;
- }
- else
- {
- button.Enabled = Startup.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 = Startup.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 != Startup.instance.configModel.RulerId)
- {
- //设置当前选中标尺
- this.appWorkspace.SetActiveRulerIndex(((ToolStripComboBox)sender).SelectedIndex);
- //应用到当前
- this.appWorkspace.Widgets.RuleListForm.MenuSubApplyCurrent();
- //int oldId = Startup.instance.configModel.RulerId;
- ////激活当前标尺到configModel
- //Startup.instance.configModel.RulerId = rulid;
- ////保存xml文件
- //string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(Startup.instance.configModel);
- //string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- //if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- //{
- // //调用startup的方法
- // Startup.instance.InitRulerInfo();
- // Startup.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
- //{
- // Startup.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\\" + Startup.instance.SettingPrefix + "\\ToolbarLocation.xml";
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Toolbar.xml";
- if (FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create))
- {
- //Startup.instance.toolbarLocationModel = toolbarLocationModel;
- Startup.instance.toolbarModel = toolbarModel;
- }
- else
- {
- MessageBox.Show("工具栏坐标保存失败");
- }
- }
- ToolStrip toolStripEx = new ToolStrip();
- /// <summary>
- /// 重置工具栏
- /// </summary>
- public void ResetCustomizeTools()
- {
- this.toolbarModel = Startup.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(Startup.instance.configModel.Language);
- button.Text = flowJ.Menus[i].Name;// .getShowName(Startup.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 (Startup.instance.configModel != null)
- {
- if (Startup.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);
- //this.toolStripContainer1.TopToolStripPanel.Refresh();
- //this.toolStripInitLayout = -100;// 10;
- //this.toolbarModel = Startup.instance.toolbarModel;
- //this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
- //SetCustomizeTools(true);
- //int toolCount = this.toolbarModel.Flows.Count;
- //for (int j = this.toolbarModel.Flows.Count - 1; j >= 0; j--)
- //{
- // Flow flowJ = this.toolbarModel.Flows[j];
- // if (flowJ.Menus.Count == 0)
- // {
- // toolCount -= 1;
- // }
- //}
- //if (toolCount == 0)
- //{
- // this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
- // return;
- //}
- //toolStrips = new ToolStrip[toolCount];
- //rulersComboBox.Clear();
- //int indexJ = 0;
- ////先将location值不为-100的菜单显示出来(初始值设置-100)
- //int heightRow = 0;// -1;// 0;
- //int widthRow1 = 0;// -1;// 0;
- ////for (int j = 0; j < Startup.instance.toolbarLocationModel.Flows.Count; j++)
- //for (int j = 0; j < Startup.instance.toolbarModel.Flows.Count; j++)
- //{
- // //ToolbarLocationModel.Flow flowJ = Startup.instance.toolbarLocationModel.Flows[j];
- // ToolbarModel.Flow flowJ = Startup.instance.toolbarModel.Flows[j];
- // if (flowJ.X > -100 && flowJ.Y > -100)
- // {
- // if (flowJ.Y > heightRow || (flowJ.Y == heightRow && flowJ.X >= widthRow1))
- // {
- // Control[] temp = this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true);
- // if (temp!=null && temp.Length>0)
- // {
- // ToolStrip toolStripEx = (ToolStrip)(temp[0]);
- // if (toolStripEx == null)
- // {
- // heightRow = flowJ.Y;
- // widthRow1 = flowJ.X + 1;
- // }
- // else
- // {
- // heightRow = flowJ.Y;
- // widthRow1 = flowJ.X + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
- // }
- // }
- // }
- // }
- //}
- //for (int i = 0; i < this.toolStripContainer1.TopToolStripPanel.Controls.Count; i++)
- //{
- // ToolStrip toolStripEx = (ToolStrip)this.toolStripContainer1.TopToolStripPanel.Controls[i];
- // Flow flowJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
- // if (flowJ == null)
- // {
- // this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripEx);
- // i--;
- // }
- // else
- // {
- // toolStrips[indexJ++] = toolStripEx;
- // }
- //}
- //if (toolbarModel == null || toolbarModel.Flows.Count == 0)
- //{
- // return;
- //}
- ////int toolStripWidth = 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();//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();
- // 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;
- // }
- // //this.Items.Add(this.separator0);
- // ToolStripItem[] items = this/*.appWorkspace.ToolBar*/.MainMenu.Items.Find(flowJ.Menus[i].Description, true);
- // //ToolbarLocationModel.Flows;
- // 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);
- // }
- // else
- // {
- // imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
- // }
- // button.ImageIndex = imageIndex;
- // button.Tag = flowJ.Menus[i].Description;
- // button.ToolTipText = flowJ.Menus[i].Name;
- // button.Text = flowJ.Menus[i].Name;
- // 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.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 (Startup.instance.configModel != null)
- // {
- // if (Startup.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);
- // //Base.SettingModel.ToolbarLocationModel.Flow flowLocJ = toolbarLocationModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
- // Base.SettingModel.ToolbarModel.Flow flowLocJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
- // if (flowLocJ.X == -100 || flowLocJ.Y == -100)
- // {
- // 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*/)
- // {
- // continue;
- // }
- // if (widthRow1 < ClientSize.Width || ClientSize.Width == 0)
- // {
- // toolStripEx.Location = new Point(widthRow1/*lastToolStripEx.Right + 1*/, heightRow/*lastToolStripEx.Top*/);
- // widthRow1 = widthRow1 + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
- // }
- // else
- // {
- // heightRow += 40;// 38;// 39;
- // toolStripEx.Location = new Point(0, heightRow/*lastToolStripEx.Bottom*/);
- // widthRow1 = 0/*toolStripEx.Left*/ + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal;
- // }
- // this.toolStripContainer1.TopToolStripPanel.Controls.Add(toolStripEx);
- // toolStrips[indexJ++] = toolStripEx;
- // }
- //}
- //this.toolStripContainer1.TopToolStripPanel.ControlRemoved += TopToolStripPanel_ControlRemoved;
- //this.toolStripContainer1.TopToolStripPanel.DragDrop += TopToolStripPanel_DragDrop;
- //this.toolStripContainer1.TopToolStripPanel.DragLeave += TopToolStripPanel_DragLeave;
- //toolStripInitLayout = 3;// 0;
- //this.toolStripContainer1.Enabled = (!this.appWorkspace.ScriptRunning);
- ////this.mainMenu.Enabled = (!this.appWorkspace.ScriptRunning);
- }
- 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] is PdnMenuItem)
- {
- 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.FromImageMat(Camera.Tools.ToMat(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;
- }
- }
- }
- }
|