internal QualifierVisualizer(IQualifier q, SelectorVisualizer parent)
        {
            this._qualifier = q;
            this._parent    = parent;
            SelectorAction      selectorAction     = q.action as SelectorAction;
            AILinkAction        aILinkAction       = q.action as AILinkAction;
            CompositeAction     compositeAction    = q.action as CompositeAction;
            IRequireTermination requireTermination = q.action as IRequireTermination;

            if (selectorAction != null)
            {
                this._action = new SelectorActionVisualizer(selectorAction, this);
                return;
            }
            if (aILinkAction != null)
            {
                this._action = new AILinkActionVisualizer(aILinkAction, this);
                return;
            }
            if (compositeAction != null)
            {
                this._action = new CompositeActionVisualizer(compositeAction, this);
                return;
            }
            if (requireTermination != null)
            {
                this._action = new ActionRequiresTerminationVisualizer(q.action, this);
                return;
            }
            if (q.action != null)
            {
                this._action = new ActionVisualizer(q.action, this);
            }
        }
Exemple #2
0
        public override void Compose(Display <Image> display)
        {
            this.DataOrigin = () => { return(Point.Zero); };
            this.DataSize   = () => {
                var data = display.Data;
                if (data != null)
                {
                    return(data.Size.ToXwt());
                }
                else
                {
                    return(Size.Zero);
                }
            };

            base.Compose(display);

            Compose(display, display.SelectionRenderer);
            Compose(display, display.MoveResizeRenderer);

            var selectAction = new SelectorAction();

            Compose(display, selectAction, true);
            selectAction.ShowGrips = false;
            selectAction.Enabled   = false;

            display.SelectAction = selectAction;
            display.ActionDispatcher.Add(selectAction);

            display.SelectAction.ShowGrips    = true;
            display.SelectAction.Enabled      = false;
            display.MouseScrollAction.Enabled = true;
        }
        internal CompositeActionVisualizer(CompositeAction action, IQualifierVisualizer parent) : base(action, parent)
        {
            this._actions = new List <ActionVisualizer>(action.actions.Count);
            for (int i = 0; i < action.actions.Count; i++)
            {
                IAction         item            = action.actions[i];
                CompositeAction compositeAction = item as CompositeAction;
                if (compositeAction == null)
                {
                    this._actions.Add(new ActionVisualizer(item, parent));
                }
                else
                {
                    this._actions.Add(new CompositeActionVisualizer(compositeAction, parent));
                }
            }
            SelectorAction selectorAction = action.connectorAction as SelectorAction;
            AILinkAction   aILinkAction   = action.connectorAction as AILinkAction;

            if (selectorAction != null)
            {
                this._connectorAction = new SelectorActionVisualizer(selectorAction, parent);
                return;
            }
            if (aILinkAction != null)
            {
                this._connectorAction = new AILinkActionVisualizer(aILinkAction, parent);
            }
        }
Exemple #4
0
        private void OnMouseDown_HandleDragSelection(object sender, MouseEventArgs e, Point mouseLocation, Point snappedLocation, bool setShapes)
        {
            if (IsMouseOverSelectedRectangle(mouseLocation))
            {
                if (setShapes)
                {
                    var shapes = Canvas.Instance.GetShapesByRectangle(selectedRectangle);
                    ClickData.Set(shapes);
                }
                mouseDownLocation = snappedLocation;

                ClickData.Set(snappedLocation, ShapeClickAction.Drag);

                selectedRectangleDownLocation = selectedRectangle.Location;
                action = SelectorAction.BeginMoveSelectedShapes;
                OnMouseMove(sender, e);
            }
            else
            {
                if (!MouseWasDown)
                {
                    action = SelectorAction.BeginSelectionRectangle;

                    mouseDownLocation             = new Point();
                    selectedRectangleDownLocation = new Point();
                    ClickData.Clear(true);

                    OnMouseDown(sender, e);
                }
            }
        }
 private ITask FindTaskOfQualifier()
 {
     if (this._task == null)
     {
         SelectorAction selectorAction = base.action as SelectorAction;
         if (selectorAction != null && selectorAction.selector != null)
         {
             this._task = selectorAction.selector as ITask;
             if (this._task != null)
             {
                 return(this._task);
             }
         }
         AILinkAction aILinkAction = base.action as AILinkAction;
         if (aILinkAction != null)
         {
             IUtilityAI aI = AIManager.GetAI(aILinkAction.aiId);
             if (aI.rootSelector is ITask)
             {
                 this._task = aI.rootSelector as ITask;
                 ITask task = this._task;
                 return(this._task);
             }
         }
     }
     return(this._task);
 }
Exemple #6
0
        private void ClearSelectedRectangle()
        {
            selectedRectangle             = new Rectangle();
            selectedRectangleDownLocation = new Point();
            mouseDownLocation             = new Point();

            ClickData.Clear(true);
            action = SelectorAction.None;
        }
