Пример #1
0
    public NodeMEntity(mEntity entity, Node node, PortOrientation orientation)
    {
        this.orientation = orientation;
        entityName       = entity.entityName;
        parent           = node;

        foreach (IComponent c in entity.components)
        {
            NodeIComponent comp = new NodeIComponent(c, node, orientation);
            comp.parentEntity = this;
            components.Add(comp);
        }

        // tree = PropertyTree.Create(components);
        // if (nodeName=="")
        {
            if (orientation == PortOrientation.Out)
            {
                port = node.AddDynamicOutput(typeof(bool));
            }
            else
            {
                port = node.AddDynamicInput(typeof(bool));
            }

            nodeName = port.fieldName;
        }
        Debug.Log(port.fieldName);
        style             = new NodeMEntityStyle();
        style.unfolded    = false;
        style.portVisible = false;
    }
        public void RemovePort(PortOrientation orientation, PortDirection direction)
        {
            if (orientation == PortOrientation.Horizontal)
            {
                if (direction == PortDirection.Input)
                {
                    m_InputCount--;
                }
                else
                {
                    m_OutputCount--;
                }
            }
            else
            {
                if (direction == PortDirection.Input)
                {
                    m_VerticalInputCount--;
                }
                else
                {
                    m_VerticalOutputCount--;
                }
            }

            DefineNode();
        }
Пример #3
0
        public virtual Port CreatePort(PortOrientation orientation)
        {
            Port port = new Port(orientation);

            OnCreateElement(port);
            return(port);
        }
Пример #4
0
    public void init(IComponent c, Node node, NodeMEntity entity, PortOrientation orientation)
    {
        //port = CreateInstance("NodePort") as NodePort;
        parent       = node;
        component    = c;
        parentEntity = entity;
        //  tree = PropertyTree.Create(component);

        if (orientation == PortOrientation.Out)
        {
            port = node.AddDynamicOutput(typeof(bool));
        }
        else
        {
            port = node.AddDynamicInput(typeof(bool));
        }

        style             = new NodeIComponentStyle();
        style.unfolded    = false;
        style.portVisible = false;

        tree = PropertyTree.Create(component);

        AssetDatabase.SaveAssets();
    }
Пример #5
0
        public Port(Port prototype) : base(prototype)
        {
            SuspendEvents = true;

            Label       = null;
            StencilItem = null;

            mAlignment   = prototype.Alignment;
            mOffset      = prototype.Offset;
            mAllowMove   = prototype.AllowMove;
            mAllowRotate = prototype.AllowRotate;
            mDirection   = prototype.Direction;
            mInteraction = prototype.Interaction;
            Label        = null;
            mPortStyle   = prototype.Style;
            Cursor       = prototype.Cursor;

            mPercent     = prototype.Percent;
            mOrientation = prototype.Orientation;

            //Needed for action mvoe
            mParent = prototype.Parent;

            SuspendEvents = false;
        }
        List <SnapToGridResult> GetClosestGridLines(Rect sourceRect, PortOrientation orientation)
        {
            SnapReference startReference  = orientation == PortOrientation.Horizontal ? SnapReference.LeftEdge : SnapReference.TopEdge;
            SnapReference centerReference = orientation == PortOrientation.Horizontal ? SnapReference.HorizontalCenter : SnapReference.VerticalCenter;
            SnapReference endReference    = orientation == PortOrientation.Horizontal ? SnapReference.RightEdge : SnapReference.BottomEdge;

            List <SnapToGridResult> results = new List <SnapToGridResult>(3);
            SnapToGridResult        result  = GetClosestGridLine(sourceRect, startReference, startReference, endReference);

            if (result != null)
            {
                results.Add(result);
            }
            result = GetClosestGridLine(sourceRect, centerReference, startReference, endReference);
            if (result != null)
            {
                results.Add(result);
            }
            result = GetClosestGridLine(sourceRect, endReference, startReference, endReference);
            if (result != null)
            {
                results.Add(result);
            }
            // Look for the minimum
            if (results.Count > 0)
            {
                results.Sort((a, b) => a.Distance.CompareTo(b.Distance));
                float minDistance = results[0].Distance;
                results.RemoveAll(r => Math.Abs(r.Distance - minDistance) > 0.01f);
            }
            return(results);
        }
