示例#1
0
        internal static bool IsUpstreamOf(this NodeModel node, NodeModel otherNode)
        {
            var gathered = new List<NodeModel>();
            otherNode.AllUpstreamNodes(gathered);

            return gathered.Contains(node);
        }
示例#2
0
        // Reverse post-order to sort nodes
        private static void MarkNode(NodeModel node, Dictionary<NodeModel, MarkFlag> nodeFlags, Stack<NodeModel> sortedList)
        {
            MarkFlag flag;
            if (!nodeFlags.TryGetValue(node, out flag))
            {
                flag = MarkFlag.NoMark;
                nodeFlags[node] = flag;
            }

            if (MarkFlag.TempMark == flag)
                return;

            if (MarkFlag.NoMark == flag)
            {
                nodeFlags[node] = MarkFlag.TempMark;

                IEnumerable<NodeModel> outputs =
                    node.Outputs.Values.SelectMany(set => set.Select(t => t.Item2)).Distinct();
                foreach (NodeModel output in outputs)
                    MarkNode(output, nodeFlags, sortedList);

                nodeFlags[node] = MarkFlag.Marked;
                sortedList.Push(node);
            }
        }
示例#3
0
 private void AssertLocationValues(NodeModel locNode, Document doc)
 {
     var locValue = GetPreviewValue(locNode.GUID.ToString()) as Location;
     Assert.AreEqual(locValue.Name, doc.SiteLocation.PlaceName);
     Assert.AreEqual(locValue.Latitude, doc.SiteLocation.Latitude.ToDegrees(), 0.001);
     Assert.AreEqual(locValue.Longitude, doc.SiteLocation.Longitude.ToDegrees(), 0.001);
 }
        /// <summary>
        /// Call this method to determine if the task should be scheduled for 
        /// execution.
        /// </summary>
        /// <param name="workspaceModel">Render packages for all the nodes in 
        /// this workspaceModel will be extracted, if 'nodeModel' parameter is 
        /// null.</param>
        /// <param name="nodeModel">An optional NodeModel from which all upstream 
        /// nodes are to be examined for render packages. If this parameter is 
        /// null, render packages are extracted from all nodes in workspaceModel.
        /// </param>
        /// <returns>Returns true if the task should be scheduled for execution,
        /// or false otherwise.</returns>
        /// 
        internal bool Initialize(WorkspaceModel workspaceModel, NodeModel nodeModel)
        {
            if (workspaceModel == null)
                throw new ArgumentNullException("workspaceModel");

            if (nodeModel == null) // No node is specified, gather all nodes.
            {
                targetedNodeId = Guid.Empty;

                // Duplicate a list of all nodes for consumption later.
                var nodes = workspaceModel.Nodes.Where(n => n.IsVisible);
                duplicatedNodeReferences = nodes.ToList();
            }
            else
            {
                targetedNodeId = nodeModel.GUID;

                // Recursively gather all upstream nodes. Stop 
                // gathering if this node does not display upstream.
                var gathered = new List<NodeModel>();
                WorkspaceUtilities.GatherAllUpstreamNodes(nodeModel,
                    gathered, model => model.IsUpstreamVisible);

                duplicatedNodeReferences = gathered;
            }

            return duplicatedNodeReferences.Any();
        }
        /// <summary>
        /// Call this method to determine if the task should be scheduled for 
        /// execution.
        /// </summary>
        /// <param name="workspaceModel">Render packages for all the nodes in 
        /// this workspaceModel will be extracted, if 'nodeModel' parameter is 
        /// null.</param>
        /// <param name="nodeModel">An optional NodeModel from which all upstream 
        /// nodes are to be examined for render packages. If this parameter is 
        /// null, render packages are extracted from all nodes in workspaceModel.
        /// </param>
        /// <returns>Returns true if the task should be scheduled for execution,
        /// or false otherwise.</returns>
        /// 
        internal bool Initialize(WorkspaceModel workspaceModel, NodeModel nodeModel)
        {
            if (workspaceModel == null)
                throw new ArgumentNullException("workspaceModel");

            if (nodeModel == null) // No node is specified, gather all nodes.
            {
                NodeId = Guid.Empty;

                // Duplicate a list of all nodes for consumption later.
                duplicatedNodeReferences = workspaceModel.Nodes.ToList();
            }
            else
            {
                NodeId = nodeModel.GUID;

                // Recursively gather all upstream nodes.
                var gathered = new List<NodeModel>();
                GatherAllUpstreamNodes(nodeModel, gathered);
                duplicatedNodeReferences = gathered;
            }

            Debug.WriteLine(string.Format("Aggregation task initialized for {0}", nodeModel == null?"null":nodeModel.GUID.ToString()));
            return duplicatedNodeReferences.Any();
        }
 public ExportWithUnitsViewModel(ExportWithUnits model, NodeView nodeView)
 {
     exportWithUnitsModel = model;           
     nodeViewModel = nodeView.ViewModel;
     nodeModel = nodeView.ViewModel.NodeModel;
     model.PropertyChanged +=model_PropertyChanged;      
 }
