Example #1
0
 public SetTrajectoryInitialNodeTool(Trajectory trajectory, TrajectoryDataControl trajectoryDataControl, NodeDataControl nodeDataControl)
 {
     this.trajectory                = trajectory;
     this.trajectoryDataControl     = trajectoryDataControl;
     this.nodeDataControl           = nodeDataControl;
     this.oldInitialNodeDataControl = trajectoryDataControl.getInitialNode();
 }
Example #2
0
 public AddTrajectorySideTool(NodeDataControl startNode, NodeDataControl endNode, Trajectory trajectory, TrajectoryDataControl trajectoryDataControl, SceneDataControl sceneDataControl)
 {
     this.startNode             = startNode;
     this.endNode               = endNode;
     this.trajectory            = trajectory;
     this.trajectoryDataControl = trajectoryDataControl;
     this.sceneDataControl      = sceneDataControl;
 }
 public DeleteTrajectoryNodeTool(DataControl dataControl, Trajectory trajectory, TrajectoryDataControl trajectoryDataControl)
 {
     this.oldNodeDataControl    = (NodeDataControl)dataControl;
     this.trajectory            = trajectory;
     this.trajectoryDataControl = trajectoryDataControl;
     this.oldSides   = new List <SideDataControl>();
     this.wasInitial = (trajectoryDataControl.getInitialNode() == oldNodeDataControl);
 }
        /**
         * Add a new side to the trajectory
         *
         * @param startNode
         *            the start node data control of the side
         * @param endNode
         *            the end node data control of the side
         * @return bool indicating if the side was added
         */
        public bool addSide(NodeDataControl startNode, NodeDataControl endNode)
        {
            if (startNode == endNode)
            {
                return(false);
            }

            Controller.getInstance().addTool(new AddTrajectorySideTool(startNode, endNode, trajectory, this, sceneDataControl));

            return(true);
        }
        public override bool doTool()
        {
            string id = "node" + (new System.Random().Next(10000));

            newNode            = trajectory.addNode(id, x, y, 1.0f);
            newNodeDataControl = new NodeDataControl(sceneDataControl, newNode, trajectory);
            trajectoryDataControl.getNodes().Add(newNodeDataControl);
            if (trajectory.getInitial() == newNode)
            {
                trajectoryDataControl.initialNode = newNodeDataControl;
                wasInitial = true;
            }
            return(true);
        }
Example #6
0
        /**
         * Add a new side to the trajectory
         *
         * @param startNode
         *            the start node data control of the side
         * @param endNode
         *            the end node data control of the side
         * @return bool indicating if the side was added
         */
        public bool addSide(NodeDataControl startNode, NodeDataControl endNode)
        {
            if (startNode == endNode)
            {
                return(false);
            }

            string sID = startNode.getID(), eID = endNode.getID();

            if (trajectory.getSides()
                .Any(s => (s.getIDStart() == sID && s.getIDEnd() == eID) ||
                     (s.getIDStart() == eID && s.getIDEnd() == sID)))
            {
                return(false);
            }

            Controller.Instance.AddTool(new AddTrajectorySideTool(startNode, endNode, trajectory, this, sceneDataControl));

            return(true);
        }
        /**
         * Constructor.
         *
         * @param sceneDataControl
         *            Link to the parent scene controller
         * @param barriersList
         *            List of activeAreas
         */
        public TrajectoryDataControl(SceneDataControl sceneDataControl, Trajectory trajectory)
        {
            this.sceneDataControl = sceneDataControl;
            this.trajectory       = trajectory;

            sideDataControlList = new List <SideDataControl>();
            nodeDataControlList = new List <NodeDataControl>();
            if (trajectory != null)
            {
                foreach (Node node in trajectory.getNodes())
                {
                    nodeDataControlList.Add(new NodeDataControl(sceneDataControl, node, trajectory));
                    if (node == trajectory.getInitial())
                    {
                        initialNode = nodeDataControlList[nodeDataControlList.Count - 1];
                        initialNode.setInitial(true);
                    }
                }
                foreach (Side side in trajectory.getSides())
                {
                    sideDataControlList.Add(new SideDataControl(sceneDataControl, this, side));
                }
            }
        }
 /**
  * Set the initial node of the trajectory to the given one
  *
  * @param nodeDataControl
  *            The new initial node data control
  */
 public void setInitialNode(NodeDataControl nodeDataControl)
 {
     Controller.getInstance().addTool(new SetTrajectoryInitialNodeTool(trajectory, this, nodeDataControl));
 }
 private bool IsPairingStartOrEnd(SideDataControl s, NodeDataControl node)
 {
     return((s.getStart() == pairing && s.getEnd() == node) || (s.getEnd() == pairing && s.getStart() == node));
 }
            public override void OnDrawingGizmos()
            {
                var trajectory = Target as TrajectoryDataControl;

                if (trajectory == null)
                {
                    return;
                }

                if (SceneEditor.Current.Disabled && pairing != null)
                {
                    pairing = null;
                }

                if (previousTrajectoryDataControl != trajectory)
                {
                    previousTrajectoryDataControl = trajectory;
                    pairing = null;
                }

                if (Event.current.type == EventType.MouseDown)
                {
                    var selected = SceneEditor.Current.SelectedElement;
                    var node     = selected as NodeDataControl;
                    var side     = selected as SideDataControl;

                    var isNode = node != null && trajectory.getNodes().Contains(node);
                    var isSide = side != null && trajectory.getSides().Contains(side);

                    switch (Action)
                    {
                    // Moving
                    case 1:
                        if (SceneEditor.Current.SelectedElement == null)
                        {
                            var pos = (Event.current.mousePosition - SceneEditor.Current.Viewport.position);
                            pos.x = (pos.x / SceneEditor.Current.Viewport.size.x) * SceneEditor.Current.Size.x;
                            pos.y = (pos.y / SceneEditor.Current.Viewport.size.y) * SceneEditor.Current.Size.y;
                            trajectory.addNode(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y));
                        }
                        break;

                    // Pariring
                    case 2:
                        if (isNode)
                        {
                            if (pairing == null)
                            {
                                pairing = node;
                            }
                            else
                            {
                                var duplicated = trajectory.getSides().Find(s => IsPairingStartOrEnd(s, node)) != null;
                                if (!duplicated)
                                {
                                    trajectory.addSide(pairing, node);
                                }
                                pairing = null;
                            }
                        }
                        else
                        {
                            pairing = null;
                        }
                        break;

                    // Initial
                    case 3:
                        if (isNode)
                        {
                            trajectory.setInitialNode(node);
                        }
                        break;

                    // Deleting
                    case 4:
                        if ((isNode || isSide) && trajectory.deleteElement(selected, false))
                        {
                            SceneEditor.Current.SelectedElement = null;
                        }
                        break;
                    }
                }

                foreach (var node in trajectory.getNodes())
                {
                    HandleUtil.DrawPoint(GetPivot(node), 10f, SceneEditor.GetColor(node.isInitial() ? Color.red : Color.blue), SceneEditor.GetColor(Color.black));
                }

                if (pairing != null)
                {
                    HandleUtil.DrawPolyLine(new Vector2[] { GetPivot(pairing), Event.current.mousePosition }, false, SceneEditor.GetColor(Color.white), 3f);
                }
            }