Search in sources :

Example 1 with CognitiveModelGenerator

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

the class PERTChartView method addDesignResults.

protected void addDesignResults(APredictionResult knownResult, Project project, Design design, Iterator<AUndertaking> tasks, List<NamedPredictionResult> availableResults) {
    while (tasks.hasNext()) {
        AUndertaking task = tasks.next();
        if ((design != null) && (task != null)) {
            if (task.isTaskGroup()) {
                addDesignResults(knownResult, project, design, ((TaskGroup) task).getUndertakings().iterator(), availableResults);
            } else {
                TaskApplication otherTa = project.getTaskApplication(task, design);
                if (otherTa != null) {
                    Iterator<CognitiveModelGenerator> modGenIt = otherTa.getModelGenerators();
                    while (modGenIt.hasNext()) {
                        CognitiveModelGenerator otherModGen = modGenIt.next();
                        if (otherModGen != null) {
                            Iterator<IPredictionAlgo> predAlgIt = otherTa.getPredictionAlgs(otherModGen);
                            while (predAlgIt.hasNext()) {
                                APredictionResult otherResult = otherTa.getResult(otherModGen, predAlgIt.next());
                                if ((otherResult != knownResult) && (otherResult != null)) {
                                    String name = otherTa.getDesign().getName() + " : " + otherTa.getTask().getName();
                                    NamedPredictionResult npr = new NamedPredictionResult(otherResult, name);
                                    addAvailableResult(npr, availableResults);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 2 with CognitiveModelGenerator

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

the class ProjectController method displayTraces.

protected void displayTraces(AUndertaking task, Design design) {
    if (task.isTaskGroup()) {
        Iterator<AUndertaking> allSubtasks = ((TaskGroup) task).getUndertakings().iterator();
        while (allSubtasks.hasNext()) {
            displayTraces(allSubtasks.next(), design);
        }
    } else {
        TaskApplication taskApp = project.getTaskApplication(task, design);
        if (taskApp != null) {
            StringBuilder labelText = new StringBuilder();
            Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
            while (modelGens.hasNext()) {
                CognitiveModelGenerator modelGen = modelGens.next();
                Iterator<IPredictionAlgo> computeAlgs = taskApp.getPredictionAlgs(modelGen);
                while (computeAlgs.hasNext()) {
                    IPredictionAlgo computeAlg = computeAlgs.next();
                    APredictionResult result = taskApp.getResult(modelGen, computeAlg);
                    int resultState = result.getResultState();
                    if ((result != null) && ((resultState == APredictionResult.IS_COMPUTED) || (resultState == APredictionResult.COMPUTE_FAILED))) {
                        labelText.delete(0, labelText.length());
                        labelText.append(tracesWindowLabel);
                        labelText.append(": ");
                        labelText.append(project.getName());
                        labelText.append(" > ");
                        labelText.append(design.getName());
                        labelText.append(" > ");
                        labelText.append(task.getName());
                        String labelStr = labelText.toString();
                        ITraceWindow traceWin = interaction.createTraceWindow(labelStr + (OSUtils.MACOSX ? "" : UI.WINDOW_TITLE), null, labelStr);
                        traceWin.appendOutputLines(result.getTraceLines());
                        traceWin.scrollToTop();
                        traceWin.appendErrorLines(result.getErrorLines());
                        traceWin.scrollToTop();
                    }
                }
            }
        }
    }
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ITraceWindow(edu.cmu.cs.hcii.cogtool.ui.Interaction.ITraceWindow) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 3 with CognitiveModelGenerator

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

the class ProjectController method createVisualization.

public boolean createVisualization(Design design, AUndertaking task, int strategy) {
    TaskApplication ta = getVisualizationTA(design, task);
    if (ta != null) {
        IPredictionAlgo activeAlgo = ta.determineActiveAlgorithm(project);
        CognitiveModelGenerator gen = ta.getFirstModelGenerator();
        if (ta.getResult(gen, activeAlgo) != null) {
            PERTChartController c = PERTChartController.openController(ta, gen, activeAlgo, project, strategy, interaction);
            return (c != null);
        }
    }
    return false;
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)

Example 4 with CognitiveModelGenerator

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

the class SEDemoController method createShowModelVisualizationAction.

protected IListenerAction createShowModelVisualizationAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            CognitiveModelGenerator modelGen = script.getModelGenerator();
            IPredictionAlgo activeAlgo = taskApplication.determineActiveAlgorithm(project);
            if (taskApplication.getResult(modelGen, activeAlgo) != null) {
                PERTChartController c = PERTChartController.openController(taskApplication, modelGen, activeAlgo, project, -1, interaction);
                return (c != null);
            }
            return false;
        }
    };
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)

Example 5 with CognitiveModelGenerator

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

the class SEDemoController method deleteScriptStep.

// createInsertSelfTransitionAction
/**
     * Perform the operations needed to DELETE a script Action
     *
     * @param selection
     * @return
     */
protected boolean deleteScriptStep(SEDemoSelectionState selection) {
    // In case we need to go back to edit initial state.
    final CognitiveModelGenerator modelGen = script.getModelGenerator();
    final Demonstration demo = script.getDemonstration();
    final TaskApplication taskApp = demo.getTaskApplication();
    // If there is no selected action, try to delete the last item
    DefaultModelGeneratorState selectedState = selection.getSelectedState();
    final DefaultModelGeneratorState stateToDelete = getValidStepState(selectedState);
    IUndoableEdit edit;
    // If no states, go back to edit initial state
    if ((stateToDelete == null) || stateToDelete.getScriptStep().isInitiallyGenerated()) {
        closeWindow(false);
        demo.setStartFrameChosen(false);
        SEFrameChooserController.openController(taskApp, modelGen, project);
        edit = new AUndoableEdit(SEDemoLID.Delete) {

            protected DemoScriptCmd.ComputationUndoRedo computeUndoRedo = new DemoScriptCmd.ComputationUndoRedo(script);

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

            @Override
            public void redo() {
                super.redo();
                DefaultController seDemoController = ControllerRegistry.ONLY.findOpenController(script);
                if (seDemoController != null) {
                    seDemoController.closeWindow(false);
                }
                demo.setStartFrameChosen(false);
                SEFrameChooserController.openController(taskApp, modelGen, project);
                computeUndoRedo.redoChanges();
            }

            @Override
            public void undo() {
                super.undo();
                if (demo.getStartFrame() != null) {
                    demo.setStartFrameChosen(true);
                    // Close the frame chooser window.
                    DefaultController frameChooserController = ControllerRegistry.ONLY.findOpenController(taskApp);
                    if (frameChooserController != null) {
                        frameChooserController.closeWindow(false);
                    }
                    // Open the new demo view window
                    try {
                        SEDemoController.openController(taskApp, modelGen, project);
                    } catch (GraphicsUtil.ImageException ex) {
                        interaction.protestInvalidImageFile();
                    }
                    computeUndoRedo.undoChanges();
                }
            }
        };
        UndoManager seFrameMgr = UndoManager.getUndoManager(taskApp, project);
        seFrameMgr.addEdit(edit);
        undoMgr.addEdit(edit);
        return true;
    }
    AScriptStep step = stateToDelete.getScriptStep();
    // If a generated think step, simply delete
    if ((step instanceof ThinkScriptStep) && !step.isInsertedByUser()) {
        edit = new AUndoableEdit(SEDemoLID.Delete) {

            protected int scriptIndex = script.removeState(stateToDelete);

            protected DemoScriptCmd.ComputationUndoRedo computeUndoRedo = new DemoScriptCmd.ComputationUndoRedo(script);

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

            @Override
            public void redo() {
                super.redo();
                script.removeState(scriptIndex);
                computeUndoRedo.redoChanges();
            }

            @Override
            public void undo() {
                super.undo();
                script.insertState(stateToDelete, scriptIndex);
                computeUndoRedo.undoChanges();
            }
        };
    } else {
        final AScriptStep demoStep = step.getOwner();
        // There are no "new" steps to replace with when deleting
        Set<AScriptStep> emptyDemoSteps = new HashSet<AScriptStep>();
        if (demoStep.getCurrentFrame() == demoStep.getDestinationFrame()) {
            final int atIndex = demo.removeStep(demoStep);
            final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, demoStep, interaction);
            Set<AScriptStep> oldDemoSteps = Collections.singleton(demoStep);
            edit = new DemoStateManager.ADemoUndoableEdit(SEDemoLID.Delete, demo, emptyDemoSteps, oldDemoSteps, demoStateMgr) {

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

                @Override
                public void redo() {
                    super.redo();
                    demo.removeStep(atIndex);
                    DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
                }

                @Override
                public void undo() {
                    super.undo();
                    demo.insertStep(demoStep, atIndex);
                    DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
                }
            };
        } else {
            if ((selectedState != null) && (demoStep != demo.getLastStep()) && !interaction.confirmDeleteScriptStep()) {
                return false;
            }
            Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
            final int atIndex = demo.replaceSteps(demoStep, emptyDemoSteps, oldDemoSteps);
            final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, demoStep, interaction);
            edit = new DemoStateManager.ADemoUndoableEdit(SEDemoLID.Delete, demo, emptyDemoSteps, oldDemoSteps, demoStateMgr) {

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

                @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(DELETE_STEP, SEDemoLID.Delete);
    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) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)16 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)11 Script (edu.cmu.cs.hcii.cogtool.model.Script)7 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)6 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)5 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)5 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)3 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 UndoManager (edu.cmu.cs.hcii.cogtool.util.UndoManager)3 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)2 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)2 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)2 ArrayList (java.util.ArrayList)2 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)1 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)1