示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphViewModelService"/> class.
 /// </summary>
 public GraphViewModelService([NotNull] NodeContainer nodeContainer)
 {
     if (nodeContainer == null)
     {
         throw new ArgumentNullException(nameof(nodeContainer));
     }
     NodePresenterFactory = new NodePresenterFactory(nodeContainer.NodeBuilder, AvailableCommands, AvailableUpdaters);
     NodeViewModelFactory = new NodeViewModelFactory();
 }
        /// <summary>
        /// Creates the node according to the type using the factory method
        /// and add it to the view-model.
        /// </summary>
        /// <param name="name">Name of the the node</param>
        /// <param name="nodeLocation"></param>
        /// <param name="centerNode">Should the node be centered</param>
        /// <returns></returns>
        public NodeViewModel CreateNode(string name, Point nodeLocation, bool centerNode, bool hasLeftPath, bool hasRightPath)
        {
            var node = NodeViewModelFactory.Create(name, nodeLocation, hasLeftPath, hasRightPath);

            NodeViewModelFactory.AttachInputAndOutputConnectors(node, 2, 2);//This is preliminary to test things out

            if (centerNode)
            {
                CenterNode(node);
            }

            Network.Nodes.Add(node);

            return(node);
        }
        /// <summary>
        /// Creates and adds a view model for the inputted node and hooks up all relevant UI callbacks.
        /// </summary>
        /// <param name="node"></param>
        private NodeViewModel CreateNodeViewModel(SpeechNode node)
        {
            NodeViewModel nodeViewModel = NodeViewModelFactory.CreateViewModel(node);

            nodeViewModel.Changed.Subscribe(e =>
            {
                if (e.PropertyName == nameof(nodeViewModel.IsSelected))
                {
                    Editor.OpenEditorForObject(node);
                }
            });
            Network.Nodes.Add(nodeViewModel);

            return(nodeViewModel);
        }