Search in sources :

Example 36 with Foundation

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

the class EnergyAngularAnalysis method show.

public void show(final String title) {
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    String s = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
    if (selectedPart instanceof Foundation) {
        s = s.replaceAll("Foundation", "Building");
        if (selectedPart.getChildren().isEmpty()) {
            JOptionPane.showMessageDialog(MainFrame.getInstance(), "There is no building on this foundation.", "No Building", JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (!isBuildingComplete((Foundation) selectedPart)) {
            if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "The selected building has not been completed.\nAre you sure to continue?", "Incomplete Building", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
                return;
            }
        }
    } else if (selectedPart instanceof Tree) {
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "Energy analysis is not applicable to a tree.", "Not Applicable", JOptionPane.WARNING_MESSAGE);
        return;
    }
    final JDialog dialog = new JDialog(MainFrame.getInstance(), title + ": " + s, true);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    graph.parent = dialog;
    final JMenuBar menuBar = new JMenuBar();
    dialog.setJMenuBar(menuBar);
    final JMenuItem miClear = new JMenuItem("Clear Previous Results");
    final JMenuItem miView = new JMenuItem("View Raw Data...");
    final JMenuItem miCopyImage = new JMenuItem("Copy Image");
    final JMenu menu = new JMenu("Options");
    menu.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(final MenuEvent e) {
            miClear.setEnabled(graph.hasRecords());
            miView.setEnabled(graph.hasData());
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

        @Override
        public void menuCanceled(final MenuEvent e) {
        }
    });
    menuBar.add(menu);
    miClear.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            final int i = JOptionPane.showConfirmDialog(dialog, "Are you sure that you want to clear all the previous results\nrelated to the selected object?", "Confirmation", JOptionPane.YES_NO_OPTION);
            if (i != JOptionPane.YES_OPTION) {
                return;
            }
            graph.clearRecords();
            graph.repaint();
            TimeSeriesLogger.getInstance().logClearGraphData(graph.getClass().getSimpleName());
        }
    });
    menu.add(miClear);
    miView.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            DataViewer.viewRawData(dialog, graph, false);
        }
    });
    menu.add(miView);
    miCopyImage.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            new ClipImage().copyImageToClipboard(graph);
        }
    });
    menu.add(miCopyImage);
    final JMenu showTypeMenu = new JMenu("Types");
    showTypeMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(final MenuEvent e) {
            showTypeMenu.removeAll();
            final Set<String> dataNames = graph.getDataNames();
            if (!dataNames.isEmpty()) {
                JMenuItem mi = new JMenuItem("Show All");
                mi.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        for (final String name : dataNames) {
                            graph.hideData(name, false);
                        }
                        graph.repaint();
                        TimeSeriesLogger.getInstance().logShowCurve(graph.getClass().getSimpleName(), "All", true);
                    }
                });
                showTypeMenu.add(mi);
                mi = new JMenuItem("Hide All");
                mi.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        for (final String name : dataNames) {
                            graph.hideData(name, true);
                        }
                        graph.repaint();
                        TimeSeriesLogger.getInstance().logShowCurve(graph.getClass().getSimpleName(), "All", false);
                    }
                });
                showTypeMenu.add(mi);
                showTypeMenu.addSeparator();
                for (final String name : dataNames) {
                    final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(name, !graph.isDataHidden(name));
                    cbmi.addItemListener(new ItemListener() {

                        @Override
                        public void itemStateChanged(final ItemEvent e) {
                            graph.hideData(name, !cbmi.isSelected());
                            graph.repaint();
                            TimeSeriesLogger.getInstance().logShowCurve(graph.getClass().getSimpleName(), name, cbmi.isSelected());
                        }
                    });
                    showTypeMenu.add(cbmi);
                }
            }
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

        @Override
        public void menuCanceled(final MenuEvent e) {
        }
    });
    menuBar.add(showTypeMenu);
    final JMenu showRunsMenu = new JMenu("Runs");
    showRunsMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(final MenuEvent e) {
            showRunsMenu.removeAll();
            if (!AngularGraph.records.isEmpty()) {
                JMenuItem mi = new JMenuItem("Show All");
                mi.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        for (final Results r : AngularGraph.records) {
                            graph.hideRun(r.getID(), false);
                        }
                        graph.repaint();
                        TimeSeriesLogger.getInstance().logShowRun(graph.getClass().getSimpleName(), "All", true);
                    }
                });
                showRunsMenu.add(mi);
                mi = new JMenuItem("Hide All");
                mi.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        for (final Results r : AngularGraph.records) {
                            graph.hideRun(r.getID(), true);
                        }
                        graph.repaint();
                        TimeSeriesLogger.getInstance().logShowRun(graph.getClass().getSimpleName(), "All", false);
                    }
                });
                showRunsMenu.add(mi);
                showRunsMenu.addSeparator();
                for (final Results r : AngularGraph.records) {
                    final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(Integer.toString(r.getID()), !graph.isRunHidden(r.getID()));
                    cbmi.addItemListener(new ItemListener() {

                        @Override
                        public void itemStateChanged(final ItemEvent e) {
                            graph.hideRun(r.getID(), !cbmi.isSelected());
                            graph.repaint();
                            TimeSeriesLogger.getInstance().logShowRun(graph.getClass().getSimpleName(), "" + r.getID(), cbmi.isSelected());
                        }
                    });
                    showRunsMenu.add(cbmi);
                }
            }
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

        @Override
        public void menuCanceled(final MenuEvent e) {
        }
    });
    menuBar.add(showRunsMenu);
    final JPanel contentPane = new JPanel(new BorderLayout());
    dialog.setContentPane(contentPane);
    final JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEtchedBorder());
    contentPane.add(panel, BorderLayout.CENTER);
    panel.add(graph, BorderLayout.CENTER);
    final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    contentPane.add(buttonPanel, BorderLayout.SOUTH);
    runButton = new JButton("Run");
    runButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            runButton.setEnabled(false);
            runAnalysis(dialog);
        }
    });
    buttonPanel.add(runButton);
    final JButton button = new JButton("Close");
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            stopAnalysis();
            if (graph.hasData()) {
                final Object[] options = { "Yes", "No", "Cancel" };
                final int i = JOptionPane.showOptionDialog(dialog, "Do you want to keep the results of this run?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
                if (i == JOptionPane.CANCEL_OPTION) {
                    return;
                }
                if (i == JOptionPane.YES_OPTION) {
                    graph.keepResults();
                }
            }
            windowLocation.setLocation(dialog.getLocationOnScreen());
            dialog.dispose();
        }
    });
    buttonPanel.add(button);
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(final WindowEvent e) {
            stopAnalysis();
            windowLocation.setLocation(dialog.getLocationOnScreen());
            dialog.dispose();
        }
    });
    dialog.pack();
    if (windowLocation.x > 0 && windowLocation.y > 0) {
        dialog.setLocation(windowLocation);
    } else {
        dialog.setLocationRelativeTo(MainFrame.getInstance());
    }
    dialog.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) Set(java.util.Set) FlowLayout(java.awt.FlowLayout) MenuListener(javax.swing.event.MenuListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) BorderLayout(java.awt.BorderLayout) Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) JMenuItem(javax.swing.JMenuItem) HousePart(org.concord.energy3d.model.HousePart) MenuEvent(javax.swing.event.MenuEvent) ClipImage(org.concord.energy3d.util.ClipImage) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) ItemListener(java.awt.event.ItemListener) JDialog(javax.swing.JDialog) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 37 with Foundation

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

