Ejemplo n.º 1
0
        /// <summary>
        /// Creates the node.
        /// </summary>
        /// <param name="groups">The group archetypes.</param>
        /// <param name="id">The node id.</param>
        /// <param name="surface">The surface.</param>
        /// <param name="groupID">The group identifier.</param>
        /// <param name="typeID">The type identifier.</param>
        /// <returns>Created node or null if failed.</returns>
        public static SurfaceNode CreateNode(List <GroupArchetype> groups, uint id, VisjectSurface surface, ushort groupID, ushort typeID)
        {
            // Find archetype for that node
            foreach (var groupArchetype in groups)
            {
                if (groupArchetype.GroupID == groupID && groupArchetype.Archetypes != null)
                {
                    foreach (var nodeArchetype in groupArchetype.Archetypes)
                    {
                        if (nodeArchetype.TypeID == typeID)
                        {
                            // Create
                            SurfaceNode node;
                            if (nodeArchetype.Create != null)
                            {
                                node = nodeArchetype.Create(id, surface, nodeArchetype, groupArchetype);
                            }
                            else
                            {
                                node = new SurfaceNode(id, surface, nodeArchetype, groupArchetype);
                            }
                            return(node);
                        }
                    }
                }
            }

            // Error
            Editor.LogError($"Failed to create Visject Surface node with id: {groupID}:{typeID}");
            return(null);
        }
Ejemplo n.º 2
0
            public void Update()
            {
                Rectangle area;

                if (Nodes.Count > 0)
                {
                    area = VisjectSurface.GetNodesBounds(Nodes);
                }
                else
                {
                    area = new Rectangle(EndBracketPosition, new Vector2(DefaultWidth, 80f));
                }
                _padding.ExpandRectangle(ref area);
                Vector2 offset = EndBracketPosition - area.UpperRight;

                area.Location += offset;
                Area           = area;
                if (!offset.IsZero)
                {
                    foreach (var node in Nodes)
                    {
                        node.Location += offset;
                    }
                }
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VisjectSurfaceContext"/> class.
        /// </summary>
        /// <param name="surface">The Visject surface using this context.</param>
        /// <param name="parent">The parent context. Defines the higher key surface graph context. May be null for the top-level context.</param>
        /// <param name="context">The context.</param>
        /// <param name="rootControl">The surface root control.</param>
        public VisjectSurfaceContext(VisjectSurface surface, VisjectSurfaceContext parent, ISurfaceContext context, SurfaceRootControl rootControl)
        {
            _surface    = surface;
            Parent      = parent;
            Context     = context ?? throw new ArgumentNullException(nameof(context));
            RootControl = rootControl ?? throw new ArgumentNullException(nameof(rootControl));

            // Set initial scale to provide nice zoom in effect on startup
            RootControl.Scale = new Vector2(0.5f);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SurfaceNode"/> class.
        /// </summary>
        /// <param name="id">The node id.</param>
        /// <param name="surface">The surface.</param>
        /// <param name="nodeArch">The node archetype.</param>
        /// <param name="groupArch">The group archetype.</param>
        public SurfaceNode(uint id, VisjectSurface surface, NodeArchetype nodeArch, GroupArchetype groupArch)
            : base(surface, nodeArch.Size.X + Constants.NodeMarginX * 2, nodeArch.Size.Y + Constants.NodeMarginY * 2 + Constants.NodeHeaderSize + Constants.NodeFooterSize)
        {
            Title          = nodeArch.Title;
            ID             = id;
            Archetype      = nodeArch;
            GroupArchetype = groupArch;

            if (Archetype.DefaultValues != null)
            {
                Values = new object[Archetype.DefaultValues.Length];
                Array.Copy(Archetype.DefaultValues, Values, Values.Length);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the node.
        /// </summary>
        /// <param name="id">The node id.</param>
        /// <param name="surface">The surface.</param>
        /// <param name="groupArchetype">The group archetype.</param>
        /// <param name="nodeArchetype">The node archetype.</param>
        /// <returns>Created node or null if failed.</returns>
        public static SurfaceNode CreateNode(uint id, VisjectSurface surface, GroupArchetype groupArchetype, NodeArchetype nodeArchetype)
        {
            Assert.IsTrue(groupArchetype.Archetypes.Contains(nodeArchetype));

            // Create
            SurfaceNode node;

            if (nodeArchetype.Create != null)
            {
                node = nodeArchetype.Create(id, surface, nodeArchetype, groupArchetype);
            }
            else
            {
                node = new SurfaceNode(id, surface, nodeArchetype, groupArchetype);
            }
            return(node);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VisjectSurfaceContext"/> class.
 /// </summary>
 /// <param name="surface">The Visject surface using this context.</param>
 /// <param name="parent">The parent context. Defines the higher key surface graph context. May be null for the top-level context.</param>
 /// <param name="context">The context.</param>
 public VisjectSurfaceContext(VisjectSurface surface, VisjectSurfaceContext parent, ISurfaceContext context)
     : this(surface, parent, context, new SurfaceRootControl())
 {
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Updates dependant/independent boxes types.
        /// </summary>
        public void UpdateBoxesTypes()
        {
            // Check there is no need to use box types dependency feature
            if (Archetype.DependentBoxes == null && Archetype.IndependentBoxes == null)
            {
                // Check if need to update update current type of the typeless boxes that use connection hints
                if ((Archetype.ConnectionsHints & ConnectionsHint.All) != 0)
                {
                    for (int j = 0; j < Elements.Count; j++)
                    {
                        if (Elements[j] is Box box && box.DefaultType == ScriptType.Null)
                        {
                            box.CurrentType = box.HasAnyConnection ? box.Connections[0].CurrentType : ScriptType.Null;
                        }
                    }
                }
                return;
            }

            // Prevent recursive loop call that might happen
            if (UpdateStack.Contains(this))
            {
                return;
            }
            UpdateStack.Add(this);

            var independentBoxesLength = Archetype.IndependentBoxes?.Length;
            var dependentBoxesLength   = Archetype.DependentBoxes?.Length;

            // Get type to assign to all dependent boxes
            var type = Archetype.DefaultType;

            for (int i = 0; i < independentBoxesLength; i++)
            {
                var b = GetBox(Archetype.IndependentBoxes[i]);
                if (b != null && b.HasAnyConnection)
                {
                    // Check if the current type is set based on connection hints (eg. null box got vector connection)
                    if (type == ScriptType.Null && b.Connections[0].CurrentType != ScriptType.Null)
                    {
                        type = b.Connections[0].CurrentType;
                        break;
                    }

                    // Check if that type if part of default type
                    if (Surface != null)
                    {
                        if (Surface.CanUseDirectCast(type, b.Connections[0].DefaultType))
                        {
                            type = b.Connections[0].CurrentType;
                            break;
                        }
                    }
                    else
                    {
                        if (VisjectSurface.CanUseDirectCastStatic(type, b.Connections[0].DefaultType))
                        {
                            type = b.Connections[0].CurrentType;
                            break;
                        }
                    }
                }
            }

            // Assign connection type
            for (int i = 0; i < dependentBoxesLength; i++)
            {
                var b = GetBox(Archetype.DependentBoxes[i]);
                if (b != null)
                {
                    b.CurrentType = Archetype.DependentBoxFilter != null?Archetype.DependentBoxFilter(b, type) : type;
                }
            }

            // Validate minor independent boxes to fit main one
            for (int i = 0; i < independentBoxesLength; i++)
            {
                var b = GetBox(Archetype.IndependentBoxes[i]);
                if (b != null)
                {
                    b.CurrentType = type;
                }
            }

            UpdateStack.Remove(this);
        }