public override ExperimentNode Clone()
        {
            var clone = new ExperimentEndNode();
            clone.CopyFrom(this);

            return clone;
        }
        /// <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
            }
        }
Exemple #3
0
        public override ExperimentNode Clone()
        {
            var clone = new ExperimentEndNode();

            clone.CopyFrom(this);

            return(clone);
        }
        /// <summary>
        /// Generates the correct node based on metadata contained in serialized vertex data
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="nodeData">The node data.</param>
        /// <returns>Experiment node</returns>
        private ExperimentNode NodeGenerator(string id, SerializedVertexData nodeData)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (nodeData == null)
            {
                throw new ArgumentNullException("nodeData");
            }

            ExperimentNode node;

            if (nodeData.Metadata is StartNodeMetadata)
            {
                node = new ExperimentStartNode(id, nodeData);
            }
            else if (nodeData.Metadata is EndNodeMetadata)
            {
                node = new ExperimentEndNode(id, nodeData);
            }
            else if (nodeData.Metadata is DecisionMetadata)
            {
                node = new ExperimentDecisionNode(id, nodeData);
            }
            else if (nodeData.Metadata is ScopeMetadata)
            {
                node = new ScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is LoopScopeMetadata)
            {
                node = new LoopScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is CompositeComponentMetadata)
            {
                node = new CompositeComponentNode(id, nodeData);
            }
            else if (nodeData.Metadata is ExitDecisionMetadata)
            {
                node = new ExitDecisionNode(id, nodeData);
            }
            else
            {
                ComponentNode componentNode = new ComponentNode(id, nodeData);
                node = componentNode;
            }

            return(node);
        }
        /// <summary>
        /// Creates new m_experiment.
        /// </summary>
        /// <returns>Returns newly created m_experiment.</returns>
        public static Experiment New()
        {
            Experiment newExperiment = new Experiment(NewExperimentName, string.Empty);
            ExperimentStartNode start = new ExperimentStartNode();
            start.Data.X = 200;
            start.Data.Y = 100;
            newExperiment.AddVertex(start);
            
            ExperimentEndNode end = new ExperimentEndNode();
            end.Data.X = 200;
            end.Data.Y = 200;
            newExperiment.AddVertex(end);

            newExperiment.ReloadStartAndEndNode();
            newExperiment.ResetModifiedFlag();

            return newExperiment;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CompositeComponentEditableGraph"/> class.
        /// Constructor used to create empty new editable graph. Initially it does not have OwnerNode.
        /// The OwnerNode is set in initialization step when metadata that contains graph is assigned to scope node.
        /// </summary>
        /// <param name="initStartEnd">if set to <c>true</c> [init start end].</param>
        public CompositeComponentEditableGraph(bool initStartEnd) : base()
        {
            if (initStartEnd)
            {
                ExperimentStartNode start = new ExperimentStartNode(Guid.NewGuid().ToString(), "Enter");
                start.Data.X = 0;
                start.Data.Y = 0;
                AddVertex(start);

                ExperimentEndNode end = new ExperimentEndNode(Guid.NewGuid().ToString(), "Exit");
                end.Data.X = 0;
                end.Data.Y = 0;
                AddVertex(end);

                ReloadStartAndEndNode();
            }

            //note, OwnerNode is set in InitializeComponentGraph of ScopeNode
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CompositeComponentEditableGraph"/> class.
        /// Constructor used to create empty new editable graph. Initially it does not have OwnerNode. 
        /// The OwnerNode is set in initialization step when metadata that contains graph is assigned to scope node.
        /// </summary>
        /// <param name="initStartEnd">if set to <c>true</c> [init start end].</param>
        public CompositeComponentEditableGraph(bool initStartEnd) : base()
        {
            if (initStartEnd)
            {
                ExperimentStartNode start = new ExperimentStartNode(Guid.NewGuid().ToString(), "Enter");
                start.Data.X = 0;
                start.Data.Y = 0;
                AddVertex(start);

                ExperimentEndNode end = new ExperimentEndNode(Guid.NewGuid().ToString(), "Exit");
                end.Data.X = 0;
                end.Data.Y = 0;
                AddVertex(end);

                ReloadStartAndEndNode();
            }

            //note, OwnerNode is set in InitializeComponentGraph of ScopeNode
        }
Exemple #8
0
        /// <summary>
        /// Creates new m_experiment.
        /// </summary>
        /// <returns>Returns newly created m_experiment.</returns>
        public static Experiment New()
        {
            Experiment          newExperiment = new Experiment(NewExperimentName, string.Empty);
            ExperimentStartNode start         = new ExperimentStartNode();

            start.Data.X = 200;
            start.Data.Y = 100;
            newExperiment.AddVertex(start);

            ExperimentEndNode end = new ExperimentEndNode();

            end.Data.X = 200;
            end.Data.Y = 200;
            newExperiment.AddVertex(end);

            newExperiment.ReloadStartAndEndNode();
            newExperiment.ResetModifiedFlag();

            return(newExperiment);
        }
Exemple #9
0
        /// <summary>
        /// This method searches through all existing verices and searches for start and end node to update the references.
        /// It is needed after loading the experiment from the xml file.
        /// </summary>
        public void ReloadStartAndEndNode()
        {
            IEnumerator <ExperimentNode> iterator = Vertices.GetEnumerator();

            // TODO: Remove the ID mappings once we've converted all saved graphs to the new Start/End metadata
            while (iterator.MoveNext() && (StartNode == null || EndNode == null))
            {
                ExperimentNode node = iterator.Current;

                if (node.Data.Metadata is EndNodeMetadata || node.ID == "End")
                {
                    EndNode = (ExperimentEndNode)node;
                }
                else if (node.Data.Metadata is StartNodeMetadata || node.ID == "Start")
                {
                    StartNode = (ExperimentStartNode)node;
                }
            }

            if (StartNode == null || EndNode == null)
            {
                throw new ArgumentException("Experiment does not have Start or End node. Experiment file has been corrupted.");
            }
        }
        /// <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));
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Generates the correct node based on metadata contained in serialized vertex data
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="nodeData">The node data.</param>
        /// <returns>Experiment node</returns>
        private ExperimentNode NodeGenerator(string id, SerializedVertexData nodeData)
        {
            if (id == null)
                throw new ArgumentNullException("id");
            if (nodeData == null)
                throw new ArgumentNullException("nodeData");

            ExperimentNode node;

            if (nodeData.Metadata is StartNodeMetadata)
            {
                node = new ExperimentStartNode(id, nodeData);
            }
            else if (nodeData.Metadata is EndNodeMetadata)
            {
                node = new ExperimentEndNode(id, nodeData);
            }
            else if (nodeData.Metadata is DecisionMetadata)
            {
                node = new ExperimentDecisionNode(id, nodeData);
            }
            else if (nodeData.Metadata is ScopeMetadata)
            {
                node = new ScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is LoopScopeMetadata)
            {
                node = new LoopScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is CompositeComponentMetadata)
            {
                node = new CompositeComponentNode(id, nodeData);
            }
            else if (nodeData.Metadata is ExitDecisionMetadata)
            {
                node = new ExitDecisionNode(id, nodeData);
            }
            // HERZUM SPRINT 1.0
            else if (nodeData.Metadata is CommentMetadata)
            {
                // HERZUM SPRINT 1.2
                // node = new CommentNode(id, nodeData);
                node = new CommentNode(id, (SerializedVertexDataWithSize) nodeData);
                // END HERZUM SPRINT 1.2
            }
            // END HERZUM SPRINT 1.0
            // HERZUM SPRINT 2.0: TLAB-65 CLASS
            else if (nodeData.Metadata is ChallengeMetadata)
            {
                node = new ChallengeNode(id, (SerializedVertexDataWithSize) nodeData);
            }
            // END HERZUM SPRINT 2.0: TLAB-65 CLASS
            else
            {
                ComponentNode componentNode = new ComponentNode(id, nodeData);
                node = componentNode;
            }

            return node;
        }
        /// <summary>
        /// Generates the correct node based on metadata contained in serialized vertex data
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="nodeData">The node data.</param>
        /// <returns>Experiment node</returns>
        private ExperimentNode NodeGenerator(string id, SerializedVertexData nodeData)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (nodeData == null)
            {
                throw new ArgumentNullException("nodeData");
            }

            ExperimentNode node;

            if (nodeData.Metadata is StartNodeMetadata)
            {
                node = new ExperimentStartNode(id, nodeData);
            }
            else if (nodeData.Metadata is EndNodeMetadata)
            {
                node = new ExperimentEndNode(id, nodeData);
            }
            else if (nodeData.Metadata is DecisionMetadata)
            {
                node = new ExperimentDecisionNode(id, nodeData);
            }
            else if (nodeData.Metadata is ScopeMetadata)
            {
                node = new ScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is LoopScopeMetadata)
            {
                node = new LoopScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is CompositeComponentMetadata)
            {
                node = new CompositeComponentNode(id, nodeData);
            }
            else if (nodeData.Metadata is ExitDecisionMetadata)
            {
                node = new ExitDecisionNode(id, nodeData);
            }
            // HERZUM SPRINT 1.0
            else if (nodeData.Metadata is CommentMetadata)
            {
                // HERZUM SPRINT 1.2
                // node = new CommentNode(id, nodeData);
                node = new CommentNode(id, (SerializedVertexDataWithSize)nodeData);
                // END HERZUM SPRINT 1.2
            }
            // END HERZUM SPRINT 1.0
            // HERZUM SPRINT 2.0: TLAB-65 CLASS
            else if (nodeData.Metadata is ChallengeMetadata)
            {
                node = new ChallengeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            // END HERZUM SPRINT 2.0: TLAB-65 CLASS
            else
            {
                ComponentNode componentNode = new ComponentNode(id, nodeData);
                node = componentNode;
            }

            return(node);
        }
        /// <summary>
        /// Generates the correct node based on metadata contained in serialized vertex data
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="nodeData">The node data.</param>
        /// <returns>Experiment node</returns>
        private ExperimentNode NodeGenerator(string id, SerializedVertexData nodeData)
        {
            if (id == null)
                throw new ArgumentNullException("id");
            if (nodeData == null)
                throw new ArgumentNullException("nodeData");

            ExperimentNode node;

            if (nodeData.Metadata is StartNodeMetadata)
            {
                node = new ExperimentStartNode(id, nodeData);
            }
            else if (nodeData.Metadata is EndNodeMetadata)
            {
                node = new ExperimentEndNode(id, nodeData);
            }
            else if (nodeData.Metadata is DecisionMetadata)
            {
                node = new ExperimentDecisionNode(id, nodeData);
            }
            else if (nodeData.Metadata is ScopeMetadata)
            {
                node = new ScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is LoopScopeMetadata)
            {
                node = new LoopScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is CompositeComponentMetadata)
            {
                node = new CompositeComponentNode(id, nodeData);
            }
            else if (nodeData.Metadata is ExitDecisionMetadata)
            {
                node = new ExitDecisionNode(id, nodeData);
            }
            else
            {
                ComponentNode componentNode = new ComponentNode(id, nodeData);
                node = componentNode;
            }

            return node;
        }