Search in sources :

Example 16 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class UndoManager method undoLastCommand.

/**
 * Undo the most recently executed set of commands.
 */
public void undoLastCommand() {
    if (commands.size() > 0) {
        CommandStatePair cmdState = commands.removeLast();
        for (int i = cmdState.myCmds.size() - 1; i >= 0; i--) {
            cmdState.myCmds.get(i).undo();
        }
        RootModel rootModel = Main.getMain().getRootModel();
        if (rootModel == null) {
            throw new InternalErrorException("rootModel is null");
        }
        if (cmdState.myState != null) {
            rootModel.setState(cmdState.myState);
            rootModel.initialize(Main.getMain().getTime());
        }
        rootModel.rerender();
    }
}
Also used : RootModel(artisynth.core.workspace.RootModel)

Example 17 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class TimelineController method loadWayPoints.

public void loadWayPoints() {
    RootModel root = myMain.getRootModel();
    WayPointProbe wayPoints = root.getWayPoints();
    wayPoints.load();
    refreshWayPoints(root);
}
Also used : RootModel(artisynth.core.workspace.RootModel) WayPointProbe(artisynth.core.probes.WayPointProbe)

Example 18 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class ComponentPropertyField method valueToTextArray.

protected String[] valueToTextArray(Object value) {
    ModelComponent comp = getComponent(value);
    RootModel root = myMain.getRootModel();
    String compStr = "/";
    String propStr = "";
    if (root == null || comp == null) {
        return new String[] { "", "" };
    }
    if (value instanceof ModelComponent) {
        compStr = ComponentUtils.getPathName(root, comp);
    } else if (value instanceof Property) {
        Property prop = (Property) value;
        boolean excludeLeaf = (myPropertySelector != null && !(prop.get() instanceof CompositeProperty));
        String path = ComponentUtils.getPropertyPathName(prop, root, false);
        int idx = path.indexOf(':');
        // default to root
        propStr = path;
        if (idx >= 0) {
            compStr = path.substring(0, idx);
            if (idx < path.length() - 1) {
                propStr = path.substring(idx + 1);
            }
        }
    } else {
        throw new InternalErrorException("Unknown value type: " + value.getClass());
    }
    return new String[] { compStr, propStr };
}
Also used : RootModel(artisynth.core.workspace.RootModel) ModelComponent(artisynth.core.modelbase.ModelComponent) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) CompositeProperty(maspack.properties.CompositeProperty)

