Search in sources :

Example 11 with Human

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

the class BuildingCost method getCostByFoundation.

@Override
public double getCostByFoundation(final Foundation foundation) {
    if (foundation == null || foundation.getProjectType() != Foundation.TYPE_BUILDING) {
        return 0;
    }
    double sum = 0;
    int buildingCount = 0;
    for (final HousePart p : Scene.getInstance().getParts()) {
        if (p instanceof Foundation) {
            buildingCount++;
        }
    }
    if (buildingCount == 1) {
        for (final HousePart p : Scene.getInstance().getParts()) {
            // if there is only one building, trees are included in its cost
            if (!p.getLockEdit() && !(p instanceof Human)) {
                sum += getPartCost(p);
            }
        }
    } else {
        sum = getPartCost(foundation);
        for (final HousePart p : Scene.getInstance().getParts()) {
            if (p.getTopContainer() == foundation) {
                sum += getPartCost(p);
            }
        }
    }
    return sum;
}
Also used : Human(org.concord.energy3d.model.Human) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart)

Example 12 with Human

use of org.concord.energy3d.model.Human 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 13 with Human

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

the class Scene method newFile.

private static void newFile(final double xLength, final double yLength) {
    try {
        open(null);
        first = false;
    } catch (final Exception e) {
        e.printStackTrace();
    }
    SceneManager.getTaskManager().update(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            instance.add(new Human(Human.JACK, 1));
            final Foundation f = new Foundation(xLength, yLength);
            f.setColor(instance.getFoundationColor());
            instance.add(f, true);
            return null;
        }
    });
}
Also used : Human(org.concord.energy3d.model.Human) Foundation(org.concord.energy3d.model.Foundation) IOException(java.io.IOException)

Example 14 with Human

use of org.concord.energy3d.model.Human 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 15 with Human

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

Aggregations

Human (org.concord.energy3d.model.Human)22 HousePart (org.concord.energy3d.model.HousePart)20 Foundation (org.concord.energy3d.model.Foundation)19 Tree (org.concord.energy3d.model.Tree)19 Window (org.concord.energy3d.model.Window)8 Vector3 (com.ardor3d.math.Vector3)6 Rack (org.concord.energy3d.model.Rack)6 SolarCollector (org.concord.energy3d.model.SolarCollector)6 SolarPanel (org.concord.energy3d.model.SolarPanel)6 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)5 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 JButton (javax.swing.JButton)5 Mirror (org.concord.energy3d.model.Mirror)5 Roof (org.concord.energy3d.model.Roof)5 Wall (org.concord.energy3d.model.Wall)5 FlowLayout (java.awt.FlowLayout)4 JDialog (javax.swing.JDialog)4