Search in sources :

Example 16 with Tree

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

the class Scene method add.

private void add(final HousePart part) {
    System.out.println("Adding: " + part);
    if (part instanceof Tree || part instanceof Human) {
        notReceivingShadowRoot.attachChild(part.getRoot());
    } else {
        originalHouseRoot.attachChild(part.getRoot());
    }
    parts.add(part);
    for (final HousePart child : part.getChildren()) {
        add(child);
    }
}
Also used : Human(org.concord.energy3d.model.Human) Tree(org.concord.energy3d.model.Tree) HousePart(org.concord.energy3d.model.HousePart)

Example 17 with Tree

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

the class Scene method importFile.

public void importFile(final URL url) throws Exception {
    if (PrintController.getInstance().isPrintPreview()) {
        MainPanel.getInstance().getPreviewButton().setSelected(false);
        while (!PrintController.getInstance().isFinished()) {
            Thread.yield();
        }
    }
    if (url != null) {
        long max = -1;
        for (final HousePart x : Scene.getInstance().parts) {
            if (x.getId() > max) {
                max = x.getId();
            }
        }
        if (max < 0) {
            max = 0;
        }
        System.out.print("Opening..." + url + "...");
        final ObjectInputStream in = new ObjectInputStream(url.openStream());
        final Scene instance = (Scene) in.readObject();
        in.close();
        // instance.cleanup();
        instance.upgradeSceneToNewVersion();
        if (url != null) {
            final AddMultiplePartsCommand cmd = new AddMultiplePartsCommand(new ArrayList<HousePart>(instance.getParts()), url);
            double cx = 0;
            double cy = 0;
            int count = 0;
            for (final HousePart p : instance.getParts()) {
                p.setId(max + p.getId());
                Scene.getInstance().parts.add(p);
                originalHouseRoot.attachChild(p.getRoot());
                if (p instanceof Foundation || p instanceof Tree || p instanceof Human) {
                    final Vector3 c = p.getAbsCenter();
                    cx += c.getX();
                    cy += c.getY();
                    count++;
                }
            }
            final Vector3 position = SceneManager.getInstance().getPickedLocationOnLand();
            if (position != null) {
                final Vector3 shift = position.subtractLocal(count == 0 ? new Vector3(0, 0, 0) : new Vector3(cx / count, cy / count, 0));
                for (final HousePart p : instance.getParts()) {
                    if (p instanceof Foundation || p instanceof Tree || p instanceof Human) {
                        for (int i = 0; i < p.getPoints().size(); i++) {
                            p.getPoints().get(i).addLocal(shift);
                        }
                    }
                }
            }
            redrawAll = true;
            SceneManager.getInstance().getUndoManager().addEdit(cmd);
        }
        root.updateWorldBound(true);
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                MainPanel.getInstance().getEnergyButton().setSelected(false);
            }
        });
        setEdited(true);
    } else {
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "URL doesn't exist.", "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : Human(org.concord.energy3d.model.Human) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) AddMultiplePartsCommand(org.concord.energy3d.undo.AddMultiplePartsCommand) HousePart(org.concord.energy3d.model.HousePart) ObjectInputStream(java.io.ObjectInputStream)

Example 18 with Tree

use of org.concord.energy3d.model.Tree 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)

Example 19 with Tree

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

the class PvProjectCost method showPieChart.

