Search in sources :

Example 31 with Wall

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

the class Scene method remove.

public void remove(final HousePart part, final boolean redraw) {
    if (part == null) {
        return;
    }
    part.setGridsVisible(false);
    part.setLinePatternVisible(false);
    final HousePart container = part.getContainer();
    if (container != null) {
        container.getChildren().remove(part);
    }
    removeChildren(part);
    if (redraw) {
        if (part instanceof Wall || part instanceof Roof) {
            // potentially need to refresh the state of the walls and roofs?
            redrawAllWallsNow();
        }
    }
}
Also used : Roof(org.concord.energy3d.model.Roof) Wall(org.concord.energy3d.model.Wall) HousePart(org.concord.energy3d.model.HousePart)

Example 32 with Wall

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

the class Scene method cleanup.

private void cleanup() {
    // fix if roof and wall are not linked from each other
    for (final HousePart p : parts) {
        if (p instanceof Roof) {
            final Roof r = (Roof) p;
            final HousePart c = r.getContainer();
            if (c != null && !c.getChildren().contains(r)) {
                c.getChildren().add(r);
            }
        }
    }
    final ArrayList<HousePart> toBeRemoved = new ArrayList<HousePart>();
    for (final HousePart p : parts) {
        if (!p.isValid()) {
            // remove invalid parts
            toBeRemoved.add(p);
        } else if (p.getContainer() == null) {
            // remove orphan parts without a container
            if (p instanceof Wall || p instanceof Roof || p instanceof Window || p instanceof Door || p instanceof SolarCollector || p instanceof Floor) {
                toBeRemoved.add(p);
            }
        } else if (!parts.contains(p.getContainer())) {
            // remove parts whose container doesn't exist in the scene
            toBeRemoved.add(p);
        }
    }
    for (final HousePart p : toBeRemoved) {
        remove(p, false);
    }
    // remove walls that are at the same position
    toBeRemoved.clear();
    for (final HousePart p : parts) {
        if (p instanceof Wall) {
            // remove walls that are at the same position
            if (((Wall) p).isAtSamePlaceAsAnotherPart()) {
                toBeRemoved.add(p);
            }
        }
    }
    for (final HousePart p : toBeRemoved) {
        remove(p, false);
    }
    // remove children with multiple parents
    toBeRemoved.clear();
    for (final HousePart p : parts) {
        for (final HousePart child : p.getChildren()) {
            if (child.getContainer() != p && !toBeRemoved.contains(child)) {
                toBeRemoved.add(child);
            }
        }
    }
    for (final HousePart p : toBeRemoved) {
        remove(p, false);
    }
    // remove from remaining parents
    for (final HousePart p : parts) {
        for (final HousePart r : toBeRemoved) {
            p.getChildren().remove(r);
        }
    }
    // remove all the children that are not in parts
    toBeRemoved.clear();
    for (final HousePart p : parts) {
        for (final HousePart child : p.getChildren()) {
            if (!parts.contains(child) && !toBeRemoved.contains(child)) {
                toBeRemoved.add(child);
            }
        }
    }
    for (final HousePart p : toBeRemoved) {
        remove(p, false);
    }
    // complete all non-completed parts
    for (final HousePart p : parts) {
        if (!p.isDrawCompleted()) {
            p.complete();
        }
    }
}
Also used : Window(org.concord.energy3d.model.Window) Floor(org.concord.energy3d.model.Floor) Roof(org.concord.energy3d.model.Roof) Wall(org.concord.energy3d.model.Wall) SolarCollector(org.concord.energy3d.model.SolarCollector) ArrayList(java.util.ArrayList) HousePart(org.concord.energy3d.model.HousePart) Door(org.concord.energy3d.model.Door)

Example 33 with Wall

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

the class Scene method showOutlineForAllWalls.

public void showOutlineForAllWalls(final boolean b) {
    for (final HousePart p : parts) {
        if (p instanceof Wall) {
            ((Wall) p).showOutline(b);
            p.draw();
        }
    }
    SceneManager.getInstance().refresh();
}
Also used : Wall(org.concord.energy3d.model.Wall) HousePart(org.concord.energy3d.model.HousePart)

Example 34 with Wall

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

the class SceneManager method deleteCurrentSelection.

