Exemplo n.º 1
0
        /// <summary>
        /// Unlink the node removing it from its origin linked nodes list and restore it to its
        /// original node class.
        /// </summary>
        public void UnlinkNode()
        {
            LinkedNodeViewModel linkedNode = (LinkedNodeViewModel)this;

            linkedNode.Origin.LinkedNodes.Remove(linkedNode);

            NestedConfigNode parent = (NestedConfigNode)linkedNode.m_parent;

            ConfigNodeViewModel unlinkedNode = getInstance(m_parentExperiment, parent,
                                                           linkedNode.nodeDefinition, m_parentExperiment.AppName);

            // Keep the content of the former ogirin node
            if (!(linkedNode.Origin is ForkedNodeViewModel))
            {
                unlinkedNode.content = linkedNode.Origin.content;
            }
            else
            {
                ForkedNodeViewModel forkedNode = (ForkedNodeViewModel)linkedNode.LinkedNode;
                int valueIndex           = int.Parse(forkedNode.currentValueIndex.Substring(0, 1)) - 1;
                ForkValueViewModel value = (ForkValueViewModel)forkedNode.children[valueIndex];
                unlinkedNode.content = value.configNode.content;
            }
            // For node substitution We don't need the index in the whole tree just
            // the index in the parent children list
            int index = parent.children.IndexOf(linkedNode);

            parent.children.Remove(linkedNode);
            parent.children.Insert(index, unlinkedNode);

            unlinkedNode.CanBeLinked = true;
            unlinkedNode.IsLinkable  = false;
        }
Exemplo n.º 2
0
        public void RemoveSelectedValue()
        {
            //we don't remove the value if there is no other value
            if (children.Count == 1)
            {
                return;
            }

            ForkValueViewModel removedValue = selectedForkValue;
            int index = children.IndexOf(selectedForkValue);

            if (index == children.Count - 1)
            {
                selectedForkValue = children[index - 1] as ForkValueViewModel;
            }
            else
            {
                selectedForkValue = children[index + 1] as ForkValueViewModel;
            }

            children.Remove(removedValue);

            renameValues();
            updateBoolFlags();
            m_parentExperiment.updateNumForkCombinations();
        }
Exemplo n.º 3
0
        public void AddValue()
        {
            string             newValueName = "Value-" + children.Count;
            ForkValueViewModel newForkValue = new ForkValueViewModel(newValueName, this, selectedValueConfigNode.clone());

            children.Add(newForkValue);
            updateBoolFlags();
            m_parentExperiment.updateNumForkCombinations();
        }
        //Constructor used from the experiment editor
        public ForkedNodeViewModel(AppViewModel appViewModel,ConfigNodeViewModel forkedNode)
        {
            m_parent = forkedNode.parent;

            ForkValueViewModel newForkValue= new ForkValueViewModel("Value-0", this, forkedNode);
            children.Add(newForkValue);
            selectedForkValue = newForkValue;

            m_appViewModel = appViewModel;
            nodeDefinition = forkedNode.nodeDefinition;
            name = forkedNode.name;
            NotifyOfPropertyChange(() => selectedForkValue);
        }