the class EnergyAnnualAnalysis method show.

public void show(final String title) {
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    String s = null;
    int cost = -1;
    if (selectedPart != null) {
        cost = (int) BuildingCost.getPartCost(selectedPart);
        if (graph.instrumentType == Graph.SENSOR) {
            SceneManager.getInstance().setSelectedPart(null);
        } else {
            s = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
            if (selectedPart instanceof Foundation) {
                cost = (int) BuildingCost.getInstance().getCostByFoundation((Foundation) selectedPart);
                s = s.replaceAll("Foundation", "Building");
                if (selectedPart.getChildren().isEmpty()) {
                    JOptionPane.showMessageDialog(MainFrame.getInstance(), "There is no building on this foundation.", "No Building", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                if (!isBuildingComplete((Foundation) selectedPart)) {
                    if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "The selected building has not been completed.\nAre you sure to continue?", "Incomplete Building", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
                        return;
                    }
                }
            } else if (selectedPart instanceof Tree) {
                JOptionPane.showMessageDialog(MainFrame.getInstance(), "Energy analysis is not applicable to a tree.", "Not Applicable", JOptionPane.WARNING_MESSAGE);
                return;
            }
        }
    }
    final JDialog dialog = createDialog(s == null ? title : title + ": " + s + " (Construction cost: $" + cost + ")");
    final JMenuBar menuBar = new JMenuBar();
    dialog.setJMenuBar(menuBar);
    menuBar.add(createOptionsMenu(dialog, null, false, false));
    menuBar.add(createTypesMenu());
    menuBar.add(createRunsMenu());
    dialog.setVisible(true);
}
Also used : Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) JDialog(javax.swing.JDialog) JMenuBar(javax.swing.JMenuBar)

