예제 #1
0
 private void processSubprocess(UIElementCollection elements)
 {
     foreach (UIElement e in elements)
     {
         if (e is SubDiagram)
         {
             SubDiagram            sd         = e as SubDiagram;
             List <ConnectionLine> connectors = ConnectorFinder.find(elements, sd);
             foreach (ConnectionLine cl in connectors)
             {
                 processConnectionLine(cl, false);
             }
         }
     }
 }
예제 #2
0
        public void deleteEntity(UIEntity ent)
        {
            if (ent != null && !(ent is Port))
            {
                UndoRedoManager.putInUndoStack(ent);
                UndoRedoManager.clearRedoStack(ent);

                List <ConnectionLine> connectors = ConnectorFinder.find(currentCanvas.Children, ent);
                foreach (ConnectionLine c in connectors)
                {
                    BindingOperations.ClearBinding(c, ConnectionLine.SourceProperty);
                    BindingOperations.ClearBinding(c, ConnectionLine.DestinationProperty);
                    currentCanvas.Children.Remove(c);
                }

                ent.removeAll();
                currentCanvas.Children.Remove(ent);
                ModelChanged();
                propertiesPanel.Children.Clear();
            }
        }
예제 #3
0
        private void restoreConnectionLines(MainWindow mw)
        {
            List <ConnectionLine> connections = ConnectorFinder.find(owner.canvas.Children, owner);

            foreach (ConnectionLine cl in connections)
            {
                // can use ==, because it's same object instance
                UIEntity connectedTo = cl.SourcePort.Owner != owner ? cl.SourcePort.Owner : cl.DestinationPort.Owner;
                PortType srcPortType = cl.SourcePort.Owner != owner ? cl.SourcePort.PortType : cl.DestinationPort.PortType;
                PortType dstPortType = cl.SourcePort.Owner != owner ? cl.DestinationPort.PortType : cl.SourcePort.PortType;

                if (!(ParameterProccesor.newResource.GetType() == typeof(MaterialResource) && PortType.BOTTOM_RESOURCE.Equals(dstPortType)))
                {
                    ConnectionLine newCl = new ConnectionLine(owner.canvas);

                    newCl.SetBinding(ConnectionLine.SourceProperty, new Binding()
                    {
                        Source = connectedTo.findPort(srcPortType),
                        Path   = new PropertyPath(Port.AnchorPointProperty)
                    });
                    newCl.SetBinding(ConnectionLine.DestinationProperty, new Binding()
                    {
                        Source = ParameterProccesor.newResource.findPort(dstPortType),
                        Path   = new PropertyPath(Port.AnchorPointProperty)
                    });


                    newCl.MouseLeftButtonDown += mw.Shape_MouseLeftButtonDown;
                    newCl.MouseLeftButtonUp   += mw.Shape_MouseLeftButtonUp;

                    ZIndexUtil.setCorrectZIndex(newCl.canvas, newCl);

                    owner.canvas.Children.Add(newCl);
                }
            }
        }