示例#7
0
        public NodeViewModel(NodeModel logic)
        {
            nodeLogic = logic;

            //respond to collection changed events to sadd
            //and remove port model views
            logic.InPorts.CollectionChanged += inports_collectionChanged;
            logic.OutPorts.CollectionChanged += outports_collectionChanged;

            logic.PropertyChanged += logic_PropertyChanged;
            dynSettings.Controller.DynamoViewModel.Model.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Model_PropertyChanged);
            dynSettings.Controller.PropertyChanged += Controller_PropertyChanged;

            this.ErrorBubble = new InfoBubbleViewModel();
            this.PreviewBubble = new InfoBubbleViewModel();
            this.PreviewBubble.PropertyChanged += PreviewBubble_PropertyChanged;

            //Do a one time setup of the initial ports on the node
            //we can not do this automatically because this constructor
            //is called after the node's constructor where the ports
            //are initially registered
            SetupInitialPortViewModels();

            //dynSettings.Controller.RequestNodeSelect += new NodeEventHandler(Controller_RequestNodeSelect);
        }
示例#8
0
 public NodeHelpPrompt(NodeModel node)
 {
     this.DataContext = node;
     this.Owner = WPF.FindUpVisualTree<DynamoView>(this);
     //this.Owner = dynSettings.Bench;
     this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
     InitializeComponent();
 }
示例#9
0
 /// <summary>
 /// Validates the watch content with the source nodes output.
 /// </summary>
 /// <param name="watch">WatchViewModel of the watch node</param>
 /// <param name="sourceNode">NodeModel for source to watch node</param>
 public void AssertWatchContent(WatchViewModel watch, NodeModel sourceNode)
 {
     string var = sourceNode.GetAstIdentifierForOutputIndex(0).Name;
     RuntimeMirror mirror = null;
     Assert.DoesNotThrow(() => mirror = ViewModel.Model.EngineController.GetMirror(var));
     Assert.IsNotNull(mirror);
     AssertWatchContent(watch, mirror.GetData());
 }
示例#10
0
        public PortViewModel(PortModel port, NodeModel node)
        {
            _node = node;
            _port = port;

            _port.PropertyChanged += _port_PropertyChanged;
            _node.PropertyChanged += _node_PropertyChanged;
        }
示例#11
0
        protected override void InitializeInputs(NodeModel model)
        {
            model.InPortData.Clear();

            if (Definition.Parameters == null) return;

            foreach (string arg in Definition.Parameters)
                model.InPortData.Add(new PortData(arg, "parameter"));
        }
示例#12
0
 /// <summary>
 /// Factory method to create a connector.  Checks to make sure that the start and end ports are valid, 
 /// otherwise returns null.
 /// </summary>
 /// <param name="start">The port where the connector starts</param>
 /// <param name="end">The port where the connector ends</param>
 /// <param name="startIndex"></param>
 /// <param name="endIndex"></param>
 /// <param name="portType"></param>
 /// <returns>The valid connector model or null if the connector is invalid</returns>
 public static ConnectorModel Make(NodeModel start, NodeModel end, int startIndex, int endIndex, PortType portType)
 {
     if (start != null && end != null && start != end && startIndex >= 0
         && endIndex >= 0 && start.OutPorts.Count > startIndex && end.InPorts.Count > endIndex )
     {
         return new ConnectorModel(start, end, startIndex, endIndex, portType);
     }
     
     return null;
 }
