Search in sources :

Example 11 with WallVisitor

use of org.concord.energy3d.util.WallVisitor in project energy3d by concord-consortium.

the class Roof method insideWalls.

public boolean insideWalls(final double x, final double y, final boolean init) {
    if (walls.isEmpty()) {
        return false;
    }
    if (init) {
        if (underlyingWallVerticesOnFoundation == null) {
            underlyingWallVerticesOnFoundation = new ArrayList<Vector2>();
        } else {
            underlyingWallVerticesOnFoundation.clear();
        }
        walls.get(0).visitNeighbors(new WallVisitor() {

            @Override
            public void visit(final Wall currentWall, final Snap prev, final Snap next) {
                int pointIndex = 0;
                if (next != null) {
                    pointIndex = next.getSnapPointIndexOf(currentWall);
                }
                pointIndex++;
                addUnderlyingWallVertex(currentWall.getAbsPoint(pointIndex == 1 ? 3 : 1));
                addUnderlyingWallVertex(currentWall.getAbsPoint(pointIndex));
            }

            private void addUnderlyingWallVertex(final ReadOnlyVector3 v3) {
                final Vector2 v2 = new Vector2(v3.getX(), v3.getY());
                boolean b = false;
                for (final Vector2 x : underlyingWallVerticesOnFoundation) {
                    if (Util.isEqual(x, v2)) {
                        b = true;
                        break;
                    }
                }
                if (!b) {
                    underlyingWallVerticesOnFoundation.add(v2);
                }
            }
        });
        if (underlyingWallPath == null) {
            underlyingWallPath = new Path2D.Double();
        } else {
            underlyingWallPath.reset();
        }
        final Vector2 v0 = underlyingWallVerticesOnFoundation.get(0);
        underlyingWallPath.moveTo(v0.getX(), v0.getY());
        for (int i = 1; i < underlyingWallVerticesOnFoundation.size(); i++) {
            final Vector2 v = underlyingWallVerticesOnFoundation.get(i);
            underlyingWallPath.lineTo(v.getX(), v.getY());
        }
        underlyingWallPath.lineTo(v0.getX(), v0.getY());
        underlyingWallPath.closePath();
    }
    return underlyingWallPath != null ? underlyingWallPath.contains(x, y) : false;
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) Path2D(java.awt.geom.Path2D) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) TriangulationPoint(org.poly2tri.triangulation.TriangulationPoint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint)

Example 12 with WallVisitor

use of org.concord.energy3d.util.WallVisitor in project energy3d by concord-consortium.

the class Floor method exploreWallNeighbors.

protected ArrayList<PolygonPoint> exploreWallNeighbors(final Wall startWall) {
    final ArrayList<PolygonPoint> poly = new ArrayList<PolygonPoint>();
    startWall.visitNeighbors(new WallVisitor() {

        @Override
        public void visit(final Wall currentWall, final Snap prev, final Snap next) {
            int pointIndex = 0;
            if (next != null) {
                pointIndex = next.getSnapPointIndexOf(currentWall);
            }
            pointIndex = pointIndex + 1;
            final ReadOnlyVector3 p1 = currentWall.getAbsPoint(pointIndex == 1 ? 3 : 1);
            final ReadOnlyVector3 p2 = currentWall.getAbsPoint(pointIndex);
            addPointToPolygon(poly, p1);
            addPointToPolygon(poly, p2);
            wallUpperVectors.add(p1);
            wallUpperVectors.add(p2);
        }
    });
    return poly;
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArrayList(java.util.ArrayList)

Example 13 with WallVisitor

use of org.concord.energy3d.util.WallVisitor in project energy3d by concord-consortium.

the class HousePart method pickContainer.

protected PickedHousePart pickContainer(final int x, final int y, final Class<?>[] typesOfHousePart) {
    final HousePart previousContainer = container;
    final PickedHousePart picked;
    if (!firstPointInserted || container == null) {
        picked = SelectUtil.pickPart(x, y, typesOfHousePart);
    } else {
        picked = SelectUtil.pickPart(x, y, container);
    }
    if (!firstPointInserted && picked != null) {
        UserData userData = null;
        if (picked != null) {
            userData = picked.getUserData();
        }
        if (container == null || userData == null || container != userData.getHousePart()) {
            if (container != null) {
                container.getChildren().remove(this);
                if (this instanceof Roof) {
                    ((Wall) container).visitNeighbors(new WallVisitor() {

                        @Override
                        public void visit(final Wall wall, final Snap prev, final Snap next) {
                            wall.setRoof(null);
                        }
                    });
                }
            }
            if (userData != null && userData.getHousePart().isDrawCompleted()) {
                if (!(userData.getHousePart() instanceof FoundationPolygon) && (!(this instanceof Roof) || ((Wall) userData.getHousePart()).getRoof() == null)) {
                    container = userData.getHousePart();
                    container.getChildren().add(this);
                }
            } else {
                container = null;
            }
        }
    }
    if (previousContainer != container) {
        if (previousContainer == null) {
            SceneManager.getInstance().setGridsVisible(false);
        } else if (container != null) {
            previousContainer.gridsMesh.getSceneHints().setCullHint(CullHint.Always);
        }
        if (container != null && !(this instanceof Roof)) {
            if (Scene.getInstance().isSnapToGrids()) {
                setGridsVisible(true);
            } else {
                setLinePatternVisible(true);
            }
        } else if (this instanceof Foundation) {
            SceneManager.getInstance().setGridsVisible(true);
        }
    }
    return picked;
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor)

Aggregations

WallVisitor (org.concord.energy3d.util.WallVisitor)13 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)6 Snap (org.concord.energy3d.model.Snap)6 Wall (org.concord.energy3d.model.Wall)6 HousePart (org.concord.energy3d.model.HousePart)4 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)4 Vector3 (com.ardor3d.math.Vector3)3 CullHint (com.ardor3d.scenegraph.hint.CullHint)3 ArrayList (java.util.ArrayList)3 Foundation (org.concord.energy3d.model.Foundation)3 TPoint (org.poly2tri.triangulation.point.TPoint)3 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 BoxLayout (javax.swing.BoxLayout)2 ButtonGroup (javax.swing.ButtonGroup)2 JDialog (javax.swing.JDialog)2 JOptionPane (javax.swing.JOptionPane)2 JPanel (javax.swing.JPanel)2 JRadioButton (javax.swing.JRadioButton)2