use of org.concord.energy3d.model.UserData in project energy3d by concord-consortium.
the class Util method reverseFace.
public static void reverseFace(final Mesh m) {
if (m == null) {
return;
}
final UserData u = (UserData) m.getUserData();
u.setNormal(u.getNormal().negate(null));
if (u.getRotatedNormal() != null) {
u.setRotatedNormal(u.getRotatedNormal().negate(null));
}
}
use of org.concord.energy3d.model.UserData in project energy3d by concord-consortium.
the class DeleteMeshCommand method undo.
@Override
public void undo() throws CannotUndoException {
super.undo();
parent.attachChild(mesh);
foundation.draw();
final int meshIndex = ((UserData) mesh.getUserData()).getMeshIndex();
final NodeState ns = foundation.getNodeState(parent);
ns.getDeletedMeshes().remove(Integer.valueOf(meshIndex));
if (deletedParts != null) {
for (final HousePart p : deletedParts) {
Scene.getInstance().add(p, true);
}
}
if (SceneManager.getInstance().getSolarHeatMap()) {
EnergyPanel.getInstance().updateRadiationHeatMap();
}
}
use of org.concord.energy3d.model.UserData in project energy3d by concord-consortium.
the class Scene method pasteToPickedLocationOnMesh.
public void pasteToPickedLocationOnMesh(final Mesh mesh) {
EnergyPanel.getInstance().updateRadiationHeatMap();
if (copyBuffer == null) {
return;
}
if (copyBuffer instanceof Foundation) {
return;
}
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Foundation)) {
return;
}
final HousePart c = copyBuffer.copy(false);
if (c == null) {
return;
}
Vector3 position = SceneManager.getInstance().getPickedLocationOnMesh(mesh);
if (position == null) {
return;
}
position = c.toRelative(position.subtractLocal(c.getContainer().getAbsPoint(0)));
final Vector3 center = c.toRelative(c.getAbsCenter().subtractLocal(c.getContainer().getAbsPoint(0)));
position = position.subtractLocal(center);
final int n = c.getPoints().size();
for (int i = 0; i < n; i++) {
final Vector3 v = c.getPoints().get(i);
v.addLocal(position);
}
if (copyBuffer instanceof Rack) {
final Rack rack = (Rack) c;
rack.moveSolarPanels(position);
setIdOfChildren(c);
final MeshLocator originalMeshLocator = ((Rack) copyBuffer).getMeshLocator();
if (originalMeshLocator != null) {
final UserData ud = (UserData) mesh.getUserData();
rack.setMeshLocator(new MeshLocator((Foundation) ud.getHousePart(), ud.getNodeIndex(), ud.getMeshIndex()));
}
} else if (copyBuffer instanceof SolarPanel) {
final SolarPanel panel = (SolarPanel) c;
final MeshLocator originalMeshLocator = ((SolarPanel) copyBuffer).getMeshLocator();
if (originalMeshLocator != null) {
final UserData ud = (UserData) mesh.getUserData();
panel.setMeshLocator(new MeshLocator((Foundation) ud.getHousePart(), ud.getNodeIndex(), ud.getMeshIndex()));
}
}
add(c, true);
copyBuffer = c;
SceneManager.getInstance().setSelectedPart(c);
SceneManager.getInstance().getUndoManager().addEdit(new PastePartCommand(c));
}
use of org.concord.energy3d.model.UserData in project energy3d by concord-consortium.
the class SceneManager method mousePressed.
private void mousePressed(final MouseState mouseState, final KeyboardState keyboardState) {
refresh = true;
taskManager.update(new Callable<Object>() {
@Override
public Object call() {
if (zoomLock) {
return null;
}
System.out.println("OPERATION: " + operation);
try {
if (operation == Operation.SELECT || operation == Operation.RESIZE || operation == Operation.ROTATE || operation == Operation.DRAW_ROOF_GABLE) {
if (selectedPart == null || selectedPart.isDrawCompleted()) {
final HousePart previousSelectedPart = selectedPart;
final PickedHousePart pickedPart = SelectUtil.selectHousePart(mouseState.getX(), mouseState.getY(), true);
final UserData pick = pickedPart == null ? null : pickedPart.getUserData();
if (pick == null) {
selectedPart = null;
} else {
selectedPart = pick.getHousePart();
}
if (selectedPart != null) {
// }
if (keyboardState.isDown(Key.LMENU) || keyboardState.isDown(Key.RMENU)) {
if (selectedPart instanceof SolarPanel && selectedPart.getContainer() instanceof Rack) {
// special case
selectedPart = selectedPart.getContainer();
}
}
}
System.out.println("Clicked on: " + pick);
if (pick != null && pick.isEditPoint()) {
cameraControl.setLeftMouseButtonEnabled(false);
}
if (operation == Operation.RESIZE) {
for (final HousePart p : Scene.getInstance().getParts()) {
if (p instanceof Foundation) {
if (p != selectedPart) {
((Foundation) p).setResizeHouseMode(false);
}
}
}
if (selectedPart != null) {
if (selectedPart instanceof Foundation) {
final Foundation foundation = (Foundation) selectedPart;
foundation.setResizeHouseMode(true);
} else {
final Foundation foundation = selectedPart.getTopContainer();
if (foundation != null) {
foundation.setResizeHouseMode(true);
setSelectedPart(foundation);
}
}
}
}
if (operation == Operation.SELECT || operation == Operation.ROTATE) {
if (previousSelectedPart instanceof Foundation) {
final Foundation foundation = (Foundation) previousSelectedPart;
foundation.updateAzimuthArrowVisibility(false);
}
if (selectedPart instanceof Foundation) {
final Foundation foundation = (Foundation) selectedPart;
foundation.drawAzimuthArrow();
foundation.pickMesh(mouseState.getX(), mouseState.getY());
}
if (selectedPart != null) {
final Foundation foundationOfSelectedPart = selectedPart instanceof Foundation ? (Foundation) selectedPart : selectedPart.getTopContainer();
if (foundationOfSelectedPart != null) {
foundationOfSelectedPart.setMovePointsVisible(true);
}
}
}
if (operation == Operation.RESIZE && selectedPart != null) {
if (!(selectedPart instanceof Foundation)) {
selectedPart.setEditPointsVisible(false);
selectedPart = selectedPart.getTopContainer();
}
}
if (selectedPart instanceof Window || selectedPart instanceof Tree || (selectedPart instanceof Foundation && pick.getEditPointIndex() != -1)) {
cameraControl.setLeftMouseButtonEnabled(false);
objectMoveStartPoint = pickedPart.getPoint().clone();
collisionLand.setTranslation(0, 0, objectMoveStartPoint.getZ());
final ArrayList<Vector3> points = selectedPart.getPoints();
if (objectMovePoints == null) {
objectMovePoints = new ArrayList<Vector3>();
} else {
objectMovePoints.clear();
}
for (final Vector3 p : points) {
objectMovePoints.add(p.clone());
}
if (selectedPart instanceof Foundation) {
final Foundation f = (Foundation) selectedPart;
if (f.isGroupMaster()) {
final List<Foundation> g = Scene.getInstance().getFoundationGroup(f);
if (!g.isEmpty()) {
if (objectGroupMovePoints == null) {
objectGroupMovePoints = new HashMap<Foundation, ArrayList<Vector3>>();
} else {
objectGroupMovePoints.clear();
}
for (final Foundation a : g) {
final ArrayList<Vector3> b = new ArrayList<Vector3>();
objectGroupMovePoints.put(a, b);
for (final Vector3 p : a.getPoints()) {
b.add(p.clone());
}
}
}
}
}
}
if (previousSelectedPart != null && previousSelectedPart != selectedPart && operation != Operation.RESIZE) {
previousSelectedPart.setEditPointsVisible(false);
previousSelectedPart.setGridsVisible(false);
previousSelectedPart.setLinePatternVisible(false);
final Foundation foundationOfPreviousSelectedPart = previousSelectedPart instanceof Foundation ? (Foundation) previousSelectedPart : previousSelectedPart.getTopContainer();
if (foundationOfPreviousSelectedPart != null) {
if (selectedPart == null) {
foundationOfPreviousSelectedPart.setMovePointsVisible(false);
} else if (foundationOfPreviousSelectedPart != (selectedPart instanceof Foundation ? (Foundation) selectedPart : selectedPart.getTopContainer())) {
foundationOfPreviousSelectedPart.setMovePointsVisible(false);
}
foundationOfPreviousSelectedPart.clearSelectedMesh();
foundationOfPreviousSelectedPart.setResizeHouseMode(false);
}
}
if (selectedPart != null && !PrintController.getInstance().isPrintPreview()) {
selectedPart.setEditPointsVisible(true);
if (pick.isEditPoint() && pick.getEditPointIndex() != -1 || operation == Operation.RESIZE || selectedPart instanceof Window || selectedPart instanceof Tree) {
if (Scene.getInstance().isSnapToGrids()) {
selectedPart.setGridsVisible(true);
} else {
selectedPart.setLinePatternVisible(true);
}
if (selectedPart instanceof Foundation) {
editPartCommand = new EditFoundationCommand((Foundation) selectedPart, !pick.isEditPoint());
} else if (selectedPart instanceof Rack) {
editPartCommand = new EditRackCommand((Rack) selectedPart);
} else if (selectedPart instanceof ParabolicTrough) {
editPartCommand = new EditParabolicTroughCommand((ParabolicTrough) selectedPart);
} else {
editPartCommand = new EditPartCommand(selectedPart);
}
}
}
SelectUtil.nextPickLayer();
if (operation == Operation.DRAW_ROOF_GABLE && selectedPart instanceof Roof) {
System.out.println("deleting roof #" + pick.getEditPointIndex());
final int roofPartIndex = pick.getEditPointIndex();
final Roof roof = (Roof) selectedPart;
roof.setGable(roofPartIndex, true, undoManager);
}
}
} else {
if (selectedPart != null) {
// selected part can be null in modes other than specified in the if clause
selectedPart.addPoint(mouseState.getX(), mouseState.getY());
}
}
} catch (final Throwable t) {
t.printStackTrace();
BugReporter.report(t);
}
return null;
}
});
}
use of org.concord.energy3d.model.UserData 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