private void addNodeButton_MouseDown(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { Type nodeType = (sender as ToolStripItem).Tag as Type; MyNodeView newNodeView = MyNodeView.CreateNodeView(nodeType, Desktop); DragDropEffects result = DoDragDrop(newNodeView, DragDropEffects.Copy); if (result == DragDropEffects.Copy) { MyNode newNode = m_mainForm.Project.CreateNode(nodeType); Target.AddChild(newNode); // TODO: Change to all transforms if (newNode is MyWorkingNode) { (newNode as MyWorkingNode).EnableAllTasks(); } newNodeView.Node = newNode; newNodeView.UpdateView(); newNodeView.OnEndDrag(); GraphLayoutForm_Enter(sender, EventArgs.Empty); } } }
private void Desktop_NodeRemoving(object sender, AcceptNodeEventArgs e) { e.Cancel = TestIfInsideSimulation(); MyNodeView nodeView = e.Node as MyNodeView; e.Cancel |= nodeView.Node is MyParentInput || nodeView.Node is MyOutput; }
private void Desktop_DoubleClick(object sender, EventArgs e) { MyNodeView nodeView = Desktop.FocusElement as MyNodeView; if (nodeView != null && nodeView.Node is MyNodeGroup) { m_mainForm.OpenGraphLayout(nodeView.Node as MyNodeGroup); } }
private void Desktop_NodeRemoving(object sender, AcceptNodeEventArgs e) { e.Cancel = CanChangeGraph(); // Suppress state saving - connections will get removed which would generate multiple steps. m_mainForm.SuppressStateSaving = true; MyNodeView nodeView = e.Node as MyNodeView; e.Cancel |= nodeView.Node is MyParentInput || nodeView.Node is MyOutput; }
private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { MyNodeView nodeView = null; foreach (GraphLayoutForm graphView in m_mainForm.GraphViews.Values) { if (graphView.Desktop.FocusElement is MyNodeView && (graphView.Desktop.FocusElement as MyNodeView).Node == propertyGrid.SelectedObject) { nodeView = graphView.Desktop.FocusElement as MyNodeView; nodeView.UpdateView(); } if (propertyGrid.SelectedObject is MyNodeGroup && graphView.Target == propertyGrid.SelectedObject) { graphView.Text = graphView.Target.Name; } graphView.Desktop.Invalidate(); } if (nodeView != null) { if (nodeView.BranchChangeNeeded) { if (nodeView.OutputBranchChangeNeeded) { m_mainForm.CloseObservers(nodeView.Node); } if (nodeView.Node is MyNodeGroup) { m_mainForm.ReloadGraphLayout(nodeView.Node as MyNodeGroup); } (nodeView as MyVariableBranchView).UpdateBranches(); } } propertyGrid.Refresh(); if (Target is MyNode) { UpdateTitleAndButtons(); m_mainForm.MemoryBlocksView.UpdateView(); } if (Target is MyAbstractObserver && m_mainForm.SimulationHandler.State == MySimulationHandler.SimulationState.PAUSED) { m_mainForm.UpdateObserverView(Target as MyAbstractObserver); } }
private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { //TODO: rewrite this, no need to loop all, just topmost foreach (GraphLayoutForm graphView in m_mainForm.GraphViews.Values) { if (graphView.Desktop.FocusElement is MyNodeView) { MyNodeView nodeView = graphView.Desktop.FocusElement as MyNodeView; nodeView.UpdateView(); } graphView.Desktop.Invalidate(); } }
private void addNodeButton_MouseDown(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return; } Type nodeType = (sender as ToolStripItem).Tag as Type; MyNodeView newNodeView = MyNodeView.CreateNodeView(nodeType, Desktop); var dataObject = new DataObject(); dataObject.SetData(typeof(MyNodeView), newNodeView); // required to get derived types from GetData DragDropEffects result = DoDragDrop(dataObject, DragDropEffects.Copy); if (result != DragDropEffects.Copy) { return; } MyNode newNode = m_mainForm.Project.CreateNode(nodeType); if (!TryAddChildNode(newNode)) { m_mainForm.Project.Network.RemoveChild(newNode); Desktop.RemoveNode(newNodeView); return; } // TODO: Change to all transforms if (newNode is MyWorkingNode) { (newNode as MyWorkingNode).EnableDefaultTasks(); } newNodeView.Node = newNode; newNodeView.UpdateView(); newNodeView.OnEndDrag(); EnterGraphLayout(); OnProjectStateChanged("Node added"); }
private void RestoreConnections(MyNode node, Dictionary <MyNode, MyNodeView> nodeViewTable) { MyNodeView toNodeView = nodeViewTable[node]; for (int i = 0; i < node.InputBranches; i++) { MyConnection connection = node.InputConnections[i]; if (connection != null) { MyNodeView fromNodeView = nodeViewTable[connection.From]; NodeItem fromNodeViewItem = fromNodeView.GetOuputBranchItem(connection.FromIndex); NodeConnection c = Desktop.Connect(fromNodeViewItem, toNodeView.GetInputBranchItem(connection.ToIndex)); c.Tag = connection; } } }
private void Desktop_ShowElementMenu(object sender, AcceptElementLocationEventArgs e) { NodeItem item = e.Element as NodeItem; if (item != null) { MyNodeView nodeView = item.Node as MyNodeView; if (nodeView != null) { MyNode node = nodeView.Node; openEditorToolStripMenuItem.Enabled = node is IScriptableNode; openGroupToolStripMenuItem.Enabled = node is MyNodeGroup; nodeContextMenuStrip.Tag = node; nodeContextMenuStrip.Show(e.Position); } } }
private void Desktop_DoubleClick(object sender, EventArgs e) { MyNodeView nodeView = Desktop.FocusElement as MyNodeView; if (nodeView != null) { MyNodeGroup group = nodeView.Node as MyNodeGroup; IScriptableNode scriptable = nodeView.Node as IScriptableNode; if (scriptable != null && group == null || scriptable != null && group != null && (Control.ModifierKeys & Keys.Shift) != 0) { m_mainForm.OpenTextEditor(scriptable); } else if (group != null) { m_mainForm.OpenGraphLayout(group); } } }
private void RestoreConnections(MyNode node, Dictionary <MyNode, MyNodeView> nodeViewTable) { MyNodeView toNodeView = nodeViewTable[node]; for (int i = 0; i < node.InputBranches; i++) { MyConnection connection = node.InputConnections[i]; if (connection != null) { MyNodeView fromNodeView = nodeViewTable[connection.From]; NodeItem fromNodeViewItem = fromNodeView.GetOuputBranchItem(connection.FromIndex); MyNodeViewConnection c = Desktop.Connect(fromNodeViewItem, toNodeView.GetInputBranchItem(connection.ToIndex)) as MyNodeViewConnection; Debug.Assert(c != null, "Invalid connection factory delegate"); c.Tag = connection; c.Hidden = connection.IsHidden; } } }
private void LoadContentIntoDesktop() { Dictionary <MyNode, MyNodeView> nodeViewTable = new Dictionary <MyNode, MyNodeView>(); //Global i/o for (int i = 0; i < Target.GroupInputNodes.Length; i++) { MyParentInput inputNode = Target.GroupInputNodes[i]; if (inputNode.Location == null) { inputNode.Location = new MyLocation() { X = 50, Y = 150 * i + 100 }; } MyNodeView inputView = MyNodeView.CreateNodeView(inputNode, Desktop); inputView.UpdateView(); Desktop.AddNode(inputView); nodeViewTable[inputNode] = inputView; } for (int i = 0; i < Target.GroupOutputNodes.Length; i++) { MyOutput outputNode = Target.GroupOutputNodes[i]; if (outputNode.Location == null) { outputNode.Location = new MyLocation() { X = 800, Y = 150 * i + 100 }; } MyNodeView outputView = MyNodeView.CreateNodeView(outputNode, Desktop); outputView.UpdateView(); Desktop.AddNode(outputView); nodeViewTable[outputNode] = outputView; } //other nodes foreach (MyNode node in Target.Children) { MyNodeView newNodeView = MyNodeView.CreateNodeView(node, Desktop); newNodeView.UpdateView(); Desktop.AddNode(newNodeView); nodeViewTable[node] = newNodeView; } foreach (MyNode outputNode in Target.GroupOutputNodes) { RestoreConnections(outputNode, nodeViewTable); } //other connections foreach (MyNode node in Target.Children) { RestoreConnections(node, nodeViewTable); } }