Search in sources :

Example 16 with Demonstration

use of edu.cmu.cs.hcii.cogtool.model.Demonstration in project cogtool by cogtool.

the class SEFrameChooserController method createOpenDemonstrationWindowAction.

/**
     * Create the window for demonstrating the entire script.
     */
protected IListenerAction createOpenDemonstrationWindowAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            // Ensure there is a selected start frame.
            final Demonstration demo = taskApp.getDemonstration();
            final Script script = taskApp.getScript(modelGen);
            if (demo.getStartFrame() != null) {
                demo.setStartFrameChosen(true);
                final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, 0, demo.getStepAt(0), interaction);
                // Close the current window.
                closeWindow(false);
                // Open the new demo view window
                try {
                    SEDemoController.openController(taskApp, modelGen, project);
                } catch (GraphicsUtil.ImageException ex) {
                    interaction.protestInvalidImageFile();
                }
                IUndoableEdit edit = new AUndoableEdit(SEFrameChooserLID.OpenScriptEditor) {

                    @Override
                    public String getPresentationName() {
                        return startDemonstrating;
                    }

                    @Override
                    public void redo() {
                        super.redo();
                        if (demo.getStartFrame() != null) {
                            demo.setStartFrameChosen(true);
                            DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
                            // Close the frame chooser window.
                            DefaultController frameController = ControllerRegistry.ONLY.findOpenController(taskApp);
                            if (frameController != null) {
                                frameController.closeWindow(false);
                            }
                            // Open the new demo view window
                            try {
                                SEDemoController.openController(taskApp, modelGen, project);
                            } catch (GraphicsUtil.ImageException ex) {
                                interaction.protestInvalidImageFile();
                            }
                        }
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        DefaultController seDemoController = ControllerRegistry.ONLY.findOpenController(script);
                        if (seDemoController != null) {
                            seDemoController.closeWindow(false);
                        }
                        demo.setStartFrameChosen(false);
                        DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
                        SEFrameChooserController.openController(taskApp, modelGen, project);
                    }
                };
                UndoManager scriptUndoMgr = UndoManager.getUndoManager(script, project);
                scriptUndoMgr.addEdit(edit);
                undoMgr.addEdit(edit);
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration)

Example 17 with Demonstration

use of edu.cmu.cs.hcii.cogtool.model.Demonstration in project cogtool by cogtool.

the class HCIPACmd method exportToHCIPA.

public static boolean exportToHCIPA(Project project, Design design, TaskGroup group, File scriptFile) {
    final String safeDblQuote = quotePHP("\"");
    //        final String safeDblQuote = "\"";   // no escaping needed for SQL
    StringBuilder php = new StringBuilder();
    php.append("<?php\n");
    php.append("// Generated by CogTool version: " + CogTool.getVersion() + "\n");
    php.append("$COGTOOL_EXPORT_VERSION = " + HCIPA_EXPORT_VERSION + ";\n");
    php.append("function insertIntoDatabase_" + HCIPA_EXPORT_VERSION + "($userId) {\n\t");
    String functionName = (String) group.getAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR);
    functionName = quotePHP(quoteSQL(functionName));
    String access = "Access " + safeDblQuote + functionName + safeDblQuote + " function";
    String enter = "Enter data for " + safeDblQuote + functionName + safeDblQuote + " Function";
    String confirm = "Confirm & Save data using " + safeDblQuote + functionName + safeDblQuote + " function";
    String monitor = "Monitor results of " + safeDblQuote + functionName + safeDblQuote + " function";
    php.append("$userId = mysql_real_escape_string($userId);\n\t");
    // fill out hcipa table
    php.append("$deviceId = Create_Task($userId, \"" + quotePHP(quoteSQL(design.getName())) + "\",\n\t");
    php.append('"' + RECOGNIZE_NEED + quotePHP(quoteSQL(group.getName())) + "\",\n\t");
    php.append('"' + DECIDE_TO_USE + functionName + "\",\n\t");
    php.append('"' + access + "\",\n\t\"" + enter + "\",\n\t");
    php.append('"' + confirm + "\",\n\t\"" + monitor + "\");\n\n");
    //        php.append("$sqlStmt =\n<<<SQL__INSERT__STRING\n\t");
    //        php.append(SQL_INSERT + "HCIPA (\n\tUser_Id,\n\tDescription,\n\tIdentify_Task,\n\t");
    //        php.append("Select_Function,\n\tAccess,\n\tEnter,\n\tConfirm_Save,\n\tMonitor)\n\t"
    //                   + SQL_VALUES + " ('$userId',\n\t'");
    //        php.append(quoteSQL(design.getName()) + "',\n\t");
    //        php.append("'" + RECOGNIZE_NEED + quoteSQL(group.getName()) + "',\n\t");
    //        php.append("'" + DECIDE_TO_USE + functionName + "',\n\t");
    //        php.append("'" + access + "',\n\t'" + enter + "',\n\t");
    //        php.append("'" + confirm + "',\n\t'" + monitor + "')\n");
    //        php.append("SQL__INSERT__STRING\n;\n\n\t");
    //        php.append("mysql_query($sqlStmt);\n\n\t");
    //        php.append("$deviceId = mysql_insert_id();\n");
    // fill out hcipa_actions table
    Iterator<AUndertaking> subtasks = group.getUndertakings().iterator();
    while (subtasks.hasNext()) {
        AUndertaking subtask = subtasks.next();
        TaskApplication ta = project.getTaskApplication(subtask, design);
        if (ta != null) {
            Demonstration demo = ta.getDemonstration();
            Iterator<AScriptStep> steps = demo.getSteps().iterator();
            while (steps.hasNext()) {
                AScriptStep step = steps.next();
                buildActionStepInsert(subtask, step, demo, php);
            }
        }
    }
    try {
        // write script to destFile
        FileWriter fileOut = null;
        BufferedWriter writer = null;
        try {
            fileOut = new FileWriter(scriptFile);
            writer = new BufferedWriter(fileOut);
            php.append("\treturn $deviceId;\n");
            php.append("} // insertIntoDatabase_" + HCIPA_EXPORT_VERSION + "\n?>\n");
            writer.write(php.toString());
        } finally {
            if (writer != null) {
                writer.close();
            } else if (fileOut != null) {
                fileOut.close();
            }
        }
    } catch (IOException ex) {
        // so we don't have to import DesignExportToHTML!
        throw new ExportIOException("Could not write PHP script ", ex);
    }
    return true;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) FileWriter(java.io.FileWriter) ExportIOException(edu.cmu.cs.hcii.cogtool.ui.DesignExportToHTML.ExportIOException) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) ExportIOException(edu.cmu.cs.hcii.cogtool.ui.DesignExportToHTML.ExportIOException) IOException(java.io.IOException) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) BufferedWriter(java.io.BufferedWriter)

