/// <summary> /// Performs operation of adding the new scope to the given decision. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> protected void ExecuteAddScopeToDecision(object sender, ExecutedRoutedEventArgs e) { GraphSharp.Controls.VertexControl vertexControl = e.Parameter as GraphSharp.Controls.VertexControl; if (vertexControl != null) { ExperimentDecisionNode decisionNode = vertexControl.Vertex as ExperimentDecisionNode; if (decisionNode != null) { ExitDecisionNode exitDecisionNode = null; IEditableExperiment experiment = decisionNode.Owner as IEditableExperiment; double rightmostX = decisionNode.Data.X; HashSet <string> currentLabels = new HashSet <string>(); //iterate through outgoing scopes and find the scope with right border located most to the right among all scopes //also locate among outgoing edges reference to exit IEnumerable <ExperimentNodeConnection> outEdges; if (experiment.TryGetOutEdges(decisionNode, out outEdges)) { foreach (ExperimentNodeConnection connection in outEdges) { ScopeNode scope = connection.Target as ScopeNode; if (scope != null) { double candidateRightMostX = scope.DataWithSize.X + scope.DataWithSize.Width / 2; if (candidateRightMostX > rightmostX) { rightmostX = candidateRightMostX; } //also collect labels currentLabels.Add(scope.Data.Metadata.Label); } else if (exitDecisionNode == null) { //try find exit decision node exitDecisionNode = connection.Target as ExitDecisionNode; } } } double xPosition = rightmostX + 100; double yPosition = decisionNode.Data.Y + 120; string finalLabel = DetermineNewScopeLabel(currentLabels); //check if deicion node is not null. In old decision nodes without scopes, there were no associated exit node, //thus the scope cannot be added for these decisions. if (exitDecisionNode != null) { ComponentFactory.AddScopeToDecision(finalLabel, xPosition, yPosition, decisionNode, exitDecisionNode, experiment); } } } }