@Override
void showPieChart() {
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    final Foundation selectedFoundation;
    if (selectedPart == null || selectedPart instanceof Tree || selectedPart instanceof Human) {
        selectedFoundation = null;
    } else if (selectedPart instanceof Foundation) {
        selectedFoundation = (Foundation) selectedPart;
    } else {
        selectedFoundation = selectedPart.getTopContainer();
        selectedPart.setEditPointsVisible(false);
        SceneManager.getInstance().setSelectedPart(selectedFoundation);
    }
    String details = "";
    int count = 0;
    for (final HousePart p : Scene.getInstance().getParts()) {
        if (p instanceof Foundation) {
            count++;
            if (selectedFoundation == null) {
                final Foundation foundation = (Foundation) p;
                details += "$" + (int) getCostByFoundation(foundation) + " (" + foundation.getId() + ") | ";
            }
        }
    }
    if (selectedFoundation == null) {
        if (count > 0) {
            details = details.substring(0, details.length() - 2);
        }
    }
    double landSum = 0;
    double solarPanelSum = 0;
    String info;
    if (selectedFoundation != null) {
        info = "Zone #" + selectedFoundation.getId();
        landSum = getPartCost(selectedFoundation);
        for (final HousePart p : Scene.getInstance().getParts()) {
            if (p.getTopContainer() == selectedFoundation) {
                if (p instanceof SolarPanel || p instanceof Rack) {
                    solarPanelSum += getPartCost(p);
                }
            }
        }
    } else {
        info = count + " zones";
        for (final HousePart p : Scene.getInstance().getParts()) {
            if (p instanceof Foundation) {
                landSum += getPartCost(p);
            } else if (p instanceof SolarPanel || p instanceof Rack) {
                solarPanelSum += getPartCost(p);
            }
        }
    }
    final double[] data = new double[] { landSum, solarPanelSum };
    final String[] legends = new String[] { "Land (" + Scene.getInstance().getPvCustomPrice().getLifespan() + " years)", "Solar Panels" };
    // show them in a popup window
    final PieChart pie = new PieChart(data, PvProjectCostGraph.colors, legends, "$", info, count > 1 ? details : null, true);
    pie.setBackground(Color.WHITE);
    pie.setBorder(BorderFactory.createEtchedBorder());
    final JDialog dialog = new JDialog(MainFrame.getInstance(), "Project Costs by Category", true);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.getContentPane().add(pie, BorderLayout.CENTER);
    final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JButton buttonClose = new JButton("Close");
    buttonClose.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            dialog.dispose();
        }
    });
    buttonPanel.add(buttonClose);
    dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    dialog.pack();
    dialog.setLocationRelativeTo(MainFrame.getInstance());
    dialog.setVisible(true);
}
Also used : Human(org.concord.energy3d.model.Human) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Rack(org.concord.energy3d.model.Rack) ActionListener(java.awt.event.ActionListener) SolarPanel(org.concord.energy3d.model.SolarPanel) Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) JDialog(javax.swing.JDialog)

Example 20 with Tree

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

the class HeatLoad method computeEnergyToday.