Example 18 with Demonstration

use of edu.cmu.cs.hcii.cogtool.model.Demonstration 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 19 with Demonstration

use of edu.cmu.cs.hcii.cogtool.model.Demonstration in project cogtool by cogtool.

the class ProjectController method createScriptEditorAction.

// Action for EditScript
protected IListenerAction createScriptEditorAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object prms) {
            if (prms != null) {
                ProjectSelectionState seln = (ProjectSelectionState) prms;
                // Must have selected tasks and design
                Design design = seln.getSelectedDesign();
                AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
                if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                    return false;
                }
                DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
                // Editing a script only applies to tasks, not task groups
                for (int i = 0; i < tasks.length; i++) {
                    if (!tasks[i].isTaskGroup()) {
                        CognitiveModelGenerator gen = MODELGEN_ALG;
                        TaskGroup group = tasks[i].getTaskGroup();
                        if (group != null) {
                            Object isSnifAct = group.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
                            if (isSnifAct != null) {
                                gen = IdentityModelGenerator.ONLY;
                            }
                        }
                        // If no script set exists for this cell, create
                        TaskApplication ta = ensureTaskApplication(tasks[i], design, gen, demoMgr);
                        Demonstration demo = ta.getDemonstration();
                        if (CogToolPref.HCIPA.getBoolean()) {
                            HCIPACmd.checkStartFrame(project, ta, gen);
                        }
                        // Determine which window to open/create
                        if ((demo.getStartFrame() == null) || !demo.isStartFrameChosen()) {
                            // No start frame; present ui to choose one
                            SEFrameChooserController.openController(ta, gen, project);
                        } else {
                            // Start frame chosen; go straight to demo ui
                            try {
                                SEDemoController.openController(ta, gen, project);
                            } catch (GraphicsUtil.ImageException ex) {
                                interaction.protestInvalidImageFile();
                            }
                        }
                    }
                // Else do nothing when a TaskGroup cell is "edited"
                }
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 20 with Demonstration

use of edu.cmu.cs.hcii.cogtool.model.Demonstration 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);
        }
    }
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration)

Aggregations

Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)24 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)11 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)9 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)9 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)9 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)8 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)7 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)7 Design (edu.cmu.cs.hcii.cogtool.model.Design)6 Script (edu.cmu.cs.hcii.cogtool.model.Script)6 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)6 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)4 HandLocation (edu.cmu.cs.hcii.cogtool.model.HandLocation)4 ThinkScriptStep (edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)4 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)3 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)3 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)3 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)3 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)3