1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819 |
- using Resources;
- using SmartCoalApplication.Actions;
- using SmartCoalApplication.Annotation.Enum;
- using SmartCoalApplication.Base;
- using SmartCoalApplication.Base.CommTool;
- using SmartCoalApplication.Base.Enum;
- using SmartCoalApplication.Base.MeasureModel;
- using SmartCoalApplication.Base.SettingModel;
- using SmartCoalApplication.Core;
- using SmartCoalApplication.Core.CustomControl;
- using SmartCoalApplication.Core.DbOpreate.DbModel;
- using SmartCoalApplication.Rule;
- using SmartCoalApplication.SystemLayer;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Windows.Forms;
- namespace SmartCoalApplication
- {
- internal class AppWorkspace : UserControl, ISnapObstacleHost, IAppWorkspaceForSurfaceBox
- {
- /// <summary>
- /// 顶部菜单和工具栏
- /// </summary>
- public PdnToolBar toolBar;
- /// <summary>
- /// 底部公用工具栏
- /// </summary>
- private PanelBottom panelBottom;
- /// <summary>
- /// 主界面左侧的快捷工具栏
- /// </summary>
- public ToolsControl toolsPanel;
- /// <summary>
- /// 包含DocumentWorkspace集合的panel
- /// </summary>
- public Panel workspacePanel;
- /// <summary>
- /// 底部状态栏
- /// </summary>
- private PdnStatusBar statusBar;
- /// <summary>
- /// 当前激活的工作空间
- /// </summary>
- private DocumentWorkspace activeDocumentWorkspace;
- /// <summary>
- /// 如果添加了新的工作空间,并且该工作空间没有被修改,则将其删除
- /// </summary>
- private DocumentWorkspace initialWorkspace;
- /// <summary>
- /// 工作空间集合,打开的图像
- /// </summary>
- private List<DocumentWorkspace> documentWorkspaces = new List<DocumentWorkspace>();
- /// <summary>
- /// 保存了许多可浮动的窗口,为了统一管理,供外部调用
- /// </summary>
- private WorkspaceWidgets widgets;
- /// <summary>
- /// 最近打开的文件
- /// </summary>
- private MostRecentFiles mostRecentFiles = null;
- /// <summary>
- /// 最近打开的文件的最大默认数量
- /// </summary>
- private const int defaultMostRecentFilesMax = 8;
- /// <summary>
- /// 锁定扩缩标记
- /// </summary>
- public bool isLockZoom = false;
- /// <summary>
- /// 锁定扩缩的百分比
- /// </summary>
- public double lockScaleRatio = 0;
- /// <summary>
- /// 测量连续绘制
- /// </summary>
- public bool continuousDrawingMeasure = false;
- /// <summary>
- /// 标记连续绘制
- /// </summary>
- public bool continuousDrawingLabel = false;
- /// <summary>
- /// 测量连续绘制
- /// </summary>
- public bool continuousDrawingView = false;
- /// <summary>
- /// 要删除的工作空间位置(避免批量保存有修改的图片时关闭的工作空间位置与for循环顺序不一致)
- /// </summary>
- public int toRemoveDocumentWorkspaceIndex = -1;
- private SnapObstacleController snapObstacle;
- private bool addedToSnapManager = false;
- private int ignoreUpdateSnapObstacle = 0;
- public DrawToolType activeTool = DrawToolType.Pointer;
- /// <summary>
- /// 结果页面标尺信息
- /// </summary>
- public double unitNum = 1;
- public string aliasName;
- public int decimalPlaces = 2;
- /// <summary>
- /// 标尺标定窗口
- /// </summary>
- private RuleListForm ruleListForm;
- public void ResetFloatingForms()
- {
- ResetFloatingForm(Widgets.RuleListForm);
- }
- public void ResetFloatingForm(FloatingToolForm ftf)
- {
- SnapManager sm = SnapManager.FindMySnapManager(this);
- if (ftf == Widgets.RuleListForm)
- {
- sm.ParkObstacle(Widgets.RuleListForm, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
- }
- else
- {
- throw new ArgumentException();
- }
- }
- public PanelBottom PanelBottom
- {
- get
- {
- return this.panelBottom;
- }
- }
- /// <summary>
- /// 单位改变事件
- /// </summary>
- public event EventHandler UnitsChanged;
- protected virtual void OnUnitsChanged()
- {
- if (UnitsChanged != null)
- {
- UnitsChanged(this, EventArgs.Empty);
- }
- }
- public MeasurementUnit Units
- {
- get
- {
- return Program.instance.measurementUnit;
- }
- set
- {
- //this.widgets.ViewConfigStrip.Units = value;
- }
- }
- protected override void OnLayout(LayoutEventArgs levent)
- {
- base.OnLayout(levent);
- }
- protected override void OnLocationChanged(EventArgs e)
- {
- base.OnLocationChanged(e);
- }
- protected override void OnSizeChanged(EventArgs e)
- {
- base.OnSizeChanged(e);
- }
- protected override void OnEnabledChanged(EventArgs e)
- {
- base.OnEnabledChanged(e);
- }
- protected override void OnVisibleChanged(EventArgs e)
- {
- base.OnVisibleChanged(e);
- }
- public PdnToolBar ToolBar
- {
- get
- {
- return this.toolBar;
- }
- }
- public MostRecentFiles MostRecentFiles
- {
- get
- {
- if (this.mostRecentFiles == null)
- {
- this.mostRecentFiles = new MostRecentFiles(defaultMostRecentFilesMax);
- }
- return this.mostRecentFiles;
- }
- }
- private void DocumentWorkspace_DocumentChanging(object sender, EventArgs<Document> e)
- {
- UI.SuspendControlPainting(this);
- }
- private void DocumentWorkspace_DocumentChanged(object sender, EventArgs e)
- {
- UpdateDocInfoInStatusBar();
- this.UpdatePixelTracking();
- UI.ResumeControlPainting(this);
- Invalidate(true);
- }
- private void CoordinatesToStrings(int x, int y, out string xString, out string yString, out string unitsString)
- {
- this.activeDocumentWorkspace.Document.CoordinatesToStrings(this.Units, x, y, out xString, out yString, out unitsString);
- }
- /// <summary>
- /// 更新右下角坐标信息
- /// </summary>
- /// <param name="cursorX"></param>
- /// <param name="cursorY"></param>
- private void UpdateCursorInfoInStatusBar(int cursorX, int cursorY)
- {
- SuspendLayout();
- if (this.activeDocumentWorkspace == null ||
- this.activeDocumentWorkspace.Document == null)
- {
- this.statusBar.CursorInfoText = string.Empty;
- }
- else
- {
- string xString;
- string yString;
- string units;
- CoordinatesToStrings(cursorX, cursorY, out xString, out yString, out units);
- string cursorText = string.Format(
- CultureInfo.InvariantCulture,
- PdnResources.GetString("StatusBar.CursorInfo.Format"),
- xString,
- units,
- yString,
- units);
- //this.statusBar.CursorInfoText = cursorText;
- }
- ResumeLayout(false);
- }
- /// <summary>
- /// 更新底部状态栏的文字等
- /// 需要修改为显示标尺相关的信息
- /// </summary>
- public void UpdateDocInfoInStatusBar()
- {
- if (this.activeDocumentWorkspace != null)
- {
- if (this.activeDocumentWorkspace.xmlSaveModel == null)
- {
- if (Program.instance.ruleDB != null)
- {
- this.statusBar.ImageInfoStatusText = Program.instance.ruleDB.ruler_name;
- this.statusBar.CursorInfoText = Math.Round(Program.instance.rules[(MeasurementUnit)Program.instance.ruleDB.ruler_units], 4) + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), Program.instance.ruleDB.ruler_units)))].ToString() + "/" + PdnResources.GetString("Menu.Pixel.text");
- }
- else {
- this.statusBar.ImageInfoStatusText = PdnResources.GetString("Menu.Unselectedruler.Text");
- this.statusBar.CursorInfoText = PdnResources.GetString("Menu.Defaultis1micron/pixel.Text");
- }
- }
- else
- {
- //选中图片是否有配置文件
- if ((ExistenceXML() && this.activeDocumentWorkspace.xmlSaveModel.pixel_length != 0) || (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.xmlSaveModel != null && this.activeDocumentWorkspace.xmlSaveModel.pixel_length != 0))
- {
- this.statusBar.ImageInfoStatusText = this.activeDocumentWorkspace.xmlSaveModel.ruler_name;
- double unitLength = (double)(this.activeDocumentWorkspace.xmlSaveModel.physical_length / (decimal)this.activeDocumentWorkspace.xmlSaveModel.pixel_length);
- this.statusBar.CursorInfoText = Math.Round(unitLength, 4) + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), this.activeDocumentWorkspace.xmlSaveModel.ruler_units)))].ToString() + "/" + PdnResources.GetString("Menu.Pixel.text");
- }
- else
- {
- this.statusBar.ImageInfoStatusText = Program.instance.ruleDB.ruler_name;
- this.statusBar.CursorInfoText = Math.Round(Program.instance.rules[(MeasurementUnit)Program.instance.ruleDB.ruler_units], 4) + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), Program.instance.ruleDB.ruler_units)))].ToString() + "/" + PdnResources.GetString("Menu.Pixel.text");
- }
- }
- }
- }
- /// <summary>
- /// 更新像素跟踪的图像
- /// </summary>
- private void UpdatePixelTracking()
- {
- }
- [Browsable(false)]
- public WorkspaceWidgets Widgets
- {
- get
- {
- return this.widgets;
- }
- }
- public DocumentWorkspace ActiveDocumentWorkspace
- {
- get
- {
- return this.activeDocumentWorkspace;
- }
- set
- {
- if (value != this.activeDocumentWorkspace)
- {
- if (value != null &&
- this.documentWorkspaces.IndexOf(value) == -1)
- {
- throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
- }
- bool focused = false;
- if (this.activeDocumentWorkspace != null)
- {
- focused = this.activeDocumentWorkspace.Focused;
- }
- UI.SuspendControlPainting(this);
- OnActiveDocumentWorkspaceChanging();
- this.activeDocumentWorkspace = value;
- OnActiveDocumentWorkspaceChanged();
- UI.ResumeControlPainting(this);
- Refresh();
- if (value != null)
- {
- value.Focus();
- }
- }
- }
- }
- private void ActiveDocumentWorkspace_FirstInputAfterGotFocus(object sender, EventArgs e)
- {
- //this.toolBar.DocumentStrip.EnsureItemFullyVisible(this.toolBar.DocumentStrip.SelectedDocumentIndex);
- }
- public DocumentWorkspace[] DocumentWorkspaces
- {
- get
- {
- return this.documentWorkspaces.ToArray();
- }
- }
- public SnapObstacle SnapObstacle
- {
- get
- {
- if (this.snapObstacle == null)
- {
- this.snapObstacle = new SnapObstacleController(
- this.Name,
- Rectangle.Empty,
- SnapRegion.Interior,
- true);
- this.snapObstacle.EnableSave = false;
- PdnBaseForm pdbForm = FindForm() as PdnBaseForm;
- pdbForm.Moving += new MovingEventHandler(ParentForm_Moving);
- pdbForm.Move += new EventHandler(ParentForm_Move);
- pdbForm.ResizeEnd += new EventHandler(ParentForm_ResizeEnd);
- pdbForm.Layout += new LayoutEventHandler(ParentForm_Layout);
- pdbForm.SizeChanged += new EventHandler(ParentForm_SizeChanged);
- UpdateSnapObstacle();
- }
- return this.snapObstacle;
- }
- }
- private void ParentForm_Move(object sender, EventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void ParentForm_SizeChanged(object sender, EventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void ParentForm_Layout(object sender, LayoutEventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void ParentForm_ResizeEnd(object sender, EventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void ParentForm_Moving(object sender, MovingEventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void AppWorkspace_Shown(object sender, EventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void SuspendUpdateSnapObstacle()
- {
- ++this.ignoreUpdateSnapObstacle;
- }
- private void ResumeUpdateSnapObstacle()
- {
- --this.ignoreUpdateSnapObstacle;
- }
- /// <summary>
- /// 更新快照
- /// </summary>
- private void UpdateSnapObstacle()
- {
- if (this.ignoreUpdateSnapObstacle > 0)
- {
- return;
- }
- if (this.snapObstacle == null)
- {
- return;
- }
- if (!this.addedToSnapManager)
- {
- SnapManager sm = SnapManager.FindMySnapManager(this);
- if (sm != null)
- {
- SnapObstacle so = this.SnapObstacle;
- if (!this.addedToSnapManager)
- {
- sm.AddSnapObstacle(this.SnapObstacle);
- this.addedToSnapManager = true;
- FindForm().Shown += new EventHandler(AppWorkspace_Shown);
- }
- }
- }
- if (this.snapObstacle != null)
- {
- Rectangle clientRect;
- if (ActiveDocumentWorkspace != null)
- {
- clientRect = ActiveDocumentWorkspace.VisibleViewRectangle;
- }
- else
- {
- clientRect = this.workspacePanel.ClientRectangle;
- }
- Rectangle screenRect = this.workspacePanel.RectangleToScreen(clientRect);
- this.snapObstacle.SetBounds(screenRect);
- this.snapObstacle.Enabled = this.Visible && this.Enabled;
- try
- {
- //this.ActiveDocumentWorkspace.PanelBottom.documentStrip.Width = screenRect.Width - this.ActiveDocumentWorkspace.PanelBottom.locationX;
- }
- catch (Exception)
- {
- // throw;
- }
- }
- }
- public DocumentWorkspace AddNewDocumentWorkspace()
- {
- if (this.initialWorkspace != null)
- {
- if (this.initialWorkspace.Document == null || !this.initialWorkspace.Document.Dirty)
- {
- RemoveDocumentWorkspace(this.initialWorkspace);
- this.initialWorkspace = null;
- }
- }
- DocumentWorkspace dw = new DocumentWorkspace(this);
- dw.AppWorkspace = this;
- dw.activeTool = this.activeTool;
- this.documentWorkspaces.Add(dw);
- this.toolBar.DocumentStrip.AddDocumentWorkspace(dw);
- return dw;
- }
- public void RemoveDocumentWorkspace(DocumentWorkspace documentWorkspace)
- {
- int dwIndex = this.documentWorkspaces.IndexOf(documentWorkspace);
- if (dwIndex == -1)
- {
- throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
- }
- bool removingCurrentDW;
- if (this.ActiveDocumentWorkspace == documentWorkspace)
- {
- removingCurrentDW = true;
- }
- else
- {
- removingCurrentDW = false;
- }
- if (removingCurrentDW)
- {
- if (this.documentWorkspaces.Count == 1)
- {
- this.ActiveDocumentWorkspace = null;
- }
- else if (dwIndex == 0)
- {
- this.ActiveDocumentWorkspace = this.documentWorkspaces[1];
- }
- else
- {
- this.ActiveDocumentWorkspace = this.documentWorkspaces[dwIndex - 1];
- }
- }
- this.documentWorkspaces.Remove(documentWorkspace);
- this.toolBar.DocumentStrip.RemoveDocumentWorkspace(documentWorkspace);
- if (this.initialWorkspace == documentWorkspace)
- {
- this.initialWorkspace = null;
- }
- // Clean up the DocumentWorkspace
- Document document = documentWorkspace.Document;
- documentWorkspace.Document = null;
- document.Dispose();
- documentWorkspace.Dispose();
- documentWorkspace = null;
- }
- public event EventHandler ActiveDocumentWorkspaceChanging;
- protected virtual void OnActiveDocumentWorkspaceChanging()
- {
- SuspendUpdateSnapObstacle();
- if (ActiveDocumentWorkspaceChanging != null)
- {
- ActiveDocumentWorkspaceChanging(this, EventArgs.Empty);
- }
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.FirstInputAfterGotFocus +=
- ActiveDocumentWorkspace_FirstInputAfterGotFocus;
- this.activeDocumentWorkspace.RulersEnabledChanged -= this.DocumentWorkspace_RulersEnabledChanged;
- this.activeDocumentWorkspace.DocumentMouseEnter -= this.DocumentMouseEnterHandler;
- this.activeDocumentWorkspace.DocumentMouseLeave -= this.DocumentMouseLeaveHandler;
- this.activeDocumentWorkspace.DocumentMouseMove -= this.DocumentMouseMoveHandler;
- this.activeDocumentWorkspace.DocumentMouseDown -= this.DocumentMouseDownHandler;
- this.activeDocumentWorkspace.Scroll -= this.DocumentWorkspace_Scroll;
- this.activeDocumentWorkspace.Layout -= this.DocumentWorkspace_Layout;
- this.activeDocumentWorkspace.DocumentClick -= this.DocumentClick;
- this.activeDocumentWorkspace.DocumentMouseUp -= this.DocumentMouseUpHandler;
- this.activeDocumentWorkspace.DocumentKeyPress -= this.DocumentKeyPress;
- this.activeDocumentWorkspace.DocumentKeyUp -= this.DocumenKeyUp;
- this.activeDocumentWorkspace.DocumentKeyDown -= this.DocumentKeyDown;
- this.activeDocumentWorkspace.StatusChanged -= OnDocumentWorkspaceStatusChanged;
- this.activeDocumentWorkspace.DocumentChanging -= DocumentWorkspace_DocumentChanging;
- this.activeDocumentWorkspace.DocumentChanged -= DocumentWorkspace_DocumentChanged;
- this.activeDocumentWorkspace.Visible = false;
- this.activeDocumentWorkspace.ToolChanging -= this.ToolChangingHandler;
- this.activeDocumentWorkspace.ToolChanged -= this.ToolChangedHandler;
- this.activeDocumentWorkspace.ActiveTool = this.activeTool;
- }
- ResumeUpdateSnapObstacle();
- UpdateSnapObstacle();
- //if (this.activeDocumentWorkspace != null)
- //{
- // if (!this.activeDocumentWorkspace.ContinuousDrawingMeasure
- // && this.activeDocumentWorkspace.activeTool >= DrawToolType.MeasureLine && this.activeDocumentWorkspace.activeTool <= DrawToolType.MeasureThreePointArc)
- // this.activeDocumentWorkspace.activeTool = DrawToolType.Pointer;
- // if (!this.activeDocumentWorkspace.ContinuousDrawingLabel
- // && this.activeDocumentWorkspace.activeTool >= DrawToolType.DrawRectangle && this.activeDocumentWorkspace.activeTool <= DrawToolType.DrawPrestoredRuler)
- // this.activeDocumentWorkspace.activeTool = DrawToolType.Pointer;
- // this.SetTopLeftCheckState();
- // this.UpdateBottomButtonSelectionStatus();
- //}
- }
- public event EventHandler ActiveDocumentWorkspaceChanged;
- protected virtual void OnActiveDocumentWorkspaceChanged()
- {
- SuspendUpdateSnapObstacle();
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.SuspendLayout();
- this.activeDocumentWorkspace.BackColor = System.Drawing.SystemColors.ControlDark;
- this.activeDocumentWorkspace.Dock = System.Windows.Forms.DockStyle.Fill;
- this.activeDocumentWorkspace.PanelAutoScroll = true;
- this.activeDocumentWorkspace.RulersEnabled = Settings.CurrentUser.GetBoolean(SettingNames.Rulers, true);
- this.activeDocumentWorkspace.TabIndex = 0;
- this.activeDocumentWorkspace.TabStop = false;
- this.activeDocumentWorkspace.RulersEnabledChanged += this.DocumentWorkspace_RulersEnabledChanged;
- this.activeDocumentWorkspace.DocumentMouseEnter += this.DocumentMouseEnterHandler;
- this.activeDocumentWorkspace.DocumentMouseLeave += this.DocumentMouseLeaveHandler;
- this.activeDocumentWorkspace.DocumentMouseMove += this.DocumentMouseMoveHandler;
- this.activeDocumentWorkspace.DocumentMouseDown += this.DocumentMouseDownHandler;
- this.activeDocumentWorkspace.Scroll += this.DocumentWorkspace_Scroll;
- this.activeDocumentWorkspace.DocumentClick += this.DocumentClick;
- this.activeDocumentWorkspace.DocumentMouseUp += this.DocumentMouseUpHandler;
- this.activeDocumentWorkspace.DocumentKeyPress += this.DocumentKeyPress;
- this.activeDocumentWorkspace.DocumentKeyUp += this.DocumenKeyUp;
- this.activeDocumentWorkspace.DocumentKeyDown += this.DocumentKeyDown;
- if (this.workspacePanel.Controls.Contains(this.activeDocumentWorkspace))
- {
- this.activeDocumentWorkspace.Visible = true;
- }
- else
- {
- this.activeDocumentWorkspace.Dock = DockStyle.Fill;
- this.workspacePanel.Controls.Add(this.activeDocumentWorkspace);
- }
- this.activeDocumentWorkspace.Layout += this.DocumentWorkspace_Layout;
- this.activeDocumentWorkspace.AppWorkspace = this;
- this.activeDocumentWorkspace.StatusChanged += OnDocumentWorkspaceStatusChanged;
- this.activeDocumentWorkspace.DocumentChanging += DocumentWorkspace_DocumentChanging;
- this.activeDocumentWorkspace.DocumentChanged += DocumentWorkspace_DocumentChanged;
- this.activeDocumentWorkspace.ToolChanging += this.ToolChangingHandler;
- this.activeDocumentWorkspace.ToolChanged += this.ToolChangedHandler;
- this.toolBar.DocumentStrip.SelectDocumentWorkspace(this.activeDocumentWorkspace);
- //处理底部缩放百分比的trackbar和textbox
- this.SetZoonTrackValue(this.activeDocumentWorkspace.ScaleFactor);
- this.activeDocumentWorkspace.ResumeLayout();
- this.activeDocumentWorkspace.PerformLayout();
- this.activeDocumentWorkspace.FirstInputAfterGotFocus += ActiveDocumentWorkspace_FirstInputAfterGotFocus;
- //更新信息
- this.UpdateDocInfoInStatusBar();
- }
- if (ActiveDocumentWorkspaceChanged != null)
- {
- ActiveDocumentWorkspaceChanged(this, EventArgs.Empty);
- }
- ResumeUpdateSnapObstacle();
- UpdateSnapObstacle();
- UpdateStatusBarContextStatus();
- }
- public void SetTopLeftCheckState()
- {
- if (this.toolBar != null && this.activeDocumentWorkspace != null)
- {
- this.toolBar.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
- this.activeDocumentWorkspace.ContinuousDrawingMeasure = this.continuousDrawingMeasure;
- this.activeDocumentWorkspace.ContinuousDrawingLabel = this.continuousDrawingLabel;
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingMeasure, "ContinuousDrawingMeasure");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingMeasure, "ContinuousDrawingMeasure");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingLabel, "ContinuousDrawingLabel");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingLabel, "ContinuousDrawingLabel");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.RulersEnabled, "ViewRuler");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.RulersEnabled, "ViewRuler");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousBinaryAction, "ContinuousOperation");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousBinaryAction, "ContinuousOperation");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ActualSize, "ActualSize");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ActualSize, "ActualSize");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.LockZoom, "LockZoom");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.LockZoom, "LockZoom");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.FixedMultiple, "FixedMultiple");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.FixedMultiple, "FixedMultiple");
- if (!this.activeDocumentWorkspace.DeleteFieldOfView)
- this.activeDocumentWorkspace.MergeFieldOfView = true;
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
- }
- }
- public AppWorkspace(Form form)
- {
- SuspendLayout();
- InitializeComponent();
- InitializeFloatingForms();
- this.toolBar.AppWorkspace = this;
- this.widgets = new WorkspaceWidgets(this);
- this.widgets.StatusBarProgress = this.statusBar;
- this.widgets.DocumentStrip = this.toolBar.DocumentStrip;
- this.Widgets.RuleListForm = this.ruleListForm;
- this.toolBar.DocumentStrip.RelinquishFocus += RelinquishFocusHandler;
- this.toolBar.DocumentStrip.RelinquishFocus += OnToolStripRelinquishFocus;
- this.toolBar.DocumentStrip.DocumentClicked += DocumentStrip_DocumentTabClicked;
- this.toolBar.DocumentStrip.DocumentListChanged += DocumentStrip_DocumentListChanged;
- ResumeLayout();
- PerformLayout();
- this.InitializeBottomEvent();
- }
- private void DocumentStrip_DocumentListChanged(object sender, EventArgs e)
- {
- bool enableThem = (this.widgets.DocumentStrip.DocumentCount != 0);
- this.widgets.RuleListForm.Enabled = enableThem;
- UpdateDocInfoInStatusBar();
- UpdateCursorInfoInStatusBar(0, 0);
- }
- private void InitializeFloatingForms()
- {
- // RuleListForm
- ruleListForm = new RuleListForm(this);
- ruleListForm.RelinquishFocus += RelinquishFocusHandler;
- ruleListForm.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- }
- public event CmdKeysEventHandler ProcessCmdKeyEvent;
- private bool OnToolFormProcessCmdKeyEvent(object sender, ref Message msg, Keys keyData)
- {
- if (ProcessCmdKeyEvent != null)
- {
- return ProcessCmdKeyEvent(sender, ref msg, keyData);
- }
- else
- {
- return false;
- }
- }
- public void SaveSettings()
- {
- this.MostRecentFiles.SaveMruList();
- }
- protected override void OnLoad(EventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- this.ActiveDocumentWorkspace.Select();
- }
- base.OnLoad(e);
- }
- private void RelinquishFocusHandler(object sender, EventArgs e)
- {
- this.Focus();
- }
- private void InitializeComponent()
- {
- this.panelBottom = new PanelBottom();
- this.toolBar = new PdnToolBar(this);
- this.statusBar = new PdnStatusBar();
- this.toolsPanel = new ToolsControl(this);
- this.workspacePanel = new Panel();
- this.workspacePanel.SuspendLayout();
- this.statusBar.SuspendLayout();
- this.SuspendLayout();
- //
- // panelBottom
- //
- this.panelBottom.Height = 30;
- this.panelBottom.Dock = DockStyle.Bottom;
- //
- // toolBar
- //
- this.toolBar.Name = "toolBar";
- this.toolBar.Dock = DockStyle.Top;
- //
- // statusBar
- //
- this.statusBar.Name = "statusBar";
- //
- // toolsPanel
- //
- this.toolsPanel.Width = 50;
- this.toolsPanel.Dock = DockStyle.Left;
- //
- // workspacePanel
- //
- this.workspacePanel.Name = "workspacePanel";
- this.workspacePanel.Dock = DockStyle.Fill;
- //
- // AppWorkspace
- //
- this.Controls.Add(this.workspacePanel);
- this.Controls.Add(this.panelBottom);
- this.Controls.Add(this.toolsPanel);
- this.Controls.Add(this.statusBar);
- this.Controls.Add(this.toolBar);
- this.Name = "AppWorkspace";
- this.Size = new System.Drawing.Size(872, 640);
- this.workspacePanel.ResumeLayout(false);
- this.statusBar.ResumeLayout(false);
- this.statusBar.PerformLayout();
- this.ResumeLayout(false);
- }
- private void DocumentStrip_DocumentTabClicked(
- object sender,
- EventArgs<Pair<DocumentWorkspace, DocumentClickAction>> e)
- {
- switch (e.Data.Second)
- {
- case DocumentClickAction.Select:
- this.ActiveDocumentWorkspace = e.Data.First;
- break;
- case DocumentClickAction.Close:
- CloseWorkspaceAction cwa = new CloseWorkspaceAction(e.Data.First);
- PerformAction(cwa);
- break;
- default:
- throw new NotImplementedException("Code for DocumentClickAction." + e.Data.Second.ToString() + " not implemented");
- }
- Update();
- }
- private void OnToolStripMouseWheel(object sender, MouseEventArgs e)
- {
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.PerformMouseWheel((Control)sender, e);
- }
- }
- private void OnToolStripRelinquishFocus(object sender, EventArgs e)
- {
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.Focus();
- }
- }
- private void DocumentMouseEnterHandler(object sender, EventArgs e)
- {
- }
- private void DocumentMouseLeaveHandler(object sender, EventArgs e)
- {
- }
- private void DocumentMouseUpHandler(object sender, MouseEventArgs e)
- {
- }
- private void DocumentMouseDownHandler(object sender, MouseEventArgs e)
- {
- }
- private void DocumentMouseMoveHandler(object sender, MouseEventArgs e)
- {
- UpdateCursorInfoInStatusBar(e.X, e.Y);
- }
- private void DocumentClick(object sender, EventArgs e)
- {
- }
- private void DocumentKeyPress(object sender, KeyPressEventArgs e)
- {
- }
- private void DocumentKeyDown(object sender, KeyEventArgs e)
- {
- }
- private void DocumenKeyUp(object sender, KeyEventArgs e)
- {
- }
- public void PerformAction(AppWorkspaceAction performMe)
- {
- Update();
- using (new WaitCursorChanger(this))
- {
- performMe.PerformAction(this);
- }
- Update();
- }
- private void ToolChangingHandler(object sender, EventArgs e)
- {
- UI.SuspendControlPainting(this.toolBar);
- }
- private void ToolChangedHandler(object sender, EventArgs e)
- {
- UpdateStatusBarContextStatus();
- UI.ResumeControlPainting(this.toolBar);
- this.toolBar.Refresh();
- }
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- }
- private void DocumentWorkspace_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
- {
- OnScroll(e);
- }
- private void DocumentWorkspace_Layout(object sender, LayoutEventArgs e)
- {
- }
- /*private void DocumentWorkspace_ZoomBasisChanged(object sender, EventArgs e)
- {
- if (this.toolBar.ViewConfigStrip.ZoomBasis != this.ActiveDocumentWorkspace.ZoomBasis)
- {
- this.toolBar.ViewConfigStrip.ZoomBasis = this.ActiveDocumentWorkspace.ZoomBasis;
- }
- }*/
- private void DocumentWorkspace_RulersEnabledChanged(object sender, EventArgs e)
- {
- PerformLayout();
- }
- public void ViewConfigStrip_UnitsChanged(object sender, EventArgs e)
- {
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.Units = this.Units;
- }
- UpdateDocInfoInStatusBar();
- this.statusBar.CursorInfoText = string.Empty;
- OnUnitsChanged();
- }
- public event EventHandler StatusChanged;
- private void OnStatusChanged()
- {
- if (StatusChanged != null)
- {
- StatusChanged(this, EventArgs.Empty);
- }
- }
- private void OnDocumentWorkspaceStatusChanged(object sender, EventArgs e)
- {
- OnStatusChanged();
- UpdateStatusBarContextStatus();
- }
- private void UpdateStatusBarContextStatus()
- {
- if (ActiveDocumentWorkspace != null)
- {
- this.statusBar.ContextStatusText = this.activeDocumentWorkspace.StatusText;
- this.statusBar.ContextStatusImage = this.activeDocumentWorkspace.StatusIcon;
- }
- else
- {
- this.statusBar.ContextStatusText = string.Empty;
- this.statusBar.ContextStatusImage = null;
- }
- }
- public bool CreateBlankDocumentInNewWorkspace(Size size, MeasurementUnit dpuUnit, double dpu, bool isInitial)
- {
- DocumentWorkspace dw1 = this.activeDocumentWorkspace;
- if (dw1 != null)
- {
- dw1.SuspendRefresh();
- }
- try
- {
- Document untitled = new Document(size.Width, size.Height);
- untitled.DpuUnit = dpuUnit;
- untitled.DpuX = dpu;
- untitled.DpuY = dpu;
- using (new WaitCursorChanger(this))
- {
- bool focused = false;
- if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.Focused)
- {
- focused = true;
- }
- untitled.surface = new Surface(new Size(size.Width, size.Height));
- untitled.surface.Clear(ColorBgra.FromBgra(255, 255, 255, 255));
- DocumentWorkspace dw = this.AddNewDocumentWorkspace();
- this.Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
- dw.SuspendRefresh();
- try
- {
- dw.Document = untitled;
- }
- catch (OutOfMemoryException)
- {
- Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory"));
- RemoveDocumentWorkspace(dw);
- untitled.Dispose();
- return false;
- }
- this.ActiveDocumentWorkspace = dw;
- dw.SetDocumentSaveOptions(null);
- dw.Document.Dirty = false;
- dw.ResumeRefresh();
- if (isInitial)
- {
- this.initialWorkspace = dw;
- }
- if (focused)
- {
- this.ActiveDocumentWorkspace.Focus();
- }
- this.Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
- }
- }
- finally
- {
- if (dw1 != null)
- {
- dw1.ResumeRefresh();
- }
- }
- return true;
- }
- public bool OpenFilesInNewWorkspace(string[] fileNames)
- {
- if (IsDisposed)
- {
- return false;
- }
- bool result = true;
- foreach (string fileName in fileNames)
- {
- result &= OpenFileInNewWorkspace(fileName);
- if (!result)
- {
- break;
- }
- }
- return result;
- }
- #region 标尺相关
- /// <summary>
- /// 刷新标尺列表
- /// </summary>
- public void RefueshRuleList()
- {
- if (this.widgets.RuleListForm != null)
- {
- this.widgets.RuleListForm.InitListViewData();
- }
- }
- /// <summary>
- /// 激活理论比例尺
- /// </summary>
- public void ActivateTemporaryRuler()
- {
- if (this.widgets.RuleListForm != null)
- {
- this.widgets.RuleListForm.ActivateTemporaryRuler();
- }
- }
- /// <summary>
- /// 设置当前选中标尺
- /// </summary>
- /// <param name="index"></param>
- public void SetActiveRulerIndex(int index)
- {
- if (this.widgets.RuleListForm != null)
- {
- this.widgets.RuleListForm.SetActiveRulerIndex(index);
- }
- }
- /// <summary>
- /// 刷新当前选中的标尺-编辑后使用
- /// </summary>
- public void RefreshActiveRuler()
- {
- if (this.widgets.RuleListForm != null)
- {
- this.widgets.RuleListForm.RefreshActiveRuler();
- }
- }
- #endregion
- public bool OpenFileInNewWorkspace(string fileName)
- {
- return OpenFileInNewWorkspace(fileName, true);
- }
- /// <summary>
- /// 需要修改
- /// (1)判断是否有同名的xml文件,有则读取并处理
- /// (2)判断是否识别其它标尺,有则读取
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="addToMruList"></param>
- /// <returns></returns>
- public bool OpenFileInNewWorkspace(string fileName, bool addToMruList)
- {
- if (fileName == null)
- {
- throw new ArgumentNullException("fileName");
- }
- if (fileName.Length == 0)
- {
- throw new ArgumentOutOfRangeException("fileName.Length == 0");
- }
- PdnBaseForm.UpdateAllForms();
- Document document;
- this.widgets.StatusBarProgress.ResetProgressStatusBar();
- ProgressEventHandler progressCallback =
- delegate (object sender, ProgressEventArgs e)
- {
- this.widgets.StatusBarProgress.SetProgressStatusBar(e.Percent);
- };
- document = DocumentWorkspace.LoadDocument(this, fileName, progressCallback);
- this.widgets.StatusBarProgress.EraseProgressStatusBar();
- if (document == null)
- {
- this.Cursor = Cursors.Default;
- }
- else
- {
- using (new WaitCursorChanger(this))
- {
- DocumentWorkspace dw = AddNewDocumentWorkspace();
- Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
- try
- {
- dw.Document = document;
- }
- catch (OutOfMemoryException)
- {
- Utility.ErrorBox(this, PdnResources.GetString("LoadImage.Error.OutOfMemoryException"));
- RemoveDocumentWorkspace(dw);
- document.Dispose();
- return false;
- }
- //判断是否存在xml,进行读取
- PicConfigModel configModel = null;
- try
- {
- string path = Path.GetDirectoryName(fileName);
- string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
- //如果xml存在
- if (System.IO.File.Exists(xmlPath))
- {
- configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
- dw.RuleAttribute(configModel);
- }
- //如果不存在,则判断
- //(1)是否自动添加ZEN标尺
- //(2)是否自动添加AxioVision标尺
- else
- {
- dw.xmlSaveModel = Program.instance.ruleDB;
- dw.InitRulerInfo();
- }
- }
- catch (Exception)
- {
- }
- dw.SetDocumentSaveOptions(fileName);
- this.ActiveDocumentWorkspace = dw;
- document.Dirty = false;
- Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
- }
- if (document != null)
- {
- if (isLockZoom && lockScaleRatio > 0)
- {
- ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(lockScaleRatio);
- }
- else
- {
- ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- }
- if (addToMruList)
- {
- ActiveDocumentWorkspace.AddToMruList();
- }
- }
- if (ActiveDocumentWorkspace != null)
- {
- ActiveDocumentWorkspace.Focus();
- }
- return document != null;
- }
- #region 底部公共按钮
- /// <summary>
- /// 初始化底部按钮的各种事件
- /// </summary>
- private void InitializeBottomEvent()
- {
- //缩小按钮
- this.PanelBottom.zoomOutButton.Click += new EventHandler(ZoomOutButton_Click);
- //放大按钮
- this.PanelBottom.zoomInButton.Click += new EventHandler(zoomInButton_Click);
- //放大缩小拖动条事件
- this.PanelBottom.trackBar.ValueChanged += new EventHandler(PanelBottom_trackBar_ValueChanged);
- //缩放缩小倍数的改变事件
- this.PanelBottom.textBox.TextChanged += new EventHandler(PanelBottom_textBox_ValueChanged);
- }
- public void SetZoonTrackValue(ScaleFactor newValue)
- {
- this.panelBottom.trackBar.Maximum = 6200;// (int)(ScaleFactor.MaxValue.Ratio * 100);
- if (newValue != null)
- {
- this.PanelBottom.trackBar.ValueChanged -= this.PanelBottom_trackBar_ValueChanged;
- double v = newValue.Ratio * 100;
- if (v <= 100)
- {
- this.PanelBottom.trackBar.Value = (int)(31 * v);
- }
- else
- {
- double x = 3100 + newValue.Ratio * 100;
- if (x > 6200) x = 6200;
- this.PanelBottom.trackBar.Value = (int)x;
- }
- this.PanelBottom.trackBar.ValueChanged += new EventHandler(this.PanelBottom_trackBar_ValueChanged);
- }
- //设置底部缩放比例的百分比textbox的值
- this.PanelBottom.textBox.TextChanged -= new EventHandler(PanelBottom_textBox_ValueChanged);
- this.PanelBottom.textBox.Text = newValue.ToString();
- this.PanelBottom.textBox.TextChanged += new EventHandler(PanelBottom_textBox_ValueChanged);
- }
- /// <summary>
- /// 最佳
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BestButton_Click(object sender, MouseEventArgs e)
- {
- }
- /// <summary>
- /// 从直方图更新选中状态
- /// </summary>
- /// <param name="selected"></param>
- public void MaxMinBest(bool best, bool maxMin, bool origin, bool gamma45)
- {
- this.activeDocumentWorkspace.best = best;
- this.activeDocumentWorkspace.maxMin = maxMin;
- this.activeDocumentWorkspace.origin = origin;
- this.activeDocumentWorkspace.gamma45 = gamma45;
- }
- /// <summary>
- /// 最大最小
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MaxMinButton_Click(object sender, MouseEventArgs e)
- {
- }
- /// <summary>
- /// 原始状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OriginButton_Click(object sender, MouseEventArgs e)
- {
- }
- /// <summary>
- /// 伽马0.45
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Gamma45Button_Click(object sender, MouseEventArgs e)
- {
- }
- /// <summary>
- /// 更新底部按钮选中状态
- /// </summary>
- public void UpdateBottomButtonSelectionStatus()
- {
- if (this.ActiveDocumentWorkspace == null)
- return;
- }
- /// <summary>
- /// 底部快捷栏 辅助线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void AuxiliaryLineButton_Click(object sender, MouseEventArgs e)
- {
- }
- /// <summary>
- /// 水平镜像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void HorizontalMirroringButton_Click(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 垂直镜像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void VerticalMirrorButton_Click(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 中心镜像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void CenterMirrorButton_Click(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 底部快捷栏 缩小事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ZoomOutButton_Click(object sender, EventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- this.ActiveDocumentWorkspace.ZoomOut();
- this.activeDocumentWorkspace.ActualSize = false;
- this.activeDocumentWorkspace.SuitableSize = false;
- this.activeDocumentWorkspace.SuitableHeight = false;
- this.activeDocumentWorkspace.SuitableWidth = false;
- this.SetTopLeftCheckState();
- this.UpdateBottomButtonSelectionStatus();
- }
- }
- /// <summary>
- /// 底部快捷栏 放大事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void zoomInButton_Click(object sender, EventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- this.ActiveDocumentWorkspace.ZoomIn();
- this.activeDocumentWorkspace.ActualSize = false;
- this.activeDocumentWorkspace.SuitableSize = false;
- this.activeDocumentWorkspace.SuitableHeight = false;
- this.activeDocumentWorkspace.SuitableWidth = false;
- this.SetTopLeftCheckState();
- this.UpdateBottomButtonSelectionStatus();
- }
- }
- /// <summary>
- /// 底部方法缩小拖动条事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PanelBottom_trackBar_ValueChanged(object sender, EventArgs e)
- {
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- if (this.PanelBottom.trackBar.Tag == null)
- {
- int v = this.PanelBottom.trackBar.Value;
- if (this.PanelBottom.trackBar.Value <= 3100)
- {
- this.PanelBottom.trackBar.SmallChange = 31;
- v = this.PanelBottom.trackBar.Value / 31;
- }
- else
- {
- this.PanelBottom.trackBar.SmallChange = 100;
- v = 100 + this.PanelBottom.trackBar.Value - 3100;
- }
- this.activeDocumentWorkspace.ScaleFactor = new ScaleFactor(v, 100);
- this.PanelBottom.trackBar.Tag = this.PanelBottom.trackBar.Value;
- }
- else
- {
- int oldValue = (int)this.PanelBottom.trackBar.Tag;
- if (oldValue != this.PanelBottom.trackBar.Value)
- {
- int v = this.PanelBottom.trackBar.Value;
- if (this.PanelBottom.trackBar.Value <= 3100)
- {
- this.PanelBottom.trackBar.SmallChange = 31;
- v = this.PanelBottom.trackBar.Value / 31;
- }
- else
- {
- this.PanelBottom.trackBar.SmallChange = 100;
- v = 100 + this.PanelBottom.trackBar.Value - 3100;
- }
- this.activeDocumentWorkspace.ScaleFactor = new ScaleFactor(v, 100);
- this.PanelBottom.trackBar.Tag = this.PanelBottom.trackBar.Value;
- }
- }
- }
- }
- private void PanelBottom_textBox_ValueChanged(object sender, EventArgs e)
- {
- int v;
- if (!string.IsNullOrEmpty(this.PanelBottom.textBox.Text) &&
- !this.PanelBottom.textBox.Text.Equals("%") &&
- int.TryParse(this.PanelBottom.textBox.Text.Replace("%", ""), out v))
- {
- if (v > this.PanelBottom.trackBar.Maximum) v = this.PanelBottom.trackBar.Maximum;
- if (v < this.PanelBottom.trackBar.Minimum) v = this.PanelBottom.trackBar.Minimum;
- if (v <= 100)
- {
- this.PanelBottom.trackBar.Value = v;
- }
- else
- {
- int x = 3000 + v;
- if (x > 6100) x = 6200;
- this.PanelBottom.trackBar.Value = x;
- }
- }
- }
- private bool ExistenceXML()
- {
- if (this.activeDocumentWorkspace != null)
- {
- return true;
- }
- //获取图片路径
- bool existenceXML = false;
- if (this.activeDocumentWorkspace != null)
- {
- string fileName;
- this.activeDocumentWorkspace.GetDocumentSaveOptions(out fileName);
- if (fileName != null)
- {
- string path = Path.GetDirectoryName(fileName);
- string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
- existenceXML = System.IO.File.Exists(xmlPath);
- if (existenceXML)
- {
- }
- }
- }
- return existenceXML;
- }
- public Dictionary<MeasurementUnit, double> getMeasureInfo()
- {
- if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.rules != null && this.ActiveDocumentWorkspace.rules.Count > 0)
- return this.ActiveDocumentWorkspace.rules;
- else
- return Program.instance.rules;
- }
- #endregion
- #region [测量相关]
- public DrawToolType GetDrawToolType()
- {
- return activeTool;
- }
- public void SetDrawToolType(DrawToolType t)
- {
- activeTool = t;
- }
- public void SetDrawNodes()
- {
- //if (this.measureListDialog != null)
- // this.measureListDialog.SetDrawNodes(null, null);
- }
- public void RefreshListView()
- {
- //if (this.measureListDialog != null)
- // this.measureListDialog.RefreshListView(null, null);
- //this.Refresh();
- }
- /// <summary>
- /// 像素跟踪
- /// 需要增加标记,在进行比如图像旋转等直接在当前
- /// 面板进行图像大小变化操作的,需要停止像素跟踪,
- /// 处理完成之后在恢复,否则可能会导致读取内存异常
- /// </summary>
- /// <param name="location"></param>
- public void SetImageAndData(Point location)
- {
- //if (this.pixelTrackingDialog != null)
- //{
- // this.pixelTrackingDialog.SetImageAndData(location);
- //}
- }
- /// <summary>
- /// 获取系统当前选中单位及每单位像素值
- /// </summary>
- /// <returns>3位字符串数组,
- /// 0:系统选中单位枚举字符串
- /// 1:系统选中单位名称字符串
- /// 2:系统选中单位符号字符串
- /// 3:系统选中单位每单位像素长度
- /// 4:系统选中单位每单位物理长度
- /// </returns>
- public string[] GetPxPerUnit()
- {
- if (this.activeDocumentWorkspace != null)
- return this.activeDocumentWorkspace.getRulerList();
- else
- {
- string[] result = new string[5];
- result[0] = Program.instance.measurementUnit.ToString();
- result[1] = InvariantData.unitsDictionary[(int)Program.instance.measurementUnit];
- result[2] = InvariantData.unitSymbolsDictionary[(int)Program.instance.measurementUnit];
- result[3] = (Program.instance.rules[Program.instance.measurementUnit]).ToString();
- result[4] = (Program.instance.rules[MeasurementUnit.Micron]).ToString();
- return result;
- }
- }
- /// <summary>
- /// 获取测量样式配置
- /// </summary>
- /// <returns></returns>
- public MeasureStyleModel GetMeasureStyleModel()
- {
- return Program.instance.measureStyleModel;
- }
- public void SetContinuousDrawingMeasure(bool value)
- {
- this.continuousDrawingMeasure = value;
- SetTopLeftCheckState();
- }
- public void SetContinuousDrawingView(bool value)
- {
- this.continuousDrawingView = value;
- }
- /// <summary>
- /// 获取当前激活的图像工作空间的视场行为
- /// 合并/剪切
- /// </summary>
- /// <returns></returns>
- public CombineMode GetCombineMode()
- {
- return this.ActiveDocumentWorkspace.CombineMode;
- }
- public RectangleF GetVisibleDocumentRectangleF()
- {
- return this.activeDocumentWorkspace.VisibleDocumentRectangleF;
- }
- public SizeF GetDocumentSize()
- {
- return this.activeDocumentWorkspace.Document.Size;
- }
- /// <summary>
- /// 更新命名的延续数字
- /// </summary>
- public void UpdateContinueNum()
- {
- if (Program.instance.configModel != null)
- {
- ConfigModel configModel = Program.instance.configModel;
- configModel.ContinueNum++;
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
- string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml";
- FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
- }
- }
- /// <summary>
- /// 获取测量区域样式配置
- /// </summary>
- /// <returns></returns>
- public MeasureAreaModel GetMeasureAreaModel()
- {
- return Program.instance.measureAreaModel;
- }
- #endregion
- /// <summary>
- /// 递归查询树状数据
- /// </summary>
- /// <param name="id"></param>
- /// <param name="originalData"></param>
- /// <param name="data"></param>
- public void RecursionGetData(string id, List<MeasureMaintenanceTreeSpecificData> originalData, out MeasureMaintenanceTreeSpecificData data)
- {
- data = originalData.Where(m => m.MeasureMaintenanceTreeSpecificDataId.Equals(id)).FirstOrDefault();
- if (data == null)
- {
- foreach (var item in originalData)
- {
- if (id.Equals("0")) {
- break;
- }
- RecursionGetData(id, item.MeasureMaintenanceTreeSpecificSonDataList, out data);
- if (data != null)
- {
- break;
- }
- }
- }
- }
- /// <summary>
- /// 根据别名查询实际名称
- /// </summary>
- /// <param name="id"></param>
- /// <param name="originalData"></param>
- /// <param name="data"></param>
- public string getRealName(List<MeasureMaintenanceTreeSpecificData> originalData,string aliasName)
- {
- foreach (var item in originalData)
- {
- foreach (var item2 in item.MeasureMaintenanceTreeSpecificSonDataList)
- {
- var data = item2.MeasureMaintenanceTreeSpecificFormulaDataList.Where(m => m.FormulaParameterAliasName == aliasName).FirstOrDefault();
- if (data == null)
- {
- continue;
- }
- return data.FormulaParameterName;
- }
- }
- return string.Empty;
- }
- public void setUnitNum(double unit)
- {
- this.unitNum = unit;
- }
- public double getUnitNum()
- {
- return this.unitNum;
- }
- public string getAliasName()
- {
- return this.aliasName;
- }
- public void setAliasName(string name)
- {
- this.aliasName = name;
- }
- public int getDecimalPlaces()
- {
- return Program.instance.decimalPlaces;
- }
-
- }
- }
|