use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class HCIPACmd method checkStartFrame.
public static void checkStartFrame(Project project, TaskApplication ta, CognitiveModelGenerator modelGen) {
Demonstration demo = ta.getDemonstration();
// If start frame is already chosen, fine.
if ((demo.getStartFrame() != null) && (demo.isStartFrameChosen())) {
return;
}
AUndertaking selectedTask = ta.getTask();
// then don't try to determine based on previous sibling's target frame
if (selectedTask.getTaskGroup() == null) {
return;
}
// Try to find the previous sibling
List<AUndertaking> tasks = selectedTask.getTaskGroup().getUndertakings();
int index = tasks.indexOf(selectedTask);
// If no previous sibling, can't do anything
if (index > 1) {
AUndertaking prevTask = tasks.get(index - 1);
TaskApplication prevTA = project.getTaskApplication(prevTask, ta.getDesign());
// can't do anything
if (prevTA != null) {
Demonstration prevDemo = prevTA.getDemonstration();
if (prevDemo != null) {
demo.setStartFrame(prevDemo.getResultFrame());
demo.setStartFrameChosen(prevDemo.isStartFrameChosen());
// In HCIPA, the last state in the previous script should be
// the same as the first state in the new script
Script s = prevTA.getScript(modelGen);
copyState(s, demo);
}
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ProjectController method createEditACTRModelAction.
// TODO it is a crock that we're cloning this stuff; when we have time
// we should design a shared mechanism to be used by all back ends
protected IListenerAction createEditACTRModelAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState selState = (ProjectSelectionState) actionParms;
Design design = selState.getSelectedDesign();
AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
for (AUndertaking task : tasks) {
TaskApplication ta = project.getTaskApplication(task, design);
if (ta == null) {
return false;
}
// find the script
Script script = ta.getScript(KLMCognitiveGenerator.ONLY);
if (script == null) {
return false;
}
// get the resourcePath
String resourcePath = script.getAssociatedPath();
if (resourcePath == null) {
return false;
}
try {
FileUtil.editFile(new File(resourcePath));
} catch (UnsupportedOperationException ex) {
throw new RcvrUnimplementedFnException("Editing a file is not implemented", ex);
} catch (IOException ex) {
throw new RcvrIOException("Problem when trying to edit a file.", ex);
}
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ProjectController method createExportActrModelFile.
// Action for ExportDesignFiles
// XXX: does this really belong in ProjectController? It seems like
// something that's tied to whichever backend we're really using,
// and so should be somewhere else
protected IListenerAction createExportActrModelFile() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState sel = (ProjectSelectionState) actionParms;
// Must have selected tasks and design
Design design = sel.getSelectedDesign();
AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
if ((design == null) || (tasks == null) || (tasks.length == 0)) {
return false;
}
// Ask user for location of saved file.
File exportFile = interaction.selectExportLocation("Exported ACT-R Model", CogToolFileTypes.LISP_FILE_EXT);
// User canceled
if (exportFile == null) {
return false;
}
for (AUndertaking task : tasks) {
// If no script set exists for this cell, create
TaskApplication ta = project.getTaskApplication(task, design);
if (ta != null) {
if (ta.getDesign() != design) {
throw new RcvrIllegalStateException("Unexpected Design mis-match (" + ta.getDesign() + ", " + design + ")");
}
// If no script exists for this cell, create one
Script script = DemoStateManager.ensureScript(ta, MODELGEN_ALG);
try {
IPredictionAlgo taAlg = ta.determineActiveAlgorithm(project);
if (!(taAlg instanceof ACTRPredictionAlgo)) {
throw new RcvrIllegalStateException("Can't export ACT-R Model from a non ACT-R task.");
}
if (script.getAssociatedPath() != null) {
File f = new File(script.getAssociatedPath());
// The following will throw an IOException if
// the input file doesn't exist; this is exactly
// the same behaviour as if we're trying to do
// a recompute, and is better than silently
// substituting a generated model file
FileUtil.copyTextFileToFile(f, exportFile);
return true;
}
ACTRPredictionAlgo algo = (ACTRPredictionAlgo) taAlg;
algo.outputModel(design, task, ta.getDemonstration().getStartFrame(), script, exportFile, null);
} catch (UnsupportedOperationException ex) {
throw new RcvrUnimplementedFnException(ex);
} catch (IOException ex) {
throw new RcvrIOException(("IOException exporting model file for task " + task.getName() + " in design " + design.getName()), ex);
}
}
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class SEDemoController method insertStep.
protected boolean insertStep(final AScriptStep newDemoStep, AScriptStep beforeStep, CogToolLID lid, final String presentationName) {
Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
Set<AScriptStep> emptyDemoSteps = // None are being replaced!
new HashSet<AScriptStep>();
Demonstration demo = script.getDemonstration();
final int atIndex = demo.insertStep(newDemoStep, beforeStep);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, beforeStep, interaction);
if (CogToolPref.HCIPA.getBoolean()) {
TaskApplication ta = script.getDemonstration().getTaskApplication();
AUndertaking t = ta.getTask();
Design d = ta.getDesign();
// Starting with the script after t, update all of the scripts in
// the task group to reflect the new state
TaskGroup grp = t.getTaskGroup();
if (grp != null) {
List<AUndertaking> tasks = grp.getUndertakings();
int startIndex = tasks.indexOf(t);
Script prevScript = script;
for (int i = startIndex + 1; i < tasks.size(); i++) {
t = tasks.get(i);
ta = project.getTaskApplication(t, d);
if (ta == null) {
continue;
}
Script s = ta.getScript(script.getModelGenerator());
Demonstration curDemo = s.getDemonstration();
HCIPACmd.copyState(prevScript, curDemo);
scriptsUndoRedos.addAll(DemoScriptCmd.regenerateScripts(curDemo, 0, curDemo.getStepAt(0), interaction));
prevScript = s;
}
}
}
IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, emptyDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return presentationName;
}
@Override
public void redo() {
super.redo();
demo.insertStep(newDemoStep, atIndex);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.removeStep(atIndex);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(presentationName, lid);
editSequence.addEdit(edit);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
}
editSequence.end();
undoMgr.addEdit(editSequence);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class SEDemoController method createInsertSelfTransitionAction.
protected IListenerAction createInsertSelfTransitionAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoUI.SelfTransition.class;
}
public boolean performAction(Object actionParms) {
SEDemoUI.SelfTransition prms = (SEDemoUI.SelfTransition) actionParms;
if (prms.target != null) {
TaskApplication taskApp = script.getDemonstration().getTaskApplication();
Set<DeviceType> deviceTypeSet = taskApp.getDesign().getDeviceTypes();
int deviceTypes = DeviceType.buildDeviceSet(deviceTypeSet);
int limitMode = ActionProperties.determineChangeActionMode(prms.target);
AAction action = prms.action;
if (prms.action == null) {
properties.resetValues();
properties.setInitialActionType(prms.target, deviceTypeSet);
if (!interaction.determineNewAction(properties, deviceTypes, limitMode, L10N.get("DE.SetActionType", "Set Action Type"))) {
return false;
}
action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
if (action == null) {
return false;
}
}
action = EditActionCmd.ensureActionIsUnique(prms.target, action, properties, deviceTypes, limitMode, null, interaction);
if (action == null) {
return false;
}
return performSelfTransition(prms.selection, prms.target, action, properties.delayInSecs, properties.delayLabel);
}
return false;
}
};
}
Aggregations