| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- using OTSMeasureApp._0_OTSModel.OTSDataType;
- using OTSModelSharp.ServiceCenter;
- using System;
- using System.Collections;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel
- {
- public partial class frmInitializeImageboundary : Form
- {
- ISemController cfun;
- public PointF FirstPoint;
- public PointF SecondPoint;
- public bool IsInclinedPlaneFocus = false;
- OTSCommon.Language lan;
- Hashtable table;
- public PointF ThirdPoint;
- CSlopFocusParam slopFocusParam;
- public frmInitializeImageboundary()
- {
- InitializeComponent();
- lan = new OTSCommon.Language(this);
- table = lan.GetNameTable(this.Name);
- }
- private void bn_FirstPoint_Click(object sender, EventArgs e)
- {
- double Px = 0;
- double Py = 0;
- double Pr = 0;
- if (cfun.GetSemPositionXY(ref Px, ref Py, ref Pr))
- {
- tB_FirstPointX.Text = Math.Round(Px,2).ToString();
- tB_FirstPointY.Text = Math.Round(Py, 2).ToString();
- }
- double WD = 0;
- if (cfun.GetWorkingDistance(ref WD))
- {
- tB_FirstPointD.Text = WD.ToString();
- }
- if (panel1 != null) panel1.Invalidate();
- }
- private void bn_SecondPoint_Click(object sender, EventArgs e)
- {
- double Px = 0;
- double Py = 0;
- double Pr = 0;
- if (cfun.GetSemPositionXY(ref Px, ref Py, ref Pr))
- {
- tB_SecondPointX.Text = Math.Round(Px, 2).ToString();
- tB_SecondPointY.Text = Math.Round(Py, 2).ToString();
- }
- double WD = 0;
- if (cfun.GetWorkingDistance(ref WD))
- {
- tB_SecondPointD.Text = WD.ToString();
- }
- if (panel1 != null) panel1.Invalidate();
- }
- private void frmInitializeImageboundary_Load(object sender, EventArgs e)
- {
- if (cfun == null) { cfun = SemController.GetSEMController(); }
- cB_Inclinedplanefocus.Checked = true; double val = 0;
- //if (cfun.GetMagnification(ref val)) tBx_Magnification.Text = val.ToString();
- if (panel1 != null)
- {
- panel1.Paint += panel1_Paint;
- panel1.MouseMove += panel1_MouseMove;
- panel1.MouseLeave += panel1_MouseLeave;
- panel1.Resize += (s, args) => {
- InitializeImageBoundaryDrawingAreas();
- panel1.Invalidate();
- };
- }
- InitializeImageBoundaryDrawingAreas();
- panel1.Invalidate();
- }
- private void bn_ThirdPoint_Click(object sender, EventArgs e)
- {
- double Px = 0;
- double Py = 0;
- double Pr = 0;
-
-
-
-
-
-
- if (cfun.GetSemPositionXY(ref Px, ref Py, ref Pr))
- {
- tB_ThirdPointX.Text = Math.Round(Px, 2).ToString();
- tB_ThirdPointY.Text = Math.Round(Py, 2).ToString();
- }
- double WD = 0;
- if (cfun.GetWorkingDistance(ref WD))
- {
- tB_ThirdPointD.Text = WD.ToString();
- }
- if (panel1 != null) panel1.Invalidate();
- }
- private void bn_gtfirst_Click(object sender, EventArgs e)
- {
- if (tB_FirstPointD.Text == "")
- {
- MessageBox.Show("Please read first!");
- return;
- }
- double Px = Convert.ToDouble(tB_FirstPointX.Text);
- double Py = Convert.ToDouble(tB_FirstPointY.Text);
- double wd = Convert.ToDouble(tB_FirstPointD.Text);
- if (cfun.MoveSEMToPoint(Px, Py))
- {
- cfun.SetWorkingDistance(wd);
- }
- }
-
- private void bn_gtsecond_Click(object sender, EventArgs e)
- {
- if (tB_SecondPointD.Text == "")
- {
- MessageBox.Show("Please read first!");
- return;
- }
- double Px = Convert.ToDouble(tB_SecondPointX.Text);
- double Py = Convert.ToDouble(tB_SecondPointY.Text);
- double wd = Convert.ToDouble(tB_SecondPointD.Text);
- if (cfun.MoveSEMToPoint(Px, Py))
- {
- cfun.SetWorkingDistance(wd);
- }
- }
- private void bn_gtthird_Click(object sender, EventArgs e)
- {
- if (tB_ThirdPointD.Text == "")
- {
- MessageBox.Show("Please read first!");
- return;
- }
- double Px = Convert.ToDouble(tB_ThirdPointX.Text);
- double Py = Convert.ToDouble(tB_ThirdPointY.Text);
- double wd = Convert.ToDouble(tB_ThirdPointD.Text);
-
- if (cfun.MoveSEMToPoint(Px, Py))
- {
- cfun.SetWorkingDistance(wd);
- }
- }
-
- private void bn_OK_Click(object sender, EventArgs e)
- {
- double iPX1, iPY1, iPX2, iPY2, iPX3, iPY3;
- iPX1 = iPY1 = iPX2 = iPY2 = iPX3 = iPY3 = 0;
- double dPW1, dPW2, dPW3;
- dPW1 = dPW2 = dPW3 = 0;
- if (!double.TryParse(tB_FirstPointX.Text, out iPX1) || !double.TryParse(tB_FirstPointY.Text, out iPY1) || !double.TryParse(tB_SecondPointX.Text, out iPX2) || !double.TryParse(tB_SecondPointY.Text, out iPY2) || !double.TryParse(tB_FirstPointD.Text, out dPW1) || !double.TryParse(tB_SecondPointD.Text, out dPW2))
- {
- DialogResult result = MessageBox.Show("Please check Params!");
- this.DialogResult = DialogResult.None;
- return;
- }
- if (tB_FirstPointX.Text == tB_SecondPointX.Text && tB_FirstPointY.Text == tB_SecondPointY.Text)
- {
- DialogResult result = MessageBox.Show("Please select different points!");
- this.DialogResult = DialogResult.None;
- return;
- }
- if (!double.TryParse(tB_ThirdPointX.Text, out iPX3) || !double.TryParse(tB_ThirdPointY.Text, out iPY3) || !double.TryParse(tB_ThirdPointD.Text, out dPW3))
- {
- MessageBox.Show("Please check Params!");
- this.DialogResult = DialogResult.None;
- return;
- }
- if ((tB_SecondPointX.Text == tB_ThirdPointX.Text && tB_FirstPointY.Text == tB_ThirdPointY.Text) || (tB_SecondPointX.Text == tB_ThirdPointX.Text && tB_SecondPointY.Text == tB_ThirdPointY.Text))
- {
- MessageBox.Show("Please check Params!");
- this.DialogResult = DialogResult.None;
- return;
- }
- FirstPoint = new PointF((float)iPX1, (float)iPY1);
- SecondPoint = new PointF((float)iPX2, (float)iPY2);
- ThirdPoint = new PointF((float)iPX3, (float)iPY3);
- if (slopFocusParam == null)
- {
- slopFocusParam = new CSlopFocusParam();
- }
- slopFocusParam.IsUsingSlopParam = cB_Inclinedplanefocus.Checked;
- slopFocusParam.FirstPoint = new Point((int)iPX1, (int)iPY1);
- slopFocusParam.FirstWD = dPW1;
- slopFocusParam.SecondPoint = new Point((int)iPX2, (int)iPY2);
- slopFocusParam.SecondWD = dPW2;
- slopFocusParam.ThirdPoint = new Point((int)iPX3, (int)iPY3);
- slopFocusParam.ThirdWD = dPW3;
- this.DialogResult=DialogResult.OK;
- this.Close();
- }
- private void bn_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- public CSlopFocusParam GetCSlopFocusParam()
- {
- return slopFocusParam;
- }
- public double GetMagnification()
- {
- double dMagnification = 0;
- double.TryParse(tBx_Magnification.Text, out dMagnification);
- return dMagnification;
- }
- private void cB_Inclinedplanefocus_CheckedChanged(object sender, EventArgs e)
- {
- IsInclinedPlaneFocus = cB_Inclinedplanefocus.Checked;
- }
- // 主圆形区域
- private RectangleF mainCircleArea;
- // 三个等距分布在圆边界上的小圆
- private RectangleF firstPointCircle;
- private RectangleF secondPointCircle;
- private RectangleF thirdPointCircle;
- // 鼠标悬停状态
- private bool isMouseOverFirstPoint = false;
- private bool isMouseOverSecondPoint = false;
- private bool isMouseOverThirdPoint = false;
- private void InitializeImageBoundaryDrawingAreas()
- {
- if (panel1 == null) return;
- // 定义主圆形区域(居中显示)
- int margin = 50;
- float diameter = Math.Min(panel1.Width, panel1.Height) - 2 * margin;
- mainCircleArea = new RectangleF(
- (panel1.Width - diameter) / 2,
- (panel1.Height - diameter) / 2,
- diameter,
- diameter);
- // 在主圆边界上等距分布3个小圆(120度间隔)
- float smallCircleDiameter = 18f;
- float smallCircleRadius = smallCircleDiameter / 2;
- float mainRadius = diameter / 2;
- PointF center = new PointF(mainCircleArea.X + mainRadius, mainCircleArea.Y + mainRadius);
- float circlePlacementRadius = mainRadius; // 小圆放置在主圆边界上
- // 计算三个等距点位置(分布在圆周上)
- // 第一个点放在顶部(90度)
- firstPointCircle = new RectangleF(
- center.X + circlePlacementRadius * (float)Math.Cos(Math.PI / 2) - smallCircleRadius,
- center.Y - circlePlacementRadius * (float)Math.Sin(Math.PI / 2) - smallCircleRadius,
- smallCircleDiameter, smallCircleDiameter);
- // 第二个点放在左下(210度)
- secondPointCircle = new RectangleF(
- center.X + circlePlacementRadius * (float)Math.Cos(Math.PI / 2 + 2 * Math.PI / 3) - smallCircleRadius,
- center.Y - circlePlacementRadius * (float)Math.Sin(Math.PI / 2 + 2 * Math.PI / 3) - smallCircleRadius,
- smallCircleDiameter, smallCircleDiameter);
- // 第三个点放在右下(330度)
- thirdPointCircle = new RectangleF(
- center.X + circlePlacementRadius * (float)Math.Cos(Math.PI / 2 + 4 * Math.PI / 3) - smallCircleRadius,
- center.Y - circlePlacementRadius * (float)Math.Sin(Math.PI / 2 + 4 * Math.PI / 3) - smallCircleRadius,
- smallCircleDiameter, smallCircleDiameter);
- }
- // 绘制主圆形(绿色)
- private void DrawMainCircle(Graphics g, RectangleF circleRect)
- {
- using (GraphicsPath path = new GraphicsPath())
- {
- path.AddEllipse(circleRect);
- // 创建绿色渐变画刷(简单线性渐变)
- using (LinearGradientBrush brush = new LinearGradientBrush(
- circleRect,
- Color.FromArgb(144, 238, 144), // 浅绿色
- Color.FromArgb(34, 139, 34), // 较深绿色
- 90f))
- {
- g.FillPath(brush, path);
- }
- // 添加外边框
- using (Pen pen = new Pen(Color.FromArgb(0, 100, 0), 2)) // 深绿色边框
- {
- g.DrawEllipse(pen, circleRect);
- }
- // 添加内边框(浅色)
- using (Pen innerPen = new Pen(Color.FromArgb(144, 255, 144), 1)) // 浅绿色内边框
- {
- RectangleF innerRect = new RectangleF(
- circleRect.X + 1,
- circleRect.Y + 1,
- circleRect.Width - 2,
- circleRect.Height - 2);
- g.DrawEllipse(innerPen, innerRect);
- }
- }
- }
- // 绘制小圆(黄色,高端效果)
- private void DrawPointCircle(Graphics g, RectangleF circleRect, bool isHovered)
- {
- using (GraphicsPath path = new GraphicsPath())
- {
- path.AddEllipse(circleRect);
- // 根据悬停状态选择颜色
- Color centerColor = isHovered ? Color.Gold : Color.Yellow;
- Color edgeColor = isHovered ? Color.OrangeRed : Color.Goldenrod;
- // 创建径向渐变画刷
- using (PathGradientBrush brush = new PathGradientBrush(path))
- {
- brush.CenterColor = centerColor;
- brush.SurroundColors = new Color[] { edgeColor };
- brush.CenterPoint = new PointF(
- circleRect.X + circleRect.Width / 2,
- circleRect.Y + circleRect.Height / 2);
- brush.FocusScales = new PointF(0.5f, 0.5f);
- g.FillPath(brush, path);
- }
- // 添加高光效果
- RectangleF highlightRect = new RectangleF(
- circleRect.X + circleRect.Width * 0.15f,
- circleRect.Y + circleRect.Height * 0.15f,
- circleRect.Width * 0.3f,
- circleRect.Height * 0.3f);
- using (SolidBrush highlightBrush = new SolidBrush(Color.FromArgb(200, Color.White)))
- {
- g.FillEllipse(highlightBrush, highlightRect);
- }
- // 添加边框
- using (Pen pen = new Pen(Color.SaddleBrown, isHovered ? 2 : 1))
- {
- g.DrawEllipse(pen, circleRect);
- }
- // 鼠标悬停时添加发光效果
- if (isHovered)
- {
- using (Pen glowPen = new Pen(Color.FromArgb(100, Color.Orange), 3))
- {
- glowPen.Alignment = PenAlignment.Outset;
- g.DrawEllipse(glowPen, circleRect);
- }
- }
- }
- }
- // 绘制坐标值
- private void DrawCoordinateText(Graphics g, RectangleF circleRect, string xValue, string yValue)
- {
- string coordinates = $"({xValue}, {yValue})";
- // 使用高质量文本渲染
- g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
- using (Font font = new Font("微软雅黑", 9, FontStyle.Bold))
- {
- SizeF textSize = g.MeasureString(coordinates, font);
- // 计算文字位置(放在圆的外侧)
- float textX = circleRect.X + circleRect.Width / 2 - textSize.Width / 2;
- float textY = circleRect.Y - textSize.Height - 10;
- // 绘制坐标文字
- using (SolidBrush textBrush = new SolidBrush(Color.Black))
- {
- g.DrawString(coordinates, font, textBrush, textX, textY);
- }
- }
- }
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- g.SmoothingMode = SmoothingMode.AntiAlias;
- g.CompositingQuality = CompositingQuality.HighQuality;
- // 确保绘图区域已初始化
- if (mainCircleArea.IsEmpty)
- {
- InitializeImageBoundaryDrawingAreas();
- }
- DrawMainCircle(g, mainCircleArea);
- // 绘制三个等距分布的小圆(黄色)
- DrawPointCircle(g, firstPointCircle, isMouseOverFirstPoint);
- DrawPointCircle(g, secondPointCircle, isMouseOverSecondPoint);
- DrawPointCircle(g, thirdPointCircle, isMouseOverThirdPoint);
- // 显示各点坐标值
- if (!string.IsNullOrEmpty(tB_FirstPointX.Text) && !string.IsNullOrEmpty(tB_FirstPointY.Text))
- {
- DrawCoordinateText(g, firstPointCircle, tB_FirstPointX.Text, tB_FirstPointY.Text);
- }
- if (!string.IsNullOrEmpty(tB_SecondPointX.Text) && !string.IsNullOrEmpty(tB_SecondPointY.Text))
- {
- DrawCoordinateText(g, secondPointCircle, tB_SecondPointX.Text, tB_SecondPointY.Text);
- }
- if (!string.IsNullOrEmpty(tB_ThirdPointX.Text) && !string.IsNullOrEmpty(tB_ThirdPointY.Text))
- {
- DrawCoordinateText(g, thirdPointCircle, tB_ThirdPointX.Text, tB_ThirdPointY.Text);
- }
- }
- private void panel1_MouseMove(object sender, MouseEventArgs e)
- {
- bool wasFirstOver = isMouseOverFirstPoint;
- bool wasSecondOver = isMouseOverSecondPoint;
- bool wasThirdOver = isMouseOverThirdPoint;
- // 检测鼠标是否在各个小圆内
- isMouseOverFirstPoint = IsPointInCircle(e.Location, firstPointCircle);
- isMouseOverSecondPoint = IsPointInCircle(e.Location, secondPointCircle);
- isMouseOverThirdPoint = IsPointInCircle(e.Location, thirdPointCircle);
- // 如果状态发生变化,刷新显示并更新GroupBox高亮
- if (wasFirstOver != isMouseOverFirstPoint ||wasSecondOver != isMouseOverSecondPoint ||wasThirdOver != isMouseOverThirdPoint)
- {
- panel1.Invalidate();
- if (wasFirstOver != isMouseOverFirstPoint)
- UpdateGroupBoxHighlight(groupBox1, isMouseOverFirstPoint);
- if (wasSecondOver != isMouseOverSecondPoint)
- UpdateGroupBoxHighlight(groupBox2, isMouseOverSecondPoint);
- if (wasThirdOver != isMouseOverThirdPoint)
- UpdateGroupBoxHighlight(groupBox3, isMouseOverThirdPoint);
- }
- }
- private void panel1_MouseLeave(object sender, EventArgs e)
- {
- bool wasFirstOver = isMouseOverFirstPoint;
- bool wasSecondOver = isMouseOverSecondPoint;
- bool wasThirdOver = isMouseOverThirdPoint;
- isMouseOverFirstPoint = false;
- isMouseOverSecondPoint = false;
- isMouseOverThirdPoint = false;
- panel1.Invalidate();
- if (wasFirstOver)
- UpdateGroupBoxHighlight(groupBox1, false);
- if (wasSecondOver)
- UpdateGroupBoxHighlight(groupBox2, false);
- if (wasThirdOver)
- UpdateGroupBoxHighlight(groupBox3, false);
- }
- private bool IsPointInCircle(Point point, RectangleF circle)
- {
- if (circle.IsEmpty) return false;
- float centerX = circle.X + circle.Width / 2;
- float centerY = circle.Y + circle.Height / 2;
- float radius = circle.Width / 2;
- float distance = (float)Math.Sqrt(Math.Pow(point.X - centerX, 2) +Math.Pow(point.Y - centerY, 2));
- return distance <= radius;
- }
-
-
-
- private void UpdateGroupBoxHighlight(GroupBox groupBox, bool isHighlighted)
- {
- if (groupBox == null) return;
- if (isHighlighted)
- {
- groupBox.BackColor = Color.FromArgb(240, 255, 240);
- groupBox.ForeColor = Color.DarkGreen;
- }
- else
- {
- groupBox.BackColor = SystemColors.Control;
- groupBox.ForeColor = SystemColors.ControlText;
- }
- groupBox.Invalidate();
- }
- }
- }
|