Search in sources :

Example 36 with TaskApplication

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

Example 37 with TaskApplication

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

the class ProjectController method createEditACTRModelAction.

// TODO it is a crock that we're cloning this stuff; when we have time
//      we should design a shared mechanism to be used by all back ends
protected IListenerAction createEditACTRModelAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState selState = (ProjectSelectionState) actionParms;
            Design design = selState.getSelectedDesign();
            AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            for (AUndertaking task : tasks) {
                TaskApplication ta = project.getTaskApplication(task, design);
                if (ta == null) {
                    return false;
                }
                // find the script
                Script script = ta.getScript(KLMCognitiveGenerator.ONLY);
                if (script == null) {
                    return false;
                }
                // get the resourcePath
                String resourcePath = script.getAssociatedPath();
                if (resourcePath == null) {
                    return false;
                }
                try {
                    FileUtil.editFile(new File(resourcePath));
                } catch (UnsupportedOperationException ex) {
                    throw new RcvrUnimplementedFnException("Editing a file is not implemented", ex);
                } catch (IOException ex) {
                    throw new RcvrIOException("Problem when trying to edit a file.", ex);
                }
            }
            return true;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) 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) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) File(java.io.File)

Example 38 with TaskApplication

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

the class ProjectController method createExportActrModelFile.

// Action for ExportDesignFiles
// XXX: does this really belong in ProjectController? It seems like
//      something that's tied to whichever backend we're really using,
//      and so should be somewhere else
protected IListenerAction createExportActrModelFile() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState sel = (ProjectSelectionState) actionParms;
            // Must have selected tasks and design
            Design design = sel.getSelectedDesign();
            AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
            if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                return false;
            }
            // Ask user for location of saved file.
            File exportFile = interaction.selectExportLocation("Exported ACT-R Model", CogToolFileTypes.LISP_FILE_EXT);
            // User canceled
            if (exportFile == null) {
                return false;
            }
            for (AUndertaking task : tasks) {
                // If no script set exists for this cell, create
                TaskApplication ta = project.getTaskApplication(task, design);
                if (ta != null) {
                    if (ta.getDesign() != design) {
                        throw new RcvrIllegalStateException("Unexpected Design mis-match (" + ta.getDesign() + ", " + design + ")");
                    }
                    // If no script exists for this cell, create one
                    Script script = DemoStateManager.ensureScript(ta, MODELGEN_ALG);
                    try {
                        IPredictionAlgo taAlg = ta.determineActiveAlgorithm(project);
                        if (!(taAlg instanceof ACTRPredictionAlgo)) {
                            throw new RcvrIllegalStateException("Can't export ACT-R Model from a non ACT-R task.");
                        }
                        if (script.getAssociatedPath() != null) {
                            File f = new File(script.getAssociatedPath());
                            // The following will throw an IOException if
                            // the input file doesn't exist; this is exactly
                            // the same behaviour as if we're trying to do
                            // a recompute, and is better than silently
                            // substituting a generated model file
                            FileUtil.copyTextFileToFile(f, exportFile);
                            return true;
                        }
                        ACTRPredictionAlgo algo = (ACTRPredictionAlgo) taAlg;
                        algo.outputModel(design, task, ta.getDemonstration().getStartFrame(), script, exportFile, null);
                    } catch (UnsupportedOperationException ex) {
                        throw new RcvrUnimplementedFnException(ex);
                    } catch (IOException ex) {
                        throw new RcvrIOException(("IOException exporting model file for task " + task.getName() + " in design " + design.getName()), ex);
                    }
                }
            }
            return true;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) 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) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) File(java.io.File) ACTRPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)

Example 39 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication 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;
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) Design(edu.cmu.cs.hcii.cogtool.model.Design) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 40 with TaskApplication

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

the class SEDemoController method createInsertSelfTransitionAction.

protected IListenerAction createInsertSelfTransitionAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            SEDemoUI.SelfTransition prms = (SEDemoUI.SelfTransition) actionParms;
            if (prms.target != null) {
                TaskApplication taskApp = script.getDemonstration().getTaskApplication();
                Set<DeviceType> deviceTypeSet = taskApp.getDesign().getDeviceTypes();
                int deviceTypes = DeviceType.buildDeviceSet(deviceTypeSet);
                int limitMode = ActionProperties.determineChangeActionMode(prms.target);
                AAction action = prms.action;
                if (prms.action == null) {
                    properties.resetValues();
                    properties.setInitialActionType(prms.target, deviceTypeSet);
                    if (!interaction.determineNewAction(properties, deviceTypes, limitMode, L10N.get("DE.SetActionType", "Set Action Type"))) {
                        return false;
                    }
                    action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
                    if (action == null) {
                        return false;
                    }
                }
                action = EditActionCmd.ensureActionIsUnique(prms.target, action, properties, deviceTypes, limitMode, null, interaction);
                if (action == null) {
                    return false;
                }
                return performSelfTransition(prms.selection, prms.target, action, properties.delayInSecs, properties.delayLabel);
            }
            return false;
        }
    };
}
Also used : DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) SEDemoUI(edu.cmu.cs.hcii.cogtool.ui.SEDemoUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Aggregations

TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)63 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)38 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)22 Design (edu.cmu.cs.hcii.cogtool.model.Design)20 Script (edu.cmu.cs.hcii.cogtool.model.Script)20 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)17 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)16 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)15 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)14 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)12 IOException (java.io.IOException)12 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)11 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)11 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)10 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)10 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)10 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)8 File (java.io.File)8 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)7 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)5