Search in sources :

Example 21 with ModelComponent

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

the class SelectionPopup method duplicateSelection.

private void duplicateSelection() {
    LinkedList<ModelComponent> selection = mySelectionManager.getCurrentSelection();
    LinkedList<ModelComponent> copySelection = mySelectionManager.getCopyExpandedSelection();
    LinkedList<ModelComponent> copyList = new LinkedList<ModelComponent>();
    HashMap<ModelComponent, ModelComponent> copyMap = new HashMap<ModelComponent, ModelComponent>(copySelection.size());
    if (copySelection.size() > selection.size()) {
        for (ModelComponent c : copySelection) {
            if (!c.isSelected()) {
                mySelectionManager.addSelected(c);
            }
        }
    }
    // component are ordered with referenced components first, so we want to
    // reverse this ordering when building the add list
    LinkedList<MutableCompositeComponent<?>> parentList = new LinkedList<MutableCompositeComponent<?>>();
    for (ModelComponent c : copySelection) {
        ModelComponent copy;
        if ((copy = copyMap.get(c)) == null) {
            copy = ((CopyableComponent) c).copy(CopyableComponent.COPY_REFERENCES, copyMap);
            copyMap.put(c, copy);
            System.out.println("copying " + c);
        }
        parentList.addFirst((MutableCompositeComponent<?>) c.getParent());
        copyList.addFirst(copy);
    }
    DuplicateAgent widget = new DuplicateAgent(myMain, copyList, parentList);
    widget.show();
}
Also used : MutableCompositeComponent(artisynth.core.modelbase.MutableCompositeComponent) DuplicateAgent(artisynth.core.gui.editorManager.DuplicateAgent) ModelComponent(artisynth.core.modelbase.ModelComponent) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 22 with ModelComponent

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

the class SelectionPopup method deleteSelection.

private void deleteSelection() {
    LinkedList<ModelComponent> selection = mySelectionManager.getCurrentSelection();
    LinkedList<ModelComponent> update = new LinkedList<ModelComponent>();
    LinkedList<ModelComponent> delete = ComponentUtils.findDependentComponents(update, selection);
    if (delete.size() > selection.size()) {
        // first, see if we can actually delete:
        System.out.println("delete size=" + delete.size());
        if (!componentsAreDeletable(delete)) {
            JOptionPane.showMessageDialog(myParentGUIComponent, "Selection refers to additional components that can't be deleted", "selection not deletable", JOptionPane.INFORMATION_MESSAGE);
        } else {
            boolean needConfirmation = false;
            for (ModelComponent c : delete) {
                if (!c.isSelected()) {
                    needConfirmation = true;
                    mySelectionManager.addSelected(c);
                }
            }
            requestViewerUpdate();
            if (needConfirmation) {
                JOptionPane confirmDialog = new JOptionPane("Dependent components will be deleted also. Proceed?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
                JDialog dialog = confirmDialog.createDialog(myParentGUIComponent, "confirm deletion");
                GuiUtils.locateHorizontally(dialog, myParentGUIComponent, GuiUtils.CENTER);
                GuiUtils.locateVertically(dialog, myParentGUIComponent, GuiUtils.BELOW);
                dialog.setVisible(true);
                if ((confirmDialog.getValue() == null) || (confirmDialog.getValue().equals(JOptionPane.NO_OPTION))) {
                    return;
                }
            }
        }
    }
    // components are deselected before they are removed. This
    // will not affect dependentSelection because it is a (possibly
    // extended) copy of the selection.
    mySelectionManager.clearSelections();
    @SuppressWarnings("unchecked") RemoveComponentsCommand cmd = new RemoveComponentsCommand("delete", delete, update);
    myMain.getUndoManager().saveStateAndExecute(cmd);
    requestViewerUpdate();
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) RemoveComponentsCommand(artisynth.core.gui.editorManager.RemoveComponentsCommand) JOptionPane(javax.swing.JOptionPane) LinkedList(java.util.LinkedList) JDialog(javax.swing.JDialog)

Example 23 with ModelComponent

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

the class MechSystemSolver method printCompVel.

void printCompVel(String msg) {
    ModelComponent c = findComponent();
    if (c != null) {
        Point n = (Point) c;
        System.out.println(msg + " " + n.getVelocity());
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent)

Example 24 with ModelComponent

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

the class CollisionManager method getExternallyCollidableBodies.

private static void getExternallyCollidableBodies(List<CollidableBody> list, ModelComponent mc) {
    if (mc instanceof CompositeComponent) {
        CompositeComponent comp = (CompositeComponent) mc;
        for (int i = 0; i < comp.numComponents(); i++) {
            ModelComponent c = comp.get(i);
            if (c instanceof Collidable) {
                Collidable col = (Collidable) c;
                if (isCollidableBody(col) && isExternallyCollidable(col)) {
                    list.add((CollidableBody) c);
                }
            }
            getExternallyCollidableBodies(list, c);
        }
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) CompositeComponent(artisynth.core.modelbase.CompositeComponent)

Example 25 with ModelComponent

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

the class CollisionManager method getInternallyCollidableBodies.

private static void getInternallyCollidableBodies(List<CollidableBody> list, ModelComponent mc) {
    if (mc instanceof CompositeComponent) {
        CompositeComponent comp = (CompositeComponent) mc;
        for (int i = 0; i < comp.numComponents(); i++) {
            ModelComponent c = comp.get(i);
            if (c instanceof Collidable) {
                Collidable col = (Collidable) c;
                if (isCollidableBody(col) && isInternallyCollidable(col)) {
                    list.add((CollidableBody) c);
                }
            }
            getInternallyCollidableBodies(list, c);
        }
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) CompositeComponent(artisynth.core.modelbase.CompositeComponent)

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