public void deleteCurrentSelection() {
    if (selectedPart == null || selectedPart.getLockEdit()) {
        return;
    }
    if (selectedPart instanceof Foundation) {
        final Foundation foundation = (Foundation) selectedPart;
        if (!foundation.getChildren().isEmpty() && foundation.getSelectedMesh() == null) {
            if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "Deleting the platform also deletes the building on it. Are you sure?", "Confirmation", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
                return;
            }
        }
    }
    taskManager.update(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            if (selectedPart != null) {
                // sometimes selectedPart can be null after the callable is sent to the task manager
                if (selectedPart instanceof Foundation && ((Foundation) selectedPart).getSelectedMesh() != null) {
                    // a mesh is selected, instead of a part
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        f.deleteMesh(m);
                    }
                } else {
                    final RemovePartCommand c = new RemovePartCommand(selectedPart);
                    if (selectedPart instanceof Wall) {
                        // undo/redo a gable roof
                        final Roof roof = ((Wall) selectedPart).getRoof();
                        if (roof != null) {
                            final List<Map<Integer, List<Wall>>> gableInfo = new ArrayList<Map<Integer, List<Wall>>>();
                            if (roof.getGableEditPointToWallMap() != null) {
                                gableInfo.add(roof.getGableEditPointToWallMap());
                            }
                            c.setGableInfo(gableInfo);
                        }
                    } else if (selectedPart instanceof Foundation) {
                        // undo/redo all the gable roofs
                        final List<Roof> roofs = ((Foundation) selectedPart).getRoofs();
                        if (!roofs.isEmpty()) {
                            final List<Map<Integer, List<Wall>>> gableInfo = new ArrayList<Map<Integer, List<Wall>>>();
                            for (final Roof r : roofs) {
                                if (r.getGableEditPointToWallMap() != null) {
                                    gableInfo.add(r.getGableEditPointToWallMap());
                                }
                            }
                            c.setGableInfo(gableInfo);
                        }
                    }
                    undoManager.addEdit(c);
                    Scene.getInstance().remove(selectedPart, true);
                }
                if (selectedPart.getContainer() != null) {
                    // redraw its container since we are not calling the costly redrawAll any more
                    selectedPart.getContainer().draw();
                }
                selectedPart = null;
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        MainPanel.getInstance().getEnergyButton().setSelected(false);
                    }
                });
            }
            return null;
        }
    });
}
Also used : Wall(org.concord.energy3d.model.Wall) RemovePartCommand(org.concord.energy3d.undo.RemovePartCommand) ArrayList(java.util.ArrayList) Mesh(com.ardor3d.scenegraph.Mesh) IOException(java.io.IOException) 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) Foundation(org.concord.energy3d.model.Foundation) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 35 with Wall

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

the class SolarRadiation method computeToday.

