/// <summary> /// Assures that all decision are selected with their scopes. /// If decision has been partially selected, meaning only decision with not all scopes was selected, /// or only some scopes were selected without decision node, this method will select all nodes /// to assure completeness of selection. /// </summary> /// <param name="originalExperiment">The original experiment.</param> private static void AssureCompleteDecisionSelection(BaseExperiment originalExperiment) { foreach (ExperimentNode node in originalExperiment.Vertices) { if (node.IsSelected) { //case 1. node is ExperimentDecisionNode if (node is ExperimentDecisionNode) { SelectDecisionsScopes(originalExperiment, node); } else if (node is ExitDecisionNode) { SelectDecisionsScopesConnectedToExitNode(originalExperiment, node); } else { //case 2. node is a scope node ScopeNode scopeNode = node as ScopeNode; if (scopeNode != null) { if (!scopeNode.DecisionNode.IsSelected) { scopeNode.DecisionNode.IsSelected = true; SelectDecisionsScopes(originalExperiment, scopeNode.DecisionNode); } } } } } }
/// <summary> /// Copies data into this experiment from another given experiment /// </summary> /// <param name="other">The other experiment from which data is copied.</param> protected virtual void CopyFrom(BaseExperiment other) { // Clone experiment info. this.m_experimentInfo = other.m_experimentInfo.Clone(); // Clone vertices Dictionary <ExperimentNode, ExperimentNode> clonedNodeLookup = new Dictionary <ExperimentNode, ExperimentNode>(); foreach (ExperimentNode node in other.Vertices) { var clonedNode = node.Clone(); clonedNodeLookup[node] = clonedNode; SetLogLevelSettings(clonedNode, Settings); AddVertex(clonedNode); } // Populate our Start and End node properties - this can only be done after the vertices are added. ReloadStartAndEndNode(); // Clone edges foreach (ExperimentNodeConnection connection in other.Edges) { ExperimentNode cloneSource = clonedNodeLookup[connection.Source]; ExperimentNode cloneTarget = clonedNodeLookup[connection.Target]; ExperimentNodeConnection clonedConnection = new ExperimentNodeConnection(connection.ID, cloneSource, cloneTarget, connection.IsFixed, connection.IsVisible); //copy also all route points clonedConnection.RoutePoints.CopyPointsFrom(connection.RoutePoints); AddEdge(clonedConnection); //special case - fix scope node references ScopeNodeHelper.TryFixScopeDecisionEntryAndExitNodes(cloneSource, cloneTarget); } // Do deep copy of errors. this.m_errors = new ObservableDictionary <ExperimentNode, ExperimentNodeError>(); foreach (KeyValuePair <ExperimentNode, ExperimentNodeError> pair in other.m_errors) { m_errors[clonedNodeLookup[pair.Key]] = new ExperimentNodeError(pair.Value.ErrorMessage, pair.Value.ErrorType); } if (other.References != null) { if (!RuntimeInfo.IsRunInMono) { References = new ObservableCollection <TraceLabSDK.PackageSystem.IPackageReference>(other.References); } else { // Mono currently has not implemented constructor of ObservableCollection(IEnumerable<T> collection) // thus we have to add references manually References = new ObservableCollection <TraceLabSDK.PackageSystem.IPackageReference>(); foreach (TraceLabSDK.PackageSystem.IPackageReference reference in other.References) { References.Add(reference); } } } }
public static void Paste(BaseExperiment targetExperiment, double x, double y) { if (clipboardComponentGraph == null) { return; } targetExperiment.CopyAndAdd(clipboardComponentGraph, x, y); }
/// <summary> /// Initializes a new instance of the <see cref="CompositeComponentGraph"/> class /// without reference to any node. /// </summary> /// <param name="componentGraph">The component graph.</param> public CompositeComponentGraph(BaseExperiment componentGraph) : base() { if (componentGraph == null) { throw new ArgumentException("Component graph cannot be null"); } CopyFrom(componentGraph); OwnerNode = null; //does not belong to any node }
public static void Copy(BaseExperiment originalExperiment) { // HERZUM SPRINT 4: TLAB-215 if (clipboardComponentGraph != null) { clipboardComponentGraph.Clear(); } // END HERZUM SPRINT 4: TLAB-215 clipboardComponentGraph = CompositeComponentGraph.ConstructGraphFromSelectedNodes(originalExperiment); foreach (ExperimentNode node in clipboardComponentGraph.Vertices) { node.IsSelected = false; } }
/// <summary> /// Copies data into this experiment from another given experiment /// </summary> /// <param name="other">The other experiment from which data is copied.</param> protected virtual void CopyFrom(BaseExperiment other) { // Clone experiment info. this.m_experimentInfo = other.m_experimentInfo.Clone(); // Clone vertices Dictionary <ExperimentNode, ExperimentNode> clonedNodeLookup = new Dictionary <ExperimentNode, ExperimentNode>(); foreach (ExperimentNode node in other.Vertices) { var clonedNode = node.Clone(); clonedNodeLookup[node] = clonedNode; SetLogLevelSettings(clonedNode, Settings); AddVertex(clonedNode); } // Populate our Start and End node properties - this can only be done after the vertices are added. ReloadStartAndEndNode(); // Clone edges foreach (ExperimentNodeConnection connection in other.Edges) { ExperimentNode cloneSource = clonedNodeLookup[connection.Source]; ExperimentNode cloneTarget = clonedNodeLookup[connection.Target]; ExperimentNodeConnection clonedConnection = new ExperimentNodeConnection(connection.ID, cloneSource, cloneTarget, connection.IsFixed, connection.IsVisible); //copy also all route points clonedConnection.RoutePoints.CopyPointsFrom(connection.RoutePoints); AddEdge(clonedConnection); //special case - fix scope node references ScopeNodeHelper.TryFixScopeDecisionEntryAndExitNodes(cloneSource, cloneTarget); } // Do deep copy of errors. this.m_errors = new ObservableDictionary <ExperimentNode, ExperimentNodeError>(); foreach (KeyValuePair <ExperimentNode, ExperimentNodeError> pair in other.m_errors) { m_errors[clonedNodeLookup[pair.Key]] = new ExperimentNodeError(pair.Value.ErrorMessage, pair.Value.ErrorType); } if (other.References != null) { References = other.References.CopyCollection(); } }
// HERZUM SPRINT 3.1 TLAB-180 private void ConstructGraphFromSelectedScopeNodes(BaseExperiment experiment) { if (experiment == null) { return; } CompositeComponentGraph.CopyAndAdd(CompositeComponentGraph.ConstructGraphFromSelectedNodes(experiment), 200.0, 200.0); foreach (ExperimentNode node in experiment.Vertices) { if (!node.IsSelected) { ScopeBaseMetadata scopeBaseMetadata = node.Data.Metadata as ScopeBaseMetadata; if (scopeBaseMetadata != null && scopeBaseMetadata.ComponentGraph != null) { ConstructGraphFromSelectedScopeNodes(scopeBaseMetadata.ComponentGraph); } } } }
/// <summary> /// Selects the decision and its scopes connected to the given exit node /// </summary> /// <param name="originalExperiment">The original experiment.</param> /// <param name="node">The exit decision node.</param> private static void SelectDecisionsScopesConnectedToExitNode(BaseExperiment originalExperiment, ExperimentNode exitDecisionNode) { //iterate throught all outcoming edges and delete successor nodes IEnumerable <ExperimentNodeConnection> edges; if (originalExperiment.TryGetInEdges(exitDecisionNode, out edges)) { //iterate over the copy of edges, as edges itself are going to be delete when nodes are deleted foreach (ExperimentNodeConnection edge in new List <ExperimentNodeConnection>(edges)) { //check if target is scope or exit, as there are might be old Decision nodes from old experiments //that do not have fixed connections to scopes if (edge.Source is ScopeNode || edge.Source is ExperimentDecisionNode) { if (!edge.Source.IsSelected) { edge.Source.IsSelected = true; } } } } }
// END HERZUM SPRINT 4.0: TLAB-204 #region Create Composite Component /// <summary> /// Constructs the graph from selected nodes of the given experiment graph. /// </summary> /// <param name="graph">The graph.</param> /// <returns></returns> public static CompositeComponentGraph ConstructGraphFromSelectedNodes(BaseExperiment originalExperiment) { var compositeComponentGraph = new CompositeComponentGraph(); // Clone experiment info. compositeComponentGraph.ExperimentInfo = new ExperimentInfo(); AssureCompleteDecisionSelection(originalExperiment); //keep lookup from original node to its clone for later edge reproduction Dictionary <ExperimentNode, ExperimentNode> clonedNodeLookup = new Dictionary <ExperimentNode, ExperimentNode>(); // Clone vertices that are selected and add them to the composite component graph foreach (ExperimentNode node in originalExperiment.Vertices) { if (node.IsSelected) { var clonedNode = node.Clone(); clonedNodeLookup[node] = clonedNode; compositeComponentGraph.SetLogLevelSettings(clonedNode, compositeComponentGraph.Settings); compositeComponentGraph.AddVertex(clonedNode); if (clonedNode.ID == "Start" && compositeComponentGraph.StartNode == null) { compositeComponentGraph.StartNode = (ExperimentStartNode)clonedNode; } else if (clonedNode.ID == "End" && compositeComponentGraph.EndNode == null) { compositeComponentGraph.EndNode = (ExperimentEndNode)clonedNode; } } } // Clone edges foreach (ExperimentNodeConnection connection in originalExperiment.Edges) { ExperimentNode cloneSourceNode, cloneTargetNode; //add edges only if both source and target nodes has been found in clones lookup bool foundSourceNode = clonedNodeLookup.TryGetValue(connection.Source, out cloneSourceNode); bool foundTargetNode = clonedNodeLookup.TryGetValue(connection.Target, out cloneTargetNode); if (foundSourceNode && foundTargetNode) { ExperimentNodeConnection clonedConnection = new ExperimentNodeConnection(connection.ID, cloneSourceNode, cloneTargetNode, connection.IsFixed, connection.IsVisible); //copy also all route points clonedConnection.RoutePoints.CopyPointsFrom(connection.RoutePoints); compositeComponentGraph.AddEdge(clonedConnection); //perform fixes for scopes ScopeNodeHelper.TryFixScopeDecisionEntryAndExitNodes(cloneSourceNode, cloneTargetNode); } } ConnectNodesToStartAndEndNode(compositeComponentGraph); //move graph closer to the origin point TraceLab.Core.Utilities.ExperimentHelper.MoveGraphCloserToOriginPoint(compositeComponentGraph, 200, 200); if (originalExperiment.References != null) { compositeComponentGraph.References = originalExperiment.References.CopyCollection(); } compositeComponentGraph.OwnerNode = null; return(compositeComponentGraph); }
public static void Cut(BaseExperiment originalExperiment) { Copy(originalExperiment); CutSelectedNodes(originalExperiment); }
private static void CutSelectedNodes(BaseExperiment originalExperiment) { originalExperiment.RemoveSelectedVertices(); }