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();
}
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();
}
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());
}
}
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);
}
}
}
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);
}
}
}
Aggregations