Search in sources :

Example 1 with EntityGroup

use of com.willwinder.ugs.nbp.designer.entities.EntityGroup in project Universal-G-Code-Sender by winder.

the class EntityTreeUtils method getSelectedPaths.

public static List<TreePath> getSelectedPaths(Controller controller, Entity entity, List<Entity> currentTreePath) {
    ArrayList<TreePath> result = new ArrayList<>();
    if (controller.getSelectionManager().isSelected(entity)) {
        List<Entity> entities = new ArrayList<>(currentTreePath);
        entities.add(entity);
        result.add(new TreePath(entities.toArray(new Entity[0])));
    }
    if (entity instanceof EntityGroup) {
        List<Entity> newCurrentTreePath = new ArrayList<>(currentTreePath);
        newCurrentTreePath.add(entity);
        result.addAll(((EntityGroup) entity).getChildren().stream().flatMap(e -> getSelectedPaths(controller, e, newCurrentTreePath).stream()).collect(Collectors.toList()));
    }
    return result;
}
Also used : Entity(com.willwinder.ugs.nbp.designer.entities.Entity) TreePath(javax.swing.tree.TreePath) EntityGroup(com.willwinder.ugs.nbp.designer.entities.EntityGroup) ArrayList(java.util.ArrayList)

Example 2 with EntityGroup

use of com.willwinder.ugs.nbp.designer.entities.EntityGroup in project Universal-G-Code-Sender by winder.

the class EntityGroupV1 method toInternal.

@Override
public Entity toInternal() {
    EntityGroup entityGroup = new EntityGroup();
    children.stream().map(EntityV1::toInternal).forEach(entityGroup::addChild);
    entityGroup.setName(getName());
    return entityGroup;
}
Also used : EntityGroup(com.willwinder.ugs.nbp.designer.entities.EntityGroup)

Example 3 with EntityGroup

use of com.willwinder.ugs.nbp.designer.entities.EntityGroup in project Universal-G-Code-Sender by winder.

the class MultiplyDialog method stateChanged.

@Override
public void stateChanged(ChangeEvent e) {
    entityGroup.removeAll();
    EntityGroup selection = new EntityGroup();
    selection.addAll(controller.getSelectionManager().getSelection().stream().map(Entity::copy).collect(Collectors.toList()));
    for (int x = 0; x < (int) xCountSpinner.getValue(); x++) {
        for (int y = 0; y < (int) yCountSpinner.getValue(); y++) {
            if (x >= 1 || y >= 1) {
                EntityGroup clone = (EntityGroup) selection.copy();
                Point2D position = clone.getPosition();
                double newX = position.getX() + (x * clone.getSize().getWidth()) + (x * (int) xSpacingSpinner.getValue());
                double newY = position.getY() + (y * clone.getSize().getHeight()) + (y * (int) ySpacingSpinner.getValue());
                clone.setPosition(new Point2D.Double(newX, newY));
                entityGroup.addAll(clone.getChildren());
            }
        }
    }
    controller.getDrawing().repaint();
}
Also used : Entity(com.willwinder.ugs.nbp.designer.entities.Entity) Point2D(java.awt.geom.Point2D) EntityGroup(com.willwinder.ugs.nbp.designer.entities.EntityGroup)

Example 4 with EntityGroup

use of com.willwinder.ugs.nbp.designer.entities.EntityGroup in project Universal-G-Code-Sender by winder.

the class FlipHorizontallyAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    SelectionManager selectionManager = controller.getSelectionManager();
    if (!selectionManager.getSelection().isEmpty()) {
        List<Entity> entities = selectionManager.getSelection();
        EntityGroup entityGroup = new EntityGroup();
        entityGroup.addAll(entities);
        UndoableFlipHorizontallyAction undoableAction = new UndoableFlipHorizontallyAction(controller.getDrawing(), entityGroup);
        controller.getUndoManager().addAction(undoableAction);
        undoableAction.execute();
    }
}
Also used : SelectionManager(com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager) Entity(com.willwinder.ugs.nbp.designer.entities.Entity) EntityGroup(com.willwinder.ugs.nbp.designer.entities.EntityGroup)

Example 5 with EntityGroup

use of com.willwinder.ugs.nbp.designer.entities.EntityGroup in project Universal-G-Code-Sender by winder.

the class FlipVerticallyAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    SelectionManager selectionManager = controller.getSelectionManager();
    if (!selectionManager.getSelection().isEmpty()) {
        List<Entity> entities = selectionManager.getSelection();
        EntityGroup entityGroup = new EntityGroup();
        entityGroup.addAll(entities);
        UndoableFlipVerticallyAction undoableAction = new UndoableFlipVerticallyAction(controller.getDrawing(), entityGroup);
        controller.getUndoManager().addAction(undoableAction);
        undoableAction.execute();
    }
}
Also used : SelectionManager(com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager) Entity(com.willwinder.ugs.nbp.designer.entities.Entity) EntityGroup(com.willwinder.ugs.nbp.designer.entities.EntityGroup)

Aggregations

EntityGroup (com.willwinder.ugs.nbp.designer.entities.EntityGroup)8 Entity (com.willwinder.ugs.nbp.designer.entities.Entity)4 SelectionManager (com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager)2 TreePath (javax.swing.tree.TreePath)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Settings (com.willwinder.ugs.nbp.designer.model.Settings)1 Point2D (java.awt.geom.Point2D)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1