public void computeEnergyToday(final Calendar today) {
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.HOUR_OF_DAY, 0);
    if (EnergyPanel.getInstance().getCityComboBox().getSelectedItem().equals("")) {
        return;
    }
    final int timeStep = Scene.getInstance().getTimeStep();
    final double[] outsideTemperatureRange = Weather.computeOutsideTemperature(today, (String) EnergyPanel.getInstance().getCityComboBox().getSelectedItem());
    // System.out.println(today.get(Calendar.DAY_OF_YEAR) + ", " + outsideTemperatureRange[0] + ", " + outsideTemperatureRange[1]);
    int iMinute = 0;
    for (int minute = 0; minute < SolarRadiation.MINUTES_OF_DAY; minute += timeStep) {
        iMinute = minute / timeStep;
        final double outsideTemperature = Weather.getInstance().getOutsideTemperatureAtMinute(outsideTemperatureRange[1], outsideTemperatureRange[0], minute);
        final double groundTemperature = Scene.getInstance().getGround().getTemperatureMinuteOfDay(today.get(Calendar.DAY_OF_YEAR), minute, 0.5 * (outsideTemperatureRange[1] - outsideTemperatureRange[0]));
        for (final HousePart part : Scene.getInstance().getParts()) {
            if (part instanceof Human || part instanceof Tree || part instanceof Floor || (part instanceof SolarCollector && !(part instanceof Sensor))) {
                continue;
            }
            final double insideTemperature = (part instanceof Foundation ? (Foundation) part : part.getTopContainer()).getThermostat().getTemperature(today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY, minute / 60);
            final float absorption = part instanceof Window ? 0 : 1 - part.getAlbedo();
            if (part instanceof Roof) {
                // need to compute piece by piece for a roof because sun affects outside temperature of roof part
                final Roof roof = (Roof) part;
                for (final Spatial child : roof.getRoofPartsRoot().getChildren()) {
                    if (child.getSceneHints().getCullHint() != CullHint.Always) {
                        final Mesh mesh = (Mesh) ((Node) child).getChild(6);
                        final double[] solarPotential = SolarRadiation.getInstance().getSolarPotential(mesh);
                        final double solarHeat = solarPotential != null ? solarPotential[iMinute] * absorption / roof.getVolumetricHeatCapacity() : 0;
                        final double deltaT = insideTemperature - (outsideTemperature + solarHeat);
                        if (part.isDrawCompleted()) {
                            final double uValue = getUValue(part);
                            if (Util.isZero(uValue)) {
                                continue;
                            }
                            double heatloss = roof.getAreaWithoutOverhang(mesh) * uValue * deltaT / 1000.0 / 60 * timeStep;
                            // if the lowest outside temperature is high enough, there is no need to turn on the heater hence no heat loss
                            if (heatloss > 0 && outsideTemperatureRange[0] >= LOWEST_TEMPERATURE_OF_WARM_DAY) {
                                heatloss = 0;
                            }
                            roof.getHeatLoss()[iMinute] += heatloss;
                            final double[] heatLossArray = SolarRadiation.getInstance().getHeatLoss(mesh);
                            if (heatLossArray != null) {
                                heatLossArray[iMinute] += heatloss;
                            }
                        }
                    }
                }
            } else if (part instanceof Foundation) {
                final Foundation foundation = (Foundation) part;
                final double deltaT = insideTemperature - groundTemperature;
                if (foundation.isDrawCompleted()) {
                    final double uValue = getUValue(part);
                    if (Util.isZero(uValue)) {
                        continue;
                    }
                    final Building building = new Building(foundation);
                    double area;
                    if (building.isWallComplete()) {
                        building.calculate();
                        area = building.getArea();
                    } else {
                        area = foundation.getArea();
                    }
                    final double heatloss = area * uValue * deltaT / 1000.0 / 60 * timeStep;
                    // if (iMinute % 4 == 0) System.out.println((int) (iMinute / 4) + "=" + outsideTemperature + ", " + groundTemperature + ", " + deltaT + ", " + heatloss);
                    foundation.getHeatLoss()[iMinute] += heatloss;
                }
            } else {
                double deltaT = insideTemperature - outsideTemperature;
                if (part instanceof Thermal) {
                    // direct solar heating raises the outside temperature
                    deltaT -= part.getSolarPotential()[iMinute] * absorption / ((Thermal) part).getVolumetricHeatCapacity();
                }
                if (part.isDrawCompleted()) {
                    final double uValue = getUValue(part);
                    if (Util.isZero(uValue)) {
                        continue;
                    }
                    double heatloss = part.getArea() * uValue * deltaT / 1000.0 / 60 * timeStep;
                    // if outside is warm enough, there is no need to turn on the heater hence no heat loss
                    if (heatloss > 0 && outsideTemperatureRange[0] >= LOWEST_TEMPERATURE_OF_WARM_DAY) {
                        heatloss = 0;
                    }
                    part.getHeatLoss()[iMinute] += heatloss;
                }
            }
        }
    }
}
Also used : Human(org.concord.energy3d.model.Human) Window(org.concord.energy3d.model.Window) Building(org.concord.energy3d.model.Building) Floor(org.concord.energy3d.model.Floor) Mesh(com.ardor3d.scenegraph.Mesh) CullHint(com.ardor3d.scenegraph.hint.CullHint) Roof(org.concord.energy3d.model.Roof) Spatial(com.ardor3d.scenegraph.Spatial) SolarCollector(org.concord.energy3d.model.SolarCollector) Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) Sensor(org.concord.energy3d.model.Sensor) Thermal(org.concord.energy3d.model.Thermal)

Aggregations

Tree (org.concord.energy3d.model.Tree)28 HousePart (org.concord.energy3d.model.HousePart)26 Foundation (org.concord.energy3d.model.Foundation)24 Human (org.concord.energy3d.model.Human)19 Window (org.concord.energy3d.model.Window)12 Rack (org.concord.energy3d.model.Rack)10 Roof (org.concord.energy3d.model.Roof)9 SolarPanel (org.concord.energy3d.model.SolarPanel)9 Wall (org.concord.energy3d.model.Wall)8 Vector3 (com.ardor3d.math.Vector3)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 JDialog (javax.swing.JDialog)7 Door (org.concord.energy3d.model.Door)7 Floor (org.concord.energy3d.model.Floor)7 SolarCollector (org.concord.energy3d.model.SolarCollector)7 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)6 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 JPanel (javax.swing.JPanel)6