/// <summary> /// Unsubscribes from SketchPanel /// <see cref="SketchPanelLib.SketchPanelListener.UnSubscribeToPanel()"/> /// </summary> public virtual void UnsubscribeFromPanel() { if (!subscribed || sketchPanel == null) { return; } subscribed = false; // Release SketchPanel selection Events sketchPanel.InkCanvas.SelectionChanged -= new EventHandler(InkCanvas_SelectionChanged); sketchPanel.InkCanvas.SelectionMoved -= new EventHandler(InkCanvas_SelectionChanged); sketchPanel.InkCanvas.SelectionResized -= new EventHandler(InkCanvas_SelectionChanged); sketchPanel.InkCanvas.StrokeCollected -= new InkCanvasStrokeCollectedEventHandler(InkCanvas_StrokeCollected); // Mouse and stylus events sketchPanel.InkCanvas.StylusDown -= new System.Windows.Input.StylusDownEventHandler(inkCanvas_StylusDown); sketchPanel.InkCanvas.StylusUp -= new System.Windows.Input.StylusEventHandler(inkCanvas_StylusUp); sketchPanel.InkCanvas.StylusInAirMove -= new System.Windows.Input.StylusEventHandler(inkCanvas_StylusInAirMove); sketchPanel.InkCanvas.StylusOutOfRange -= new System.Windows.Input.StylusEventHandler(inkCanvas_StylusOutOfRange); sketchPanel.InkCanvas.StylusButtonDown -= new StylusButtonEventHandler(InkCanvas_StylusButtonDown); sketchPanel.InkCanvas.StylusButtonUp -= new StylusButtonEventHandler(InkCanvas_StylusButtonUp); editMenu.InkRerecognized -= new EditMenu.InkRerecognizedEventHandler(editMenu_InkRerecognized); editMenu.regroup -= new EditMenu.RegroupEventHandler(Regroup); editMenu.LearnFromCorrection -= new EditMenu.LearningEventHandler(editMenu_LearnFromCorrection); // Remove InkCanvas children sketchPanel.InkCanvas.Children.Remove(selectionPopup); sketchPanel.InkCanvas.Children.Remove(editPopup); sketchPanel.InkCanvas.Children.Remove(labelPopup); //sketchPanel.InkCanvas.Children.Remove(editMenu.labelMenu); editMenu.removeMenu(); if (editMenu.labelMenuIsOpen) { this.editMenu.closeLabelMenu(); } // Clear selection and unsubscribe from the panel if (selector.subscribed) { selector.UnsubscribeFromPanel(); } sketchPanel.EnableDrawing(); selectionActive = false; }
/// <summary> /// Groups selected strokes. /// </summary> public void Group() { closeLabelMenu(); Group(new ShapeType().Name, sketchPanel.InkCanvas.GetSelectedStrokes()); sketchPanel.EnableDrawing(); }
/// <summary> /// Clear selection and unsubscribe any events /// </summary> public virtual void UnsubscribeFromPanel() { if (sketchPanel == null) { return; } sketchPanel.EnableDrawing(); if (!subscribed) { return; } subscribed = false; Clear(); sketchPanel.InkCanvas.StylusDown -= new System.Windows.Input.StylusDownEventHandler(InkCanvas_StylusDown); sketchPanel.InkCanvas.StylusUp -= new System.Windows.Input.StylusEventHandler(InkCanvas_StylusUp); sketchPanel.InkCanvas.StylusLeave -= new System.Windows.Input.StylusEventHandler(InkCanvas_StylusUp); selectionMade = false; }
/// <summary> /// Groups selected strokes. /// </summary> public void Group() { Group(new ShapeType(), sketchPanel.InkCanvas.GetSelectedStrokes()); sketchPanel.EnableDrawing(); }
/// <summary> /// Applies a label to a group of substrokes. /// </summary> public override bool Execute() { // Get the sketch we are working with Sketch.Sketch sketch = sketchPanel.InkSketch.Sketch; // Accumulate the list of substrokes that are about to be relabeled List <Sketch.Substroke> substrokes = new List <Sketch.Substroke>(); foreach (Stroke stroke in inkStrokes) { // Find the corresponding substroke in the sketch Sketch.Substroke sub = sketchPanel.InkSketch.GetSketchSubstrokeByInk(stroke); // Add it to the growing list substrokes.Add(sub); } // Make a new shape out of these substrokes Domain.ShapeType theType = Domain.LogicDomain.getType(label); List <Sketch.Shape> shapesToRegroup; labeledShape = sketch.MakeNewShapeFromSubstrokes(out shapesToRegroup, substrokes, theType, 1.0); if (userSpecifiedLabel) { // Updates the orientation for the sake of the ghost gate if (labeledShape.Type.Classification == LogicDomain.GATE_CLASS) { RecognitionInterfaces.Orienter orienter = RecognitionManager.RecognitionPipeline.createDefaultOrienter(); orienter.orient(labeledShape, sketchPanel.InkSketch.FeatureSketch); } // Update the shape name for text else if (labeledShape.Type.Classification == LogicDomain.TEXT_CLASS) { RecognitionInterfaces.Recognizer recognizer = new Recognizers.TextRecognizer(); recognizer.recognize(labeledShape, sketchPanel.InkSketch.FeatureSketch); } } // Record the fact that user specified this grouping or label, // so we don't accidentally change it in the future. labeledShape.AlreadyGrouped = userSpecifiedGroup; if (label != new ShapeType().Name) { labeledShape.UserLabeled = userSpecifiedLabel; // Also, update the recognition to take this into account if (userSpecifiedLabel && ErrorCorrected != null) { ErrorCorrected(labeledShape); } } // Fun Fix // Problem description: // Suppose you draw wire -> notgate -> wire // --------|>o-------- // Then you label the notgate as a wire, so the // whole ensamble becomes a single wire. Then you // relabel it as a notgate again. The two wires // which *were* distinct are still part of the same // wire mesh. // Problem solution: // Here, when you apply a label to a group of // substrokes, we will "explode" all the wire shapes // that were changed (break them into single-substroke // shapes). We expect that they will be reconnected // later. List <Sketch.Shape> newShapesToRegroup = new List <Sketch.Shape>(shapesToRegroup); foreach (Sketch.Shape modifiedShape in shapesToRegroup) { if (Domain.LogicDomain.IsWire(modifiedShape.Type)) { List <Sketch.Shape> newShapes = sketch.ExplodeShape(modifiedShape); newShapesToRegroup.Remove(modifiedShape); newShapesToRegroup.AddRange(newShapes); } } shapesToRegroup = newShapesToRegroup; // Make sure the old connected shapes are updated with their // relationships to the newly labeled shape if (Regroup != null) { // Regroup everything so highlighting/labels are correctly updated // Ensures that the newly labeled shape's relationship to its // connected shapes are updated as well shapesToRegroup.Add(labeledShape); Regroup(new List <Sketch.Shape>(shapesToRegroup)); } sketchPanel.EnableDrawing(); return(true); }