Search in sources :

Example 11 with Window

use of org.concord.energy3d.model.Window in project energy3d by concord-consortium.

the class SceneManager method mouseMoved.

private void mouseMoved() {
    if (!mouseControlEnabled) {
        return;
    }
    final int x = mouseState.getX();
    final int y = mouseState.getY();
    if (Scene.getInstance().getDisableShadowInAction()) {
        if (mouseState.getButtonState(MouseButton.LEFT) == ButtonState.DOWN || mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.DOWN) {
            if (MainPanel.getInstance().getShadowButton().isSelected()) {
                shadowPass.setEnabled(false);
            }
        } else {
            if (MainPanel.getInstance().getShadowButton().isSelected()) {
                shadowPass.setEnabled(true);
            }
        }
    }
    try {
        if (selectedPart != null) {
            if (!selectedPart.isDrawCompleted()) {
                selectedPart.setPreviewPoint(x, y);
                if (selectedPart instanceof Meshable) {
                    // don't draw grid if it sits on an imported mesh
                    selectedPart.setGridsVisible(((Meshable) selectedPart).getMeshLocator() == null);
                }
            } else if (objectMoveStartPoint != null) {
                if ((operation == Operation.RESIZE || selectedPart instanceof Foundation)) {
                    final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
                    if (pick != null) {
                        if (selectedPart instanceof Foundation) {
                            final Foundation foundation = (Foundation) selectedPart;
                            final Vector3 pickPoint = pick.getPoint().clone();
                            // if (!foundation.insideBuilding(pickPoint.getX(), pickPoint.getY(), true)) { // only move the building when clicking outside
                            final Vector3 d = pickPoint.multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
                            if (foundation.isGroupMaster()) {
                                final List<Foundation> g = Scene.getInstance().getFoundationGroup(foundation);
                                for (final Foundation f : g) {
                                    final ArrayList<Vector3> movePoints = objectGroupMovePoints.get(f);
                                    if (movePoints != null) {
                                        // just in case this foundation's move point hasn't been included yet
                                        f.move(d, movePoints);
                                    }
                                }
                            } else {
                                foundation.move(d, objectMovePoints);
                            }
                        }
                    }
                } else if (selectedPart instanceof Tree) {
                    final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
                    if (pick != null) {
                        final Vector3 d = pick.getPoint().multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
                        ((Tree) selectedPart).move(d, objectMovePoints);
                    }
                } else if (selectedPart instanceof Window) {
                    final PickedHousePart pick = SelectUtil.pickPart(x, y, selectedPart.getContainer());
                    if (pick != null) {
                        final Vector3 d = pick.getPoint().subtract(objectMoveStartPoint, null);
                        ((Window) selectedPart).move(d, objectMovePoints);
                    }
                }
            }
        }
        hoveredPart = null;
        if ((operation == Operation.SELECT || operation == Operation.RESIZE) && mouseState.getButtonState(MouseButton.LEFT) == ButtonState.UP && mouseState.getButtonState(MouseButton.MIDDLE) == ButtonState.UP && mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.UP) {
            final PickedHousePart pickedPart = SelectUtil.selectHousePart(x, y, false);
            pick = pickedPart == null ? null : pickedPart.getUserData();
            final HousePart housePart = pick == null ? null : pick.getHousePart();
            if (pick != null) {
                hoveredPart = housePart;
                if (pick.getEditPointIndex() != -1) {
                    lastSelectedEditPointMouseState = mouseState;
                }
            }
        }
        mouseState = null;
    } catch (final Throwable t) {
        t.printStackTrace();
        BugReporter.report(t);
    }
    EventQueue.invokeLater(new // this method is run by the main Energy3D thread, so invoke the Swing code later
    Runnable() {

        @Override
        public void run() {
            final Component canvasComponent = (Component) canvas;
            canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            if (!zoomLock && (operation == Operation.SELECT || operation == Operation.RESIZE) && hoveredPart != null) {
                if (hoveredPart instanceof Tree || hoveredPart instanceof Human) {
                    canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                } else if (hoveredPart instanceof SolarCollector) {
                    if (pick.getEditPointIndex() >= 0) {
                        canvasComponent.setCursor(Cursor.getPredefinedCursor(pick.getEditPointIndex() == 0 ? Cursor.MOVE_CURSOR : Cursor.HAND_CURSOR));
                    }
                } else {
                    if (pick.getEditPointIndex() == -1) {
                        if (hoveredPart instanceof Window) {
                            // for windows, there is no apparent move point
                            canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        }
                    }
                }
            }
        }
    });
}
Also used : Window(org.concord.energy3d.model.Window) Human(org.concord.energy3d.model.Human) ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) Meshable(org.concord.energy3d.model.Meshable) SolarCollector(org.concord.energy3d.model.SolarCollector) Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) ArrayList(java.util.ArrayList) List(java.util.List) Component(java.awt.Component) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) PickedHousePart(org.concord.energy3d.model.PickedHousePart)