예제 #4
0
        private void connectResourcesBetweenThemselves(UIElementCollection elements, sapr_sim.Figures.Resource resource)
        {
            List <ConnectionLine> connectors = ConnectorFinder.find(elements, resource);

            foreach (ConnectionLine con in connectors)
            {
                UIEntity worker     = null;
                UIEntity instrument = null;
                UIEntity material   = null;

                if (con.SourcePort != null)
                {
                    UIEntity src = con.SourcePort.Owner;
                    UIEntity dst = con.DestinationPort.Owner;
                    worker     = src is sapr_sim.Figures.WorkerResource ? src : dst is sapr_sim.Figures.WorkerResource ? dst : null;
                    instrument = src is sapr_sim.Figures.InstrumentResource ? src : dst is sapr_sim.Figures.InstrumentResource ? dst : null;
                    material   = src is sapr_sim.Figures.MaterialResource ? src : dst is sapr_sim.Figures.MaterialResource ? dst : null;

                    if (src is sapr_sim.Figures.WorkerResource && dst is sapr_sim.Figures.MaterialResource ||
                        dst is sapr_sim.Figures.WorkerResource && src is sapr_sim.Figures.MaterialResource)
                    {
                        if (worker != null && material != null)
                        {
                            Entities.WorkerResource   realWorker   = resMap[worker] as Entities.WorkerResource;
                            Entities.MaterialResource realMaterial = resMap[material] as Entities.MaterialResource;
                            if (!realWorker.materials.Contains(realMaterial))
                            {
                                realWorker.materials.Add(realMaterial);
                            }
                        }
                    }

                    if (src is sapr_sim.Figures.WorkerResource && dst is sapr_sim.Figures.InstrumentResource ||
                        dst is sapr_sim.Figures.WorkerResource && src is sapr_sim.Figures.InstrumentResource)
                    {
                        if (worker != null && instrument != null)
                        {
                            Entities.WorkerResource     realWorker     = resMap[worker] as Entities.WorkerResource;
                            Entities.InstrumentResource realInstrument = resMap[instrument] as Entities.InstrumentResource;
                            if (!realWorker.instruments.Contains(realInstrument))
                            {
                                realWorker.instruments.Add(realInstrument);
                            }
                        }
                    }

                    if (src is sapr_sim.Figures.InstrumentResource && dst is sapr_sim.Figures.MaterialResource ||
                        src is sapr_sim.Figures.MaterialResource && dst is sapr_sim.Figures.InstrumentResource)
                    {
                        if (instrument != null && material != null)
                        {
                            Entities.InstrumentResource realInstrument = resMap[instrument] as Entities.InstrumentResource;
                            Entities.MaterialResource   realMaterial   = resMap[material] as Entities.MaterialResource;
                            if (!realInstrument.materials.Contains(realMaterial))
                            {
                                realInstrument.materials.Add(realMaterial);
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
        private void processResource(UIElementCollection elements, sapr_sim.Figures.Resource resource)
        {
            List <ConnectionLine> connectors = ConnectorFinder.find(elements, resource);

            Entities.Resource res = null;
            if (resource is sapr_sim.Figures.WorkerResource)
            {
                sapr_sim.Figures.WorkerResource wr = resource as sapr_sim.Figures.WorkerResource;
                res = new Entities.WorkerResource()
                {
                    name       = wr.EntityName,
                    id         = wr.Id,
                    count      = wr.Count,
                    type       = Entities.ResourceType.WORKER,
                    efficiency = wr.Efficiency,
                    isShared   = wr.IsShared,
                    price      = wr.Price
                };
            }
            else if (resource is sapr_sim.Figures.InstrumentResource)
            {
                sapr_sim.Figures.InstrumentResource ir = resource as sapr_sim.Figures.InstrumentResource;
                res = new Entities.InstrumentResource()
                {
                    name     = ir.EntityName,
                    id       = ir.Id,
                    count    = ir.Count,
                    type     = Entities.ResourceType.INSTRUMENT,
                    isShared = ir.IsShared,
                    price    = ir.Price,
                    power    = ir.Power
                };
            }
            else if (resource is sapr_sim.Figures.MaterialResource)
            {
                sapr_sim.Figures.MaterialResource mr = resource as sapr_sim.Figures.MaterialResource;
                res = new Entities.MaterialResource()
                {
                    name     = mr.EntityName,
                    id       = mr.Id,
                    count    = mr.Count,
                    type     = Entities.ResourceType.MATERIAL,
                    isShared = mr.IsShared,
                    perTick  = mr.Consumption
                };
            }

            resources.Add(res);
            resMap.Add(resource as UIEntity, res);

            foreach (ConnectionLine con in connectors)
            {
                UIEntity procedure = null;
                if (con.SourcePort != null)
                {
                    UIEntity src = con.SourcePort.Owner;
                    UIEntity dst = con.DestinationPort.Owner;
                    procedure = src is Procedure ? src : dst is Procedure ? dst : null;

                    if (procedure != null)
                    {
                        Entities.impl.Procedure realprocedure = map[procedure] as Entities.impl.Procedure;
                        if (!realprocedure.getResources().Contains(res))
                        {
                            addAdditionalRelations(realprocedure, res);
                        }
                    }
                }
            }
        }