Search in sources :

Example 6 with AScriptStep

use of edu.cmu.cs.hcii.cogtool.model.AScriptStep in project cogtool by cogtool.

the class SNIFACTCmd method setUpTaskApplication.

/**
     * Generates a script using the given generator and situates the task
     * application in the project.
     * Assumes the demonstration in the task application already contains a list
     * of script steps.
     */
public static void setUpTaskApplication(Project project, TaskApplication ta, CognitiveModelGenerator gen) {
    Design design = ta.getDesign();
    Demonstration demo = ta.getDemonstration();
    DemoStateManager.getStateManager(project, design).trackEdits(demo);
    Script s = new Script(demo, gen);
    // Scripts generated by the SNIF-ACT algorithm are not editable!
    demo.setEditable(false);
    Iterator<AScriptStep> newDemoSteps = demo.getStepsAt(0);
    List<DefaultModelGeneratorState> newStepStates = new ArrayList<DefaultModelGeneratorState>();
    List<String> errorLines = new ArrayList<String>();
    DefaultModelGeneratorState stepState = demo.getInitialState();
    while (newDemoSteps.hasNext()) {
        AScriptStep newDemoStep = newDemoSteps.next();
        stepState = gen.generateScriptSteps(newDemoStep, stepState, errorLines, newStepStates);
    }
    s.replaceStepStates(0, newStepStates);
    ta.setScript(gen, s);
    project.setTaskApplication(ta);
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) Script(edu.cmu.cs.hcii.cogtool.model.Script) ArrayList(java.util.ArrayList) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 7 with AScriptStep

use of edu.cmu.cs.hcii.cogtool.model.AScriptStep in project cogtool by cogtool.

the class SEDemoUI method addSelectionChangeListeners.

/**
     * Add the selection Change event listeners.
     */
protected void addSelectionChangeListeners() {
    SWTselectionChangeHandler = new SelectionListener() {

        public void widgetSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            for (TableItem selectedItem : selectedItems) {
                // TODO: Currently supports only single selection.
                Object data = selectedItem.getData();
                if (data instanceof Frame) {
                    selection.setSelectedState(null);
                } else {
                    // should be instanceof DefaultModelGeneratorState!!!
                    AScriptStep step = ((DefaultModelGeneratorState) data).getScriptStep();
                    if (step instanceof HearScriptStep) {
                        if (interaction.askEditFrame()) {
                            Frame f = step.getCurrentFrame();
                            performAction(DesignEditorLID.EditFrame, f);
                        }
                        TableItem previousSelectedRow = swtList.getRowItem(selection.getPreviousSelection());
                        selection.setSelectedState(previousSelectedRow);
                    } else {
                        selection.setSelectedState(selectedItem);
                    }
                }
            }
            centerSelectedRegion();
            setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
        // Let selection change handle changing the frame
        }

        public void widgetDefaultSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            // TODO: Currently supports only single selection.
            for (TableItem selectedItem : selectedItems) {
                Object data = selectedItem.getData();
                if (data instanceof DefaultModelGeneratorState) {
                    DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
                    AScriptStep step = stepState.getScriptStep();
                    // In case we need this; not a context selection
                    // in truth, but we can re-use the structure.
                    contextSelection.setSelectedState(stepState);
                    if (editable) {
                        if (step instanceof DelayScriptStep) {
                            performAction(SEDemoLID.ChangeWaitProperties, contextSelection);
                        } else if (step instanceof ThinkScriptStep) {
                            performAction(SEDemoLID.ChangeThinkProperties, contextSelection);
                        } else if (isEditable(step)) {
                            performAction(SEDemoLID.Edit, contextSelection);
                        }
                    }
                }
            }
        }
    };
    view.addSWTListSelectionHandler(SWTselectionChangeHandler);
    AlertHandler selectionChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            SEDemoSelectionState.StepStateSelectionChange event = (SEDemoSelectionState.StepStateSelectionChange) alert;
            if (event != null) {
                if (event.selected) {
                    DefaultModelGeneratorState stepState = event.changedState;
                    uiModel.setCurrentOverride(script, script.getPreviousState(stepState));
                    Frame resultFrame = null;
                    if (stepState != null) {
                        resultFrame = stepState.getScriptStep().getCurrentFrame();
                    } else {
                        resultFrame = script.getDemonstration().getResultFrame();
                    }
                    try {
                        setCurrentFrame(resultFrame);
                    } catch (GraphicsUtil.ImageException ex) {
                        throw new RcvrImageException("Changing current demonstration frame", ex);
                    }
                } else {
                    // deselect item.
                    uiModel.setCurrentOverride(script, script.getLastState());
                }
            }
        }
    };
    selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
Also used : DelayScriptStep(edu.cmu.cs.hcii.cogtool.model.DelayScriptStep) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TableItem(org.eclipse.swt.widgets.TableItem) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) EventObject(java.util.EventObject) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) SWTList(edu.cmu.cs.hcii.cogtool.view.SWTList) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HearScriptStep(edu.cmu.cs.hcii.cogtool.model.HearScriptStep) EventObject(java.util.EventObject) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 8 with AScriptStep

use of edu.cmu.cs.hcii.cogtool.model.AScriptStep in project cogtool by cogtool.

the class SEDemoController method performInsertThink.