Пример #7
0
    public NodeFilter(List <mEntity> entities, Node node, PortOrientation orientation)
    {
        // port = CreateInstance("NodePort") as NodePort;
        this.orientation = orientation;
        //Debug.Log("Adding entities to new filter");
        foreach (mEntity e in entities)
        {
            parent = node;
            NodeMEntity mE = new NodeMEntity(e, node, orientation);
            //  NodeMEntity mE = CreateInstance("NodeMEntity") as NodeMEntity; // // as NodeMEntity;
            //  mE.init(e, node, orientation);

            mE.parentFilter = this;
            filter.Add(mE);
        }

        if (port == null)
        {
            if (orientation == PortOrientation.Out)
            {
                port = node.AddDynamicOutput(typeof(bool));
            }
            else
            {
                port = node.AddDynamicInput(typeof(bool));
            }
        }

        style             = new NodeFilterStyle();
        style.unfolded    = false;
        style.portVisible = true;
    }
        public void SendSpacingCommand(PortOrientation orientation)
        {
            m_Orientation = orientation;

            // Get spacing delta for each element
            Dictionary <IGraphElementModel, Vector2> results = GetElementDeltaResults();

            // Dispatch command
            SendPlacementCommand(results.Keys.ToList(), results.Values.ToList());
        }
        /// <summary>
        /// Adds a new placeholder port on a node.
        /// </summary>
        /// <param name="self">The node to add the new port on.</param>
        /// <param name="direction">The direction of the port the create.</param>
        /// <param name="uniqueId">The ID of the port to create.</param>
        /// <param name="orientation">The orientation of the port to create.</param>
        /// <returns>The newly created placeholder port.</returns>
        public static IPortModel AddPlaceHolderPort(this IInputOutputPortsNodeModel self, PortDirection direction, string uniqueId,
                                                    PortOrientation orientation = PortOrientation.Horizontal)
        {
            if (direction == PortDirection.Input)
            {
                return(self.AddInputPort(uniqueId, PortType.MissingPort, TypeHandle.MissingPort, uniqueId, orientation,
                                         PortModelOptions.NoEmbeddedConstant));
            }

            return(self.AddOutputPort(uniqueId, PortType.MissingPort, TypeHandle.MissingPort, uniqueId, orientation,
                                      PortModelOptions.NoEmbeddedConstant));
        }
Пример #10
0
        IEnumerator SpaceElements(PortOrientation orientation)
        {
            m_AutoSpacingHelper.SendSpacingCommand(orientation);
            yield return(null);

            // Get the UI elements
            m_FirstNode  = FirstNodeModel.GetUI <Node>(graphView);
            m_SecondNode = SecondNodeModel.GetUI <Node>(graphView);
            m_ThirdNode  = ThirdNodeModel.GetUI <Node>(graphView);
            m_FourthNode = FourthNodeModel.GetUI <Node>(graphView);
            m_Placemat   = PlacematModel.GetUI <Placemat>(graphView);
            m_StickyNote = StickyNoteModel.GetUI <StickyNote>(graphView);
        }
Пример #11
0
    public NodeFilter populateFilter(NodeFilter filter, List <mEntity> source, PortOrientation orientation)
    {
        //  filter = CreateInstance<NodeFilter>() as NodeFilter;
        // filter.init(source, this, orientation);
        //   AssetDatabase.CreateAsset(filter, AssetDatabase.GenerateUniqueAssetPath("Assets/filter.asset"));

        // AssetDatabase.AddObjectToAsset(filter, this);
        filter = new NodeFilter(source, this, orientation);
        AssetDatabase.SaveAssets();
        //  AddThingsToOtherThings.Add(graph.nodes[graph.nodes.IndexOf(this)], filter);
        Debug.Log("How f*****g interesting");
        return(filter);
    }
 public override IPortModel CreatePort(PortDirection direction, PortOrientation orientation, string portName, PortType portType,
                                       TypeHandle dataType, string portId, PortModelOptions options)
 {
     return(new FakePortModel(GraphModel)
     {
         Direction = direction,
         Orientation = orientation,
         Title = portName,
         PortType = portType,
         DataTypeHandle = dataType,
         NodeModel = this
     });
 }
 public override IPortModel CreatePort(PortDirection direction, PortOrientation orientation, string portName, PortType portType, TypeHandle dataType, string portId, PortModelOptions options)
 {
     return(new MathExpressionPortModel
     {
         Direction = direction,
         Orientation = orientation,
         PortType = portType,
         DataTypeHandle = dataType,
         Title = portName ?? "",
         UniqueName = portId,
         Options = options,
         NodeModel = this,
         AssetModel = AssetModel
     });
 }