Exemple #7
0
 public override void OnUnloadTool()
 {
     ClearSelectedRectangle();
     ClickData.Clear(false);
     action = SelectorAction.None;
     if (OutlinePen != null)
     {
         OutlinePen.Dispose();
     }
 }
Exemple #8
0
        public override void OnMouseUp(object sender, MouseEventArgs e)
        {
            var mouseLocation   = e.Location;
            var snappedLocation = Grid.SnapToGrid(mouseLocation);

            switch (action)
            {
            case SelectorAction.BeginSelectionRectangle:
                // Redirect to MouseUp:EndSelectionRectangle
                action = SelectorAction.EndSelectionRectangle;
                OnMouseUp(sender, e);
                break;

            case SelectorAction.EndSelectionRectangle:
                SetSelectedRectangle(mouseDownLocation, mouseLocation);
                break;

            case SelectorAction.BeginMoveSelectedShapes:
                // Redirect to MouseUp:EndMoveSelectedShapes
                action = SelectorAction.EndMoveSelectedShapes;
                OnMouseUp(sender, e);
                break;

            case SelectorAction.EndMoveSelectedShapes:
                ClickData.ShapeApplyOffset();

                // Reset click data
                ClickData.Clear(false);
                selectedRectangleDownLocation = new Point();
                mouseDownLocation             = new Point();

                break;

            case SelectorAction.None:
                break;

            default:
                throw EnumNotImplementedException.Throw(action, ExceptionMessages.MSG_NOT_YET_IMPLEMENTED);
            }

            Canvas.Instance.Invalidate();
        }
Exemple #9
0
        public override void OnMouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            var mouseLocation   = e.Location;
            var snappedLocation = Grid.SnapToGrid(mouseLocation);

            switch (action)
            {
            case SelectorAction.BeginSelectionRectangle:
                mouseDownLocation = mouseLocation;
                //ClickData.Set(mouseDownLocation, ShapeClickAction.Drag);
                SetSelectedRectangle(mouseDownLocation, mouseLocation);
                break;

            case SelectorAction.EndSelectionRectangle:
                OnMouseDown_HandleDragSelection(sender, e, mouseLocation, snappedLocation, true);
                break;

            case SelectorAction.EndMoveSelectedShapes:
                OnMouseDown_HandleDragSelection(sender, e, mouseLocation, snappedLocation, false);
                break;

            case SelectorAction.None:
                // This should only get triggered on the initial mouse down,
                // But in case, just clear the selected rectangle info and MouseDown with BeginSelectionRectangle
                ClearSelectedRectangle();
                action = SelectorAction.BeginSelectionRectangle;

                OnMouseDown(sender, e);
                break;

            default:
                throw EnumNotImplementedException.Throw(action, ExceptionMessages.MSG_NOT_YET_IMPLEMENTED);
            }

            Canvas.Instance.Invalidate();
        }
Exemple #10
0
 internal SelectorActionVisualizer(SelectorAction action, IQualifierVisualizer parent)
     : base(action, parent)
 {
 }
Exemple #11
0
        internal bool Connect(QualifierView qv, TopLevelView targetView)
        {
            ActionView av = null;

            var sv = targetView as SelectorView;

            if (sv != null)
            {
                if (sv.selector.IsConnectedTo(qv.parent.selector))
                {
                    EditorUtility.DisplayDialog("Invalid Action", "Circular connections are not allowed.", "Ok");
                    return(false);
                }

                //Composite actions may also act as selectors as the last step
                var cav = qv.actionView as CompositeActionView;
                if (cav != null)
                {
                    var ca           = (CompositeAction)cav.action;
                    var newConnector = new SelectorAction(sv.selector);

                    _undoRedo.Do(new ConnectCompositeOperation(cav, ca.connectorAction, newConnector));
                    ca.connectorAction = newConnector;
                    cav.targetView     = null;
                    return(true);
                }

                av = new SelectorActionView
                {
                    targetSelector = sv,
                    action         = new SelectorAction(sv.selector),
                    parent         = qv
                };
            }

            var lv = targetView as AILinkView;

            if (lv != null)
            {
                var cav = qv.actionView as CompositeActionView;
                if (cav != null)
                {
                    var ca           = (CompositeAction)cav.action;
                    var newConnector = new AILinkAction(lv.aiId);

                    _undoRedo.Do(new ConnectCompositeOperation(cav, ca.connectorAction, newConnector));
                    ca.connectorAction = newConnector;
                    cav.targetView     = null;
                    return(true);
                }

                av = new AILinkActionView
                {
                    targetAI = lv,
                    action   = new AILinkAction(lv.aiId),
                    parent   = qv
                };
            }

            if (av != null)
            {
                SetAction(av, qv);
                return(true);
            }

            return(false);
        }