Search in sources :

Example 1 with SelectionManager

use of artisynth.core.gui.selectionManager.SelectionManager in project artisynth_core by artisynth.

the class MenuBarHandler method actionPerformed.

/**
 * action performed to process all the menu and button actions in this class
 */
public void actionPerformed(ActionEvent event) {
    String cmd = event.getActionCommand();
    // Scripts menu
    if (isScriptMenuItem(event.getSource())) {
        String scriptName = myMain.getScriptName(cmd);
        runScript(scriptName);
    } else if (cmd.equals("load script from file")) {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setCurrentDirectory(ArtisynthPath.getWorkingDir());
        FileFilter jythonFilter = new GenericFileFilter(new String[] { "py", "jy" }, "Jython files");
        fileChooser.addChoosableFileFilter(jythonFilter);
        fileChooser.setFileFilter(jythonFilter);
        int result = fileChooser.showOpenDialog(myFrame);
        if (result == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();
            runScript(selectedFile.getAbsolutePath());
        }
    } else // 
    if (myMain.isDemoClassName(cmd)) {
        ModelInfo mi = new ModelInfo(myMain.getDemoClassName(cmd), cmd, null);
        doLoadModelSafely(mi);
    } else // 
    if (cmd.equals("Clear model")) {
        doClearModel();
    } else if (cmd.equals("New blank MechModel")) {
        doBlankMechmodel();
    } else if (cmd.equals("Save model")) {
        doSaveModel();
    } else if (cmd.equals("Save model as ...")) {
        doSaveModelAs();
    } else if (cmd.equals("Reload model")) {
        doReloadModel();
    } else if (cmd.equals("Load model ...")) {
        doLoadModel();
    } else if (cmd.equals("Load from class ...")) {
        doLoadFromClass();
    } else if (cmd.equals("Switch workspace ...")) {
        doSwitchWorkspace();
    } else if (cmd.equals("Open MATLAB connection")) {
        doOpenMatlab();
    } else if (cmd.equals("Close MATLAB connection")) {
        doCloseMatlab();
    } else if (cmd.equals("Load probes ...")) {
        doLoadProbes();
    } else if (cmd.equals("Save probes")) {
        doSaveProbes();
    } else if (cmd.equals("Save probes as ...")) {
        doSaveProbesAs();
    } else if (cmd.equals("Load probes from ...")) {
        newLoadProbesFrom();
    } else if (cmd.equals("Save probes new")) {
        newSaveProbes();
    } else if (cmd.equals("Save probes in ...")) {
        newSaveProbesIn();
    } else if (cmd.equals("Save viewer image ...")) {
        saveViewerImage();
    } else if (cmd.equals("Quit")) {
        myMain.quit();
    } else // 
    if (cmd.equals("Add input probe")) {
        doAddInputProbe();
    } else if (cmd.equals("Add output probe")) {
        doAddOutputProbe();
    } else if (cmd.equals("Add control panel")) {
        doAddControlPanel();
    } else if (cmd.equals("Load control panel")) {
        doLoadControlPanel();
    } else if (cmd.equals("Print selection")) {
        SelectionManager sm = myMain.getSelectionManager();
        for (ModelComponent c : sm.getCurrentSelection()) {
            System.out.println(ComponentUtils.getPathName(c));
        }
    } else if (cmd.equals("Undo")) {
        doUndoCommand();
    } else // 
    if (cmd.equals("Background color")) {
        setBackgroundColor();
    } else if (cmd.equals("Selection color")) {
        setSelectionColor();
    } else if (cmd.equals("Enable selection highlighting")) {
        setSelectionColorEnabled(true);
    } else if (cmd.equals("Disable selection highlighting")) {
        setSelectionColorEnabled(false);
    } else if (cmd.equals("Visual display rate")) {
        setVisualDisplayRate();
    } else if (cmd.equals("Real-time scaling")) {
        setRealTimeScaling();
    } else if (cmd.equals("Mouse Preferences ...")) {
        openMouseSettingsDialog();
    } else if (cmd.equals("Init draggers in world coords")) {
        myMain.setInitDraggersInWorldCoords(true);
    } else if (cmd.equals("Init draggers in local coords")) {
        myMain.setInitDraggersInWorldCoords(false);
    } else if (cmd.equals("Enable articulated transforms")) {
        myMain.setArticulatedTransformsEnabled(true);
    } else if (cmd.equals("Disable articulated transforms")) {
        myMain.setArticulatedTransformsEnabled(false);
    } else // }
    if (cmd.equals("PullController properties ...")) {
        showPullControllerPropertyDialog();
    } else if (cmd.equals("PullController render props ...")) {
        showPullControllerRenderPropsDialog();
    } else // 
    if (cmd.equals("Center view on selection")) {
        myMain.centerViewOnSelection();
    } else if (cmd.equals("Hide timeline")) {
        myMain.setTimelineVisible(false);
        isTimelineVisible = false;
    } else if (cmd.equals("Show timeline")) {
        myMain.setTimelineVisible(true);
        isTimelineVisible = true;
    } else if (cmd.equals("Reset view")) {
        GLViewer v = myMain.getViewer();
        v.setAxialView(v.getAxialView());
        v.autoFit();
    } else if (cmd.equals("Perspective view")) {
        myMain.getViewer().setOrthographicView(false);
    } else if (cmd.equals("Orthographic view")) {
        myMain.getViewer().setOrthographicView(true);
    } else if (cmd.equals("Hide Jython console")) {
        setJythonConsoleVisible(false);
    } else if (cmd.equals("Show Jython console")) {
        setJythonConsoleVisible(true);
    } else if (cmd.equals("Show Inverse panel")) {
        myMain.getInverseManager().showInversePanel(myMain.getRootModel(), InverseManager.findInverseController());
    } else if (cmd.equals("Hide Inverse panel")) {
        myMain.getInverseManager().hideInversePanel();
    } else if (cmd.equals("Show movie panel")) {
        myFrame.getMain().getViewer().getCanvas().display();
        myMain.getMovieMaker().showDialog(myFrame);
    } else if (cmd.equals("Hide movie panel")) {
        // TODO: this isn't implemented yet because we need to set
        // this up as an action
        myMain.getMovieMaker().closeDialog();
    } else if (cmd.equals("Show empty components in navpanel")) {
        myFrame.getNavPanel().setHideEmptyComponents(false);
    } else if (cmd.equals("Hide empty components in navpanel")) {
        myFrame.getNavPanel().setHideEmptyComponents(true);
    } else if (cmd.equals("New viewer")) {
        myMain.createViewerFrame();
    } else if (cmd.equals("Clear traces")) {
        myMain.getRootModel().clearTraces();
    } else if (cmd.equals("Disable all tracing")) {
        myMain.getRootModel().disableAllTracing();
    } else if (cmd.equals("Remove traces")) {
        RemoveComponentsCommand rmCmd = new RemoveComponentsCommand("remove traces", myMain.getRootModel().getTracingProbes());
        myMain.getUndoManager().saveStateAndExecute(rmCmd);
        myMain.rerender();
    } else if (cmd.equals("Set traces visible")) {
        myMain.getRootModel().setTracingProbesVisible(true);
        myMain.rerender();
    } else if (cmd.equals("Set traces invisible")) {
        myMain.getRootModel().setTracingProbesVisible(false);
        myMain.rerender();
    } else if (cmd.equals("Hide viewer toolbar")) {
        isToolbarVisible = false;
        detachViewerToolbar(toolbarPanel);
    } else if (cmd.equals("Show viewer toolbar")) {
        isToolbarVisible = true;
        attachViewerToolbar(toolbarPanel);
    } else if (cmd.equals("Merge control panels")) {
        myMain.getRootModel().mergeAllControlPanels(true);
    } else if (cmd.equals("Separate control panels")) {
        myMain.getRootModel().mergeAllControlPanels(false);
    } else if (cmd.equals("Show progress")) {
        spawnProgressBar();
    } else // 
    if (cmd.equals("About ArtiSynth")) {
        myFrame.displayAboutArtisynth();
    } else if (cmd.equals("About the current model")) {
        myFrame.displayAboutModel(myMain.getRootModel());
    } else if (cmd.equals("Keybindings")) {
        myFrame.displayKeybindings();
    } else // 
    if (cmd.equals("Hide NavBar")) {
        myFrame.getNavPanel().setStatus(!myFrame.getNavPanel().getStatus());
        myFrame.refreshSplitPane();
        navBarButton.setToolTipText("Show Navbar");
        navBarButton.setActionCommand("Show Navbar");
    } else if (cmd.equals("Show Navbar")) {
        myFrame.getNavPanel().setStatus(!myFrame.getNavPanel().getStatus());
        myFrame.refreshSplitPane();
        navBarButton.setToolTipText("Hide NavBar");
        navBarButton.setActionCommand("Hide NavBar");
    } else if (cmd.equals("Re-render")) {
        myMain.rerender();
    } else if (cmd.equals("Reset")) {
        myMain.getScheduler().reset();
    } else if (cmd.equals("Rewind")) {
        myMain.getScheduler().rewind();
    } else if (cmd.equals("Play")) {
        myMain.getScheduler().play();
    } else if (cmd.equals("Pause")) {
        myMain.getScheduler().pause();
    } else if (cmd.equals("Single step")) {
        myMain.getScheduler().step();
    } else if (cmd.equals("Fast forward")) {
        myMain.getScheduler().fastForward();
    } else if (cmd.equals("cancel")) {
        return;
    } else {
        throw new InternalErrorException("Unimplemented command: " + cmd);
    }
}
Also used : SelectionManager(artisynth.core.gui.selectionManager.SelectionManager) GLViewer(maspack.render.GL.GLViewer) JFileChooser(javax.swing.JFileChooser) ModelComponent(artisynth.core.modelbase.ModelComponent) RemoveComponentsCommand(artisynth.core.gui.editorManager.RemoveComponentsCommand) GenericFileFilter(maspack.util.GenericFileFilter) InternalErrorException(maspack.util.InternalErrorException) ExtensionFileFilter(artisynth.core.util.ExtensionFileFilter) GenericFileFilter(maspack.util.GenericFileFilter) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 2 with SelectionManager

