Ejemplo n.º 1
0
        public static Region GetConnectionRegion(NodeConnection connection)
        {
            var pt1 = ConnectorInterfacePoint(connection.From);
            var pt2 = ConnectorInterfacePoint(connection.To);

            Region region;
            float  centerX;
            float  centerY;

            using (var linePath = GetArrowLinePath(pt1.X, pt1.Y, pt2.X, pt2.Y, out centerX, out centerY, true, 5.0f))
            {
                region = new Region(linePath);
            }
            return(region);
        }
Ejemplo n.º 2
0
        public bool Disconnect(NodeConnection connection)
        {
            if (connection == null)
            {
                return(false);
            }

            if (ConnectionRemoving != null)
            {
                var eventArgs = new AcceptNodeConnectionEventArgs(connection);
                ConnectionRemoving(this, eventArgs);
                if (eventArgs.Cancel)
                {
                    return(false);
                }
            }

            // if (HasFocus(connection))
            //     FocusElement = null;

            var from = connection.From;
            var to   = connection.To;

            if (from != null && from.Node != null)
            {
                from.Node.RemoveConnection(connection);
            }
            if (to != null && to.Node != null)
            {
                to.Node.RemoveConnection(connection);
            }

            // Just in case somebody stored it somewhere ..
            connection.From = null;
            connection.To   = null;

            if (ConnectionRemoved != null)
            {
                ConnectionRemoved(this, new NodeConnectionEventArgs(from, to, connection));
            }

            UpdateRevisionIndex();
            if (InvalidateViews != null)
            {
                InvalidateViews(this, EventArgs.Empty);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public static Region GetConnectionRegion(NodeConnection connection)
        {
            var        to   = connection.To;
            var        from = connection.From;
            RectangleF toBounds;
            RectangleF fromBounds;

            if (to.Node.Collapsed)
            {
                toBounds = to.Node.inputBounds;
            }
            else
            {
                toBounds = to.bounds;
            }
            if (from.Node.Collapsed)
            {
                fromBounds = from.Node.outputBounds;
            }
            else
            {
                fromBounds = from.bounds;
            }

            var pt1 = ConnectorInterfacePoint(fromBounds, ConnectorType.Output);
            var pt2 = ConnectorInterfacePoint(toBounds, ConnectorType.Input);

            Region region;
            float  centerX;
            float  centerY;

            using (var linePath = GetArrowLinePath(pt1.X, pt1.Y, pt2.X, pt2.Y, out centerX, out centerY, true, 5.0f))
            {
                region = new Region(linePath);
            }
            return(region);
        }
Ejemplo n.º 4
0
		public static Region GetConnectionRegion(NodeConnection connection)
		{
            var pt1 = ConnectorInterfacePoint(connection.From);
            var pt2 = ConnectorInterfacePoint(connection.To);

            Region region;
			float centerX;
			float centerY;
            using (var linePath = GetArrowLinePath(pt1.X, pt1.Y, pt2.X, pt2.Y, out centerX, out centerY, true, 5.0f))
			{
				region = new Region(linePath);
			}
			return region;
		}
Ejemplo n.º 5
0
        public bool Disconnect(NodeConnection connection)
        {
            if (connection == null)
                return false;

            if (ConnectionRemoving != null)
            {
                var eventArgs = new AcceptNodeConnectionEventArgs(connection);
                ConnectionRemoving(this, eventArgs);
                if (eventArgs.Cancel)
                    return false;
            }

            if (HasFocus(connection))
                FocusElement = null;

            var from	= connection.From;
            var to		= connection.To;
            if (from != null && from.Node != null)
            {
                from.Node.connections.Remove(connection);
            }
            if (to != null && to.Node != null)
            {
                to.Node.connections.Remove(connection);
            }

            // Just in case somebody stored it somewhere ..
            connection.From = null;
            connection.To = null;

            if (ConnectionRemoved != null)
                ConnectionRemoved(this, new NodeConnectionEventArgs(from, to, connection));

            this.Invalidate();
            return true;
        }
Ejemplo n.º 6
0
        public NodeConnection Connect(NodeConnector from, NodeConnector to, string name)
        {
            if (from != null)
            {
                foreach (var other in from.Node.Connections)
                {
                    if (other.From == from &&
                        other.To == to)
                        return null;
                }
            }

            if (to != null)
            {
                foreach (var other in to.Node.Connections)
                {
                    if (other.From == from &&
                        other.To == to)
                        return null;
                }
            }

            var connection = new NodeConnection();
            connection.From = from;
            connection.To = to;
            connection.Name = name;

            if (from != null)
                from.Node.AddConnection(connection);
            if (to != null)
                to.Node.AddConnection(connection);

            if (ConnectionAdded != null)
            {
                var eventArgs = new AcceptNodeConnectionEventArgs(connection);
                ConnectionAdded(this, eventArgs);
                if (eventArgs.Cancel)
                {
                    Disconnect(connection);
                    return null;
                }
            }

            UpdateRevisionIndex();
            if (InvalidateViews != null) 
                InvalidateViews(this, EventArgs.Empty);

            return connection;
        }
Ejemplo n.º 7
0
 public void RemoveConnection(NodeConnection connection)
 {
     connections.Remove(connection);
 }
Ejemplo n.º 8
0
        public static Region GetConnectionRegion(NodeConnection connection)
        {
            var to		= connection.To;
            var from	= connection.From;
            RectangleF toBounds;
            RectangleF fromBounds;
            if (to.Node.Collapsed)		toBounds = to.Node.inputBounds;
            else						toBounds = to.bounds;
            if (from.Node.Collapsed)	fromBounds = from.Node.outputBounds;
            else						fromBounds = from.bounds;

            var pt1 = ConnectorInterfacePoint(fromBounds, ConnectorType.Output);
            var pt2 = ConnectorInterfacePoint(toBounds, ConnectorType.Input);

            Region region;
            float centerX;
            float centerY;
            using (var linePath = GetArrowLinePath(pt1.X, pt1.Y, pt2.X, pt2.Y, out centerX, out centerY, true, 5.0f))
            {
                region = new Region(linePath);
            }
            return region;
        }
Ejemplo n.º 9
0
        void OnConnectorDoubleClick(object sender, HyperGraph.GraphControl.NodeConnectorEventArgs e)
        {
            var dialog = new HyperGraph.TextEditForm();
            dialog.InputText = "1.0f";

                //  look for an existing simple connection attached to this connector
            foreach(var i in e.Node.Connections)
            {
                if (i.To == e.Connector && i.From == null)
                    dialog.InputText = i.Name;
            }

            var result = dialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                bool foundExisting = false;
                foreach (var i in e.Node.Connections)
                    if (i.To == e.Connector && i.From == null)
                    {
                        i.Name = dialog.InputText;
                        foundExisting = true;
                    }

                if (!foundExisting)
                {
                    var connection = new NodeConnection();
                    connection.To = e.Connector;
                    connection.Name = dialog.InputText;
                    e.Node.AddConnection(connection);
                }

                ShaderFragmentNodeUtil.InvalidateAttachedConstants(graphControl);
            }
        }
Ejemplo n.º 10
0
 public NodeConnectionEventArgs(NodeConnection connection) { Connection = connection; From = connection.From; To = connection.To; }
Ejemplo n.º 11
0
 public AcceptNodeConnectionEventArgs(NodeConnection connection)
 {
     Connection = connection;
 }
Ejemplo n.º 12
0
 public NodeConnectionEventArgs(NodeConnector from, NodeConnector to, NodeConnection connection)
 {
     Connection = connection; From = from; To = to;
 }
Ejemplo n.º 13
0
 public NodeConnectionEventArgs(NodeConnection connection)
 {
     Connection = connection; From = connection.From; To = connection.To;
 }
Ejemplo n.º 14
0
 public AcceptNodeConnectionEventArgs(NodeConnection connection, bool cancel) : base(cancel)
 {
     Connection = connection;
 }
Ejemplo n.º 15
0
        public static void AddToHyperGraph(ShaderPatcherLayer.NodeGraph nodeGraph, HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
        {
            //
                //      Convert from the "ShaderPatcherLayer" representation back to
                //      our graph control nodes.
                //
                //      This is required for robust serialisation. We can't easily
                //      serialise in and out the graph control objects directly, because
                //      it risks problems if the rendering code or shader fragment objects
                //      change. That is, it's not very version-robust.
                //
                //      It's better to serialise a slightly higher level representation
                //      that just contains the node names and connections. That way, we
                //      can adapt to changes in the tool and data.
                //
            {
                    // --------< Basic Nodes >--------
                var newNodes = new Dictionary<int, Node>();
                var nodeIdToControlNode = new Dictionary<UInt64, Node>();
                foreach (var n in nodeGraph.Nodes)
                {
                    if (!newNodes.ContainsKey(n.VisualNodeId))
                    {
                        if (n.NodeType == ShaderPatcherLayer.Node.Type.Procedure)
                        {
                            var fn = ShaderFragmentArchive.Archive.GetFunction(n.FragmentArchiveName);
                            if (fn != null)
                            {
                                var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];
                                var newNode = ShaderFragmentNodeCreator.CreateNode(fn, n.FragmentArchiveName, graphControl, doc);
                                newNode.Location = visualNode.Location;
                                newNode.Collapsed = visualNode.State == ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                                newNodes[n.VisualNodeId] = newNode;
                                nodeIdToControlNode[n.NodeId] = newNode;
                            }
                        }
                        else
                        {
                            var ps = ShaderFragmentArchive.Archive.GetParameterStruct(n.FragmentArchiveName);
                            if (ps != null)
                            {
                                var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];
                                var newNode = ShaderFragmentNodeCreator.CreateParameterNode(ps, n.FragmentArchiveName, AsSourceType(n.NodeType));
                                newNode.Location = visualNode.Location;
                                newNode.Collapsed = visualNode.State == ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                                newNodes[n.VisualNodeId] = newNode;
                                nodeIdToControlNode[n.NodeId] = newNode;
                            }
                        }
                    }
                }

                graphControl.AddNodes(newNodes.Values);

                    // --------< Node Connections >--------
                foreach (var c in nodeGraph.NodeConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.InputNodeID) && nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var inputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.InputNodeID],
                            (item) => (item.Output != null && item.Output.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.InputParameterName)),
                            () => new ShaderFragmentNodeItem("return", c.InputType, null, false, true));

                        var outputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.OutputNodeID],
                            (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                            () => new ShaderFragmentNodeItem(c.OutputParameterName, c.OutputType, null, true, false));

                        graphControl.Connect(inputItem.Output, outputItem.Input);
                    }
                }

                    // --------< Node Constant Connections >--------
                foreach (var c in nodeGraph.NodeConstantConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var node = nodeIdToControlNode[c.OutputNodeID];
                        var outputItem = FindOrCreateNodeItem(node,
                            (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                            () => new ShaderFragmentNodeItem(c.OutputParameterName, "float", null, true, false));

                        var connection = new NodeConnection();
                        connection.To = outputItem.Input;
                        connection.Name = c.Value;
                        node.AddConnection(connection);
                    }
                }

            }
        }