Example 12 with Window

use of org.concord.energy3d.model.Window in project energy3d by concord-consortium.

the class SceneManager method initMouse.

private void initMouse() {
    logicalLayer.registerTrigger(new InputTrigger(new MouseButtonPressedCondition(MouseButton.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            ((Component) canvas).requestFocusInWindow();
            if (Config.isMac()) {
                // control-click is mouse right-click on the Mac, skip
                final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
                if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
                    return;
                }
            }
            if (firstClickState == null) {
                firstClickState = inputStates;
                mousePressed(inputStates.getCurrent().getMouseState(), inputStates.getCurrent().getKeyboardState());
            } else {
                firstClickState = null;
                mouseReleased(inputStates.getCurrent().getMouseState());
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new MouseButtonReleasedCondition(MouseButton.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (Config.isMac()) {
                // control-click is mouse right-click on the Mac, skip
                final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
                if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
                    return;
                }
            }
            // if editing object using select or resize then only mouse drag is allowed
            if (operation == Operation.SELECT || operation == Operation.RESIZE) {
                firstClickState = null;
                mouseReleased(inputStates.getCurrent().getMouseState());
            } else if (firstClickState != null) {
                final MouseState mouseState = inputStates.getCurrent().getMouseState();
                final MouseState prevMouseState = firstClickState.getCurrent().getMouseState();
                final ReadOnlyVector2 p1 = new Vector2(prevMouseState.getX(), prevMouseState.getY());
                final ReadOnlyVector2 p2 = new Vector2(mouseState.getX(), mouseState.getY());
                if (!(selectedPart instanceof Foundation || selectedPart instanceof Wall || selectedPart instanceof Window || selectedPart instanceof Door) || p1.distance(p2) > 10) {
                    firstClickState = null;
                    mouseReleased(inputStates.getCurrent().getMouseState());
                }
            }
        }
    }));
    ((Component) canvas).addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (Util.isRightClick(e)) {
                mouseRightClicked(e);
            }
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (Util.isRightClick(e)) {
                if (cameraChanged) {
                    TimeSeriesLogger.getInstance().logCamera("Pan");
                    cameraChanged = false;
                }
            }
        }
    });
    ((Component) canvas).addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseDragged(final MouseEvent e) {
            EnergyPanel.getInstance().update();
            cameraChanged = true;
        }
    });
    ((Component) canvas).addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(final MouseWheelEvent e) {
            TimeSeriesLogger.getInstance().logCamera("Zoom");
        }
    });
    logicalLayer.registerTrigger(new InputTrigger(new MouseMovedCondition(), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            refresh = true;
            mouseState = inputStates.getCurrent().getMouseState();
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new MouseButtonClickedCondition(MouseButton.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (Config.isMac()) {
                // control-click is mouse right-click on the Mac, skip
                final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
                if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
                    return;
                }
            }
            if (!isTopView() && inputStates.getCurrent().getMouseState().getClickCount(MouseButton.LEFT) == 2) {
                if (PrintController.getInstance().isPrintPreview()) {
                    final MouseState mouse = inputStates.getCurrent().getMouseState();
                    final Ray3 pickRay = Camera.getCurrentCamera().getPickRay(new Vector2(mouse.getX(), mouse.getY()), false, null);
                    final PickResults pickResults = new PrimitivePickResults();
                    PickingUtil.findPick(PrintController.getInstance().getPagesRoot(), pickRay, pickResults, false);
                    if (pickResults.getNumber() > 0) {
                        cameraControl.zoomAtPoint(pickResults.getPickData(0).getIntersectionRecord().getIntersectionPoint(0));
                    }
                } else {
                    final PickedHousePart pickedHousePart = SelectUtil.pickPart(inputStates.getCurrent().getMouseState().getX(), inputStates.getCurrent().getMouseState().getY());
                    if (pickedHousePart != null) {
                        cameraControl.zoomAtPoint(pickedHousePart.getPoint());
                    }
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.LSHIFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
        // SelectUtil.setPickLayer(0);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.LSHIFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
        // SelectUtil.setPickLayer(-1);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.DELETE), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            deleteCurrentSelection();
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.BACK), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            deleteCurrentSelection();
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.ESCAPE), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            hideAllEditPoints();
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ZERO), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
            if (Config.isMac()) {
                if (ks.isDown(Key.LMETA) || ks.isDown(Key.RMETA)) {
                    resetCamera();
                }
            } else {
                if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
                    resetCamera();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.I), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            System.out.println("---- Parts: ------------------------");
            System.out.println("size = " + Scene.getInstance().getParts().size());
            for (final HousePart part : Scene.getInstance().getParts()) {
                System.out.println(part);
            }
            System.out.println("---- Scene: ------------------------");
            System.out.println("size = " + Scene.getOriginalHouseRoot().getNumberOfChildren());
            for (final Spatial mesh : Scene.getOriginalHouseRoot().getChildren()) {
                System.out.println(mesh);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            Scene.getInstance().redrawAll(true);
        }
    }));
    // Run/pause model replay
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = !PlayControl.replaying;
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = false;
                PlayControl.backward = true;
            }
            if (isTopView()) {
                if (tooManyPartsToMove()) {
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
                } else {
                    if (arrowKeyHolderTask != null) {
                        arrowKeyHolderTask.cancel();
                    }
                    arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
                    keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
                }
            } else {
                if (selectedPart instanceof Window) {
                    final Vector3 v = selectedPart.getNormal().clone();
                    v.crossLocal(Vector3.UNIT_Z);
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), v);
                    Scene.getInstance().redrawAll();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.LEFT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.UP), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = false;
                PlayControl.backward = true;
            }
            if (isTopView()) {
                if (tooManyPartsToMove()) {
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
                } else {
                    if (arrowKeyHolderTask != null) {
                        arrowKeyHolderTask.cancel();
                    }
                    arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
                    keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
                }
            } else {
                if (selectedPart instanceof Window) {
                    final Vector3 n = selectedPart.getNormal().clone();
                    final Vector3 v = n.cross(Vector3.UNIT_Z, null);
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), v.crossLocal(n));
                    Scene.getInstance().redrawAll();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.UP), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.RIGHT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = false;
                PlayControl.forward = true;
            }
            if (isTopView()) {
                if (tooManyPartsToMove()) {
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
                } else {
                    if (arrowKeyHolderTask != null) {
                        arrowKeyHolderTask.cancel();
                    }
                    arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
                    keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
                }
            } else {
                if (selectedPart instanceof Window) {
                    final Vector3 v = selectedPart.getNormal().clone();
                    v.crossLocal(Vector3.UNIT_Z).negateLocal();
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), v);
                    Scene.getInstance().redrawAll();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.RIGHT), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.DOWN), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (PlayControl.active) {
                PlayControl.replaying = false;
                PlayControl.forward = true;
            }
            if (isTopView()) {
                if (tooManyPartsToMove()) {
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
                } else {
                    if (arrowKeyHolderTask != null) {
                        arrowKeyHolderTask.cancel();
                    }
                    arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
                    keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
                }
            } else {
                if (selectedPart instanceof Window) {
                    final Vector3 n = selectedPart.getNormal().clone();
                    final Vector3 v = n.cross(Vector3.UNIT_Z, null).negateLocal();
                    moveWithKey(inputStates.getCurrent().getKeyboardState(), v.crossLocal(n));
                    Scene.getInstance().redrawAll();
                }
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.DOWN), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ESCAPE), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            PlayControl.active = false;
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.W), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (tooManyPartsToMove()) {
                moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
            } else {
                if (arrowKeyHolderTask != null) {
                    arrowKeyHolderTask.cancel();
                }
                arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
                keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.W), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.E), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (tooManyPartsToMove()) {
                moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
            } else {
                if (arrowKeyHolderTask != null) {
                    arrowKeyHolderTask.cancel();
                }
                arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
                keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.E), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.S), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (tooManyPartsToMove()) {
                moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
            } else {
                if (arrowKeyHolderTask != null) {
                    arrowKeyHolderTask.cancel();
                }
                arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
                keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.S), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.N), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (tooManyPartsToMove()) {
                moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
            } else {
                if (arrowKeyHolderTask != null) {
                    arrowKeyHolderTask.cancel();
                }
                arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
                keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
            }
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.N), new TriggerAction() {

        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (arrowKeyHolderTask != null) {
                arrowKeyHolderTask.cancel();
            }
        }
    }));
}
Also used : TriggerAction(com.ardor3d.input.logical.TriggerAction) MouseButtonReleasedCondition(com.ardor3d.input.logical.MouseButtonReleasedCondition) Wall(org.concord.energy3d.model.Wall) KeyPressedCondition(com.ardor3d.input.logical.KeyPressedCondition) InputTrigger(com.ardor3d.input.logical.InputTrigger) MouseButtonPressedCondition(com.ardor3d.input.logical.MouseButtonPressedCondition) KeyReleasedCondition(com.ardor3d.input.logical.KeyReleasedCondition) MouseWheelListener(java.awt.event.MouseWheelListener) Ray3(com.ardor3d.math.Ray3) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) KeyboardState(com.ardor3d.input.KeyboardState) Foundation(org.concord.energy3d.model.Foundation) Component(java.awt.Component) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) PickedHousePart(org.concord.energy3d.model.PickedHousePart) Window(org.concord.energy3d.model.Window) MouseEvent(java.awt.event.MouseEvent) MouseMovedCondition(com.ardor3d.input.logical.MouseMovedCondition) Canvas(com.ardor3d.framework.Canvas) MouseAdapter(java.awt.event.MouseAdapter) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) MouseButtonClickedCondition(com.ardor3d.input.logical.MouseButtonClickedCondition) Door(org.concord.energy3d.model.Door) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseWheelEvent(java.awt.event.MouseWheelEvent) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) Spatial(com.ardor3d.scenegraph.Spatial) MouseState(com.ardor3d.input.MouseState) TwoInputStates(com.ardor3d.input.logical.TwoInputStates) PickResults(com.ardor3d.intersection.PickResults) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) KeyHeldCondition(com.ardor3d.input.logical.KeyHeldCondition)

