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));
}
}
}
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);
}
}
}
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;
}
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;
}
};
}
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;
}
Aggregations