Search in sources :

Example 6 with ThinkScriptStep

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));
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ArrayList(java.util.ArrayList) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 7 with ThinkScriptStep

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;
}
Also used : TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)

Example 8 with ThinkScriptStep

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;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) FileWriter(java.io.FileWriter) IOException(java.io.IOException) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) Design(edu.cmu.cs.hcii.cogtool.model.Design) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) TextActionSegment(edu.cmu.cs.hcii.cogtool.model.TextActionSegment) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) LookAtScriptStep(edu.cmu.cs.hcii.cogtool.model.LookAtScriptStep) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) File(java.io.File) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 9 with ThinkScriptStep

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;
}
Also used : DelayScriptStep(edu.cmu.cs.hcii.cogtool.model.DelayScriptStep) SEDemoInteraction(edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)

Example 10 with ThinkScriptStep

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;
}
Also used : ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) SEDemoInteraction(edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)

Aggregations

ThinkScriptStep (edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)11 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)8 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)7 DelayScriptStep (edu.cmu.cs.hcii.cogtool.model.DelayScriptStep)5 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)4 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)4 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)3 SEDemoInteraction (edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction)3 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)2 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)2 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)1 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)1 ActionScriptStep (edu.cmu.cs.hcii.cogtool.model.ActionScriptStep)1 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)1 HearScriptStep (edu.cmu.cs.hcii.cogtool.model.HearScriptStep)1 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)1 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1