示例#1
0
 /// <summary>
 ///     Requests that a Node or Note model should be centered.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 internal virtual void OnRequestNodeCentered(object sender, ModelEventArgs e)
 {
     if (RequestNodeCentered != null)
         RequestNodeCentered(this, e);
 }
示例#2
0
        /// <summary>
        ///     Adds a node to this workspace.
        /// </summary>
        public void AddAndRegisterNode(NodeModel node, bool centered = false)
        {
            if (nodes.Contains(node))
                return;

            RegisterNode(node);

            if (centered)
            {
                var args = new ModelEventArgs(node, true);
                OnRequestNodeCentered(this, args);
            }

            AddNode(node);

            HasUnsavedChanges = true;

            RequestRun();
        }
示例#3
0
 public void AddNote(NoteModel note, bool centered)
 {
     if (centered)
     {
         var args = new ModelEventArgs(note, true);
         OnRequestNodeCentered(this, args);
     }
     AddNote(note);
 }
示例#4
0
 public virtual void OnRequestSelect(object sender, ModelEventArgs e)
 {
     if (RequestNodeSelect != null)
         RequestNodeSelect(sender, e);
 }
示例#5
0
 public virtual void OnRequestCenterViewOnElement(object sender, ModelEventArgs e)
 {
     if (RequestCenterViewOnElement != null)
         RequestCenterViewOnElement(this, e);
 }
示例#6
0
        internal NoteModel AddNoteInternal(DynCmd.CreateNoteCommand command, WorkspaceModel workspace)
        {
            double x = 0.0;
            double y = 0.0;
            if (false == command.DefaultPosition)
            {
                x = command.X;
                y = command.Y;
            }

            NoteModel noteModel = new NoteModel(x, y);
            noteModel.GUID = command.NodeId;

            //if we have null parameters, the note is being added
            //from the menu, center the view on the note

            if (command.DefaultPosition)
            {
                ModelEventArgs args = new ModelEventArgs(noteModel, true);
                DynamoViewModel vm = dynSettings.Controller.DynamoViewModel;
                vm.CurrentSpaceViewModel.OnRequestNodeCentered(this, args);
            }

            noteModel.Text = "New Note";
            if (!string.IsNullOrEmpty(command.NoteText))
                noteModel.Text = command.NoteText;

            if (null == workspace)
                workspace = CurrentWorkspace;

            workspace.Notes.Add(noteModel);
            return noteModel;
        }
示例#7
0
        /// <summary>
        /// Create a node with the given parameters. Since this method is called
        /// on an instance of DynamoModel, it also raises node added event to any
        /// event handlers, typically useful for real user scenario (listeners 
        /// may include package manager and other UI components).
        /// </summary>
        /// <param name="nodeId">The Guid to be used for the new node, it cannot
        /// be Guid.Empty since this method does not attempt to internally generate 
        /// a new Guid. An ArgumentException will be thrown if this argument is 
        /// Guid.Empty.</param>
        /// <param name="nodeName">The name of the node type to be created.</param>
        /// <param name="x">The x coordinates where the newly created node should 
        /// be placed. This value is ignored if useDefaultPos is true.</param>
        /// <param name="y">The y coordinates where the newly created node should 
        /// be placed. This value is ignored if useDefaultPos is true.</param>
        /// <param name="useDefaultPos">This parameter indicates if the node 
        /// should be created at the default position. If this parameter is true,
        /// the node is created at the center of view, and both x and y parameters
        /// are ignored. If this is false, the values for both x and y parameters 
        /// will be used as the initial position of the new node.</param>
        /// <param name="transformCoordinates">If this parameter is true, then the
        /// position of new node will be transformed from outerCanvas space into 
        /// zoomCanvas space.</param>
        /// <param name="xmlNode">This argument carries information that a node 
        /// may require for its creation. The new node loads itself from this 
        /// parameter if one is specified. This parameter is optional.</param>
        /// <returns>Returns the created NodeModel, or null if the operation has 
        /// failed.</returns>
        /// 
        private NodeModel CreateNodeInternal(
            Guid nodeId, string nodeName, double x, double y,
            bool useDefaultPos, bool transformCoordinates, XmlNode xmlNode)
        {
            if (nodeId == Guid.Empty)
                throw new ArgumentException("Node ID must be specified", "nodeId");

            NodeModel node = CreateNodeInstance(nodeName);
            if (node == null)
            {
                string format = "Failed to create node '{0}' (GUID: {1})";
                WriteToLog(string.Format(format, nodeName, nodeId));
                return null;
            }

            // Fix for: http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-4024
            // Various derived classes of NodeModel like CodeBlockNode, build 
            // their internal variables based on the node's GUID. In cases like 
            // this, a node's GUID must be finalized before variable generation 
            // logic kicks in.
            // 
            node.GUID = nodeId; // Set the node's GUID before anything else.

            if (useDefaultPos == false) // Position was specified.
            {
                node.X = x;
                node.Y = y;
            }

            CurrentWorkspace.Nodes.Add(node);
            node.WorkSpace = CurrentWorkspace;

            if (null != xmlNode)
                node.Load(xmlNode);

            DynamoViewModel viewModel = dynSettings.Controller.DynamoViewModel;
            WorkspaceViewModel workspaceViewModel = viewModel.CurrentSpaceViewModel;

            ModelEventArgs args = null;
            if (!useDefaultPos)
                args = new ModelEventArgs(node, x, y, transformCoordinates);
            else
            {
                // The position of the new node has not been specified.
                args = new ModelEventArgs(node, transformCoordinates);
            }

            DynamoViewModel vm = dynSettings.Controller.DynamoViewModel;
            vm.CurrentSpaceViewModel.OnRequestNodeCentered(this, args);

            node.EnableInteraction();

            if (CurrentWorkspace == HomeSpace)
                node.SaveResult = true;

            OnNodeAdded(node);
            return node;
        }
