Search in sources :

Example 26 with Script

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

the class DemoStateManager method ensureScript.

public static Script ensureScript(TaskApplication ta, CognitiveModelGenerator gen) {
    if (gen != null) {
        Script script = ta.getScript(gen);
        if (script == null) {
            script = new Script(ta.getDemonstration(), gen);
            ta.setScript(gen, script);
        }
        return script;
    }
    return null;
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script)

Example 27 with Script

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

the class ComputePredictionCmd method computeAllPredictions.

/**
     * Utility to recompute in the main thread all the results for
     * all the scripts of a TaskApplication, using the given callback.
     */
public static IUndoableEdit computeAllPredictions(Project project, final TaskApplication ta, final IPredictionAlgo compute, boolean inBackground, Interaction interaction) {
    // The list of old results that were replaced.
    final Map<CognitiveModelGenerator, APredictionResult> oldResults = new HashMap<CognitiveModelGenerator, APredictionResult>();
    // It is possible the set of old results does not include one for the
    // specified computation algorithm; after enumerating, track new
    // results for that algorithm (needed so that we can unset results
    // in the undo action!).
    final List<APredictionResult> ensuredResults = new ArrayList<APredictionResult>();
    Iterator<CognitiveModelGenerator> modelGens = ta.getModelGenerators();
    int obsoleteWaitContainingResults = 0;
    while (modelGens.hasNext()) {
        CognitiveModelGenerator modelGen = modelGens.next();
        APredictionResult oldResult = ta.getResult(modelGen, compute);
        // oldResult may be null if not set
        oldResults.put(modelGen, oldResult);
        Script script = ta.getScript(modelGen);
        APredictionResult ensureResult;
        if (inBackground) {
            ensureResult = computeInBackground(compute, script, interaction);
        } else {
            ensureResult = computePrediction(compute, script, null);
        }
        if (ACTRPredictionAlgo.usesObsoleteWaits(ensureResult)) {
            ++obsoleteWaitContainingResults;
        }
        ensuredResults.add(ensureResult);
        ta.setResult(modelGen, compute, ensureResult);
    }
    if (obsoleteWaitContainingResults > 0) {
        interaction.protestObsoleteWaits();
    }
    if (ensuredResults.size() > 0) {
        IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {

            @Override
            public String getPresentationName() {
                return L10N.get("UNDO.PM.RecomputeScript(s)", "Recompute Script(s)");
            }

            protected void setResults(List<APredictionResult> results) {
                int numResults = results.size();
                for (int i = 0; i < numResults; i++) {
                    APredictionResult result = results.get(i);
                    result = PredictionResultProxy.getLatestResult(result);
                    results.set(i, result);
                    ta.setResult(result.getScript().getModelGenerator(), result.getPredictionAlgorithm(), result);
                }
            }

            @Override
            public void redo() {
                super.redo();
                setResults(ensuredResults);
            }

            @Override
            public void undo() {
                super.undo();
                Iterator<Map.Entry<CognitiveModelGenerator, APredictionResult>> resetResults = oldResults.entrySet().iterator();
                while (resetResults.hasNext()) {
                    Map.Entry<CognitiveModelGenerator, APredictionResult> entry = resetResults.next();
                    // key is modelGen, value part is the old result
                    CognitiveModelGenerator modelGen = entry.getKey();
                    APredictionResult oldResult = entry.getValue();
                    if (oldResult == null) {
                        ta.unsetResult(modelGen, compute);
                    } else {
                        ta.setResult(modelGen, compute, oldResult);
                    }
                }
            }
        };
        addUndoableEditToScripts(edit, ta, project);
        return edit;
    }
    return null;
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) ArrayList(java.util.ArrayList) List(java.util.List) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) HashMap(java.util.HashMap) Map(java.util.Map)

Example 28 with Script

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

the class ScriptViewerUI method dispose.

@Override
public void dispose() {
    CogTool.selectionPhase.removeDelayedWork(delayedStateSelection);
    CogTool.repaintPhase.removeDelayedWork(delayedRepainting);
    uiModel.dispose();
    TaskGroup group = (TaskGroup) taskDesign.getTask();
    Iterator<AUndertaking> tasks = group.getUndertakings().iterator();
    while (tasks.hasNext()) {
        AUndertaking t = tasks.next();
        TaskApplication tApp = project.getTaskApplication(t, design);
        if (tApp == null) {
            continue;
        }
        Script script = tApp.getOnlyScript();
        script.removeAllHandlers(this);
        script.getDemonstration().removeAllHandlers(this);
    }
    selection.removeAllHandlers(this);
    view.removeSWTListSelectionHandler(SWTselectionChangeHandler);
    super.dispose();
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) SWTListGroupScript(edu.cmu.cs.hcii.cogtool.view.SWTListGroupScript) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Aggregations

Script (edu.cmu.cs.hcii.cogtool.model.Script)28 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)20 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)13 Design (edu.cmu.cs.hcii.cogtool.model.Design)10 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)8 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)7 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)7 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)7 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)6 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)6 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)6 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)5 File (java.io.File)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ACTRPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)4 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)4 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)4 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)4 RcvrUnimplementedFnException (edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException)4