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