using OpenCvSharp;
using Resources;
using SmartCoalApplication.Annotation;
using SmartCoalApplication.Annotation.FieldView;
using SmartCoalApplication.Base.CommTool;
using SmartCoalApplication.Base.FunctionModel;
using SmartCoalApplication.Core;
using SmartCoalApplication.Core.CustomControl;
using SmartCoalApplication.Core.Param;
using SmartCoalApplication.ParameterSet;
using SmartCoalApplication.Resources;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static SmartCoalApplication.AutomaticMeasurement.ImageTools;
namespace SmartCoalApplication.AutomaticMeasurement
{
internal partial class PlotTheMeasurementRange : PdnBaseForm
{
///
/// 分析设置存储信息
///
protected AnalyzeSettingModel analyzeSettingModel = new AnalyzeSettingModel();
///
/// 图片名称对应关系
///
Dictionary pNames = new Dictionary();
private List pictures = new List();
private List originalPictures = new List();
private List oldOriginalPictures = new List();
private List pictureNames = new List();
private int index = new int();
private AppWorkspace appWorkspace;
private CommonControlButtons commonControlButtons;
private Bitmap bitmap;
///
/// hint 提示信息
///
public ToolTip toolTip;
///
/// 图像面板
///
private DocumentWorkspaceWindow documentWorkspace;
///
/// 图像面板
///
private AutomaticMeasurement AutomaticMeasurement;
private Dictionary dataList = new Dictionary();
private int thisindex;
private int selectedIndex = -1;
private Dictionary> GraphicsList = new Dictionary>();
///
/// 播放模式 1 从后播放 2 从前往后播
///
private int playType = 2;
///
/// 播放模式 是否循环播放
///
private bool isLoop = false;
///
/// 播放还是暂停
///
private bool isPlay = false;
public List BitmapArray = new List();
public int OverlapWidth { get; set; }
public int OverlapHeight { get; set; }
private bool isNormal = false;
private AutomaticMeasurementModel automaticMeasurement;
private bool startSpin = false;
private System.Drawing.PointF startPoint;
private System.Drawing.PointF endPoint;
bool isErzhiCheckBox = false;
Dictionary> isErzhichuliList = new Dictionary>();
private Dictionary dataIsErzhichuliList = new Dictionary();
bool isFanweiCheckBox = false;
Dictionary> isFanweibuchangList = new Dictionary>();
private Dictionary dataIsFanweibuchangList = new Dictionary();
Dictionary> boolList = new Dictionary>();
private Dictionary dataBoolList = new Dictionary();
private double hasAngle = 0;
public PlotTheMeasurementRange(List pictures, List pictureNames, AppWorkspace appWorkspace, AutomaticMeasurement form, int index, Dictionary> GraphicsList, Dictionary> boolList,bool showCheckBox
, Dictionary> isFanweibuchangList, bool isFanweibuchangCheckBox, Dictionary> isErzhichuliList, bool isErzhichuliCheckBox)
{
this.pictures = pictures;
this.originalPictures.AddRange(pictures);
this.oldOriginalPictures.AddRange(pictures);
this.pictureNames = pictureNames;
InitializeComponent();
InitializeComponent2();
#region [播放按钮初始化]
//
// 从后往前播放
//
this.button1.Image = PdnResources.GetImageResource("Icons.MultiFromAfterPlayIcon.png").Reference;
this.button1.FlatStyle = FlatStyle.Flat;
this.button1.FlatAppearance.BorderSize = 0;
//
// 从前往后播放
//
this.button2.Image = PdnResources.GetImageResource("Icons.MultiFromBehindPlayIcon.png").Reference;
this.button2.FlatStyle = FlatStyle.Flat;
this.button2.FlatAppearance.BorderSize = 0;
this.button2.BackColor = Color.DarkGray;
//
// 循环播放
//
this.button3.Image = PdnResources.GetImageResource("Icons.MultiCirclePlayIcon.png").Reference;
this.button3.FlatStyle = FlatStyle.Flat;
this.button3.FlatAppearance.BorderSize = 0;
//
// 播放(暂停) 备注:这里需要判断显示播放/暂停
//
this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
this.button4.FlatStyle = FlatStyle.Flat;
this.button4.FlatAppearance.BorderSize = 0;
this.toolTip = new ToolTip();
this.toolTip.SetToolTip(this.button1, PdnResources.GetString("Menu.Playitbackwards.text"));
this.toolTip.SetToolTip(this.button2, PdnResources.GetString("Menu.Playbackandforth.text"));
this.toolTip.SetToolTip(this.button3, PdnResources.GetString("Menu.Loopfor.text"));
this.toolTip.SetToolTip(this.button4, PdnResources.GetString("Menu.Playpause.text"));
#endregion
this.Icon = PdnInfo.AppIcon;
this.appWorkspace = appWorkspace;
this.AutomaticMeasurement = form;
thisindex = index;
this.GraphicsList = GraphicsList;
this.dataList = new Dictionary();
if (this.GraphicsList.ContainsKey(thisindex))
{
int dataIndex = 0;
foreach (var item in this.GraphicsList[thisindex])
{
dataList.Add(dataIndex, item);
dataIndex++;
}
}
this.boolList = boolList;
if (this.boolList.ContainsKey(thisindex))
{
int dataIndex = 0;
foreach (var item in this.boolList[thisindex])
{
dataBoolList.Add(dataIndex, item);
dataIndex++;
}
}
this.isFanweibuchangList = isFanweibuchangList;
if (this.isFanweibuchangList.ContainsKey(thisindex))
{
int dataIndex = 0;
foreach (var item in this.isFanweibuchangList[thisindex])
{
dataIsFanweibuchangList.Add(dataIndex, item);
dataIndex++;
}
}
this.isErzhichuliList = isErzhichuliList;
if (this.isErzhichuliList.ContainsKey(thisindex))
{
int dataIndex = 0;
foreach (var item in this.isErzhichuliList[thisindex])
{
dataIsErzhichuliList.Add(dataIndex, item);
dataIndex++;
}
}
#region [图像面板相关]
//
//初始化图像控件
//
this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace);
this.documentWorkspace.Cursor = Cursors.Default;
this.documentWorkspace.Dock = DockStyle.Fill;
this.documentWorkspace.HookMouseEvents();
this.documentWorkspace.Visible = true;
//this.documentWorkspace.panel.Click += new EventHandler(this.documentWorkspace_panel_Click);
this.documentWorkspace.panel.MouseDown += new MouseEventHandler(this.documentWorkspace_panel_MouseDown);
this.documentWorkspace.panel.MouseMove += new MouseEventHandler(this.documentWorkspace_panel_MouseMove);
this.documentWorkspace.panel.MouseUp += new MouseEventHandler(this.documentWorkspace_panel_MouseUp);
PdnBaseForm.RegisterFormHotKey(Keys.Delete, OnDeleteHotKeyPressed);
PdnBaseForm.RegisterFormHotKey(Keys.Control | Keys.Delete, OneDataOnDeleteHotKeyPressed);
this.documentWorkspace.keepDraw = false;
PdnBaseForm.RegisterFormHotKey(Keys.Left, lastPicture);
PdnBaseForm.RegisterFormHotKey(Keys.Up, lastPicture);
PdnBaseForm.RegisterFormHotKey(Keys.Down, nextPicture);
PdnBaseForm.RegisterFormHotKey(Keys.Right, nextPicture);
this.groupBoxZhangshu.Controls.Add(this.documentWorkspace);
#endregion
this.commonControlButtons = new CommonControlButtons();
this.commonControlButtons.Dock = DockStyle.Top;
this.commonControlButtons.Height = 30;
this.commonControlButtons.HideZoomToWindowAndActualSize();
if (showCheckBox)
{
this.commonControlButtons.ShowCheckBox();
if (dataBoolList.Count > 0)
{
this.commonControlButtons.isModeCheckBox.Checked = dataBoolList[0];
}
}
else if (isFanweibuchangCheckBox)
{
isFanweiCheckBox = isFanweibuchangCheckBox;
this.commonControlButtons.ShowIsFanweibuchang();
if (dataIsFanweibuchangList.Count > 0)
{
this.commonControlButtons.isModeCheckBox.Checked = dataIsFanweibuchangList[0];
}
}
else if (isErzhichuliCheckBox)
{
isErzhiCheckBox = isErzhichuliCheckBox;
this.commonControlButtons.ShowIsErzhichuli();
if (dataIsErzhichuliList.Count > 0)
{
this.commonControlButtons.isModeCheckBox.Checked = dataIsErzhichuliList[0];
}
}
this.groupBoxZhangshu.Controls.Add(commonControlButtons);
InitCommonButtonEvent();
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
//this.documentWorkspace.SetContinuousDrawingVoid(true);
this.PlotTheMeasurementRange_Load();
#region [播放事件初始化]
this.triangleTrackBar1.Value = 1;
this.triangleTrackBar1.Maximum = this.listPictureName.Items.Count;
this.textBox1.Text = $"{this.listPictureName.SelectedIndex + 1}/{this.triangleTrackBar1.Maximum}";
#endregion
#region [默认叠加]
this.button6_Click(null, null);
#endregion
this.getLastData();
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.saveLastData);
}
private void InitializeComponent2()
{
this.Text = PdnResources.GetString("NewDrawMeasurementRange");
this.groupBox1.Text = PdnResources.GetString("NewOperation");
this.checkBox1.Text = PdnResources.GetString("NewPauseDrawing");
this.buttonOKDraw.Text = PdnResources.GetString("NewMakeSureDraw");
this.groupBox2.Text = PdnResources.GetString("NewPictureList");
this.button6.Text = PdnResources.GetString("NewSuperposition");
this.button5.Text = PdnResources.GetString("NewNormal");
this.label1.Text = PdnResources.GetString("NewTransparency") +":";
this.groupBoxZhangshu.Text = PdnResources.GetString("NewTheFirstNne");
}
#region [参数保存]
///
/// 获取上次操作参数
///
private void getLastData()
{
string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\AutomaticMeasurement.xml";
if (!System.IO.File.Exists(filePath))
{
automaticMeasurement = new AutomaticMeasurementModel();
automaticMeasurement.PlotTheMeasurementRangeModels = new PlotTheMeasurementRangeModel();
string porosityInfoXml = XmlSerializeHelper.XmlSerialize(automaticMeasurement);
Directory.CreateDirectory(Application.StartupPath + "\\Config\\Default\\ParameterSaving\\");
FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.CreateNew);
}
else
{
automaticMeasurement = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
if (automaticMeasurement.PlotTheMeasurementRangeModels == null)
{
automaticMeasurement.PlotTheMeasurementRangeModels = new PlotTheMeasurementRangeModel();
}
if (automaticMeasurement.PlotTheMeasurementRangeModels.hasUsed)
{
checkBox1.Checked = automaticMeasurement.PlotTheMeasurementRangeModels.parameter1;
textBox2.Text = automaticMeasurement.PlotTheMeasurementRangeModels.parameter2.ToString();
this.timer1.Interval = automaticMeasurement.PlotTheMeasurementRangeModels.parameter2;
}
}
}
///
/// 保存上次操作参数
///
private void saveLastData(object sender, EventArgs e)
{
if (automaticMeasurement.PlotTheMeasurementRangeModels == null)
{
automaticMeasurement.PlotTheMeasurementRangeModels = new PlotTheMeasurementRangeModel();
}
int Interval = 1000;
try
{
Interval = Convert.ToInt32(textBox2.Text);
}
catch (Exception)
{
}
automaticMeasurement.PlotTheMeasurementRangeModels.hasUsed = true;
automaticMeasurement.PlotTheMeasurementRangeModels.parameter1 = checkBox1.Checked;
automaticMeasurement.PlotTheMeasurementRangeModels.parameter2 = Interval;
string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\AutomaticMeasurement.xml";
string porosityInfoXml = XmlSerializeHelper.XmlSerialize(automaticMeasurement);
FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.Create);
this.timer1.Stop();
#region [清空内存]
originalPictures.Clear();
oldOriginalPictures.Clear();
//pictures.Clear();
BitmapArray.Clear();
GC.Collect();
#endregion
}
#endregion
private bool lastPicture(Keys keys)
{
if (this.listPictureName.SelectedIndex == 0)
{
this.listPictureName.SelectedIndex = this.listPictureName.Items.Count - 1;
}
else {
this.listPictureName.SelectedIndex -= 1;
}
return true;
}
private bool nextPicture(Keys keys)
{
if (this.listPictureName.SelectedIndex == this.listPictureName.Items.Count - 1)
{
this.listPictureName.SelectedIndex = 0;
}
else
{
this.listPictureName.SelectedIndex += 1;
}
return true;
}
private void documentWorkspace_panel_MouseMove(object sender, MouseEventArgs e)
{
if (this.startSpin)
{
return;
}
}
private bool OneDataOnDeleteHotKeyPressed(Keys keys)
{
if (this.listPictureName.SelectedItem != null)
{
this.documentWorkspace.GraphicsList.Clear();
if (this.dataList.ContainsKey(this.listPictureName.SelectedIndex)) {
this.dataList[this.listPictureName.SelectedIndex].Clear();
}
this.documentWorkspace.Refresh();
}
return true;
}
private bool OnDeleteHotKeyPressed(Keys keys)
{
this.documentWorkspace.GraphicsList.Clear();
foreach (var item in dataList)
{
item.Value.Clear();
}
this.documentWorkspace.Refresh();
if (this.startSpin)
{
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.DrawLine;
}
else {
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
}
return true;
}
private void documentWorkspace_panel_MouseUp(object sender, MouseEventArgs e)
{
#region [旋转]
if (this.startSpin)
{
if (e.Button == MouseButtons.Left)
{
double angle = 0;
int removeIndex = -1;
for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
{
if (this.documentWorkspace.GraphicsList[i].objectType != Annotation.Enum.DrawClass.Label)
{
continue;
}
if (this.documentWorkspace.GraphicsList[i].startPoint.X <= this.documentWorkspace.GraphicsList[i].endPoint.X)
{
this.startPoint = this.documentWorkspace.GraphicsList[i].startPoint;
this.endPoint = this.documentWorkspace.GraphicsList[i].endPoint;
}
else {
this.startPoint = this.documentWorkspace.GraphicsList[i].endPoint;
this.endPoint = this.documentWorkspace.GraphicsList[i].startPoint;
}
angle = BasicCalculationHelper.Angle(startPoint, endPoint, new PointF(startPoint.X, endPoint.Y));
removeIndex = i;
}
angle = 0 - angle + this.hasAngle;
this.hasAngle = angle;
ParamObject action = new Data.Action.Action5017();
for (int i = 0; i < action.Lists.Count; i++)
{
if (action.Lists[i] is DecimalNumber)
{
action.Lists[i].value = angle;
}
}
Bitmap bitmap = (Bitmap)this.oldOriginalPictures[this.selectedIndex].Clone();
Mat mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap));
Bitmap newbitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
pictures[this.selectedIndex] = newbitmap;
this.originalPictures[this.selectedIndex] = newbitmap;
if (removeIndex != -1)
{
this.documentWorkspace.GraphicsList.RemoveAt(removeIndex);
this.documentWorkspace.Refresh();
}
#region [清空内存]
if (bitmap != null)
{
bitmap.Dispose();
}
//if (newbitmap != null)
//{
// newbitmap.Dispose();
//}
//if (mat != null)
//{
// mat.Dispose();
//}
#endregion
}
else if (e.Button == MouseButtons.Right)
{
pictures[this.selectedIndex] = this.oldOriginalPictures[this.selectedIndex];
this.originalPictures[this.selectedIndex] = this.oldOriginalPictures[this.selectedIndex];
this.hasAngle = 0;
}
this.bitmap = pictures[this.selectedIndex];
Document document = Document.FromImage(this.bitmap);
this.documentWorkspace.Document = document;
this.documentWorkspace.Visible = true;
return;
}
#endregion
GraphicsList graphicsList = new GraphicsList();
int removeData = -1;
for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
{
if (this.documentWorkspace.GraphicsList[i].Width <= 100 && this.documentWorkspace.GraphicsList[i].Height <= 100)
{
removeData = i;
continue;
}
graphicsList.Add(this.documentWorkspace.GraphicsList[i].Clone(this.documentWorkspace));
}
if (removeData != -1)
{
this.documentWorkspace.GraphicsList.RemoveAt(removeData);
this.documentWorkspace.SetContinuousDrawingVoid(true);
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
this.documentWorkspace.Refresh();
return;
}
if (e.Button == MouseButtons.Left)
{
for (int i = 0; i < this.listPictureName.Items.Count; i++)
{
if (this.dataList.ContainsKey(i))
{
this.dataList[i] = graphicsList;
}
else
{
this.dataList.Add(i, graphicsList);
}
}
}
else if (e.Button == MouseButtons.Right)
{
if (this.listPictureName.SelectedItem != null)
{
if (this.dataList.ContainsKey(this.listPictureName.SelectedIndex))
{
this.dataList[this.listPictureName.SelectedIndex] = graphicsList;
}
else
{
this.dataList.Add(this.listPictureName.SelectedIndex, graphicsList);
}
}
if (isPlay)
{
timer1.Start();
}
}
if (this.checkBox1.Checked)
{
if (isPlay)
{
timer1.Start();
}
}
}
///
///
///
///
///
private void documentWorkspace_panel_MouseDown(object sender, MouseEventArgs e)
{
if (this.startSpin)
{
this.documentWorkspace.tools[(int)(this.documentWorkspace.activeTool)].InvokeMember("OnMouseDown",
BindingFlags.Public |
BindingFlags.Static |
BindingFlags.InvokeMethod,
null,
null,
new object[2] { this.documentWorkspace, e });
return;
}
if (this.documentWorkspace.GraphicsList.Count > 0)
{
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.Pointer;
this.documentWorkspace.SetContinuousDrawingVoid(false);
this.documentWorkspace.tools[(int)(this.documentWorkspace.activeTool)].InvokeMember("OnMouseDown",
BindingFlags.Public |
BindingFlags.Static |
BindingFlags.InvokeMethod,
null,
null,
new object[2] { this.documentWorkspace, e });
var baseData = (ViewRectangle)this.documentWorkspace.GraphicsList[this.documentWorkspace.GraphicsList.Count - 1];
if (!baseData.isHitTest)
{
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
this.documentWorkspace.SetContinuousDrawingVoid(true);
this.documentWorkspace.GraphicsList.RemoveAt(this.documentWorkspace.GraphicsList.Count - 1);
}
}
this.documentWorkspace.tools[(int)(this.documentWorkspace.activeTool)].InvokeMember("OnMouseDown",
BindingFlags.Public |
BindingFlags.Static |
BindingFlags.InvokeMethod,
null,
null,
new object[2] { this.documentWorkspace, e });
if (isPlay)
{
if (this.checkBox1.Checked || e.Button == MouseButtons.Right)
{
timer1.Stop();
}
else
{
GraphicsList graphicsList = new GraphicsList();
for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
{
graphicsList.Add(this.documentWorkspace.GraphicsList[i].Clone(this.documentWorkspace));
}
if (e.Button == MouseButtons.Left)
{
for (int i = 0; i < this.listPictureName.Items.Count; i++)
{
if (this.dataList.ContainsKey(i))
{
this.dataList[i] = graphicsList;
}
else
{
this.dataList.Add(i, graphicsList);
}
}
}
else if (e.Button == MouseButtons.Right)
{
if (this.listPictureName.SelectedItem != null)
{
if (this.dataList.ContainsKey(this.listPictureName.SelectedIndex))
{
this.dataList[this.listPictureName.SelectedIndex] = graphicsList;
}
else
{
this.dataList.Add(this.listPictureName.SelectedIndex, graphicsList);
}
}
}
}
}
}
#region 公共按钮
private void InitCommonButtonEvent()
{
this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
this.commonControlButtons.isModeCheckBox.CheckedChanged += new EventHandler(isModeCheckBox_Click);
}
private void isModeCheckBox_Click(object sender, EventArgs e)
{
if (!this.isNormal)
{//叠加
int daodianbuCount = this.dataBoolList.Keys.Count;
int fanweiCount = this.dataIsFanweibuchangList.Keys.Count;
int erzhiCount = this.dataIsErzhichuliList.Keys.Count;
if (!isFanweiCheckBox && !isErzhiCheckBox && daodianbuCount >0)
for (int index = 0; index < daodianbuCount; index++)
{
if (this.dataBoolList.ContainsKey(index))
{
this.dataBoolList[index] = this.commonControlButtons.isModeCheckBox.Checked;
}
else
{
this.dataBoolList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
}
}
if (isFanweiCheckBox && fanweiCount > 0)
for (int index = 0; index < fanweiCount; index++)
{
if (this.dataIsFanweibuchangList.ContainsKey(index))
{
this.dataIsFanweibuchangList[index] = this.commonControlButtons.isModeCheckBox.Checked;
}
else
{
this.dataIsFanweibuchangList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
}
}
if (isErzhiCheckBox && erzhiCount > 0)
for (int index = 0; index < erzhiCount; index++)
{
if (this.dataIsErzhichuliList.ContainsKey(index))
{
this.dataIsErzhichuliList[index] = this.commonControlButtons.isModeCheckBox.Checked;
}
else
{
this.dataIsErzhichuliList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
}
}
return;
}
if (this.listPictureName.SelectedItem != null)
{
int index = listPictureName.SelectedIndex;
if (!isFanweiCheckBox && !isErzhiCheckBox)
if (this.dataBoolList.ContainsKey(index))
{
this.dataBoolList[index] = this.commonControlButtons.isModeCheckBox.Checked;
}
else
{
this.dataBoolList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
}
if (isFanweiCheckBox)
if (this.dataIsFanweibuchangList.ContainsKey(index))
{
this.dataIsFanweibuchangList[index] = this.commonControlButtons.isModeCheckBox.Checked;
}
else
{
this.dataIsFanweibuchangList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
}
if (isErzhiCheckBox)
if (this.dataIsErzhichuliList.ContainsKey(index))
{
this.dataIsErzhichuliList[index] = this.commonControlButtons.isModeCheckBox.Checked;
}
else
{
this.dataIsErzhichuliList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
}
}
}
private void zoomInButton_Click(object sender, EventArgs e)
{
if (this.bitmap != null)
this.documentWorkspace.ZoomIn();
}
private void zoomOutButton_Click(object sender, EventArgs e)
{
if (this.bitmap != null)
this.documentWorkspace.ZoomOut();
}
private void zoomToWindowButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
}
private void actualSizeButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
}
private void pointerButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
}
private void mobileModeButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
}
#endregion
private void PlotTheMeasurementRange_Load()
{
listPictureName.DataSource = null;
listPictureName.DataSource = pictureNames;
}
private void listPictureName_MouseDown(object sender, EventArgs e)
{
if (this.listPictureName.SelectedItem != null)
{
if (this.selectedIndex == this.listPictureName.SelectedIndex)
{
return;
}
this.hasAngle = 0;
GraphicsList graphicsList = new GraphicsList();
index = listPictureName.SelectedIndex;
this.selectedIndex = index;
if (!this.isPlay)
{
if (index + 1 != this.triangleTrackBar1.Value)
{
this.listPictureName.SelectedValueChanged -= new System.EventHandler(this.listPictureName_MouseDown);
this.triangleTrackBar1.Value = index + 1;
this.textBox1.Text = this.triangleTrackBar1.Value + @"/" + this.triangleTrackBar1.Maximum;
this.listPictureName.SelectedValueChanged += new System.EventHandler(this.listPictureName_MouseDown);
}
}
if (!isFanweiCheckBox && !isErzhiCheckBox)
if (this.dataBoolList.ContainsKey(index))
{
bool isCheck;
this.dataBoolList.TryGetValue(index, out isCheck);
if (isCheck)
{
this.commonControlButtons.isModeCheckBox.Checked = true;
}
else
{
this.commonControlButtons.isModeCheckBox.Checked = false;
}
}
if (isFanweiCheckBox)
if (this.dataIsFanweibuchangList.ContainsKey(index))
{
bool isCheck;
this.dataIsFanweibuchangList.TryGetValue(index, out isCheck);
if (isCheck)
{
this.commonControlButtons.isModeCheckBox.Checked = true;
}
else
{
this.commonControlButtons.isModeCheckBox.Checked = false;
}
}
if (isErzhiCheckBox)
if (this.dataIsErzhichuliList.ContainsKey(index))
{
bool isCheck;
this.dataIsErzhichuliList.TryGetValue(index, out isCheck);
if (isCheck)
{
this.commonControlButtons.isModeCheckBox.Checked = true;
}
else
{
this.commonControlButtons.isModeCheckBox.Checked = false;
}
}
if (index < 0 || index >= pictures.Count)
{
return;
}
#region [判断透明度]
if (this.isNormal)
{
int num = 255;
try
{
num = Convert.ToInt32(textBox3.Text);
if (num > 255)
{
num = 255;
textBox3.Text = "255";
}
}
catch (Exception)
{
}
this.BitmapArray.Clear();
var abc = (Bitmap)originalPictures[index].Clone();
Bitmap map = MakeTransparent(abc, num);
if (map != null)
{
this.BitmapArray.Add(map);
this.BitmapArray.Add(map);
this.OverlapHeight = this.BitmapArray[0].Height;
this.OverlapWidth = this.BitmapArray[0].Width;
pictures[index] = Overlap(OverlapType.CENTER);
}
if (abc != null)
{
abc.Dispose();
}
}
#endregion
if (this.startSpin)
{
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.DrawLine;
}
else {
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
}
this.bitmap = pictures[index];
Document document = Document.FromImage(this.bitmap);
this.documentWorkspace.Document = document;
this.documentWorkspace.Visible = true;
if (this.dataList.ContainsKey(index))
{
for (int i = 0; i < this.dataList[index].Count; i++)
{
graphicsList.Add(this.dataList[index][i].Clone(this.documentWorkspace));
}
this.documentWorkspace.GraphicsList = graphicsList;
}
else
{
this.documentWorkspace.GraphicsList = graphicsList;
}
this.documentWorkspace.Refresh();
groupBoxZhangshu.Text = "第" + (index + 1).ToString() + PdnResources.GetString("NewZhang");
}
}
///
/// 确定
///
///
///
private void buttonOKDraw_Click(object sender, EventArgs e)
{
if (this.listPictureName.SelectedItem != null)
{
index = listPictureName.SelectedIndex;
GraphicsList graphicsList = new GraphicsList();
for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
{
graphicsList.Add(this.documentWorkspace.GraphicsList[i].Clone(this.documentWorkspace));
}
if (this.dataList.ContainsKey(index))
{
this.dataList[index] = graphicsList;
}
else
{
this.dataList.Add(index, graphicsList);
}
}
for (int i = 0; i < this.listPictureName.Items.Count; i++)
if (!this.dataList.ContainsKey(i))//避免空数据导致的后续bug
this.dataList.Add(i, new GraphicsList());
this.AutomaticMeasurement.getList(this.dataList, thisindex);
this.AutomaticMeasurement.getBoolList(this.dataBoolList, thisindex);
if (isFanweiCheckBox) this.AutomaticMeasurement.getIsFanweibuchangList(this.dataIsFanweibuchangList, thisindex);
if (isErzhiCheckBox) this.AutomaticMeasurement.getIsErzhichuliList(this.dataIsErzhichuliList, thisindex);
this.Close();
}
#region [播放相关]
///
/// 图片选择改变
///
///
///
private void trackBar_Scroll(object sender, EventArgs e)
{
this.textBox1.Text = this.triangleTrackBar1.Value + @"/" + this.triangleTrackBar1.Maximum;
try
{
//滚动到指定的行位置
this.listPictureName.SelectedIndex = this.triangleTrackBar1.Value - 1;
}
catch (Exception ex)
{
this.listPictureName.SelectedIndex = 0;
}
}
#endregion
///
/// 从后往前播放按钮
///
///
///
private void button1_Click(object sender, EventArgs e)
{
if (this.startSpin)
{
return;
}
if (this.button1.BackColor == Color.DarkGray)
return;
else
{
this.button1.BackColor = Color.DarkGray;
this.button2.BackColor = Color.FromArgb(255, 240, 240, 240);
this.playType = 1;
}
}
///
/// 从前往后播放按钮
///
///
///
private void button2_Click(object sender, EventArgs e)
{
if (this.startSpin)
{
return;
}
if (this.button2.BackColor == Color.DarkGray)
return;
else
{
this.button2.BackColor = Color.DarkGray;
this.button1.BackColor = Color.FromArgb(255, 240, 240, 240);
this.playType = 2;
}
}
///
/// 是否循环播放
///
///
///
private void button3_Click(object sender, EventArgs e)
{
if (this.startSpin)
{
return;
}
if (this.button3.BackColor == Color.DarkGray)
{
this.button3.BackColor = Color.FromArgb(255, 240, 240, 240);
this.isLoop = false;
}
else
{
this.button3.BackColor = Color.DarkGray;
this.isLoop = true;
}
}
///
/// 播放 暂停
///
///
///
private void button4_Click(object sender, EventArgs e)
{
if (this.startSpin)
{
MessageBox.Show("旋轉模式中,請勿播放!");
return;
}
if (this.isPlay)
{
this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
this.isPlay = false;
this.timer1.Stop();
}
else
{
this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPauseIcon.png").Reference;
this.isPlay = true;
this.timer1.Start();
}
}
///
/// 开始播放
///
///
///
private void timer1_Tick(object sender, EventArgs e)
{
if (this.playType == 2)
{
if (this.selectedIndex < this.listPictureName.Items.Count - 1)
{
this.listPictureName.SelectedIndex = this.selectedIndex + 1;
this.triangleTrackBar1.Value = this.selectedIndex + 1;
}
else
{
if (this.isLoop)
{
this.listPictureName.SelectedIndex = 0;
this.triangleTrackBar1.Value = 1;
}
else {
this.isPlay = false;
this.timer1.Stop();
this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
}
}
}
else {
if (this.selectedIndex > 0)
{
int index = this.selectedIndex;
this.listPictureName.SelectedIndex = this.selectedIndex - 1;
this.triangleTrackBar1.Value = index;
}
else
{
if (this.isLoop)
{
this.listPictureName.SelectedIndex = this.listPictureName.Items.Count - 1;
this.triangleTrackBar1.Value = this.listPictureName.Items.Count;
}
else
{
this.isPlay = false;
this.timer1.Stop();
this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
}
}
}
this.textBox1.Text = this.triangleTrackBar1.Value + @"/" + this.triangleTrackBar1.Maximum;
}
public Bitmap Overlap(OverlapType type)
{
Bitmap bmPhoto;
try
{
Bitmap[] bitmaps = this.BitmapArray.ToArray();
int width = this.OverlapWidth;
int height = this.OverlapHeight;
if (width == 0 || height == 0)
{
return null;
}
Mat mat = new Mat(height, width, MatType.CV_8UC4, new Scalar(240, 240, 240, 255));
bmPhoto = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
float x = 0;
float y = 0;
//load the Bitmap into a Graphics object
Graphics grPhoto = Graphics.FromImage(bmPhoto);
//Set the rendering quality for this Graphics object
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;//清除锯齿的呈现
//haix
for (int i = 0; i < bitmaps.Length; i++)
{
Bitmap img = bitmaps[i];
if (img == null)
{
continue;
}
if (type == OverlapType.CENTER)
{
x = (width - img.Width) / 2.0f;
y = (height - img.Height) / 2.0f;
if (i == 1)
{
x += 1;
y += 1;
}
}
grPhoto.DrawImage(img, 0,0,img.Width, img.Height);
}
if (mat != null)
{
mat.Dispose();
}
}
catch (Exception)
{
return null;
}
return bmPhoto;
}
//定义图像透明度调整函数
public Bitmap MakeTransparent(Bitmap src, int num)
{
return ImageTools.MakeTransparent(src, num);
}
///
/// 透明度修改
///
///
///
private void textBox3_TextChanged(object sender, KeyEventArgs e)
{
if (this.startSpin)
{
return;
}
if (e.KeyCode == Keys.Control || e.KeyCode == Keys.Enter)
{
if (this.isNormal)
{
int num = 255;
try
{
num = Convert.ToInt32(textBox3.Text);
if (num > 255)
{
num = 255;
textBox3.Text = "255";
}
}
catch (Exception)
{
}
this.BitmapArray.Clear();
var abc = (Bitmap)originalPictures[this.selectedIndex].Clone();
Bitmap map = MakeTransparent(abc, num);
this.BitmapArray.Add(map);
this.BitmapArray.Add(map);
pictures[this.selectedIndex] = Overlap(OverlapType.CENTER);
abc.Dispose();
this.bitmap = pictures[this.selectedIndex];
Document document = Document.FromImage(this.bitmap);
this.documentWorkspace.Document = document;
this.documentWorkspace.Visible = true;
}
else {
int num = 255 / this.listPictureName.Items.Count;
try
{
num = Convert.ToInt32(textBox3.Text);
if (num > 255)
{
num = 255;
textBox3.Text = "255";
}
}
catch (Exception)
{
}
this.BitmapArray.Clear();
foreach (Bitmap item in originalPictures)
{
Bitmap cloneData = (Bitmap)item.Clone();
Bitmap bitmap = MakeTransparent(cloneData, num);
this.BitmapArray.Add(bitmap);
cloneData.Dispose();
}
this.OverlapHeight = this.BitmapArray[0].Height;
this.OverlapWidth = this.BitmapArray[0].Width;
this.bitmap = Overlap(OverlapType.CENTER);
Document document = Document.FromImage(this.bitmap);
this.documentWorkspace.Document = document;
this.documentWorkspace.Visible = true;
}
}
}
///
/// 时间间隔修改
///
///
///
private void textBox2_TextChanged(object sender, KeyEventArgs e)
{
if (this.startSpin)
{
return;
}
if (e.KeyCode == Keys.Control || e.KeyCode == Keys.Enter)
{
int Interval = 1000;
try
{
Interval = Convert.ToInt32(textBox2.Text);
}
catch (Exception)
{
}
timer1.Interval = Interval;
}
}
///
/// 正常
///
///
///
private void button5_Click(object sender, EventArgs e)
{
if (this.startSpin)
{
this.startSpin = false;
this.button7.Text = "旋转";
}
this.textBox3.Text = "255";
this.listPictureName.Enabled = true;
this.selectedIndex = -1;
this.isNormal = true;
this.BitmapArray.Clear();
for (int i = 0; i <= originalPictures.Count - 1; i++)
{
var abc = (Bitmap)originalPictures[i].Clone();
Bitmap map = MakeTransparent(abc, 255);
this.BitmapArray.Add(map);
this.OverlapHeight = this.BitmapArray[0].Height;
this.OverlapWidth = this.BitmapArray[0].Width;
pictures[i] = Overlap(OverlapType.CENTER);
abc.Dispose();
}
this.listPictureName_MouseDown(null, null);
}
///
/// 叠加
///
///
///
private void button6_Click(object sender, EventArgs e)
{
if (this.startSpin)
{
this.startSpin = false;
this.button7.Text = "旋转";
}
if (this.documentWorkspace.activeTool != Annotation.Enum.DrawToolType.ViewRectangle)
{
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
this.documentWorkspace.SetContinuousDrawingVoid(true);
}
var num = Convert.ToInt32(255 / this.listPictureName.Items.Count);
this.textBox3.Text = num.ToString();
this.listPictureName.Enabled = false;
this.BitmapArray.Clear();
foreach (Bitmap item in originalPictures)
{
Bitmap cloneData = (Bitmap)item.Clone();
Bitmap bitmap = MakeTransparent(cloneData, num);
this.BitmapArray.Add(bitmap);
cloneData.Dispose();
}
this.OverlapHeight = this.BitmapArray[0].Height;
this.OverlapWidth = this.BitmapArray[0].Width;
this.bitmap = Overlap(OverlapType.CENTER);
Document document = Document.FromImage(this.bitmap);
this.documentWorkspace.Document = document;
this.documentWorkspace.Visible = true;
if (this.isPlay)
{
this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
this.isPlay = false;
this.timer1.Stop();
}
this.isNormal = false;
GC.Collect();
}
///
/// 旋转开始
///
///
///
private void button7_Click(object sender, EventArgs e)
{
if (this.isPlay)
{
return;
}
this.startSpin = !this.startSpin;
if (this.startSpin)
{
this.button7.Text = "停止旋转";
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.DrawLine;
}
else {
this.button7.Text = "旋转";
this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
}
}
}
}