// insertStep
protected boolean performInsertThink(SEDemoSelectionState selection) {
    SEDemoInteraction.TimedActionData data = getTimedActionData(ThinkScriptStep.DEFAULT_KLM_THINK_DURATION, ThinkScriptStep.DEFAULT_THINK_LABEL, IS_THINK);
    // Check to see if the user canceled the operation.
    if (data != null) {
        AScriptStep beforeStep = getDemoStep(selection);
        // a Delay, if so ask the user about it.
        if ((beforeStep != null) && (beforeStep instanceof DelayScriptStep)) {
            Boolean reposition = interaction.confirmNewThinkLocation();
            if (reposition == null) {
                // Break out; the user canceled
                return false;
            }
            if (reposition.booleanValue()) {
                // We want to insert it AFTER the delay step
                beforeStep = script.getDemonstration().getNextStep(beforeStep);
            }
        // O.w., the user confirmed they wanted it where they put it.
        }
        AScriptStep thinkStep = new ThinkScriptStep(getCurrentFrame(beforeStep), data.duration, data.labelString);
        return insertStep(thinkStep, beforeStep, SEDemoLID.InsertThink, INSERT_THINK);
    }
    // Cannot complete action / was canceled
    return false;
}
Also used : DelayScriptStep(edu.cmu.cs.hcii.cogtool.model.DelayScriptStep) SEDemoInteraction(edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)

Example 9 with AScriptStep

use of edu.cmu.cs.hcii.cogtool.model.AScriptStep in project cogtool by cogtool.

the class SEDemoController method performTransition.

/**
     * Take the transition, and perform the action
     *
     * @param transition
     */
protected boolean performTransition(SEDemoSelectionState selection, Transition transition, CogToolLID lid) {
    AScriptStep stepToReplace = getDemoStep(selection);
    if (stepToReplace != null) {
        Frame currentFrame = stepToReplace.getCurrentFrame();
        if (transition.getDestination() == currentFrame) {
            return insertStep(new TransitionScriptStep(transition), stepToReplace, lid, PERFORM_TRANSITION);
        }
        if (!interaction.confirmDestructiveInsert()) {
            return false;
        }
    }
    AScriptStep newDemoStep = new TransitionScriptStep(transition);
    TransitionSource source = transition.getSource();
    if (source.getFrame() == transition.getDestination() && (source instanceof IWidget)) {
        toggleIfGermane((IWidget) source, newDemoStep, transition.getAction());
    }
    Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
    Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
    Demonstration demo = script.getDemonstration();
    final int atIndex = demo.replaceSteps(stepToReplace, newDemoSteps, oldDemoSteps);
    final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, stepToReplace, interaction);
    IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, oldDemoSteps, demoStateMgr) {

        @Override
        public String getPresentationName() {
            return PERFORM_TRANSITION;
        }

        @Override
        public void redo() {
            super.redo();
            demo.replaceSteps(atIndex, redoDemoSteps);
            DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
        }

        @Override
        public void undo() {
            super.undo();
            demo.replaceSteps(atIndex, undoDemoSteps);
            DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
        }
    };
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(PERFORM_TRANSITION, lid);
    editSequence.addEdit(edit);
    if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
        DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
    }
    editSequence.end();
    undoMgr.addEdit(editSequence);
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TransitionScriptStep(edu.cmu.cs.hcii.cogtool.model.TransitionScriptStep) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 10 with AScriptStep

use of edu.cmu.cs.hcii.cogtool.model.AScriptStep in project cogtool by cogtool.

the class SEDemoController method performInsertDelay.

// performChangeThink
protected boolean performInsertDelay(SEDemoSelectionState selection) {
    SEDemoInteraction.TimedActionData data = getTimedActionData(DelayScriptStep.DEFAULT_DELAY_DURATION, DelayScriptStep.DEFAULT_DELAY_LABEL, IS_WAIT);
    // Check to see if the user canceled the operation.
    if (data != null) {
        AScriptStep beforeStep = getDemoStep(selection);
        // Check to see that we are not inserting the
        // delay DIRECTLY after a think.
        AScriptStep prevStep = null;
        if (beforeStep == null) {
            prevStep = script.getDemonstration().getLastStep();
        } else {
            prevStep = script.getDemonstration().getPreviousStep(beforeStep);
        }
        if ((prevStep != null) && (prevStep instanceof ThinkScriptStep)) {
            Boolean reposition = interaction.confirmNewDelayLocation();
            if (reposition == null) {
                // Break out; the user canceled
                return false;
            }
            if (reposition.booleanValue()) {
                beforeStep = prevStep;
            }
        // O.w., the user confirmed they wanted it where they put it.
        }
        AScriptStep delayStep = new DelayScriptStep(getCurrentFrame(beforeStep), data.duration, data.labelString);
        return insertStep(delayStep, beforeStep, SEDemoLID.InsertDelay, INSERT_DELAY);
    }
    // Can not complete action / was canceled
    return false;
}
Also used : DelayScriptStep(edu.cmu.cs.hcii.cogtool.model.DelayScriptStep) SEDemoInteraction(edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)

Aggregations

AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)16 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)8 ThinkScriptStep (edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)8 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)6 DelayScriptStep (edu.cmu.cs.hcii.cogtool.model.DelayScriptStep)5 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)5 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)3 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)3 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)3 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 LinkedHashSet (java.util.LinkedHashSet)3 ActionScriptStep (edu.cmu.cs.hcii.cogtool.model.ActionScriptStep)2 LookAtScriptStep (edu.cmu.cs.hcii.cogtool.model.LookAtScriptStep)2 Script (edu.cmu.cs.hcii.cogtool.model.Script)2 TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)2 SEDemoInteraction (edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction)2 BufferedWriter (java.io.BufferedWriter)2