Search in sources :

Example 16 with ModelComponent

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

the class IsRenderableEditor method applyAction.

public void applyAction(String actionCommand, LinkedList<ModelComponent> selection, Rectangle popupBounds) {
    if (glEditCmd.equals(actionCommand)) {
        ArrayList<HasProperties> contained = new ArrayList<HasProperties>(selection.size());
        for (ModelComponent mc : selection) {
            if (mc instanceof IsRenderableHolder) {
                IsRenderableHolder holder = (IsRenderableHolder) mc;
                IsRenderable glr = holder.getRenderable();
                if (glr instanceof HasProperties) {
                    contained.add((HasProperties) glr);
                }
            }
        }
        if (contained.size() > 0) {
            createPropertyDialog(contained, true, popupBounds);
        } else {
            JOptionPane.showMessageDialog(null, "No properties for selected components", "No properties", JOptionPane.INFORMATION_MESSAGE);
        }
    }
}
Also used : IsRenderable(maspack.render.IsRenderable) ModelComponent(artisynth.core.modelbase.ModelComponent) IsRenderableHolder(artisynth.core.renderables.IsRenderableHolder) HasProperties(maspack.properties.HasProperties) ArrayList(java.util.ArrayList)

Example 17 with ModelComponent

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

the class TimelineController method selectionChanged.

public void selectionChanged(SelectionEvent e) {
    for (ModelComponent c : e.getAddedComponents()) {
        if (c instanceof Probe) {
            ProbeInfo info = myProbeMap.get((Probe) c);
            selectedProbes.add(info);
        }
    }
    for (ModelComponent c : e.getRemovedComponents()) {
        if (c instanceof Probe) {
            ProbeInfo info = myProbeMap.get((Probe) c);
            selectedProbes.remove(info);
        }
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) Probe(artisynth.core.probes.Probe) WayPointProbe(artisynth.core.probes.WayPointProbe)

Example 18 with ModelComponent

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

the class InverseManager method configureTargetMotionProbe.

private void configureTargetMotionProbe(NumericProbeBase probe, ArrayList<MotionTargetComponent> targets, String filename) {
    // System.out.println ("configuring motion probe");
    ArrayList<Property> props = new ArrayList<Property>();
    for (ModelComponent target : targets) {
        if (target instanceof Point) {
            props.add(target.getProperty("position"));
        } else if (target instanceof Frame) {
            props.add(target.getProperty("position"));
            props.add(target.getProperty("orientation"));
        } else {
            System.err.println("Unknown target component type: " + target.getClass().toString());
        }
    }
    // probe.setModel(myController.getMech());
    probe.setAttachedFileName(filename);
    if (probe instanceof NumericInputProbe) {
        ((NumericInputProbe) probe).setInputProperties(props.toArray(new Property[props.size()]));
    } else if (probe instanceof NumericOutputProbe) {
        ((NumericOutputProbe) probe).setOutputProperties(props.toArray(new Property[props.size()]));
    }
    if (probe instanceof NumericInputProbe) {
        File file = probe.getAttachedFile();
        if (file == null || !file.exists()) {
            ((NumericInputProbe) probe).loadEmpty();
            probe.setActive(false);
        } else {
            try {
                probe.load();
                probe.setActive(true);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Frame(artisynth.core.mechmodels.Frame) ModelComponent(artisynth.core.modelbase.ModelComponent) NumericInputProbe(artisynth.core.probes.NumericInputProbe) ArrayList(java.util.ArrayList) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) Point(artisynth.core.mechmodels.Point) WayPoint(artisynth.core.probes.WayPoint) IOException(java.io.IOException) Property(maspack.properties.Property) File(java.io.File)

Example 19 with ModelComponent

use of artisynth.core.modelbase.ModelComponent 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 20 with ModelComponent

use of artisynth.core.modelbase.ModelComponent 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)

Aggregations

ModelComponent (artisynth.core.modelbase.ModelComponent)53 RootModel (artisynth.core.workspace.RootModel)9 Property (maspack.properties.Property)8 CompositeComponent (artisynth.core.modelbase.CompositeComponent)5 ArrayList (java.util.ArrayList)5 Point (artisynth.core.mechmodels.Point)4 Renderable (maspack.render.Renderable)4 InternalErrorException (maspack.util.InternalErrorException)4 HasCoordinateFrame (artisynth.core.modelbase.HasCoordinateFrame)3 Traceable (artisynth.core.modelbase.Traceable)3 WayPoint (artisynth.core.probes.WayPoint)3 Point (java.awt.Point)3 LinkedList (java.util.LinkedList)3 CompositeProperty (maspack.properties.CompositeProperty)3 FractionRenderType (artisynth.core.femmodels.AuxMaterialBundle.FractionRenderType)2 FemModel3d (artisynth.core.femmodels.FemModel3d)2 HexElement (artisynth.core.femmodels.HexElement)2 DirectionRenderType (artisynth.core.femmodels.MuscleBundle.DirectionRenderType)2 RemoveComponentsCommand (artisynth.core.gui.editorManager.RemoveComponentsCommand)2 ExcitationComponent (artisynth.core.mechmodels.ExcitationComponent)2