コード例 #1
0
        /// <summary>
        /// Connects the nodes to start and end node.
        /// In case user selected partial graph without start or/and end node, this methods adds
        /// accordingly Start and End node to the given composite graph.
        /// If some selected nodes didn't have any outgoing paths they are automatically connected to the end node.
        /// If some selected nodes didn't have any incoming paths they are automatically connected to the start node.
        /// </summary>
        /// <param name="compositeComponentGraph">The composite component graph.</param>

        // HERZUM SPRINT 2.4 TLAB-157
        // private static void ConnectNodesToStartAndEndNode(CompositeComponentGraph compositeComponentGraph)
        public static void ConnectNodesToStartAndEndNode(CompositeComponentGraph compositeComponentGraph)
        // END HERZUM SPRINT 2.4 TLAB-157
        {
            if (compositeComponentGraph.StartNode == null || compositeComponentGraph.EndNode == null)
            {
                double startX, startY, endX, endY;

                DetermineOptimalStartEndPositions(compositeComponentGraph, out startX, out startY, out endX, out endY);

                if (compositeComponentGraph.StartNode == null)
                {
                    //create start node and add it to graph, and connect it to the existing graph
                    ExperimentStartNode start = new ExperimentStartNode();
                    start.Data.X = startX;
                    start.Data.Y = startY;
                    compositeComponentGraph.AddVertex(start);
                    compositeComponentGraph.StartNode = start;
                }

                if (compositeComponentGraph.EndNode == null)
                {
                    //create start node and add it to graph, and connect it to the existing graph
                    ExperimentEndNode end = new ExperimentEndNode();
                    end.Data.X = endX;
                    end.Data.Y = endY;
                    compositeComponentGraph.AddVertex(end);
                    compositeComponentGraph.EndNode = end;
                }

                //connect subgraph to start and end
                foreach (ExperimentNode node in compositeComponentGraph.Vertices)
                {
                    if (node is ExperimentStartNode == false && node is ExperimentEndNode == false)
                    {
                        //if node has not any incoming connection from other Selected Nodes it has to be connected to the start
                        if (compositeComponentGraph.IsInEdgesEmpty(node))
                        {
                            compositeComponentGraph.AddEdge(new ExperimentNodeConnection(Guid.NewGuid().ToString(), compositeComponentGraph.StartNode, node));
                        }

                        //if node has not any outcoming connection from other Selected Nodes it has to be connected to the end
                        if (compositeComponentGraph.IsOutEdgesEmpty(node))
                        {
                            compositeComponentGraph.AddEdge(new ExperimentNodeConnection(Guid.NewGuid().ToString(), node, compositeComponentGraph.EndNode));
                        }
                    }
                }
                // HERZUM SPRINT 3.0: COMPOSITE BUG FIX
                if (compositeComponentGraph.EdgeCount == 0 && compositeComponentGraph.StartNode != null && compositeComponentGraph.EndNode != null)
                {
                    compositeComponentGraph.AddEdge(new ExperimentNodeConnection(Guid.NewGuid().ToString(), compositeComponentGraph.StartNode, compositeComponentGraph.EndNode));
                    compositeComponentGraph.StartNode.Data.X = 0;
                    compositeComponentGraph.StartNode.Data.Y = 0;
                    compositeComponentGraph.EndNode.Data.X   = 0;
                    compositeComponentGraph.EndNode.Data.Y   = 100;
                }
                // END HERZUM SPRINT 3.0: COMPOSITE BUG FIX
            }
        }
コード例 #2
0
        /// <summary>
        /// Connects the nodes to start and end node.
        /// In case user selected partial graph without start or/and end node, this methods adds 
        /// accordingly Start and End node to the given composite graph. 
        /// If some selected nodes didn't have any outgoing paths they are automatically connected to the end node.
        /// If some selected nodes didn't have any incoming paths they are automatically connected to the start node.
        /// </summary>
        /// <param name="compositeComponentGraph">The composite component graph.</param>
        private static void ConnectNodesToStartAndEndNode(CompositeComponentGraph compositeComponentGraph)
        {
            if (compositeComponentGraph.StartNode == null || compositeComponentGraph.EndNode == null)
            {
                double startX, startY, endX, endY;

                DetermineOptimalStartEndPositions(compositeComponentGraph, out startX, out startY, out endX, out endY);

                if (compositeComponentGraph.StartNode == null)
                {
                    //create start node and add it to graph, and connect it to the existing graph
                    ExperimentStartNode start = new ExperimentStartNode();
                    start.Data.X = startX;
                    start.Data.Y = startY;
                    compositeComponentGraph.AddVertex(start);
                    compositeComponentGraph.StartNode = start;
                }

                if (compositeComponentGraph.EndNode == null)
                {
                    //create start node and add it to graph, and connect it to the existing graph
                    ExperimentEndNode end = new ExperimentEndNode();
                    end.Data.X = endX;
                    end.Data.Y = endY;
                    compositeComponentGraph.AddVertex(end);
                    compositeComponentGraph.EndNode = end;
                }

                //connect subgraph to start and end
                foreach (ExperimentNode node in compositeComponentGraph.Vertices)
                {
                    if (node is ExperimentStartNode == false && node is ExperimentEndNode == false)
                    {
                        //if node has not any incoming connection from other Selected Nodes it has to be connected to the start
                        if (compositeComponentGraph.IsInEdgesEmpty(node))
                        {
                            compositeComponentGraph.AddEdge(new ExperimentNodeConnection(Guid.NewGuid().ToString(), compositeComponentGraph.StartNode, node));
                        }

                        //if node has not any outcoming connection from other Selected Nodes it has to be connected to the end
                        if (compositeComponentGraph.IsOutEdgesEmpty(node))
                        {
                            compositeComponentGraph.AddEdge(new ExperimentNodeConnection(Guid.NewGuid().ToString(), node, compositeComponentGraph.EndNode));
                        }
                    }
                }
            }
        }
コード例 #3
0
        // 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);
        }
コード例 #4
0
        /// <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)
            {
                if (!TraceLabSDK.RuntimeInfo.IsRunInMono)
                {
                    compositeComponentGraph.References = new ObservableCollection<TraceLabSDK.PackageSystem.IPackageReference>(originalExperiment.References);
                }
                else
                {
                    // Mono currently has not implemented constructor of ObservableCollection(IEnumerable<T> collection)
                    // thus we have to add references manually
                    compositeComponentGraph.References = new ObservableCollection<TraceLabSDK.PackageSystem.IPackageReference>();
                    foreach (TraceLabSDK.PackageSystem.IPackageReference reference in originalExperiment.References)
                    {
                        compositeComponentGraph.References.Add(reference);
                    }
                }
            }

            compositeComponentGraph.OwnerNode = null;

            return compositeComponentGraph;
        }