/// <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); }