use of edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException 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.util.RcvrIllegalStateException in project cogtool by cogtool.
the class ProjectController method createGenerateACTRModelAction.
// createImportHumanCSVFileAction
protected IListenerAction createGenerateACTRModelAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
// Must have selected tasks and design
Design design = seln.getSelectedDesign();
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
for (AUndertaking task : tasks) {
TaskApplication ta = project.getTaskApplication(task, design);
Script s = DemoStateManager.ensureScript(ta, KLMCognitiveGenerator.ONLY);
// TODO There's too much algorithm specific code
// in here; but for now it seems the expedient
// thing to do -- all this needs to be thought
// through for all back ends, and restructured
String path = s.getAssociatedPath();
String filename = null;
if (path == null) {
filename = design.getName() + "-" + task.getName();
} else {
filename = (new File(path)).getName();
if ((filename != null) && filename.endsWith(CogToolFileTypes.LISP_FILE_EXT)) {
filename = filename.substring(0, filename.length() - CogToolFileTypes.LISP_FILE_EXT.length());
}
}
File file = interaction.selectExportLocation(filename, CogToolFileTypes.LISP_FILE_EXT);
if (file == null) {
return false;
}
s.setAssociatedPath(file.getAbsolutePath());
// so we have to delete it.
if (file.length() == 0) {
file.delete();
}
try {
IPredictionAlgo taAlg = ta.determineActiveAlgorithm(project);
if (!(taAlg instanceof ACTRPredictionAlgo)) {
throw new RcvrIllegalStateException("Can't generate ACT-R Model from a non ACT-R task.");
}
ACTRPredictionAlgo algo = (ACTRPredictionAlgo) taAlg;
algo.outputModel(design, task, s.getDemonstration().getStartFrame(), s, file, null);
} catch (UnsupportedOperationException ex) {
throw new RcvrUnimplementedFnException(ex);
} catch (IOException ex) {
throw new RcvrIOException(("IOException generating model file for task " + task.getName() + " in design " + design.getName()), ex);
}
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException in project cogtool by cogtool.
the class ProjectController method importDesign.
protected void importDesign(TaskParent parent, DesignSelectionState prms, Design newDesign, Collection<Demonstration> demonstrations, Set<AUndertaking> newUndertakings, IUndoableEditSequence editSeq) {
makeDesignNameUnique(newDesign);
ProjectCmd.addNewDesign(project, newDesign, prms.getSelectedDesign(), importXMLPresentation, editSeq);
// Add taskapplications/tasks as well for demonstrations
if ((demonstrations != null) && (demonstrations.size() > 0)) {
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, newDesign);
Iterator<Demonstration> demoIt = demonstrations.iterator();
while (demoIt.hasNext()) {
Demonstration demo = demoIt.next();
TaskApplication taskApp = demo.getTaskApplication();
AUndertaking demoTask = taskApp.getTask();
if (demoTask.getTaskGroup() == null && !newUndertakings.contains(demoTask)) {
// If the taskApp's task is not already part of the
// project, add it. Regardless, any project root task
// with the same name should be the same at this point!
AUndertaking rootTask = parent.getUndertaking(demoTask.getName());
if (rootTask == null) {
parent.addUndertaking(demoTask);
editSeq.addEdit(createNewTaskUndo(parent, Project.AT_END, demoTask, ProjectLID.ImportXML, importXMLPresentation));
} else if (rootTask != demoTask) {
throw new RcvrIllegalStateException("Unexpected root task difference");
}
}
project.setTaskApplication(taskApp);
demoMgr.trackEdits(demo);
}
}
}
Aggregations