Example 13 with Window

use of org.concord.energy3d.model.Window in project energy3d by concord-consortium.

the class DataViewer method viewRawData.

static void viewRawData(final java.awt.Window parent, final Graph graph, final boolean selectAll) {
    String[] header = null;
    if (graph instanceof BuildingEnergyDailyGraph) {
        header = new String[] { "Hour", "Windows", "Solar Panels", "Heater", "AC", "Net" };
    } else if (graph instanceof BuildingEnergyAnnualGraph) {
        header = new String[] { "Month", "Windows", "Solar Panels", "Heater", "AC", "Net" };
    } else if (graph instanceof PartEnergyDailyGraph) {
        final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
        if (selectAll || selectedPart instanceof SolarPanel || selectedPart instanceof Rack || selectedPart instanceof Mirror || selectedPart instanceof Foundation) {
            header = new String[] { "Hour", "Solar" };
        } else if (selectedPart instanceof Wall || selectedPart instanceof Roof || selectedPart instanceof Door) {
            header = new String[] { "Hour", "Heat Gain" };
        } else if (selectedPart instanceof Window) {
            header = new String[] { "Hour", "Solar", "Heat Gain" };
        }
        if (graph.instrumentType == Graph.SENSOR) {
            final List<HousePart> parts = Scene.getInstance().getParts();
            final List<String> sensorList = new ArrayList<String>();
            for (final HousePart p : parts) {
                if (p instanceof Sensor) {
                    final Sensor sensor = (Sensor) p;
                    sensorList.add("Light: #" + sensor.getId());
                    sensorList.add("Heat Flux: #" + sensor.getId());
                }
            }
            if (!sensorList.isEmpty()) {
                header = new String[1 + sensorList.size()];
                header[0] = "Hour";
                for (int i = 1; i < header.length; i++) {
                    header[i] = sensorList.get(i - 1);
                }
            }
        }
    } else if (graph instanceof PartEnergyAnnualGraph) {
        final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
        if (selectAll || selectedPart instanceof SolarPanel || selectedPart instanceof Rack || selectedPart instanceof Mirror || selectedPart instanceof Foundation) {
            header = new String[] { "Month", "Solar" };
        } else if (selectedPart instanceof Wall || selectedPart instanceof Roof || selectedPart instanceof Door) {
            header = new String[] { "Month", "Heat Gain" };
        } else if (selectedPart instanceof Window) {
            header = new String[] { "Month", "Solar", "Heat Gain" };
        }
        if (graph.instrumentType == Graph.SENSOR) {
            final List<HousePart> parts = Scene.getInstance().getParts();
            final List<String> sensorList = new ArrayList<String>();
            for (final HousePart p : parts) {
                if (p instanceof Sensor) {
                    final Sensor sensor = (Sensor) p;
                    sensorList.add("Light: #" + sensor.getId());
                    sensorList.add("Heat Flux: #" + sensor.getId());
                }
            }
            if (!sensorList.isEmpty()) {
                header = new String[1 + sensorList.size()];
                header[0] = "Month";
                for (int i = 1; i < header.length; i++) {
                    header[i] = sensorList.get(i - 1);
                }
            }
        }
    } else if (graph instanceof BuildingEnergyAngularGraph) {
        header = new String[] { "Degree", "Windows", "Solar Panels", "Heater", "AC", "Net" };
    } else if (graph instanceof PartEnergyAngularGraph) {
        final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
        if (selectedPart instanceof SolarPanel || selectedPart instanceof Rack || selectedPart instanceof Mirror || selectedPart instanceof Foundation) {
            header = new String[] { "Degree", "Solar" };
        } else if (selectedPart instanceof Wall || selectedPart instanceof Roof || selectedPart instanceof Door) {
            header = new String[] { "Degree", "Heat Gain" };
        } else if (selectedPart instanceof Window) {
            header = new String[] { "Degree", "Solar", "Heat Gain" };
        }
    }
    if (header == null) {
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "Problem in finding data.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    final int m = header.length;
    final int n = graph.getLength();
    final Object[][] column = new Object[n][m + 1];
    for (int i = 0; i < n; i++) {
        column[i][0] = header[0].equals("Hour") ? i : (i + 1);
    }
    for (int j = 1; j < m; j++) {
        final List<Double> list = graph.getData(header[j]);
        for (int i = 0; i < n; i++) {
            column[i][j] = list.get(i);
        }
    }
    showDataWindow("Data", column, header, parent);
}
Also used : Wall(org.concord.energy3d.model.Wall) ArrayList(java.util.ArrayList) Rack(org.concord.energy3d.model.Rack) Roof(org.concord.energy3d.model.Roof) Foundation(org.concord.energy3d.model.Foundation) ArrayList(java.util.ArrayList) List(java.util.List) HousePart(org.concord.energy3d.model.HousePart) Window(org.concord.energy3d.model.Window) Door(org.concord.energy3d.model.Door) SolarPanel(org.concord.energy3d.model.SolarPanel) Mirror(org.concord.energy3d.model.Mirror) Sensor(org.concord.energy3d.model.Sensor)

Example 14 with Window

use of org.concord.energy3d.model.Window in project energy3d by concord-consortium.

the class EnergyAngularAnalysis method updateGraph.

@Override
public void updateGraph() {
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    if (selectedPart instanceof Foundation) {
        if (graph instanceof BuildingEnergyAngularGraph) {
            final Foundation selectedBuilding = (Foundation) selectedPart;
            final double window = selectedBuilding.getPassiveSolarToday();
            final double solarPanel = selectedBuilding.getPhotovoltaicToday();
            final double heater = selectedBuilding.getHeatingToday();
            final double ac = selectedBuilding.getCoolingToday();
            final double net = selectedBuilding.getTotalEnergyToday();
            graph.addData("Windows", window);
            graph.addData("Solar Panels", solarPanel);
            graph.addData("Heater", heater);
            graph.addData("AC", ac);
            graph.addData("Net", net);
        } else {
            graph.addData("Solar", selectedPart.getSolarPotentialToday());
        }
    } else if (selectedPart instanceof Window) {
        final Window window = (Window) selectedPart;
        final double solar = selectedPart.getSolarPotentialToday() * window.getSolarHeatGainCoefficient();
        graph.addData("Solar", solar);
        final double[] loss = selectedPart.getHeatLoss();
        double sum = 0;
        for (final double x : loss) {
            sum += x;
        }
        graph.addData("Heat Gain", -sum);
    } else if (selectedPart instanceof Wall || selectedPart instanceof Roof || selectedPart instanceof Door) {
        final double[] loss = selectedPart.getHeatLoss();
        double sum = 0;
        for (final double x : loss) {
            sum += x;
        }
        graph.addData("Heat Gain", -sum);
    } else if (selectedPart instanceof SolarPanel) {
        graph.addData("Solar", ((SolarPanel) selectedPart).getYieldToday());
    } else if (selectedPart instanceof Rack) {
        graph.addData("Solar", ((Rack) selectedPart).getYieldToday());
    }
    graph.repaint();
}
Also used : Window(org.concord.energy3d.model.Window) Rack(org.concord.energy3d.model.Rack) Roof(org.concord.energy3d.model.Roof) Wall(org.concord.energy3d.model.Wall) SolarPanel(org.concord.energy3d.model.SolarPanel) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) Door(org.concord.energy3d.model.Door)