Пример #14
0
        //Sets the inital orientation and percentage
        public Port(PortOrientation orientation, float percent)
        {
            Label       = null;
            StencilItem = null;

            _validate    = true;
            _allowMove   = true;
            _allowRotate = true;
            _offset      = new PointF();
            _orientation = orientation;
            _percent     = percent;
            Alignment    = PortAlignment.Center;
            Direction    = Direction.Both;
            Interaction  = UserInteraction.BringToFront;
            Style        = PortStyle.Default;
        }
Пример #15
0
 private int GetPortRotation(PortOrientation orientation)
 {
     if (orientation == PortOrientation.Right)
     {
         return(90);
     }
     if (orientation == PortOrientation.Bottom)
     {
         return(180);
     }
     if (orientation == PortOrientation.Left)
     {
         return(270);
     }
     return(0);
 }
Пример #16
0
        SnapToSpacingResult GetClosestSpacingPosition(Rect sourceRect, PortOrientation orientation)
        {
            SnapToSpacingResult minResult = null;
            float minDistance             = float.MaxValue;

            foreach (var spacingPos in m_SpacingPositions.Where(spacingPos => spacingPos.Value.Orientation == orientation))
            {
                SnapToSpacingResult result = GetSnapToSpacingResult(sourceRect, spacingPos.Key, spacingPos.Value);
                if (result != null && minDistance > result.Distance)
                {
                    minDistance = result.Distance;
                    minResult   = result;
                }
            }

            return(minResult);
        }
Пример #17
0
        //Takes the port and validates its location against the shape's path
        public bool ValidatePortLocation(Port port, PointF location)
        {
            //Check for switch changes
            if (!port.AllowRotate)
            {
                PortOrientation orientation = Geometry.GetOrientation(location, Center, Bounds);
                if (port.Orientation != orientation)
                {
                    return(false);
                }
            }

            //Offset location to local co-ordinates and check outline
            location.X -= Bounds.X;
            location.Y -= Bounds.Y;

            return(TransformPath.IsOutlineVisible(location, new Pen(Color.Black, 5)));
        }
Пример #18
0
        //Constructors
        //Sets the inital orientation
        public Port(PortOrientation orientation)
        {
            SuspendEvents = true;

            Label       = null;
            StencilItem = null;

            mValidate     = true;
            mAllowMove    = true;
            mAllowRotate  = true;
            mOffset       = new PointF();
            mOrientation  = orientation;
            Alignment     = PortAlignment.Center;
            Direction     = Direction.Both;
            Interaction   = UserInteraction.BringToFront;
            Style         = PortStyle.Default;
            SuspendEvents = false;
        }
Пример #19
0
		//Constructors
		//Sets the inital orientation
		public Port(PortOrientation orientation)
		{
			SuspendEvents = true;

			Label = null;
			StencilItem = null;

			mValidate  = true;
			mAllowMove = true;
			mAllowRotate = true;
			mOffset = new PointF();
			mOrientation = orientation;
			Alignment =  PortAlignment.Center;
			Direction = Direction.Both;
			Interaction = UserInteraction.BringToFront;
			Style = PortStyle.Default;
			SuspendEvents = false;
		}
        public override IPortModel CreatePort(PortDirection direction, PortOrientation orientation, string portName,
                                              PortType portType, TypeHandle dataType, string portId, PortModelOptions options)
        {
            var port = new PortModel
            {
                Direction      = direction,
                Orientation    = orientation,
                PortType       = portType,
                DataTypeHandle = dataType,
                Title          = portName,
                UniqueName     = portId,
                Options        = options,
                NodeModel      = this
            };

            port.SetGraphModel(GraphModel);
            return(port);
        }