Exemplo n.º 5
0
        //Constructor used from the experiment editor
        public ForkedNodeViewModel(AppViewModel appViewModel, ConfigNodeViewModel forkedNode)
        {
            m_parent = forkedNode.parent;

            ForkValueViewModel newForkValue = new ForkValueViewModel("Value-0", this, forkedNode);

            children.Add(newForkValue);
            selectedForkValue = newForkValue;

            m_appViewModel = appViewModel;
            nodeDefinition = forkedNode.nodeDefinition;
            name           = forkedNode.name;
            NotifyOfPropertyChange(() => selectedForkValue);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Link nodes when experiment is loaded from a file. This has to be done once all nodes
        /// are loaded.
        /// </summary>
        private void LinkNodes()
        {
            var nodeStack = new Stack <ConfigNodeViewModel>(new[] { children[0] });

            while (nodeStack.Any())
            {
                ConfigNodeViewModel node = nodeStack.Pop();

                if (node is LinkedNodeViewModel)
                {
                    LinkedNodeViewModel linkedNode = (LinkedNodeViewModel)node;
                    linkedNode.Origin = DepthFirstSearch(linkedNode.OriginName, linkedNode.OriginAlias);

                    linkedNode.CreateLinkedNode();
                    linkedNode.LinkedNode.IsLinkable  = false;
                    linkedNode.LinkedNode.IsLinked    = true;
                    linkedNode.LinkedNode.IsNotLinked = false;
                    // Add the node to origin linked nodes give the functionality to reflect content
                    // changes of in all linked nodes
                    linkedNode.Origin.LinkedNodes.Add(linkedNode.LinkedNode);

                    if (linkedNode.Origin is ForkedNodeViewModel)
                    {
                        ForkedNodeViewModel forkedOrigin = (ForkedNodeViewModel)linkedNode.Origin;
                        int len = forkedOrigin.children.Count;

                        for (int i = 0; i < len; i++)
                        {
                            ForkedNodeViewModel linkedFork      = (ForkedNodeViewModel)linkedNode.LinkedNode;
                            ForkValueViewModel  linkedForkValue = (ForkValueViewModel)linkedFork.children[i];
                            ((ForkValueViewModel)forkedOrigin.children[i]).configNode.LinkedNodes
                            .Add(linkedForkValue.configNode);
                            linkedForkValue.configNode.name           = linkedNode.name;
                            linkedForkValue.configNode.comment        = linkedNode.comment;
                            linkedForkValue.configNode.nodeDefinition = linkedNode.nodeDefinition;
                        }
                    }
                }

                WalkThroughBranch(ref nodeStack, node);
            }
        }
Exemplo n.º 7
0
        //Constructor used from the experiment editor
        public ForkedNodeViewModel(ExperimentViewModel parentExperiment, ConfigNodeViewModel forkedNode)
        {
            m_parent = forkedNode.parent;

            ForkValueViewModel newForkValue = new ForkValueViewModel("Value-0", this, forkedNode);

            children.Add(newForkValue);

            selectedForkValue = newForkValue;

            m_parentExperiment = parentExperiment;
            nodeDefinition     = forkedNode.nodeDefinition;
            name = forkedNode.name;
            NotifyOfPropertyChange(() => selectedForkValue);

            //register this fork
            m_parentExperiment.forkRegistry.Add(this);

            //we set the alias AFTER adding the fork to the registry to make sure that validation is properly done
            alias = forkedNode.name;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Actually perform the linking with the node.
        /// </summary>
        /// <param name="targetNode"></param>
        public void Link(ConfigNodeViewModel targetNode)
        {
            var linkedNode = new LinkedNodeViewModel(m_parentExperiment,
                                                     m_parentExperiment.LinkOriginNode, targetNode);

            var node = m_parentExperiment.DepthFirstSearch(targetNode);

            NestedConfigNode parent = (NestedConfigNode)node.m_parent;
            // For node substitution we just need the index in the parent children list
            int index = parent.children.IndexOf(node);

            parent.children.Remove(node);
            parent.children.Insert(index, linkedNode);

            m_parentExperiment.LinkOriginNode.LinkedNodes.Add(linkedNode.LinkedNode);
            // If the origin is a ForkedNode we also need to link the fork values inside
            // this is for content changes reflection.
            if (m_parentExperiment.LinkOriginNode is ForkedNodeViewModel)
            {
                ForkedNodeViewModel forkedOrigin = (ForkedNodeViewModel)m_parentExperiment.LinkOriginNode;
                int len = forkedOrigin.children.Count;

                for (int i = 0; i < len; i++)
                {
                    ForkedNodeViewModel linkedFork      = (ForkedNodeViewModel)linkedNode.LinkedNode;
                    ForkValueViewModel  linkedForkValue = (ForkValueViewModel)linkedFork.children[i];
                    ((ForkValueViewModel)forkedOrigin.children[i]).configNode.LinkedNodes
                    .Add(linkedForkValue.configNode);
                    linkedForkValue.configNode.name           = targetNode.name;
                    linkedForkValue.configNode.comment        = targetNode.comment;
                    linkedForkValue.configNode.nodeDefinition = targetNode.nodeDefinition;
                }
            }

            linkedNode.LinkedNode.IsLinkable  = false;
            linkedNode.LinkedNode.IsLinked    = true;
            linkedNode.LinkedNode.IsNotLinked = false;
        }
Exemplo n.º 9
0
        public override void setForkCombination(ref int id, ref string combinationName)
        {
            int valueId = 0;
            ForkValueViewModel currentValue = children[0] as ForkValueViewModel;

            //set the correct value for this fork

            if (getNumForkCombinations() != children.Count)
            {
                //at least there's one fork beneath this one
                while (valueId < children.Count - 1 && currentValue != null && id >= currentValue.getNumForkCombinations())
                {
                    id -= currentValue.getNumForkCombinations();
                    ++valueId;
                    if (valueId < children.Count)
                    {
                        currentValue = children[valueId] as ForkValueViewModel;
                    }
                }
            }
            else
            {
                //leaf
                valueId      = id % children.Count;
                id           = id / children.Count;
                currentValue = children[valueId] as ForkValueViewModel;
            }

            combinationName  += "-" + valueId;
            selectedForkValue = currentValue;

            //set correct values for child forked nodes
            if (currentValue.getNumForkCombinations() > 1)
            {
                currentValue.setForkCombination(ref id, ref combinationName);
            }
        }
Exemplo n.º 10
0
 public void addValue()
 {
     string newValueName= "Value-" + children.Count;
     ForkValueViewModel newForkValue = new ForkValueViewModel(newValueName,this,selectedValueConfigNode.clone());
     children.Add(newForkValue);
     updateBoolFlags();
     m_appViewModel.updateNumForkCombinations();
 }