Example 38 with Foundation

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

the class EnergyAnnualAnalysis method toJson.

@Override
public String toJson() {
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    String s = "{\"Months\": " + getNumberOfDataPoints();
    String[] names;
    if (selectedPart instanceof Foundation) {
        s += ", \"Building\": " + selectedPart.getId();
        names = new String[] { "Net", "AC", "Heater", "Windows", "Solar Panels" };
    } else {
        s += ", \"Part\": \"" + selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1) + "\"";
        names = new String[] { "Solar", "Heat Gain" };
    }
    for (final String name : names) {
        final List<Double> data = graph.getData(name);
        if (data == null) {
            continue;
        }
        s += ", \"" + name + "\": {";
        s += "\"Monthly\": [";
        for (final Double x : data) {
            s += Graph.ENERGY_FORMAT.format(x) + ",";
        }
        s = s.substring(0, s.length() - 1);
        s += "]\n";
        s += ", \"Total\": " + Graph.ENERGY_FORMAT.format(getResult(name));
        s += "}";
    }
    s += "}";
    return s;
}
Also used : Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart)

Example 39 with Foundation

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

the class EnergyDailyAnalysis method runAnalysis.

@Override
void runAnalysis(final JDialog parent) {
    graph.info = "Calculating...";
    graph.repaint();
    onStart();
    SceneManager.getTaskManager().update(new Callable<Object>() {

        @Override
        public Object call() {
            final Throwable t = compute();
            if (t != null) {
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        BugReporter.report(t);
                    }
                });
            }
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    onCompletion();
                    if (graph instanceof BuildingEnergyDailyGraph) {
                        final int net = (int) Math.round(getResult("Net"));
                        final Map<String, Double> recordedResults = getRecordedResults("Net");
                        final int n = recordedResults.size();
                        if (n > 0) {
                            String previousRuns = "";
                            final Object[] keys = recordedResults.keySet().toArray();
                            for (int i = n - 1; i >= 0; i--) {
                                previousRuns += keys[i] + " : " + Graph.TWO_DECIMALS.format(recordedResults.get(keys[i])) + " kWh<br>";
                            }
                            final Object[] options = new Object[] { "OK", "Copy Data" };
                            final String msg = "<html>The calculated daily net energy is <b>" + net + " kWh</b>.<br><hr>Results from previously recorded tests:<br>" + previousRuns + "</html>";
                            final JOptionPane optionPane = new JOptionPane(msg, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
                            final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Daily Net Energy");
                            dialog.setVisible(true);
                            final Object choice = optionPane.getValue();
                            if (choice == options[1]) {
                                String output = "";
                                for (int i = 0; i < n; i++) {
                                    output += Graph.TWO_DECIMALS.format(recordedResults.get(keys[i])) + "\n";
                                }
                                output += Graph.TWO_DECIMALS.format(getResult("Net"));
                                final Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
                                clpbrd.setContents(new StringSelection(output), null);
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>" + (n + 1) + " data points copied to system clipboard.<br><hr>" + output, "Confirmation", JOptionPane.INFORMATION_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(parent, "<html>The calculated daily net energy is <b>" + net + " kWh</b>.</html>", "Daily Net Energy", JOptionPane.INFORMATION_MESSAGE);
                        }
                        final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                        if (selectedPart instanceof Foundation) {
                            EnergyPanel.getInstance().getBuildingDailyEnergyGraph().addGraph((Foundation) selectedPart);
                        }
                    }
                }
            });
            return null;
        }
    });
}
Also used : JOptionPane(javax.swing.JOptionPane) StringSelection(java.awt.datatransfer.StringSelection) Foundation(org.concord.energy3d.model.Foundation) Clipboard(java.awt.datatransfer.Clipboard) JDialog(javax.swing.JDialog) HousePart(org.concord.energy3d.model.HousePart)

