/// <summary> /// Load a Stroke with a corresponding substroke. /// Precondition: Substroke is in the Sketch/FeatureSketch. /// Postcondition: The stroke's in our bookkeeping data structures. /// </summary> /// <param name="inkStroke">The Stroke to add</param> public void AddInkStrokeWithSubstroke(System.Windows.Ink.Stroke inkStroke, Sketch.Substroke substroke) { // Format the inkStroke inkStroke.AddPropertyData(dtGuid, (ulong)DateTime.Now.ToFileTime()); String strokeId = System.Guid.NewGuid().ToString(); inkStroke.AddPropertyData(idGuid, strokeId); // Add it to the data structures (InkCanvas last) ink2sketchStr.Add(strokeId, substroke.XmlAttrs.Id); sketchStr2ink.Add(substroke.XmlAttrs.Id, strokeId); substrokeIdMap.Add(substroke.XmlAttrs.Id, substroke); mInkCanvas.Strokes.Add(inkStroke); }
/// <summary> /// Adds a Stroke to our internal data structures - the Sketch and FeatureSketch /// </summary> /// Precondition: The InkStroke is not in the InkCanvas's collection of strokes. /// Postcondition: The InkStroke has been added to the InkCanvas, Sketch's list of /// Strokes, Substrokes, and FeatureSketch. /// <param name="inkStroke"></param> public void AddStroke(System.Windows.Ink.Stroke inkStroke) { if (mInkCanvas.Strokes.Contains(inkStroke)) { throw new Exception("adding a stroke to the InkCanvasSketch, but it was already there!"); } // Format the stroke inkStroke.AddPropertyData(dtGuid, (ulong)DateTime.Now.ToFileTime()); string strokeId = Guid.NewGuid().ToString(); inkStroke.AddPropertyData(idGuid, strokeId); // Update the dictionaries Sketch.Stroke sketchStroke = new Sketch.Stroke(inkStroke, dtGuid, SAMPLE_RATE); ink2sketchStr.Add(strokeId, sketchStroke.Substrokes[0].XmlAttrs.Id); sketchStr2ink.Add(sketchStroke.Substrokes[0].Id, strokeId); substrokeIdMap.Add(sketchStroke.Substrokes[0].Id, sketchStroke.Substrokes[0]); // Add it to the relevant data structures (InkCanvas last.) mFeatureSketch.AddStroke(sketchStroke); mInkCanvas.Strokes.Add(inkStroke); }
private void inkCScribble_MouseUp(object sender, MouseButtonEventArgs e) { if (inkCScribble.Strokes.Count > 0) { currentStroke = inkCScribble.Strokes[inkCScribble.Strokes.Count - 1]; currentStroke.AddPropertyData(strokeObjectPropertyID, Guid.NewGuid().ToString()); } if (CurrentTool == ActiveReadingTool.Pen) //add strokes to Document (when strokes are close to each other cluster them in one strokeCollection) { foreach (ScribbleCollection collection in ActualDocument[ActualPage].ScribblingCollections) { if (Distance(currentStroke.GetBounds().TopLeft, new System.Windows.Point(collection.X, collection.Y)) < defaultClusterStrokeDistanceCm || Distance(currentStroke.GetBounds().BottomRight, new System.Windows.Point(collection.X, collection.Y)) < defaultClusterStrokeDistanceCm) { if (!collection.Scribbles.Contains(currentStroke)) { collection.Scribbles.Add(currentStroke); currentStroke.AddPropertyData(strokeCollectionPropertyID, collection.ID.ToString()); //creates a point for undo for this action PushToUndoStack(ActiveReadingTool.Pen, collection, currentStroke); } return; } } //if stroke is not close to another one, create new collection ScribbleCollection newCollection = new ScribbleCollection(); newCollection.Scribbles = new StrokeCollection(); newCollection.Scribbles.Add(currentStroke); currentStroke.AddPropertyData(strokeCollectionPropertyID, newCollection.ID.ToString()); ActualDocument[ActualPage].ScribblingCollections.Add(newCollection); //creates a point for undo for this action PushToUndoStack(ActiveReadingTool.Pen, newCollection); } else if (CurrentTool == ActiveReadingTool.Eraser) inkCScribble.Strokes.Remove(currentStroke); //remove red eraser stroke }