Search in sources :

Example 1 with Traceable

use of artisynth.core.modelbase.Traceable 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 2 with Traceable

use of artisynth.core.modelbase.Traceable in project artisynth_core by artisynth.

the class RootModel method getTraceSet.

public Collection<Traceable> getTraceSet() {
    Collection<TracingProbe> tprobes = getTracingProbes();
    ArrayList<Traceable> traceSet = new ArrayList<Traceable>();
    for (TracingProbe tp : tprobes) {
        traceSet.add((Traceable) tp.getHost(0));
    }
    return traceSet;
}
Also used : TracingProbe(artisynth.core.probes.TracingProbe) Traceable(artisynth.core.modelbase.Traceable)

Example 3 with Traceable

use of artisynth.core.modelbase.Traceable in project artisynth_core by artisynth.

the class SelectionPopup method addPropertyEditMenuItems.

public void addPropertyEditMenuItems(LinkedList<ModelComponent> selection) {
    // parse the selection list.
    boolean allSelectedHaveProperties = false;
    boolean allSelectedAreTraceable = false;
    int tracingCnt = 0;
    boolean oneSelectedIsRenderable = false;
    boolean oneSelectedHasRenderProps = false;
    boolean oneSelectedHasFixedRenderProps = false;
    boolean oneSelectedIsVisible = false;
    boolean oneSelectedIsInvisible = false;
    boolean oneSelectedHasRenderPropsProperty = false;
    if (selection.size() > 0) {
        allSelectedHaveProperties = true;
        allSelectedAreTraceable = true;
        for (ModelComponent c : selection) {
            if (c instanceof RenderableComponent) {
                oneSelectedIsRenderable = true;
                RenderableComponent rcomp = (RenderableComponent) c;
                if (isVisible(rcomp)) {
                    oneSelectedIsVisible = true;
                } else {
                    oneSelectedIsInvisible = true;
                }
                // RenderableComponent > HasProperties, but may not have
                // renderProps property
                PropertyInfo rinfo = rcomp.getAllPropertyInfo().get("renderProps");
                if (rinfo != null) {
                    oneSelectedHasRenderPropsProperty = true;
                }
                if (rcomp.getRenderProps() != null) {
                    oneSelectedHasRenderProps = true;
                    // be set to null ...
                    if (!oneSelectedHasFixedRenderProps) {
                        if (!rinfo.getNullValueOK()) {
                            oneSelectedHasFixedRenderProps = true;
                        }
                    }
                }
            }
            if (!(c instanceof HasProperties)) {
                allSelectedHaveProperties = false;
            }
            if (!(c instanceof Traceable)) {
                allSelectedAreTraceable = false;
            }
        }
    }
    Collection<Traceable> traceSet = myMain.getRootModel().getTraceSet();
    for (Traceable tr : traceSet) {
        if (tr instanceof ModelComponent && ((ModelComponent) tr).isSelected()) {
            tracingCnt++;
        }
    }
    if (allSelectedHaveProperties) {
        addMenuItem("Edit properties ...");
    }
    if (oneSelectedIsRenderable && oneSelectedHasRenderPropsProperty) {
        if (oneSelectedHasRenderProps) {
            addMenuItem("Edit render props ...");
            if (!oneSelectedHasFixedRenderProps) {
                addMenuItem("Clear render props");
            }
        } else {
            addMenuItem("Set render props ...");
        }
    }
    if (oneSelectedIsInvisible) {
        addMenuItem("Set visible");
    }
    if (oneSelectedIsVisible) {
        addMenuItem("Set invisible");
    }
    if (allSelectedAreTraceable) {
        if (selection.size() - tracingCnt > 0) {
            addMenuItem("Enable tracing");
        }
        if (tracingCnt > 0) {
            addMenuItem("Disable tracing");
        }
        JMenuItem menuItem = new JMenuItem("Clear trace");
        menuItem.addActionListener(this);
        String[] commonTraceables = getCommonTraceables(selection);
        if (commonTraceables.length > 0) {
            menuItem = new JMenuItem("Add tracing probe");
            myTraceItem = menuItem;
        }
        menuItem.addActionListener(this);
        add(menuItem);
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) RenderableComponent(artisynth.core.modelbase.RenderableComponent) HasProperties(maspack.properties.HasProperties) PropertyInfo(maspack.properties.PropertyInfo) Traceable(artisynth.core.modelbase.Traceable) JMenuItem(javax.swing.JMenuItem) Point(java.awt.Point)

Example 4 with Traceable

use of artisynth.core.modelbase.Traceable in project artisynth_core by artisynth.

the class SelectionPopup method addTracing.

private void addTracing(LinkedList<ModelComponent> selectedItems) {
    // RootModel root = myMain.getRootModel();
    // String name = null;
    // double startTime = myMain.getTimeSec();
    // double updateInterval = root.getMaxStepSizeSec();
    Traceable firstTraceable = null;
    for (ModelComponent comp : selectedItems) {
        if (comp instanceof Traceable) {
            firstTraceable = (Traceable) comp;
        }
    }
    if (firstTraceable == null) {
        throw new InternalErrorException("'Add tracing' called with no traceabled in selection");
    }
    TracingProbePanel panel = new TracingProbePanel(firstTraceable, getCommonTraceables(selectedItems));
    panel.pack();
    GuiUtils.locateRelative(panel, myLastBounds, 0.5, 0.5, 0, 0.5);
    // if (myTraceItemLoc != null)
    // { panel.setLocation (
    // myTraceItemLoc.x, myTraceItemLoc.y);
    // }
    panel.setVisible(true);
    if (panel.getReturnValue() == OptionPanel.OK_OPTION) {
        for (ModelComponent comp : selectedItems) {
            if (comp instanceof Traceable) {
                TracingProbe probe = panel.createProbe((Traceable) comp);
                myMain.getRootModel().addOutputProbe(probe);
            }
        }
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) TracingProbePanel(artisynth.core.gui.editorManager.TracingProbePanel) InternalErrorException(maspack.util.InternalErrorException) TracingProbe(artisynth.core.probes.TracingProbe) Traceable(artisynth.core.modelbase.Traceable)

Aggregations

Traceable (artisynth.core.modelbase.Traceable)4 ModelComponent (artisynth.core.modelbase.ModelComponent)3 RenderableComponent (artisynth.core.modelbase.RenderableComponent)2 TracingProbe (artisynth.core.probes.TracingProbe)2 EditorBase (artisynth.core.gui.editorManager.EditorBase)1 TracingProbePanel (artisynth.core.gui.editorManager.TracingProbePanel)1 ReferenceComponent (artisynth.core.modelbase.ReferenceComponent)1 RootModel (artisynth.core.workspace.RootModel)1 Point (java.awt.Point)1 LinkedList (java.util.LinkedList)1 JMenuItem (javax.swing.JMenuItem)1 HasProperties (maspack.properties.HasProperties)1 PropertyInfo (maspack.properties.PropertyInfo)1 Renderable (maspack.render.Renderable)1 InternalErrorException (maspack.util.InternalErrorException)1 RenderPropsDialog (maspack.widgets.RenderPropsDialog)1