Search in sources :

Example 61 with HousePart

use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.

the class Scene method init.

private void init() {
    root.detachAllChildren();
    originalHouseRoot.detachAllChildren();
    notReceivingShadowRoot.detachAllChildren();
    root.attachChild(originalHouseRoot);
    root.attachChild(notReceivingShadowRoot);
    if (url != null) {
        for (final HousePart p : parts) {
            final boolean b = p instanceof Tree || p instanceof Human;
            (b ? notReceivingShadowRoot : originalHouseRoot).attachChild(p.getRoot());
        }
        System.out.println("initSceneNow done");
    }
    root.updateWorldBound(true);
    SceneManager.getInstance().updateHeliodonAndAnnotationSize();
    SceneManager.getInstance().setAxesVisible(!hideAxes);
    SceneManager.getInstance().getSolarLand().setVisible(solarMapForLand);
    setTheme(theme);
    SceneManager.getInstance().getLand().setDefaultColor(landColor != null ? landColor : new ColorRGBA(0, 1, 0, 0.5f));
    PvModulesData.getInstance();
    final EnergyPanel energyPanel = EnergyPanel.getInstance();
    if (calendar != null) {
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        if (url == null) {
            // if a new file is created, its default time is always set to noon so that the user does not get a dark night scene
            calendar.set(Calendar.HOUR_OF_DAY, 12);
            calendar.set(Calendar.MINUTE, 0);
        }
        final Date time = calendar.getTime();
        Heliodon.getInstance().setDate(time);
        Heliodon.getInstance().setTime(time);
        Util.setSilently(energyPanel.getDateSpinner(), time);
        Util.setSilently(energyPanel.getTimeSpinner(), time);
        if ("Boston".equals(city) || city == null || "".equals(city)) {
            city = "Boston, MA";
            latitude = 42;
        }
        // already silent
        energyPanel.setLatitude(latitude);
        Util.selectSilently(energyPanel.getCityComboBox(), city);
        final LocationData ld = LocationData.getInstance();
        if (ld.getLatitudes().get(city) != null) {
            energyPanel.getCityComboBox().setToolTipText("<html>(" + ld.getLatitudes().get(city) + "&deg;, " + ld.getLongitudes().get(city) + "&deg;), elevation " + ld.getAltitudes().get(city).intValue() + "m<br>Use Edit>Set Region... to select country and region.</html>");
        } else {
            JOptionPane.showMessageDialog(MainFrame.getInstance(), city + " not supported. Please upgrade your Energy3D to the latest.", "Missing City", JOptionPane.ERROR_MESSAGE);
        }
        Scene.getInstance().updateTreeLeaves();
        SceneManager.getInstance().changeSkyTexture();
        if (!first) {
            SceneManager.getInstance().setHeliodonVisible(isHeliodonVisible);
            Util.selectSilently(MainPanel.getInstance().getHeliodonButton(), isHeliodonVisible);
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    MainPanel.getInstance().getSunAnimationButton().setEnabled(isHeliodonVisible);
                }
            });
        }
        Heliodon.getInstance().drawSun();
        SceneManager.getInstance().setShading(Heliodon.getInstance().isNightTime());
    }
    // previous versions do not have the following classes
    if (designSpecs == null) {
        designSpecs = new DesignSpecs();
    } else {
        designSpecs.setDefaultValues();
    }
    if (pvDesignSpecs == null) {
        pvDesignSpecs = new PvDesignSpecs();
    } else {
        pvDesignSpecs.setDefaultValues();
    }
    if (cspDesignSpecs == null) {
        cspDesignSpecs = new CspDesignSpecs();
    } else {
        cspDesignSpecs.setDefaultValues();
    }
    if (pvCustomPrice == null) {
        pvCustomPrice = new PvCustomPrice();
    } else {
        pvCustomPrice.setDefaultValues();
    }
    if (cspCustomPrice == null) {
        cspCustomPrice = new CspCustomPrice();
    } else {
        cspCustomPrice.setDefaultValues();
    }
    if (ground == null) {
        ground = new Ground();
    }
    if (atmosphere == null) {
        atmosphere = new Atmosphere();
    }
    if (unit == null) {
        unit = Unit.InternationalSystemOfUnits;
    }
    // restore the default values
    if (Util.isZero(heatVectorLength)) {
        heatVectorLength = 5000;
    }
    if (Util.isZero(heatFluxGridSize)) {
        heatFluxGridSize = 2;
    }
    if (Util.isZero(solarStep)) {
        solarStep = 2;
    }
    if (Util.isZero(timeStep)) {
        timeStep = 15;
    }
    if (Util.isZero(solarPanelNx)) {
        solarPanelNx = 4;
    }
    if (Util.isZero(solarPanelNy)) {
        solarPanelNy = 4;
    }
    if (Util.isZero(rackNx)) {
        rackNx = 8;
    }
    if (Util.isZero(rackNy)) {
        rackNy = 8;
    }
    if (Util.isZero(mirrorNx)) {
        mirrorNx = 4;
    }
    if (Util.isZero(mirrorNy)) {
        mirrorNy = 4;
    }
    if (Util.isZero(parabolicDishN)) {
        parabolicDishN = 4;
    }
    if (Util.isZero(rackCellSize)) {
        rackCellSize = 1;
    }
    if (Util.isZero(solarContrast)) {
        solarContrast = 50;
    }
    // in case we need to have more instruction sheets
    if (instructionSheetText != null) {
        if (instructionSheetText.length < INSTRUCTION_SHEET_NUMBER) {
            final String[] tmp = new String[INSTRUCTION_SHEET_NUMBER];
            System.arraycopy(instructionSheetText, 0, tmp, 0, instructionSheetText.length);
            instructionSheetText = tmp;
        }
    }
    if (instructionSheetTextType != null) {
        if (instructionSheetTextType.length < INSTRUCTION_SHEET_NUMBER) {
            final String[] tmp = new String[INSTRUCTION_SHEET_NUMBER];
            System.arraycopy(instructionSheetTextType, 0, tmp, 0, instructionSheetTextType.length);
            instructionSheetTextType = tmp;
        }
    }
    setEdited(false);
    setCopyBuffer(null);
    Util.setSilently(energyPanel.getColorMapSlider(), solarContrast);
    // need to do this to avoid logging
    Util.setSilently(MainPanel.getInstance().getNoteTextArea(), note == null ? "" : note);
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            energyPanel.updateThermostat();
            // necessary for the scroll bars to show up appropriately
            MainPanel.getInstance().setNoteVisible(MainPanel.getInstance().isNoteVisible());
            // moved from OpenNow to here to avoid triggering EnergyComputer -> RedrawAllNow before open is completed
            MainPanel.getInstance().getEnergyButton().setSelected(false);
            SceneManager.getInstance().getUndoManager().discardAllEdits();
            MainApplication.getEventLog().clear();
        }
    });
}
Also used : Human(org.concord.energy3d.model.Human) PvCustomPrice(org.concord.energy3d.simulation.PvCustomPrice) Ground(org.concord.energy3d.simulation.Ground) Date(java.util.Date) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) EnergyPanel(org.concord.energy3d.gui.EnergyPanel) LocationData(org.concord.energy3d.simulation.LocationData) DesignSpecs(org.concord.energy3d.simulation.DesignSpecs) CspDesignSpecs(org.concord.energy3d.simulation.CspDesignSpecs) PvDesignSpecs(org.concord.energy3d.simulation.PvDesignSpecs) CspDesignSpecs(org.concord.energy3d.simulation.CspDesignSpecs) Atmosphere(org.concord.energy3d.simulation.Atmosphere) PvDesignSpecs(org.concord.energy3d.simulation.PvDesignSpecs) Tree(org.concord.energy3d.model.Tree) CspCustomPrice(org.concord.energy3d.simulation.CspCustomPrice) HousePart(org.concord.energy3d.model.HousePart)

