/// <summary> /// Creates summing points for all current inputs which are connected to n > 1 output ports and are through. /// The summing point has n inputs and one output /// The SummingPoint is represanted as a simulationmodel /// </summary> /// <returns></returns> public bool CreateSummingPoints() { // Counter for summing points int spCount = 0; Dictionary <string, SimulationModel> summingPointsAsSim = new Dictionary <string, SimulationModel>(); foreach (var simulationModel in SimulationsModels.Values) { foreach (var input in simulationModel.Inputs) { // Summing Point needed when input is connected to more than one Port and input is current. if (IsThroughVariable(input) && input.ConnectedTo.Count > 1) { SummingPoint summingPoint = createNewSummingPoint("Sum_" + spCount++, summingPointsAsSim, input); summingPointsAsSim.Add(summingPoint.Name, summingPoint.GetAsSimulationModel()); } } } // Adding the summing points as simulationmodel foreach (var key in summingPointsAsSim.Keys) { SimulationsModels.Add(key, summingPointsAsSim[key]); } return(true); }
/// <summary> /// Returns true when there is a port of relationship elment one which is connected to a port /// of relationship element two /// </summary> /// <param name="rel"></param> /// <returns></returns> public bool RelationHasConnection(RelationshipElement rel) { // There is no simulationmodel if (!SimulationsModels.ContainsKey(rel.ValueFirst) || !SimulationsModels.ContainsKey(rel.ValueSecond)) { return(true); } SimulationModel firstSim = SimulationsModels[rel.ValueFirst]; SimulationModel secondSim = SimulationsModels[rel.ValueSecond]; // There are Relations which are not necassary if (!rel.IsCertainConnection || firstSim.Inputs.Count == 0 || secondSim.Inputs.Count == 0) { return(true); } // Checking if there is at least one connection if (hasConnectionToOtherValue(firstSim.Inputs, rel.ValueSecond) || hasConnectionToOtherValue(secondSim.Inputs, rel.ValueFirst) || hasConnectionToOtherValue(firstSim.PhysicalPorts, rel.ValueSecond)) { return(true); } return(false); }
/// <summary> /// Checks the Datatypes of the connected In and Outputs and /// returns a list of strings with the names and /// the datatype of the in and output /// which are connected but do not share the same datatype. /// </summary> /// <param name="relationshipElement"></param> /// <param name="firstEle"></param> /// <param name="secondEle"></param> /// <returns></returns> public List <string> ReturnListWithMessageForDifferentDatatypes(RelationshipElement relationshipElement, string firstEle, string secondEle) { List <String> sameDatatype = new List <string>(); if (SimulationsModels.ContainsKey(firstEle) && SimulationsModels.ContainsKey(secondEle)) { foreach (var input in SimulationsModels[firstEle].Inputs.Concat(SimulationsModels[secondEle].Inputs)) { foreach (var connection in input.ConnectedTo) { if (!input.Datatype.Equals(connection.Datatype)) { sameDatatype.Add($"{input.IdShort}({input.Datatype})" + $"and {connection.IdShort}({connection.Datatype})" + $"are connected but do not share the same datatype"); } } } return(sameDatatype); } else { return(sameDatatype); } }
/// <summary> /// Compares the domains of the ports of the simulationmodels belonging to the given relationshiElement /// and connects if the domains are the same. /// If atleast one connetion is foudn true is returned. /// </summary> /// <param name="relationshipElement"></param> /// <param name="firstEle"></param> /// <param name="secondEle"></param> /// <param name="interfaceFirst"></param> /// <param name="interFaceSecond"></param> /// <returns></returns> public bool CheckCompatibleDomainsAndConnect(RelationshipElement relationshipElement, string firstEle, string secondEle, string interfaceFirst, string interFaceSecond) { if (SimulationsModels.ContainsKey(firstEle) && SimulationsModels.ContainsKey(secondEle)) { bool foundConnection = false; // Holen der Liste der Input Ports von ele1 List <IOput> inputsFirst = SimulationsModels[firstEle].GetInputsWithInterfaceName(interfaceFirst); // Hohlen der Liste der Input Ports von ele2 List <IOput> inputsSecond = SimulationsModels[secondEle].GetInputsWithInterfaceName(interFaceSecond); // Holen der Outputs von ele1 List <IOput> outputsFirst = SimulationsModels[firstEle].GetOutputsWithInterfaceName(interfaceFirst); // Holen der Outputs von ele2 List <IOput> outputsSecond = SimulationsModels[secondEle].GetOutputsWithInterfaceName(interFaceSecond); List <IOput> physicalFirst = SimulationsModels[firstEle].GetPhysicalPortsWithInterfaceName(interfaceFirst); List <IOput> physicalSecond = SimulationsModels[secondEle].GetPhysicalPortsWithInterfaceName(interFaceSecond); foundConnection = connectInputsAndOutputsByDomain(physicalFirst, physicalSecond); foundConnection = connectInputsAndOutputsByDomain(inputsFirst, outputsSecond) || foundConnection; foundConnection = connectInputsAndOutputsByDomain(inputsSecond, outputsFirst) || foundConnection; // Erstellen einer Liste, welche die Verbindungen enthält return(foundConnection); } else { return(false); } }
/// <summary> /// Checks the EClass ids of all connected in and output ports /// If they are not compatible the connection gets removed /// Returns a list of strings with the name, eclass id and /// unit of the in and output ports of all removed connections /// </summary> /// <param name="relationshipElement"></param> /// <param name="firstEle"></param> /// <param name="secondEle"></param> /// <returns></returns> public List <string> CheckeClassConnectionAndRemoveIncompatible(RelationshipElement relationshipElement, string firstEle, string secondEle) { EClass eClass = new EClass(); List <string> changed = new List <string>(); if (SimulationsModels.ContainsKey(firstEle) && SimulationsModels.ContainsKey(secondEle)) { foreach (var input in SimulationsModels[firstEle].Inputs.Concat(SimulationsModels[secondEle].Inputs)) { for (int i = input.ConnectedTo.Count - 1; i >= 0; i--) { var connection = input.ConnectedTo[i]; if (SimulationsModels[input.Owner].Mappings.Count != 0) { Console.WriteLine("---Mappings of " + input.Owner); foreach (var map in SimulationsModels[input.Owner].Mappings.Values) { Console.WriteLine(map.BasicId + " " + map.UnknownId); } } // Search for compatible Eclass IDs if (EClass.CheckEClassConnection(input.EclassID, connection.EclassID) || checkForMapping(input, connection, eClass)) { } // Not Compatible Eclass ids and connection gets removed. else { input.RemoveConnection(connection); changed.Add(input.IdShort + $"({input.EclassID})({input.Unit}) and " + connection.IdShort + $"({connection.EclassID})({connection.Unit})" + $"are connected but do not have compatible Eclass ID"); } } } } return(changed); }
/// <summary> /// Creates a node, represented as a Simulationmodel, for all physical ports which are connected. /// </summary> public void CreateNodesForPhysicalPorts() { int nodeCount = 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 = "www.tedz.itsowl.com/ids/cd/1132_9030_2102_4033"; key.type = "ConceptDescription"; key.local = true; key.index = 0; key.idType = "IRI"; semanticId.Keys.Add(key); List <List <IOput> > nodeLists = new List <List <IOput> >(); foreach (var simmod in SimulationsModels.Values) { foreach (var port in simmod.PhysicalPorts) { if (!nodeLists.Contains(port.ConnectedTo) && port.ConnectedTo.Count > 1) { nodeLists.Add(port.ConnectedTo); } } } foreach (var list in nodeLists) { SimulationModel nodeModel = createNode(nodeCount, semanticId, list); if (nodeModel.PhysicalPorts.Count > 0) { newSimMod.Add(nodeModel); nodeCount++; } } foreach (var simmod in newSimMod) { SimulationsModels.Add(simmod.Name, simmod); } }
/// <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); }