/// <summary> /// Main constructor of the subcircuit window. Takes in a project that it will wrap into an inkcanvas sketch /// in order to display. /// </summary> /// <param name="subSketch"></param> public MainWindow(ref Sketch.Project subSketch) { try { InitializeComponent(); } catch (Exception ex) { // Log error System.Console.WriteLine(ex.InnerException.Message); //System.Console.WriteLine(ex.ListTrace); } // Set up notes panel this.subSketch = subSketch; WrapperSketch = new InkToSketchWPF.InkCanvasSketch(new InkCanvas()); WrapperSketch.project = subSketch; this.WrapperSketch.ClearButNotSketch(); // Makes the ink to display WrapperSketch.CreateInkStrokesFromSketch(); //Set up the ink holder this.inkCanvas = WrapperSketch.InkCanvas; this.inkCanvas.Height = dockPanel.Height; this.inkCanvas.Width = dockPanel.Width; //The dockPanel is in a view box, which means that it will scale (and scale its children) //to fit the screen. TextBlock helpText = new TextBlock(); helpText.Text = "You can click a sub-circuit if one exists to view it"; helpText.FontSize = 16; dockPanel.Children.Clear(); dockPanel.Children.Add(this.inkCanvas); this.inkCanvas.Children.Add(helpText); //Actually color the strokes on the inkcanvas according to the recognition //This is valid because only simulatable circuits can be viewed here foreach (System.Windows.Ink.Stroke inkStroke in this.inkCanvas.Strokes) { Sketch.Substroke substroke = (Sketch.Substroke)WrapperSketch.GetSketchSubstrokeByInk(inkStroke); Domain.ShapeType label = substroke.Type; Color color = label.Color; inkStroke.DrawingAttributes.Color = color; } //Draws the inkcanvas with the new colors this.WrapperSketch.InkCanvas.InvalidateVisual(); this.inkCanvas.UpdateLayout(); // Set Editing Modes inkCanvas.EditingMode = InkCanvasEditingMode.None; inkCanvas.EditingModeInverted = InkCanvasEditingMode.None; inkCanvas.StylusDown += new StylusDownEventHandler(inkCanvas_StylusDown); }
public void TestXMLConversion() { const string filename = "tmp.xml"; Domain.ShapeType testType = Domain.LogicDomain.AND; Sketch.Sketch sketch1 = Sketches.newValidSketch(); foreach (Sketch.Shape shape in sketch1.Shapes) { shape.Type = testType; } ConverterXML.SaveToXML writer = new ConverterXML.SaveToXML(sketch1); writer.WriteXML(filename); ConverterXML.ReadXML reader = new ConverterXML.ReadXML(filename); Sketch.Sketch sketch2 = reader.Sketch; sketch2.CheckConsistency(); Assert.IsTrue(sketch1.Equals(sketch2), "Original sketch is not equal to the loaded sketch"); Assert.IsTrue(sketch2.Equals(sketch1), "Loaded sketch is not equal to the original"); foreach (Sketch.Shape shape in sketch2.Shapes) { Assert.AreEqual(testType, shape.Type, "Shape types are not preserved across save/load"); } }
/// <summary> /// Colors Ink strokes in the parent SketchPanel using the domain. /// </summary> protected virtual void colorStrokes() { // Attempt to color all Ink strokes foreach (System.Windows.Ink.Stroke iStroke in sketchPanel.InkCanvas.Strokes) { // Get corresponding label Substroke sStroke = sketchPanel.InkSketch.GetSketchSubstrokeByInkId((String)iStroke.GetPropertyData(idGuid)); Domain.ShapeType label = sStroke.Type; //Console.WriteLine("String label: " + sStroke.FirstLabel+" Color: "+mDomain.GetColor(label)); // Color the stroke; if the stroke is not in the domain, then we // color the stroke black. iStroke.DrawingAttributes.Color = label.Color; } // Request repaint sketchPanel.InkCanvas.InvalidateVisual(); sketchPanel.InkCanvas.UpdateLayout(); }
/// <summary> /// Strokes to Group /// </summary> /// <param name="strokes"></param> private void Group(StrokeCollection strokes, string classification) { List <Sketch.Substroke> listSubstrokes = new List <Sketch.Substroke>(); Domain.ShapeType temporaryType = new Domain.ShapeType(); foreach (Stroke s in strokes) { Sketch.Substroke sub = sketchPanel.InkSketch.GetSketchSubstrokeByInk(s); sub.Classification = classification; listSubstrokes.Add(sub); s.DrawingAttributes.Color = (new Domain.ShapeType()).Color; } Sketch.Shape labelShape = sketchPanel.Sketch.AddLabel(listSubstrokes, temporaryType); labelShape.AlreadyGrouped = true; labelShape.AlreadyLabeled = false; GroupTogether(labelShape); }
public void ColorStrokesByType(List <Sketch.Substroke> substrokes) { if (!coloringOn) { ClearColors(); return; } if (this.panel.InkSketch.Sketch != null) { foreach (Sketch.Substroke substroke in substrokes) { Domain.ShapeType label = substroke.Type; Color color = label.Color; System.Windows.Ink.Stroke stroke = panel.InkSketch.GetInkStrokeBySubstroke(substroke); stroke.DrawingAttributes.Color = color; } panel.InkCanvas.InvalidateVisual(); panel.InkCanvas.UpdateLayout(); } }