Beispiel #1
0
        private DaggerLib.UI.AStar.AStar _createPathGrid(DaggerUIGraph uigraph, int grain, int diagonalCost)
        {
            int w = (int)((float)uigraph.CanvasSize.Width / (float)grain) + 1;
            int h = (int)((float)uigraph.CanvasSize.Height / (float)grain) + 1;

            DaggerLib.UI.AStar.AStar grid = new DaggerLib.UI.AStar.AStar(
                new Rectangle(0, 0, w, h),
                10,
                diagonalCost,
                new Point(w - 1, h - 1));

            foreach (DaggerUINode node in uigraph.AllNodes)
            {
                int top    = (int)((float)(node.Top - uigraph.AutoScrollPosition.Y) / (float)grain);
                int left   = (int)((float)(node.Left - uigraph.AutoScrollPosition.X) / (float)grain);
                int right  = (int)((float)(node.Right - uigraph.AutoScrollPosition.X) / (float)grain + 1);
                int bottom = (int)((float)(node.Bottom - uigraph.AutoScrollPosition.Y) / (float)grain + 1);

                if (top < 0 || bottom > h || left < 0 || right > w)
                {
                    //autoscroll has jumped the gun on updating the node positions
                    return(null);
                }

                for (int u = left; u < right; u++)
                {
                    for (int v = top; v < bottom; v++)
                    {
                        grid[u, v].CellCost = int.MaxValue;
                    }
                }
            }

            // increase the cost of the imported/exported pin regions
            if (uigraph.Graph.ImportedPins.Count > 0)
            {
                int right = (int)((float)((uigraph.Graph.ImportedPins[0].PinUIElements as PinUI).PinLocation.X) / (float)grain + 1);
                for (int u = 0; u < right; u++)
                {
                    for (int v = 0; v < grid.Size.Height; v++)
                    {
                        grid[u, v].CellCost = int.MaxValue;
                    }
                }
            }

            if (uigraph.Graph.ExportedPins.Count > 0)
            {
                int left = (int)((float)((uigraph.Graph.ExportedPins[0].PinUIElements as PinUI).PinLocation.X) / (float)grain);
                for (int u = left; u <= grid.Size.Width; u++)
                {
                    for (int v = 0; v < grid.Size.Height; v++)
                    {
                        grid[u, v].CellCost = int.MaxValue;
                    }
                }
            }

            return(grid);
        }
Beispiel #2
0
        /// <summary>
        /// Event that is raised when the Edit SubNode Caption button is toggled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _editSubNodeButton_StateChanged(object sender, EventArgs e)
        {
            if (_editSubNodeButton.State)
            {
                if (_subNodeUIGraph == null)
                {
                    // create the ui graph for the SubNode
                    _subNodeUIGraph         = new DaggerUIGraph(_node.SubNodeGraph, (ParentUIGraph as DaggerUIGraph).PinLegend);
                    _subNodeUIGraph.Visible = true;
                    _subNodeUIGraph.Dock    = DockStyle.Fill;
                    _internalControl.Controls.Add(_subNodeUIGraph);

                    // copy the settings of the parent ui graph
                    (ParentUIGraph as DaggerUIGraph).CopySettings(_subNodeUIGraph);
                }

                //expand node for editing
                InternalControl.Visible = true;
                Size      = _subNodeUIGraph.OccupiedRegion.Size;
                Resizable = true;
            }
            else
            {
                //collapse node
                InternalControl.Visible = false;
                Resizable = false;
                Size      = NodeMinimumSize;
            }
        }
        void tmi_MouseEnter(object sender, EventArgs e)
        {
            DaggerUIGraph uigraph = (Tag as DaggerBasePin).ParentNode.ParentGraph.ParentUIGraph as DaggerUIGraph;
            PinConnection con     = con = (PinConnection)(sender as ToolStripMenuItem).Tag;

            uigraph._trackingConnectPin = new DraggingNoodle(con.InputPin, con.OutputPin);
            uigraph.Invalidate(false);
        }
