Search in sources :

Example 1 with RemovePartCommand

use of org.concord.energy3d.undo.RemovePartCommand in project energy3d by concord-consortium.

the class SceneManager method deleteCurrentSelection.

public void deleteCurrentSelection() {
    if (selectedPart == null || selectedPart.getLockEdit()) {
        return;
    }
    if (selectedPart instanceof Foundation) {
        final Foundation foundation = (Foundation) selectedPart;
        if (!foundation.getChildren().isEmpty() && foundation.getSelectedMesh() == null) {
            if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "Deleting the platform also deletes the building on it. Are you sure?", "Confirmation", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
                return;
            }
        }
    }
    taskManager.update(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            if (selectedPart != null) {
                // sometimes selectedPart can be null after the callable is sent to the task manager
                if (selectedPart instanceof Foundation && ((Foundation) selectedPart).getSelectedMesh() != null) {
                    // a mesh is selected, instead of a part
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        f.deleteMesh(m);
                    }
                } else {
                    final RemovePartCommand c = new RemovePartCommand(selectedPart);
                    if (selectedPart instanceof Wall) {
                        // undo/redo a gable roof
                        final Roof roof = ((Wall) selectedPart).getRoof();
                        if (roof != null) {
                            final List<Map<Integer, List<Wall>>> gableInfo = new ArrayList<Map<Integer, List<Wall>>>();
                            if (roof.getGableEditPointToWallMap() != null) {
                                gableInfo.add(roof.getGableEditPointToWallMap());
                            }
                            c.setGableInfo(gableInfo);
                        }
                    } else if (selectedPart instanceof Foundation) {
                        // undo/redo all the gable roofs
                        final List<Roof> roofs = ((Foundation) selectedPart).getRoofs();
                        if (!roofs.isEmpty()) {
                            final List<Map<Integer, List<Wall>>> gableInfo = new ArrayList<Map<Integer, List<Wall>>>();
                            for (final Roof r : roofs) {
                                if (r.getGableEditPointToWallMap() != null) {
                                    gableInfo.add(r.getGableEditPointToWallMap());
                                }
                            }
                            c.setGableInfo(gableInfo);
                        }
                    }
                    undoManager.addEdit(c);
                    Scene.getInstance().remove(selectedPart, true);
                }
                if (selectedPart.getContainer() != null) {
                    // redraw its container since we are not calling the costly redrawAll any more
                    selectedPart.getContainer().draw();
                }
                selectedPart = null;
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        MainPanel.getInstance().getEnergyButton().setSelected(false);
                    }
                });
            }
            return null;
        }
    });
}
Also used : Wall(org.concord.energy3d.model.Wall) RemovePartCommand(org.concord.energy3d.undo.RemovePartCommand) ArrayList(java.util.ArrayList) Mesh(com.ardor3d.scenegraph.Mesh) IOException(java.io.IOException) Roof(org.concord.energy3d.model.Roof) GambrelRoof(org.concord.energy3d.model.GambrelRoof) ShedRoof(org.concord.energy3d.model.ShedRoof) PyramidRoof(org.concord.energy3d.model.PyramidRoof) HipRoof(org.concord.energy3d.model.HipRoof) CustomRoof(org.concord.energy3d.model.CustomRoof) Foundation(org.concord.energy3d.model.Foundation) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Mesh (com.ardor3d.scenegraph.Mesh)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CustomRoof (org.concord.energy3d.model.CustomRoof)1 Foundation (org.concord.energy3d.model.Foundation)1 GambrelRoof (org.concord.energy3d.model.GambrelRoof)1 HipRoof (org.concord.energy3d.model.HipRoof)1 PyramidRoof (org.concord.energy3d.model.PyramidRoof)1 Roof (org.concord.energy3d.model.Roof)1 ShedRoof (org.concord.energy3d.model.ShedRoof)1 Wall (org.concord.energy3d.model.Wall)1 RemovePartCommand (org.concord.energy3d.undo.RemovePartCommand)1