示例#13
0
 /// <summary>
 /// Factory method to create a connector.  Checks to make sure that the start and end ports are valid, 
 /// otherwise returns null.
 /// </summary>
 /// <param name="start">The port where the connector starts</param>
 /// <param name="end">The port where the connector ends</param>
 /// <param name="startIndex"></param>
 /// <param name="endIndex"></param>
 /// <param name="portType"></param>
 /// <returns>The valid connector model or null if the connector is invalid</returns>
 internal static ConnectorModel Make(WorkspaceModel workspaceModel, NodeModel start, NodeModel end, int startIndex, int endIndex, PortType portType)
 {
     if (workspaceModel != null && start != null && end != null && start != end && startIndex >= 0
         && endIndex >= 0 && start.OutPorts.Count > startIndex && end.InPorts.Count > endIndex )
     {
         return new ConnectorModel(workspaceModel, start, end, startIndex, endIndex, portType);
     }
     
     return null;
 }
示例#14
0
 protected override void InitializeOutputs(NodeModel model)
 {
     model.OutPortData.Clear();
     if (Definition.ReturnKeys != null && Definition.ReturnKeys.Any())
     {
         foreach (string key in Definition.ReturnKeys)
             model.OutPortData.Add(new PortData(key, "return value"));
     }
     else
         model.OutPortData.Add(new PortData("", "return value"));
 }
示例#15
0
        private ConnectorModel(
            NodeModel start, NodeModel end, int startIndex, int endIndex, Guid guid)
        {
            GUID = guid;
            Start = start.OutPorts[startIndex];

            PortModel endPort = end.InPorts[endIndex];

            Start.Connect(this);
            Connect(endPort);
        }
示例#16
0
        /// <summary>
        /// Factory method to create a connector.  Checks to make sure that the start and end ports are valid, 
        /// otherwise returns null.
        /// </summary>
        /// <param name="start">The port where the connector starts</param>
        /// <param name="end">The port where the connector ends</param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <param name="guid"></param>
        /// <returns>The valid connector model or null if the connector is invalid</returns>
        internal static ConnectorModel Make(
            NodeModel start, NodeModel end, int startIndex, int endIndex, Guid? guid = null)
        {
            if (start != null && end != null && start != end && startIndex >= 0
                && endIndex >= 0 && start.OutPorts.Count > startIndex
                && end.InPorts.Count > endIndex)
            {
                return new ConnectorModel(start, end, startIndex, endIndex, guid ?? Guid.NewGuid());
            }

            return null;
        }
示例#17
0
        protected override AssociativeNode GetFunctionApplication(NodeModel model, List<AssociativeNode> inputAstNodes)
        {
            if (!model.IsPartiallyApplied)
                return AstFactory.BuildFunctionCall(Definition.FunctionName, inputAstNodes);

            var count = Definition.Parameters.Count();
            return AstFactory.BuildFunctionObject(
                Definition.FunctionName,
                count,
                Enumerable.Range(0, count).Where(model.HasInput),
                inputAstNodes);
        }
示例#18
0
        public DynamoSlider(NodeModel model, IViewModelView<NodeViewModel> nodeUI)
        {
            InitializeComponent();

            nodeModel = model;
            ui = nodeUI;

            slider.PreviewMouseUp += delegate
            {
                nodeUI.ViewModel.DynamoViewModel.ReturnFocusToSearch();
            };

        }
示例#19
0
        public DynamoSlider(NodeModel model, IViewModelView<NodeViewModel> nodeUI)
        {
            InitializeComponent();
            this.slider.IsMoveToPointEnabled = true;            
            nodeModel = model;
            ui = nodeUI;

            slider.PreviewMouseUp += delegate
            {
                nodeUI.ViewModel.DynamoViewModel.OnRequestReturnFocusToView();
            };

        }