Example 40 with Foundation

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

the class EnergyDailyAnalysis method show.

public void show(final String title) {
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    String s = null;
    int cost = -1;
    if (selectedPart != null) {
        cost = (int) BuildingCost.getPartCost(selectedPart);
        if (graph.instrumentType == Graph.SENSOR) {
            SceneManager.getInstance().setSelectedPart(null);
        } else {
            s = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
            if (selectedPart instanceof Foundation) {
                cost = (int) BuildingCost.getInstance().getCostByFoundation((Foundation) selectedPart);
                s = s.replaceAll("Foundation", "Building");
                if (selectedPart.getChildren().isEmpty()) {
                    JOptionPane.showMessageDialog(MainFrame.getInstance(), "There is no building on this foundation.", "No Building", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                if (!isBuildingComplete((Foundation) selectedPart)) {
                    if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "The selected building has not been completed.\nAre you sure to continue?", "Incomplete Building", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
                        return;
                    }
                }
            } else if (selectedPart instanceof Tree) {
                JOptionPane.showMessageDialog(MainFrame.getInstance(), "Energy analysis is not applicable to a tree.", "Not Applicable", JOptionPane.WARNING_MESSAGE);
                return;
            }
        }
    }
    final JDialog dialog = createDialog(s == null ? title : title + ": " + s + " (Construction cost: $" + cost + ")");
    final JMenuBar menuBar = new JMenuBar();
    dialog.setJMenuBar(menuBar);
    menuBar.add(createOptionsMenu(dialog, null, false));
    menuBar.add(createTypesMenu());
    menuBar.add(createRunsMenu());
    dialog.setVisible(true);
}
Also used : Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) JDialog(javax.swing.JDialog) JMenuBar(javax.swing.JMenuBar)

Aggregations

Foundation (org.concord.energy3d.model.Foundation)174 HousePart (org.concord.energy3d.model.HousePart)153 Rack (org.concord.energy3d.model.Rack)47 SolarPanel (org.concord.energy3d.model.SolarPanel)45 Window (org.concord.energy3d.model.Window)39 ActionEvent (java.awt.event.ActionEvent)38 ActionListener (java.awt.event.ActionListener)38 Roof (org.concord.energy3d.model.Roof)38 Wall (org.concord.energy3d.model.Wall)37 ArrayList (java.util.ArrayList)35 JDialog (javax.swing.JDialog)35 JMenuItem (javax.swing.JMenuItem)33 Mirror (org.concord.energy3d.model.Mirror)32 FresnelReflector (org.concord.energy3d.model.FresnelReflector)27 Door (org.concord.energy3d.model.Door)24 ParabolicTrough (org.concord.energy3d.model.ParabolicTrough)24 Tree (org.concord.energy3d.model.Tree)24 Vector3 (com.ardor3d.math.Vector3)22 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)22 ParabolicDish (org.concord.energy3d.model.ParabolicDish)22