123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791 |
- using System;
- using System.Collections;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace OTSMeasureApp
- {
- public class CStageManage
- {
- #region 添加样品
- /// <summary>
- /// 添加样品
- /// </summary>
- /// <param name="IsSelect"></param>
- /// <param name="SampleHoleName"></param>
- /// <param name="SampleName"></param>
- /// <param name="oTSSamplespaceWindow"></param>
- /// <returns></returns>
- public static bool AddSample(string SampleHoleName, string SampleName, ARectangleGDIObject m_MeasureGDIObjects, OTSSamplespaceWindow oTSSamplespaceWindow,float globalZoomNum)
- {
- try
- {
- if (OTSSamplespaceWindow.m_SampleHoleGDIObjects != null)
- {
- if (OTSSamplespaceWindow.m_SampleHoleGDIObjects.Count > 0)
- {
- ARectangleGDIObject itemAdd = null;
- //设置样品选择状态为非工作样品
- foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
- itemSample.IsWorkSample = false;
- }
- foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
- {
- itemAdd = items;
- if (items.Name == SampleHoleName)
- {
- //获取样品台类型
- int shape = itemAdd.CreateType;// == (int)CreateRectangleType.Rectangle ? (int)CreateRectangleType.Rectangle: (int)CreateRectangleType.Ellipse;
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- Color selColor = ColorTranslator.FromHtml(ColorStr);
- CreateRectangle NewSample = new CreateRectangle(items.Region, (int)CreateRectangleType.SelectSample, shape, items.Name, selColor);
- //累加样品数量
- items.SampleCount += 1;
- items.IsWorkSample = true;
- NewSample.SampleName = SampleName;
- NewSample.Name = itemAdd.Name;
- //设置当前添加的样品为工作样品
- NewSample.IsWorkSample = true;
- // 获取样品孔的大小与初始大小
- NewSample.Region = items.Region;
- NewSample.RegionF = items.RegionF;
- NewSample.DrawRegionF = items.DrawRegionF;
- //绘制样品路径
- GraphicsPath NewSamplePath = new GraphicsPath();
- if (NewSample.Shape == (int)CreateRectangleType.Circle)
- {
- NewSamplePath.AddEllipse(NewSample.Region);
- }
- else
- {
- NewSamplePath.AddRectangle(NewSample.Region);
- }
- NewSample.GPath = NewSamplePath;
- OTSSamplespaceWindow.m_SampleGDIObjects.Add(NewSample);
- //获取测量区域尺寸与位置
- m_MeasureGDIObjects = GetSampleMeasureInfo(NewSample, m_MeasureGDIObjects, globalZoomNum);
- //设置样品孔名称
- m_MeasureGDIObjects.Name = items.Name;
- //根据节点设置样品台窗口中所选择的样品名称
- OTSSamplespaceWindow.m_SampleSelectName = SampleName;
- //添加测量区域
- return AddMeasure(m_MeasureGDIObjects.CreateType, m_MeasureGDIObjects);
- }
- }
- }
- }
- }
- catch (Exception)
- {
- }
- return false;
- }
- #region 根据样品位置 获取测量区域位置
- public static ARectangleGDIObject GetSampleMeasureInfo(ARectangleGDIObject NewSample, ARectangleGDIObject m_MeasureGDIObjects, float globalZoomNum)
- {
- //根据样品位置 获取测量区域位置
- int MeasurePointX = (int)(NewSample.Region.Location.X + ((NewSample.Region.Size.Width - (m_MeasureGDIObjects.Region.Width * globalZoomNum)) / 2));
- int MeasurePointY = (int)(NewSample.Region.Location.Y + ((NewSample.Region.Size.Height - (m_MeasureGDIObjects.Region.Height * globalZoomNum)) / 2));
- int MeasureWidth = Convert.ToInt32(m_MeasureGDIObjects.Region.Width * globalZoomNum);
- int MeasureHeight = Convert.ToInt32(m_MeasureGDIObjects.Region.Height * globalZoomNum);
-
- float MeasureFPointX = (float)(NewSample.RegionF.Location.X + (NewSample.RegionF.Size.Width - m_MeasureGDIObjects.Region.Width ) / 2);
- float MeasureFPointY = (float)(NewSample.RegionF.Location.Y + (NewSample.RegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2);
- float MeasureFWidth = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Width);
- float MeasureFHeight = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Height);
- float MeasureDrawPointX = (float)(NewSample.DrawRegionF.Location.X + (NewSample.DrawRegionF.Size.Width - m_MeasureGDIObjects.Region.Width) / 2);
- float MeasureDrawPointY = (float)(NewSample.DrawRegionF.Location.Y + (NewSample.DrawRegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2);
- float MeasureDrawWidth = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Width);
- float MeasureDrawHeight = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Height);
- m_MeasureGDIObjects.Region = new Rectangle(new Point(MeasurePointX, MeasurePointY), new Size(MeasureWidth, MeasureHeight));
- m_MeasureGDIObjects.RegionF = new RectangleF(new PointF(MeasureFPointX, MeasureFPointY), new SizeF(MeasureFWidth, MeasureFHeight));
- m_MeasureGDIObjects.DrawRegionF = new RectangleF(new PointF(MeasureDrawPointX, MeasureDrawPointY), new SizeF(MeasureDrawWidth, MeasureDrawHeight));
- return m_MeasureGDIObjects;
- }
- #endregion
- /// <summary>
- /// 添加样品
- /// </summary>
- /// <param name="IsSelect"></param>
- /// <param name="SampleHoleName"></param>
- /// <param name="SampleName"></param>
- /// <param name="oTSSamplespaceWindow"></param>
- /// <returns></returns>
- public static bool AddOnlySample(string SampleHoleName, string SampleName, OTSSamplespaceWindow oTSSamplespaceWindow)
- {
- try
- {
- if (OTSSamplespaceWindow.m_SampleHoleGDIObjects != null)
- {
- if (OTSSamplespaceWindow.m_SampleHoleGDIObjects.Count > 0)
- {
- ARectangleGDIObject itemAdd = null;
- //设置样品选择状态为非工作样品
- foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
- itemSample.IsWorkSample = false;
- }
- foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
- {
- itemAdd = items;
- if (items.Name == SampleHoleName)
- {
- //获取样品台类型
- int shape = itemAdd.CreateType;// == (int)CreateRectangleType.Rectangle ? (int)CreateRectangleType.Rectangle: (int)CreateRectangleType.Ellipse;
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- Color selColor = ColorTranslator.FromHtml(ColorStr);
- CreateRectangle AddSample = new CreateRectangle(items.Region, (int)CreateRectangleType.SelectSample, shape, items.Name, selColor);
- //累加样品数量
- items.SampleCount += 1;
- items.IsWorkSample = true;
- AddSample.SampleName = SampleName;
- AddSample.Name = itemAdd.Name;
- //绘制测量区域路径
- GraphicsPath AddSamplePath = new GraphicsPath();
- AddSamplePath.AddRectangle(AddSample.Region);
- AddSample.GPath = AddSamplePath;
- OTSSamplespaceWindow.m_SampleGDIObjects.Add(AddSample);
- return true;
- }
- }
- }
- }
- return false;
- }
- catch (Exception)
- {
- }
- return false;
- }
- #endregion
- #region 删除样品
- /// <summary>
- /// 删除样品
- /// </summary>
- /// <param name="IsIsDragging">是否选择样品孔 0:未选择 1:选择</param>
- /// <param name="stageName">样品孔名称</param>
- /// <returns>是否成功</returns>
- public static bool DeleteStage(int IsSelect, string SampleName)
- {
- try
- {
- if (OTSSamplespaceWindow.m_SampleHoleGDIObjects != null)
- {
- if (OTSSamplespaceWindow.m_SampleHoleGDIObjects.Count > 0)
- {
- ARectangleGDIObject itemAdd = null;
- if (OTSSamplespaceWindow.m_SampleGDIObjects.Count > 0)
- {
- foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- itemAdd = items;
- if (IsSelect > 0)
- {
- if (items.SampleName == SampleName)
- {
- foreach (ARectangleGDIObject itemSampleHole in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
- {
- if (itemSampleHole.Name == itemAdd.Name)
- {
- itemSampleHole.SampleCount -= 1;
- break;
- }
- }
- //将样品孔恢复未拖动状态
- items.IsSelect = false;
- OTSSamplespaceWindow.m_SampleGDIObjects.Remove(items);
- return true;
- }
- }
- else
- {
- //删除样品测量
- if (items.SampleName == SampleName)
- {
- //将样品孔恢复未拖动状态
- items.IsSelect = false;
- OTSSamplespaceWindow.m_SampleGDIObjects.Remove(items);
- return true;
- }
- }
- }
- }
- }
- }
- }
- catch (Exception)
- {
- }
- return false;
- }
- #endregion
- #region 通过样品名称 删除样品
- /// <summary>
- /// 删除样品
- /// </summary>
- /// <param name="stageName">样品孔名称</param>
- /// <returns>是否成功</returns>
- public static bool DeleteSample(string SampleName)
- {
- try
- {
- if (OTSSamplespaceWindow.m_SampleHoleGDIObjects != null)
- {
- if (OTSSamplespaceWindow.m_SampleHoleGDIObjects.Count > 0)
- {
- ARectangleGDIObject itemAdd = null;
- if (OTSSamplespaceWindow.m_SampleGDIObjects.Count > 0)
- {
- foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- itemAdd = items;
- if (items.SampleName == SampleName)
- {
- foreach (ARectangleGDIObject itemSampleHole in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
- {
- if (itemSampleHole.Name == itemAdd.Name)
- {
- itemSampleHole.SampleCount -= 1;
- break;
- }
- }
- //将样品孔恢复未拖动状态
- items.IsSelect = false;
- OTSSamplespaceWindow.m_SampleGDIObjects.Remove(items);
- if (DeleteMeasure(SampleName))
- {
- return true;
- }
- }
- }
- }
- }
- }
- }
- catch (Exception)
- {
- }
- return false;
- }
- #endregion
- #region 修改测量区域选择状态
- public static void SetMeasureState(Color setColor)
- {
- foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_MeasureGDIObjects)
- {
- items.SelColor = setColor;
- }
- }
- #endregion
- #region 修改样品选择状态
- public static void SetSampleState(Color setColor)
- {
- foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- if (items.IsDragging)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- items.SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- else
- {
- items.SelColor = setColor;
- }
- }
- }
- #endregion
- #region 添加测量
- /// <summary>
- /// 添加测量
- /// </summary>
- /// <param name="IsIsDragging">是否选择样品 0:未选择 1:选择</param>
- /// <param name="sampleName">样品名称</param>
- /// <returns>是否成功</returns>
- public static bool AddMeasure(int IsSelect, string sampleName)
- {
- try
- {
- if (OTSSamplespaceWindow.m_SampleGDIObjects != null)
- {
- if (OTSSamplespaceWindow.m_SampleGDIObjects.Count > 0)
- {
- ARectangleGDIObject itemAdd = null;
- if (IsSelect > 0)
- {
- foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- //判断是否与传递的样品名称相同
- itemAdd = items;
- if (items.Name == sampleName)
- {
- //添加测量区域
- //获取样品台类型
- int shape = itemAdd.CreateType;// == (int)CreateRectangleType.Rectangle ? (int)CreateRectangleType.Rectangle: (int)CreateRectangleType.Ellipse;
- GraphicsPath MeasurePath = new GraphicsPath();
- if (shape == (int)CreateRectangleType.Rectangle)
- {
- MeasurePath.AddRectangle(itemAdd.Region);
- }
- else
- {
- MeasurePath.AddEllipse(itemAdd.Region);
- }
- //缩小与样品的尺寸
- Rectangle rectMeasure = items.Region;
- rectMeasure.X = rectMeasure.X + 5;
- rectMeasure.Y = rectMeasure.Y + 5;
- rectMeasure.Width = rectMeasure.Width - 10;
- rectMeasure.Height = rectMeasure.Height - 10;
- //与样品中心相差的距离
- Point sampleCenterDifferPoint = new Point();
- //获取测量区域中心与样品中心相差的距离
- sampleCenterDifferPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectMeasure, items.Region);
- //创建测量区域
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- CreateRectangle selectState = new CreateRectangle(rectMeasure, sampleCenterDifferPoint, (int)CreateRectangleType.MeasureArea, shape, items.Name, items.Name, ColorTranslator.FromHtml(ColorStr));
- selectState.GPath = MeasurePath;
- OTSSamplespaceWindow.m_MeasureGDIObjects.Add(selectState);
- return true;
- }
- }
- }
- else
- {
- //默认添加测量
- itemAdd = OTSSamplespaceWindow.m_SampleGDIObjects[0];
- CreateRectangle selectState = new CreateRectangle(itemAdd.Region, (int)CreateRectangleType.MeasureArea, sampleName);
- GraphicsPath MeasurePath = new GraphicsPath();
- if (selectState.Shape == (int)CreateRectangleType.Rectangle)
- {
- MeasurePath.AddRectangle(itemAdd.Region);
- }
- else
- {
- MeasurePath.AddEllipse(itemAdd.Region);
- }
- selectState.GPath = MeasurePath;
- OTSSamplespaceWindow.m_MeasurePathGDIObjects.Add(selectState);
- return true;
- }
- }
- }
- }
- catch (Exception)
- {
- throw;
- }
- return false;
- }
- #endregion
- #region 添加测量
- /// <summary>
- /// 添加测量
- /// </summary>
- /// <param name="IsIsDragging">是否选择样品 0:未选择 1:选择</param>
- /// <param name="sampleName">样品名称</param>
- /// <returns>是否成功</returns>
- public static bool AddMeasure(int CreateType, ARectangleGDIObject m_MeasureGDIObjects)
- {
- try
- {
- //添加测量区域
- int shape = CreateType;// == 1 ? 1 : 0;
- GraphicsPath MeasurePath = new GraphicsPath();
- if (shape == (int)CreateRectangleType.Rectangle)
- {
- MeasurePath.AddRectangle(m_MeasureGDIObjects.Region);
- }
- else
- {
- MeasurePath.AddEllipse(m_MeasureGDIObjects.Region);
- }
- //缩小与样品的尺寸
- Rectangle rectMeasure = m_MeasureGDIObjects.Region;
- Color MeasureColor = Color.Red;
- CreateRectangle MeasureRect = new CreateRectangle(rectMeasure, m_MeasureGDIObjects.SampleCenterDifferCenterPoint, (int)CreateRectangleType.MeasureArea, shape, m_MeasureGDIObjects.Name, m_MeasureGDIObjects.SampleName, MeasureColor);
- MeasureRect.GPath = MeasurePath;
- MeasureRect.sampleName = m_MeasureGDIObjects.SampleName;
- MeasureRect.Name = m_MeasureGDIObjects.Name;
- //获取缩放前尺寸与位置
- MeasureRect.RegionF = m_MeasureGDIObjects.RegionF;
- MeasureRect.DrawRegionF = m_MeasureGDIObjects.DrawRegionF;
- OTSSamplespaceWindow.m_MeasureGDIObjects.Add(MeasureRect);
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
- #endregion
- #region 复位测量
- /// <summary>
- /// 复位测量
- /// </summary>
- /// <param name="CreateType">是否选择样品 0:圆形 3:矩形</param>
- /// <param name="m_MeasureGDIObjects">测量区域</param>
- /// <returns>是否成功</returns>
- public static ARectangleGDIObject ResetMeasure(int CreateType, ARectangleGDIObject m_SampleGDIObjects, ARectangleGDIObject m_MeasureGDIObjects, float globalZoomNum)
- {
- try
- {
- //复位测量
- int shape = CreateType;
- GraphicsPath MeasurePath = new GraphicsPath();
- if (shape == (int)CreateRectangleType.Rectangle)
- {
- MeasurePath.AddRectangle(m_SampleGDIObjects.Region);
- }
- else
- {
- MeasurePath.AddEllipse(m_SampleGDIObjects.Region);
- }
- //缩小与样品的尺寸
- Rectangle rectMeasure = m_SampleGDIObjects.Region;
- Color MeasureColor = Color.Red;
- return GetSampleMeasureInfo(m_SampleGDIObjects, m_MeasureGDIObjects, globalZoomNum);
- }
- catch (Exception)
- {
- return null;
- }
- }
- #endregion
- #region 通过样品名称 删除测量
- /// <summary>
- /// 通过样品名称 删除测量
- /// </summary>
- /// <param name="measureName">测量名称</param>
- /// <returns>是否成功</returns>
- public static bool DeleteMeasure(string sampleName)
- {
- try
- {
- if (OTSSamplespaceWindow.m_MeasureGDIObjects.Count > 0)
- {
- foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_MeasureGDIObjects)
- {
- //删除样品测量
- if (items.SampleName == sampleName)
- {
- //将样品孔恢复未拖动状态
- items.IsSelect = false;
- OTSSamplespaceWindow.m_MeasureGDIObjects.Remove(items);
- //设置样品与测量区域
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- SetSampleState(ColorTranslator.FromHtml(ColorStr));
- SetMeasureState(ColorTranslator.FromHtml(ColorStr));
- OTSSamplespaceWindow.m_IsMeasure = false;
- foreach (ARectangleGDIObject sampleItem in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- if (sampleItem.SampleName == items.SampleName)
- {
- sampleItem.IsWorkSample = true;
- //设置颜色
- string SampleSelColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- sampleItem.SelColor = ColorTranslator.FromHtml(SampleSelColor);
- }
- }
- return true;
- }
- }
- }
- }
- catch (Exception)
- {
- }
- return false;
- }
- #endregion
- #region 删除测量
- /// <summary>
- /// 删除测量
- /// </summary>
- /// <param name="IsIsDragging">是否选择测量 0:未选择 1:选择</param>
- /// <param name="measureName">测量名称</param>
- /// <returns>是否成功</returns>
- public static bool DeleteMeasure(int IsSelect, string sampleName)
- {
- try
- {
- if (OTSSamplespaceWindow.m_MeasureGDIObjects.Count > 0)
- {
- foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_MeasureGDIObjects)
- {
- //删除样品测量
- if (items.SampleName == sampleName)
- {
- //将样品孔恢复未拖动状态
- items.IsSelect = false;
- OTSSamplespaceWindow.m_MeasureGDIObjects.Remove(items);
- //设置样品与测量区域
- //设置颜色
- string SampleColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- SetSampleState(ColorTranslator.FromHtml(SampleColor));
- SetMeasureState(ColorTranslator.FromHtml(SampleColor));
- OTSSamplespaceWindow.m_IsMeasure = false;
- foreach (ARectangleGDIObject sampleItem in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- if (sampleItem.Name == items.SampleName)
- {
- //设置颜色
- string SampleSelColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- sampleItem.IsWorkSample = true;
- sampleItem.SelColor = ColorTranslator.FromHtml(SampleSelColor);
- }
- }
- return true;
- }
- }
- }
- }
- catch (Exception)
- {
- }
- return false;
- }
- #endregion
- #region 更换样品名称
- /// <summary>
- /// 更换样品名称
- /// </summary>
- /// <param name="sampleName">新样品名称</param>
- public static void ChangeSampleName(string sampleName)
- {
- //循环 样品与测量区域的名称修改为新名称
- foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- if (itemSample.IsWorkSample)
- {
- foreach (ARectangleGDIObject measureItemSample in OTSSamplespaceWindow.m_MeasureGDIObjects)
- {
- if (measureItemSample.SampleName == itemSample.SampleName)
- {
- measureItemSample.SampleName = sampleName;
- itemSample.SampleName = sampleName;
- return;
- }
- }
- }
- }
- }
- #endregion
- #region 更换样品形状
- /// <summary>
- /// 更换样品形状
- /// </summary>
- /// <param name="iShape">形状</param>
- public static bool ChangeSampleShape(int iShape)
- {
- foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- if (itemSample.IsWorkSample)
- {
- foreach (ARectangleGDIObject itemMeasure in OTSSamplespaceWindow.m_MeasureGDIObjects)
- {
- if (itemSample.SampleName == itemMeasure.SampleName)
- {
- if (itemMeasure.Shape != iShape)
- {
- //改变大小
- itemMeasure.Region = new Rectangle(itemMeasure.Region.X, itemMeasure.Region.Y, itemMeasure.Region.Height, itemMeasure.Region.Height);
- itemMeasure.RegionF = new RectangleF(itemMeasure.RegionF.X, itemMeasure.RegionF.Y, itemMeasure.RegionF.Height, itemMeasure.RegionF.Height);
- itemMeasure.DrawRegionF = new RectangleF(itemMeasure.DrawRegionF.X, itemMeasure.DrawRegionF.Y, itemMeasure.DrawRegionF.Height, itemMeasure.DrawRegionF.Height);
- itemMeasure.Shape = iShape;
- GraphicsPath NewMeasurePath = new GraphicsPath();
- if (itemMeasure.Shape == (int)CreateRectangleType.Circle)
- {
- NewMeasurePath.AddEllipse(itemMeasure.Region);
- }
- else
- {
- NewMeasurePath.AddRectangle(itemMeasure.Region);
- }
- itemMeasure.GPath = NewMeasurePath;
- return true;
- }
- return false;
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region 设置工作样品
- /// <summary>
- /// 设置工作样品与测量区域
- /// </summary>
- /// <param name="sampleName">样品名称</param>
- public static void SetWorkSampleAndWorkMeasure(string sampleName)
- {
- foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- if (itemSample.SampleName == sampleName)
- {
- itemSample.IsWorkSample = true;
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- else
- {
- itemSample.IsWorkSample = false;
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- }
- foreach (ARectangleGDIObject itemMeasure in OTSSamplespaceWindow.m_MeasureGDIObjects)
- {
- if (itemMeasure.SampleName == sampleName)
- {
- itemMeasure.IsWorkSample = true;
- itemMeasure.SelColor = Color.Red;
- }
- else
- {
- itemMeasure.IsWorkSample = false;
- itemMeasure.SelColor = Color.Transparent;
- }
- }
- //修改测量区域集合 索引 (添加样品或者切换样品时,将当前工作样品显示在样品孔的最上)
- OTSSamplespaceWindow.m_MeasureGDIObjects = OTSSamplespaceGraphicsPanelFun.SelectMeasureIndexIsTop(OTSSamplespaceWindow.m_MeasureGDIObjects, sampleName);
- //修改样品集合 索引
- OTSSamplespaceWindow.m_SampleGDIObjects = OTSSamplespaceGraphicsPanelFun.SelectSampleIndexIsTop(OTSSamplespaceWindow.m_SampleGDIObjects, sampleName);
- }
- #endregion
- public static void SetShowCMStrip(int IsSelectType, ContextMenuStrip cmStrip, bool IsTrue)
- {
- //鼠标右键选择的类型 0:样品台 1:样品 2:测量区域
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = (int)MessageState.ShotBSEPicture;
- switch (IsSelectType)
- {
- case (int)ContextMenuType.SampleHoleMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
- break;
- case (int)ContextMenuType.SampleMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
- break;
- case (int)ContextMenuType.MeasureMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
- //cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Text = str2;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.MeasureBSEPicture;
- break;
- case (int)ContextMenuType.SingleMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
- //cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Text = str2;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.MeasureBSEPicture;
- break;
- case (int)ContextMenuType.ThreadRunMenu:
- for (int i = 0; i < cmStrip.Items.Count; i++)
- {
- cmStrip.Items[i].Enabled = false;
- }
- break;
- case (int)ContextMenuType.SampleStateMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
- break;
- case (int)ContextMenuType.SampleHoleBSEImage:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = IsTrue;
- break;
- }
- }
- }
- }
|