Ejemplo n.º 16
0
Archivo: Node.cs Proyecto: taknim/XLE
 public void AddConnection(NodeConnection newConnection)
 {
     connections.Add(newConnection);
 }
Ejemplo n.º 17
0
 public NodeConnectionEventArgs(NodeConnector from, NodeConnector to, NodeConnection connection) { Connection = connection; From = from; To = to; }
Ejemplo n.º 18
0
 public AcceptNodeConnectionEventArgs(NodeConnection connection) { Connection = connection; }
Ejemplo n.º 19
0
        public void AddToHyperGraph(ShaderPatcherLayer.NodeGraph nodeGraph, HyperGraph.IGraphModel graph)
        {
                //
                //      Convert from the "ShaderPatcherLayer" representation back to
                //      our graph control nodes. 
                //
                //      This is required for robust serialisation. We can't easily
                //      serialise in and out the graph control objects directly, because
                //      it risks problems if the rendering code or shader fragment objects
                //      change. That is, it's not very version-robust.
                //
                //      It's better to serialise a slightly higher level representation
                //      that just contains the node names and connections. That way, we 
                //      can adapt to changes in the tool and data.
                //
            {
                    // --------< Basic Nodes >--------
                var newNodes = new Dictionary<int, Node>();
                var nodeIdToControlNode = new Dictionary<UInt64, Node>();
                foreach (var n in nodeGraph.Nodes)
                {
                    if (!newNodes.ContainsKey(n.VisualNodeId))
                    {
                        var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];

                        // also look for preview settings...
                        var previewSettings = nodeGraph.PreviewSettingsObjects.Where(x => x.VisualNodeId == n.VisualNodeId).FirstOrDefault();
                        Node newNode = null;
                        if (n.NodeType == ShaderPatcherLayer.Node.Type.Procedure)
                        {
                            var fn = _shaderFragments.GetFunction(n.FragmentArchiveName);
                            newNode = _nodeCreator.CreateNode(fn, n.FragmentArchiveName, previewSettings);
                        }
                        else
                        {
                            var ps = _shaderFragments.GetParameterStruct(n.FragmentArchiveName);
                            newNode = _nodeCreator.CreateParameterNode(ps, n.FragmentArchiveName, AsSourceType(n.NodeType));
                        }

                        if (newNode != null)
                        {
                            MatchVisualNode(newNode, visualNode);
                            newNodes[n.VisualNodeId] = newNode;
                            nodeIdToControlNode[n.NodeId] = newNode;
                        }
                    }
                }

                graph.AddNodes(newNodes.Values);

                    // --------< Node Connections >--------
                foreach (var c in nodeGraph.NodeConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.InputNodeID) && nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var inputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.InputNodeID],
                            (item) => (item.Output != null && item.Output.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.InputParameterName)),
                            () => new ShaderFragmentNodeItem(c.InputParameterName, c.InputType, null, false, true));
                        
                        var outputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.OutputNodeID],
                            (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                            () => new ShaderFragmentNodeItem(c.OutputParameterName, c.OutputType, null, true, false));

                        graph.Connect(inputItem.Output, outputItem.Input);
                    }
                }

                    // --------< Constant Connections >--------
                foreach (var c in nodeGraph.ConstantConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var node = nodeIdToControlNode[c.OutputNodeID];
                        var outputItem = FindOrCreateNodeItem(node,
                            (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                            () => new ShaderFragmentNodeItem(c.OutputParameterName, "float", null, true, false));

                        var connection = new NodeConnection();
                        connection.To = outputItem.Input;
                        connection.Name = c.Value;
                        node.AddConnection(connection);
                    }
                }

                    // --------< Input Parameter Connections >--------
                foreach (var c in nodeGraph.InputParameterConnections)
                {
                    if (!nodeIdToControlNode.ContainsKey(c.OutputNodeID)) continue;

                    var dstItem = FindOrCreateNodeItem(
                        nodeIdToControlNode[c.OutputNodeID],
                        (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                        () => new ShaderFragmentNodeItem(c.OutputParameterName, c.Type, null, true, false));

                    Node srcNode;
                    if (!newNodes.ContainsKey(c.VisualNodeId))
                    {
                        srcNode = _nodeCreator.CreateInterfaceNode("Inputs", InterfaceDirection.In);
                        MatchVisualNode(srcNode, nodeGraph.VisualNodes[c.VisualNodeId]);
                        newNodes[c.VisualNodeId] = srcNode;
                        graph.AddNode(srcNode);
                    } 
                    else
                        srcNode = newNodes[c.VisualNodeId];

                    var srcItem = FindOrCreateNodeItem(
                        srcNode,
                        (item) => {
                            var i = item as ShaderFragmentInterfaceParameterItem;
                            if (i==null) return false;
                            return i.Name.Equals(c.Name) && i.Type.Equals(c.Type) && i.Semantic.Equals(c.Semantic);
                        },
                        () => new ShaderFragmentInterfaceParameterItem(c.Name, c.Type, InterfaceDirection.In) { Semantic = c.Semantic, Default = c.Default });

                    graph.Connect(srcItem.Output, dstItem.Input);
                }

                    // --------< Output Parameter Connections >--------
                foreach (var c in nodeGraph.OutputParameterConnections)
                {
                    if (!nodeIdToControlNode.ContainsKey(c.InputNodeID)) continue;

                    var srcItem = FindOrCreateNodeItem(
                        nodeIdToControlNode[c.InputNodeID],
                        (item) => (item.Output != null && item.Output.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.InputParameterName)),
                        () => new ShaderFragmentNodeItem(c.InputParameterName, c.Type, null, false, true));

                    Node dstNode;
                    if (!newNodes.ContainsKey(c.VisualNodeId))
                    {
                        dstNode = _nodeCreator.CreateInterfaceNode("Outputs", InterfaceDirection.Out);
                        MatchVisualNode(dstNode, nodeGraph.VisualNodes[c.VisualNodeId]);
                        newNodes[c.VisualNodeId] = dstNode;
                        graph.AddNode(dstNode);
                    }
                    else
                        dstNode = newNodes[c.VisualNodeId];

                    var dstItem = FindOrCreateNodeItem(
                        dstNode,
                        (item) =>
                        {
                            var i = item as ShaderFragmentInterfaceParameterItem;
                            if (i == null) return false;
                            return i.Name.Equals(c.Name) && i.Type.Equals(c.Type) && i.Semantic.Equals(c.Semantic);
                        },
                        () => new ShaderFragmentInterfaceParameterItem(c.Name, c.Type, InterfaceDirection.Out) { Semantic = c.Semantic });

                    graph.Connect(srcItem.Output, dstItem.Input);
                }
            }
        }