Example 62 with HousePart

use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.

the class Scene method groupFoundations.

/* put overlapping foundations into separate groups */
private void groupFoundations() {
    if (foundationGroups == null) {
        foundationGroups = new ArrayList<List<Foundation>>();
    } else {
        foundationGroups.clear();
    }
    final List<Foundation> foundations = new ArrayList<Foundation>();
    for (final HousePart p : parts) {
        if (p instanceof Foundation) {
            foundations.add((Foundation) p);
        }
    }
    final int n = foundations.size();
    if (n > 1) {
        int count = 0;
        final List<Pair> pairs = new ArrayList<Pair>();
        for (int i = 0; i < n - 1; i++) {
            final Foundation fi = foundations.get(i);
            for (int j = i + 1; j < n; j++) {
                final Foundation fj = foundations.get(j);
                if (fi.overlap(fj)) {
                    final Pair p = new Pair(i, j);
                    if (!pairs.contains(p)) {
                        pairs.add(p);
                    }
                }
            }
        }
        int m = pairs.size();
        while (m > 0) {
            Pair p = pairs.get(0);
            final List<Integer> list = new ArrayList<Integer>();
            list.add(p.i());
            list.add(p.j());
            pairs.remove(p);
            m = pairs.size();
            if (m > 0) {
                final List<Pair> toRemove = new ArrayList<Pair>();
                for (int x = 0; x < m; x++) {
                    p = pairs.get(x);
                    final int i = p.i();
                    final int j = p.j();
                    if (list.contains(i) && list.contains(j)) {
                        if (!toRemove.contains(p)) {
                            toRemove.add(p);
                        }
                    } else if (!list.contains(i) && list.contains(j)) {
                        list.add(i);
                        if (!toRemove.contains(p)) {
                            toRemove.add(p);
                        }
                    } else if (!list.contains(j) && list.contains(i)) {
                        list.add(j);
                        if (!toRemove.contains(p)) {
                            toRemove.add(p);
                        }
                    }
                }
                if (!toRemove.isEmpty()) {
                    pairs.removeAll(toRemove);
                }
            }
            final List<Foundation> group = new ArrayList<Foundation>();
            for (final Integer a : list) {
                group.add(foundations.get(a));
            }
            foundationGroups.add(group);
            count += group.size();
            m = pairs.size();
        }
        if (count < foundations.size()) {
            for (final Foundation f : foundations) {
                boolean linked = false;
                for (final List<Foundation> g : foundationGroups) {
                    if (g.contains(f)) {
                        linked = true;
                        break;
                    }
                }
                if (!linked) {
                    final List<Foundation> g = new ArrayList<Foundation>();
                    g.add(f);
                    foundationGroups.add(g);
                }
            }
        }
    // System.out.println("###" + foundationGroups.size() + "," + (foundations.size() - count));
    } else {
        foundationGroups.add(foundations);
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) Pair(org.concord.energy3d.util.Pair)

Example 63 with HousePart

use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.

the class Scene method redrawAllWallsNow.

// special case for redrawing walls and roofs that are interconnected (this is needed when we deal with a lot of solar collectors)
public void redrawAllWallsNow() {
    System.out.println("redrawAllWallsNow()");
    connectWalls();
    List<Roof> roofs = null;
    for (final HousePart part : parts) {
        if (part instanceof Roof) {
            if (roofs == null) {
                roofs = new ArrayList<Roof>();
            }
            roofs.add((Roof) part);
            part.draw();
        }
    }
    for (final HousePart part : parts) {
        if (part instanceof Wall) {
            part.draw();
            part.drawChildren();
        }
    }
    if (roofs != null && !roofs.isEmpty()) {
        // need to draw roof again because roof holes depend on drawn windows
        for (final Roof r : roofs) {
            r.draw();
        }
        roofs.clear();
    }
    SceneManager.getInstance().refresh();
}
Also used : Roof(org.concord.energy3d.model.Roof) Wall(org.concord.energy3d.model.Wall) HousePart(org.concord.energy3d.model.HousePart)

Example 64 with HousePart

use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.

the class Scene method openNow.

public static void openNow(final URL file) throws Exception {
    SceneManager.getInstance().clearMouseState();
    SceneManager.getInstance().cursorWait(true);
    if (PrintController.getInstance().isPrintPreview()) {
        MainPanel.getInstance().getPreviewButton().setSelected(false);
        while (!PrintController.getInstance().isFinished()) {
            Thread.yield();
        }
    }
    url = file;
    if (!first) {
        SceneManager.getInstance().setHeliodonVisible(false);
        SceneManager.getInstance().setSunAnimation(false);
        Util.selectSilently(MainPanel.getInstance().getHeliodonButton(), false);
        Util.selectSilently(MainPanel.getInstance().getSunAnimationButton(), false);
    }
    SceneManager.getInstance().setSolarHeatMapWithoutUpdate(false);
    Wall.resetDefaultWallHeight();
    if (instance != null) {
        // in case of any possible memory leak
        instance.destroy();
    }
    if (url == null) {
        instance = new Scene();
        System.out.println("done");
    } else {
        System.out.println("Opening..." + file + "...");
        final ObjectInputStream in = new ObjectInputStream(file.openStream());
        instance = (Scene) in.readObject();
        in.close();
        for (final HousePart part : instance.parts) {
            part.getRoot();
        }
        instance.upgradeSceneToNewVersion();
        instance.cleanup();
        loadCameraLocation();
    }
    if (Util.isZero(instance.groundImageScale)) {
        instance.groundImageScale = 1;
    }
    SceneManager.getInstance().hideAllEditPoints();
    final CameraControl cameraControl = SceneManager.getInstance().getCameraControl();
    if (cameraControl != null) {
        cameraControl.reset();
    }
    instance.init();
    instance.applyGroundImage();
    EventQueue.invokeLater(new // update GUI must be called in Event Queue to prevent possible deadlocks
    Runnable() {

        @Override
        public void run() {
            MainPanel.getInstance().getAnnotationButton().setSelected(instance.isAnnotationsVisible);
            MainFrame.getInstance().updateTitleBar();
            SceneManager.getInstance().cursorWait(false);
            if (file != null) {
                final HashMap<String, Object> attributes = new HashMap<String, Object>();
                attributes.put("Open File", Scene.getURL());
                MainApplication.addEvent(new OperationEvent(Scene.getURL(), System.currentTimeMillis(), "Open File", attributes));
            }
        }
    });
}
Also used : HashMap(java.util.HashMap) OperationEvent(org.concord.energy3d.agents.OperationEvent) HousePart(org.concord.energy3d.model.HousePart) ObjectInputStream(java.io.ObjectInputStream)

Example 65 with HousePart

use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.

the class Scene method setModuleLengthForAllParabolicTroughs.

public void setModuleLengthForAllParabolicTroughs(final double moduleLength) {
    for (final HousePart p : parts) {
        if (p instanceof ParabolicTrough) {
            final ParabolicTrough t = (ParabolicTrough) p;
            t.setModuleLength(moduleLength);
            t.ensureFullModules(false);
            t.draw();
        }
    }
    SceneManager.getInstance().refresh();
}
Also used : ParabolicTrough(org.concord.energy3d.model.ParabolicTrough) HousePart(org.concord.energy3d.model.HousePart)

Aggregations

HousePart (org.concord.energy3d.model.HousePart)277 Foundation (org.concord.energy3d.model.Foundation)153 Rack (org.concord.energy3d.model.Rack)69 SolarPanel (org.concord.energy3d.model.SolarPanel)60 Roof (org.concord.energy3d.model.Roof)47 Wall (org.concord.energy3d.model.Wall)45 Window (org.concord.energy3d.model.Window)43 ActionEvent (java.awt.event.ActionEvent)42 ActionListener (java.awt.event.ActionListener)42 ArrayList (java.util.ArrayList)41 Mirror (org.concord.energy3d.model.Mirror)38 JMenuItem (javax.swing.JMenuItem)36 JDialog (javax.swing.JDialog)35 FresnelReflector (org.concord.energy3d.model.FresnelReflector)34 ParabolicTrough (org.concord.energy3d.model.ParabolicTrough)32 ParabolicDish (org.concord.energy3d.model.ParabolicDish)28 Tree (org.concord.energy3d.model.Tree)26 Door (org.concord.energy3d.model.Door)25 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)21 JPanel (javax.swing.JPanel)21