示例#1
0
        public void Paint(IPaintbrush pb)
        {
            Location          cur = current;
            IComponentPainter ip  = new ComponentPainter(pb, new DummyInstanceState(masterInstance));

            pb.TranslateCoordinates(cur.X, cur.Y);
            if (currentValid)
            {
                pb.Color = Constants.COLOR_GHOST;
            }
            else
            {
                pb.Color = Constants.COLOR_DEAD;
            }
            master.Paint(ip);
        }
        protected override void PaintModel(IPaintbrush pb)
        {
            repainter.NotifyRepainted();
            LayoutModel      layoutModel = this.Layout;
            LayoutSimulation layoutSim   = this.LayoutSim;

            if (layoutModel == null)
            {
                return;
            }
            if (layoutSim.LayoutModel != layoutModel)
            {
                Console.Error.WriteLine("layoutSim and layoutModel do not match");
                return;
            }
            ComponentPainter  ip       = new ComponentPainter(pb, null);
            bool              noHidden = hidden.Count == 0;
            Transaction       xn       = new Transaction();
            ISimulationAccess sim      = xn.RequestReadAccess(layoutSim.SimulationModel);
            ILayoutAccess     layout   = xn.RequestReadAccess(layoutModel);

            using (xn.Start()) {
                using (IPaintbrush pbSub = pb.Create()) {
                    pbSub.StrokeWidth = Constants.WIRE_WIDTH;
                    foreach (WireSegment wire in layout.Wires)
                    {
                        Value val0 = layoutSim.GetValueAt(layout, sim, wire.End0);
                        pbSub.Color = Constants.GetColorFor(val0);
                        pbSub.StrokeLine(wire.End0.X, wire.End0.Y, wire.End1.X, wire.End1.Y);
                    }
                }

                InstanceState state = new InstanceState(sim, null);
                ip.InstanceState = state;
                foreach (Component component in layout.Components)
                {
                    if (noHidden || !hidden.Contains(component))
                    {
                        Location loc = component.GetLocation(layout);
                        using (IPaintbrush pbSub = pb.Create()) {
                            pbSub.TranslateCoordinates(loc.X, loc.Y);
                            ip.Paintbrush  = pbSub;
                            state.Instance = layoutSim.GetInstance(layout, component);
                            component.Paint(ip);
                        }
                    }
                }

                using (IPaintbrush pbSub = pb.Create()) {
                    foreach (Location loc in WiringPoints.SolderPoints)
                    {
                        Value val = layoutSim.GetValueAt(layout, sim, loc);
                        pbSub.Color = Constants.GetColorFor(val);
                        if (noHidden || WiringPoints.IsSolderPoint(loc, hidden))
                        {
                            pbSub.FillCircle(loc.X, loc.Y, Constants.SOLDER_RADIUS);
                        }
                    }
                }
            }
        }