public override Gate CreateUserInstance() { Gates.IOGates.Comment cmt = _gate as Gates.IOGates.Comment; Comment c = new Comment(); ((Gates.IOGates.Comment)c.AbGate).Value = cmt.Value; return(c); }
public Comment(Gates.IOGates.Comment cmt) : base(cmt, new TerminalID[0]) { ph = new Path(); ph.Stroke = Brushes.Black; ph.StrokeThickness = 2; ph.Fill = Brushes.White; ph.Margin = new System.Windows.Thickness(15); myCanvas.Children.Add(ph); nm = new TextBox(); nm.Text = cmt.Value; nm.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; nm.VerticalAlignment = System.Windows.VerticalAlignment.Center; nm.Margin = new System.Windows.Thickness(20); nm.Width = this.Width - 40; nm.Height = this.Height - 40; nm.BorderThickness = new Thickness(0); myCanvas.Children.Add(nm); nm.TextChanged += (sender, e) => { cmt.Value = nm.Text; }; nm.LostFocus += (sender, e) => { // because I don't want to create an undo event // for every single keypress! if (UndoProvider != null) { UndoProvider.Add(new UndoRedo.ChangeUserText(this, prevcmt, nm.Text, txt => { cmt.Value = txt; })); } prevcmt = nm.Text; }; nm.GotFocus += (sender, e) => { if (MyGateCanvas != null) { MyGateCanvas.ClearSelection(); } }; cmt.PropertyChanged += (sender, e) => { if (e.PropertyName == "Value") { ResizeDueToName(); } }; ResizeDueToName(); }
private void ResizeDueToName() { Gates.IOGates.Comment cmt = _gate as Gates.IOGates.Comment; FormattedText ft = new FormattedText(cmt.Value, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface(nm.FontFamily, nm.FontStyle, nm.FontWeight, nm.FontStretch), nm.FontSize, nm.Foreground); // I would assume 40 b/c that is the total below // for diff between label width and gate width // but it is not enough // hacking it this.Width = Math.Max(64, ft.Width + 50); string path = "M0,0 "; for (int i = 20; i < this.Width - 20; i += 9) { path += "a 5,5 45 1 1 9,0 "; } path += "a 5,5 45 1 1 9,0 "; for (int i = 20; i < this.Height - 20; i += 9) { path += "a 5,5 45 1 1 0,9 "; } path += "a 5,5 45 1 1 0,9 "; for (int i = 20; i < this.Width - 20; i += 9) { path += "a 5,5 45 1 1 -9,0 "; } path += "a 5,5 45 1 1 -9,0 "; for (int i = 20; i < this.Height - 20; i += 9) { path += "a 5,5 45 1 1 0,-9 "; } path += "a 5,5 45 1 1 0,-9 "; ph.Data = StreamGeometry.Parse(path); nm.Text = cmt.Value; nm.Width = this.Width - 40; nm.Height = this.Height - 40; }
private Gates.AbstractGate CreateGate(XElement gate) { int numInputs = 2; // default for variable input gates if (gate.Attribute("NumInputs") != null) numInputs = int.Parse(gate.Attribute("NumInputs").Value); switch (gate.Attribute("Type").Value) { case "And": return new Gates.BasicGates.And(numInputs); case "Not": return new Gates.BasicGates.Not(); case "Or": return new Gates.BasicGates.Or(numInputs); case "Nand": return new Gates.BasicGates.Nand(numInputs); case "Nor": return new Gates.BasicGates.Nor(numInputs); case "Xor": return new Gates.BasicGates.Xor(); case "Xnor": return new Gates.BasicGates.Xnor(); case "Buffer": return new Gates.BasicGates.Buffer(); case "UserInput": Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); ui.SetName(gate.Attribute("Name").Value); return ui; case "UserOutput": Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo.SetName(gate.Attribute("Name").Value); return uo; case "NumericInput": Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value)); ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); ni.Value = gate.Attribute("Value").Value; return ni; case "NumericOutput": Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value)); no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); return no; case "Clock": Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value)); return clk; case "IC": // check if this ic has been renamed string cname = gate.Attribute("Name").Value; // check first if we need to rename if (UpdateICNames.ContainsKey(cname)) cname = UpdateICNames[cname]; return icl.GetIC(cname).AbGate.Clone(); case "Comment": Gates.IOGates.Comment cmt = new Gates.IOGates.Comment(); cmt.Value = gate.Element("Comment").Value; return cmt; } throw new ArgumentException("unknown gate"); }
//Modified method from CircuitXML.CreateGate Method private Gates.AbstractGate CreateGate(XElement gate) { int numInputs = 2; // default for variable input gates if (gate.Attribute("NumInputs") != null) numInputs = int.Parse(gate.Attribute("NumInputs").Value); switch (gate.Attribute("Type").Value) { case "And": return new Gates.BasicGates.And(numInputs); case "Not": return new Gates.BasicGates.Not(); case "Or": return new Gates.BasicGates.Or(numInputs); case "Nand": return new Gates.BasicGates.Nand(numInputs); case "Nor": return new Gates.BasicGates.Nor(numInputs); case "Xor": return new Gates.BasicGates.Xor(); case "Xnor": return new Gates.BasicGates.Xnor(); case "Buffer": return new Gates.BasicGates.Buffer(); case "UserInput": Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); ui.SetName(gate.Attribute("Name").Value); return ui; case "UserOutput": Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo.SetName(gate.Attribute("Name").Value); return uo; case "NumericInput": Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value)); ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); ni.Value = gate.Attribute("Value").Value; return ni; case "NumericOutput": Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value)); no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); return no; case "Clock": Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value)); return clk; case "Comment": Gates.IOGates.Comment cmt = new Gates.IOGates.Comment(); cmt.Value = gate.Element("Comment").Value; return cmt; } throw new ArgumentException("unknown gate"); }
private Gates.AbstractGate CreateGate(XElement gate) { int numInputs = 2; // default for variable input gates if (gate.Attribute("NumInputs") != null) { numInputs = int.Parse(gate.Attribute("NumInputs").Value); } switch (gate.Attribute("Type").Value) { case "And": return(new Gates.BasicGates.And(numInputs)); case "Not": return(new Gates.BasicGates.Not()); case "Or": return(new Gates.BasicGates.Or(numInputs)); case "Nand": return(new Gates.BasicGates.Nand(numInputs)); case "Nor": return(new Gates.BasicGates.Nor(numInputs)); case "Xor": return(new Gates.BasicGates.Xor()); case "Xnor": return(new Gates.BasicGates.Xnor()); case "Buffer": return(new Gates.BasicGates.Buffer()); case "UserInput": Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); ui.SetName(gate.Attribute("Name").Value); return(ui); case "UserOutput": Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo.SetName(gate.Attribute("Name").Value); return(uo); case "NumericInput": Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value)); ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation) int.Parse(gate.Attribute("SelRep").Value); ni.Value = gate.Attribute("Value").Value; return(ni); case "NumericOutput": Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value)); no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation) int.Parse(gate.Attribute("SelRep").Value); return(no); case "Clock": Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value)); return(clk); case "IC": // check if this ic has been renamed string cname = gate.Attribute("Name").Value; // check first if we need to rename if (UpdateICNames.ContainsKey(cname)) { cname = UpdateICNames[cname]; } return(icl.GetIC(cname).AbGate.Clone()); case "Comment": Gates.IOGates.Comment cmt = new Gates.IOGates.Comment(); cmt.Value = gate.Element("Comment").Value; return(cmt); } throw new ArgumentException("unknown gate"); }