Ejemplo n.º 1
0
 public SummingPoint(IOput output, string name, AdminShellNS.AdminShell.SemanticId semanticId)
 {
     this.output     = output;
     this.Name       = name;
     this.SemanticId = semanticId;
     inputs          = new List <IOput>();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates connections between physical ports. All ports which are connected share the same ConnectedTo
        /// Port list.
        /// </summary>
        /// <param name="portToConnect"></param>
        public void AddPhysicalConnection(IOput portToConnect)
        {
            if (this.ConnectedTo.Count == 0 && portToConnect.ConnectedTo.Count == 0)
            {
                this.ConnectedTo.Add(portToConnect);
                this.ConnectedTo.Add(this);
                portToConnect.ConnectedTo = this.ConnectedTo;
            }
            else if (this.ConnectedTo.Count != 0 && portToConnect.ConnectedTo.Count == 0)
            {
                this.ConnectedTo.Add(portToConnect);
                portToConnect.ConnectedTo = this.ConnectedTo;
            }
            else if (this.ConnectedTo.Count == 0 && portToConnect.ConnectedTo.Count != 0)
            {
                portToConnect.ConnectedTo.Add(this);
                this.ConnectedTo = portToConnect.ConnectedTo;
            }
            else if (this.ConnectedTo.Count != 0 && portToConnect.ConnectedTo.Count != 0)
            {
                List <IOput> ports = this.ConnectedTo.Concat(portToConnect.ConnectedTo).ToList();

                foreach (var port in ports)
                {
                    port.ConnectedTo = ports;
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds a connetion to the given port.
 /// </summary>
 /// <param name="portToConnect"></param>
 public void AddConnection(IOput portToConnect)
 {
     if (portToConnect != null)
     {
         this.ConnectedTo.Add(portToConnect);
         portToConnect.ConnectedTo.Add(this);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Removes the connection to the given port, in case there is one.
 /// </summary>
 /// <param name="connectedPort"></param>
 public void RemoveConnection(IOput connectedPort)
 {
     if (connectedPort != null && !this.IsPhysical)
     {
         this.ConnectedTo.Remove(connectedPort);
         connectedPort.ConnectedTo.Remove(this);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the given port as property
        /// </summary>
        /// <param name="port"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        private AdminShellNS.AdminShell.Property GetPortAsProperty(IOput port, string direction)
        {
            AdminShellNS.AdminShell.Property port_prop = new AdminShellNS.AdminShell.Property();
            port_prop.idShort = port.IdShort;
            port_prop.AddQualifier("direction", direction);
            port_prop.AddQualifier("Domain", port.Domain);
            port_prop.valueType  = port.Datatype;
            port_prop.semanticId = port.SemanticId;

            return(port_prop);
        }
        /// <summary>
        /// Sets the outputs for the SimulationModel
        /// </summary>
        /// <param name="token"></param>
        private void setOutputs(JToken token)
        {
            if (token.SelectToken("value") != null)
            {
                JArray outs = (JArray)token["value"];

                foreach (var singleout in outs)
                {
                    Outputs.Add(IOput.Parse(singleout, Name));
                }
            }
        }
        /// <summary>
        /// Sets the inputs for the SimulationModel
        /// </summary>
        /// <param name="token"></param>
        private void setInputs(JToken token)
        {
            if (token.SelectToken("value") != null)
            {
                JArray ins = (JArray)token["value"];

                foreach (var singlein in ins)
                {
                    Inputs.Add(IOput.Parse(singlein, Name));
                }
            }
        }
        /// <summary>
        /// Sets the physical ports
        /// </summary>
        /// <param name="token"></param>
        private void setPhysicalPorts(JToken token)
        {
            if (token.SelectToken("value") != null)
            {
                JArray ports = (JArray)token["value"];

                foreach (var port in ports)
                {
                    PhysicalPorts.Add(IOput.Parse(port, Name, true));
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Checks for mappings for the in or output port and returns true in case there is a mapping.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="eClass"></param>
        /// <returns></returns>
        private bool checkForMapping(IOput input, IOput output, EClass eClass)
        {
            SimulationModel simulationModel = SimulationsModels[input.Owner];
            bool            result          = simulationModel.Mappings.ContainsKey(input.EclassID) &&
                                              EClass.CheckEClassConnection(simulationModel.Mappings[input.EclassID].BasicId, output.EclassID);

            // Check output ports only if mapping was not already found in input ports
            if (result == false)
            {
                simulationModel = SimulationsModels[output.Owner];
                result          = simulationModel.Mappings.ContainsKey(output.EclassID) &&
                                  EClass.CheckEClassConnection(input.EclassID, simulationModel.Mappings[output.EclassID].BasicId);
            }
            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a new SummingPoint between the given input and the outputs connected to it.
        /// </summary>
        /// <param name="spName"></param>
        /// <param name="summingPointsAsSim"></param>
        /// <param name="input"></param>
        private SummingPoint createNewSummingPoint(string spName,
                                                   Dictionary <string, SimulationModel> summingPointsAsSim,
                                                   IOput input)
        {
            IOput newOutput = new IOput("out", spName, input.SemanticId);

            SummingPoint summingPoint = new SummingPoint(newOutput, spName, createSemanticIdSummingPoint());

            createConnectionBetweenOutputsConnectedToInputAndSummingPoint(summingPoint, input, spName);

            input.AddConnection(summingPoint.output);
            summingPoint.output.Domain = "SimToolSubset";


            return(summingPoint);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Returns whether or not the given port is an through variable
        /// </summary>
        /// <param name="port"></param>
        /// <returns></returns>
        public bool IsThroughVariable(IOput port)
        {
            if (port.Domain.Equals("elecDC"))
            {
                return(port.Unit.Contains("Ampere"));
            }
            else if (port.Domain.Equals("mechRot"))
            {
                return(port.Unit.Contains("Newtonmeter"));
            }
            else if (port.Domain.Equals("mechTrans"))
            {
                return(port.Unit.Equals("Newton"));
            }


            return(port.Unit.Contains("Ampere"));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Parses the given JToken into an IOput object
        /// </summary>
        /// <param name="token"></param>
        /// <param name="ownerName"></param>
        /// <param name="isPhysical"></param>
        /// <returns></returns>
        public static IOput Parse(JToken token, string ownerName, bool isPhysical = false)
        {
            IOput ioput = new IOput();

            ioput.Owner      = ownerName;
            ioput.IsPhysical = isPhysical;
            ioput.SetEClass(token);

            ioput.SetIdShort(token);
            ioput.SetUnit(token);
            ioput.SetDomain(token);
            ioput.SetDatatype(token);
            ioput.SetSemanticId(token);
            ioput.SetInterfaceName(token);


            return(ioput);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Returns whether or not the given port is an across variable
        /// </summary>
        /// <param name="port"></param>
        /// <returns></returns>
        public bool IsAcrossVariable(IOput port)
        {
            if (port.Domain.Equals("elecDC"))
            {
                return(port.Unit.Contains("Volt"));
            }
            else if (port.Domain.Equals("mechRot"))
            {
                return(port.Unit.Contains("1/min"));
            }
            else if (port.Domain.Equals("mechTrans"))
            {
                return(port.Unit.Equals("m/s"));
            }


            return(false);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sets the SemanticID of the relation depending in the semanticPort class.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public AdminShellNS.AdminShell.SemanticId SetSemanticIdRelEle(IOput input, IOput output, int type)
        {
            AdminShellNS.AdminShell.SemanticId semantic = new AdminShellNS.AdminShell.SemanticId();
            AdminShellNS.AdminShell.Key        key      = new AdminShellNS.AdminShell.Key();
            key.idType = "IRI";
            key.index  = 0;
            key.local  = true;
            key.type   = "ConceptDescription";
            switch (type)
            {
            case 0: key.value = SemanticPort.GetInstance().GetSemanticForPort("SmdComp_SignalFlow"); break;

            case 1: key.value = SemanticPort.GetInstance().GetSemanticForPort("SmdComp_PhysicalElectric"); break;

            case 2: key.value = "mechanic"; break;
            }
            semantic.JsonKeys.Add(key);
            return(semantic);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates the connection between the output ports which are connected to input and the summingpoint.
        /// And removes the existing connections.
        /// </summary>
        /// <param name="summingPoint"></param>
        /// <param name="input"></param>
        /// <param name="name"></param>
        private void createConnectionBetweenOutputsConnectedToInputAndSummingPoint(SummingPoint summingPoint,
                                                                                   IOput input,
                                                                                   string name)
        {
            for (int i = input.ConnectedTo.Count - 1; i >= 0; i--)
            {
                var output = input.ConnectedTo[i];
                output.Domain = "SimToolSubset";
                IOput newSPPort = new IOput("in_" + (i + 1), name);
                newSPPort.SemanticId = output.SemanticId;
                newSPPort.Domain     = "SimToolSubset";
                //Einfügen eines neuen input in den summingpoint
                summingPoint.inputs.Add(newSPPort);

                // An stelle dessen einfügen einer Verbindung zwischen dem neuen input und dem output
                newSPPort.AddConnection(output);
                // Finden der alten Verbindung und entfernen dieser
                output.RemoveConnection(input);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Returns the given Relationshipelement as RelationshipElement of Adminshell
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public AdminShellNS.AdminShell.RelationshipElement GetPortsAsRelation(IOput input, IOput output, int type = 0)
        {
            AdminShellNS.AdminShell.Submodel submodel = new AdminShellNS.AdminShell.Submodel();

            submodel.identification.id     = "urn:itsowl.tedz.com:sm:instance:9053_7072_4002_2783";
            submodel.identification.idType = "IRI";


            // Finden der zugehörigen properties der in und out
            AdminShellNS.AdminShell.Entity entity = new AdminShellNS.AdminShell.Entity();
            entity.idShort = input.Owner;
            entity.parent  = submodel;

            AdminShellNS.AdminShell.Property property = new AdminShellNS.AdminShell.Property();
            property.idShort = input.IdShort;
            property.parent  = entity;


            AdminShellNS.AdminShell.Entity outentity = new AdminShellNS.AdminShell.Entity();
            outentity.idShort = output.Owner;
            outentity.parent  = submodel;

            AdminShellNS.AdminShell.Property outproperty = new AdminShellNS.AdminShell.Property();
            outproperty.idShort = output.IdShort;
            outproperty.parent  = outentity;


            // setzen als first bzw second

            AdminShellNS.AdminShell.RelationshipElement relationshipElement =
                new AdminShellNS.AdminShell.RelationshipElement();

            relationshipElement.first      = outproperty.GetReference();
            relationshipElement.second     = property.GetReference();
            relationshipElement.semanticId = SetSemanticIdRelEle(input, output, type);
            relationshipElement.idShort    = $"{relCount++}";


            return(relationshipElement);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a node between the given ports
        /// </summary>
        /// <param name="nodeCount"></param>
        /// <param name="semanticId"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        private static SimulationModel createNode(int nodeCount,
                                                  AdminShellNS.AdminShell.SemanticId semanticId,
                                                  List <IOput> list)
        {
            SimulationModel nodeModel = new SimulationModel();

            nodeModel.IsNode = true;
            string name = "node_" + nodeCount;

            nodeModel.Name       = name;
            nodeModel.SemanticId = semanticId;
            int portnumber = 0;

            foreach (var port in list)
            {
                IOput newport = new IOput(port.IdShort + "_" + portnumber++, name);
                newport.IsPhysical = true;
                newport.ConnectedTo.Add(port);
                nodeModel.PhysicalPorts.Add(newport);
            }

            return(nodeModel);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates multiplication points in case there is a connection where the ports to not share the same unit
        /// but were connected because of a mapping. The mapping conatains a value which is used here as the factor
        /// for the multiplication. The existing output port of the existing connection gets connected to the multports
        /// input port and the input port of the connection gets connected to the multports output port.
        /// The old connection is removed.
        /// </summary>
        /// <returns></returns>
        public bool CreateMultPoints()
        {
            int multCount = 0;
            List <SimulationModel> newSimMod = new List <SimulationModel>();


            AdminShellNS.AdminShell.SemanticId semanticId = new AdminShellNS.AdminShell.SemanticId();
            AdminShellNS.AdminShell.Key        key        = new AdminShellNS.AdminShell.Key();
            key.value  = SemanticPort.GetInstance().GetSemanticForPort("BoM_SmdComp_Mult");
            key.type   = "ConceptDescription";
            key.local  = true;
            key.index  = 0;
            key.idType = "IRI";
            semanticId.Keys.Add(key);

            foreach (var simmod in SimulationsModels.Values)
            {
                foreach (var input in simmod.Inputs)
                {
                    if (input.EclassID != null && simmod.Mappings.ContainsKey(input.EclassID))
                    {
                        foreach (var connected in input.ConnectedTo.ToList())
                        {
                            string          name     = "mult_" + multCount++;
                            SimulationModel multPort = new SimulationModel();
                            multPort.SemanticId = semanticId;
                            multPort.Multfactor = simmod.Mappings[input.EclassID].Value;

                            IOput iput = new IOput("in", name);
                            iput.SemanticId = input.SemanticId;

                            IOput oput = new IOput("out", name);
                            oput.SemanticId = input.SemanticId;

                            input.RemoveConnection(connected);

                            oput.AddConnection(input);
                            iput.AddConnection(connected);

                            multPort.Outputs.Add(oput);
                            multPort.Inputs.Add(iput);
                            multPort.Name = name;
                            newSimMod.Add(multPort);
                        }
                    }
                }


                foreach (var output in simmod.Outputs)
                {
                    if (output.EclassID != null && simmod.Mappings.ContainsKey(output.EclassID))
                    {
                        foreach (var connected in output.ConnectedTo.ToList())
                        {
                            string          name     = "mult_" + multCount++;
                            SimulationModel multPort = new SimulationModel();
                            multPort.SemanticId = semanticId;
                            multPort.Multfactor = simmod.Mappings[output.EclassID].Value;

                            IOput iput = new IOput("in", name);
                            iput.SemanticId = output.SemanticId;

                            IOput oput = new IOput("out", name);
                            oput.SemanticId = output.SemanticId;

                            output.RemoveConnection(connected);

                            iput.AddConnection(output);
                            oput.AddConnection(connected);

                            multPort.Outputs.Add(oput);
                            multPort.Inputs.Add(iput);
                            multPort.Name = name;
                            newSimMod.Add(multPort);
                        }
                    }
                }
            }
            foreach (var simMod in newSimMod)
            {
                SimulationsModels.Add(simMod.Name, simMod);
            }

            return(true);
        }