Esempio n. 1
0
 //开始画图,更改文本及状态量
 private void StartDrawingButton_Click(object sender, EventArgs e)
 {
     try
     {
         PolyLineLengthLabel.Text     = "折线长度:NaN (m)";
         ResultLabel.Text             = "点位:";
         DrawingTipLabel.Text         = "左键绘点,右键撤销,双击或按F2结束绘制。请绘制第1个点,按Esc取消";
         DrawGroupBox.Enabled         = false;
         PolyLineCalcGroupBox.Enabled = false;
         FileGroupBox.Enabled         = false;
         PlotPointPictureBox.Cursor   = CrossCur;
         Line.Points.Clear();
         EditStateButton.CheckState = CheckState.Unchecked;
         PolyLineDrawing.ClearPictureBox(PlotPointPictureBox);
         PlotPointPictureBox.Image = new Bitmap(PlotPointPictureBox.Width, PlotPointPictureBox.Height);
         IsDrawing    = true;
         CurrentPoint = 0;
         PlotPointPictureBox.Cursor = CrossCur;
         EditStateButton.Enabled    = false;
     }
     catch (Exception err)
     {
         MessageBoxes.Error(err.Message);
     }
 }
Esempio n. 2
0
 //计算线段对应比例点
 private void CalcButton_Click(object sender, EventArgs e)
 {
     try
     {
         float  Ratio      = (float)(PolyLineRatioScrollBar.Value / 100.0);
         double ScaleRatio = Convert.ToDouble(RatioTextBox.Text);
         if (Ratio < 0 || Ratio > 1)
         {
             throw new Exception("所求线段比例非法!");
         }
         else
         {
             PlotPoint Target = new PlotPoint();                 //为所求点新建对象
             Target = Algorithm.GetPointPos(Line.Points, Ratio); //计算所求点位置
             ClearAndDraw();
             PolyLineDrawing.DrawPoints(Target, PlotPointPictureBox, Algorithm.InverseColor(PointColorPictureBox.BackColor), PointWidthTrackBar.Value);
             PolyLineDrawing.DrawFonts(Target, "P", PlotPointPictureBox, FontColorPictureBox.BackColor, FontStyleDisplayLabel.Font, PointWidthTrackBar.Value);
             PlotPointPictureBox.Invalidate();
             //计算并输出实际坐标系点位
             PlotPoint Corrected = Algorithm.GetActualPos(PlotPointPictureBox, Target);
             ResultLabel.Text = "点位:(" + (Corrected.X * ScaleRatio / PlotPointPictureBox.Width).ToString("0.0000") + ", " + (Corrected.Y * ScaleRatio / PlotPointPictureBox.Width).ToString("0.0000") + ") (m)";
             IsCalculated     = true;
         }
     }
     catch (Exception err)
     {
         MessageBoxes.Error(err.Message);
     }
 }
Esempio n. 3
0
 //窗口关闭中
 private void SaveUserSettings(object sender, FormClosingEventArgs e)
 {
     try
     {
         SettingsOperation(1);
     }
     catch (Exception err)
     {
         MessageBoxes.Error(err.Message);
     }
 }
Esempio n. 4
0
        //按钮管理类
        private void FileManagement(object sender, EventArgs e)
        {
            try
            {
                //存储
                if (sender == SaveToFileButton)
                {
                    string st = FilePathTextBox.Text + "\\PlotPoints.xml";
                    IO.SaveToFile(st, Line.Points);
                    DrawingTipLabel.Text = "成功保存点位信息至" + st;
                }

                //读取
                if (sender == ReadFromFileButton)
                {
                    string st = FilePathTextBox.Text + "\\PlotPoints.xml";
                    Line.Points.Clear();
                    Line.Points = IO.LoadFromFile(st);
                    FileLoad(st);
                }

                //改路径
                if (sender == ChangeFilePathButton)
                {
                    FolderBrowserDialog ChangeFilePath = new FolderBrowserDialog();
                    if (ChangeFilePath.ShowDialog() == DialogResult.OK)
                    {
                        FilePathTextBox.Text = ChangeFilePath.SelectedPath;
                        DrawingTipLabel.Text = "已更改工作目录至" + FilePathTextBox.Text;
                    }
                }

                //开文件夹
                if (sender == OpenFileLocation)
                {
                    System.Diagnostics.Process.Start("explorer.exe", FilePathTextBox.Text);
                }

                //存图
                if (sender == SaveToPicButton)
                {
                    string st = FilePathTextBox.Text + "\\PolyLine_" + IO.DT() + ".png";
                    IO.Save2Pic(PlotPointPictureBox, st);
                    DrawingTipLabel.Text = "成功保存当前绘图至" + st;
                }
            }
            catch (Exception err)
            {
                MessageBoxes.Error(err.Message);
            }
        }
Esempio n. 5
0
 //窗口加载,进行初始化操作
 private void PolyLinePlotPoints_Load(object sender, EventArgs e)
 {
     try
     {
         FilePathTextBox.Text         = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
         PolyLineCalcGroupBox.Enabled = false;
         SaveToPicButton.Enabled      = false;
         PolyLineDrawing.ClearPictureBox(PlotPointPictureBox);    //启动时清空画板
         SettingsOperation(-1);
     }
     catch (Exception err)
     {
         MessageBoxes.Error(err.Message);
     }
 }
