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