void NuGenView_MouseClick(object sender, MouseEventArgs e) { Focus(); cursorLocation = new Point(e.X, e.Y); Graphics g = Buffer; switch (doc.DigitizeState) { case DigitizeState.AxisState: { if (doc.AxisPointCount == 3) { MessageBox.Show("You can only create 3 axis points", "Axis Points Defined", MessageBoxButtons.OK); return; } NuGenPoint p = doc.AddPoint(e.X, e.Y); DrawAxes(g); Refresh(); AxisPointDialog dlg = new AxisPointDialog(); DialogResult result = dlg.ShowDialog(); if (result == DialogResult.Cancel) { doc.RemovePoint(p); DrawAll(); Refresh(); return; } if (!doc.SetAxisPoint(p, dlg.XTheta, dlg.YR)) { sendStatusMessage("One or more axis points need to be redefined"); } else { switch (doc.AxisPointCount) { case 1: sendStatusMessage("One axis point defined. Need two more"); break; case 2: sendStatusMessage("Two axes points defined. Need one more"); break; case 3: sendStatusMessage("Axes Defined"); break; } } break; } case DigitizeState.CurveState: { if (doc.ProcessedImage.Width < e.X || doc.ProcessedImage.Height < e.Y) return; NuGenPoint p = doc.AddPoint(e.X, e.Y); DrawAll(); break; } case DigitizeState.MeasureState: { if (doc.PointSets.GetMeasure(doc.ActiveMeasureName).Points.Count != 0) return; if (doc.ProcessedImage.Width < e.X || doc.ProcessedImage.Height < e.Y) return; NuGenPoint p = doc.AddPoint(e.X, e.Y); DrawAll(); break; } case DigitizeState.PointMatchState: { if(!doc.MatchSamplePoint(new Point(e.X, e.Y))) { MessageBox.Show("You must select a suitable match point.", "Unsuitable Point"); } DrawAll(); break; } case DigitizeState.ScaleState: break; case DigitizeState.SegmentState: if (selectedSegment == null) break; foreach (NuGenPoint p in selectedSegment.FillPoints(doc.SegmentSettings)) { doc.AddPoint(p); } DrawAll(); break; case DigitizeState.SelectState: break; } }
void NuGenView_MouseRelease(object sender, MouseEventArgs e) { cursorLocation = new Point(e.X, e.Y); if (doc.DigitizeState == DigitizeState.SelectState) { if (dragged && selectedPointList.Count > 0) { //Remove all the original points foreach (NuGenPoint p in selectedPointGestatingList) { doc.RemovePoint(p); } //Clear them as well selectedPointList.Clear(); //Add the new points to the list selectedPointList.AddRange(selectedPointGestatingList); selectedPointGestatingList.Clear(); List<NuGenPoint> tempList = new List<NuGenPoint>(); //And connect them internally foreach (NuGenPoint p in selectedPointList) { NuGenPoint newPoint = doc.AddPoint(p); //Add this point to a temp list so that selected items list stays up to date tempList.Add(newPoint); if (p.PointSet == doc.PointSets.Axes) { AxisPointDialog dlg = new AxisPointDialog(); if (dlg.ShowDialog() == DialogResult.OK) { GridMeshSettings settings = doc.GridDisplaySettings; GridRemovalSettings removal = doc.GridRemovalSettings; settings.initialized = false; removal.gridMesh.initialized = false; doc.GridRemovalSettings = removal; doc.GridDisplaySettings = settings; doc.SetAxisPoint(newPoint, dlg.XTheta, dlg.YR); } else { doc.RemovePoint(p); } DrawAll(); } else if (p.PointSet == doc.PointSets.ScaleBar) { //Tests to see if there are two scale points in the selection bool cont = false; bool found = false; foreach(NuGenPoint pNew in selectedPointList) { if (pNew.PointSet == doc.PointSets.ScaleBar) { if (found == true) { cont = true; break; } found = true; } } //No need to readjust scale point values if both were moved if (cont) continue; ScaleBarDialog sdlg = new ScaleBarDialog(); if (sdlg.ShowDialog() == DialogResult.OK) { NuGenPoint other = new NuGenPoint(0,0); //Get the other scale point, if it exists, which it should if you are moving the points foreach (NuGenPoint p2 in doc.PointSets.ScaleBar.Points) { if (p2 != p) { other = p; break; } } GridMeshSettings settings = doc.GridDisplaySettings; GridRemovalSettings removal = doc.GridRemovalSettings; settings.initialized = false; removal.gridMesh.initialized = false; doc.SetScalePoint(other, 0, 0); doc.SetScalePoint(p, sdlg.Length, 0); doc.Units = sdlg.Units; } DrawAll(); } } selectedPointList = tempList; return; } if (selectionBox.Size.Width != 0 && selectionBox.Height != 0) { SelectRegion(selectionBox); DrawAll(); } dragged = false; } if (doc.DigitizeState == DigitizeState.MeasureState) { gestatingMeasurePoint = null; DrawAll(); Refresh(); } if (doc.DigitizeState != DigitizeState.ScaleState) return; if (doc.ProcessedImage.Width < e.X || doc.ProcessedImage.Height < e.Y) return; if (scaleStart == null || scaleEnd == null) return; if (scaleStart.XScreen == e.X && scaleStart.YScreen == e.Y) { MessageBox.Show("Scale bar is drawn by clicking and dragging. You must drag to a new point"); doc.RemovePoint(scaleStart); doc.RemovePoint(scaleEnd); scaleStart = null; scaleEnd = null; DrawAll(); return; } ScaleBarDialog sdlg2 = new ScaleBarDialog(); sdlg2.ShowDialog(); double length = sdlg2.Length; if (!(doc.SetScalePoint(scaleStart, 0.0, 0.0) && doc.SetScalePoint(scaleEnd, length, 0.0))) { sendStatusMessage("One or more scale points must be redefined"); } else { doc.Units = sdlg2.Units; } scaleStart = null; scaleEnd = null; if (doc.ValidScale) { sendStatusMessage("Scale Bar Defined"); } DrawScaleBar(Buffer); Refresh(); }
void NuGenView_MouseDoubleClick(object sender, MouseEventArgs e) { CheckForPointIntersection(e.X, e.Y); foreach (NuGenPoint p in selectedPointList) { if (p.PointSet == doc.PointSets.Axes) { AxisPointDialog dlg = new AxisPointDialog(); if (dlg.ShowDialog() == DialogResult.OK) { GridMeshSettings settings = doc.GridDisplaySettings; GridRemovalSettings removal = doc.GridRemovalSettings; settings.initialized = false; removal.gridMesh.initialized = false; doc.GridRemovalSettings = removal; doc.GridDisplaySettings = settings; doc.SetAxisPoint(p, dlg.XTheta, dlg.YR); } else { doc.RemovePoint(p); } DrawAll(); } else if (p.PointSet == doc.PointSets.ScaleBar) { ScaleBarDialog sdlg = new ScaleBarDialog(); if (sdlg.ShowDialog() == DialogResult.OK) { NuGenPoint other = new NuGenPoint(0, 0); //Get the other scale point, if it exists, which it should if you are moving the points foreach (NuGenPoint p2 in doc.PointSets.ScaleBar.Points) { if (p2 != p) { other = p; break; } } GridMeshSettings settings = doc.GridDisplaySettings; GridRemovalSettings removal = doc.GridRemovalSettings; settings.initialized = false; removal.gridMesh.initialized = false; doc.SetScalePoint(other, 0, 0); doc.SetScalePoint(p, sdlg.Length, 0); } DrawAll(); } } }