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