You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
4.7 KiB
C#
162 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace GeoSigmaViewer
|
|
{
|
|
public partial class PointAddDialog : Form
|
|
{
|
|
private Timer myTimer = new Timer();
|
|
private Drawer drawer;
|
|
private Point2D oldPt = new Point2D();
|
|
|
|
|
|
public PointAddDialog(ref Drawer drawer)
|
|
{
|
|
InitializeComponent();
|
|
angleTextBox.Text = "0.0";
|
|
this.drawer = drawer;
|
|
myTimer.Tick += new EventHandler(TimerEventProcessor);
|
|
|
|
// Sets the timer interval to 0.1 seconds.
|
|
myTimer.Interval = 100;
|
|
myTimer.Start();
|
|
}
|
|
|
|
private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
|
|
{
|
|
Point2D pt = new Point2D();
|
|
drawer.Geo.GetPoint2DFromItem(out pt);
|
|
|
|
//<修复Bug:手工输入坐标无效>
|
|
if (Math.Abs(pt.x) < 0.000001 && Math.Abs(pt.y) < 0.000001)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Math.Abs(pt.x - oldPt.x) < 0.000001
|
|
&& Math.Abs(pt.y - oldPt.y) < 0.000001)
|
|
{
|
|
return;
|
|
}
|
|
oldPt.x = pt.x;
|
|
oldPt.y = pt.y;
|
|
//</修复Bug:手工输入坐标无效>
|
|
|
|
xCoordTextBox.Text = pt.x.ToString();
|
|
yCoordTextBox.Text = pt.y.ToString();
|
|
// angleTextBox.Text = "0.0";
|
|
}
|
|
|
|
private void PointAddDialog_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
myTimer.Stop();
|
|
drawer.Geo.CancelDisplayPointInItem();
|
|
drawer.Geo.EnableRedraw(true);
|
|
drawer.ReDraw();
|
|
drawer.ActiveTool = DrawToolType.Select;
|
|
}
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
//如果是连续绘点,点击"确定"按钮后,不添加点。
|
|
//因为鼠标点击绘图区后,立刻会添加一个点。这个点的坐标也会填写到界面上。
|
|
//若点击"确定",添加此点。则会重复添加点了。
|
|
if (continueCheckBox.CheckState != CheckState.Checked)
|
|
{
|
|
if (AddPoint() == false)
|
|
{
|
|
return ;
|
|
}
|
|
}
|
|
Close();
|
|
}
|
|
|
|
private void continueCheckBox_CheckStateChanged(object sender, EventArgs e)
|
|
{
|
|
if (continueCheckBox.CheckState == CheckState.Checked)
|
|
drawer.Geo.ChangePointAddedMode(1);
|
|
else
|
|
drawer.Geo.ChangePointAddedMode(0);
|
|
}
|
|
|
|
private void nextButton_Click(object sender, EventArgs e)
|
|
{
|
|
AddPoint();
|
|
}
|
|
|
|
private bool AddPoint()
|
|
{
|
|
Point2D pt = new Point2D();
|
|
pt.pointName = pointNameTextBox.Text;
|
|
|
|
try
|
|
{
|
|
pt.x = float.Parse(xCoordTextBox.Text);
|
|
pt.y = float.Parse(yCoordTextBox.Text);
|
|
pt.angle = float.Parse(angleTextBox.Text);
|
|
}
|
|
catch (ArgumentNullException )
|
|
{
|
|
MessageBox.Show("输入信息有误,请重新输入。", "出错信息");
|
|
return false;
|
|
}
|
|
catch (FormatException )
|
|
{
|
|
MessageBox.Show("输入信息有误,请重新输入。", "出错信息");
|
|
return false;
|
|
}
|
|
catch (OverflowException ofEx)
|
|
{
|
|
MessageBox.Show("输入信息有误,请重新输入。", "出错信息");
|
|
return false;
|
|
}
|
|
|
|
drawer.Geo.AddPoint2DToDoc(ref pt);
|
|
return true;
|
|
}
|
|
|
|
private void pointNameTextBox_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (pointNameTextBox.Text == null)
|
|
return;
|
|
|
|
if (pointNameTextBox.Text.Length == 0)
|
|
return;
|
|
|
|
drawer.Geo.AddPointNameToItem(pointNameTextBox.Text);
|
|
drawer.Geo.EnableRedraw(true);
|
|
drawer.ReDraw();
|
|
}
|
|
|
|
private void angleTextBox_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
double angle = 0;
|
|
try
|
|
{
|
|
angle = float.Parse(angleTextBox.Text);
|
|
}
|
|
catch (Exception )
|
|
{
|
|
//TODO:log
|
|
return ;
|
|
}
|
|
|
|
drawer.Geo.ChangeAnglgeToItem(angle);
|
|
drawer.Geo.EnableRedraw(true);
|
|
drawer.ReDraw();
|
|
}
|
|
}
|
|
}
|