private void RemoveLine(NuGenPoint pFrom, NuGenPoint pTo) { lines.Remove(pFrom.NextLine); pFrom.NextLine = null; pTo.PreviousLine = null; }
//Sets a gestating point to a full scale point so that it takes place in // scale computations public bool SetScalePoint(NuGenPoint p, double x, double y) { dirtyScaleTransformation = true; p.XThetaGraph = x; p.YRGraph = y; int result = ComputeTransformation(); switch (result) { case NuGenMath.SUCCESS: return(true); case NuGenMath.NO_SPREAD: MessageBox.Show("Invalid scale point definition for a log scale, redefine points"); break; case NuGenMath.NONPOSITIVE_COORDINATE: MessageBox.Show("Invalid scale point definition for a log scale, redefine points"); break; case NuGenMath.BAD_GRAPH_COORDINATES: MessageBox.Show("Scale points can not be colinear or colocated"); break; case NuGenMath.BAD_SCREEN_COORDINATES: MessageBox.Show("Scale points can not be colinear or colocated"); break; } return(false); }
//Adds the point p to the measure with the name "name" public void AddPointMeasure(NuGenPoint p, string name) { foreach (NuGenPointSet pointset in measureList) { if (pointset.Name.Equals(name)) { pointset.AddPoint(p); } } }
public NuGenPoint(NuGenPoint other) { this.xScreen = other.xScreen; this.yScreen = other.yScreen; xThetaGraph = other.XThetaGraph; yRGraph = other.yRGraph; xThetaDefined = other.xThetaDefined; yRDefined = other.yRDefined; pointSet = new NuGenPointSet(); }
// for curve pointsets connected as Single Valued Functions, since the graph coordinates // of all points are updated, we must reconnect any points that were reordered. remember, // a single valued function has only a single value per xTheta value, so the lines cannot overlap public void ForceSingleValued(CoordSettings coord, NuGenScreenTranslate transform) { // quick exit if pointset is a closed contour, which is the case for all axis, scale and // measure pointsets. curve pointsets may be either single valued functions, or closed contours if (style.lineConnectAs != LineConnectAs.SingleValuedFunction) { return; } // quick exit if points are already in order if (SingleValued(coord, transform)) { return; } Comparison <NuGenPoint> comparison = new Comparison <NuGenPoint>(this.XThetaSort); // sort the points by xTheta points.Sort(comparison); // to prevent having to remove N lines and then immediately adding N lines, we only // adjust as many lines as necessary NuGenPoint pOld = points[points.Count - 1]; NuGenPoint pOlder = null; foreach (NuGenPoint pNew in points) { if (pOlder != null) { if ((pOlder.NextLine != pNew.PreviousLine) || (pNew.PreviousLine == null)) { if (pOlder.NextLine == null) { pOlder.NextLine = pOld.NextLine; pOld.NextLine = null; } pOlder.NextLine.start.X = pOlder.XScreen; pOlder.NextLine.start.Y = pOlder.YScreen; pOlder.NextLine.end.X = pNew.XScreen; pOlder.NextLine.end.Y = pNew.YScreen; pNew.PreviousLine = pOlder.NextLine; } } else { pNew.PreviousLine = null; } pOlder = pNew; } }
// merge the x values of this pointset into a sorted list having unique x values. although // this returns numeric x values with full precision, their exported precision must be // specified so no adjacent exported x values will have the same value (breaks postprocessing // tools such as sql databases) public void MergeUniqueXValues(List <double> list, int xPrecision) { if (points.Count == 0) { return; } NuGenPoint p = points[0]; int index = 0; for (int i = 0; i < list.Count; i++) { double x = list[i]; for (; p.XThetaGraph < x && index < points.Count; index++) { p = points[index]; list.Insert(list.IndexOf(x), p.XThetaGraph); } if (index >= points.Count) { break; } } while (index < points.Count) { p = points[index++]; list.Add(p.XThetaGraph); } string xLast = "", xNew; double d = list[0]; for (int i = 1; i < list.Count;) { xNew = String.Format("{0}", Math.Round(d, xPrecision).ToString()); if (xLast.Equals(xNew)) { list.Remove(d); d = list[i]; } else { d = list[i++]; } xLast = xNew; } }
//Gets the distance along the curve of each point private void GeometryInfoDistance(ref int pNextRow, List <NuGenGeometryWindowItem> rInfo, bool cartesian) { bool firstPoint; double xLast = 0.0, yLast = 0.0, x, y; double totalDistance = 0.0, distance; rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 0, cartesian ? "X" : "Theta")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 1, cartesian ? "Y" : "R")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 2, "Index")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 3, "Distance")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 4, "Percent")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 5, "Distance")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 6, "Percent")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 7, "Angle")); pNextRow++; // first pass computes totalDistance and xLast and yLast, second pass outputs one line per point for (int pass = 0; pass < 2; pass++) { firstPoint = true; distance = 0.0; NuGenPoint point; for (int i = 0; i < points.Count; i++) { point = points[i]; x = point.XThetaGraph; y = point.YRGraph; if (!firstPoint) { distance += Math.Sqrt((x - xLast) * (x - xLast) + (y - yLast) * (y - yLast)); } NuGenPoint next = (i + 1) != points.Count ? points[i + 1] : points[0]; if (pass == 1) { GeometryInfoDistancePass1(i, next, xLast, yLast, x, y, distance, totalDistance, ref pNextRow, rInfo); } firstPoint = false; xLast = x; yLast = y; } totalDistance = distance; } }
// add axis or curve point, depending on state. axis point graph coordinates are set later by // setAxisPoint so user can see where the new axis point lies while editing the graph coordinatees public NuGenPoint AddPoint(int xScreen, int yScreen, NuGenPointSet destination) { double xThetaGraph = 0.0, yRGraph = 0.0; NuGenPoint p; if ((digitizeState == DigitizeState.CurveState) || (digitizeState == DigitizeState.MeasureState)) { ScreenToXThetaYR(xScreen, yScreen, out xThetaGraph, out yRGraph); p = new NuGenPoint(xScreen, yScreen, xThetaGraph, yRGraph); } else { p = new NuGenPoint(xScreen, yScreen); } switch (digitizeState) { case DigitizeState.AxisState: dirtyAxesTransformation = true; pointSets.AddPointAxes(p); break; case DigitizeState.CurveState: case DigitizeState.SegmentState: pointSets.AddPointCurve(p, currentCurveName); break; case DigitizeState.MeasureState: pointSets.AddPointMeasure(p, currentMeasureName); break; case DigitizeState.ScaleState: dirtyScaleTransformation = true; pointSets.AddPointScale(p); break; case DigitizeState.SelectState: //Could be any type of point, so decide if (destination != null) { destination.AddPoint(p); } break; } PointSets.UpdateGraphCoordinates(coordSettings, transform); return(p); }
// adding and removing lines involves updating update area and point pointers private void AddLine(NuGenPoint pFrom, NuGenPoint pTo) { Line line = new Line(); line.start.X = pFrom.XScreen; line.start.Y = pFrom.YScreen; line.end.X = pTo.XScreen; line.end.Y = pTo.YScreen; lines.Add(line); pFrom.NextLine = line; pTo.PreviousLine = line; }
// add point to pointset, not worrying about keeping the pointset single valued (which is for // curves only). if new point is on the line between two points then insert it between // those two points (desired behavior for curve and measure pointsets, which happens to not affect // axes and scale pointsets) public void AddPoint(NuGenPoint point) { // insert point between two other points if it lies on the line between the two points const int LineEpsilonPixels = 2; int index = 0; double x = point.XScreen; double y = point.YScreen; NuGenPoint pOld = null; foreach (NuGenPoint pNew in points) { double xNew = pNew.XScreen; double yNew = pNew.YScreen; if (pOld != null) { double xOld = pOld.XScreen; double yOld = pOld.YScreen; double xProj, yProj; NuGenMath.ProjectPointOnToLine(x, y, xOld, yOld, xNew, yNew, out xProj, out yProj); double diff = Math.Sqrt((x - xProj) * (x - xProj) + (y - yProj) * (y - yProj)); if (diff < LineEpsilonPixels) { points.Insert(index, point); point.PointSet = this; RemoveLine(pOld, pNew); AddLine(pOld, point); AddLine(point, pNew); return; } } pOld = pNew; index++; } points.Add(point); point.PointSet = this; if (pOld != null) { AddLine(pOld, point); } }
//Removes a point from the document based on the documents current digitize state public void RemovePoint(NuGenPoint p) { switch (DigitizeState) { case DigitizeState.AxisState: pointSets.Axes.RemovePoint(p); break; case DigitizeState.CurveState: foreach (NuGenPointSet pointSet in pointSets.Curves) { pointSet.RemovePoint(p); } break; case DigitizeState.MeasureState: foreach (NuGenPointSet pointSet in pointSets.Measures) { pointSet.RemovePoint(p); } break; case DigitizeState.ScaleState: pointSets.ScaleBar.RemovePoint(p); break; case DigitizeState.SelectState: //find and remove the point since it is generic { foreach (NuGenPointSet pointSet in pointSets.Curves) { pointSet.RemovePoint(p); } foreach (NuGenPointSet pointSet in pointSets.Measures) { pointSet.RemovePoint(p); } pointSets.Axes.RemovePoint(p); pointSets.ScaleBar.RemovePoint(p); gridDisplaySettings.initialized = false; gridRemovalSettings.gridMesh.initialized = false; ComputeTransformation(); } break; } }
// add point to pointset, not worrying about keeping the pointset single valued (which is for // curves only). if new point is on the line between two points then insert it between // those two points (desired behavior for curve and measure pointsets, which happens to not affect // axes and scale pointsets) public void AddPoint(NuGenPoint point) { // insert point between two other points if it lies on the line between the two points const int LineEpsilonPixels = 2; int index = 0; double x = point.XScreen; double y = point.YScreen; NuGenPoint pOld = null; foreach (NuGenPoint pNew in points) { double xNew = pNew.XScreen; double yNew = pNew.YScreen; if (pOld != null) { double xOld = pOld.XScreen; double yOld = pOld.YScreen; double xProj, yProj; NuGenMath.ProjectPointOnToLine(x, y, xOld, yOld, xNew, yNew, out xProj, out yProj); double diff = Math.Sqrt((x - xProj) * (x - xProj) + (y - yProj) * (y - yProj)); if (diff < LineEpsilonPixels) { points.Insert(index, point); point.PointSet = this; RemoveLine(pOld, pNew); AddLine(pOld, point); AddLine(point, pNew); return; } } pOld = pNew; index++; } points.Add(point); point.PointSet = this; if (pOld != null) AddLine(pOld, point); }
private void GeometryInfoDistancePass1(int i, NuGenPoint pointNext, double xLast, double yLast, double x, double y, double distance, double totalDistance, ref int pNextRow, List <NuGenGeometryWindowItem> rInfo) { double xNext = pointNext.XThetaGraph; double yNext = pointNext.YRGraph; double pcDistance; if (totalDistance <= 0.0) { pcDistance = 100.0; } else { pcDistance = 100.0 * distance / totalDistance; } double[] r1 = new double[3]; double[] r2 = new double[3]; r1[0] = xLast - x; // xLast from last point of pass 0 is used by first point in pass 1 r1[1] = yLast - y; // yLast from last point of pass 0 is used by first point in pass 1 r1[2] = 0.0; r2[0] = xNext - x; r2[1] = yNext - y; r2[2] = 0.0; double angle = NuGenMath.Angle(r1, r2) * 180.0 / Math.PI; double distDiff = totalDistance - distance; double pcDiff = 100.0 - pcDistance; rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 0, x.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 1, y.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 2, i.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 3, distance.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 4, pcDistance.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 5, distDiff.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 6, pcDiff.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 7, angle.ToString())); pNextRow++; }
//deserialize public void SerializeRead(System.Runtime.Serialization.SerializationInfo info, string prefix) { name = (string)info.GetValue(prefix + ".name", typeof(string)); style.pointShape = (PointShape)info.GetValue(prefix + ".style.pointShape", typeof(PointShape)); style.pointSize = (PointSize)info.GetValue(prefix + ".style.pointSize", typeof(PointSize)); style.pointLineSize = (PointLineSize)info.GetValue(prefix + ".style.pointLineSize", typeof(PointLineSize)); style.pointLineColor = (Color)info.GetValue(prefix + ".style.pointLineColor", typeof(Color)); style.pointInColor = (Color)info.GetValue(prefix + ".style.pointInColor", typeof(Color)); style.lineSize = (LineSize)info.GetValue(prefix + ".style.lineSize", typeof(LineSize)); style.lineColor = (Color)info.GetValue(prefix + ".style.lineColor", typeof(Color)); style.lineConnectAs = (LineConnectAs)info.GetValue(prefix + ".style.lineConnectAs", typeof(LineConnectAs)); int count = (int)info.GetValue(prefix + ".points.count", typeof(int)); for (int index = 0; index < count; index++) { NuGenPoint point = new NuGenPoint(0, 0); point.XScreen = (int)info.GetValue(prefix + ".point" + index + ".xScreen", typeof(int)); point.YScreen = (int)info.GetValue(prefix + ".point" + index + ".yScreen", typeof(int)); point.XThetaGraph = (double)info.GetValue(prefix + ".point" + index + ".xThetaGraph", typeof(double)); point.YRGraph = (double)info.GetValue(prefix + ".point" + index + ".yRGraph", typeof(double)); AddPoint(point); } }
// given an x value, return the corresponding y value, interpolating if necessary public string ExportCurvePoint(double x, CoordSettings coord, bool useInterpolation, int yPrecision) { string yNew = ""; // initial empty value might be returned if interpolation is disabled if (Points.Count == 0) { return(yNew); } if (!useInterpolation) { // x value has to exactly match one of the points in this curve foreach (NuGenPoint p in Points) { if (x == p.XThetaGraph) { return(Math.Round(p.YRGraph, yPrecision).ToString()); } } return(yNew); } if (Points.Count == 1) { foreach (NuGenPoint p in Points) { return(Math.Round(p.YRGraph, yPrecision).ToString()); } } IEnumerator <NuGenPoint> lEnum = Points.GetEnumerator(); IEnumerator <NuGenPoint> rEnum = Points.GetEnumerator(); rEnum.MoveNext(); rEnum.MoveNext(); lEnum.MoveNext(); NuGenPoint pLeft = lEnum.Current; NuGenPoint pRight = rEnum.Current; while (x > rEnum.Current.XThetaGraph) { rEnum.MoveNext(); lEnum.MoveNext(); if (rEnum.Current != null) { pLeft = lEnum.Current; pRight = rEnum.Current; } else { break; } } double leftPointX = pLeft.XThetaGraph; double rightPointX = pRight.XThetaGraph; double leftPointY = pLeft.YRGraph; double rightPointY = pRight.YRGraph; if (AdjustForLogScale(coord.xThetaScale, ref leftPointX) && AdjustForLogScale(coord.xThetaScale, ref rightPointX) && AdjustForLogScale(coord.xThetaScale, ref x) && AdjustForLogScale(coord.yRScale, ref leftPointY) && AdjustForLogScale(coord.yRScale, ref rightPointY)) { double denominator = rightPointX - leftPointX; if (denominator < NuGenDefaultSettings.GetInstance().DoubleMin) { yNew = Math.Round(leftPointX, yPrecision).ToString(); } else { // if x value is between the points this is an interpolation (0<s<1), otherwise an extrapolation double s = (x - leftPointX) / denominator; // interpolate or extrapolate double otherPoint = (1.0 - s) * leftPointY + s * rightPointY; // adjust for log scale if (coord.yRScale == Scale.Log) { otherPoint = Math.Pow((double)10.0, otherPoint); } yNew = Math.Round(otherPoint, yPrecision).ToString(); } } return(yNew); }
void NuGenView_MousePress(object sender, MouseEventArgs e) { cursorLocation = new Point(e.X, e.Y); if (doc.ProcessedImage.Width < e.X || doc.ProcessedImage.Height < e.Y) return; if (doc.DigitizeState == DigitizeState.SelectState) { //In the select state a mouse click means the user is trying to select a point CheckForPointIntersection(e.X, e.Y); //DrawSelectedPoints(Buffer); //Refresh(); DrawAll(); return; } if (doc.DigitizeState == DigitizeState.MeasureState) { if (doc.PointSets.GetMeasure(doc.ActiveMeasureName).Points.Count >= 1) { gestatingMeasurePoint = doc.AddPoint(e.X, e.Y); DrawMeasurePoints(Buffer); Refresh(); } } if (doc.DigitizeState != DigitizeState.ScaleState) return; if (doc.ValidScale) { MessageBox.Show("Scale Bar is already defined, to change it use the selection tool"); return; } scaleStart = doc.AddPoint(e.X, e.Y); scaleEnd = doc.AddPoint(e.X, e.Y); DrawScaleBar(Buffer); Refresh(); }
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(); }
private void GeometryInfoDistancePass1(int i, NuGenPoint pointNext, double xLast, double yLast, double x, double y, double distance, double totalDistance, ref int pNextRow, List<NuGenGeometryWindowItem> rInfo) { double xNext = pointNext.XThetaGraph; double yNext = pointNext.YRGraph; double pcDistance; if (totalDistance <= 0.0) pcDistance = 100.0; else pcDistance = 100.0 * distance / totalDistance; double[] r1 = new double[3]; double[] r2 = new double[3]; r1[0] = xLast - x; // xLast from last point of pass 0 is used by first point in pass 1 r1[1] = yLast - y; // yLast from last point of pass 0 is used by first point in pass 1 r1[2] = 0.0; r2[0] = xNext - x; r2[1] = yNext - y; r2[2] = 0.0; double angle = NuGenMath.Angle(r1, r2) * 180.0 / Math.PI; double distDiff = totalDistance - distance; double pcDiff = 100.0 - pcDistance; rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 0, x.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 1, y.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 2, i.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 3, distance.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 4, pcDistance.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 5, distDiff.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 6, pcDiff.ToString())); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 7, angle.ToString())); pNextRow++; }
//delegate method for sorting points by their xtheta values public int XThetaSort(NuGenPoint p1, NuGenPoint p2) { return((int)(p1.XThetaGraph - p2.XThetaGraph)); }
//Used primarily for dragging operations, hence the "dragged" boolean flag void NuGenView_MouseMove(object sender, MouseEventArgs e) { showCoordinates(e.X, e.Y); Graphics g = Buffer; if (doc.DigitizeState == DigitizeState.SelectState && e.Button != MouseButtons.None) { if (e.X == cursorLocation.X && e.Y == cursorLocation.Y) return; dragged = true; if (selectedPointList.Count > 0) { foreach (NuGenPoint p in selectedPointGestatingList) { doc.RemovePoint(p); } foreach (NuGenPoint p in selectedPointList) { doc.RemovePoint(p); } List<NuGenPoint> clearList = new List<NuGenPoint>(); clearList.AddRange(selectedPointGestatingList); selectedPointGestatingList.Clear(); int xDiff = e.X - cursorLocation.X; int yDiff = e.Y - cursorLocation.Y; if (xDiff == 0 && yDiff == 0) return; foreach (NuGenPoint p in selectedPointList) { NuGenPoint newPoint = doc.AddPoint(p.XScreen + xDiff, p.YScreen + yDiff, p.PointSet); selectedPointGestatingList.Add(newPoint); } DrawAll(); return; } else { if (cursorLocation.X == e.X && cursorLocation.Y == e.Y) return; g.Clear(Color.Transparent); DrawAll(new Region(new Rectangle(0,0,backBuffer.Width, backBuffer.Height))); DrawSelectionRectangle(e.X, e.Y, g); Refresh(); } } if (doc.ProcessedImage.Width < e.X || doc.ProcessedImage.Height < e.Y) return; if (doc.DigitizeState == DigitizeState.SegmentState) { CheckForSegmentIntersection(e.X, e.Y); DrawAll(); return; } if (doc.DigitizeState == DigitizeState.PointMatchState) { doc.HighlightCandidateMatchPoint(new Point(e.X, e.Y)); DrawAll(); DrawMatchHighlights(Buffer); Refresh(); return; } if (doc.DigitizeState == DigitizeState.MeasureState) { if (gestatingMeasurePoint == null) return; doc.RemovePoint(gestatingMeasurePoint); gestatingMeasurePoint = doc.AddPoint(e.X, e.Y); DrawAll(); } if (scaleStart == null || scaleEnd == null) return; if (doc.DigitizeState != DigitizeState.ScaleState) return; doc.RemovePoint(scaleEnd); scaleEnd = doc.AddPoint(e.X, e.Y); DrawAll(); }
// remove a point from this pointset public void RemovePoint(NuGenPoint p) { if (!points.Contains(p)) return; NuGenPoint pFirst = points[0]; NuGenPoint pLast = points[points.Count - 1]; if (points.Count > 1) { // remove one of its attached lines. four cases are: // 1. solitary point (0 lines->0 lines) // 2. leftmost point (1 attached lines->0 attached lines) // 3. doubly attached point (2 attached lines->1 attached line) // 4. rightmost point (1 attached line->0 attached lines) // not case 1 if ((p == points[0] || (p == points[points.Count - 1]))) { NuGenPoint pOld = null; foreach (NuGenPoint pNew in points) { if ((p == pOld && p == pFirst) || (p == pNew) && (p == pLast)) { RemoveLine(pOld, pNew); break; } pOld = pNew; } } else { NuGenPoint pOlder = null; NuGenPoint pOld = null; foreach (NuGenPoint pNew in points) { if (p == pOld) { if (pOlder != null) { RemoveLine(pOld, pNew); Line pOlderNextLine = new Line(); pOlderNextLine.start.X = pOlder.XScreen; pOlderNextLine.start.Y = pOlder.YScreen; pOlderNextLine.end.X = pNew.XScreen; pOlderNextLine.end.Y = pNew.YScreen; pOlder.NextLine = pOlderNextLine; pNew.PreviousLine = pOlder.NextLine; break; } } pOlder = pOld; pOld = pNew; } } } points.Remove(p); }
// remove a point from this pointset public void RemovePoint(NuGenPoint p) { if (!points.Contains(p)) { return; } NuGenPoint pFirst = points[0]; NuGenPoint pLast = points[points.Count - 1]; if (points.Count > 1) { // remove one of its attached lines. four cases are: // 1. solitary point (0 lines->0 lines) // 2. leftmost point (1 attached lines->0 attached lines) // 3. doubly attached point (2 attached lines->1 attached line) // 4. rightmost point (1 attached line->0 attached lines) // not case 1 if ((p == points[0] || (p == points[points.Count - 1]))) { NuGenPoint pOld = null; foreach (NuGenPoint pNew in points) { if ((p == pOld && p == pFirst) || (p == pNew) && (p == pLast)) { RemoveLine(pOld, pNew); break; } pOld = pNew; } } else { NuGenPoint pOlder = null; NuGenPoint pOld = null; foreach (NuGenPoint pNew in points) { if (p == pOld) { if (pOlder != null) { RemoveLine(pOld, pNew); Line pOlderNextLine = new Line(); pOlderNextLine.start.X = pOlder.XScreen; pOlderNextLine.start.Y = pOlder.YScreen; pOlderNextLine.end.X = pNew.XScreen; pOlderNextLine.end.Y = pNew.YScreen; pOlder.NextLine = pOlderNextLine; pNew.PreviousLine = pOlder.NextLine; break; } } pOlder = pOld; pOld = pNew; } } } points.Remove(p); }
//delegate method for sorting points by their xtheta values public int XThetaSort(NuGenPoint p1, NuGenPoint p2) { return (int)(p1.XThetaGraph - p2.XThetaGraph); }
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(); } } }
//deserialize public void SerializeRead(System.Runtime.Serialization.SerializationInfo info, string prefix) { name = (string)info.GetValue(prefix + ".name", typeof(string)); style.pointShape = (PointShape)info.GetValue(prefix + ".style.pointShape", typeof(PointShape)); style.pointSize = (PointSize)info.GetValue(prefix + ".style.pointSize", typeof(PointSize)); style.pointLineSize = (PointLineSize)info.GetValue(prefix + ".style.pointLineSize", typeof(PointLineSize)); style.pointLineColor = (Color)info.GetValue(prefix + ".style.pointLineColor", typeof(Color)); style.pointInColor = (Color)info.GetValue(prefix + ".style.pointInColor", typeof(Color)); style.lineSize = (LineSize)info.GetValue(prefix + ".style.lineSize", typeof(LineSize)); style.lineColor = (Color)info.GetValue(prefix + ".style.lineColor", typeof(Color)); style.lineConnectAs = (LineConnectAs)info.GetValue(prefix + ".style.lineConnectAs", typeof(LineConnectAs)); int count = (int)info.GetValue(prefix + ".points.count", typeof(int)); for(int index = 0; index<count; index++) { NuGenPoint point = new NuGenPoint(0,0); point.XScreen = (int)info.GetValue(prefix + ".point" + index + ".xScreen", typeof(int)); point.YScreen = (int)info.GetValue(prefix + ".point" + index + ".yScreen", typeof(int)); point.XThetaGraph = (double)info.GetValue(prefix + ".point" + index + ".xThetaGraph", typeof(double)); point.YRGraph = (double)info.GetValue(prefix + ".point" + index + ".yRGraph", typeof(double)); AddPoint(point); } }
public NuGenPoint AddPoint(NuGenPoint p) { return(AddPoint(p.XScreen, p.YScreen, p.PointSet)); }
// add a point to an axes, curve, measure or scale pointset public void AddPointAxes(NuGenPoint p) { axesPointSet.AddPoint(p); }
public void AddPointScale(NuGenPoint p) { scalePointSet.AddPoint(p); }
//selects the given point and makes it available for move/delete/edit operations private void SelectPoint(NuGenPoint p) { selectedPointList.Clear(); selectedPointList.Add(p); selectedPointGestatingList.Clear(); selectedPointGestatingList.Add(p); DrawSelectedPoints(Buffer); }