Search in sources :

Example 6 with AddArrayCommand

use of org.concord.energy3d.undo.AddArrayCommand in project energy3d by concord-consortium.

the class Rack method addSolarPanels.

public void addSolarPanels() {
    EnergyPanel.getInstance().updateRadiationHeatMap();
    final AddArrayCommand command = new AddArrayCommand(removeAllChildren(), this, new Class[] { SolarPanel.class });
    if (monolithic) {
        ensureFullSolarPanels(false);
        draw();
    } else {
        final Foundation foundation = getTopContainer();
        final double azFoundation = Math.toRadians(foundation.getAzimuth());
        if (!Util.isZero(azFoundation)) {
            foundation.rotate(azFoundation, null, false);
        }
        final double azRack = relativeAzimuth;
        setRelativeAzimuth(0);
        final boolean portrait = !sampleSolarPanel.isRotated();
        final double a = portrait ? sampleSolarPanel.getPanelWidth() : sampleSolarPanel.getPanelHeight();
        final double b = portrait ? sampleSolarPanel.getPanelHeight() : sampleSolarPanel.getPanelWidth();
        final int rows = (int) Math.floor(rackWidth / a);
        final int cols = (int) Math.floor(rackHeight / b);
        final double remainderX = rackWidth - rows * a;
        final double remainderY = rackHeight - cols * b;
        final Vector3 p0 = getAbsPoint(0);
        final double w = a / Scene.getInstance().getAnnotationScale();
        final double h = b / Scene.getInstance().getAnnotationScale();
        final double costilt = Math.cos(Math.toRadians(monthlyTiltAngles[Heliodon.getInstance().getCalendar().get(Calendar.MONTH)]));
        final double x0 = p0.getX() - 0.5 * (rackWidth - remainderX) / Scene.getInstance().getAnnotationScale();
        final double y0 = p0.getY() - 0.5 * (rackHeight - remainderY) / Scene.getInstance().getAnnotationScale() * costilt;
        for (int r = 0; r < rows; r++) {
            for (int c = 0; c < cols; c++) {
                final double x = x0 + w * (r + 0.5);
                final double y = y0 + h * (c + 0.5) * costilt;
                final SolarPanel sp = new SolarPanel();
                sp.setContainer(this);
                final Vector3 v = sp.toRelative(new Vector3(x, y, 0));
                sp.points.get(0).setX(v.getX());
                sp.points.get(0).setY(v.getY());
                sp.setPanelWidth(sampleSolarPanel.getPanelWidth());
                sp.setPanelHeight(sampleSolarPanel.getPanelHeight());
                sp.setRotated(!portrait);
                Scene.getInstance().add(sp, false);
                sp.complete();
                sp.draw();
            }
        }
        if (!Util.isZero(azFoundation)) {
            foundation.rotate(-azFoundation, null, false);
        }
        setRelativeAzimuth(azRack);
        Scene.getInstance().redrawAll();
    }
    if (!command.getOldArray().isEmpty()) {
        SceneManager.getInstance().getUndoManager().addEdit(command);
    }
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            EnergyPanel.getInstance().updateProperties();
        }
    });
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) AddArrayCommand(org.concord.energy3d.undo.AddArrayCommand) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Aggregations

Vector3 (com.ardor3d.math.Vector3)6 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)6 CullHint (com.ardor3d.scenegraph.hint.CullHint)6 AddArrayCommand (org.concord.energy3d.undo.AddArrayCommand)6 Path2D (java.awt.geom.Path2D)1 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1