Пример #21
0
        List <SpacingLine> GetSpacingLines(List <Rect> rects, PortOrientation orientation)
        {
            SnapReference startReference = orientation == PortOrientation.Vertical ? SnapReference.BottomEdge : SnapReference.RightEdge;
            SnapReference endReference   = orientation == PortOrientation.Vertical ? SnapReference.TopEdge : SnapReference.LeftEdge;

            float maxCoordinate         = rects.Max(rect => orientation == PortOrientation.Vertical ? rect.xMax : rect.yMax) + SpacingLine.DefaultSpacingLineSideLength;
            float spacingLineSideLength = SpacingLine.DefaultSpacingLineSideLength / m_CurrentScale;

            Vector2 firstSidePos  = GetMaxPos(rects[0], startReference);
            Vector2 secondSidePos = GetMaxPos(rects[1], endReference);
            Vector2 thirdSidePos  = GetMaxPos(rects[1], startReference);
            Vector2 fourthSidePos = GetMaxPos(rects[2], endReference);

            return(new List <SpacingLine>
            {
                GetSpacingLine(maxCoordinate, spacingLineSideLength, firstSidePos, secondSidePos, orientation),
                GetSpacingLine(maxCoordinate, spacingLineSideLength, thirdSidePos, fourthSidePos, orientation)
            });
        }
Пример #22
0
        //Deserializes info into a new solid element
        protected Port(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            SuspendEvents = true;

            Validate = false;

            Alignment    = (PortAlignment)Enum.Parse(typeof(PortAlignment), info.GetString("Alignment"), true);
            mPortStyle   = (PortStyle)Enum.Parse(typeof(PortStyle), info.GetString("Style"), true);
            AllowMove    = info.GetBoolean("AllowMove");
            AllowRotate  = info.GetBoolean("AllowRotate");
            DrawSelected = info.GetBoolean("DrawSelected");
            Selected     = info.GetBoolean("Selected");
            Direction    = (Direction)Enum.Parse(typeof(Direction), info.GetString("Direction"), true);
            Interaction  = (UserInteraction)Enum.Parse(typeof(UserInteraction), info.GetString("Interaction"), true);

            mOrientation = (PortOrientation)Enum.Parse(typeof(PortOrientation), info.GetString("Orientation"), true);
            mPercent     = info.GetSingle("Percent");

            Validate      = true;
            SuspendEvents = false;
        }
Пример #23
0
        public Port(Port prototype) : base(prototype)
        {
            Label       = null;
            StencilItem = null;

            _offset      = prototype.Offset;
            _allowMove   = prototype.AllowMove;
            _allowRotate = prototype.AllowRotate;
            _direction   = prototype.Direction;
            _interaction = prototype.Interaction;
            Label        = null;
            _portStyle   = prototype.Style;
            Cursor       = prototype.Cursor;

            _percent     = prototype.Percent;
            _orientation = prototype.Orientation;

            //Needed for action move
            _parent   = prototype.Parent;
            Alignment = prototype.Alignment;
        }
Пример #24
0
    public void init(List <mEntity> entities, Node node, PortOrientation orientation)
    {
        // port = CreateInstance("NodePort") as NodePort;
        this.orientation = orientation;
        filter           = new List <NodeMEntity>();
        style            = new NodeFilterStyle();
        //Debug.Log("Adding entities to new filter");
        foreach (mEntity e in entities)
        {
            parent = node;
            NodeMEntity mE = new NodeMEntity(e, node, orientation);
            //  NodeMEntity mE = CreateInstance("NodeMEntity") as NodeMEntity;
            //  mE.init(e, node, orientation);

            mE.parentFilter = this;
            filter.Add(mE);
        }


        if (orientation == PortOrientation.Out)
        {
            port = node.AddDynamicOutput(typeof(bool));
        }
        else
        {
            port = node.AddDynamicInput(typeof(bool));
        }

        style             = new NodeFilterStyle();
        style.unfolded    = false;
        style.portVisible = true;

        //   EditorUtility.SetDirty(this);
        //   EditorUtility.SetDirty(port);
        AssetDatabase.SaveAssets();
        //   AssetDatabase.Refresh();
        //  */
    }