use of artisynth.core.gui.selectionManager.SelectionManager in project artisynth_core by artisynth.

the class MenuBarHandler method createViewMenu.

private void createViewMenu(JMenu menu) {
    JMenuItem item;
    RootModel root = myMain.getRootModel();
    boolean hasTraceables = root.getNumTraceables() > 0;
    boolean hasTraces = false;
    boolean hasVisibleTrace = false;
    boolean hasInvisibleTrace = false;
    for (Probe p : root.getOutputProbes()) {
        if (p instanceof TracingProbe) {
            hasTraces = true;
            if (RenderableUtils.isVisible((TracingProbe) p)) {
                hasVisibleTrace = true;
            } else {
                hasInvisibleTrace = true;
            }
        }
    }
    if (isTimelineVisible) {
        addMenuItem(menu, "Hide timeline");
    } else {
        addMenuItem(menu, "Show timeline");
    }
    if (JythonInit.jythonIsAvailable()) {
        if (myMain.myJythonFrame != null && myMain.myJythonFrame.isVisible()) {
            addMenuItem(menu, "Hide Jython console");
        } else {
            addMenuItem(menu, "Show Jython console");
        }
    }
    if (InverseManager.inverseControllerExists()) {
        if (InverseManager.isInversePanelVisible()) {
            addMenuItem(menu, "Hide Inverse panel");
        } else {
            addMenuItem(menu, "Show Inverse panel");
        }
    }
    if (isToolbarVisible) {
        addMenuItem(menu, "Hide viewer toolbar");
    } else {
        addMenuItem(menu, "Show viewer toolbar");
    }
    addMenuItem(menu, "Show movie panel");
    menu.add(new JSeparator());
    addMenuItem(menu, "New viewer");
    SelectionManager sm = myMain.getSelectionManager();
    if (sm.getNumSelected() > 0) {
        addMenuItem(menu, "Center view on selection");
    }
    if (getMainViewer().isOrthogonal()) {
        addMenuItem(menu, "Perspective view");
    } else {
        addMenuItem(menu, "Orthographic view");
    }
    menu.add(new JSeparator());
    addMenuItem(menu, "Merge control panels");
    addMenuItem(menu, "Separate control panels");
    addMenuItem(menu, "Show progress");
    if (myFrame.getNavPanel().getHideEmptyComponents()) {
        addMenuItem(menu, "Show empty components in navpanel");
    } else {
        addMenuItem(menu, "Hide empty components in navpanel");
    }
    menu.add(new JSeparator());
    item = addMenuItem(menu, "Clear traces");
    item.setEnabled(hasTraceables);
    item = addMenuItem(menu, "Disable all tracing");
    item.setEnabled(hasTraceables);
    item = addMenuItem(menu, "Remove traces");
    item.setEnabled(hasTraces);
    item = addMenuItem(menu, "Set traces visible");
    item.setEnabled(hasInvisibleTrace);
    item = addMenuItem(menu, "Set traces invisible");
    item.setEnabled(hasVisibleTrace);
}
Also used : SelectionManager(artisynth.core.gui.selectionManager.SelectionManager) RootModel(artisynth.core.workspace.RootModel) TracingProbe(artisynth.core.probes.TracingProbe) JMenuItem(javax.swing.JMenuItem) Probe(artisynth.core.probes.Probe) TracingProbe(artisynth.core.probes.TracingProbe) JSeparator(javax.swing.JSeparator)

