Search in sources :

Example 96 with Foundation

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

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

the class Scene method removeAllParabolicTroughs.

public void removeAllParabolicTroughs() {
    final ArrayList<HousePart> troughs = new ArrayList<HousePart>();
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    if (selectedPart != null) {
        final Foundation foundation = selectedPart instanceof Foundation ? (Foundation) selectedPart : selectedPart.getTopContainer();
        for (final HousePart part : parts) {
            if (part instanceof ParabolicTrough && part.getTopContainer() == foundation) {
                troughs.add(part);
            }
        }
    } else {
        for (final HousePart part : parts) {
            if (part instanceof ParabolicTrough) {
                troughs.add(part);
            }
        }
    }
    if (troughs.isEmpty()) {
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "There is no parabolic trough to remove.", "No Parabolic Trough", JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "Do you really want to remove all " + troughs.size() + " parabolic troughs" + (selectedPart != null ? " on the selected foundation" : "") + "?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
        return;
    }
    final RemoveMultiplePartsCommand c = new RemoveMultiplePartsCommand(troughs);
    for (final HousePart part : troughs) {
        remove(part, false);
    }
    redrawAll();
    SceneManager.getInstance().getUndoManager().addEdit(c);
    edited = true;
}
Also used : ParabolicTrough(org.concord.energy3d.model.ParabolicTrough) ArrayList(java.util.ArrayList) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) RemoveMultiplePartsCommand(org.concord.energy3d.undo.RemoveMultiplePartsCommand)

Example 98 with Foundation

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

the class Scene method countNodes.

public int countNodes() {
    int count = 0;
    final List<Foundation> foundations = getAllFoundations();
    for (final Foundation f : foundations) {
        if (f.getImportedNodes() != null) {
            count += f.getImportedNodes().size();
        }
    }
    return count;
}
Also used : Foundation(org.concord.energy3d.model.Foundation)

Example 99 with Foundation

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

the class Scene method removeAllSolarPanels.

public void removeAllSolarPanels(List<SolarPanel> panels) {
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    if (panels == null) {
        panels = new ArrayList<SolarPanel>();
        if (selectedPart != null) {
            if (selectedPart instanceof Rack) {
                for (final HousePart part : selectedPart.getChildren()) {
                    if (part instanceof SolarPanel) {
                        panels.add((SolarPanel) part);
                    }
                }
            } else {
                final Foundation foundation = selectedPart instanceof Foundation ? (Foundation) selectedPart : selectedPart.getTopContainer();
                for (final HousePart part : parts) {
                    if (part instanceof SolarPanel && part.getTopContainer() == foundation) {
                        panels.add((SolarPanel) part);
                    }
                }
            }
        } else {
            for (final HousePart part : parts) {
                if (part instanceof SolarPanel) {
                    panels.add((SolarPanel) part);
                }
            }
        }
    }
    if (panels.isEmpty()) {
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "There is no solar panel to remove.", "No Solar Panel", JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "Do you really want to remove all " + panels.size() + " solar panels" + (selectedPart != null ? " of the selected building" : "") + "?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
        return;
    }
    final RemoveMultiplePartsCommand c = new RemoveMultiplePartsCommand(new ArrayList<HousePart>(panels));
    for (final HousePart part : panels) {
        remove(part, false);
    }
    redrawAll();
    SceneManager.getInstance().getUndoManager().addEdit(c);
    edited = true;
}
Also used : Rack(org.concord.energy3d.model.Rack) SolarPanel(org.concord.energy3d.model.SolarPanel) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) RemoveMultiplePartsCommand(org.concord.energy3d.undo.RemoveMultiplePartsCommand)

Example 100 with Foundation

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

the class Scene method importCollada.

public void importCollada(final File file) throws Exception {
    boolean success = true;
    Vector3 position = SceneManager.getInstance().getPickedLocationOnLand();
    if (position == null) {
        position = new Vector3();
    }
    final Foundation foundation = new Foundation(100, 100);
    for (final Vector3 p : foundation.getPoints()) {
        p.addLocal(position);
    }
    Scene.getInstance().add(foundation, false);
    try {
        final Node n = foundation.importCollada(file.toURI().toURL(), position);
        if (n != null) {
        // TODO: automatically center the model at the center
        }
    } catch (final Throwable t) {
        BugReporter.report(t);
        success = false;
    }
    if (success) {
        SceneManager.getInstance().getUndoManager().addEdit(new AddNodeCommand(foundation));
    }
    setEdited(true);
}
Also used : AddNodeCommand(org.concord.energy3d.undo.AddNodeCommand) Node(com.ardor3d.scenegraph.Node) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Foundation(org.concord.energy3d.model.Foundation)

Aggregations

Foundation (org.concord.energy3d.model.Foundation)174 HousePart (org.concord.energy3d.model.HousePart)153 Rack (org.concord.energy3d.model.Rack)47 SolarPanel (org.concord.energy3d.model.SolarPanel)45 Window (org.concord.energy3d.model.Window)39 ActionEvent (java.awt.event.ActionEvent)38 ActionListener (java.awt.event.ActionListener)38 Roof (org.concord.energy3d.model.Roof)38 Wall (org.concord.energy3d.model.Wall)37 ArrayList (java.util.ArrayList)35 JDialog (javax.swing.JDialog)35 JMenuItem (javax.swing.JMenuItem)33 Mirror (org.concord.energy3d.model.Mirror)32 FresnelReflector (org.concord.energy3d.model.FresnelReflector)27 Door (org.concord.energy3d.model.Door)24 ParabolicTrough (org.concord.energy3d.model.ParabolicTrough)24 Tree (org.concord.energy3d.model.Tree)24 Vector3 (com.ardor3d.math.Vector3)22 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)22 ParabolicDish (org.concord.energy3d.model.ParabolicDish)22