示例#20
0
 protected override void AssignIdentifiersForFunctionCall(
     NodeModel model, AssociativeNode rhs, List<AssociativeNode> resultAst)
 {
     if (model.OutPortData.Count == 1)
     {
         resultAst.Add(AstFactory.BuildAssignment(model.AstIdentifierForPreview, rhs));
         resultAst.Add(
             AstFactory.BuildAssignment(
                 model.GetAstIdentifierForOutputIndex(0),
                 model.AstIdentifierForPreview));
     }
     else
         base.AssignIdentifiersForFunctionCall(model, rhs, resultAst);
 }
示例#21
0
        private ConnectorModel(WorkspaceModel workspaceModel, NodeModel start, NodeModel end, int startIndex, int endIndex, PortType portType)
        {
            this.workspaceModel = workspaceModel;

            pStart = start.OutPorts[startIndex];

            PortModel endPort = null;

            if (portType == PortType.INPUT)
                endPort = end.InPorts[endIndex];

            pStart.Connect(this);
            this.Connect(endPort);
        }
示例#22
0
        private ConnectorModel(NodeModel start, NodeModel end, int startIndex, int endIndex, PortType portType)
        {
            //Stopwatch sw = new Stopwatch();
            //sw.Start();
            pStart = start.OutPorts[startIndex];

            PortModel endPort = null;

            if (portType == PortType.INPUT)
                endPort = end.InPorts[endIndex];

            pStart.Connect(this);
            this.Connect(endPort);
            //sw.Stop();
            //Debug.WriteLine(string.Format("{0} elapsed for constructing connector.", sw.Elapsed));
        }
示例#23
0
        protected override void BuildAstForPartialMultiOutput(
            NodeModel model, AssociativeNode rhs, List<AssociativeNode> resultAst)
        {
            base.BuildAstForPartialMultiOutput(model, rhs, resultAst);

            var emptyList = AstFactory.BuildExprList(new List<AssociativeNode>());
            var previewIdInit = AstFactory.BuildAssignment(model.AstIdentifierForPreview, emptyList);

            resultAst.Add(previewIdInit);
            resultAst.AddRange(
                Definition.ReturnKeys.Select(
                    (rtnKey, idx) =>
                        AstFactory.BuildAssignment(
                            AstFactory.BuildIdentifier(
                                model.AstIdentifierForPreview.Name,
                                AstFactory.BuildStringNode(rtnKey)),
                            model.GetAstIdentifierForOutputIndex(idx))));
        }
示例#24
0
        internal static void GatherAllUpstreamNodes(NodeModel nodeModel,
            List<NodeModel> gathered, Predicate<NodeModel> match)
        {
            if ((nodeModel == null) || gathered.Contains(nodeModel))
                return; // Look no further, node is already in the list.

            gathered.Add(nodeModel); // Add to list first, avoiding re-entrant.
            if (!match(nodeModel)) // Determine if the search should proceed.
                return;

            foreach (var upstreamNode in nodeModel.InputNodes)
            {
                if (upstreamNode.Value == null)
                    continue;

                // Add all the upstream nodes found into the list.
                GatherAllUpstreamNodes(upstreamNode.Value.Item2, gathered, match);
            }
        }
