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