Beispiel #4
0
 public DaggerNoodleContainer(DaggerUIGraph uigraph, NoodleStyle style)
 {
     _uigraph = uigraph;
     _noodles = new List <DaggerNoodle>();
 }
        protected override void OnOpening(System.ComponentModel.CancelEventArgs e)
        {
            base.OnOpening(e);

            //clear out the existing items and rebuild the menu to specs
            Items.Clear();

            bool itemsAdded = false;

            DaggerBasePin pin = Tag as DaggerBasePin;

            if (pin.IsConnected)
            {
                Items.Add(_disconnectMenuItem);
                itemsAdded = true;
            }
            else if (pin.ParentNode != null)
            {
                DaggerUIGraph parentui = pin.ParentNode.ParentGraph.ParentUIGraph as DaggerUIGraph;

                // can we set the value?
                if (parentui.AllowPinSetValue)
                {
                    Items.Add(_setpropertyMenuItem);
                    itemsAdded = true;
                }

                // can we export?
                if (parentui.AllowPinExport)
                {
                    Items.Add(_exportMenuItem);
                    itemsAdded = true;
                }
            }

            // build the "Connect to" list
            if ((pin is DaggerOutputPin && (pin as DaggerOutputPin).AllowMultiConnect) ||
                (pin is DaggerOutputPin && !(pin as DaggerOutputPin).AllowMultiConnect && !pin.IsConnected) ||
                (pin is DaggerInputPin && !pin.IsConnected))
            {
                _attachToPinMenuItem.DropDownItems.Clear();

                DaggerNode myNode = pin.ParentNode;

                foreach (DaggerNode node in pin.ParentNode.ParentGraph.AllNodes)
                {
                    if (node != myNode)
                    {
                        if (pin is DaggerInputPin)
                        {
                            if (node.Ordinal <= myNode.Ordinal || node.SubgraphAffiliation != myNode.SubgraphAffiliation)
                            {
                                foreach (DaggerOutputPin outpin in node.OutputPins.MutexAvailablePins)
                                {
                                    if ((!outpin.IsConnected || outpin.AllowMultiConnect) && outpin.IsCompatibleDataTypes((DaggerInputPin)pin, (DaggerOutputPin)outpin))
                                    {
                                        ToolStripMenuItem tmi = new ToolStripMenuItem();
                                        tmi.Text                  = node.UINode.CaptionText + ": " + outpin.Name;
                                        tmi.Tag                   = new PinConnection(outpin, (DaggerInputPin)pin);
                                        tmi.DisplayStyle          = ToolStripItemDisplayStyle.ImageAndText;
                                        tmi.Image                 = (outpin.PinUIElements as PinUI).PinImageDisconnected;
                                        tmi.ImageTransparentColor = (outpin.PinUIElements as PinUI).PinImageDisconnectedTransparent;
                                        tmi.MouseEnter           += new EventHandler(tmi_MouseEnter);
                                        tmi.MouseLeave           += new EventHandler(tmi_MouseLeave);
                                        tmi.Click                += new EventHandler(tmi_Click);
                                        _attachToPinMenuItem.DropDownItems.Add(tmi);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (node.Ordinal >= myNode.Ordinal || node.SubgraphAffiliation != myNode.SubgraphAffiliation)
                            {
                                foreach (DaggerInputPin inpin in node.InputPins.MutexAvailablePins)
                                {
                                    if (!inpin.IsConnected && inpin.IsCompatibleDataTypes((DaggerInputPin)inpin, (DaggerOutputPin)pin))
                                    {
                                        ToolStripMenuItem tmi = new ToolStripMenuItem();
                                        tmi.Text                  = node.UINode.CaptionText + ": " + inpin.Name;
                                        tmi.Tag                   = new PinConnection((DaggerOutputPin)pin, inpin);
                                        tmi.DisplayStyle          = ToolStripItemDisplayStyle.ImageAndText;
                                        tmi.Image                 = (inpin.PinUIElements as PinUI).PinImageDisconnected;
                                        tmi.ImageTransparentColor = (inpin.PinUIElements as PinUI).PinImageDisconnectedTransparent;
                                        tmi.MouseEnter           += new EventHandler(tmi_MouseEnter);
                                        tmi.MouseLeave           += new EventHandler(tmi_MouseLeave);
                                        tmi.Click                += new EventHandler(tmi_Click);
                                        _attachToPinMenuItem.DropDownItems.Add(tmi);
                                    }
                                }
                            }
                        }
                    }
                }

                if (_attachToPinMenuItem.DropDownItems.Count > 0)
                {
                    Items.Add(_attachToPinMenuItem);
                    itemsAdded = true;
                }
            }

            //merge the pin's user defined context menu
            if ((pin.PinUIElements as PinUI).ContextMenuStrip != null)
            {
                if (itemsAdded)
                {
                    Items.Add(_seperator);
                }

                // simulate a sync root on the MenuItemCollection
                ToolStripMenuItem[] tia = new ToolStripMenuItem[(pin.PinUIElements as PinUI).ContextMenuStrip.Items.Count];
                (pin.PinUIElements as PinUI).ContextMenuStrip.Items.CopyTo(tia, 0);
                for (int i = 0; i < tia.Length; i++)
                {
                    Items.Add(tia[i]);
                }
                itemsAdded = true;
            }

            //if we didn't add anything, don't show it
            e.Cancel = !itemsAdded;
        }
Beispiel #6
0
 public Selector(DaggerUIGraph graph)
 {
     _tracking        = false;
     _selectedNodes   = new List <IDaggerUINode>(graph.AllNodes);
     _selectedNoodles = new List <IDaggerNoodle>(graph.AllNoodles);
 }