Search in sources :

Example 1 with UserData

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;
        }
    });
}
Also used : JPanel(javax.swing.JPanel) UserData(org.concord.energy3d.model.UserData) CullHint(com.ardor3d.scenegraph.hint.CullHint) JPopupMenu(javax.swing.JPopupMenu) Rack(org.concord.energy3d.model.Rack) MouseState(com.ardor3d.input.MouseState) SolarPanel(org.concord.energy3d.model.SolarPanel) Foundation(org.concord.energy3d.model.Foundation) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) PickedHousePart(org.concord.energy3d.model.PickedHousePart)

Example 2 with UserData

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);
    }
}
Also used : OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) UserData(org.concord.energy3d.model.UserData) Spatial(com.ardor3d.scenegraph.Spatial) ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 3 with UserData

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;
        }
    }
}
Also used : PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) UserData(org.concord.energy3d.model.UserData) CancellationException(java.util.concurrent.CancellationException) Spatial(com.ardor3d.scenegraph.Spatial) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) PickResults(com.ardor3d.intersection.PickResults) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point) Ray3(com.ardor3d.math.Ray3)

Example 4 with UserData

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()];
                        }
                    }
                }
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) UserData(org.concord.energy3d.model.UserData) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart)

Example 5 with UserData

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;
}
Also used : UserData(org.concord.energy3d.model.UserData) Pickable(com.ardor3d.intersection.Pickable) Mesh(com.ardor3d.scenegraph.Mesh) PickData(com.ardor3d.intersection.PickData) PickedHousePart(org.concord.energy3d.model.PickedHousePart)

Aggregations

UserData (org.concord.energy3d.model.UserData)17 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)10 Foundation (org.concord.energy3d.model.Foundation)9 HousePart (org.concord.energy3d.model.HousePart)9 Vector3 (com.ardor3d.math.Vector3)8 Mesh (com.ardor3d.scenegraph.Mesh)8 Spatial (com.ardor3d.scenegraph.Spatial)6 Rack (org.concord.energy3d.model.Rack)6 SolarPanel (org.concord.energy3d.model.SolarPanel)6 Node (com.ardor3d.scenegraph.Node)5 PickedHousePart (org.concord.energy3d.model.PickedHousePart)5 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)4 CullHint (com.ardor3d.scenegraph.hint.CullHint)4 ArrayList (java.util.ArrayList)4 Roof (org.concord.energy3d.model.Roof)4 Window (org.concord.energy3d.model.Window)4 List (java.util.List)3 NodeState (org.concord.energy3d.model.NodeState)3 ParabolicTrough (org.concord.energy3d.model.ParabolicTrough)3 Wall (org.concord.energy3d.model.Wall)3