Example 3 with SelectionManager

use of artisynth.core.gui.selectionManager.SelectionManager in project artisynth_core by artisynth.

the class ProbeInfo method duplicateProbe.

/**
 * duplicate the probe
 */
private void duplicateProbe() {
    // don't need to supply a copyMap to copy because it won't be used
    Probe oldProbe = getProbe();
    if (!(oldProbe.getParent() instanceof MutableCompositeComponent)) {
        throw new InternalErrorException("Probe's parent is not editable");
    }
    Probe newProbe = null;
    try {
        newProbe = (Probe) getProbe().clone();
    } catch (Exception e) {
        e.printStackTrace();
        throw new InternalErrorException("Cannot clone probe of type " + getProbe().getClass());
    }
    // set start time so that probe follows right after this one ...
    double startTime = getProbe().getStartTime();
    double stopTime = getProbe().getStopTime();
    newProbe.setStartTime(stopTime);
    newProbe.setStopTime(stopTime + (stopTime - startTime));
    AddComponentsCommand cmd = new AddComponentsCommand("duplicate probe", newProbe, (MutableCompositeComponent) oldProbe.getParent());
    getMain().getUndoManager().saveStateAndExecute(cmd);
    SelectionManager selman = getMain().getSelectionManager();
    selman.removeSelected(oldProbe);
    selman.addSelected(newProbe);
// myController.deselectAllProbes(); XXX need to fix?
}
Also used : SelectionManager(artisynth.core.gui.selectionManager.SelectionManager) MutableCompositeComponent(artisynth.core.modelbase.MutableCompositeComponent) AddComponentsCommand(artisynth.core.gui.editorManager.AddComponentsCommand) InternalErrorException(maspack.util.InternalErrorException) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) WayPointProbe(artisynth.core.probes.WayPointProbe) Probe(artisynth.core.probes.Probe) NumericInputProbe(artisynth.core.probes.NumericInputProbe) InternalErrorException(maspack.util.InternalErrorException) IOException(java.io.IOException)

Aggregations

SelectionManager (artisynth.core.gui.selectionManager.SelectionManager)3 Probe (artisynth.core.probes.Probe)2 InternalErrorException (maspack.util.InternalErrorException)2 AddComponentsCommand (artisynth.core.gui.editorManager.AddComponentsCommand)1 RemoveComponentsCommand (artisynth.core.gui.editorManager.RemoveComponentsCommand)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 MutableCompositeComponent (artisynth.core.modelbase.MutableCompositeComponent)1 NumericInputProbe (artisynth.core.probes.NumericInputProbe)1 NumericOutputProbe (artisynth.core.probes.NumericOutputProbe)1 TracingProbe (artisynth.core.probes.TracingProbe)1 WayPointProbe (artisynth.core.probes.WayPointProbe)1 ExtensionFileFilter (artisynth.core.util.ExtensionFileFilter)1 RootModel (artisynth.core.workspace.RootModel)1 File (java.io.File)1 IOException (java.io.IOException)1 JFileChooser (javax.swing.JFileChooser)1 JMenuItem (javax.swing.JMenuItem)1 JSeparator (javax.swing.JSeparator)1 FileFilter (javax.swing.filechooser.FileFilter)1 GLViewer (maspack.render.GL.GLViewer)1