示例#25
0
        public NodeViewModel(NodeModel logic)
        {
            nodeLogic = logic;

            //respond to collection changed events to sadd
            //and remove port model views
            logic.InPorts.CollectionChanged += inports_collectionChanged;
            logic.OutPorts.CollectionChanged += outports_collectionChanged;

            logic.PropertyChanged += logic_PropertyChanged;

            dynSettings.Controller.DynamoViewModel.Model.PropertyChanged += Model_PropertyChanged;
            dynSettings.Controller.PropertyChanged += Controller_PropertyChanged;

            this.ErrorBubble = new InfoBubbleViewModel();
            this.ErrorBubble.PropertyChanged += ErrorBubble_PropertyChanged;

            // Nodes mentioned in switch cases will not have preview bubble
            switch (nodeLogic.Name)
            {
                case "Number":
                    break;
                case "String":
                    break;
                case "Watch":
                    break;
                case "Watch 3D":
                    break;
                case "Boolean":
                    break;
                default:
                    this.PreviewBubble = new InfoBubbleViewModel();
                    this.PreviewBubble.PropertyChanged += PreviewBubble_PropertyChanged;
                    break;
            }
            //Do a one time setup of the initial ports on the node
            //we can not do this automatically because this constructor
            //is called after the node's constructor where the ports
            //are initially registered
            SetupInitialPortViewModels();

            //dynSettings.Controller.RequestNodeSelect += new NodeEventHandler(Controller_RequestNodeSelect);
        }
 /// <summary>
 ///     Produces AST for a partial function application of a multi-output function.
 /// </summary>
 /// <param name="model">NodeModel to produce AST for.</param>
 /// <param name="rhs">AST representing the partial application. This will need to be used to assign all output port identifiers.</param>
 /// <param name="resultAst">Result accumulator: add all new output AST to this list.</param>
 protected virtual void BuildAstForPartialMultiOutput(
     NodeModel model, AssociativeNode rhs, List<AssociativeNode> resultAst)
 {
     var missingAmt =
         Enumerable.Range(0, model.InPortData.Count).Count(x => !model.HasInput(x));
     var tmp =
         AstFactory.BuildIdentifier("__partial_" + model.GUID.ToString().Replace('-', '_'));
     resultAst.Add(AstFactory.BuildAssignment(tmp, rhs));
     resultAst.AddRange(
         (Definition.ReturnKeys ?? Enumerable.Empty<string>()).Select(
             AstFactory.BuildStringNode)
             .Select(
                 (rtnKey, index) =>
                     AstFactory.BuildAssignment(
                         model.GetAstIdentifierForOutputIndex(index),
                         AstFactory.BuildFunctionObject(
                             "__ComposeBuffered",
                             3,
                             new[] { 0, 1 },
                             new List<AssociativeNode>
                             {
                                 AstFactory.BuildExprList(
                                     new List<AssociativeNode>
                                     {
                                         AstFactory.BuildFunctionObject(
                                             "__GetOutput",
                                             2,
                                             new[] { 1 },
                                             new List<AssociativeNode>
                                             {
                                                 AstFactory.BuildNullNode(),
                                                 rtnKey
                                             }),
                                         tmp
                                     }),
                                 AstFactory.BuildIntNode(missingAmt),
                                 AstFactory.BuildNullNode()
                             }))));
 }
示例#27
0
        /// <summary>
        /// If all nodes that the node outputs to are in scopes list. I.e.,
        /// </summary>
        /// <param name="node"></param>
        /// <param name="scopes"></param>
        /// <returns></returns>
        private bool IsNodeInScope(NodeModel node, IEnumerable<NodeModel> scopes)
        {
            if (node is Symbol)
            {
                return false;
            }

            foreach (var index in Enumerable.Range(0, node.OutPortData.Count))
            {
                HashSet<Tuple<int, NodeModel>> outputTuples = null;
                if (!node.TryGetOutput(index, out outputTuples))
                {
                    continue;
                }

                if (!outputTuples.All(t => scopes.Contains(t.Item2)))
                {
                    return false;
                }
            }

            return true;
        }
示例#28
0
        internal void ShowElement(NodeModel e)
        {
            if (dynamicRun)
                return;

            if (!_model.Nodes.Contains(e))
            {
                if (_model.HomeSpace != null && _model.HomeSpace.Nodes.Contains(e))
                {
                    //Show the homespace
                    _model.ViewHomeWorkspace();
                }
                else
                {
                    foreach (CustomNodeDefinition funcDef in Controller.CustomNodeManager.GetLoadedDefinitions())
                    {
                        if (funcDef.WorkspaceModel.Nodes.Contains(e))
                        {
                            FocusCustomNodeWorkspace(funcDef);
                            break;
                        }
                    }
                }
            }

            var dvm = dynSettings.Controller.DynamoViewModel;
            dvm.CurrentSpaceViewModel.OnRequestCenterViewOnElement(this, new ModelEventArgs(e));
        }
示例#29
0
 protected virtual void OnRenderPackagesUpdated(NodeModel node, IEnumerable<IRenderPackage> packages)
 {
     AddGeometryForRenderPackages(packages);
 }
示例#30
0
 private void UnregisterPortEventHandlers(NodeModel node)
 {
     node.PortConnected -= PortConnectedHandler;
     node.PortDisconnected -= PortDisconnectedHandler;
 }