Search in sources :

Example 11 with Demonstration

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);
            }
        }
    }
}
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 12 with Demonstration

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;
        }
    };
}
Also used : ProjectContextSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectContextSelectionState) SAXException(org.xml.sax.SAXException) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) URLCrawlEntry(edu.cmu.cs.hcii.cogtool.model.URLCrawlEntry) ImportCogToolXML(edu.cmu.cs.hcii.cogtool.model.ImportCogToolXML) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Collection(java.util.Collection) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) RcvrXMLParsingException(edu.cmu.cs.hcii.cogtool.util.RcvrXMLParsingException) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Demonstration

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);
}
Also used : HandLocation(edu.cmu.cs.hcii.cogtool.model.HandLocation) 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) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 14 with Demonstration

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TransitionScriptStep(edu.cmu.cs.hcii.cogtool.model.TransitionScriptStep) 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) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 15 with Demonstration

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;
}
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)

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