Пример #1
0
        public void SetView(LayoutModel value, LayoutSimulation layoutSim)
        {
            LayoutModel      oldLayout = this.Layout;
            LayoutSimulation oldSim    = this.LayoutSim;
            bool             updated   = false;

            if (value != oldLayout)
            {
                this.Layout    = value;
                this.LayoutSim = layoutSim;
                repainter.SetSimulationModel(layoutSim.SimulationModel);
                WiringPoints     = new LayoutWiringPoints(value);
                hidden           = new HashSet <Component>();
                this.NullGesture = new GestureNull(this);
                if (oldLayout != null)
                {
                    oldLayout.LayoutModifiedEvent -= LayoutUpdated;
                }
                if (value != null)
                {
                    value.LayoutModifiedEvent += LayoutUpdated;
                }
                updated = true;
            }
            else if (oldSim != layoutSim)
            {
                updated        = true;
                this.LayoutSim = layoutSim;
                repainter.SetSimulationModel(layoutSim.SimulationModel);
            }
            if (updated)
            {
                RepaintCanvas();
            }
        }
Пример #2
0
 public void SetView(ProjectModule module, LayoutSimulation sim)
 {
     if (module.Implementation is LayoutModel)
     {
         LayoutModel      layoutModel = (LayoutModel)module.Implementation;
         LayoutSimulation layoutSim;
         if (sim != null)
         {
             layoutSim = sim;
             moduleSimulations[module] = sim;
         }
         else if (!moduleSimulations.TryGetValue(module, out layoutSim))
         {
             SimulationModel simModel = new SimulationModel();
             layoutSim = new LayoutSimulation(simModel, layoutModel);
             moduleSimulations[module] = layoutSim;
         }
         SimulationThread newThread = new SimulationThread(layoutSim.SimulationModel);
         newThread.Start();
         SimulationThread oldThread = simThread;
         simThread = newThread;
         if (oldThread != null)
         {
             oldThread.RequestStop();
         }
         this.CurrentModule = module;
         ToolboxModel.UpdateCurrent(module);
         LayoutCanvas.SetView(layoutModel, layoutSim);
     }
     else
     {
         throw new InvalidOperationException("cannot view this module type");
     }
 }
Пример #3
0
 internal void RequestView(ProjectModule module, LayoutSimulation sim)
 {
     callback.SetView(module, sim);
 }
Пример #4
0
        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);
                        }
                    }
                }
            }
        }
Пример #5
0
 public void RequestView(object module, object sim)
 {
     viewRequested  = module as ProjectModule;
     viewSimulation = sim as LayoutSimulation;
 }