Exemplo n.º 1
0
 private void addAdditionalRelations(Entity src, Entities.Resource dst)
 {
     if (src is Entities.impl.Procedure)
     {
         (src as Entities.impl.Procedure).addResource(dst);
     }
 }
Exemplo n.º 2
0
        public List <UIEntity> transform(List <Identifable> elements)
        {
            List <UIEntity> uiEntities = new List <UIEntity>(elements.Count);

            foreach (Identifable e in elements)
            {
                if (e is Entity)
                {
                    Entity ent = e as Entity;
                    if (map.ContainsValue(ent))
                    {
                        UIEntity uie = map.FirstOrDefault(x => x.Value.Equals(ent)).Key;
                        if (uie != null)
                        {
                            uiEntities.Add(uie);
                        }
                    }
                }
                else if (e is Entities.Resource)
                {
                    Entities.Resource res = e as Entities.Resource;
                    if (resources.Contains(res))
                    {
                        UIEntity uie = resMap.FirstOrDefault(x => x.Value.Equals(res)).Key;
                        if (uie != null)
                        {
                            uiEntities.Add(uie);
                        }
                    }
                }
            }
            return(uiEntities);
        }
Exemplo n.º 3
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);
                        }
                    }
                }
            }
        }