Ejemplo n.º 20
0
 public AcceptNodeConnectionEventArgs(NodeConnection connection, bool cancel) : base(cancel) { Connection = connection; }
Ejemplo n.º 21
0
        static void RenderLabel(Graphics graphics, NodeConnection connection, string text, PointF center, RenderState state)
        {
            using (var path = new GraphicsPath(FillMode.Winding))
            {
                int cornerSize			= (int)GraphConstants.CornerSize * 2;

                var stringFormat = GraphConstants.RightTextStringFormat; // CenterTextStringFormat;
                var size = graphics.MeasureString(text, SystemFonts.StatusFont, center, stringFormat);
                RectangleF position = connection.textBounds = new RectangleF(new PointF(center.X - size.Width, center.Y - size.Height/2), size);

                path.AddArc(position.Left,                  position.Top,   cornerSize, cornerSize, 180, 90);
                path.AddArc(position.Right - cornerSize,    position.Top,   cornerSize, cornerSize, 270, 90);

                path.AddArc(position.Right - cornerSize,                    position.Bottom - cornerSize,   cornerSize, cornerSize, 0, 90);
                path.AddArc(position.Left, position.Bottom - cornerSize,    cornerSize,                     cornerSize, 90, 90);
                path.CloseFigure();

                using (var brush = new SolidBrush(GetArrowLineColor(state)))
                {
                    graphics.FillPath(brush, path);
                }
                graphics.DrawString(text, SystemFonts.StatusFont, Brushes.Black, position, GraphConstants.CenterTextStringFormat);

                if (state == RenderState.None)
                    graphics.DrawPath(Pens.Black, path);

                //graphics.DrawRectangle(Pens.Black, connection.textBounds.Left, connection.textBounds.Top, connection.textBounds.Width, connection.textBounds.Height);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Checks whether the connection between two connectors is allowed.
        /// This is achieved through event propagation.
        /// </summary>
        /// <returns></returns>
        private bool ConnectionIsAllowed(NodeConnector from, NodeConnector to)
        {
            if (HighlightCompatible && null != CompatibilityStrategy)
            {
                if (CompatibilityStrategy.CanConnect(from, to) == ConnectionType.Incompatible)
                    return false;
            }

            // If someone has subscribed to the ConnectionAdding event,
            // give them a chance to interrupt this connection attempt.
            if (null != ConnectionAdding)
            {
                // Populate a temporary NodeConnection instance.
                var connection = new NodeConnection();
                connection.From = from;
                connection.To = to;

                // Fire the event and see if someone cancels it.
                var eventArgs = new AcceptNodeConnectionEventArgs(connection);
                ConnectionAdding(this, eventArgs);
                if (eventArgs.Cancel)
                    return false;
            }
            return true;
        }
Ejemplo n.º 23
0
 public void AddConnection(NodeConnection newConnection)
 {
     connections.Add(newConnection);
 }
Ejemplo n.º 24
0
        public NodeConnection Connect(NodeConnector from, NodeConnector to)
        {
            if (from      == null || to      == null ||
                from.Node == null || to.Node == null ||
                !from.Enabled ||
                !to.Enabled)
                return null;

            foreach (var other in from.Node.connections)
            {
                if (other.From == from &&
                    other.To == to)
                    return null;
            }

            foreach (var other in to.Node.connections)
            {
                if (other.From == from &&
                    other.To == to)
                    return null;
            }

            var connection = new NodeConnection();
            connection.From = from;
            connection.To = to;

            from.Node.connections.Add(connection);
            to.Node.connections.Add(connection);

            if (ConnectionAdded != null)
            {
                var eventArgs = new AcceptNodeConnectionEventArgs(connection);
                ConnectionAdded(this, eventArgs);
                if (eventArgs.Cancel)
                {
                    Disconnect(connection);
                    return null;
                }
            }

            return connection;
        }
Ejemplo n.º 25
0
 public bool MoveToFront(NodeConnection connection)
 {
     if (connections[0] == connection) return false;
     connections.Remove(connection);
     connections.Insert(0, connection);
     return true;
 }
Ejemplo n.º 26
0
 public void RemoveConnection(NodeConnection connection)
 {
     connections.Remove(connection);
 }