use of artisynth.core.gui.editorManager.DuplicateAgent 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();
}
Aggregations