Search in sources :

Example 1 with DuplicateAgent

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

Aggregations

DuplicateAgent (artisynth.core.gui.editorManager.DuplicateAgent)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 MutableCompositeComponent (artisynth.core.modelbase.MutableCompositeComponent)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1