/// <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); } } } }
/// <summary> /// Determines whether the given decision is an old version decision. /// Previously decisions were independent nodes without scopes and corresponding exit node. /// Thus for old decisions we want to choose another template. /// </summary> /// <param name="decisionNode">The decision node.</param> /// <returns> /// <c>true</c> if the specified decision node is old decision; otherwise, <c>false</c>. /// </returns> private static bool IsGotoDecision(ExperimentDecisionNode decisionNode) { IEditableExperiment experiment = decisionNode.Owner as IEditableExperiment; IEnumerable <ExperimentNodeConnection> outEdges; if (experiment.TryGetOutEdges(decisionNode, out outEdges)) { foreach (ExperimentNodeConnection connection in outEdges) { if (connection.Target is ExitDecisionNode) { return(false); } } } return(true); }