use of edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException 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;
}
};
}
Aggregations