use of edu.cmu.cs.hcii.cogtool.model.Demonstration 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.Demonstration in project cogtool by cogtool.
the class ProjectController method createImportAction.
protected IListenerAction createImportAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
boolean computeScripts = CogToolPref.COMPSCR.getBoolean();
if (importFile == null) {
importFile = interaction.selectXMLFile(true, null);
} else {
computeScripts = importFileComputes;
}
if (importFile == null) {
return false;
}
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(importXMLPresentation, ProjectLID.ImportXML);
Map<Design, Collection<Demonstration>> parsedDesigns = null;
Set<AUndertaking> newUndertakings = null;
TaskParent parent = project;
try {
if (CogToolPref.HCIPA.getBoolean()) {
TaskGroup importGroup = new TaskGroup(importFile.getName(), GroupNature.SUM);
parent = importGroup;
project.addUndertaking(importGroup);
editSeq.addEdit(createNewTaskUndo(project, Project.AT_END, importGroup, ProjectLID.ImportXML, importXMLPresentation));
}
ImportCogToolXML importer = new ImportCogToolXML();
if (!importer.importXML(importFile, parent, MODELGEN_ALG) || (importer.getDesigns().size() == 0)) {
List<String> errors = importer.getObjectFailures();
if ((errors != null) && (errors.size() > 0)) {
interaction.reportProblems(importXMLPresentation, errors);
} else {
interaction.reportProblem(importXMLPresentation, xmlParseFailed);
}
return false;
}
List<String> warnings = importer.getGenerationWarnings();
if (warnings.size() > 0) {
interaction.reportWarnings(importXMLPresentation, warnings);
}
parsedDesigns = importer.getDesigns();
newUndertakings = importer.getNewUndertakings();
} catch (ImportCogToolXML.ImportFailedException ex) {
throw new RcvrXMLParsingException("Missing XML component", ex);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Image error during loading XML", ex);
} catch (IOException ex) {
throw new RcvrXMLParsingException("IO error loading XML", ex);
} catch (SAXException ex) {
throw new RcvrXMLParsingException("Error parsing XML", ex);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
importFile = null;
importFileComputes = false;
}
for (AUndertaking u : newUndertakings) {
parent.addUndertaking(u);
final AUndertaking uu = u;
final TaskParent pp = parent;
editSeq.addEdit(new AUndoableEdit(ProjectLID.ImportXML) {
@Override
public void redo() {
super.redo();
pp.addUndertaking(uu);
}
@Override
public void undo() {
super.undo();
pp.removeUndertaking(uu);
}
});
}
Iterator<Map.Entry<Design, Collection<Demonstration>>> designDemos = parsedDesigns.entrySet().iterator();
while (designDemos.hasNext()) {
Map.Entry<Design, Collection<Demonstration>> entry = designDemos.next();
importDesign(parent, (DesignSelectionState) prms, entry.getKey(), entry.getValue(), newUndertakings, editSeq);
}
editSeq.end();
undoMgr.addEdit(editSeq);
if (computeScripts) {
//compute predictions for imported project
ProjectContextSelectionState seln = new ProjectContextSelectionState(project);
seln.addSelectedDesigns(project.getDesigns());
ui.selectAllTasks();
recomputeScripts(seln);
ui.deselectAllTasks();
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Demonstration in project cogtool by cogtool.
the class SEDemoController method setMouseHandAction.
// resetComputations
protected void setMouseHandAction(final boolean mouseHand) {
final Demonstration demo = script.getDemonstration();
final boolean oldMouseHand = demo.getMouseHand();
final DefaultModelGeneratorState initialState = demo.getInitialState();
final HandLocation mouseHandLoc = initialState.getHandLocation(oldMouseHand);
final DemoStateManager.IConformanceUndoRedo conformanceUndoRedo = demoStateMgr.restoreConformance(demo);
demo.setMouseHand(mouseHand);
initialState.setHandLocation(mouseHand, mouseHandLoc);
initialState.setHandLocation(!mouseHand, HandLocation.OnKeyboard);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, 0, demo.getStepAt(0), interaction);
IUndoableEdit edit = new AUndoableEdit(SEDemoLID.SetMouseHand) {
@Override
public String getPresentationName() {
return SET_MOUSE_HAND;
}
@Override
public void redo() {
super.redo();
conformanceUndoRedo.redo();
initialState.setHandLocation(mouseHand, mouseHandLoc);
initialState.setHandLocation(!mouseHand, HandLocation.OnKeyboard);
// Do this last as it will alert
demo.setMouseHand(mouseHand);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
conformanceUndoRedo.undo();
initialState.setHandLocation(oldMouseHand, mouseHandLoc);
initialState.setHandLocation(!oldMouseHand, HandLocation.OnKeyboard);
// Do this last as it will alert
demo.setMouseHand(oldMouseHand);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
undoMgr.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.Demonstration in project cogtool by cogtool.
the class SEDemoController method performTransition.
/**
* Take the transition, and perform the action
*
* @param transition
*/
protected boolean performTransition(SEDemoSelectionState selection, Transition transition, CogToolLID lid) {
AScriptStep stepToReplace = getDemoStep(selection);
if (stepToReplace != null) {
Frame currentFrame = stepToReplace.getCurrentFrame();
if (transition.getDestination() == currentFrame) {
return insertStep(new TransitionScriptStep(transition), stepToReplace, lid, PERFORM_TRANSITION);
}
if (!interaction.confirmDestructiveInsert()) {
return false;
}
}
AScriptStep newDemoStep = new TransitionScriptStep(transition);
TransitionSource source = transition.getSource();
if (source.getFrame() == transition.getDestination() && (source instanceof IWidget)) {
toggleIfGermane((IWidget) source, newDemoStep, transition.getAction());
}
Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
Demonstration demo = script.getDemonstration();
final int atIndex = demo.replaceSteps(stepToReplace, newDemoSteps, oldDemoSteps);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, stepToReplace, interaction);
IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, oldDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return PERFORM_TRANSITION;
}
@Override
public void redo() {
super.redo();
demo.replaceSteps(atIndex, redoDemoSteps);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.replaceSteps(atIndex, undoDemoSteps);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(PERFORM_TRANSITION, 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.Demonstration 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;
}
Aggregations