Пример #25
0
    public void init(mEntity entity, Node node, PortOrientation orientation)
    {
        // port = CreateInstance("NodePort") as NodePort;
        this.orientation = orientation;
        this.entity      = entity;
        entityName       = entity.entityName;
        parent           = node;
        Debug.Log("entity components: " + entity.components.Count);
        foreach (IComponent c in entity.components)
        {
            //  NodeIComponent comp = CreateInstance("NodeIComponent") as NodeIComponent;
            //  AssetDatabase.SaveAssets();

            //  comp.init(c, node, this, orientation);
            NodeIComponent comp = new NodeIComponent(c, node, orientation);
            comp.parentEntity = this;
            Debug.Log(comp);
            components.Add(comp);
        }

        // tree = PropertyTree.Create(components);
        //  if (port == null)
        {
            if (orientation == PortOrientation.Out)
            {
                port = node.AddDynamicOutput(typeof(bool));
            }
            else
            {
                port = node.AddDynamicInput(typeof(bool));
            }
        }
        style             = new NodeMEntityStyle();
        style.unfolded    = false;
        style.portVisible = false;
        AssetDatabase.SaveAssets();
    }
Пример #26
0
    public NodeIComponent(IComponent c, Node node, PortOrientation orientation)
    {
        // port = CreateInstance("NodePort") as NodePort;
        parent    = node;
        component = c;
        //  tree = PropertyTree.Create(component);
        if (port == null)
        {
            if (orientation == PortOrientation.Out)
            {
                port = node.AddDynamicOutput(typeof(bool));
            }
            else
            {
                port = node.AddDynamicInput(typeof(bool));
            }
        }

        style             = new NodeIComponentStyle();
        style.unfolded    = false;
        style.portVisible = false;

        tree = PropertyTree.Create(component);
    }
Пример #27
0
		private int GetPortRotation(PortOrientation orientation)
		{
			if (orientation == PortOrientation.Right) return 90;
			if (orientation == PortOrientation.Bottom) return 180;
			if (orientation == PortOrientation.Left) return 270;
			return 0;
		}
Пример #28
0
		//Deserializes info into a new solid element
		protected Port(SerializationInfo info, StreamingContext context): base(info,context)
		{
			SuspendEvents = true;

			Validate = false;

			Alignment = (PortAlignment) Enum.Parse(typeof(PortAlignment), info.GetString("Alignment"),true);
			mPortStyle = (PortStyle) Enum.Parse(typeof(PortStyle), info.GetString("Style"),true);
			AllowMove = info.GetBoolean("AllowMove");
			AllowRotate = info.GetBoolean("AllowRotate");
			DrawSelected = info.GetBoolean("DrawSelected");
			Selected = info.GetBoolean("Selected");
			Direction = (Direction) Enum.Parse(typeof(Direction), info.GetString("Direction"),true);
			Interaction = (UserInteraction) Enum.Parse(typeof(UserInteraction), info.GetString("Interaction"),true);

			mOrientation = (PortOrientation) Enum.Parse(typeof(PortOrientation), info.GetString("Orientation"),true);
			mPercent = info.GetSingle("Percent");

			Validate = true;
			SuspendEvents = false;
		}
Пример #29
0
		public Port(Port prototype): base(prototype)
		{
			SuspendEvents = true;

			Label = null;
			StencilItem = null;

			mAlignment = prototype.Alignment;				
			mOffset = prototype.Offset;
			mAllowMove = prototype.AllowMove;
			mAllowRotate = prototype.AllowRotate;
			mDirection = prototype.Direction;
			mInteraction = prototype.Interaction;
			Label = null;
			mPortStyle = prototype.Style;
			Cursor = prototype.Cursor;

			mPercent = prototype.Percent;
			mOrientation = prototype.Orientation;
			
			//Needed for action mvoe
			mParent = prototype.Parent;

			SuspendEvents = false;
		}