示例#8
0
        /// <summary>
        /// Create a node with the given parameters. Since this method is called
        /// on an instance of DynamoModel, it also raises node added event to any
        /// event handlers, typically useful for real user scenario (listeners 
        /// may include package manager and other UI components).
        /// </summary>
        /// <param name="nodeId">The Guid to be used for the new node, it cannot
        /// be Guid.Empty since this method does not attempt to internally generate 
        /// a new Guid. An ArgumentException will be thrown if this argument is 
        /// Guid.Empty.</param>
        /// <param name="nodeName">The name of the node type to be created.</param>
        /// <param name="x">The x coordinates where the newly created node should 
        /// be placed. This value is ignored if useDefaultPos is true.</param>
        /// <param name="y">The y coordinates where the newly created node should 
        /// be placed. This value is ignored if useDefaultPos is true.</param>
        /// <param name="useDefaultPos">This parameter indicates if the node 
        /// should be created at the default position. If this parameter is true,
        /// the node is created at the center of view, and both x and y parameters
        /// are ignored. If this is false, the values for both x and y parameters 
        /// will be used as the initial position of the new node.</param>
        /// <param name="transformCoordinates">If this parameter is true, then the
        /// position of new node will be transformed from outerCanvas space into 
        /// zoomCanvas space.</param>
        /// <param name="xmlNode">This argument carries information that a node 
        /// may require for its creation. The new node loads itself from this 
        /// parameter if one is specified. This parameter is optional.</param>
        /// <returns>Returns the created NodeModel, or null if the operation has 
        /// failed.</returns>
        /// 
        private NodeModel CreateNodeInternal(
            Guid nodeId, string nodeName, double x, double y,
            bool useDefaultPos, bool transformCoordinates, XmlNode xmlNode)
        {
            if (nodeId == Guid.Empty)
                throw new ArgumentException("Node ID must be specified", "nodeId");

            NodeModel node = CreateNodeInstance(nodeName);
            if (node == null)
            {
                string format = "Failed to create node '{0}' (GUID: {1})";
                WriteToLog(string.Format(format, nodeName, nodeId));
                return null;
            }

            if (useDefaultPos == false) // Position was specified.
            {
                node.X = x;
                node.Y = y;
            }

            if ((node is Symbol || node is Output) && CurrentWorkspace is HomeWorkspaceModel)
            {
                string format = "Cannot place '{0}' in HomeWorkspace (GUID: {1})";
                WriteToLog(string.Format(format, nodeName, nodeId));
                return null;
            }

            CurrentWorkspace.Nodes.Add(node);
            node.WorkSpace = CurrentWorkspace;

            if (null != xmlNode)
                node.Load(xmlNode, HomeSpace.WorkspaceVersion);

            // Override the guid so we can store for connection lookup
            node.GUID = nodeId;

            DynamoViewModel viewModel = dynSettings.Controller.DynamoViewModel;
            WorkspaceViewModel workspaceViewModel = viewModel.CurrentSpaceViewModel;

            ModelEventArgs args = null;
            if (!useDefaultPos)
                args = new ModelEventArgs(node, x, y, transformCoordinates);
            else
            {
                // The position of the new node has not been specified.
                args = new ModelEventArgs(node, transformCoordinates);
            }

            DynamoViewModel vm = dynSettings.Controller.DynamoViewModel;
            vm.CurrentSpaceViewModel.OnRequestNodeCentered(this, args);

            node.EnableInteraction();

            if (CurrentWorkspace == HomeSpace)
                node.SaveResult = true;

            OnNodeAdded(node);
            return node;
        }