private void Image_MouseEnter(object sender, MouseEventArgs e) { ICBuilder x = new ICBuilder(gateCanvas.Circuit, g => { Gate fg = gateCanvas.FindGate(g); return(new GateLocation() { X = fg.Margin.Left, Y = fg.Margin.Top, Width = fg.Width, Height = fg.Height, Angle = ((RotateTransform)fg.RenderTransform).Angle }); }); var pRect = x.createCenter(); var adj_pRect = pRect; ICBounds_Line1 = new Line(); ICBounds_Line1.Stroke = System.Windows.Media.Brushes.Green; ICBounds_Line1.Opacity = 0.5; ICBounds_Line1.X1 = adj_pRect.Left; ICBounds_Line1.Y1 = adj_pRect.Top; ICBounds_Line1.X2 = adj_pRect.Right; ICBounds_Line1.Y2 = adj_pRect.Bottom; ICBounds_Line1.StrokeThickness = 2; gateCanvas.GC.Children.Add(ICBounds_Line1); ICBounds_Line2 = new Line(); ICBounds_Line2.Stroke = System.Windows.Media.Brushes.Green; ICBounds_Line2.Opacity = 0.5; ICBounds_Line2.X1 = adj_pRect.Right; ICBounds_Line2.Y1 = adj_pRect.Top; ICBounds_Line2.X2 = adj_pRect.Left; ICBounds_Line2.Y2 = adj_pRect.Bottom; ICBounds_Line2.StrokeThickness = 2; gateCanvas.GC.Children.Add(ICBounds_Line2); ICBounds = new Rectangle(); ICBounds.Stroke = System.Windows.Media.Brushes.Green; ICBounds.Opacity = 0.5; ICBounds.Width = adj_pRect.Width; ICBounds.Height = adj_pRect.Height; ICBounds.Margin = new Thickness() { Left = adj_pRect.Left, Top = adj_pRect.Top }; ICBounds.StrokeThickness = 2; gateCanvas.GC.Children.Add(ICBounds); }
/// <summary> /// Given an XML circuit representation, create an IC. /// The local IC List will be used to deference any nested ICs. /// </summary> /// <param name="circuit"></param> /// <returns></returns> public UIGates.IC LoadCircuit(XElement circuit) { Gates.Circuit c = new Gates.Circuit(); Dictionary <int, Gates.AbstractGate> gid = new Dictionary <int, Gates.AbstractGate>(); Dictionary <Gates.AbstractGate, GateLocation> gpt = new Dictionary <Gates.AbstractGate, GateLocation>(); foreach (XElement gate in circuit.Element("Gates").Elements()) { Gates.AbstractGate abgate = CreateGate(gate); c.Add(abgate); gid.Add(int.Parse(gate.Attribute("ID").Value), abgate); double x = double.Parse(gate.Element("Point").Attribute("X").Value); double y = double.Parse(gate.Element("Point").Attribute("Y").Value); double angle = double.Parse(gate.Element("Point").Attribute("Angle").Value); gpt.Add(abgate, new GateLocation() { X = x, Y = y, Angle = angle }); } foreach (XElement wire in circuit.Element("Wires").Elements()) { c[CreateTerminal(gid, wire.Element("To"))] = CreateTerminal(gid, wire.Element("From")); } ICBuilder icb = new ICBuilder(c, (Gates.AbstractGate abgate) => { return(gpt[abgate]); }); // for top level circuit, must not create terminals // otherwise input/output overridden if (circuit.Attribute("Name") != null) { string cname = circuit.Attribute("Name").Value; // check first if we need to rename if (UpdateICNames.ContainsKey(cname)) { cname = UpdateICNames[cname]; } return(icb.CreateIC(cname)); } else { return(icb.CreateNonTerminaledIC("")); } }
/// <summary> /// Create an IC based on the circuit in this gate. The position of the gates /// will be used to setup the location hints. If desired, a subset of the gates /// may be used to create the IC. /// </summary> /// <param name="name"></param> /// <param name="selectedOnly"></param> /// <returns></returns> public UIGates.IC CreateIC(string name, SELECTED_GATES selectedOnly) { Gates.Circuit nc; Dictionary<int, int> idxmap = null; if ( (selected.Count > 1 && selectedOnly == SELECTED_GATES.SELECTED_IF_TWO_OR_MORE) || selectedOnly == SELECTED_GATES.SELECTED) nc = c.Clone(selected.ToList().ConvertAll(g => g.AbGate), out idxmap); else nc = c.Clone(); ICBuilder icb = new ICBuilder(nc, new ICBuilder.GatePosition( gate => { int idx = nc.IndexOf(gate); if (idxmap != null) { foreach (KeyValuePair<int, int> kv in idxmap) if (kv.Value == idx) { idx = kv.Key; break; }// this makes me want to cry // there must be a better way to look up by value // because the value is the new circuit idx // and the key is the old circuit idx // don't just reverse it on create // we use it the other way too } Gates.AbstractGate oldgate = c[idx]; return new GateLocation(gates[oldgate].Margin.Left, gates[oldgate].Margin.Top, ((RotateTransform)gates[oldgate].RenderTransform).Angle); })); return icb.CreateIC(name); }
/// <summary> /// Given an XML circuit representation, create an IC. /// The local IC List will be used to deference any nested ICs. /// </summary> /// <param name="circuit"></param> /// <returns></returns> public UIGates.IC LoadCircuit(XElement circuit) { Gates.Circuit c = new Gates.Circuit(); Dictionary<int, Gates.AbstractGate> gid = new Dictionary<int, Gates.AbstractGate>(); Dictionary<Gates.AbstractGate, GateLocation> gpt = new Dictionary<Gates.AbstractGate, GateLocation>(); foreach (XElement gate in circuit.Element("Gates").Elements()) { Gates.AbstractGate abgate = CreateGate(gate); c.Add(abgate); gid.Add(int.Parse(gate.Attribute("ID").Value), abgate); double x = double.Parse(gate.Element("Point").Attribute("X").Value); double y = double.Parse(gate.Element("Point").Attribute("Y").Value); double angle = double.Parse(gate.Element("Point").Attribute("Angle").Value); gpt.Add(abgate, new GateLocation(x, y, angle)); } foreach (XElement wire in circuit.Element("Wires").Elements()) { c[CreateTerminal(gid, wire.Element("To"))] = CreateTerminal(gid, wire.Element("From")); } ICBuilder icb = new ICBuilder(c, (Gates.AbstractGate abgate) => { return gpt[abgate]; }); // for top level circuit, must not create terminals // otherwise input/output overridden if (circuit.Attribute("Name") != null) { string cname = circuit.Attribute("Name").Value; // check first if we need to rename if (UpdateICNames.ContainsKey(cname)) cname = UpdateICNames[cname]; return icb.CreateIC(cname); } else return icb.CreateNonTerminaledIC(""); }