using IWshRuntimeLibrary;
using Metis.Measuring;
using PaintDotNet.Actions;
using PaintDotNet.Annotation;
using PaintDotNet.Annotation.Enum;
using PaintDotNet.Base;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Base.Functionodel;
using PaintDotNet.Base.SettingModel;
using PaintDotNet.CustomControl;
using PaintDotNet.DbOpreate.DbBll;
using PaintDotNet.DbOpreate.DbModel;
using PaintDotNet.DedicatedAnalysis.DuctileIron.Common;
using PaintDotNet.ImageCollect;
using PaintDotNet.ImageLabel;
using PaintDotNet.Instrument;
using PaintDotNet.Measuring;
using PaintDotNet.SystemLayer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
using static PaintDotNet.Base.Functionodel.ZipXmlModel;
using MSWord = Microsoft.Office.Interop.Word;
using MSExcel = Microsoft.Office.Interop.Excel;
namespace PaintDotNet
{
internal class AppWorkspace : UserControl, ISnapObstacleHost, IAppWorkspaceForSurfaceBox
{
#region 控件
///
/// 顶部菜单和工具栏
///
public PdnToolBar toolBar;
///
/// 底部公用工具栏
///
private PanelBottom panelBottom;
///
/// 主界面左侧的快捷工具栏
///
public ToolsControl toolsPanel;
///
/// 包含DocumentWorkspace集合的panel
///
public Panel workspacePanel;
///
/// 底部状态栏
///
private PdnStatusBar statusBar;
///
/// 要删除的工作空间位置(避免批量保存有修改的图片时关闭的工作空间位置与for循环顺序不一致)
///
public int toRemoveDocumentWorkspaceIndex = -1;
///
/// 图像索引窗口控制状态 -1代表activeDocumentWorkspace无变化 1、2代表进行了添加或者删除操作,需要刷新图像索引窗口内容
///
public int toInitImageIndexDialogFlag = -1;
///
/// 当前激活的工作空间
///
private DocumentWorkspace activeDocumentWorkspace;
///
/// 如果添加了新的工作空间,并且该工作空间没有被修改,则将其删除。
/// 这将通过CreateBlankDocumentInNewWorkspace添加的最后一个工作空间确定
/// (如果为第二个参数传递了true)
///
private DocumentWorkspace initialWorkspace;
///
/// 标尺标定窗口
///
private RuleListForm ruleListForm;
///
/// 像素跟踪窗口
///
private PixelTrackingDialog pixelTrackingDialog;
///
/// 图像索引窗口
///
private ImageIndexDialog imageIndexDialog;
///
/// 交互测量
///
private GeometryMeasureDialog geometryMeasureDialog;
///
/// 脚本执行跟踪窗口
///
private ScriptRunningDialog runningDialog;
///
/// 直方图窗口
///
private HistogramDialog histogramDialog;
///
/// 脚本管理窗口
///
private ScriptManageDialog scriptManageDialog;
///
/// 划痕处理窗口
///
private ScratchTreatmentDialog scratchTreatmentDialog;
///
/// 污迹处理窗口
///
private SmudgeTreatmentDialog smudgeTreatmentDialog;
///
/// 标注列表窗口
///
private LabelListDialog labelListDialog;
///
/// 工作流程窗口
///
public WorkFlowDialog workFlowDialog;
///
/// 测量列表窗口
///
public MeasureListDialog measureListDialog;
///
/// 光密度窗口
///
public OpticalDensityDialog opticalDensityDialog;
///
/// 项目工程窗口
///
public ProjectEngineering projectEngineering;
///
/// 图像预览窗口
///
public CameraPreviewDialog cameraPreviewDialog;
#endregion
///
/// 工作空间集合,打开的图像
///
private List documentWorkspaces = new List();
///
/// 保存了许多可浮动的窗口,为了统一管理,供外部调用
///
private WorkspaceWidgets widgets;
///
/// 最近打开的文件
///
private MostRecentFiles mostRecentFiles = null;
///
/// 最近打开的文件的最大默认数量
///
private const int defaultMostRecentFilesMax = 8;
private SnapObstacleController snapObstacle;
private bool addedToSnapManager = false;
private int ignoreUpdateSnapObstacle = 0;
//private XmlSaveModel xmlSaveModel;
///
/// 是否循环播放
///
private bool isLoopPlayback = false;
///
/// 播放模式 1.后到前;2.前到后
///
private int playMode = 2;
///
/// 播放使用的定时器
///
private Timer timer;
///
/// 锁定扩缩标记
///
public bool isLockZoom = false;
///
/// 锁定扩缩的百分比
///
public double lockScaleRatio = 0;
///
/// 当前是否自动运行着脚本
///
private bool scriptAutomatic = false;
///
/// 当前是否运行着脚本
///
private bool scriptRunning = false;
///
/// 当前是否等待着脚本继续执行
///
private bool scriptStopping = false;
private Form form;
///
/// 测量连续绘制
///
public bool continuousDrawingMeasure = false;
///
/// 标记连续绘制
///
public bool continuousDrawingLabel = false;
public DrawToolType drawToolType = DrawToolType.Pointer;
///
/// 录制脚本时带入的
///
public List micScriptStepList = new List();
public Dictionary> micScriptStepParamList = new Dictionary>();
///
/// 录制脚本时添加的
///
public List addMicScriptStepList = new List();
public Dictionary> addMicScriptStepParamList = new Dictionary>();
///
/// 是否开启脚本录制
///
public bool startScriptRecording = false;
///
/// 脚本录制是否编辑
///
public bool editScriptRecording = false;
///
/// 脚本录制是否编辑
///
public mic_script ScriptRecordingModel;
public PanelBottom PanelBottom
{
get
{
return this.panelBottom;
}
}
public bool ScriptAutomatic
{
get
{
return this.scriptAutomatic;
}
set
{
this.scriptAutomatic = value;
}
}
public bool ScriptRunning
{
get
{
return this.scriptRunning;
}
set
{
this.scriptRunning = value;
}
}
public void SetScriptRunning(Boolean value)
{
this.scriptRunning = value;
}
public bool GetScriptRunning()
{
return this.scriptRunning;
}
public bool ScriptStopping
{
get
{
return this.scriptStopping;
}
set
{
this.scriptStopping = value;
//if (value == false)
// this.ResumeScriptRunning();
}
}
public void SetScriptStopping(Boolean value)
{
this.ScriptStopping = value;
}
public bool GetScriptStopping()
{
return this.scriptStopping;
}
public Data.Param.ParamObject ScriptCurrentParam
{
set
{
if (this.ScriptDialog != null) this.ScriptDialog.ScriptCurrentParam = value;
}
get
{
if (this.ScriptDialog != null) return this.ScriptDialog.ScriptCurrentParam;
else return null;
}
}
public void ShutDownScriptRunning()
{
if (this.ScriptDialog != null) this.ScriptDialog.ShutDownScriptRunning();
}
public void ResumeScriptRunning()
{
if (this.ScriptDialog != null/* && !this.ScriptDialog.IsDisposed*/) this.ScriptDialog.ResumeScriptRunning();
}
private void DocumentWorkspace_DrawGridChanged(object sender, EventArgs e)
{
DrawGrid = this.activeDocumentWorkspace.DrawGrid;
}
/*private void ViewConfigStrip_DrawGridChanged(object sender, EventArgs e)
{
DrawGrid = ((ViewConfigStrip)sender).DrawGrid;
}*/
///
/// 绘制像素网格的flag
///
private bool DrawGrid
{
get
{
return false;// this.Widgets.ViewConfigStrip.DrawGrid;
}
set
{
if (this.Widgets.ViewConfigStrip.DrawGrid != value)
{
this.Widgets.ViewConfigStrip.DrawGrid = value;
}
if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.DrawGrid != value)
{
this.activeDocumentWorkspace.DrawGrid = value;
}
Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, this.DrawGrid);
}
}
///
/// 单位改变事件
///
public event EventHandler UnitsChanged;
protected virtual void OnUnitsChanged()
{
if (UnitsChanged != null)
{
UnitsChanged(this, EventArgs.Empty);
}
}
public MeasurementUnit Units
{
get
{
return Startup.instance.measurementUnit;//this.widgets.ViewConfigStrip.Units;
}
set
{
//this.widgets.ViewConfigStrip.Units = value;
}
}
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 SuspendUpdateSnapObstacle()
{
++this.ignoreUpdateSnapObstacle;
}
private void ResumeUpdateSnapObstacle()
{
--this.ignoreUpdateSnapObstacle;
}
///
/// 更新快照
///
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;
}
}
}
private void AppWorkspace_Shown(object sender, EventArgs e)
{
UpdateSnapObstacle();
}
protected override void OnLayout(LayoutEventArgs levent)
{
UpdateSnapObstacle();
base.OnLayout(levent);
}
protected override void OnLocationChanged(EventArgs e)
{
UpdateSnapObstacle();
base.OnLocationChanged(e);
}
protected override void OnSizeChanged(EventArgs e)
{
UpdateSnapObstacle();
base.OnSizeChanged(e);
}
protected override void OnEnabledChanged(EventArgs e)
{
UpdateSnapObstacle();
base.OnEnabledChanged(e);
}
protected override void OnVisibleChanged(EventArgs e)
{
UpdateSnapObstacle();
base.OnVisibleChanged(e);
}
public void ResetFloatingForms()
{
ResetFloatingForm(Widgets.RuleListForm);
ResetFloatingForm(Widgets.PixelTrackingDialog);
ResetFloatingForm(Widgets.ImageIndexDialog);
ResetFloatingForm(Widgets.GeometryMeasureDialog);
ResetFloatingForm(Widgets.RunningDialog);
ResetFloatingForm(Widgets.HistogramDialog);
ResetFloatingForm(Widgets.ScratchTreatmentDialog);
ResetFloatingForm(Widgets.SmudgeTreatmentDialog);
ResetFloatingForm(Widgets.LabelListDialog);
ResetFloatingForm(Widgets.WorkFlowDialog);
ResetFloatingForm(Widgets.MeasureListDialog);
ResetFloatingForm(Widgets.OpticalDensityDialog);
ResetFloatingForm(Widgets.ProjectEngineering);
}
public void ResetFloatingForm(FloatingToolForm ftf)
{
SnapManager sm = SnapManager.FindMySnapManager(this);
if (ftf == Widgets.RuleListForm)
{
sm.ParkObstacle(Widgets.RuleListForm, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.PixelTrackingDialog)
{
sm.ParkObstacle(Widgets.PixelTrackingDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.ImageIndexDialog)
{
sm.ParkObstacle(Widgets.ImageIndexDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.GeometryMeasureDialog)
{
sm.ParkObstacle(Widgets.GeometryMeasureDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.RunningDialog)
{
sm.ParkObstacle(Widgets.RunningDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.HistogramDialog)
{
sm.ParkObstacle(Widgets.HistogramDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.ScratchTreatmentDialog)
{
sm.ParkObstacle(Widgets.ScratchTreatmentDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.SmudgeTreatmentDialog)
{
sm.ParkObstacle(Widgets.SmudgeTreatmentDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.LabelListDialog)
{
sm.ParkObstacle(Widgets.LabelListDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.WorkFlowDialog)
{
sm.ParkObstacle(Widgets.WorkFlowDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.MeasureListDialog)
{
sm.ParkObstacle(Widgets.MeasureListDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.OpticalDensityDialog)
{
sm.ParkObstacle(Widgets.OpticalDensityDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
}
else if (ftf == Widgets.ProjectEngineering)
{
sm.ParkObstacle(Widgets.ProjectEngineering, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
}
else
{
throw new ArgumentException();
}
}
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 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);
}
///
/// 更新右下角坐标信息
///
///
///
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);
}
///
/// 更新底部状态栏的文字等
/// 需要修改为显示标尺相关的信息
///
public void UpdateDocInfoInStatusBar()
{
if (this.activeDocumentWorkspace != null)
{
if (this.activeDocumentWorkspace.xmlSaveModel == null)
{
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 = Startup.instance.ruleDB.ruler_name;
this.statusBar.CursorInfoText = Math.Round(Startup.instance.rules[(MeasurementUnit)Startup.instance.ruleDB.ruler_units], 4) + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), Startup.instance.ruleDB.ruler_units)))].ToString() + "/" + PdnResources.GetString("Menu.Pixel.text");
}
}
}
/*if (this.activeDocumentWorkspace == null ||
this.activeDocumentWorkspace.Document == null)
{
this.statusBar.ImageInfoStatusText = string.Empty;
}
else if (this.activeDocumentWorkspace != null &&
this.activeDocumentWorkspace.Document != null)
{
string widthString;
string heightString;
string units;
CoordinatesToStrings(
this.activeDocumentWorkspace.Document.Width,
this.activeDocumentWorkspace.Document.Height,
out widthString,
out heightString,
out units);
string imageText = string.Format(
CultureInfo.InvariantCulture,
this.imageInfoStatusBarFormat,
widthString,
units,
heightString,
units);
this.statusBar.ImageInfoStatusText = imageText;
}*/
}
///
/// 更新像素跟踪的图像
///
private void UpdatePixelTracking()
{
if (this.pixelTrackingDialog != null)
{
this.pixelTrackingDialog.Mat = null;
}
}
[Browsable(false)]
public WorkspaceWidgets Widgets
{
get
{
return this.widgets;
}
}
public HistogramDialog Histogram
{
get
{
if (this.histogramDialog != null)
{
return this.histogramDialog;
}
else
{
return null;
}
}
}
public ScriptManageDialog ScriptDialog
{
get
{
if (this.scriptManageDialog != null)
{
return this.scriptManageDialog;
}
else
{
return null;
}
}
set
{
this.scriptManageDialog = value;
}
}
public SmudgeTreatmentDialog SmudgeTreatmentDialog
{
get
{
if (this.smudgeTreatmentDialog != null)
{
return this.smudgeTreatmentDialog;
}
else
{
return null;
}
}
set
{
this.smudgeTreatmentDialog = value;
}
}
public ScratchTreatmentDialog ScratchTreatmentDialog
{
get
{
if (this.scratchTreatmentDialog != null)
{
return this.scratchTreatmentDialog;
}
else
{
return null;
}
}
set
{
this.scratchTreatmentDialog = value;
}
}
[Browsable(false)]
public DocumentWorkspace[] ScriptWorkspaces
{
get
{
List scriptWorkspaces = new List();
for (int index = 0; index < this.documentWorkspaces.Count; index++)
{
DocumentWorkspace workspace = this.documentWorkspaces[index];
if (workspace.OpenInScriptRunning)
{
scriptWorkspaces.Add(workspace);
}
}
if (scriptWorkspaces.Count > 0)
return scriptWorkspaces.ToArray();
else
return null;
}
}
public bool ContinuousDrawing
{
get => DocumentView.ContinuousDrawing;
set
{
DocumentView.ContinuousDrawing = value;
toolBar.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingMeasure");
toolsPanel.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingMeasure");
toolBar.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingLabel");
toolsPanel.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingLabel");
if (ActiveDocumentWorkspace != null && !DocumentView.ContinuousDrawing
&& ActiveDocumentWorkspace.ActiveTool >= DrawToolType.MeasureLine && ActiveDocumentWorkspace.ActiveTool <= DrawToolType.MeasureThreePointArc)
{
ActiveDocumentWorkspace.ToolNumber = -1;
ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
}
toolBar.MainMenu.measureActionMenu.checkMenu(DocumentView.ContinuousDrawing);
toolBar.MainMenu.labelActionMenu.checkMenu(DocumentView.ContinuousDrawing);
if (cameraPreviewDialog != null && !cameraPreviewDialog.IsDisposed)
{
if (!DocumentView.ContinuousDrawing)
{
cameraPreviewDialog.documentWorkspace.ActiveTool = DrawToolType.Pointer;
}
if (ActiveDocumentWorkspace != null
&& ActiveDocumentWorkspace.ActiveTool >= DrawToolType.MeasureLine
&& ActiveDocumentWorkspace.ActiveTool <= DrawToolType.MeasureThreePointArc)
{
ActiveDocumentWorkspace.ToolNumber = -1;
}
}
}
}
public DocumentWorkspace ActiveDocumentWorkspace
{
get
{
return this.activeDocumentWorkspace;
}
set
{
if (this.activeDocumentWorkspace != null)
{
drawToolType = this.activeDocumentWorkspace.ActiveTool;
}
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;
if (this.toInitImageIndexDialogFlag != 2)
{
this.toInitImageIndexDialogFlag = 1;
}
OnActiveDocumentWorkspaceChanged();
this.toInitImageIndexDialogFlag = -1;
UI.ResumeControlPainting(this);
if (this.ContinuousDrawing && value != null)
{
value.ActiveTool = drawToolType;
}
Refresh();
if (value != null)
{
value.Focus();
}
//if (this.histogramDialog != null) this.histogramDialog.ResetMat();
//backupImage
if (value != null && value.needBackup)
{
FileOperationHelper.BackupImages(value.CompositionSurface.CreateAliasedBitmap(), value.GetFriendlyName(), value.FilePath);
value.needBackup = false;
}
}
}
}
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 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.ContinuousDrawingLabel = this.ContinuousDrawing;
dw.ContinuousDrawingMeasure = this.ContinuousDrawing;
if (this.drawToolType == DrawToolType.DrawAutoRuler || this.drawToolType == DrawToolType.DrawPrestoredRuler || this.drawToolType == DrawToolType.DrawDateMark || this.drawToolType == DrawToolType.DrawTimeMark || this.drawToolType == DrawToolType.DrawGainNumber)
{
dw.ActiveTool = DrawToolType.Pointer;
}
else {
dw.ActiveTool = this.drawToolType;
}
this.documentWorkspaces.Add(dw);
this.toolBar.DocumentStrip.AddDocumentWorkspace(dw);
return dw;
}
public DocumentWorkspace NewDocumentWorkspace()
{
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.ContinuousDrawingLabel = this.continuousDrawingLabel;
dw.ContinuousDrawingMeasure = this.continuousDrawingMeasure;
return dw;
}
public bool DisplayShoot(Bitmap image, GraphicsList graphicsList, bool hasRuler, int mode = 0)
{
if (Widgets.ImageIndexDialog.Visible)
{
Startup.instance.configModel.Txt1 = Widgets.ImageIndexDialog.comboBox_T1.Text;
Startup.instance.configModel.Txt2 = Widgets.ImageIndexDialog.comboBox_T2.Text;
Startup.instance.configModel.Txt3 = Widgets.ImageIndexDialog.comboBox_T2.Text;
}
string photoName;
if (Startup.instance.ruleDB == null)
{
photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, "默认标尺", "0", mode);
}
else
{
photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, Startup.instance.ruleDB.ruler_name, Startup.instance.ruleDB.gain_multiple.ToString(), mode);
}
UpdateContinueNum();
Widgets.ImageIndexDialog.PreviewRefresh();
DocumentWorkspace dw = NewDocumentWorkspace();
dw.fileText = photoName;
Document document = Document.FromMat(PaintDotNet.Camera.Tools.ToMat(image));
document.Dirty = true;
dw.Document = document;
//dw.rules = new Dictionary(Startup.instance.rules);
dw.xmlSaveModel = Startup.instance.ruleDB;
dw.InitRulerInfo(); //激活
//如果绘制了标注、测量,则需要深度copy过去
if (graphicsList?.Count > 0)
{
for (int i = 0; i < graphicsList.Count; i++)
{
DrawObject mobject = graphicsList[i].Clone(dw);
mobject.Selected = false;
dw.GraphicsList.Add(mobject);
}
}
//绘制标尺
if (hasRuler)
{
bool needResetDB = false;
decimal oldGainNumber = dw.GetGainMultiple();
Dictionary measurementUnitDictionary = this.getMeasureInfo();
MeasurementUnit unit = this.Units;
double oldRatio = measurementUnitDictionary[unit];//每像素多少长度
//mic_rulers mic_Ruler = (mic_rulers)this.comboBox1.SelectedValue;
mic_rulers mic_Ruler = dw.xmlSaveModel;
if (Startup.instance.ruleDB == null)
{
Startup.instance.ruleDB = new mic_rulers();
needResetDB = true;
}
Startup.instance.ruleDB.gain_multiple = mic_Ruler.gain_multiple;
double micronRatio;
Startup.instance.rules.TryGetValue(unit, out micronRatio);
Startup.instance.rules[unit] = micronRatio;
dw.ActiveTool = Annotation.Enum.DrawToolType.DrawAutoRuler;
dw.Units = unit;
if (needResetDB)
Startup.instance.ruleDB = null;
else
Startup.instance.ruleDB.gain_multiple = oldGainNumber;
Startup.instance.rules[unit] = oldRatio;
}
dw.Refresh();
switch (mode)
{
case 0:
case 2:
Add(dw);
break;
case 1:
return dw.DoSaveAsNew(mode);
case 3:
var result = dw.DoSaveAsNew(mode);
if (!result) return result; Add(dw);
break;
case -1:
dw.fileText = photoName + ".jpg";
dw.picName = dw.fileText;
dw.filePath = Startup.instance.configModel.FilePath != null ? Startup.instance.configModel.FilePath + "\\" + dw.fileText : Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\" + dw.fileText;
return dw.DoSaveNew();
case -3:
dw.fileText = photoName + ".jpg";
dw.UpdateDw2buttonName(dw.fileText);
dw.picName = dw.fileText;
dw.filePath = Startup.instance.configModel.FilePath != null ? Startup.instance.configModel.FilePath + "\\" + dw.fileText : Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\" + dw.fileText;
var res = dw.DoSaveNew();
if (!res) return res; Add(dw);
break;
}
ActiveDocumentWorkspace = dw;
if (isLockZoom && lockScaleRatio > 0)
{
ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(lockScaleRatio);
SetZoonTrackValue(ActiveDocumentWorkspace.ScaleFactor);
}
else
{
ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
}
return true;
}
public void Add(DocumentWorkspace dw)
{
this.documentWorkspaces.Add(dw);
this.toolBar.DocumentStrip.AddDocumentWorkspace(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;
}
this.toInitImageIndexDialogFlag = 2;
// Choose new active DW if removing the current DW
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.toInitImageIndexDialogFlag = 1;
this.documentWorkspaces.Remove(documentWorkspace);
this.toolBar.DocumentStrip.RemoveDocumentWorkspace(documentWorkspace);
//刷新图像索引窗口
if ((this.activeDocumentWorkspace == null || this.activeDocumentWorkspace != null && this.toInitImageIndexDialogFlag == 1)
&& ImageIndexDialog.imageIndexDialog != null)
ImageIndexDialog.imageIndexDialog.InitData();
this.toInitImageIndexDialogFlag = -1;
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()
{
//如果定时器在运行则先关闭
if (timer.Enabled)
timer.Enabled = false;
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.DrawGridChanged -= this.DocumentWorkspace_DrawGridChanged;
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.ScaleFactorChanged -= ZoomChangedHandler;
//this.activeDocumentWorkspace.ZoomBasisChanged -= DocumentWorkspace_ZoomBasisChanged;
this.activeDocumentWorkspace.Visible = false;
this.activeDocumentWorkspace.ToolChanging -= this.ToolChangingHandler;
this.activeDocumentWorkspace.ToolChanged -= this.ToolChangedHandler;
}
ResumeUpdateSnapObstacle();
UpdateSnapObstacle();
}
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.DrawGrid = this.DrawGrid;
this.activeDocumentWorkspace.PanelAutoScroll = true;
this.activeDocumentWorkspace.RulersEnabled = Settings.CurrentUser.GetBoolean(SettingNames.Rulers, true);
this.activeDocumentWorkspace.AuxiliaryLineEnabled = Settings.CurrentUser.GetBoolean(SettingNames.DrawAuxiliaryLine, 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.DrawGridChanged += this.DocumentWorkspace_DrawGridChanged;
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;
bool isLianXu = this.ContinuousDrawing;
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.toolBar.ViewConfigStrip.ScaleFactor = this.activeDocumentWorkspace.ScaleFactor;
//this.toolBar.ViewConfigStrip.ZoomBasis = this.activeDocumentWorkspace.ZoomBasis;
this.activeDocumentWorkspace.AppWorkspace = this;
this.activeDocumentWorkspace.StatusChanged += OnDocumentWorkspaceStatusChanged;
this.activeDocumentWorkspace.DocumentChanging += DocumentWorkspace_DocumentChanging;
this.activeDocumentWorkspace.DocumentChanged += DocumentWorkspace_DocumentChanged;
//this.activeDocumentWorkspace.ScaleFactorChanged += ZoomChangedHandler;
//this.activeDocumentWorkspace.ZoomBasisChanged += DocumentWorkspace_ZoomBasisChanged;
//this.activeDocumentWorkspace.Units = this.widgets.ViewConfigStrip.Units;
this.activeDocumentWorkspace.ToolChanging += this.ToolChangingHandler;
this.activeDocumentWorkspace.ToolChanged += this.ToolChangedHandler;
this.toolBar.DocumentStrip.SelectDocumentWorkspace(this.activeDocumentWorkspace);
//切换相
this.PanelBottom.documentStrip.ClearPhase();
this.PanelBottom.documentStrip.AddPhase(this.activeDocumentWorkspace.phaseModels);
//处理像素跟踪
if (this.pixelTrackingDialog != null) this.pixelTrackingDialog.Mat = null;
//Bitmap map = this.activeDocumentWorkspace.SurfaceBox.Surface.CreateAliasedBitmap();
////oldMat = PaintDotNet.Camera.Tools.ToMat(map);
//if (this.histogramDialog != null) this.histogramDialog.Mat = PaintDotNet.Camera.Tools.ToMat(map);// null;
//处理底部缩放百分比的trackbar和textbox
this.SetZoonTrackValue(this.activeDocumentWorkspace.ScaleFactor);
this.activeDocumentWorkspace.ResumeLayout();
this.activeDocumentWorkspace.PerformLayout();
this.activeDocumentWorkspace.FirstInputAfterGotFocus += ActiveDocumentWorkspace_FirstInputAfterGotFocus;
//更新信息
this.UpdateDocInfoInStatusBar();
//判断当前对象是否是zip的,如果是则需要处理右下角按钮及读取图片
if (this.activeDocumentWorkspace.zipXmlModel == null)
{
this.PanelBottom.documentStrip.ShowPictures = false;
}
else
{
this.PanelBottom.documentStrip.ShowPictures = true;
this.PanelBottom.documentStrip.trackBar.Maximum = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
PicName oldPicName = this.activeDocumentWorkspace.zipXmlModel.picNameList.Find(a => a.name == this.activeDocumentWorkspace.picName);
this.panelBottom.documentStrip.trackBar.Value = this.activeDocumentWorkspace.zipXmlModel.picNameList.IndexOf(oldPicName) + 1;
this.PanelBottom.documentStrip.textBox.Text = this.PanelBottom.documentStrip.trackBar.Value + @"/" + this.PanelBottom.documentStrip.trackBar.Maximum;
ChangeImageInActiveDocument(this.panelBottom.documentStrip.trackBar.Value);
}
}
bool isLianxu = this.ContinuousDrawing;
if (ActiveDocumentWorkspaceChanged != null)
{
ActiveDocumentWorkspaceChanged(this, EventArgs.Empty);
}
UpdateStatusBarContextStatus();
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();
if (this.activeDocumentWorkspace.best)
this.activeDocumentWorkspace.buttonType = 0;
else if (this.activeDocumentWorkspace.maxMin)
this.activeDocumentWorkspace.buttonType = 1;
else if (this.activeDocumentWorkspace.gamma45)
this.activeDocumentWorkspace.buttonType = 2;
else if (this.activeDocumentWorkspace.origin)
this.activeDocumentWorkspace.buttonType = 3;
this.RefreshHistogram();
RefreshOpticalDensity();
}
//直方图
if (this.histogramDialog != null) this.histogramDialog.ResetMat();
//if (this.activeDocumentWorkspace != null)
//{
// Bitmap map = this.activeDocumentWorkspace.SurfaceBox.Surface.CreateAliasedBitmap();
// //oldMat = PaintDotNet.Camera.Tools.ToMat(map);
// if (this.histogramDialog != null) this.histogramDialog.Mat = PaintDotNet.Camera.Tools.ToMat(map);// null;
//}
//else
//{
// if (this.histogramDialog != null) this.histogramDialog.Mat = null;
//}
//刷新图像索引窗口
if ((this.activeDocumentWorkspace == null || this.activeDocumentWorkspace != null && this.toInitImageIndexDialogFlag == 1)
&& ImageIndexDialog.imageIndexDialog != null)
ImageIndexDialog.imageIndexDialog.InitData();
}
public void SetTopLeftCheckState()
{
if (this.toolBar != null && this.activeDocumentWorkspace != null)
{
this.activeDocumentWorkspace.ContinuousDrawingMeasure = this.ContinuousDrawing;
this.activeDocumentWorkspace.ContinuousDrawingLabel = this.ContinuousDrawing;
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.AuxiliaryLineEnabled, "AuxiliaryLine");
this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
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");
this.toolBar.RefreshBtnSelect(this.Widgets.LabelListDialog.Visible, "LabelListAction");
this.toolsPanel.RefreshBtnSelect(this.Widgets.LabelListDialog.Visible, "LabelListAction");
this.toolBar.RefreshBtnSelect(this.Widgets.MeasureListDialog.Visible, "MeasureList");
this.toolsPanel.RefreshBtnSelect(this.Widgets.MeasureListDialog.Visible, "MeasureList");
this.toolBar.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
this.toolsPanel.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
this.toolBar.RefreshBtnSelect(this.Widgets.OpticalDensityDialog.Visible, "OpticalDensity");
this.toolsPanel.RefreshBtnSelect(this.Widgets.OpticalDensityDialog.Visible, "OpticalDensity");
this.toolBar.RefreshBtnSelect(this.Widgets.HistogramDialog.Visible, "Histogram");
this.toolsPanel.RefreshBtnSelect(this.Widgets.HistogramDialog.Visible, "Histogram");
this.toolBar.RefreshBtnSelect(this.Widgets.PixelTrackingDialog.Visible, "PixelTracking");
this.toolsPanel.RefreshBtnSelect(this.Widgets.PixelTrackingDialog.Visible, "PixelTracking");
this.toolBar.RefreshBtnSelect(this.Widgets.ImageIndexDialog.Visible, "ImageIndex");
this.toolsPanel.RefreshBtnSelect(this.Widgets.ImageIndexDialog.Visible, "ImageIndex");
this.toolBar.RefreshBtnSelect(this.Widgets.GeometryMeasureDialog.Visible, "Geometry");
this.toolsPanel.RefreshBtnSelect(this.Widgets.GeometryMeasureDialog.Visible, "Geometry");
this.toolBar.RefreshBtnSelect(this.Widgets.WorkFlowDialog.Visible, "WorkFlow");
this.toolsPanel.RefreshBtnSelect(this.Widgets.WorkFlowDialog.Visible, "WorkFlow");
this.toolBar.RefreshBtnSelect(this.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
this.toolsPanel.RefreshBtnSelect(this.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
this.toolBar.RefreshBtnSelect(this.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
this.toolsPanel.RefreshBtnSelect(this.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
this.toolBar.RefreshBtnSelect(this.Widgets.ProjectEngineering.Visible, "OpenProject");
this.toolsPanel.RefreshBtnSelect(this.Widgets.ProjectEngineering.Visible, "OpenProject");
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)
{
this.form = form;
SuspendLayout();
// initialize!
InitializeComponent();
InitializeFloatingForms();
//初始化相机列表
this.toolBar.MainMenu.imageCollectionMenu.InitCameraList();
//this.toolBar.ToolChooserStrip.ToolClicked += new ToolClickedEventHandler(this.MainToolBar_ToolClicked);
this.toolBar.AppWorkspace = this;
// init the Widgets container
this.widgets = new WorkspaceWidgets(this);
//this.widgets.ViewConfigStrip = this.toolBar.ViewConfigStrip;
//this.widgets.CommonActionsStrip = this.toolBar.CommonActionsStrip;
this.Widgets.RuleListForm = this.ruleListForm;
this.Widgets.PixelTrackingDialog = this.pixelTrackingDialog;
this.Widgets.ImageIndexDialog = this.imageIndexDialog;
this.Widgets.GeometryMeasureDialog = this.geometryMeasureDialog;
this.Widgets.RunningDialog = this.runningDialog;
this.Widgets.HistogramDialog = this.histogramDialog;
this.Widgets.ScratchTreatmentDialog = this.scratchTreatmentDialog;
this.Widgets.SmudgeTreatmentDialog = this.smudgeTreatmentDialog;
this.Widgets.LabelListDialog = this.labelListDialog;
this.Widgets.WorkFlowDialog = this.workFlowDialog;
this.Widgets.MeasureListDialog = this.measureListDialog;
this.Widgets.OpticalDensityDialog = this.opticalDensityDialog;
this.Widgets.ProjectEngineering = this.projectEngineering;
this.widgets.StatusBarProgress = this.statusBar;
this.widgets.DocumentStrip = this.toolBar.DocumentStrip;
this.toolBar.DocumentStrip.RelinquishFocus += RelinquishFocusHandler;
//this.toolBar.CommonActionsStrip.RelinquishFocus += OnToolStripRelinquishFocus;
//this.toolBar.CommonActionsStrip.MouseWheel += OnToolStripMouseWheel;
/*this.toolBar.ViewConfigStrip.DrawGridChanged += ViewConfigStrip_DrawGridChanged;
this.toolBar.ViewConfigStrip.ZoomBasisChanged += ViewConfigStrip_ZoomBasisChanged;
this.toolBar.ViewConfigStrip.ZoomScaleChanged += ViewConfigStrip_ZoomScaleChanged;
this.toolBar.ViewConfigStrip.ZoomIn += ViewConfigStrip_ZoomIn;
this.toolBar.ViewConfigStrip.ZoomOut += ViewConfigStrip_ZoomOut;
this.toolBar.ViewConfigStrip.UnitsChanged += ViewConfigStrip_UnitsChanged;
this.toolBar.ViewConfigStrip.RelinquishFocus += OnToolStripRelinquishFocus;
this.toolBar.ViewConfigStrip.MouseWheel += OnToolStripMouseWheel;*/
this.toolBar.DocumentStrip.RelinquishFocus += OnToolStripRelinquishFocus;
this.toolBar.DocumentStrip.DocumentClicked += DocumentStrip_DocumentTabClicked;
this.toolBar.DocumentStrip.DocumentListChanged += DocumentStrip_DocumentListChanged;
ResumeLayout();
PerformLayout();
this.InitializeBottomEvent();
this.InitializePanelBottomRight();
PdnBaseForm.RegisterFormHotKey(Keys.Escape, EscapeMethod);
}
///
/// esc事件
///
///
///
private bool EscapeMethod(Keys t)
{
if (this.activeDocumentWorkspace != null)
{
if (!this.continuousDrawingMeasure && !this.continuousDrawingLabel)
{
this.activeDocumentWorkspace.MouseEvent_Del(null, null);
this.activeDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
}
}
return true;
}
private void DocumentStrip_DocumentListChanged(object sender, EventArgs e)
{
bool enableThem = (this.widgets.DocumentStrip.DocumentCount != 0);
this.widgets.RuleListForm.Enabled = enableThem;
this.widgets.PixelTrackingDialog.Enabled = enableThem;
this.widgets.ImageIndexDialog.Enabled = enableThem;
this.widgets.GeometryMeasureDialog.Enabled = enableThem;
this.widgets.RunningDialog.Enabled = enableThem;
this.widgets.HistogramDialog.Enabled = enableThem;
this.widgets.ScratchTreatmentDialog.Enabled = enableThem;
this.widgets.SmudgeTreatmentDialog.Enabled = enableThem;
this.widgets.LabelListDialog.Enabled = enableThem;
this.widgets.WorkFlowDialog.Enabled = enableThem;
this.widgets.MeasureListDialog.Enabled = enableThem;
this.widgets.OpticalDensityDialog.Enabled = enableThem;
this.widgets.ProjectEngineering.Enabled = enableThem;
UpdateDocInfoInStatusBar();
UpdateCursorInfoInStatusBar(0, 0);
}
public void SaveSettings()
{
Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, this.DrawGrid);
this.MostRecentFiles.SaveMruList();
}
protected override void OnLoad(EventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
this.ActiveDocumentWorkspace.Select();
}
UpdateSnapObstacle();
base.OnLoad(e);
}
private void RelinquishFocusHandler(object sender, EventArgs e)
{
this.Focus();
}
/*private void ZoomChangedHandler(object sender, EventArgs e)
{
ScaleFactor sf = this.activeDocumentWorkspace.ScaleFactor;
this.toolBar.ViewConfigStrip.SuspendEvents();
this.toolBar.ViewConfigStrip.ZoomBasis = this.activeDocumentWorkspace.ZoomBasis;
this.toolBar.ViewConfigStrip.ScaleFactor = sf;
this.toolBar.ViewConfigStrip.ResumeEvents();
}*/
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> 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)
{
}
private void InitializeFloatingForms()
{
// RuleListForm
ruleListForm = new RuleListForm(this);
ruleListForm.RelinquishFocus += RelinquishFocusHandler;
ruleListForm.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
// PixelTrackingDialog
pixelTrackingDialog = new PixelTrackingDialog(this);
pixelTrackingDialog.RelinquishFocus += RelinquishFocusHandler;
pixelTrackingDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
// imageIndexDialog
imageIndexDialog = new ImageIndexDialog(this);
imageIndexDialog.RelinquishFocus += RelinquishFocusHandler;
imageIndexDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
// geometryMeasureDialog
geometryMeasureDialog = new GeometryMeasureDialog(this);
geometryMeasureDialog.RelinquishFocus += RelinquishFocusHandler;
geometryMeasureDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
// RunningDialog
runningDialog = new ScriptRunningDialog(this, null);
runningDialog.RelinquishFocus += RelinquishFocusHandler;
runningDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
// HistogramDialog
histogramDialog = new HistogramDialog(this);
histogramDialog.RelinquishFocus += RelinquishFocusHandler;
histogramDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
//ScratchTreatmentDialog
scratchTreatmentDialog = new ScratchTreatmentDialog(this);
scratchTreatmentDialog.RelinquishFocus += RelinquishFocusHandler;
scratchTreatmentDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
//SmudgeTreatmentDialog
smudgeTreatmentDialog = new SmudgeTreatmentDialog(this);
smudgeTreatmentDialog.RelinquishFocus += RelinquishFocusHandler;
smudgeTreatmentDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
//LabelListDialog
labelListDialog = new LabelListDialog(this);
labelListDialog.RelinquishFocus += RelinquishFocusHandler;
labelListDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
// WorkFlowDialog
workFlowDialog = new WorkFlowDialog(this);
workFlowDialog.RelinquishFocus += RelinquishFocusHandler;
workFlowDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
measureListDialog = new MeasureListDialog(this);
measureListDialog.RelinquishFocus += RelinquishFocusHandler;
measureListDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
opticalDensityDialog = new OpticalDensityDialog(this);
opticalDensityDialog.RelinquishFocus += RelinquishFocusHandler;
opticalDensityDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
projectEngineering = new ProjectEngineering(this);
projectEngineering.RelinquishFocus += RelinquishFocusHandler;
projectEngineering.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 PerformActionAsync(AppWorkspaceAction performMe)
{
this.BeginInvoke(new Procedure(PerformAction), new object[] { performMe });
}
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)
{
UpdateSnapObstacle();
base.OnResize(e);
}
private void DocumentWorkspace_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
{
OnScroll(e);
}
private void DocumentWorkspace_Layout(object sender, LayoutEventArgs e)
{
UpdateSnapObstacle();
}
/*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;
try
{
Document untitled = new Document(size.Width, size.Height);
untitled.DpuUnit = dpuUnit;
untitled.DpuX = dpu;
untitled.DpuY = dpu;
/*BitmapLayer bitmapLayer;
try
{
using (new WaitCursorChanger(this))
{
bitmapLayer = Layer.CreateBackgroundLayer(size.Width, size.Height);
}
}
catch (OutOfMemoryException)
{
Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory"));
return false;
}*/
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));
untitled.surface.PixelFormat = PixelFormat.Format32bppArgb;
//untitled.Layers.Add(bitmapLayer);
DocumentWorkspace dw = this.AddNewDocumentWorkspace();
dw.needBackup = false;
this.Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
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/*, null, null*/);
dw.Document.Dirty = false;
if (isInitial)
{
this.initialWorkspace = dw;
}
if (focused)
{
this.ActiveDocumentWorkspace.Focus();
}
this.Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
}
}
finally
{
}
return true;
}
public bool OpenFilesInNewWorkspace(string[] fileNames)
{
if (IsDisposed)
{
return false;
}
bool result = true;
ProgressThreadProcClass procClass = new ProgressThreadProcClass();
int itemCount = fileNames.Length;
ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
System.Threading.ThreadStart copyThreadProc =
delegate ()
{
try
{
for (int i = 0; i < fileNames.Length; i++)
{
if (!OpenFileInNewWorkspace(fileNames[i]))
{
continue;
}
System.Threading.Thread.Sleep(100);
this.Invoke(new Action(() =>
{
progressEvents.SetStringProgress((i + 1) + "/" + fileNames.Length);
}));
}
}
catch (Exception)
{
}
finally
{
progressEvents.EndOperation(OperationResult.Finished);
}
};
procClass.StartProgressAction((MainForm)this.Parent, itemCount, copyThreadProc, progressEvents, "打开图片");
return result;
}
public void OpenFileInNewWorkspaceThread(object obj)
{
string[] fileNames = (string[])obj;
foreach (string fileName in fileNames)
{
bool result = OpenFileInNewWorkspace(fileName);
if (!result)
{
continue;
}
System.Threading.Thread.Sleep(100);
}
}
public bool OpenFileInNewWorkspace(string fileName)
{
return OpenFileInNewWorkspace(fileName, true);
}
///
/// 需要修改
/// (1)判断是否有同名的xml文件,有则读取并处理
/// (2)判断是否识别其它标尺,有则读取
///
///
///
///
public bool OpenFileInNewWorkspace(string fileName, bool addToMruList)
{
if (fileName == null)
{
throw new ArgumentNullException("fileName");
}
if (fileName.Length == 0)
{
throw new ArgumentOutOfRangeException("fileName.Length == 0");
}
//判断是压缩包文件
ZipHandleHelper zipHandleHelper = null;
ZipXmlModel zipXmlModel = null;
bool isZipFile = false;
string picName = "";
Image zipImage = null;
if (Path.GetExtension(fileName) == ".tga")
{
zipHandleHelper = new ZipHandleHelper(fileName);
zipXmlModel = zipHandleHelper.GetXmlFromZip();
if (zipXmlModel.picNameList != null && zipXmlModel.picNameList.Count > 0)
{
picName = zipXmlModel.picNameList[0].name;//获取xml中第一张图的名称
zipImage = zipHandleHelper.GetPicFromZip(picName);
isZipFile = true;
}
else
return false;//没有xml文件或有xml但一张图片都没有,不做处理
}
this.Invoke(new Action(() =>
{
PdnBaseForm.UpdateAllForms();
}));
//FileType fileType = null;
Document document;
//this.widgets.StatusBarProgress.ResetProgressStatusBar();
ProgressEventHandler progressCallback =
delegate (object sender, ProgressEventArgs e)
{
this.widgets.StatusBarProgress.SetProgressStatusBar(e.Percent);
};
if (isZipFile)
{
if (zipImage == null)
return false;
document = Document.FromImageMat(Camera.Tools.ToMat((Bitmap)zipImage));
}
else
{
OpenCvSharp.Mat temp = new OpenCvSharp.Mat(fileName);
if (temp.Empty()) return false;
document = Document.FromMat(temp);// DocumentWorkspace.LoadDocument(this, fileName, /*out fileType, */progressCallback);
}
this.widgets.StatusBarProgress.EraseProgressStatusBar();
if (document == null)
{
this.Cursor = Cursors.Default;
}
else
{
this.Invoke(new Action(() =>
{
using (new WaitCursorChanger(this))
{
DocumentWorkspace dw = AddNewDocumentWorkspace();
//如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
if (this.ScriptRunning/* && this.ScriptCurrentParam != null && this.ScriptCurrentParam.MenuId == action.MenuId*/)
{
dw.OpenInScriptRunning = true;
}
Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
try
{
dw.Document = document;
//dw.rules = new Dictionary(Startup.instance.rules);
//dw.xmlSaveModel = Startup.instance.ruleDB;
//dw.InitRulerInfo();
if (isZipFile)
{
dw.fileText = picName;
dw.zipHandleHelper = zipHandleHelper;
dw.zipXmlModel = zipXmlModel;
dw.picName = picName;
}
}
catch (OutOfMemoryException)
{
Utility.ErrorBox(this, PdnResources.GetString("LoadImage.Error.OutOfMemoryException"));
RemoveDocumentWorkspace(dw);
document.Dispose();
//return false;
}
//判断是否存在xml,进行读取
PicConfigModel configModel = null;
try
{
if (isZipFile)
{
configModel = zipHandleHelper.GetImageXmlFromZip();
if (configModel != null)
{
RestoreLabelAndMeasure(configModel, dw);
}
}
string path = Path.GetDirectoryName(fileName);
string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
string xmlPathAV = fileName+"_meta.xml";
string xmlPathZEN = fileName + "_zen.xml";
//如果xml存在
if (System.IO.File.Exists(xmlPath))
{
configModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
dw.RuleAttribute(configModel);
dw.Units = Startup.instance.measurementUnit;
if (configModel != null)
{
RestoreLabelAndMeasure(configModel, dw);
}
}
//else if (System.IO.File.Exists(xmlPathAV) && Startup.instance.configModel.AddAxioVision == 1)
//{
// dw.RuleAttribute(xmlPathAV);
// dw.Units = Startup.instance.measurementUnit;
// //string[] vs = XmlSerializeHelper.GetRuler(xmlPathAV);
//}
//else if (System.IO.File.Exists(xmlPathZEN) && Startup.instance.configModel.AddZEN == 1)
//{
// //dw.RuleAttribute(xmlPathZEN);
// //dw.Units = Startup.instance.measurementUnit;
//}
//如果不存在,则判断
//(1)是否自动添加ZEN标尺
//(2)是否自动添加AxioVision标尺
else
{
dw.xmlSaveModel = Startup.instance.ruleDB;
dw.InitRulerInfo();
}
//else
//{
// string path = Path.GetDirectoryName(fileName);
// string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
// //如果xml存在
// if (System.IO.File.Exists(xmlPath))
// {
// configModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
// dw.RuleAttribute(configModel);
// if (configModel != null)
// {
// RestoreLabelAndMeasure(configModel, dw);
// }
// }
// //如果不存在,则判断
// //(1)是否自动添加ZEN标尺
// //(2)是否自动添加AxioVision标尺
// else
// {
// dw.xmlSaveModel = Startup.instance.ruleDB;
// dw.InitRulerInfo();
// }
//}
}
catch (Exception)
{
}
if (!isZipFile)
dw.SetDocumentSaveOptions(fileName/*, fileType, null*/);
this.ActiveDocumentWorkspace = dw;
this.ActiveDocumentWorkspace.Units = Startup.instance.measurementUnit;
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 (isZipFile)
{
this.PanelBottom.documentStrip.ShowPictures = true;
}
else
this.PanelBottom.documentStrip.ShowPictures = false;
}
// add to MRU list
if (addToMruList && !isZipFile)
{
ActiveDocumentWorkspace.AddToMruList();
}
//this.toolBar.DocumentStrip.SyncThumbnails();
WarnAboutSavedWithVersion(document.SavedWithVersion);
if (ActiveDocumentWorkspace != null)
{
ActiveDocumentWorkspace.Focus();
}
}
}));
}
return document != null;
}
///
/// 还原标注和测量
///
///
///
public void RestoreLabelAndMeasure(PicConfigModel configModel, DocumentWorkspace dw)
{
//还原标注
if (configModel.labels != null && configModel.labels.Count > 0)
{
configModel.labels.Reverse();
foreach (LabelMeasureDataModel label in configModel.labels)
{
string className = InvariantData.path_Label + "." + label.drawToolType;
object[] parameters = new object[4];
parameters[0] = dw;
parameters[1] = label.points;
parameters[2] = label.style;
parameters[3] = label.content;
object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
dw.GraphicsList.Add((DrawObject)obj);
}
}
//还原测量
if (configModel.measures != null && configModel.measures.Count > 0)
{
configModel.measures.Reverse();
foreach (LabelMeasureDataModel measure in configModel.measures)
{
string className = InvariantData.path_Measure + "." + measure.drawToolType;
object[] parameters = new object[4];
parameters[0] = dw;
parameters[1] = measure.points;
parameters[2] = measure.style;
parameters[3] = measure.content;
object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
dw.GraphicsList.Add((DrawObject)obj);
}
}
//还原其他
//if (configModel.others != null && configModel.others.Count > 0)
//{
// configModel.others.Reverse();
// foreach (LabelMeasureDataModel other in configModel.others)
// {
// string className = InvariantData.path_Other + "." + other.drawToolType;
// object[] parameters = new object[4];
// parameters[0] = dw;
// parameters[1] = other.points;
// parameters[2] = other.style;
// parameters[3] = other.content;
// object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
// dw.GraphicsList.Add((DrawObject)obj);
// }
//}
}
///
/// 版本警告,暂时用不到
///
///
private void WarnAboutSavedWithVersion(Version savedWith)
{
if (savedWith < new Version(2, 6, 0))
{
Version ourVersion = PdnInfo.GetVersion();
Version ourVersion2 = new Version(ourVersion.Major, ourVersion.Minor);
Version ourVersion3 = new Version(ourVersion.Major, ourVersion.Minor, ourVersion.Build);
int fields;
if (savedWith < ourVersion2)
{
fields = 2;
}
else
{
fields = 3;
}
string format = PdnResources.GetString("SavedWithOlderVersion.Format");
string text = string.Format(format, savedWith.ToString(fields), ourVersion.ToString(fields));
//Utility.InfoBox(this, text);
}
}
///
/// Computes what the size of a new document should be. If the screen is in a normal,
/// wider-than-tall (landscape) mode then it returns 800x600. If the screen is in a
/// taller-than-wide (portrait) mode then it retusn 600x800. If the screen is square
/// then it returns 800x600.
///
public Size GetNewDocumentSize()
{
PdnBaseForm findForm = this.FindForm() as PdnBaseForm;
if (findForm != null && findForm.ScreenAspect < 1.0)
{
return new Size(600, 800);
}
else
{
return new Size(800, 600);
}
}
///
/// 保存快捷方式
///
///
public bool DoSaveLnk()
{
//保存窗口
SaveFileDialog saveLnkDialog = new SaveFileDialog();
saveLnkDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
saveLnkDialog.AddExtension = true;
saveLnkDialog.Filter = "Lnk(*.lnk)|*.lnk";
saveLnkDialog.FilterIndex = 1;
saveLnkDialog.CheckFileExists = false;// true;
saveLnkDialog.DefaultExt = "lnk";
saveLnkDialog.FileName = PdnResources.GetString("Menu.Ashortcu.Text");
saveLnkDialog.Title = PdnResources.GetString("Menu.Tools.CreateShortcut.Text");
//saveLnkDialog.DereferenceLinks = true;
if (saveLnkDialog.ShowDialog() == DialogResult.OK)
{
try
{
//存快捷方式
WshShell shell = new WshShell();
string savePath = saveLnkDialog.FileName;
string saveName = Path.GetFileNameWithoutExtension(savePath);
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(savePath);
shortcut.TargetPath = Application.ExecutablePath;
shortcut.WorkingDirectory = Application.StartupPath;
shortcut.WindowStyle = 1;
shortcut.Arguments = "/personalConfig /" + saveName;//参数
bool b = FileOperationHelper.CopyDirectory(Application.StartupPath + "\\Config\\Default\\", Application.StartupPath + "\\Config\\" + saveName + "\\", true);
if (!b)
{
MessageBox.Show(PdnResources.GetString("Menu.Failedtosaveconfigurationfile.text"));
return false;
}
shortcut.Save();
return true;
}
catch (Exception)
{
MessageBox.Show(PdnResources.GetString("Menu.Shortcutsavefailed.text"));
return false;
}
}
else
return false;
}
#region 对外接口
///
/// 获取网格样式配置
///
///
public GridModel GetGridModel()
{
return Startup.instance.gridModel;
}
///
/// 获取标注样式配置
///
///
public LabelStyleModel GetLabelStyleModel()
{
return Startup.instance.labelStyleModel;
}
///
/// 获取测量样式配置
///
///
public MeasureStyleModel GetMeasureStyleModel()
{
return Startup.instance.measureStyleModel;
}
///
/// 获取设置-常规设置-辅助线样式信息
///
///
public GuideStyleModel GetGuideStyleModel()
{
return Startup.instance.guideStyleModel;
}
///
/// 获取水印样式配置
///
///
public WatermarkModel GetWatermarkModel()
{
return Startup.instance.watermarkModel;
}
///
/// 获取工字线配置
///
///
public WorkTypeStyleModel GetWorkTypeStyleModel()
{
return Startup.instance.workTypeStyleModel;
}
///
/// 获取标尺样式配置
///
///
public RulerModel GetRulerStyleModel()
{
return Startup.instance.rulerModel;
}
///
/// 像素跟踪
/// 需要增加标记,在进行比如图像旋转等直接在当前
/// 面板进行图像大小变化操作的,需要停止像素跟踪,
/// 处理完成之后在恢复,否则可能会导致读取内存异常
///
///
public void SetImageAndData(Point location, DocumentView doc)
{
if (this.pixelTrackingDialog != null)
{
this.pixelTrackingDialog.SetImageAndData(location, doc);
}
}
///
/// 刷新标注列表
///
public void RefreshLabelListDialog()
{
if (this.labelListDialog != null)
this.labelListDialog.RefreshDateGridView(null, null);
}
///
/// 刷新交互测量列表
///
public void RefreshMeasureListView()
{
Form form = Application.OpenForms["GeometryMeasureDialog"];
if (form != null)
{
((GeometryMeasureDialog)form).RefreshListView(null, null);
}
this.Refresh();
}
///
/// 刷新测量列表
///
public void RefreshListView()
{
if (this.measureListDialog != null)
this.measureListDialog.RefreshListView(null, null);
this.Refresh();
}
///
/// 刷新直方图
///
public void RefreshHistogram()
{
if (this.histogramDialog != null)
this.histogramDialog.ButtonFocus(null, null);
this.Refresh();
}
///
/// 取得绘制属性
///
public void SetDrawNodes()
{
if (this.measureListDialog != null)
this.measureListDialog.SetDrawNodes(null, null);
}
///
/// 刷新光密度画面
///
public void RefreshOpticalDensity()
{
if (this.opticalDensityDialog != null)
this.opticalDensityDialog.RefreshOpticalDensity(null, null);
}
/*public PointF GetDocumentScrollPositionF()
{
return this.activeDocumentWorkspace.DocumentScrollPositionF;
}
public void SetDocumentScrollPositionF(PointF newScrollPos)
{
this.activeDocumentWorkspace.DocumentScrollPositionF = newScrollPos;
}*/
public RectangleF GetVisibleDocumentRectangleF()
{
return this.activeDocumentWorkspace.VisibleDocumentRectangleF;
}
public SizeF GetDocumentSize()
{
//return this.activeDocumentWorkspace.Document.Size;
if (this.cameraPreviewDialog != null && !this.cameraPreviewDialog.IsDisposed)
{
if (this.cameraPreviewDialog.documentWorkspace != null)
{
return this.cameraPreviewDialog.documentWorkspace.Document.Size;
}
}
else
{
return this.activeDocumentWorkspace.Document.Size;
}
return this.activeDocumentWorkspace.Document.Size;
}
public double GetRatio()
{
return this.activeDocumentWorkspace.ScaleFactor.Ratio;
}
public PointF DocumentToClient(PointF pointF)
{
return this.activeDocumentWorkspace.DocumentToClient(pointF);
}
///
/// 获取系统当前选中单位及每单位像素值
///
/// 3位字符串数组,
/// 0:系统选中单位枚举字符串
/// 1:系统选中单位名称字符串
/// 2:系统选中单位符号字符串
/// 3:系统选中单位每单位像素长度
/// 4:系统选中单位每单位物理长度
///
public string[] GetPxPerUnit()
{
if (this.activeDocumentWorkspace != null)
return this.activeDocumentWorkspace.getRulerList();
else
{
string[] result = new string[5];
result[0] = Startup.instance.measurementUnit.ToString();
result[1] = InvariantData.unitsDictionary[(int)Startup.instance.measurementUnit];
result[2] = InvariantData.unitSymbolsDictionary[(int)Startup.instance.measurementUnit];
result[3] = (Startup.instance.rules[Startup.instance.measurementUnit]).ToString();
result[4] = (Startup.instance.rules[MeasurementUnit.Micron]).ToString();
return result;
}
}
///
/// 获取当前激活的图像工作空间的视场行为
/// 合并/剪切
///
///
public CombineMode GetCombineMode()
{
return this.ActiveDocumentWorkspace.CombineMode;
}
///
/// 获取测量单位对应的换算字典
///
///
public Dictionary getMeasureInfo()
{
if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.rules != null)
return this.ActiveDocumentWorkspace.rules;
else
return Startup.instance.rules;
}
///
/// 获取系统当前放大倍数
///
///
public decimal GetGainMultiple()
{
if (Startup.instance.ruleDB == null)
{
return decimal.Zero;
}
else
{
return Startup.instance.ruleDB.gain_multiple;
}
}
PanelBottom IAppWorkspaceForSurfaceBox.GetPanelBottom()
{
return PanelBottom;
}
///
/// 更新命名的延续数字
///
public void UpdateContinueNum()
{
if (Startup.instance.configModel != null)
{
ConfigModel configModel = Startup.instance.configModel;
configModel.ContinueNum++;
string configXml = XmlSerializeHelper.XmlSerialize(configModel);
string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
}
}
#endregion
#region 底部公共按钮
///
/// 初始化底部按钮的各种事件
///
private void InitializeBottomEvent()
{
//最佳
this.PanelBottom.bestButton.MouseDown += new MouseEventHandler(BestButton_Click);
//最大最小
this.PanelBottom.maxMinButton.MouseDown += new MouseEventHandler(MaxMinButton_Click);
//原始状态
this.PanelBottom.originButton.MouseDown += new MouseEventHandler(OriginButton_Click);
//伽马0.45
this.PanelBottom.gamma45Button.MouseDown += new MouseEventHandler(Gamma45Button_Click);
//网格
this.PanelBottom.gridButton.MouseDown += new MouseEventHandler(GridButton_Click);
//辅助线
this.PanelBottom.auxiliaryLineButton.MouseDown += new MouseEventHandler(AuxiliaryLineButton_Click);
//水平镜像
this.PanelBottom.horizontalMirroringButton.Click += new EventHandler(HorizontalMirroringButton_Click);
//垂直镜像
this.PanelBottom.verticalMirrorButton.Click += new EventHandler(VerticalMirrorButton_Click);
//中心镜像
this.PanelBottom.centerMirrorButton.Click += new EventHandler(CenterMirrorButton_Click);
//移动模式
this.PanelBottom.mobileModeButton.MouseDown += new MouseEventHandler(MobileModeButton_Click);
//指针模式
this.PanelBottom.cursorModeButton.MouseDown += new MouseEventHandler(CursorModeButton_Click);
//实际大小
this.PanelBottom.actualSizeButton.MouseDown += new MouseEventHandler(ActualSizeButton_Click);
//合适大小
this.PanelBottom.zoomToWindowButton.MouseDown += new MouseEventHandler(ZoomToWindowButton_Click);
//定倍显示
//this.PanelBottom.fixedTimesButton.Click += null;
//锁定扩缩
this.PanelBottom.lockdownButton.MouseDown += new MouseEventHandler(LockdownButton_Click);
//缩小按钮
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);
//相的选中事件
this.panelBottom.ItemICheckChanged += new EventHandler>(this.PhaseItemICheckChanged);
}
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);
}
///
/// 最佳
///
///
///
private void BestButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
{
if (!this.activeDocumentWorkspace.best)
{
this.activeDocumentWorkspace.best = true;
this.activeDocumentWorkspace.maxMin = false;
this.activeDocumentWorkspace.origin = false;
this.activeDocumentWorkspace.gamma45 = false;
this.PanelBottom.maxMinButton.selected = false;
this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.originButton.selected = false;
this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gamma45Button.selected = false;
this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.best)
{
this.PanelBottom.bestButton.selected = true;
this.PanelBottom.bestButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.bestButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.bestButton.selected = false;
this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
this.Histogram.BestButtonMethod();
if (this.activeDocumentWorkspace != null)
{
this.activeDocumentWorkspace.buttonType = 0;
this.RefreshHistogram();
}
}
}
///
/// 从直方图更新选中状态
///
///
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;
if (this.activeDocumentWorkspace.best)
{
this.PanelBottom.bestButton.selected = true;
this.PanelBottom.bestButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.bestButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.bestButton.selected = false;
this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.maxMin)
{
this.PanelBottom.maxMinButton.selected = true;
this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.maxMinButton.selected = false;
this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.origin)
{
this.PanelBottom.originButton.selected = true;
this.PanelBottom.originButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.originButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.originButton.selected = false;
this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.gamma45)
{
this.PanelBottom.gamma45Button.selected = true;
this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 1;
this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.gamma45Button.selected = false;
this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
}
///
/// 最大最小
///
///
///
private void MaxMinButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
{
if (!this.activeDocumentWorkspace.maxMin)
{
this.activeDocumentWorkspace.maxMin = true;
this.activeDocumentWorkspace.best = false;
this.activeDocumentWorkspace.origin = false;
this.activeDocumentWorkspace.gamma45 = false;
this.PanelBottom.bestButton.selected = false;
this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.originButton.selected = false;
this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gamma45Button.selected = false;
this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.maxMin)
{
this.PanelBottom.maxMinButton.selected = true;
this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.maxMinButton.selected = false;
this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace != null)
{
this.activeDocumentWorkspace.buttonType = 1;
this.RefreshHistogram();
}
this.Histogram.MaxMinButtonMethod();
}
}
///
/// 原始状态
///
///
///
private void OriginButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
{
if (!this.activeDocumentWorkspace.origin)
{
this.activeDocumentWorkspace.origin = true;
this.activeDocumentWorkspace.maxMin = false;
this.activeDocumentWorkspace.best = false;
this.activeDocumentWorkspace.gamma45 = false;
this.PanelBottom.bestButton.selected = false;
this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.maxMinButton.selected = false;
this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gamma45Button.selected = false;
this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.origin)
{
this.PanelBottom.originButton.selected = true;
this.PanelBottom.originButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.originButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.originButton.selected = false;
this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace != null)
{
this.activeDocumentWorkspace.buttonType = 3;
this.RefreshHistogram();
}
this.Histogram.OriginButtonMethod();
}
}
///
/// 伽马0.45
///
///
///
private void Gamma45Button_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
{
if (!this.activeDocumentWorkspace.gamma45)
{
this.activeDocumentWorkspace.gamma45 = true;
this.activeDocumentWorkspace.origin = false;
this.activeDocumentWorkspace.maxMin = false;
this.activeDocumentWorkspace.best = false;
this.PanelBottom.bestButton.selected = false;
this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.maxMinButton.selected = false;
this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.originButton.selected = false;
this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.gamma45)
{
this.PanelBottom.gamma45Button.selected = true;
this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 1;
this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.gamma45Button.selected = false;
this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace != null)
{
this.activeDocumentWorkspace.buttonType = 2;
this.RefreshHistogram();
}
this.Histogram.Gamma45ButtonMethod();
}
}
///
/// 更新底部按钮选中状态
///
public void UpdateBottomButtonSelectionStatus()
{
if (this.ActiveDocumentWorkspace == null)
return;
if (this.ActiveDocumentWorkspace.GridLineEnabled)
{
this.PanelBottom.gridButton.selected = true;
this.PanelBottom.gridButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gridButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.gridButton.selected = false;
this.PanelBottom.gridButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gridButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.ActiveDocumentWorkspace.AuxiliaryLineEnabled)
{
this.PanelBottom.auxiliaryLineButton.selected = true;
this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.auxiliaryLineButton.selected = false;
this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.ActualSize)
{
this.PanelBottom.actualSizeButton.selected = true;
this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.actualSizeButton.selected = false;
this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.SuitableSize)
{
this.PanelBottom.zoomToWindowButton.selected = true;
this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.zoomToWindowButton.selected = false;
this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.ActiveDocumentWorkspace.LockZoom)
{
this.PanelBottom.lockdownButton.selected = true;
this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.lockdownButton.selected = false;
this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.best)
{
this.PanelBottom.bestButton.selected = true;
this.PanelBottom.bestButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.bestButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.bestButton.selected = false;
this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.maxMin)
{
this.PanelBottom.maxMinButton.selected = true;
this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.maxMinButton.selected = false;
this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.origin)
{
this.PanelBottom.originButton.selected = true;
this.PanelBottom.originButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.originButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.originButton.selected = false;
this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.gamma45)
{
this.PanelBottom.gamma45Button.selected = true;
this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 1;
this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.gamma45Button.selected = false;
this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.ActiveDocumentWorkspace.GridLineEnabled)
{
this.PanelBottom.gridButton.selected = true;
this.PanelBottom.gridButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gridButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.gridButton.selected = false;
this.PanelBottom.gridButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gridButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.mobileMode)
{
this.PanelBottom.mobileModeButton.selected = true;
this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.mobileModeButton.selected = false;
this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.cursorMode)
{
this.PanelBottom.cursorModeButton.selected = true;
this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.cursorModeButton.selected = false;
this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
}
///
/// 网格
///
///
///
private void GridButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
this.ActiveDocumentWorkspace.GridLineEnabled = !this.ActiveDocumentWorkspace.GridLineEnabled;
if (this.ActiveDocumentWorkspace.GridLineEnabled)
{
this.PanelBottom.gridButton.selected = true;
this.PanelBottom.gridButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gridButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.gridButton.selected = false;
this.PanelBottom.gridButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.gridButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
this.ActiveDocumentWorkspace.Refresh();
}
}
///
/// 底部快捷栏 辅助线
///
///
///
private void AuxiliaryLineButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
this.ActiveDocumentWorkspace.AuxiliaryLineEnabled = !Settings.CurrentUser.GetBoolean(SettingNames.DrawAuxiliaryLine, false);
if (this.ActiveDocumentWorkspace.AuxiliaryLineEnabled)
{
this.PanelBottom.auxiliaryLineButton.selected = true;
this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.auxiliaryLineButton.selected = false;
this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
Settings.CurrentUser.SetBoolean(SettingNames.DrawAuxiliaryLine, this.ActiveDocumentWorkspace.AuxiliaryLineEnabled);
this.ActiveDocumentWorkspace.Refresh();
}
}
///
/// 水平镜像
///
///
///
public void HorizontalMirroringButton_Click(object sender, EventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
OpenCvSharp.Mat src = this.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.Y);
if (this.scriptRunning)
{
DocumentWorkspace dw = this.AddNewDocumentWorkspace();
Document document = Document.FromImageMat(dst);
dw.Document = document;
dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
this.ActiveDocumentWorkspace = dw;
Startup.instance.step_length += 1;
}
else
{
Document document = Document.FromImageMat(dst);
this.ActiveDocumentWorkspace.Document = document;
this.ActiveDocumentWorkspace.Refresh();
}
}
}
///
/// 垂直镜像
///
///
///
public void VerticalMirrorButton_Click(object sender, EventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
OpenCvSharp.Mat src = this.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.X);
if (this.scriptRunning)
{
DocumentWorkspace dw = this.AddNewDocumentWorkspace();
Document document = Document.FromImageMat(dst);
dw.Document = document;
dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
this.ActiveDocumentWorkspace = dw;
Startup.instance.step_length += 1;
}
else
{
Document document = Document.FromImageMat(dst);
this.ActiveDocumentWorkspace.Document = document;
this.ActiveDocumentWorkspace.Refresh();
}
}
}
///
/// 中心镜像
///
///
///
public void CenterMirrorButton_Click(object sender, EventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
OpenCvSharp.Mat src = this.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.XY);
if (this.scriptRunning)
{
DocumentWorkspace dw = this.AddNewDocumentWorkspace();
Document document = Document.FromImageMat(dst);
dw.Document = document;
dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
this.ActiveDocumentWorkspace = dw;
Startup.instance.step_length += 1;
}
else
{
Document document = Document.FromImageMat(dst);
this.ActiveDocumentWorkspace.Document = document;
this.ActiveDocumentWorkspace.Refresh();
}
}
}
///
/// 移动模式
///
///
///
private void MobileModeButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
if (!this.activeDocumentWorkspace.mobileMode)
{
this.activeDocumentWorkspace.mobileMode = true;
this.activeDocumentWorkspace.cursorMode = false;
this.PanelBottom.cursorModeButton.selected = false;
this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.mobileMode)
{
this.PanelBottom.mobileModeButton.selected = true;
this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.mobileModeButton.selected = false;
this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
this.ActiveDocumentWorkspace.ActiveTool = DrawToolType.MoveMode;
}
}
///
/// 指针模式
///
///
///
private void CursorModeButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
if (!this.activeDocumentWorkspace.cursorMode)
{
this.activeDocumentWorkspace.cursorMode = true;
this.activeDocumentWorkspace.mobileMode = false;
this.PanelBottom.mobileModeButton.selected = false;
this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.cursorMode)
{
this.PanelBottom.cursorModeButton.selected = true;
this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.cursorModeButton.selected = false;
this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
this.ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
}
}
///
/// 底部快捷栏 实际大小
///
///
///
private void ActualSizeButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
if (!this.activeDocumentWorkspace.ActualSize)
{
this.activeDocumentWorkspace.ActualSize = !this.activeDocumentWorkspace.ActualSize;
this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
this.activeDocumentWorkspace.SuitableSize = false;
this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
}
else
{
this.activeDocumentWorkspace.ActualSize = !this.activeDocumentWorkspace.ActualSize;
this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
}
if (this.activeDocumentWorkspace.ActualSize)
{
this.PanelBottom.actualSizeButton.selected = true;
this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.actualSizeButton.selected = false;
this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.SuitableSize)
{
this.PanelBottom.zoomToWindowButton.selected = true;
this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.zoomToWindowButton.selected = false;
this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
this.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
this.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
}
}
///
/// 底部快捷栏 合适大小
///
///
///
private void ZoomToWindowButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
if (!this.activeDocumentWorkspace.SuitableSize)
{
this.activeDocumentWorkspace.SuitableSize = !this.activeDocumentWorkspace.SuitableSize;
this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
this.activeDocumentWorkspace.ActualSize = false;
this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
}
else
{
this.activeDocumentWorkspace.SuitableSize = !this.activeDocumentWorkspace.SuitableSize;
this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
}
if (this.activeDocumentWorkspace.SuitableSize)
{
this.PanelBottom.zoomToWindowButton.selected = true;
this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.zoomToWindowButton.selected = false;
this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
if (this.activeDocumentWorkspace.ActualSize)
{
this.PanelBottom.actualSizeButton.selected = true;
this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.actualSizeButton.selected = false;
this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
this.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
}
}
///
/// 底部快捷键 锁定扩缩
///
///
///
private void LockdownButton_Click(object sender, MouseEventArgs e)
{
if (this.ActiveDocumentWorkspace != null)
{
this.ActiveDocumentWorkspace.LockZoom = !this.ActiveDocumentWorkspace.LockZoom;
this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.LockZoom, "LockZoom");
this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.LockZoom, "LockZoom");
if (this.ActiveDocumentWorkspace.LockZoom)
{
this.PanelBottom.lockdownButton.selected = true;
this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(181, 215, 243);
this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 1;
this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
}
else
{
this.PanelBottom.lockdownButton.selected = false;
this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(0, 0, 0, 0);
this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 0;
this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
}
this.isLockZoom = !this.isLockZoom;
this.lockScaleRatio = this.activeDocumentWorkspace.ScaleFactor.Ratio;
}
}
///
/// 底部快捷栏 缩小事件
///
///
///
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();
}
}
///
/// 底部快捷栏 放大事件
///
///
///
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();
}
}
///
/// 底部方法缩小拖动条事件
///
///
///
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 = 31 * v;
}
else
{
int x = 3000 + v;
if (x > 6100) x = 6200;
this.PanelBottom.trackBar.Value = x;
}
}
}
///
/// 用于相的选中和取消
///
///
///
private void PhaseItemICheckChanged(object sender, EventArgs e)
{
if (e.Data > 0)
{
if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.phaseModels.Count >= e.Data)
{
this.activeDocumentWorkspace.phaseModels[e.Data - 1].choise = !this.activeDocumentWorkspace.phaseModels[e.Data - 1].choise;
this.activeDocumentWorkspace.panel.Refresh();
}
}
}
///
/// 初始化右下角播放系列按钮的各种事件
///
private void InitializePanelBottomRight()
{
this.playMode = 2;//默认是前到后的播放模式
this.PanelBottom.documentStrip.play2Button.BackColor = Color.Gray;//前到后的按钮选中
//初始化定时器
timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
timer.Enabled = false;
//滚动条事件
this.panelBottom.documentStrip.trackBar.TrackBarScroll += new EventHandler(PanelBottom_TrackBarScroll);
//从后往前播放模式
this.PanelBottom.documentStrip.play1Button.Click += new EventHandler(PanelBottom_Play1ButtonClick);
//从前往后播放模式
this.PanelBottom.documentStrip.play2Button.Click += new EventHandler(PanelBottom_Play2ButtonClick);
//循环播放模式
this.PanelBottom.documentStrip.play3Button.Click += new EventHandler(PanelBottom_Play3ButtonClick);
//播放(暂停)
this.PanelBottom.documentStrip.playOrPauseButton.Click += new EventHandler(PanelBottom_PlayOrPauseButtonClick);
//删除当前显示页
this.PanelBottom.documentStrip.deleteButton.Click += new EventHandler(PanelBottom_DeleteButtonClick);
//修改播放时间间隔
this.panelBottom.documentStrip.editTimeButton.Click += new EventHandler(PanelBottom_EditTimeButtonClick);
}
///
/// 右下滚动条事件
///
///
///
private void PanelBottom_TrackBarScroll(object sender, EventArgs e)
{
if (this.activeDocumentWorkspace.zipXmlModel.picNameList != null && this.activeDocumentWorkspace.zipXmlModel.picNameList.Count > 0
&& this.activeDocumentWorkspace.zipHandleHelper != null)
{
ChangeImageInActiveDocument(this.PanelBottom.documentStrip.trackBar.Value);
}
}
///
/// 从后往前播放按钮
///
///
///
private void PanelBottom_Play1ButtonClick(object sender, EventArgs e)
{
if (this.PanelBottom.documentStrip.play1Button.BackColor == Color.Gray)
return;
else
{
this.PanelBottom.documentStrip.play1Button.BackColor = Color.Gray;
this.panelBottom.documentStrip.play2Button.BackColor = Color.FromArgb(255, 240, 240, 240);
this.playMode = 1;
}
}
///
/// 从前往后播放按钮
///
///
///
private void PanelBottom_Play2ButtonClick(object sender, EventArgs e)
{
if (this.PanelBottom.documentStrip.play2Button.BackColor == Color.Gray)
return;
else
{
this.PanelBottom.documentStrip.play2Button.BackColor = Color.Gray;
this.panelBottom.documentStrip.play1Button.BackColor = Color.FromArgb(255, 240, 240, 240);
this.playMode = 2;
}
}
///
/// 循环播放按钮
///
///
///
private void PanelBottom_Play3ButtonClick(object sender, EventArgs e)
{
if (this.PanelBottom.documentStrip.play3Button.BackColor == Color.Gray)
{
this.panelBottom.documentStrip.play3Button.BackColor = Color.FromArgb(255, 240, 240, 240);
this.isLoopPlayback = false;
}
else
{
this.PanelBottom.documentStrip.play3Button.BackColor = Color.Gray;
this.isLoopPlayback = true;
}
}
///
/// 播放(暂停)按钮
///
///
///
private void PanelBottom_PlayOrPauseButtonClick(object sender, EventArgs e)
{
timer.Enabled = !timer.Enabled;
}
///
/// 删除当前页按钮
///
///
///
private void PanelBottom_DeleteButtonClick(object sender, EventArgs e)
{
if (this.activeDocumentWorkspace.zipHandleHelper != null)
{
//如点击删除时正在播放是否需要关闭定时器?
if (timer.Enabled)
timer.Enabled = false;
//压缩包里只有一张图片的情况,可能需替换成别的逻辑
if (this.activeDocumentWorkspace.zipXmlModel.picNameList.Count == 1)
{
MessageBox.Show(PdnResources.GetString("Menu.Thereisonlyoneimwedtobedeleted.text"));
return;
}
this.activeDocumentWorkspace.zipHandleHelper.DeletePicFromZip(this.activeDocumentWorkspace.zipXmlModel.picNameList[this.PanelBottom.documentStrip.trackBar.Value - 1].name);
this.activeDocumentWorkspace.zipXmlModel.picNameList.RemoveAt(this.PanelBottom.documentStrip.trackBar.Value - 1);
this.activeDocumentWorkspace.zipHandleHelper.ModifyXmlNodes(this.activeDocumentWorkspace.zipXmlModel);
//如果删除的是最后一张图,索引向前移一位
if (this.PanelBottom.documentStrip.trackBar.Value > this.activeDocumentWorkspace.zipXmlModel.picNameList.Count)
this.PanelBottom.documentStrip.trackBar.Value -= 1;
ChangeImageInActiveDocument(this.PanelBottom.documentStrip.trackBar.Value);
this.PanelBottom.documentStrip.trackBar.Maximum = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
this.PanelBottom.documentStrip.textBox.Text = this.PanelBottom.documentStrip.trackBar.Value + @"/" + this.PanelBottom.documentStrip.trackBar.Maximum;
}
}
///
/// 修改播放间隔按钮
///
///
///
private void PanelBottom_EditTimeButtonClick(object sender, EventArgs e)
{
using (PlayIntervalSettingDialog playIntervalSettingDialog = new PlayIntervalSettingDialog())
{
playIntervalSettingDialog.StartPosition = FormStartPosition.CenterScreen;
playIntervalSettingDialog.textBox1.Text = timer.Interval.ToString();
playIntervalSettingDialog.button1.Click += new EventHandler(IntervalDialog_ButtonClick);
playIntervalSettingDialog.ShowDialog();
}
}
///
/// 播放间隔设置页的确定按钮
///
///
///
private void IntervalDialog_ButtonClick(object sender, EventArgs e)
{
Button button = (Button)sender;
PlayIntervalSettingDialog playIntervalSettingDialog = (PlayIntervalSettingDialog)button.Parent;
timer.Interval = Convert.ToInt32(playIntervalSettingDialog.textBox1.Text);
playIntervalSettingDialog.Close();
}
///
/// 播放使用定时器
///
///
///
private void timer_Tick(object sender, EventArgs e)
{
//前到后
if (this.playMode == 2)
{
if (this.PanelBottom.documentStrip.trackBar.Value < this.activeDocumentWorkspace.zipXmlModel.picNameList.Count)//当前不是最后一张图
this.PanelBottom.documentStrip.trackBar.Value += 1;
else
{
//是否循环
if (isLoopPlayback)
{
this.PanelBottom.documentStrip.trackBar.Value = 1;
}
else
{
//不循环则到终点关闭定时器
timer.Enabled = false;
return;
}
}
}
//后到前
if (this.playMode == 1)
{
if (this.PanelBottom.documentStrip.trackBar.Value > 1)//当前不是第一张图
this.PanelBottom.documentStrip.trackBar.Value -= 1;
else
{
//是否循环
if (isLoopPlayback)
{
this.PanelBottom.documentStrip.trackBar.Value = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
}
else
{
//不循环则到终点关闭定时器
timer.Enabled = false;
return;
}
}
}
ChangeImageInActiveDocument(this.PanelBottom.documentStrip.trackBar.Value);
this.PanelBottom.documentStrip.trackBar.Maximum = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
this.PanelBottom.documentStrip.textBox.Text = this.PanelBottom.documentStrip.trackBar.Value + @"/" + this.PanelBottom.documentStrip.trackBar.Maximum;
}
///
/// 替换当前画布的图片
///
///
private void ChangeImageInActiveDocument(int trackBarValue)
{
this.activeDocumentWorkspace.picName = this.activeDocumentWorkspace.zipXmlModel.picNameList[trackBarValue - 1].name;
Image zipImage = this.activeDocumentWorkspace.zipHandleHelper.GetPicFromZip(this.activeDocumentWorkspace.picName);
Document document = Document.FromImageMat(Camera.Tools.ToMat((Bitmap)zipImage));
this.activeDocumentWorkspace.fileText = this.activeDocumentWorkspace.picName;//tab页改图片名不好用
this.activeDocumentWorkspace.Document = document;
}
private bool ExistenceXML()
{
if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.existenceXML)
{
return true;
}
//获取图片路径
bool existenceXML = false;
if (this.activeDocumentWorkspace != null)
{
string fileName;
//FileType fileType;
//SaveConfigToken saveConfigToken;
this.activeDocumentWorkspace.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/);
if (fileName != null)
{
string path = Path.GetDirectoryName(fileName);
string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
existenceXML = System.IO.File.Exists(xmlPath);
if (existenceXML)
{
PicConfigModel configModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
this.activeDocumentWorkspace.RuleAttribute(configModel);
}
//this.activeDocumentWorkspace.existenceXML = existenceXML;
}
}
return existenceXML;
}
#endregion
#region 标尺相关
///
/// 刷新标尺列表
///
public void RefueshRuleList()
{
if (this.widgets.RuleListForm != null)
{
this.widgets.RuleListForm.InitListViewData();
}
}
///
/// 激活理论比例尺
///
public void ActivateTemporaryRuler()
{
if (this.widgets.RuleListForm != null)
{
this.widgets.RuleListForm.ActivateTemporaryRuler();
}
}
///
/// 设置当前选中标尺
///
///
public void SetActiveRulerIndex(int index)
{
if (this.widgets.RuleListForm != null)
{
this.widgets.RuleListForm.SetActiveRulerIndex(index);
}
}
///
/// 刷新当前选中的标尺-编辑后使用
///
public void RefreshActiveRuler()
{
if (this.widgets.RuleListForm != null)
{
this.widgets.RuleListForm.RefreshActiveRuler();
}
}
#endregion
///
/// 刷新测量工具相关别名
///
public void RefreshAliasName()
{
if (this.widgets.GeometryMeasureDialog != null)
{
this.widgets.GeometryMeasureDialog.RefreshAliasName();
}
}
#region 项目工程
///
/// 通用、专用分析添加到项目工程,获取路径,路径就是编号
///
/// 1通用分析 2专用分析
/// 分析的名称
///
public ProjectEngineering.NodeItem GetInsertProjectPath(int type, string analysis, string originPath)
{
return this.Widgets.ProjectEngineering.GetProjectPath(type, analysis, originPath);
}
///
/// 插入数据库
///
/// 分析设置信息
/// 项目编号
public void InsertIntoDB(AnalyzeSettingModel analyzeSettingModel, ProjectEngineering.NodeItem code)
{
this.Widgets.ProjectEngineering.InsertIntoDB(analyzeSettingModel, code);
}
#endregion
#region 生成报告相关
///
/// 导出结果(一个sheet页/多个sheet页),可选择性的显示进度条
///
public void ExportDataToExcelWithProgress(List datas, string path, bool heaterTextShow = true, bool multiSheet = false, bool showProgress = false, Form currentForm = null, string dialogText = null)
{
AppCommon appCommon = new AppCommon();
if (!appCommon.isExcelInstalled())
{
MessageBox.Show(PdnResources.GetString("office.Message"));
return;
}
Microsoft.Office.Interop.Excel.Worksheet workSheet = null;
Microsoft.Office.Interop.Excel.Workbook workBook = null;
Microsoft.Office.Interop.Excel.Workbooks workbooks = null;
Microsoft.Office.Interop.Excel.Application xlApp = null;
if (showProgress /*&& currentForm != null*/ && datas != null && datas.Count > 0)
{
ProgressThreadProcClass procClass = new ProgressThreadProcClass();
int itemCount = 100;
ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
System.Threading.ThreadStart copyThreadProc =
delegate ()
{
try
{
progressEvents.SetItemCount(itemCount);
double currentWriteRow = 0.0;
double rowsCount = 0.0;
foreach (System.Data.DataTable dtb in datas)
rowsCount += dtb.Rows.Count;
progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
//if(heaterTextShow)
//{
// for (int i = 0; i < itemCount; ++i)
// {
// System.Threading.Thread.Sleep(50);
// progressEvents.SetItemOrdinal(i);
// }
//}
xlApp = new Microsoft.Office.Interop.Excel.Application();
workbooks = xlApp.Workbooks;
workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
if (multiSheet)
{
if (datas != null && datas.Count > 0)
{
int ka = 1;
foreach (System.Data.DataTable dtb in datas)
{
if (ka > 1)
{
Microsoft.Office.Interop.Excel.Sheets sheets = workBook.Worksheets;
workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
}
else
{
workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
}
if (dtb.TableName != null)
{
workSheet.Name = dtb.TableName;
}
ka++;
if (heaterTextShow)
{
for (int i = 0; i < dtb.Columns.Count; i++)
{
workSheet.Cells[1, i + 1] = dtb.Columns[i].ColumnName;
}
}
//解决标题重复显示的问题
bool columNameRepeat = true;
if (dtb.Rows.Count > 0)
for (int k = 0; k < dtb.Columns.Count; k++)
if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
{
columNameRepeat = false;
break;
}
for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
{
currentWriteRow += 1;
progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
for (int k = 0; k < dtb.Columns.Count; k++)
{
workSheet.Cells[j + (heaterTextShow ? 2 : 1) /*- (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
}
}
//workSheet.SaveAs(path, missing, missing, missing, missing, missing, missing, missing, missing, missing);
}
}
}
else
{
workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
if (datas != null && datas.Count > 0)
{
int kk = 0;
int jj = 0;
foreach (System.Data.DataTable dtb in datas)
{
//if (kk == 0)
{
if (heaterTextShow)
{
if (kk > 0)
jj++;//避免标题被后面数据覆盖
for (int i = 0; i < dtb.Columns.Count; i++)
{
workSheet.Cells[jj + 1, i + 1] = dtb.Columns[i].ColumnName;
}
}
kk++;
}
//解决标题重复显示的问题
bool columNameRepeat = true;
if (dtb.Rows.Count > 0)
for (int k = 0; k < dtb.Columns.Count; k++)
if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
{
columNameRepeat = false;
break;
}
for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
{
currentWriteRow += 1;
progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
for (int k = 0; k < dtb.Columns.Count; k++)
{
workSheet.Cells[jj + (heaterTextShow ? 2 : 1)/* - (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
}
jj++;
}
}
}
}
object nothing = Type.Missing;
workBook.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
finally
{
if (xlApp != null)
{
if (xlApp != null && workBook != null)
workBook.Close(false);
xlApp.Quit();
OfficeFileHandleHelper.Kill(xlApp);
}
progressEvents.EndOperation(OperationResult.Finished);
}
};
procClass.StartProgressAction(/*currentForm*/this.form, itemCount, copyThreadProc, progressEvents, dialogText);
return;
}
try
{
xlApp = new Microsoft.Office.Interop.Excel.Application();
workbooks = xlApp.Workbooks;
workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
if (multiSheet)
{
if (datas != null && datas.Count > 0)
{
int ka = 1;
foreach (System.Data.DataTable dtb in datas)
{
if (ka > 1)
{
Microsoft.Office.Interop.Excel.Sheets sheets = workBook.Worksheets;
workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
}
else
{
workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
}
if (dtb.TableName != null)
workSheet.Name = dtb.TableName;
ka++;
if (heaterTextShow)
{
for (int i = 0; i < dtb.Columns.Count; i++)
{
workSheet.Cells[1, i + 1] = dtb.Columns[i].ColumnName;
}
}
//解决标题重复显示的问题
bool columNameRepeat = true;
if (dtb.Rows.Count > 0)
for (int k = 0; k < dtb.Columns.Count; k++)
if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
{
columNameRepeat = false;
break;
}
for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
{
for (int k = 0; k < dtb.Columns.Count; k++)
{
workSheet.Cells[j + (heaterTextShow ? 2 : 1)/* - (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
}
}
//workSheet.SaveAs(path, missing, missing, missing, missing, missing, missing, missing, missing, missing);
}
}
}
else
{
workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
if (datas != null && datas.Count > 0)
{
int kk = 0;
int jj = 0;
foreach (System.Data.DataTable dtb in datas)
{
//if (kk == 0)
{
if (heaterTextShow)
{
if (kk > 0)
jj++;//避免标题被后面数据覆盖
for (int i = 0; i < dtb.Columns.Count; i++)
{
workSheet.Cells[jj + 1, i + 1] = dtb.Columns[i].ColumnName;
}
}
kk++;
}
//解决标题重复显示的问题
bool columNameRepeat = true;
if (dtb.Rows.Count > 0)
for (int k = 0; k < dtb.Columns.Count; k++)
if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
{
columNameRepeat = false;
break;
}
for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
{
for (int k = 0; k < dtb.Columns.Count; k++)
{
workSheet.Cells[jj + (heaterTextShow ? 2 : 1) /*- (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
}
jj++;
}
}
}
}
object nothing = Type.Missing;
workBook.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
finally
{
if (xlApp != null)
{
if (xlApp != null && workBook != null)
workBook.Close(false);
xlApp.Quit();
OfficeFileHandleHelper.Kill(xlApp);
}
}
}
///
/// 生成分析报告(夹杂物)
///
/// 基础信息对象
/// 数据对象模型
/// 图片集合
/// 除基础信息外的word书签与excel坐标对应信息
public void CreateAnalysisReportInclusion(AnalyzeSettingModel analyzeSettingModel, List>> sheets, List bitmapList,
Dictionary tagPositionDic)
{
AppCommon appCommon = new AppCommon();
if (!appCommon.isExcelInstalled())
{
MessageBox.Show(PdnResources.GetString("office.Message"));
return;
}
if (analyzeSettingModel == null)
{
MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
return;
}
if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
{
MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
return;
}
if (sheets.Count == 0)
{
MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
return;
}
ProgressThreadProcClass procClass = new ProgressThreadProcClass();
System.Threading.ThreadStart copyThreadProc =
delegate ()
{
int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
double pointPitch = 0;
if (dotPitch > 0)
{
mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
if (screenList != null)
{
try
{
pointPitch = double.Parse(screenList.point_pitch);//获取点距
}
catch (System.Exception)
{
}
}
}
//获取系统的毫米标尺
double unitLength = 0;
this.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLength);
if (unitLength == 0)
unitLength = 1;
try
{
OfficeFileHandleHelper.CreateAnalysisReportInclusion(analyzeSettingModel, sheets, bitmapList, tagPositionDic, pointPitch, unitLength, GetGainMultiple());
procClass.DismissProgressAction(this.form);
MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
}
catch (Exception)
{
MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
}
finally
{
procClass.DismissProgressAction(this.form);
}
};
procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
}
///
/// 生成分析报告
///
///
///
///
///
public void CreateAnalysisReport(AnalyzeSettingModel analyzeSettingModel, List> contentList, List bitmapList,
Dictionary tagPositionDic, string dictPath = null, Dictionary pNames = null, List> content2List = null)
{
AppCommon appCommon = new AppCommon();
if (!appCommon.isExcelInstalled())
{
MessageBox.Show(PdnResources.GetString("office.Message"));
return;
}
if (analyzeSettingModel == null)
{
MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
return;
}
if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
{
MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
return;
}
//if (contentList != null && contentList.Count == 0)
//{
// MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
// return;
//}
ProgressThreadProcClass procClass = new ProgressThreadProcClass();
System.Threading.ThreadStart copyThreadProc =
delegate ()
{
//bool isNeedZoom = false;//是否需要缩放
//int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
//double pointPitch = 0;
//if (dotPitch > 0)
//{
// mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
// if (screenList != null)
// {
// try
// {
// pointPitch = double.Parse(screenList.point_pitch);//获取点距
// if (pointPitch > 0)
// isNeedZoom = true;
// }
// catch (System.Exception)
// {
// }
// }
//}
//当前图片微米标尺(点距计算用毫米)
double unitLength = 0;
//当前图片放大倍数
double pointPitch = 0;
this.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
//获取当前图片放大倍数
if (this.activeDocumentWorkspace != null)
pointPitch = (double)this.activeDocumentWorkspace.xmlSaveModel.gain_multiple;
else
pointPitch = 1;
bool isNeedZoom = true;
if (unitLength == 0)
unitLength = 1;
try
{
OfficeFileHandleHelper.CreateAnalysisReport(analyzeSettingModel, contentList, bitmapList, tagPositionDic, isNeedZoom, pointPitch, unitLength, GetGainMultiple(), dictPath, pNames, content2List);
procClass.DismissProgressAction(this.form);
MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
}
catch (Exception)
{
MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
}
finally
{
procClass.DismissProgressAction(this.form);
}
};
procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
}
///
/// 生成分析报告并保存图片与中间数据
///
///
///
///
///
///
///
///
public void CreateAnalysisReport(AnalyzeSettingModel analyzeSettingModel, List> contentList, List dataList,
List bitmapList, Dictionary tagPositionDic, string newPath, string newCode
, string dictPath = null, Dictionary pNames = null, List> content2List = null)
{
AppCommon appCommon = new AppCommon();
if (!appCommon.isExcelInstalled())
{
MessageBox.Show(PdnResources.GetString("office.Message"));
return;
}
if (analyzeSettingModel == null)
{
MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
return;
}
if (string.IsNullOrEmpty(newPath))
{
MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
return;
}
if (contentList.Count == 0)
{
MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
return;
}
if (string.IsNullOrEmpty(newCode))
{
MessageBox.Show(PdnResources.GetString("Menu.nonumcannotsave.Text"));
return;
}
ProgressThreadProcClass procClass = new ProgressThreadProcClass();
System.Threading.ThreadStart copyThreadProc =
delegate ()
{
//bool isNeedZoom = false;//是否需要缩放
//int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
//double pointPitch = 0;
//if (dotPitch > 0)
//{
// mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
// if (screenList != null)
// {
// try
// {
// pointPitch = double.Parse(screenList.point_pitch);//获取点距
// if (pointPitch > 0)
// isNeedZoom = true;
// }
// catch (System.Exception)
// {
// }
// }
//}
////获取系统的毫米标尺
//double unitLength = 0;
//this.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLength);
//if (unitLength == 0)
// unitLength = 1;
//当前图片微米标尺(点距计算用毫米)
double unitLength = 0;
//当前图片放大倍数
double pointPitch = 0;
this.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
//获取当前图片放大倍数
if (this.activeDocumentWorkspace != null)
pointPitch = (double)this.activeDocumentWorkspace.xmlSaveModel.gain_multiple;
else
pointPitch = 1;
bool isNeedZoom = true;
try
{
OfficeFileHandleHelper.CreateAnalysisReport(analyzeSettingModel, contentList, dataList, bitmapList, tagPositionDic, newPath, newCode, isNeedZoom, pointPitch, unitLength, GetGainMultiple(), dictPath, pNames, content2List);
procClass.DismissProgressAction(this.form);
MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
}
catch (Exception)
{
MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
}
finally
{
procClass.DismissProgressAction(this.form);
}
};
procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Exportproject.text"));
}
public void CopyAndPasteByControlAndDoubleClick()
{
this.ToolBar.CopyAndPasteByControlAndDoubleClick();
}
#endregion
#region
//creating by zm
///
/// 生成高碳铬轴承钢分析报告
///
///
///
///
///
public void CreateAnalysisReportBearingSteal(AnalyzeSettingModel analyzeSettingModel, List> contentList, List bitmapList,
Dictionary tagPositionDic, string dictPath = null, Dictionary pNames = null, List> content2List = null)
{
AppCommon appCommon = new AppCommon();
if (!appCommon.isExcelInstalled())
{
MessageBox.Show(PdnResources.GetString("office.Message"));
return;
}
if (analyzeSettingModel == null)
{
MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
return;
}
if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
{
MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
return;
}
if (contentList != null && contentList.Count == 0)
{
MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
return;
}
ProgressThreadProcClass procClass = new ProgressThreadProcClass();
System.Threading.ThreadStart copyThreadProc =
delegate ()
{
//当前图片微米标尺(点距计算用毫米)
double unitLength = 0;
//当前图片放大倍数
double pointPitch = 0;
this.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
//获取当前图片放大倍数
if (this.activeDocumentWorkspace != null)
pointPitch = (double)this.activeDocumentWorkspace.xmlSaveModel.gain_multiple;
else
pointPitch = 1;
bool isNeedZoom = true;
if (unitLength == 0)
unitLength = 1;
CreateAnalysisReportBearingSteelExcel(analyzeSettingModel, contentList, bitmapList, tagPositionDic, isNeedZoom, pointPitch, unitLength, GetGainMultiple(), dictPath, pNames, content2List);
//CreateBearingStealDOC(analyzeSettingModel, contentList,bitmapList, tagPositionDic, pointPitch, unitLength, GetGainMultiple());
procClass.DismissProgressAction(this.form);
MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
};
procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
}
///
/// 生成分析报告
///
/// 基础信息对象
/// 数据对象模型
/// 图片集合
/// 除基础信息外的word书签与excel坐标对应信息
/// 当前图片放大倍数
/// 当前图片标尺
/// 系统激活放大倍数(暂时不用保留)
private static void CreateAnalysisReportBearingSteelExcel(AnalyzeSettingModel analyzeSettingModel, List> contentList, List bitmapList,
Dictionary tagPositionDic, bool isNeedZoom, double pointPitch, double unitLength, decimal gainMultiple, string dictPath = null, Dictionary pNames = null, List> content2List = null)
{
string saveAsPath = "";
string excelModulePath = Path.GetDirectoryName(analyzeSettingModel.modulePath) + "\\公式.xlsx";//获取excel公式模板的路径
if (System.IO.File.Exists(excelModulePath))
{
saveAsPath = analyzeSettingModel.savePath + "\\" + "高碳铬轴承钢_GBT18254-2002_带状"
+ DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";//另存的excel文件名
//如果savePath是盘符不是文件夹,会多出一个斜杠,office的saveas无法识别,固需处理一下
if (saveAsPath.IndexOf("\\\\") != -1)
saveAsPath = saveAsPath.Replace("\\\\", "\\");
if (contentList != null)
{
SaveAsExcelWithModule(excelModulePath, saveAsPath, contentList, dictPath, pNames, content2List);
}
CreateBearingStealDOC(analyzeSettingModel, contentList, bitmapList, tagPositionDic, pointPitch, unitLength, gainMultiple);
}
}
private static MSWord.Application m_word;
private static MSWord.Document m_doc;
private static Object missing = Type.Missing;
private static MSExcel.Application m_excel;
private static MSExcel.Workbook m_workbook;
private static MSExcel.Worksheet m_worksheet;
private static MSExcel.Worksheet m2_worksheet;
///
/// 通过公式模板创建并保存excel
///
/// excel公式模板路径
/// 新文件另存路径
/// 数据对象模型
///
private static bool SaveAsExcelWithModule(string excelModulePath, string saveAsPath, List> contentList, string dictPath = null, Dictionary pNames = null
, List> content2List = null)
{
try
{
m_excel = new MSExcel.Application();
m_workbook = m_excel.Workbooks.Add(excelModulePath);
m_worksheet = m_workbook.Sheets.Item[1];//数据固定插入在第二个sheet页
if (contentList != null)
{
if (m_workbook.Sheets.Count < 3)
m_workbook.Sheets.Add(System.Reflection.Missing.Value, m_worksheet, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
m2_worksheet = m_workbook.Sheets.Item[1];
AddTableToExcelSheet(m2_worksheet, 1, 1, contentList);
}
m_worksheet.SaveAs(saveAsPath, missing, missing, missing, missing, missing, missing, missing, missing, missing);
//m_worksheet.Activate();
m_workbook.Close(false);
m_excel.Application.Quit();
OfficeFileHandleHelper.Kill(m_excel);
m_worksheet = null;
m2_worksheet = null;
m_workbook = null;
m_excel = null;
}
catch (Exception)
{
if (m_excel != null)
{
if (m_workbook != null)
m_workbook.Close(false);
m_excel.Application.Quit();
OfficeFileHandleHelper.Kill(m_excel);
}
m_worksheet = null;
m2_worksheet = null;
m_workbook = null;
m_excel = null;
return false;
}
return true;
}
///
/// 向excel的sheet页指定单元格插入表格(自行拼接的list形式)
///
/// sheet页
/// 插入初始位置横坐标
/// 插入初始位置纵坐标
/// 表格对象
private static void AddTableToExcelSheet(MSExcel.Worksheet worksheet, int x, int y, List> contentList)
{
if (contentList.Count > 0)
{
for (int i = x; i < contentList.Count + 1; i++)
{
List rowContent = contentList[i - 1];
if (rowContent.Count > 0)
{
for (int j = y; j < rowContent.Count + 1; j++)
{
worksheet.Cells[i, j] = rowContent[j - 1];
}
}
}
}
}
///
/// 通过模板创建高碳铬轴承钢word报告文档
///
///
///
///
private static void CreateBearingStealDOC(AnalyzeSettingModel analyzeSettingModel, List> contentList, List bitmapList, Dictionary tagValueDic, double pointPitch, double unitLength, decimal gainMultiple)
{
if (!string.IsNullOrEmpty(analyzeSettingModel.modulePath) && Directory.Exists(analyzeSettingModel.savePath))
{
string newFilePath = analyzeSettingModel.savePath + "\\" + "高碳铬轴承钢_GBT18254-2002_带状" +
DateTime.Now.ToString("yyyyMMddHHmmss") + ".docx";
if (newFilePath.IndexOf("\\\\") != -1)
newFilePath = newFilePath.Replace("\\\\", "\\");
try
{
System.IO.File.Copy(analyzeSettingModel.modulePath, newFilePath, true);
}
catch (Exception)
{
//MessageBox.Show("word模板文件已打开,请关闭后重试");
return;
}
Object pathObj = newFilePath;
try
{
m_word = new MSWord.Application();
m_doc = m_word.Documents.Open(ref pathObj,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
foreach (MSWord.Bookmark bk in m_doc.Bookmarks)
{
if (bk.Name == "modulePath")
bk.Range.Text = analyzeSettingModel.modulePath;
else if (bk.Name == "savePath")
bk.Range.Text = analyzeSettingModel.savePath;
else if (bk.Name == "inspectionPerson")
bk.Range.Text = analyzeSettingModel.inspectionPerson;
else if (bk.Name == "itemNumber")
bk.Range.Text = analyzeSettingModel.itemNumber;
else if (bk.Name == "inspectionDepartment")
bk.Range.Text = analyzeSettingModel.inspectionDepartment;
else if (bk.Name == "contact")
bk.Range.Text = analyzeSettingModel.contact;
else if (bk.Name == "ratingDate")
bk.Range.Text = analyzeSettingModel.ratingDate.ToString("yyyy/MM/dd");
else if (bk.Name == "inspectionDate")
bk.Range.Text = analyzeSettingModel.inspectionDate.ToString("yyyy/MM/dd");
else if (bk.Name == "analyzeClassify")
bk.Range.Text = analyzeSettingModel.analyzeClassify;
else if (bk.Name == "other")
{
if (analyzeSettingModel.otherList != null && analyzeSettingModel.otherList.Count > 0)
{
MSWord.Table table = m_doc.Tables.Add(bk.Range, analyzeSettingModel.otherList.Count + 1, 2, ref missing, ref missing);
table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
table.Cell(1, 1).Range.Text = "名称";
table.Cell(1, 2).Range.Text = "内容";
for (int i = 0; i < analyzeSettingModel.otherList.Count; i++)
{
table.Cell(2 + i, 1).Range.Text = analyzeSettingModel.otherList[i].name;
table.Cell(2 + i, 2).Range.Text = analyzeSettingModel.otherList[i].content;
}
}
}
else if (bk.Name == "picture")
{
if (bitmapList != null && bitmapList.Count > 0)
{
bitmapList.Reverse();
for (int i = 0; i < bitmapList.Count; i++)
{
//Clipboard.SetDataObject(System.Environment.NewLine);
//bk.Range.Paste();
//Image img = bitmapList[i];
//OpenCvSharp.Mat m = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmapList[i]);
//OpenCvSharp.Mat resize_image = new OpenCvSharp.Mat();
//OpenCvSharp.Cv2.Resize(m,resize_image,new OpenCvSharp.Size(),0.5,0.5);
//Bitmap b = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resize_image);
//Clipboard.SetDataObject(b);
//bk.Range.Paste();
Bitmap bitmap = bitmapList[i];
int new_w = (int)bitmap.Width / 4;
int new_h = (int)bitmap.Height / 4;
Bitmap b = new Bitmap(new_w, new_h);
Graphics g = Graphics.FromImage(b);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(bitmap, new System.Drawing.Rectangle(0, 0, new_w, new_h), new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel);
Clipboard.SetDataObject(b);
bk.Range.Paste();
b.Dispose();
g.Dispose();
}
}
}
else
{
if (tagValueDic != null && tagValueDic.Count > 0)
{
foreach (KeyValuePair kvp in tagValueDic)
{
if (bk.Name == kvp.Key)
{
bk.Range.Text = kvp.Value;
break;
}
}
}
}
}
m_doc.Save();
m_doc.Close(true);
m_word.Quit();
}
catch (Exception ex)
{
string msg = ex.Message;
if (m_word != null)
{
if (m_doc != null)
m_doc.Close(false);
m_word.Quit();
}
}
m_doc = null;
m_word = null;
}
}
///
/// 返回定倍(A4纸)显示后的图片
/// 定倍计算公式:图片像素(宽和高) * 当前图片标尺 * 当前图片放大倍数
///
///
/// 当前图片放大倍数
/// 当前图片标尺
/// 系统激活标尺放大倍数(暂时没用)
///
private static Bitmap GetFixedMultipleBitmap(Bitmap oldBit, double pointPitch, double unitLength, decimal gainMultiple)
{
if (pointPitch == 0)
return oldBit;
int oldWidth = oldBit.Width;
int oldHeight = oldBit.Height;
int targetWidth = 0;
int targetHeight = 0;
if (oldWidth <= 1 || oldHeight <= 1)//像素最小为1,之后不再处理
return oldBit;
int newWidth = oldWidth / 2;
int newHeight = oldHeight / 2;
//缩放图片
Bitmap targetBit = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(targetBit);
g.DrawImage(oldBit, new System.Drawing.Rectangle(0, 0, newWidth, newHeight), new System.Drawing.Rectangle(0, 0, oldWidth, oldHeight), GraphicsUnit.Pixel);
return targetBit;
}
#endregion
public void SetContinuousDrawingMeasure(bool value)
{
this.continuousDrawingMeasure = value;
this.continuousDrawingLabel = value;
SetTopLeftCheckState();
}
public void SetContinuousDrawingLable(bool value)
{
this.continuousDrawingLabel = value;
this.continuousDrawingLabel = value;
SetTopLeftCheckState();
}
///
/// 录制脚本添加参数
///
public void SetScriptStartRecording(int menuId, string menuName, List list)
{
mic_script_step script_Step = new mic_script_step();
script_Step.automatic = 2;
script_Step.menu_id = menuId;
script_Step.script_id = 0;
script_Step.step_name = menuName;
script_Step.step_sort = this.addMicScriptStepList.Count;
this.addMicScriptStepList.Add(script_Step);
this.addMicScriptStepParamList.Add(script_Step, list);
}
}
}