private void inkOverlay_StrokesDeleting(object sender, InkOverlayStrokesDeletingEventArgs e) { if (this.InvokeRequired) { return; } Strokes strokes = e.StrokesToDelete; //Remove the corresponding nodes and edges for each stroke for (int i = 0; i < strokes.Count; i++) { if (StrokeManager.isClosed(strokes[i], 0)) { graph.Remove(graph.Nodes.getNode(strokes[i])); } else { graph.Remove(graph.Edges.getEdge(strokes[i])); } } Invalidate(); }
private void inkOverlay_Stroke(object sender, InkCollectorStrokeEventArgs e) { if (this.InvokeRequired) { return; } //in effect, this is reseting the timer to start from the beginning. edgeTimer.Stop(); edgeTimer.Start(); //Check if the stroke was a tap, and if it was, get the node it tapped. Node n = StrokeManager.TappedNode(e.Stroke, graph); if (n != null) { //If its eraser mode, delete it. if (inkOverlay.EditingMode == InkOverlayEditingMode.Delete) { graph.Remove(n); } else { //Any other mode, select it and change to selection mode int[] ids = { n.Stroke.Id }; selectionButton(sender, e); inkOverlay.Selection = e.Stroke.Ink.CreateStrokes(ids); } e.Stroke.Ink.DeleteStroke(e.Stroke); Invalidate(); return; } //The following code is for pen mode only strokes if (inkOverlay.EditingMode != InkOverlayEditingMode.Ink) { return; } //If a stroke is inside a node, store it in n n = StrokeManager.HitNodeTest(e.Stroke, graph); //If the stroke is closed and it's a start, assign a home or destination if (StrokeManager.isClosed(e.Stroke) && n != null && StrokeManager.isStar(e.Stroke)) { graph.AssignNode(n); RecognizeWeight(); //Attempt at recognizing weight is made after every stroke. } //If the stroke is closed and it is not enclosed in a node and is a circle, make a circular node else if (StrokeManager.isClosed(e.Stroke) && n == null && e.Stroke.PacketCount > StrokeManager.SMALLEST_N_SIZE && StrokeManager.FitsCircleProperties(e.Stroke)) { Stroke circle = StrokeManager.makeCircle(inkOverlay, e.Stroke); Node circleNode = new Node(circle); graph.Add(circleNode); RecognizeWeight(); } //If the stroke is close and it is not enclosed in a node and is a rectangle, make a rectangular node else if (StrokeManager.isClosed(e.Stroke) && n == null && e.Stroke.PacketCount > StrokeManager.SMALLEST_N_SIZE && StrokeManager.FitsRectProperties(e.Stroke)) { Stroke rect = StrokeManager.makeRect(inkOverlay, e.Stroke); Node rectNode = new Node(rect); graph.Add(rectNode); RecognizeWeight(); } //if the stroke isn't closed, then it is an edge. else if (!StrokeManager.isClosed(e.Stroke)) { //Get all the nodes hit by this stroke and create edges for them Nodes edgeNodes = StrokeManager.ifEdgeGetNodes(e.Stroke, graph); if (edgeNodes != null && !StrokeManager.isScratchOut(e.Stroke)) { for (int i = 0; i < edgeNodes.Length() - 1; i++) { if (!Edge.hasEdge(edgeNodes[i], edgeNodes[i + 1])) { Edge edge = new Edge(edgeNodes[i], edgeNodes[i + 1], inkOverlay); graph.Add(edge); } } } else if (StrokeManager.isScratchOut(e.Stroke)) { ArrayList objs = StrokeManager.HitObjects(e.Stroke, graph); for (int i = 0; i < objs.Count; i++) { graph.Remove(objs[i]); } } RecognizeWeight(); } else { //if all of the above fails, then the stroke is considered for edge weights Edge hitEdge = StrokeManager.HitEdgeTest(e.Stroke, graph); if (hitEdge != null) { /* if the edge hit is the same as the previous one, * accumulate strokes for it before recognizing, * if it's a different edge, then recognize and add this * stroke to the new edge. */ if (prevEdgeHit == null) { prevEdgeHit = hitEdge; } if (hitEdge.Equals(prevEdgeHit)) { myRecognizer.Strokes.Add(StrokeManager.CopyStroke(e.Stroke)); } else { RecognizeWeight(); prevEdgeHit = hitEdge; myRecognizer.Strokes.Add(StrokeManager.CopyStroke(e.Stroke)); } } } e.Stroke.Ink.DeleteStroke(e.Stroke); Invalidate(); }