Example 15 with Window

use of org.concord.energy3d.model.Window in project energy3d by concord-consortium.

the class GroupAnnualAnalysis method updateGraph.

@Override
public void updateGraph() {
    for (final HousePart p : selectedParts) {
        final String customText = p.getLabelCustomText();
        if (p instanceof Window) {
            final Window window = (Window) p;
            final double solar = p.getSolarPotentialToday() * window.getSolarHeatGainCoefficient();
            graph.addData("Solar " + p.getId(), solar);
            final double[] loss = p.getHeatLoss();
            double sum = 0;
            for (final double x : loss) {
                sum += x;
            }
            graph.addData("Heat Gain " + p.getId(), -sum);
        } else if (p instanceof Wall || p instanceof Roof) {
            final double[] loss = p.getHeatLoss();
            double sum = 0;
            for (final double x : loss) {
                sum += x;
            }
            graph.addData("Heat Gain " + p.getId(), -sum);
        } else if (p instanceof SolarPanel) {
            if (customText != null) {
                graph.addData("Solar " + p.getId() + graph.getDataNameDelimiter() + customText, ((SolarPanel) p).getYieldToday());
            } else {
                graph.addData("Solar " + p.getId(), ((SolarPanel) p).getYieldToday());
            }
        } else if (p instanceof Rack) {
            if (customText != null) {
                graph.addData("Solar " + p.getId() + graph.getDataNameDelimiter() + customText, ((Rack) p).getYieldToday());
            } else {
                graph.addData("Solar " + p.getId(), ((Rack) p).getYieldToday());
            }
        } else if (p instanceof Mirror) {
            final Mirror mirror = (Mirror) p;
            final double solar = mirror.getSolarPotentialToday() * mirror.getSystemEfficiency();
            if (customText != null) {
                graph.addData("Solar " + p.getId() + graph.getDataNameDelimiter() + customText, solar);
            } else {
                graph.addData("Solar " + p.getId(), solar);
            }
        } else if (p instanceof ParabolicTrough) {
            final ParabolicTrough trough = (ParabolicTrough) p;
            final double solar = trough.getSolarPotentialToday() * trough.getSystemEfficiency();
            if (customText != null) {
                graph.addData("Solar " + p.getId() + graph.getDataNameDelimiter() + customText, solar);
            } else {
                graph.addData("Solar " + p.getId(), solar);
            }
        } else if (p instanceof ParabolicDish) {
            final ParabolicDish dish = (ParabolicDish) p;
            final double solar = dish.getSolarPotentialToday() * dish.getSystemEfficiency();
            if (customText != null) {
                graph.addData("Solar " + p.getId() + graph.getDataNameDelimiter() + customText, solar);
            } else {
                graph.addData("Solar " + p.getId(), solar);
            }
        } else if (p instanceof FresnelReflector) {
            final FresnelReflector reflector = (FresnelReflector) p;
            final double solar = reflector.getSolarPotentialToday() * reflector.getSystemEfficiency();
            if (customText != null) {
                graph.addData("Solar " + p.getId() + graph.getDataNameDelimiter() + customText, solar);
            } else {
                graph.addData("Solar " + p.getId(), solar);
            }
        } else if (p instanceof Foundation) {
            final boolean mean = group.getType().endsWith("(Mean)");
            final Foundation foundation = (Foundation) p;
            switch(foundation.getProjectType()) {
                case Foundation.TYPE_PV_PROJECT:
                    double pv = foundation.getPhotovoltaicToday();
                    if (mean) {
                        pv /= foundation.getNumberOfSolarPanels();
                        if (customText != null) {
                            graph.addData("PV " + p.getId() + graph.getDataNameDelimiter() + customText + " mean", pv);
                        } else {
                            graph.addData("PV " + p.getId() + " mean", pv);
                        }
                    } else {
                        if (customText != null) {
                            graph.addData("PV " + p.getId() + graph.getDataNameDelimiter() + customText, pv);
                        } else {
                            graph.addData("PV " + p.getId(), pv);
                        }
                    }
                    break;
                case Foundation.TYPE_CSP_PROJECT:
                    double csp = foundation.getCspToday();
                    if (mean) {
                        csp /= foundation.countParts(new Class[] { Mirror.class, ParabolicTrough.class, ParabolicDish.class });
                        if (customText != null) {
                            graph.addData("CSP " + p.getId() + graph.getDataNameDelimiter() + customText + " mean", csp);
                        } else {
                            graph.addData("CSP " + p.getId() + " mean", csp);
                        }
                    } else {
                        if (customText != null) {
                            graph.addData("CSP " + p.getId() + graph.getDataNameDelimiter() + customText, csp);
                        } else {
                            graph.addData("CSP " + p.getId(), csp);
                        }
                    }
                    break;
                case Foundation.TYPE_BUILDING:
                    final double totalEnergy = foundation.getTotalEnergyToday();
                    graph.addData("Building " + p.getId(), totalEnergy);
                    break;
            }
        }
    }
    graph.repaint();
}
Also used : Window(org.concord.energy3d.model.Window) ParabolicTrough(org.concord.energy3d.model.ParabolicTrough) FresnelReflector(org.concord.energy3d.model.FresnelReflector) Wall(org.concord.energy3d.model.Wall) ParabolicDish(org.concord.energy3d.model.ParabolicDish) Rack(org.concord.energy3d.model.Rack) Roof(org.concord.energy3d.model.Roof) SolarPanel(org.concord.energy3d.model.SolarPanel) Foundation(org.concord.energy3d.model.Foundation) Mirror(org.concord.energy3d.model.Mirror) HousePart(org.concord.energy3d.model.HousePart)

Aggregations

Window (org.concord.energy3d.model.Window)57 HousePart (org.concord.energy3d.model.HousePart)43 Foundation (org.concord.energy3d.model.Foundation)39 Roof (org.concord.energy3d.model.Roof)28 Wall (org.concord.energy3d.model.Wall)28 Rack (org.concord.energy3d.model.Rack)27 Door (org.concord.energy3d.model.Door)25 SolarPanel (org.concord.energy3d.model.SolarPanel)25 Mirror (org.concord.energy3d.model.Mirror)16 ArrayList (java.util.ArrayList)15 FresnelReflector (org.concord.energy3d.model.FresnelReflector)14 ParabolicTrough (org.concord.energy3d.model.ParabolicTrough)14 ParabolicDish (org.concord.energy3d.model.ParabolicDish)13 Tree (org.concord.energy3d.model.Tree)12 List (java.util.List)10 Floor (org.concord.energy3d.model.Floor)10 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)9 SolarCollector (org.concord.energy3d.model.SolarCollector)9 Human (org.concord.energy3d.model.Human)8 Vector3 (com.ardor3d.math.Vector3)7