public void circuitInkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) { CurrentStroke = e.Stroke; if (!circuitInkCanvas.Strokes.Contains(e.Stroke)) { circuitInkCanvas.Strokes.Add(e.Stroke); } #region Flick Detection //Flick Gesture TimeSpan timespan = DateTime.Now - _stylusDownTime; StrokeInfo stroke = new StrokeInfo(CurrentStroke, timespan); //Real Analysis if (StrokeAnalyzer.Instance.IsFlick(stroke) && 1 == 0) { FlickDirections direction = StrokeAnalyzer.Instance.DetectFlickDirection(stroke); StylusPoint PointA = stroke.StartPoint; StylusPoint PointB = stroke.EndPoint; AnimateArrowInFlickDirection(PointA.X, PointA.Y, PointB.X, PointB.Y); //Throw one gate xaml on the canvas Gate newGate = null; switch (direction) { case FlickDirections.UpLeft: newGate = new UserOutput(); break; case FlickDirections.DownLeft: newGate = new Xor(); //OR break; case FlickDirections.Down: newGate = new And(); //AND break; case FlickDirections.DownRight: //NOT newGate = new Not(); break; case FlickDirections.Up: //INPUT newGate = new Or(); break; case FlickDirections.UpRight: //OUTPUT newGate = new UserInput(); break; } //GateLocation location = new GateLocation(); //Heuristic //BO KANG?? Point temp = new Point(PointA.X - 30, PointA.Y - 30); this.AddGate(newGate, new GateLocation(this.GetNearestSnapTo(this.TranslateScrolledPoint(temp)))); //this.AddGate(newGate, location); this.circuitInkCanvas.UpdateLayout(); this.circuitInkCanvas.Strokes.Remove(CurrentStroke); } #endregion /* check for drag Gate Stroke*/ if (onGateStroke) { circuitInkCanvas.Strokes.Remove(e.Stroke); return; } /*check for draw wire stroke*/ if(onWireStroke) { circuitInkCanvas.Strokes.Remove(e.Stroke); onWireStroke = false; return; }else { if(onWireMoveStroke) { circuitInkCanvas.Strokes.Remove(e.Stroke); onWireMoveStroke = false; return; } } //Debug.WriteLine("Stroke Bound Percentage is " + stroke.BoundPercentage); /* Test if the current stroke is wire connect stroke */ if (stroke.BoundPercentage > 10) { return; } //Debug.WriteLine("Stroke BoundPercentage is " + stroke.BoundPercentage.ToString()); /* check for scribble delete */ if (ScribbleDelete(e.Stroke)) return; }
public void AddGate(Gates.AbstractGate gate, GateLocation pos) { // maybe we could use extension methods // to add a method to create a UIGate for each AbstractGate? Gate uigate; if (gate is Gates.BasicGates.And) { uigate = new UIGates.And((Gates.BasicGates.And)gate); } else if (gate is Gates.BasicGates.Not) { uigate = new UIGates.Not((Gates.BasicGates.Not)gate); } else if (gate is Gates.BasicGates.Or) { uigate = new UIGates.Or((Gates.BasicGates.Or)gate); } else if (gate is Gates.BasicGates.Nand) { uigate = new UIGates.Nand((Gates.BasicGates.Nand)gate); } else if (gate is Gates.BasicGates.Nor) { uigate = new UIGates.Nor((Gates.BasicGates.Nor)gate); } else if (gate is Gates.BasicGates.Xor) { uigate = new UIGates.Xor((Gates.BasicGates.Xor)gate); } else if (gate is Gates.BasicGates.Xnor) { uigate = new UIGates.Xnor((Gates.BasicGates.Xnor)gate); } else if (gate is Gates.BasicGates.Buffer) { uigate = new UIGates.Buffer((Gates.BasicGates.Buffer)gate); } else if (gate is Gates.IOGates.UserInput) { uigate = new UIGates.UserInput((Gates.IOGates.UserInput)gate); } else if (gate is Gates.IOGates.UserOutput) { uigate = new UIGates.UserOutput((Gates.IOGates.UserOutput)gate); } else if (gate is Gates.IOGates.AbstractNumeric) { uigate = new UIGates.Numeric((Gates.IOGates.AbstractNumeric)gate); } else if (gate is Gates.IOGates.Clock) { uigate = new UIGates.Clock((Gates.IOGates.Clock)gate); } else if (gate is Gates.IOGates.Comment) { uigate = new UIGates.Comment((Gates.IOGates.Comment)gate); } else if (gate is Gates.IC) { uigate = UIGates.IC.CreateFromTemplate((Gates.IC)gate, icl.GetIC(gate.Name)); } else throw new ArgumentException("gate not of known subclass"); AddGate(uigate, pos); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.UserControlToolTipXY = ((System.Windows.Media.TranslateTransform)(target)); return; case 2: this.pieMenu = ((LogicPad2.Diagram.PieMenu)(target)); return; case 3: this.tbNot = ((LogicPad2.Diagram.UIGates.Not)(target)); return; case 4: this.tbAnd = ((LogicPad2.Diagram.UIGates.And)(target)); return; case 5: this.tbXor = ((LogicPad2.Diagram.UIGates.Xor)(target)); return; case 6: this.tbUserOutput = ((LogicPad2.Diagram.UIGates.UserOutput)(target)); return; case 7: this.tbOr = ((LogicPad2.Diagram.UIGates.Or)(target)); return; case 8: this.tbUserInput = ((LogicPad2.Diagram.UIGates.UserInput)(target)); return; } this._contentLoaded = true; }