Пример #30
0
		public virtual Port CreatePort(PortOrientation orientation)
		{
			Port port = new Port(orientation);

			OnCreateElement(port);
			return port;
		}
        protected TContextModel CreateContext <TContextModel>(string title, Vector2 position, int inCount = 0, int outCount = 0, int exeInCount = 0, int exeOutCount = 0, PortOrientation orientation = PortOrientation.Horizontal) where TContextModel : ContextNodeModel, new()
        {
            var node = GraphModel.CreateNode <TContextModel>(title, position, initializationCallback: model =>
            {
                model.InputCount    = inCount;
                model.OuputCount    = outCount;
                model.ExeInputCount = exeInCount;
                model.ExeOuputCount = exeOutCount;
            });

            foreach (var portModel in node.Ports.Cast <PortModel>())
            {
                portModel.Orientation = orientation;
            }

            return(node);
        }
 protected IONodeModel CreateNode(string title = "", Vector2 position = default, int inCount = 0, int outCount = 0, int exeInCount = 0, int exeOutCount = 0, PortOrientation orientation = PortOrientation.Horizontal)
 {
     return(CreateNode <IONodeModel>(title, position, inCount, outCount, exeInCount, exeOutCount, orientation));
 }
Пример #33
0
        static List <float> GetSpacingPositions(Rect sourceRect, Rect firstRect, Rect secondRect, SnapReference startReference, SnapReference endReference, PortOrientation orientation)
        {
            if (AreElementsSuperposed(firstRect, secondRect, orientation))
            {
                return(null);
            }

            Vector2 firstRectStartPos  = GetMaxPos(firstRect, startReference);
            Vector2 firstRectEndPos    = GetMaxPos(firstRect, endReference);
            Vector2 secondRectStartPos = GetMaxPos(secondRect, startReference);
            Vector2 secondRectEndPos   = GetMaxPos(secondRect, endReference);

            List <float> positions = orientation == PortOrientation.Vertical ?
                                     ComputeSpacingPositions(firstRectStartPos.y, firstRectEndPos.y, secondRectStartPos.y, secondRectEndPos.y, sourceRect.height * 0.5f) :
                                     ComputeSpacingPositions(firstRectStartPos.x, firstRectEndPos.x, secondRectStartPos.x, secondRectEndPos.x, sourceRect.width * 0.5f);

            return(positions);
        }
Пример #34
0
        void AddSpacingPositions(List <float> positions, Rect sourceRect, Rect firstRect, Rect secondRect, PortOrientation orientation)
        {
            if (positions != null)
            {
                // Position before firstRect
                AddSpacingPosition(positions[0], new ReferenceRects
                {
                    Rects = new List <Rect> {
                        sourceRect, firstRect, secondRect
                    },
                    Orientation = orientation
                });

                // Position between firstRect and secondRect
                AddSpacingPosition(positions[1], new ReferenceRects
                {
                    Rects = new List <Rect> {
                        firstRect, sourceRect, secondRect
                    },
                    Orientation = orientation
                });

                // Position after secondRect
                AddSpacingPosition(positions[2], new ReferenceRects
                {
                    Rects = new List <Rect> {
                        firstRect, secondRect, sourceRect
                    },
                    Orientation = orientation
                });
            }
        }
Пример #35
0
        static SpacingLine GetSpacingLine(float maxCoordinate, float spacingLineSideLength, Vector2 startPos, Vector2 endPos, PortOrientation orientation)
        {
            // Start side's line of spacingLine
            Vector2 start         = orientation == PortOrientation.Vertical ? new Vector2(maxCoordinate, startPos.y) : new Vector2(startPos.x, maxCoordinate);
            Vector2 end           = startPos;
            Line    startSideLine = new Line(start, end);

            // Line in between of spacingLine
            float linePos = maxCoordinate - spacingLineSideLength * 0.5f;

            start = orientation == PortOrientation.Vertical ? new Vector2(linePos, startPos.y) : new Vector2(startPos.x, linePos);
            end   = orientation == PortOrientation.Vertical ? new Vector2(linePos, endPos.y) : new Vector2(endPos.x, linePos);
            Line lineInBetween = new Line(start, end);

            // End side's line of spacingLine
            start = orientation == PortOrientation.Vertical ? new Vector2(maxCoordinate, endPos.y) : new Vector2(endPos.x, maxCoordinate);
            end   = endPos;
            Line endSideLine = new Line(start, end);

            return(new SpacingLine
            {
                StartSideLine = startSideLine,
                LineInBetween = lineInBetween,
                EndSideLine = endSideLine
            });
        }