Esempio n. 6
0
        //预览或编辑
        private void PreviewOrEdit(object sender, MouseEventArgs e)
        {
            try
            {
                //预览
                if (IsDrawing && IsPreviewing)
                {
                    PlotPoint Preview = new PlotPoint
                    {
                        X = e.X,
                        Y = e.Y
                    };
                    ClearAndDraw();
                    if (Line.Points.Count > 0)
                    {
                        if (PolyLineCalcGroupBox.Visible)
                        {
                            PolyLineLengthLabel.Text = "折线长度:" + (((Algorithm.GetPolyLineLength(Line.Points) + Algorithm.GetSingleLineLength(Line.Points[Line.Points.Count - 1], Preview)) / (PlotPointPictureBox.Width)) * Convert.ToDouble(RatioTextBox.Text)).ToString("0.0000") + " (m)";
                        }
                        if (IsPolygonCheckBox.Checked)
                        {
                            if (Line.Points.Count > 1)
                            {
                                PolyLineDrawing.DrawPolygon(Line.Points, PlotPointPictureBox, PolygonColorPictureBox.BackColor, PolygonTransparencyTrackBar.Value * 255 / (PolygonTransparencyTrackBar.Maximum - PolygonTransparencyTrackBar.Minimum), Preview);
                                List <PlotPoint> PreviewArea = new List <PlotPoint>();
                                for (int i = 0; i < Line.Points.Count(); i++)
                                {
                                    PreviewArea.Add(Line.Points[i]);
                                }
                                PreviewArea.Add(Preview);
                                PolygonAreaLabel.Text = "多边形面积:" + (Algorithm.GetPolygonArea(PreviewArea, PlotPointPictureBox, Convert.ToSingle(RatioTextBox.Text))).ToString("0.0000") + "(m ^ 2)";
                            }
                            PolyLineDrawing.DrawPreviewLine(Line.Points[0], Preview, PlotPointPictureBox, Algorithm.InverseColor(LineColorPictureBox.BackColor), LineWidthTrackBar.Value);
                        }
                        PolyLineDrawing.DrawPreviewLine(Line.Points[Line.Points.Count - 1], Preview, PlotPointPictureBox, Algorithm.InverseColor(LineColorPictureBox.BackColor), LineWidthTrackBar.Value);
                    }
                    PolyLineDrawing.DrawPoints(Preview, PlotPointPictureBox, Algorithm.InverseColor(PointColorPictureBox.BackColor), PointWidthTrackBar.Value);
                    PolyLineDrawing.DrawFonts(Preview, Convert.ToString(Line.Points.Count + 1), PlotPointPictureBox, FontColorPictureBox.BackColor, FontStyleDisplayLabel.Font, PointWidthTrackBar.Value);
                    PlotPointPictureBox.Invalidate();
                }

                //编辑
                if (!IsDrawing && IsEditing && !IsPointMoving && Line.Points.Count != 0)
                {
                    PlotPointPictureBox.Cursor = Cursors.Arrow;
                    List <double> Dis     = new List <double>();
                    PlotPoint     EditPos = new PlotPoint
                    {
                        X = e.X,
                        Y = e.Y
                    };

                    foreach (PlotPoint Point in Line.Points)
                    {
                        Dis.Add(Algorithm.GetSingleLineLength(EditPos, Point));
                    }

                    //找最小距离点
                    double MinDistance      = Dis[0];
                    int    MinDistanceIndex = 0;
                    for (int i = 0; i < Dis.Count; i++)
                    {
                        if (Dis[i] < MinDistance)
                        {
                            MinDistance      = Dis[i];
                            MinDistanceIndex = i;
                        }
                    }

                    //小于容差则选中
                    if (MinDistance < Convert.ToDouble(ToleranceTextBox.Text))
                    {
                        IsPointSelected            = true;
                        PlotPointPictureBox.Cursor = CrossCur;
                        SelectedPointIndex         = MinDistanceIndex;
                        DrawingTipLabel.Text       = "已选中第" + Convert.ToString(SelectedPointIndex + 1) + "个点,按住鼠标左键拖动以改变位置,按Del或鼠标右键删除";
                        PolyLineDrawing.DrawPoints(Line.Points[SelectedPointIndex], PlotPointPictureBox, Algorithm.InverseColor(PointColorPictureBox.BackColor), Convert.ToInt32(PointWidthTrackBar.Value * 1.5));
                        PlotPointPictureBox.Refresh();
                    }
                    else
                    {
                        if (SelectedPointIndex != -1)
                        {
                            ClearAndDraw();
                        }
                        DisSelect();
                        DrawingTipLabel.Text = "未选中任何点";
                    }
                }

                //移动选中点
                if (!IsDrawing && IsEditing && IsPointMoving && Line.Points.Count != 0)
                {
                    if (e.X >= 0 && e.Y >= 0 && e.X <= PlotPointPictureBox.Width && e.Y <= PlotPointPictureBox.Height)
                    {
                        Line.Points[SelectedPointIndex].X = e.X;
                        Line.Points[SelectedPointIndex].Y = e.Y;
                        ClearAndDraw();
                        DrawingTipLabel.Text = "正在移动第" + Convert.ToString(SelectedPointIndex + 1) + "个点";
                    }
                    else
                    {
                        DisSelect();
                        DrawingTipLabel.Text = "焦点丢失";
                    }
                }
            }
            catch (Exception err)
            {
                MessageBoxes.Error(err.Message);
            }
        }