Exemplo n.º 1
0
 private Task WaitFor(InputType type, UserDirective directive, RubberBandGenerator onCursorMove)
 {
     pushValueDone = new TaskCompletionSource <bool>();
     SetPrompt(directive.Prompt);
     currentDirective              = directive;
     AllowedInputTypes             = type;
     lastType                      = PushedValueType.None;
     pushedPoint                   = default(Point);
     pushedEntity                  = null;
     pushedDirective               = null;
     pushedString                  = null;
     Workspace.RubberBandGenerator = onCursorMove;
     return(pushValueDone.Task);
 }
Exemplo n.º 2
0
        public DisplayInteractionManager(IWorkspace workspace, ProjectionStyle uiProjectionStyle)
        {
            _workspace          = workspace;
            UIProjectionStyle   = uiProjectionStyle;
            rubberBandGenerator = _workspace.RubberBandGenerator;
            panCommand          = (PanCommand)_workspace.GetCommand("View.Pan").Item1;

            _workspace.WorkspaceChanged                   += Workspace_WorkspaceChanged;
            _workspace.CommandExecuted                    += Workspace_CommandExecuted;
            _workspace.RubberBandGeneratorChanged         += Workspace_RubberBandGeneratorChanged;
            _workspace.SelectedEntities.CollectionChanged += SelectedEntities_CollectionChanged;
            _workspace.InputService.ValueRequested        += InputService_ValueRequested;
            _workspace.InputService.ValueReceived         += InputService_ValueReceived;
            _workspace.InputService.InputCanceled         += InputService_InputCanceled;
            _workspace.Update(viewControl: this, isDirty: _workspace.IsDirty);

            SetCursorVisibility();
        }
 public RubberBandGeneratorChangedEventArgs(RubberBandGenerator generator)
 {
     Generator = generator;
 }
Exemplo n.º 4
0
        public async Task <ValueOrDirective <IEnumerable <Entity> > > GetEntities(string prompt = null, EntityKind entityKinds = EntityKind.All, RubberBandGenerator onCursorMove = null)
        {
            OnValueRequested(new ValueRequestedEventArgs(InputType.Entities | InputType.Directive));
            ValueOrDirective <IEnumerable <Entity> >?result = null;
            HashSet <Entity> entities     = new HashSet <Entity>();
            bool             awaitingMore = true;

            while (awaitingMore)
            {
                await WaitFor(InputType.Entities | InputType.Directive, new UserDirective(prompt ?? "Select entities", "all"), onCursorMove);

                switch (lastType)
                {
                case PushedValueType.Cancel:
                    result = ValueOrDirective <IEnumerable <Entity> > .GetCancel();

                    awaitingMore = false;
                    break;

                case PushedValueType.Directive:
                    Debug.Assert(false, "TODO: allow 'all' directive and 'r' to remove objects from selection");
                    break;

                case PushedValueType.None:
                    result = ValueOrDirective <IEnumerable <Entity> > .GetValue(entities);

                    awaitingMore = false;
                    break;

                case PushedValueType.Entity:
                    if ((entityKinds & pushedEntity.Entity.Kind) == pushedEntity.Entity.Kind)
                    {
                        entities.Add(pushedEntity.Entity);
                        Workspace.SelectedEntities.Add(pushedEntity.Entity);
                    }
                    // TODO: print status
                    break;

                case PushedValueType.Entities:
                    foreach (var e in pushedEntities)
                    {
                        if ((entityKinds & e.Kind) == e.Kind)
                        {
                            entities.Add(e);
                            Workspace.SelectedEntities.Add(e);
                        }
                    }
                    // TODO: print status
                    break;

                default:
                    throw new Exception("Unexpected pushed value");
                }
            }

            ResetWaiters();
            Debug.Assert(result != null, "result should never be null");
            return(result.Value);
        }
Exemplo n.º 5
0
        public async Task <ValueOrDirective <SelectedEntity> > GetEntity(UserDirective directive, RubberBandGenerator onCursorMove = null)
        {
            OnValueRequested(new ValueRequestedEventArgs(InputType.Entity | InputType.Directive));
            await WaitFor(InputType.Entity | InputType.Directive, directive, onCursorMove);

            ValueOrDirective <SelectedEntity> result;

            switch (lastType)
            {
            case PushedValueType.None:
                result = new ValueOrDirective <SelectedEntity>();
                break;

            case PushedValueType.Cancel:
                result = ValueOrDirective <SelectedEntity> .GetCancel();

                break;

            case PushedValueType.Entity:
                result = ValueOrDirective <SelectedEntity> .GetValue(pushedEntity);

                break;

            case PushedValueType.Directive:
                result = ValueOrDirective <SelectedEntity> .GetDirective(pushedDirective);

                break;

            default:
                throw new Exception("Unexpected pushed value");
            }

            ResetWaiters();
            return(result);
        }
Exemplo n.º 6
0
        public async Task <ValueOrDirective <Point> > GetPoint(UserDirective directive, RubberBandGenerator onCursorMove = null, Optional <Point> lastPoint = default(Optional <Point>))
        {
            this.LastPoint = lastPoint.HasValue ? lastPoint.Value : this.LastPoint;
            OnValueRequested(new ValueRequestedEventArgs(InputType.Point | InputType.Directive));
            await WaitFor(InputType.Point | InputType.Directive, directive, onCursorMove);

            ValueOrDirective <Point> result;

            switch (lastType)
            {
            case PushedValueType.Cancel:
                result = ValueOrDirective <Point> .GetCancel();

                break;

            case PushedValueType.None:
                result = new ValueOrDirective <Point>();    // TODO: default directive?
                break;

            case PushedValueType.Directive:
                result = ValueOrDirective <Point> .GetDirective(pushedDirective);

                break;

            case PushedValueType.Point:
                result = ValueOrDirective <Point> .GetValue(pushedPoint);

                break;

            default:
                throw new Exception("Unexpected pushed value");
            }

            ResetWaiters();
            return(result);
        }
Exemplo n.º 7
0
 private void Workspace_RubberBandGeneratorChanged(object sender, EventArgs e)
 {
     rubberBandGenerator = _workspace.RubberBandGenerator;
     UpdateRubberBandLines(unprojectMatrix.Transform(lastPointerPosition));
 }