Search in sources :

Example 1 with EditPartCommand

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

the class SceneManager method mousePressed.

private void mousePressed(final MouseState mouseState, final KeyboardState keyboardState) {
    refresh = true;
    taskManager.update(new Callable<Object>() {

        @Override
        public Object call() {
            if (zoomLock) {
                return null;
            }
            System.out.println("OPERATION: " + operation);
            try {
                if (operation == Operation.SELECT || operation == Operation.RESIZE || operation == Operation.ROTATE || operation == Operation.DRAW_ROOF_GABLE) {
                    if (selectedPart == null || selectedPart.isDrawCompleted()) {
                        final HousePart previousSelectedPart = selectedPart;
                        final PickedHousePart pickedPart = SelectUtil.selectHousePart(mouseState.getX(), mouseState.getY(), true);
                        final UserData pick = pickedPart == null ? null : pickedPart.getUserData();
                        if (pick == null) {
                            selectedPart = null;
                        } else {
                            selectedPart = pick.getHousePart();
                        }
                        if (selectedPart != null) {
                            // }
                            if (keyboardState.isDown(Key.LMENU) || keyboardState.isDown(Key.RMENU)) {
                                if (selectedPart instanceof SolarPanel && selectedPart.getContainer() instanceof Rack) {
                                    // special case
                                    selectedPart = selectedPart.getContainer();
                                }
                            }
                        }
                        System.out.println("Clicked on: " + pick);
                        if (pick != null && pick.isEditPoint()) {
                            cameraControl.setLeftMouseButtonEnabled(false);
                        }
                        if (operation == Operation.RESIZE) {
                            for (final HousePart p : Scene.getInstance().getParts()) {
                                if (p instanceof Foundation) {
                                    if (p != selectedPart) {
                                        ((Foundation) p).setResizeHouseMode(false);
                                    }
                                }
                            }
                            if (selectedPart != null) {
                                if (selectedPart instanceof Foundation) {
                                    final Foundation foundation = (Foundation) selectedPart;
                                    foundation.setResizeHouseMode(true);
                                } else {
                                    final Foundation foundation = selectedPart.getTopContainer();
                                    if (foundation != null) {
                                        foundation.setResizeHouseMode(true);
                                        setSelectedPart(foundation);
                                    }
                                }
                            }
                        }
                        if (operation == Operation.SELECT || operation == Operation.ROTATE) {
                            if (previousSelectedPart instanceof Foundation) {
                                final Foundation foundation = (Foundation) previousSelectedPart;
                                foundation.updateAzimuthArrowVisibility(false);
                            }
                            if (selectedPart instanceof Foundation) {
                                final Foundation foundation = (Foundation) selectedPart;
                                foundation.drawAzimuthArrow();
                                foundation.pickMesh(mouseState.getX(), mouseState.getY());
                            }
                            if (selectedPart != null) {
                                final Foundation foundationOfSelectedPart = selectedPart instanceof Foundation ? (Foundation) selectedPart : selectedPart.getTopContainer();
                                if (foundationOfSelectedPart != null) {
                                    foundationOfSelectedPart.setMovePointsVisible(true);
                                }
                            }
                        }
                        if (operation == Operation.RESIZE && selectedPart != null) {
                            if (!(selectedPart instanceof Foundation)) {
                                selectedPart.setEditPointsVisible(false);
                                selectedPart = selectedPart.getTopContainer();
                            }
                        }
                        if (selectedPart instanceof Window || selectedPart instanceof Tree || (selectedPart instanceof Foundation && pick.getEditPointIndex() != -1)) {
                            cameraControl.setLeftMouseButtonEnabled(false);
                            objectMoveStartPoint = pickedPart.getPoint().clone();
                            collisionLand.setTranslation(0, 0, objectMoveStartPoint.getZ());
                            final ArrayList<Vector3> points = selectedPart.getPoints();
                            if (objectMovePoints == null) {
                                objectMovePoints = new ArrayList<Vector3>();
                            } else {
                                objectMovePoints.clear();
                            }
                            for (final Vector3 p : points) {
                                objectMovePoints.add(p.clone());
                            }
                            if (selectedPart instanceof Foundation) {
                                final Foundation f = (Foundation) selectedPart;
                                if (f.isGroupMaster()) {
                                    final List<Foundation> g = Scene.getInstance().getFoundationGroup(f);
                                    if (!g.isEmpty()) {
                                        if (objectGroupMovePoints == null) {
                                            objectGroupMovePoints = new HashMap<Foundation, ArrayList<Vector3>>();
                                        } else {
                                            objectGroupMovePoints.clear();
                                        }
                                        for (final Foundation a : g) {
                                            final ArrayList<Vector3> b = new ArrayList<Vector3>();
                                            objectGroupMovePoints.put(a, b);
                                            for (final Vector3 p : a.getPoints()) {
                                                b.add(p.clone());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (previousSelectedPart != null && previousSelectedPart != selectedPart && operation != Operation.RESIZE) {
                            previousSelectedPart.setEditPointsVisible(false);
                            previousSelectedPart.setGridsVisible(false);
                            previousSelectedPart.setLinePatternVisible(false);
                            final Foundation foundationOfPreviousSelectedPart = previousSelectedPart instanceof Foundation ? (Foundation) previousSelectedPart : previousSelectedPart.getTopContainer();
                            if (foundationOfPreviousSelectedPart != null) {
                                if (selectedPart == null) {
                                    foundationOfPreviousSelectedPart.setMovePointsVisible(false);
                                } else if (foundationOfPreviousSelectedPart != (selectedPart instanceof Foundation ? (Foundation) selectedPart : selectedPart.getTopContainer())) {
                                    foundationOfPreviousSelectedPart.setMovePointsVisible(false);
                                }
                                foundationOfPreviousSelectedPart.clearSelectedMesh();
                                foundationOfPreviousSelectedPart.setResizeHouseMode(false);
                            }
                        }
                        if (selectedPart != null && !PrintController.getInstance().isPrintPreview()) {
                            selectedPart.setEditPointsVisible(true);
                            if (pick.isEditPoint() && pick.getEditPointIndex() != -1 || operation == Operation.RESIZE || selectedPart instanceof Window || selectedPart instanceof Tree) {
                                if (Scene.getInstance().isSnapToGrids()) {
                                    selectedPart.setGridsVisible(true);
                                } else {
                                    selectedPart.setLinePatternVisible(true);
                                }
                                if (selectedPart instanceof Foundation) {
                                    editPartCommand = new EditFoundationCommand((Foundation) selectedPart, !pick.isEditPoint());
                                } else if (selectedPart instanceof Rack) {
                                    editPartCommand = new EditRackCommand((Rack) selectedPart);
                                } else if (selectedPart instanceof ParabolicTrough) {
                                    editPartCommand = new EditParabolicTroughCommand((ParabolicTrough) selectedPart);
                                } else {
                                    editPartCommand = new EditPartCommand(selectedPart);
                                }
                            }
                        }
                        SelectUtil.nextPickLayer();
                        if (operation == Operation.DRAW_ROOF_GABLE && selectedPart instanceof Roof) {
                            System.out.println("deleting roof #" + pick.getEditPointIndex());
                            final int roofPartIndex = pick.getEditPointIndex();
                            final Roof roof = (Roof) selectedPart;
                            roof.setGable(roofPartIndex, true, undoManager);
                        }
                    }
                } else {
                    if (selectedPart != null) {
                        // selected part can be null in modes other than specified in the if clause
                        selectedPart.addPoint(mouseState.getX(), mouseState.getY());
                    }
                }
            } catch (final Throwable t) {
                t.printStackTrace();
                BugReporter.report(t);
            }
            return null;
        }
    });
}
Also used : Window(org.concord.energy3d.model.Window) EditPartCommand(org.concord.energy3d.undo.EditPartCommand) EditRackCommand(org.concord.energy3d.undo.EditRackCommand) ParabolicTrough(org.concord.energy3d.model.ParabolicTrough) UserData(org.concord.energy3d.model.UserData) HashMap(java.util.HashMap) EditParabolicTroughCommand(org.concord.energy3d.undo.EditParabolicTroughCommand) ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Rack(org.concord.energy3d.model.Rack) EditFoundationCommand(org.concord.energy3d.undo.EditFoundationCommand) 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) SolarPanel(org.concord.energy3d.model.SolarPanel) Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) ArrayList(java.util.ArrayList) List(java.util.List) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) PickedHousePart(org.concord.energy3d.model.PickedHousePart)

Aggregations

Vector3 (com.ardor3d.math.Vector3)1 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)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 HousePart (org.concord.energy3d.model.HousePart)1 ParabolicTrough (org.concord.energy3d.model.ParabolicTrough)1 PickedHousePart (org.concord.energy3d.model.PickedHousePart)1 PyramidRoof (org.concord.energy3d.model.PyramidRoof)1 Rack (org.concord.energy3d.model.Rack)1 Roof (org.concord.energy3d.model.Roof)1 ShedRoof (org.concord.energy3d.model.ShedRoof)1 SolarPanel (org.concord.energy3d.model.SolarPanel)1 Tree (org.concord.energy3d.model.Tree)1 UserData (org.concord.energy3d.model.UserData)1 Window (org.concord.energy3d.model.Window)1