use of org.concord.energy3d.model.UserData in project energy3d by concord-consortium.
the class SceneManager method mouseRightClicked.
// the x and y coordinates come from MouseEvent, not MouseState.
private void mouseRightClicked(final MouseEvent e) {
final JPanel cp = MainPanel.getInstance().getCanvasPanel();
final int x = e.getX();
final int y = cp.getHeight() - e.getY();
mouseState = new MouseState(x, y, 0, 0, 0, null, null);
pickMouseState = mouseState;
refresh = true;
taskManager.update(new Callable<Object>() {
@Override
public Object call() {
try {
if (operation == Operation.SELECT || operation == Operation.RESIZE) {
final HousePart previousSelectedHousePart = selectedPart;
if (mouseState == null) {
mouseState = new MouseState(x, y, 0, 0, 0, null, null);
}
final PickedHousePart pickedHousePart = SelectUtil.selectHousePart(mouseState.getX(), mouseState.getY(), true);
final UserData pick = pickedHousePart == null ? null : pickedHousePart.getUserData();
selectedPart = pick == null ? null : pick.getHousePart();
if (selectedPart instanceof Foundation) {
final Foundation foundation = (Foundation) selectedPart;
if (foundation.getImportedNodes() != null) {
// if this foundation contains any imported node, pick a mesh
foundation.pickMesh(x, y);
}
} else {
if (e.isAltDown()) {
if (selectedPart instanceof SolarPanel && selectedPart.getContainer() instanceof Rack) {
// special case (to be removed later)
selectedPart = selectedPart.getContainer();
}
}
}
System.out.println("Right-clicked on: (" + mouseState.getX() + ", " + mouseState.getY() + ") " + pick);
if (previousSelectedHousePart != null && previousSelectedHousePart != selectedPart) {
previousSelectedHousePart.setEditPointsVisible(false);
previousSelectedHousePart.setGridsVisible(false);
previousSelectedHousePart.setLinePatternVisible(false);
}
if (selectedPart != null) {
// to undo edit flag set by SelectUtil above. FIXME: This taints the wall's heat map texture
selectedPart.complete();
if (!PrintController.getInstance().isPrintPreview()) {
selectedPart.setEditPointsVisible(true);
}
EnergyPanel.getInstance().update();
}
EnergyPanel.getInstance().updateGraphs();
EnergyPanel.getInstance().updateProperties();
final int mouseStateX = mouseState.getX();
final int mouseStateY = mouseState.getY();
final boolean pickOnLand = onLand(pickMouseState.getX(), pickMouseState.getY());
EventQueue.invokeLater(new // seriously, our error log on 6/14/2017 showed that this caused deadlock if not invoked later!
Runnable() {
@Override
public void run() {
final JPopupMenu popup = PopupMenuFactory.getPopupMenu(e, pickOnLand);
if (popup != null) {
final JPanel cp = MainPanel.getInstance().getCanvasPanel();
popup.show(cp, mouseStateX, cp.getHeight() - mouseStateY);
}
}
});
}
} 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 PrintController method computePrintCenterOf.
private void computePrintCenterOf(final Spatial printPart, final ArrayList<ArrayList<Spatial>> pages) {
boolean isFitted = false;
for (int pageNum = 0; pageNum < pages.size() && !isFitted; pageNum++) {
isFitted = fitInPage(printPart, pages.get(pageNum));
}
if (!isFitted) {
printPart.updateWorldBound(true);
final OrientedBoundingBox bounds = (OrientedBoundingBox) printPart.getWorldBound().asType(Type.OBB);
((UserData) printPart.getUserData()).setPrintCenter(new Vector3(bounds.getExtent().getX() + pageLeft, Scene.getOriginalHouseRoot().getWorldBound().getCenter().getY(), -bounds.getExtent().getZ() - pageTop));
final ArrayList<Spatial> page = new ArrayList<Spatial>();
page.add(printPart);
pages.add(page);
}
}
use of org.concord.energy3d.model.UserData in project energy3d by concord-consortium.
the class SolarRadiation method computeOnImportedMesh.
private void computeOnImportedMesh(final int minute, final ReadOnlyVector3 directionTowardSun, final Foundation foundation, final Mesh mesh) {
final UserData userData = (UserData) mesh.getUserData();
if (!userData.isReachable()) {
return;
}
final ReadOnlyVector3 normal = userData.getRotatedNormal() == null ? userData.getNormal() : userData.getRotatedNormal();
final MeshDataStore data = onMesh.get(mesh);
final int timeStep = Scene.getInstance().getTimeStep();
final int iMinute = minute / timeStep;
final double dot = normal.dot(directionTowardSun);
final double directRadiation = dot > 0 ? calculateDirectRadiation(directionTowardSun, normal) : 0;
final double indirectRadiation = calculateDiffuseAndReflectedRadiation(directionTowardSun, normal);
final double solarStep = Scene.getInstance().getSolarStep();
final double annotationScale = Scene.getInstance().getAnnotationScale();
final double scaleFactor = annotationScale * annotationScale / 60 * timeStep;
final float absorption = 1 - foundation.getAlbedo();
for (int col = 0; col < data.cols; col++) {
// final double w = col == data.cols - 1 ? data.p2.distance(data.u.multiply(col * solarStep, null).addLocal(data.p0)) : solarStep;
final double w = col == data.cols - 1 ? data.p2.distance(data.p0) - col * solarStep : solarStep;
final ReadOnlyVector3 pU = data.u.multiply(col * solarStep + 0.5 * w, null).addLocal(data.p0);
for (int row = 0; row < data.rows; row++) {
if (EnergyPanel.getInstance().isCancelled()) {
throw new CancellationException();
}
if (data.dailySolarIntensity[row][col] == -1) {
continue;
}
final double h = row == data.rows - 1 ? data.p1.distance(data.p0) - row * solarStep : solarStep;
// cannot do offset as in computeOnMesh
final ReadOnlyVector3 p = data.v.multiply(row * solarStep + 0.5 * h, null).addLocal(pU);
final Ray3 pickRay = new Ray3(p, directionTowardSun);
final PickResults pickResults = new PrimitivePickResults();
// assuming that indirect (ambient or diffuse) radiation can always reach a grid point
double radiation = indirectRadiation;
final double scaledArea = w * h * scaleFactor;
if (dot > 0) {
for (final Spatial spatial : collidables) {
if (EnergyPanel.getInstance().isCancelled()) {
throw new CancellationException();
}
if (spatial != mesh) {
PickingUtil.findPick(spatial, pickRay, pickResults, false);
if (pickResults.getNumber() != 0) {
break;
}
}
}
if (pickResults.getNumber() == 0) {
radiation += directRadiation;
}
}
data.dailySolarIntensity[row][col] += Scene.getInstance().getOnlyAbsorptionInSolarMap() ? absorption * radiation : radiation;
if (data.solarPotential != null) {
data.solarPotential[iMinute] += radiation * scaledArea;
}
// sum all the solar energy up over all meshes and store in the foundation's solar potential array
foundation.getSolarPotential()[iMinute] += radiation * scaledArea;
}
}
}
use of org.concord.energy3d.model.UserData in project energy3d by concord-consortium.
the class SolarRadiation method setupImportedMeshes.
private void setupImportedMeshes() {
for (final HousePart part : Scene.getInstance().getParts()) {
if (part instanceof Foundation) {
final Foundation foundation = (Foundation) part;
final boolean nonZeroAz = !Util.isZero(foundation.getAzimuth());
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;
final UserData ud = (UserData) m.getUserData();
ReadOnlyVector3 normal = ud.getNormal();
if (nonZeroAz) {
// if the foundation is rotated, rotate the imported meshes, too, but this doesn't alter their original normals
// this must be recalculated in case the foundation has been rotated after loading
ud.setRotatedNormal(node.getRotation().applyPost(normal, null));
normal = ud.getRotatedNormal();
}
MeshDataStore data = onMesh.get(m);
if (data == null) {
// initialize mesh solar data and texture
data = initMeshTextureData(m, m, normal, true);
data.solarPotential = new double[MINUTES_OF_DAY / Scene.getInstance().getTimeStep()];
}
}
}
}
}
}
}
use of org.concord.energy3d.model.UserData in project energy3d by concord-consortium.
the class SelectUtil method getPickResultForImportedMesh.
// if this is an imported mesh, do it here. getPickResult method below returns incorrect result.
private static PickedHousePart getPickResultForImportedMesh() {
if (pickResults.getNumber() > 0) {
final PickData pick = pickResults.getPickData(0);
final Pickable pickable = pick.getTarget();
if (pickable instanceof Mesh) {
final Mesh m = (Mesh) pickable;
final UserData u = (UserData) m.getUserData();
// the user data of land can be null
if (u != null && u.isImported()) {
return new PickedHousePart(u, pick.getIntersectionRecord().getIntersectionPoint(0), u.getRotatedNormal() == null ? u.getNormal() : u.getRotatedNormal());
}
}
}
return null;
}
Aggregations