Example 19 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class SelectionPopup method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    LinkedList<ModelComponent> selectedItems = mySelectionManager.getCurrentSelection();
    if (command.equals("Edit reference list properties ...")) {
        createPropertyDialog(selectedItems);
    } else if (command.equals("Edit reference properties ...")) {
        createPropertyDialog(myRefComponentSelection);
    }
    if (command.equals("Edit properties ...")) {
        LinkedList<ModelComponent> selection = myPropertyEditSelection;
        if (myRefComponentSelection.size() > 0 && myRefComponentSelection.size() < selection.size()) {
            selection = new LinkedList<ModelComponent>();
            for (ModelComponent c : myPropertyEditSelection) {
                if (!(c instanceof ReferenceComponent)) {
                    selection.add(c);
                }
            }
        }
        createPropertyDialog(selection);
    } else if (command.equals("Edit render props ...") || command.equals("Set render props ...")) {
        LinkedList<ModelComponent> renderables = new LinkedList<ModelComponent>();
        for (ModelComponent c : myPropertyEditSelection) {
            if (c instanceof Renderable) {
                renderables.add(c);
            }
        }
        RenderPropsDialog dialog = new RenderPropsDialog("Edit render properties", renderables);
        if (dialog.numProperties() == 0) {
            JOptionPane.showMessageDialog(myParentGUIComponent, "No common render properties for selected components", "no common render properties", JOptionPane.INFORMATION_MESSAGE);
        } else {
            if (myLocateRenderPropEditClose) {
                GuiUtils.locateRelative(dialog, myLastBounds, 0.5, 0.5, 0, 0.5);
            } else {
                dialog.locateRight(myMain.getFrame());
            }
            myMain.registerWindow(dialog);
            dialog.setTitle("RenderProps for " + getNameForSelection(myPropertyEditSelection));
            dialog.setVisible(true);
        }
    } else if (command.equals("Clear render props")) {
        for (ModelComponent c : myPropertyEditSelection) {
            if (c instanceof Renderable) {
                ((Renderable) c).setRenderProps(null);
            }
        }
        requestViewerUpdate();
    } else if (command.equals("Set visible")) {
        for (ModelComponent c : myPropertyEditSelection) {
            if (c instanceof RenderableComponent) {
                setVisible((RenderableComponent) c, true);
            }
        }
        requestViewerUpdate();
    } else if (command.equals("Set invisible")) {
        for (ModelComponent c : myPropertyEditSelection) {
            if (c instanceof RenderableComponent) {
                setVisible((RenderableComponent) c, false);
            }
        }
        requestViewerUpdate();
    } else if (command.equals("Enable tracing")) {
        RootModel rootModel = myMain.getRootModel();
        for (ModelComponent c : myPropertyEditSelection) {
            if (c instanceof Traceable) {
                Traceable tr = (Traceable) c;
                if (!rootModel.isTracing(tr)) {
                    rootModel.enableTracing(tr);
                }
            }
        }
    } else if (command.equals("Disable tracing")) {
        RootModel rootModel = myMain.getRootModel();
        for (ModelComponent c : myPropertyEditSelection) {
            if (c instanceof Traceable) {
                Traceable tr = (Traceable) c;
                if (rootModel.isTracing(tr)) {
                    rootModel.disableTracing(tr);
                }
            }
        }
    } else if (command.equals("Clear trace")) {
        RootModel rootModel = myMain.getRootModel();
        for (ModelComponent c : myPropertyEditSelection) {
            if (c instanceof Traceable) {
                Traceable tr = (Traceable) c;
                if (rootModel.isTracing(tr)) {
                    rootModel.clearTracing(tr);
                }
            }
        }
        myMain.rerender();
    } else if (command.equals("Add tracing probe")) {
        addTracing(myPropertyEditSelection);
    } else if (command.equals("Save as ...")) {
        EditorUtils.saveComponent(selectedItems.get(0));
    } else if (command == "Delete") {
        deleteSelection();
    } else if (command.equals("Delete reference(s)")) {
        deleteRefComponentSelection();
    } else if (command == "Duplicate") {
        duplicateSelection();
    } else {
        // EditorBase editor = myEditActionMap.get (command);
        // if (editor != null) {
        // editor.applyAction (command, selectedItems, myLastBounds);
        // }
        EditorBase editor = myEditActionMap.getEditor(command);
        if (editor != null) {
            editor.applyAction(command, selectedItems, myLastBounds);
        }
    }
}
Also used : Renderable(maspack.render.Renderable) RootModel(artisynth.core.workspace.RootModel) ModelComponent(artisynth.core.modelbase.ModelComponent) ReferenceComponent(artisynth.core.modelbase.ReferenceComponent) RenderPropsDialog(maspack.widgets.RenderPropsDialog) RenderableComponent(artisynth.core.modelbase.RenderableComponent) EditorBase(artisynth.core.gui.editorManager.EditorBase) Traceable(artisynth.core.modelbase.Traceable) LinkedList(java.util.LinkedList)

Example 20 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class Main method reloadModel.

public void reloadModel() throws IOException {
    if (myModelFile != null) {
        loadModelFile(myModelFile);
    } else {
        RootModel root = getRootModel();
        if (root != null) {
            Class<?> rootClass = root.getClass();
            String name = myModelName;
            if (name == null) {
                name = root.getName();
            }
            if (name == null) {
                name = "ArtiSynth";
            }
            loadModel(lastModelInfo);
        }
    }
}
Also used : RootModel(artisynth.core.workspace.RootModel)

Aggregations

RootModel (artisynth.core.workspace.RootModel)44 ModelComponent (artisynth.core.modelbase.ModelComponent)10 InternalErrorException (maspack.util.InternalErrorException)7 IOException (java.io.IOException)6 WayPoint (artisynth.core.probes.WayPoint)4 FileNotFoundException (java.io.FileNotFoundException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Probe (artisynth.core.probes.Probe)3 WayPointProbe (artisynth.core.probes.WayPointProbe)3 File (java.io.File)3 Property (maspack.properties.Property)3 ControlPanel (artisynth.core.gui.ControlPanel)2 CompositeComponent (artisynth.core.modelbase.CompositeComponent)2 TracingProbe (artisynth.core.probes.TracingProbe)2 Point (java.awt.Point)2 JFileChooser (javax.swing.JFileChooser)2 JMenuItem (javax.swing.JMenuItem)2 JSeparator (javax.swing.JSeparator)2 CompositeProperty (maspack.properties.CompositeProperty)2 ArgParser (argparser.ArgParser)1