Search in sources :

Example 11 with CognitiveModelGenerator

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

the class DemoScriptCmd method resetComputations.

/**
     * Adds all generated undos/redos to the given collection.
     */
public static void resetComputations(TaskApplication taskApp, Collection<ComputationUndoRedo> undoRedos) {
    Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
    while (modelGens.hasNext()) {
        CognitiveModelGenerator modelGen = modelGens.next();
        Script s = taskApp.getScript(modelGen);
        if (s != null) {
            undoRedos.add(new DemoScriptCmd.ComputationUndoRedo(s));
        }
    }
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)

Example 12 with CognitiveModelGenerator

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

the class DemoScriptCmd method addUndoableEditToScripts.

/**
     * Adds the edit for each of the scripts in the demonstration except
     * the given script.
     */
protected static void addUndoableEditToScripts(IUndoableEditSequence seq, Demonstration demo, Script exceptScript, Project project) {
    TaskApplication taskApp = demo.getTaskApplication();
    Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
    while (modelGens.hasNext()) {
        CognitiveModelGenerator modelGen = modelGens.next();
        Script script = taskApp.getScript(modelGen);
        if (script != exceptScript) {
            CommandUtil.addAsUndoableEdit(seq, script, project);
        }
    }
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)

Example 13 with CognitiveModelGenerator

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

the class DemoScriptCmd method regenerateScripts.

public static Collection<ComputationUndoRedo> regenerateScripts(Demonstration demo, int atStepIndex, AScriptStep oldDemoStep, Interaction interaction) {
    Collection<ComputationUndoRedo> scriptsUndoRedoData = new ArrayList<ComputationUndoRedo>();
    if (!demo.isEditable()) {
        return scriptsUndoRedoData;
    }
    TaskApplication taskApp = demo.getTaskApplication();
    Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
    while (modelGens.hasNext()) {
        CognitiveModelGenerator modelGen = modelGens.next();
        Script script = taskApp.getScript(modelGen);
        if (script != null) {
            scriptsUndoRedoData.add(new ScriptUndoRedo(script, interaction, atStepIndex, oldDemoStep));
        }
    }
    return scriptsUndoRedoData;
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) ArrayList(java.util.ArrayList) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)

Example 14 with CognitiveModelGenerator

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

the class ProjectController method createScriptEditorAction.

// Action for EditScript
protected IListenerAction createScriptEditorAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object prms) {
            if (prms != null) {
                ProjectSelectionState seln = (ProjectSelectionState) prms;
                // Must have selected tasks and design
                Design design = seln.getSelectedDesign();
                AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
                if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                    return false;
                }
                DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
                // Editing a script only applies to tasks, not task groups
                for (int i = 0; i < tasks.length; i++) {
                    if (!tasks[i].isTaskGroup()) {
                        CognitiveModelGenerator gen = MODELGEN_ALG;
                        TaskGroup group = tasks[i].getTaskGroup();
                        if (group != null) {
                            Object isSnifAct = group.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
                            if (isSnifAct != null) {
                                gen = IdentityModelGenerator.ONLY;
                            }
                        }
                        // If no script set exists for this cell, create
                        TaskApplication ta = ensureTaskApplication(tasks[i], design, gen, demoMgr);
                        Demonstration demo = ta.getDemonstration();
                        if (CogToolPref.HCIPA.getBoolean()) {
                            HCIPACmd.checkStartFrame(project, ta, gen);
                        }
                        // Determine which window to open/create
                        if ((demo.getStartFrame() == null) || !demo.isStartFrameChosen()) {
                            // No start frame; present ui to choose one
                            SEFrameChooserController.openController(ta, gen, project);
                        } else {
                            // Start frame chosen; go straight to demo ui
                            try {
                                SEDemoController.openController(ta, gen, project);
                            } catch (GraphicsUtil.ImageException ex) {
                                interaction.protestInvalidImageFile();
                            }
                        }
                    }
                // Else do nothing when a TaskGroup cell is "edited"
                }
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 15 with CognitiveModelGenerator

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

the class ProjectController method openProjectOnCompute.

/**
     * editSeq will be null if no regeneration occurred; otherwise,
     * the edit sequence will contain the undoable edit for the regeneration.
     */
public static boolean openProjectOnCompute(Project project, final Script script, final APredictionResult newResult, CompoundUndoableEdit editSeq) {
    boolean notModified;
    try {
        notModified = UndoManager.isAtSavePoint(project);
    } catch (IllegalStateException ex) {
        System.err.println("Ignoring that isAtSavePoint failed.");
        notModified = false;
    }
    ProjectController c = ProjectController.openController(project, false, notModified);
    final CognitiveModelGenerator modelGen = script.getModelGenerator();
    final IPredictionAlgo computeAlg = newResult.getPredictionAlgorithm();
    final TaskApplication taskApp = script.getDemonstration().getTaskApplication();
    final APredictionResult oldResult = taskApp.getResult(modelGen, computeAlg);
    taskApp.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(newResult));
    UndoManager scriptUndoMgr = UndoManager.getUndoManager(script, project);
    IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {

        protected APredictionResult redoResult = newResult;

        protected APredictionResult undoResult = oldResult;

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

        @Override
        public void redo() {
            super.redo();
            redoResult = PredictionResultProxy.getLatestResult(redoResult);
            taskApp.setResult(modelGen, computeAlg, redoResult);
        }

        @Override
        public void undo() {
            super.undo();
            undoResult = PredictionResultProxy.getLatestResult(undoResult);
            taskApp.setResult(modelGen, computeAlg, undoResult);
        }
    };
    if (editSeq != null) {
        editSeq.addEdit(edit);
        editSeq.end();
        edit = editSeq;
    }
    // Add to script's undo mgr first to set owner properly
    scriptUndoMgr.addEdit(edit);
    c.undoMgr.addEdit(edit);
    c.takeFocus();
    return true;
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Aggregations

CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)16 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)11 Script (edu.cmu.cs.hcii.cogtool.model.Script)7 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)6 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)5 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)5 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)3 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 UndoManager (edu.cmu.cs.hcii.cogtool.util.UndoManager)3 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)2 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)2 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)2 ArrayList (java.util.ArrayList)2 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)1 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)1