private void computeToday() {
    // save current calendar for restoring at the end of this calculation
    final Calendar today = (Calendar) Heliodon.getInstance().getCalendar().clone();
    hourOfDay = today.get(Calendar.HOUR_OF_DAY);
    minuteOfHour = today.get(Calendar.MINUTE);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.HOUR_OF_DAY, 0);
    final String city = (String) EnergyPanel.getInstance().getCityComboBox().getSelectedItem();
    dailyAirTemperatures = Weather.computeOutsideTemperature(today, city);
    final int timeStep = Scene.getInstance().getTimeStep();
    final ReadOnlyVector3[] sunLocations = new ReadOnlyVector3[SolarRadiation.MINUTES_OF_DAY / timeStep];
    int totalSteps = 0;
    for (int minute = 0; minute < SolarRadiation.MINUTES_OF_DAY; minute += timeStep) {
        final ReadOnlyVector3 sunLocation = Heliodon.getInstance().computeSunLocation(today).normalizeLocal();
        sunLocations[minute / timeStep] = sunLocation;
        if (sunLocation.getZ() > 0) {
            totalSteps++;
        }
        today.add(Calendar.MINUTE, timeStep);
    }
    totalSteps -= 2;
    final double dayLength = totalSteps * timeStep / 60.0;
    int step = 1;
    setupImportedMeshes();
    // for (int minute = MINUTES_OF_DAY / 2; minute < MINUTES_OF_DAY / 2 + timeStep; minute += timeStep) { // test for 12 pm for comparison with shadow
    for (int minute = 0; minute < MINUTES_OF_DAY; minute += timeStep) {
        final ReadOnlyVector3 sunLocation = sunLocations[minute / timeStep];
        if (sunLocation.getZ() > 0) {
            final ReadOnlyVector3 directionTowardSun = sunLocation.normalize(null);
            calculatePeakRadiation(directionTowardSun, dayLength);
            for (final HousePart part : Scene.getInstance().getParts()) {
                if (part.isDrawCompleted()) {
                    if (part instanceof Window) {
                        computeOnMesh(minute, directionTowardSun, part, part.getRadiationMesh(), (Mesh) part.getRadiationCollisionSpatial(), part.getNormal());
                    } else if (part instanceof Wall) {
                        if (((Wall) part).getType() == Wall.SOLID_WALL) {
                            computeOnMesh(minute, directionTowardSun, part, part.getRadiationMesh(), (Mesh) part.getRadiationCollisionSpatial(), part.getNormal());
                        }
                    } else if (part instanceof Door || part instanceof Floor) {
                        computeOnMesh(minute, directionTowardSun, part, part.getRadiationMesh(), (Mesh) part.getRadiationCollisionSpatial(), part.getNormal());
                    } else if (part instanceof Foundation) {
                        final Foundation foundation = (Foundation) part;
                        for (int i = 0; i < 5; i++) {
                            final Mesh radiationMesh = foundation.getRadiationMesh(i);
                            final ReadOnlyVector3 normal = i == 0 ? part.getNormal() : ((UserData) radiationMesh.getUserData()).getNormal();
                            computeOnMesh(minute, directionTowardSun, part, radiationMesh, foundation.getRadiationCollisionSpatial(i), normal);
                        }
                        if (!Scene.getInstance().getOnlySolarComponentsInSolarMap()) {
                            final List<Node> importedNodes = foundation.getImportedNodes();
                            if (importedNodes != null) {
                                for (final Node node : importedNodes) {
                                    for (final Spatial s : node.getChildren()) {
                                        final Mesh m = (Mesh) s;
                                        computeOnImportedMesh(minute, directionTowardSun, foundation, m);
                                    }
                                }
                            }
                        }
                    } else if (part instanceof Roof) {
                        for (final Spatial roofPart : ((Roof) part).getRoofPartsRoot().getChildren()) {
                            if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
                                final ReadOnlyVector3 faceDirection = (ReadOnlyVector3) roofPart.getUserData();
                                final Mesh mesh = (Mesh) ((Node) roofPart).getChild(6);
                                computeOnMesh(minute, directionTowardSun, part, mesh, mesh, faceDirection);
                            }
                        }
                    } else if (part instanceof SolarPanel) {
                        computeOnSolarPanel(minute, directionTowardSun, (SolarPanel) part);
                    } else if (part instanceof Rack) {
                        computeOnRack(minute, directionTowardSun, (Rack) part);
                    } else if (part instanceof Mirror) {
                        computeOnMirror(minute, directionTowardSun, (Mirror) part);
                    } else if (part instanceof FresnelReflector) {
                        computeOnFresnelReflector(minute, directionTowardSun, (FresnelReflector) part);
                    } else if (part instanceof ParabolicTrough) {
                        computeOnParabolicTrough(minute, directionTowardSun, (ParabolicTrough) part);
                    } else if (part instanceof ParabolicDish) {
                        computeOnParabolicDish(minute, directionTowardSun, (ParabolicDish) part);
                    } else if (part instanceof Sensor) {
                        computeOnSensor(minute, directionTowardSun, (Sensor) part);
                    }
                }
            }
            computeOnLand(directionTowardSun);
            EnergyPanel.getInstance().progress((int) Math.round(100.0 * step / totalSteps));
            step++;
        }
    }
    maxValue = Math.round((MINUTES_OF_DAY / timeStep + 1.0) * (1 - 0.01 * Scene.getInstance().getSolarHeatMapColorContrast()));
    // If tracking the sun, the heliodon's calendar has been changed. Restore the time now.
    resetTrackables();
}
Also used : ParabolicTrough(org.concord.energy3d.model.ParabolicTrough) Wall(org.concord.energy3d.model.Wall) UserData(org.concord.energy3d.model.UserData) Node(com.ardor3d.scenegraph.Node) Rack(org.concord.energy3d.model.Rack) Roof(org.concord.energy3d.model.Roof) Foundation(org.concord.energy3d.model.Foundation) List(java.util.List) ArrayList(java.util.ArrayList) HousePart(org.concord.energy3d.model.HousePart) Window(org.concord.energy3d.model.Window) Floor(org.concord.energy3d.model.Floor) FresnelReflector(org.concord.energy3d.model.FresnelReflector) Calendar(java.util.Calendar) Mesh(com.ardor3d.scenegraph.Mesh) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point) Door(org.concord.energy3d.model.Door) ParabolicDish(org.concord.energy3d.model.ParabolicDish) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) SolarPanel(org.concord.energy3d.model.SolarPanel) Mirror(org.concord.energy3d.model.Mirror) Sensor(org.concord.energy3d.model.Sensor)

Aggregations

Wall (org.concord.energy3d.model.Wall)57 HousePart (org.concord.energy3d.model.HousePart)45 Foundation (org.concord.energy3d.model.Foundation)37 Roof (org.concord.energy3d.model.Roof)31 Window (org.concord.energy3d.model.Window)28 Door (org.concord.energy3d.model.Door)25 Rack (org.concord.energy3d.model.Rack)23 SolarPanel (org.concord.energy3d.model.SolarPanel)23 ArrayList (java.util.ArrayList)16 Mirror (org.concord.energy3d.model.Mirror)14 FresnelReflector (org.concord.energy3d.model.FresnelReflector)12 Floor (org.concord.energy3d.model.Floor)11 List (java.util.List)10 ParabolicDish (org.concord.energy3d.model.ParabolicDish)10 ParabolicTrough (org.concord.energy3d.model.ParabolicTrough)10 ActionEvent (java.awt.event.ActionEvent)9 ActionListener (java.awt.event.ActionListener)9 Tree (org.concord.energy3d.model.Tree)8 JMenuItem (javax.swing.JMenuItem)7 JPanel (javax.swing.JPanel)7