use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class HCIPACmd method initHCIPATaskDesign.
// For each design
protected static void initHCIPATaskDesign(Project project, String taskName, AUndertaking[] subtasks, Design design, CognitiveModelGenerator modelGen) {
Frame f = getStartFrame(design);
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
TaskApplication ta = DemoStateManager.ensureTaskApplication(project, subtasks[0], design, modelGen, demoMgr);
Script script = ta.getScript(modelGen);
Demonstration demo = script.getDemonstration();
demo.setStartFrame(f);
demo.setStartFrameChosen(true);
IPredictionAlgo computeAlg = ta.determineActiveAlgorithm(project);
ThinkScriptStep thinkStep = new ThinkScriptStep(f, RECOGNIZE_NEED + taskName);
demo.appendStep(thinkStep);
List<String> warnings = new ArrayList<String>();
List<DefaultModelGeneratorState> states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
script.replaceStepStates(0, states);
APredictionResult result = ComputePredictionCmd.computePrediction(computeAlg, script);
ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
ta = DemoStateManager.ensureTaskApplication(project, subtasks[1], design, modelGen, demoMgr);
script = ta.getScript(modelGen);
demo = ta.getDemonstration();
demo.setStartFrame(f);
demo.setStartFrameChosen(true);
thinkStep = new ThinkScriptStep(f, "Select Function Step");
demo.appendStep(thinkStep);
states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
script.replaceStepStates(0, states);
result = ComputePredictionCmd.computePrediction(computeAlg, script);
ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
}
use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class HCIPACmd method chgFnName.
protected static ThinkScriptStep chgFnName(Project project, AUndertaking renamedTask, Design design, CognitiveModelGenerator modelGen, String thinkLabel) {
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
TaskApplication ta = DemoStateManager.ensureTaskApplication(project, renamedTask, design, modelGen, demoMgr);
AScriptStep thinkStep = ta.getDemonstration().getLastStep();
if ((thinkStep != null) && (thinkStep instanceof ThinkScriptStep)) {
((ThinkScriptStep) thinkStep).setLabel(thinkLabel);
return (ThinkScriptStep) thinkStep;
}
// Either no step or not a think step
return null;
}
use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class DemoScriptCmd method exportScriptToCSV.
public static boolean exportScriptToCSV(Script script, Project project, Interaction interaction, IUndoableEditSequence editSeq) {
Demonstration demo = script.getDemonstration();
TaskApplication ta = demo.getTaskApplication();
Design design = ta.getDesign();
AUndertaking task = ta.getTask();
String name = project.getName();
name += "_" + design.getName();
name += "_" + task.getName();
File dest = null;
if (interaction != null) {
dest = interaction.selectCSVFileDest(name);
} else {
dest = new File(CogTool.exportCSVKludgeDir, name + ".txt");
}
if (dest == null) {
return false;
}
FileWriter fw = null;
BufferedWriter buffer = null;
try {
fw = new FileWriter(dest);
buffer = new BufferedWriter(fw);
CSVSupport.writeCell("Format version:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(FORMAT_VERSION, buffer);
CSVSupport.addLineEnding(buffer);
Date now = new Date();
String date = DateFormat.getDateTimeInstance().format(now);
CSVSupport.writeCell("Date and Time:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(date, buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Project Name:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(project.getName(), buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Design Name:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(design.getName(), buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Task Hierarchy:", buffer);
String taskName = task.getFullName();
String[] cells = taskName.split(":");
for (String cell : cells) {
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(cell, buffer);
}
CSVSupport.addLineEnding(buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.addLineEnding(buffer);
buffer.write("\"Frame\",\"Action\",\"Widget-Name\"," + "\"Displayed-Label\",\"Widget-Type\"");
CSVSupport.addLineEnding(buffer);
IWidget lastMovedToWidget = null;
Iterator<DefaultModelGeneratorState> stepStates = script.getStepStates().iterator();
while (stepStates.hasNext()) {
DefaultModelGeneratorState stepState = stepStates.next();
AScriptStep step = stepState.getScriptStep();
TransitionSource stepFocus = step.getStepFocus();
String frameName = step.getCurrentFrame().getName();
String actionName = KeyDisplayUtil.convertActionToMenuText(step.getLocalizedString());
if ((!(step instanceof LookAtScriptStep)) && (!(step instanceof ThinkScriptStep)) && (!(step instanceof TextActionSegment))) {
actionName = step.getLocalizedActionString(actionName, lastMovedToWidget);
}
lastMovedToWidget = stepState.getLastMovedToWidget();
String widgetName = "";
String widgetType = "";
String widgetTitle = "";
if (stepFocus != null) {
widgetName = stepFocus.getName();
if (stepFocus instanceof IWidget) {
IWidget w = (IWidget) stepFocus;
widgetType = w.getWidgetType().toString();
String s = w.getTitle();
if (s != null) {
widgetTitle = s;
}
}
}
CSVSupport.writeCell(frameName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(actionName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetTitle, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetType, buffer);
CSVSupport.addLineEnding(buffer);
}
Frame resultFrame = demo.getResultFrame();
if (resultFrame != null) {
CSVSupport.writeCell(resultFrame.getName(), buffer);
}
if (interaction != null) {
interaction.setStatusMessage(L10N.get("DSO.ExportCompletedPre", "Export completed to ") + dest + L10N.get("DSO.ExportCompletePost", "."));
}
} catch (IOException e) {
if (interaction != null) {
interaction.reportProblem("File I/O Error", e.getMessage());
} else {
e.printStackTrace();
}
return false;
} finally {
try {
if (buffer != null) {
buffer.close();
}
if (fw != null) {
fw.close();
}
} catch (IOException e) {
if (interaction != null) {
interaction.reportProblem("File I/O Error on Close", e.getMessage());
} else {
e.printStackTrace();
}
return false;
}
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class SEDemoController method performInsertThink.
// insertStep
protected boolean performInsertThink(SEDemoSelectionState selection) {
SEDemoInteraction.TimedActionData data = getTimedActionData(ThinkScriptStep.DEFAULT_KLM_THINK_DURATION, ThinkScriptStep.DEFAULT_THINK_LABEL, IS_THINK);
// Check to see if the user canceled the operation.
if (data != null) {
AScriptStep beforeStep = getDemoStep(selection);
// a Delay, if so ask the user about it.
if ((beforeStep != null) && (beforeStep instanceof DelayScriptStep)) {
Boolean reposition = interaction.confirmNewThinkLocation();
if (reposition == null) {
// Break out; the user canceled
return false;
}
if (reposition.booleanValue()) {
// We want to insert it AFTER the delay step
beforeStep = script.getDemonstration().getNextStep(beforeStep);
}
// O.w., the user confirmed they wanted it where they put it.
}
AScriptStep thinkStep = new ThinkScriptStep(getCurrentFrame(beforeStep), data.duration, data.labelString);
return insertStep(thinkStep, beforeStep, SEDemoLID.InsertThink, INSERT_THINK);
}
// Cannot complete action / was canceled
return false;
}
use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class SEDemoController method performChangeThink.
// performInsertThink
protected boolean performChangeThink(SEDemoSelectionState selection) {
DefaultModelGeneratorState selectedState = selection.getSelectedState();
if ((selectedState == null) || !(selectedState.getScriptStep() instanceof ThinkScriptStep)) {
interaction.protestNotThinkStep();
return false;
}
final ThinkScriptStep thinkStep = (ThinkScriptStep) selectedState.getScriptStep();
final double oldDuration = thinkStep.getThinkDuration();
final String oldLabel = thinkStep.getLabel();
final SEDemoInteraction.TimedActionData data = getTimedActionData(oldDuration, oldLabel, IS_THINK);
if (data == null) {
return false;
}
thinkStep.setThinkDuration(data.duration);
thinkStep.setLabel(data.labelString);
final Collection<ComputationUndoRedo> computeUndoRedos = resetComputations();
IUndoableEdit edit = new AUndoableEdit(SEDemoLID.ChangeThinkProperties) {
@Override
public String getPresentationName() {
return CHG_THINK_PROPERTIES;
}
@Override
public void redo() {
super.redo();
thinkStep.setThinkDuration(data.duration);
thinkStep.setLabel(data.labelString);
DemoScriptCmd.redoAllChanges(computeUndoRedos);
}
@Override
public void undo() {
super.undo();
thinkStep.setThinkDuration(oldDuration);
thinkStep.setLabel(oldLabel);
DemoScriptCmd.undoAllChanges(computeUndoRedos);
}
};
undoMgr.addEdit(edit);
return true;
}
Aggregations