Search in sources :

Example 6 with WallVisitor

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

the class MainFrame method showColorDialogForParts.

void showColorDialogForParts() {
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    ActionListener colorActionListener;
    if (selectedPart == null) {
        final ReadOnlyColorRGBA color = Scene.getInstance().getLandColor();
        if (color != null) {
            colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
        }
        colorActionListener = new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final float[] newColor = colorChooser.getColor().getComponents(null);
                final ColorRGBA rgba = new ColorRGBA(newColor[0], newColor[1], newColor[2], 0.5f);
                if (!Scene.getInstance().getLandColor().equals(rgba)) {
                    final ChangeLandColorCommand cmd = new ChangeLandColorCommand();
                    Scene.getInstance().setLandColor(rgba);
                    Scene.getInstance().setEdited(true);
                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                }
            }
        };
    } else {
        if (Scene.getInstance().getTextureMode() != TextureMode.None) {
            // when the user wants to set the color, automatically switch to no texture
            if (JOptionPane.showConfirmDialog(this, "To set color for an individual part, we have to remove the texture. Is that OK?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
                return;
            }
            Scene.getInstance().setTextureMode(TextureMode.None);
        }
        final ReadOnlyColorRGBA color = selectedPart.getColor();
        if (color != null) {
            colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
        }
        colorActionListener = new ActionListener() {

            private boolean changed;

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart == null) {
                    return;
                }
                final Color c = colorChooser.getColor();
                final float[] newColor = c.getComponents(null);
                final boolean restartPrintPreview = Scene.getInstance().getRoofColor().equals(ColorRGBA.WHITE) || c.equals(Color.WHITE);
                final ColorRGBA color = new ColorRGBA(newColor[0], newColor[1], newColor[2], newColor[3]);
                final JPanel panel = new JPanel();
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
                if (selectedPart instanceof Wall) {
                    final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
                    final JRadioButton rb2 = new JRadioButton("All Walls Connected to This One (Direct and Indirect)");
                    final JRadioButton rb3 = new JRadioButton("All Walls of this Building");
                    final JRadioButton rb4 = new JRadioButton("All Walls");
                    panel.add(rb1);
                    panel.add(rb2);
                    panel.add(rb3);
                    panel.add(rb4);
                    final ButtonGroup bg = new ButtonGroup();
                    bg.add(rb1);
                    bg.add(rb2);
                    bg.add(rb3);
                    bg.add(rb4);
                    final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                    final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                    final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Color");
                    while (true) {
                        changed = false;
                        dialog.setVisible(true);
                        final Object choice = optionPane.getValue();
                        if (choice == options[1]) {
                            break;
                        } else {
                            changed = !color.equals(selectedPart.getColor());
                            if (rb1.isSelected()) {
                                // apply to only this part
                                if (changed) {
                                    final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
                                    selectedPart.setColor(color);
                                    selectedPart.draw();
                                    SceneManager.getInstance().refresh();
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else if (rb2.isSelected()) {
                                final Wall w = (Wall) selectedPart;
                                if (!changed) {
                                    w.visitNeighbors(new WallVisitor() {

                                        @Override
                                        public void visit(final Wall currentWall, final Snap prev, final Snap next) {
                                            if (!color.equals(currentWall.getColor())) {
                                                changed = true;
                                            }
                                        }
                                    });
                                }
                                if (changed) {
                                    final ChangeColorOfConnectedWallsCommand cmd = new ChangeColorOfConnectedWallsCommand(w);
                                    Scene.getInstance().setColorOfConnectedWalls(w, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else if (rb3.isSelected()) {
                                if (!changed) {
                                    for (final HousePart x : Scene.getInstance().getPartsOfSameTypeInBuilding(selectedPart)) {
                                        if (!color.equals(x.getColor())) {
                                            changed = true;
                                            break;
                                        }
                                    }
                                }
                                if (changed) {
                                    final ChangeBuildingColorCommand cmd = new ChangeBuildingColorCommand(selectedPart);
                                    Scene.getInstance().setPartColorOfBuilding(selectedPart, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else if (rb4.isSelected()) {
                                if (!changed) {
                                    for (final HousePart x : Scene.getInstance().getAllPartsOfSameType(selectedPart)) {
                                        if (!color.equals(x.getColor())) {
                                            changed = true;
                                            break;
                                        }
                                    }
                                }
                                if (changed) {
                                    final ChangeColorOfAllPartsOfSameTypeCommand cmd = new ChangeColorOfAllPartsOfSameTypeCommand(selectedPart);
                                    Scene.getInstance().setColorOfAllPartsOfSameType(selectedPart, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            }
                            // remember the color decision for the next wall to be added
                            Scene.getInstance().setWallColor(color);
                            if (choice == options[0]) {
                                break;
                            }
                        }
                    }
                } else if (selectedPart instanceof Roof) {
                    final JRadioButton rb1 = new JRadioButton("Only this Roof", true);
                    final JRadioButton rb2 = new JRadioButton("All Roofs");
                    panel.add(rb1);
                    panel.add(rb2);
                    final ButtonGroup bg = new ButtonGroup();
                    bg.add(rb1);
                    bg.add(rb2);
                    final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                    final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                    final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Roof Color");
                    while (true) {
                        changed = false;
                        dialog.setVisible(true);
                        final Object choice = optionPane.getValue();
                        if (choice == options[1]) {
                            break;
                        } else {
                            changed = !color.equals(selectedPart.getColor());
                            if (rb1.isSelected()) {
                                // apply to only this part
                                if (changed) {
                                    final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
                                    selectedPart.setColor(color);
                                    selectedPart.draw();
                                    SceneManager.getInstance().refresh();
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else {
                                if (!changed) {
                                    for (final HousePart x : Scene.getInstance().getAllPartsOfSameType(selectedPart)) {
                                        if (!color.equals(x.getColor())) {
                                            changed = true;
                                            break;
                                        }
                                    }
                                }
                                if (changed) {
                                    final ChangeColorOfAllPartsOfSameTypeCommand cmd = new ChangeColorOfAllPartsOfSameTypeCommand(selectedPart);
                                    Scene.getInstance().setColorOfAllPartsOfSameType(selectedPart, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            }
                            // remember the color decision for the next roof to be added
                            Scene.getInstance().setRoofColor(color);
                            if (choice == options[0]) {
                                break;
                            }
                        }
                    }
                } else if (selectedPart instanceof Foundation) {
                    final JRadioButton rb1 = new JRadioButton("Only this Foundation", true);
                    final JRadioButton rb2 = new JRadioButton("All Foundations");
                    panel.add(rb1);
                    panel.add(rb2);
                    final ButtonGroup bg = new ButtonGroup();
                    bg.add(rb1);
                    bg.add(rb2);
                    final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                    final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                    final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Foundation Color");
                    while (true) {
                        changed = false;
                        dialog.setVisible(true);
                        final Object choice = optionPane.getValue();
                        if (choice == options[1]) {
                            break;
                        } else {
                            changed = !color.equals(selectedPart.getColor());
                            if (rb1.isSelected()) {
                                // apply to only this part
                                if (changed) {
                                    final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
                                    selectedPart.setColor(color);
                                    selectedPart.draw();
                                    SceneManager.getInstance().refresh();
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else {
                                if (!changed) {
                                    for (final HousePart x : Scene.getInstance().getAllPartsOfSameType(selectedPart)) {
                                        if (!color.equals(x.getColor())) {
                                            changed = true;
                                            break;
                                        }
                                    }
                                }
                                if (changed) {
                                    final ChangeColorOfAllPartsOfSameTypeCommand cmd = new ChangeColorOfAllPartsOfSameTypeCommand(selectedPart);
                                    Scene.getInstance().setColorOfAllPartsOfSameType(selectedPart, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            }
                            // remember the color decision for the next foundation to be added
                            Scene.getInstance().setFoundationColor(color);
                            if (choice == options[0]) {
                                break;
                            }
                        }
                    }
                } else {
                    changed = !color.equals(selectedPart.getColor());
                    if (changed) {
                        final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
                        selectedPart.setColor(color);
                        selectedPart.draw();
                        SceneManager.getInstance().refresh();
                        SceneManager.getInstance().getUndoManager().addEdit(cmd);
                        if (selectedPart instanceof Door) {
                            // remember the color decision for the next part
                            Scene.getInstance().setDoorColor(color);
                        } else if (selectedPart instanceof Floor) {
                            Scene.getInstance().setFloorColor(color);
                        }
                    }
                }
                Scene.getInstance().setTextureMode(Scene.getInstance().getTextureMode());
                if (restartPrintPreview && PrintController.getInstance().isPrintPreview()) {
                    PrintController.getInstance().restartAnimation();
                }
                MainPanel.getInstance().getEnergyButton().setSelected(false);
                Scene.getInstance().setEdited(changed);
            }
        };
    }
    JColorChooser.createDialog(this, "Select Color", true, colorChooser, colorActionListener, null).setVisible(true);
}
Also used : ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) JPanel(javax.swing.JPanel) Wall(org.concord.energy3d.model.Wall) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) Snap(org.concord.energy3d.model.Snap) ChangeColorOfConnectedWallsCommand(org.concord.energy3d.undo.ChangeColorOfConnectedWallsCommand) WallVisitor(org.concord.energy3d.util.WallVisitor) Roof(org.concord.energy3d.model.Roof) ChangePartColorCommand(org.concord.energy3d.undo.ChangePartColorCommand) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) ChangeLandColorCommand(org.concord.energy3d.undo.ChangeLandColorCommand) Floor(org.concord.energy3d.model.Floor) ChangeColorOfAllPartsOfSameTypeCommand(org.concord.energy3d.undo.ChangeColorOfAllPartsOfSameTypeCommand) Color(java.awt.Color) JOptionPane(javax.swing.JOptionPane) Door(org.concord.energy3d.model.Door) ActionListener(java.awt.event.ActionListener) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) ButtonGroup(javax.swing.ButtonGroup) ChangeBuildingColorCommand(org.concord.energy3d.undo.ChangeBuildingColorCommand) JDialog(javax.swing.JDialog)

Example 7 with WallVisitor

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

the class Scene method showOutlineOfConnectedWalls.

public void showOutlineOfConnectedWalls(final Wall w, final boolean b) {
    w.visitNeighbors(new WallVisitor() {

        @Override
        public void visit(final Wall currentWall, final Snap prev, final Snap next) {
            currentWall.showOutline(b);
            currentWall.draw();
        }
    });
    SceneManager.getInstance().refresh();
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) Wall(org.concord.energy3d.model.Wall) Snap(org.concord.energy3d.model.Snap)

Example 8 with WallVisitor

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

the class Scene method setColorOfConnectedWalls.

public void setColorOfConnectedWalls(final Wall w, final ColorRGBA color) {
    w.visitNeighbors(new WallVisitor() {

        @Override
        public void visit(final Wall currentWall, final Snap prev, final Snap next) {
            currentWall.setColor(color);
            currentWall.draw();
        }
    });
    SceneManager.getInstance().refresh();
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) Wall(org.concord.energy3d.model.Wall) Snap(org.concord.energy3d.model.Snap)

Example 9 with WallVisitor

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

the class PopupMenuForWall method getPopupMenuForWall.

static JPopupMenu getPopupMenuForWall() {
    if (popupMenuForWall == null) {
        final JMenuItem miPaste = new JMenuItem("Paste");
        miPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
        miPaste.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                SceneManager.getTaskManager().update(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        Scene.getInstance().pasteToPickedLocationOnWall();
                        Scene.getInstance().setEdited(true);
                        return null;
                    }
                });
            }
        });
        final JMenuItem miClear = new JMenuItem("Clear");
        miClear.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                SceneManager.getTaskManager().update(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        Scene.getInstance().removeAllChildren(SceneManager.getInstance().getSelectedPart());
                        EventQueue.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                MainPanel.getInstance().getEnergyButton().setSelected(false);
                                Scene.getInstance().setEdited(true);
                            }
                        });
                        return null;
                    }
                });
            }
        });
        final JMenuItem miDeleteAllConnectedWalls = new JMenuItem("Delete All Connected Walls");
        miDeleteAllConnectedWalls.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Wall) {
                    Scene.getInstance().deleteAllConnectedWalls((Wall) selectedPart);
                }
            }
        });
        final JMenuItem miThickness = new JMenuItem("Thickness...");
        miThickness.addActionListener(new ActionListener() {

            // remember the scope selection as the next action will likely be applied to the same scope
            private int selectedScopeIndex = 0;

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (!(selectedPart instanceof Wall)) {
                    return;
                }
                final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
                final Wall w = (Wall) selectedPart;
                final String title = "<html>Thickness of " + partInfo + "</html>";
                final String footnote = "<html><hr><font size=2>Thickness of wall is in meters.<hr></html>";
                final JPanel gui = new JPanel(new BorderLayout());
                final JPanel panel = new JPanel();
                gui.add(panel, BorderLayout.CENTER);
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
                final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
                final JRadioButton rb2 = new JRadioButton("All Walls on This Foundation");
                final JRadioButton rb3 = new JRadioButton("All Walls");
                panel.add(rb1);
                panel.add(rb2);
                panel.add(rb3);
                final ButtonGroup bg = new ButtonGroup();
                bg.add(rb1);
                bg.add(rb2);
                bg.add(rb3);
                switch(selectedScopeIndex) {
                    case 0:
                        rb1.setSelected(true);
                        break;
                    case 1:
                        rb2.setSelected(true);
                        break;
                    case 2:
                        rb3.setSelected(true);
                        break;
                }
                final JTextField inputField = new JTextField(EnergyPanel.TWO_DECIMALS.format(w.getThickness() * Scene.getInstance().getAnnotationScale()));
                gui.add(inputField, BorderLayout.SOUTH);
                final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Thickness");
                while (true) {
                    inputField.selectAll();
                    inputField.requestFocusInWindow();
                    dialog.setVisible(true);
                    final Object choice = optionPane.getValue();
                    if (choice == options[1] || choice == null) {
                        break;
                    } else {
                        double val = 0;
                        boolean ok = true;
                        try {
                            val = Double.parseDouble(inputField.getText());
                        } catch (final NumberFormatException exception) {
                            JOptionPane.showMessageDialog(MainFrame.getInstance(), inputField.getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
                            ok = false;
                        }
                        if (ok) {
                            if (val < 0.1 || val > 10) {
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), "The thickness of a wall must be between 0.1 and 10 meters.", "Range Error", JOptionPane.ERROR_MESSAGE);
                            } else {
                                val /= Scene.getInstance().getAnnotationScale();
                                Wall.setDefaultThickess(val);
                                boolean changed = Math.abs(val - w.getThickness()) > 0.000001;
                                if (rb1.isSelected()) {
                                    if (changed) {
                                        final ChangeWallThicknessCommand c = new ChangeWallThicknessCommand(w);
                                        w.setThickness(val);
                                        w.draw();
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 0;
                                } else if (rb2.isSelected()) {
                                    final Foundation foundation = w.getTopContainer();
                                    if (!changed) {
                                        for (final Wall x : foundation.getWalls()) {
                                            if (Math.abs(val - x.getThickness()) > 0.000001) {
                                                changed = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (changed) {
                                        final ChangeFoundationWallThicknessCommand c = new ChangeFoundationWallThicknessCommand(foundation);
                                        foundation.setThicknessOfWalls(val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 1;
                                } else if (rb3.isSelected()) {
                                    if (!changed) {
                                        for (final Wall x : Scene.getInstance().getAllWalls()) {
                                            if (Math.abs(val - x.getThickness()) > 0.000001) {
                                                changed = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (changed) {
                                        final ChangeThicknessForAllWallsCommand c = new ChangeThicknessForAllWallsCommand(w);
                                        Scene.getInstance().setThicknessForAllWalls(val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 2;
                                }
                                if (changed) {
                                    updateAfterEdit();
                                }
                                if (choice == options[0]) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        });
        final JMenuItem miHeight = new JMenuItem("Height...");
        miHeight.addActionListener(new ActionListener() {

            // remember the scope selection as the next action will likely be applied to the same scope
            private int selectedScopeIndex = 0;

            private boolean changed;

            private double val;

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (!(selectedPart instanceof Wall)) {
                    return;
                }
                final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
                final Wall w = (Wall) selectedPart;
                final String title = "<html>Height of " + partInfo + "</html>";
                final String footnote = "<html><hr><font size=2>Height of wall is in meters.<hr></html>";
                final JPanel gui = new JPanel(new BorderLayout());
                final JPanel panel = new JPanel();
                gui.add(panel, BorderLayout.CENTER);
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
                final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
                final JRadioButton rb2 = new JRadioButton("All Walls Connected to This One (Direct and Indirect)");
                final JRadioButton rb3 = new JRadioButton("All Walls on This Foundation");
                final JRadioButton rb4 = new JRadioButton("All Walls");
                panel.add(rb1);
                panel.add(rb2);
                panel.add(rb3);
                panel.add(rb4);
                final ButtonGroup bg = new ButtonGroup();
                bg.add(rb1);
                bg.add(rb2);
                bg.add(rb3);
                bg.add(rb4);
                switch(selectedScopeIndex) {
                    case 0:
                        rb1.setSelected(true);
                        break;
                    case 1:
                        rb2.setSelected(true);
                        break;
                    case 2:
                        rb3.setSelected(true);
                        break;
                    case 3:
                        rb4.setSelected(true);
                        break;
                }
                final JTextField inputField = new JTextField(EnergyPanel.TWO_DECIMALS.format(w.getHeight() * Scene.getInstance().getAnnotationScale()));
                gui.add(inputField, BorderLayout.SOUTH);
                final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Height");
                while (true) {
                    inputField.selectAll();
                    inputField.requestFocusInWindow();
                    dialog.setVisible(true);
                    final Object choice = optionPane.getValue();
                    if (choice == options[1] || choice == null) {
                        break;
                    } else {
                        boolean ok = true;
                        try {
                            val = Double.parseDouble(inputField.getText());
                        } catch (final NumberFormatException exception) {
                            JOptionPane.showMessageDialog(MainFrame.getInstance(), inputField.getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
                            ok = false;
                        }
                        if (ok) {
                            if (val < 1 || val > 1000) {
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), "The height of a wall must be between 1 and 1000 meters.", "Range Error", JOptionPane.ERROR_MESSAGE);
                            } else {
                                val /= Scene.getInstance().getAnnotationScale();
                                changed = Math.abs(val - w.getHeight()) > 0.000001;
                                if (rb1.isSelected()) {
                                    if (changed) {
                                        final ChangeWallHeightCommand c = new ChangeWallHeightCommand(w);
                                        w.setHeight(val, true);
                                        Scene.getInstance().redrawAllWallsNow();
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                        final Foundation foundation = w.getTopContainer();
                                        if (foundation.hasSolarReceiver()) {
                                            foundation.drawSolarReceiver();
                                            for (final HousePart x : Scene.getInstance().getParts()) {
                                                if (x instanceof FresnelReflector) {
                                                    final FresnelReflector reflector = (FresnelReflector) x;
                                                    if (foundation == reflector.getReceiver() && reflector.isSunBeamVisible()) {
                                                        reflector.drawSunBeam();
                                                    }
                                                } else if (x instanceof Mirror) {
                                                    final Mirror heliostat = (Mirror) x;
                                                    if (foundation == heliostat.getReceiver() && heliostat.isSunBeamVisible()) {
                                                        heliostat.drawSunBeam();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    selectedScopeIndex = 0;
                                } else if (rb2.isSelected()) {
                                    if (!changed) {
                                        w.visitNeighbors(new WallVisitor() {

                                            @Override
                                            public void visit(final Wall currentWall, final Snap prev, final Snap next) {
                                                if (Math.abs(val - currentWall.getHeight()) > 0.000001) {
                                                    changed = true;
                                                }
                                            }
                                        });
                                    }
                                    if (changed) {
                                        final ChangeHeightForConnectedWallsCommand c = new ChangeHeightForConnectedWallsCommand(w);
                                        Scene.getInstance().setHeightOfConnectedWalls(w, val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 1;
                                } else if (rb3.isSelected()) {
                                    final Foundation foundation = w.getTopContainer();
                                    if (!changed) {
                                        for (final Wall x : foundation.getWalls()) {
                                            if (Math.abs(val - x.getHeight()) > 0.000001) {
                                                changed = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (changed) {
                                        final ChangeFoundationWallHeightCommand c = new ChangeFoundationWallHeightCommand(foundation);
                                        foundation.setHeightOfWalls(val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 2;
                                } else if (rb4.isSelected()) {
                                    if (!changed) {
                                        for (final Wall x : Scene.getInstance().getAllWalls()) {
                                            if (Math.abs(val - x.getHeight()) > 0.000001) {
                                                changed = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (changed) {
                                        final ChangeHeightForAllWallsCommand c = new ChangeHeightForAllWallsCommand(w);
                                        Scene.getInstance().setHeightForAllWalls(val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 3;
                                }
                                if (changed) {
                                    updateAfterEdit();
                                }
                                if (choice == options[0]) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        });
        final JCheckBoxMenuItem miOutline = new JCheckBoxMenuItem("Outline...", true);
        miOutline.addActionListener(new ActionListener() {

            // remember the scope selection as the next action will likely be applied to the same scope
            private int selectedScopeIndex = 0;

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (!(selectedPart instanceof Wall)) {
                    return;
                }
                final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
                final Wall w = (Wall) selectedPart;
                final String title = "<html>Outline of " + partInfo + "</html>";
                final String footnote = "<html>Hiding outline may create a continuous effect of a polygon<br>formed by many walls.</html>";
                final JPanel gui = new JPanel(new BorderLayout());
                final JPanel panel = new JPanel();
                gui.add(panel, BorderLayout.CENTER);
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
                final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
                final JRadioButton rb2 = new JRadioButton("All Walls Connected to This One (Direct and Indirect)");
                final JRadioButton rb3 = new JRadioButton("All Walls on This Foundation");
                final JRadioButton rb4 = new JRadioButton("All Walls");
                panel.add(rb1);
                panel.add(rb2);
                panel.add(rb3);
                panel.add(rb4);
                final ButtonGroup bg = new ButtonGroup();
                bg.add(rb1);
                bg.add(rb2);
                bg.add(rb3);
                bg.add(rb4);
                switch(selectedScopeIndex) {
                    case 0:
                        rb1.setSelected(true);
                        break;
                    case 1:
                        rb2.setSelected(true);
                        break;
                    case 2:
                        rb3.setSelected(true);
                        break;
                    case 3:
                        rb4.setSelected(true);
                        break;
                }
                final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Outline");
                while (true) {
                    dialog.setVisible(true);
                    final Object choice = optionPane.getValue();
                    if (choice == options[1] || choice == null) {
                        break;
                    } else {
                        if (rb1.isSelected()) {
                            // final ChangeWallHeightCommand c = new ChangeWallHeightCommand(w);
                            w.showOutline(miOutline.isSelected());
                            w.draw();
                            // SceneManager.getInstance().getUndoManager().addEdit(c);
                            selectedScopeIndex = 0;
                        } else if (rb2.isSelected()) {
                            // final ChangeHeightForConnectedWallsCommand c = new ChangeHeightForConnectedWallsCommand(w);
                            Scene.getInstance().showOutlineOfConnectedWalls(w, miOutline.isSelected());
                            // SceneManager.getInstance().getUndoManager().addEdit(c);
                            selectedScopeIndex = 1;
                        } else if (rb3.isSelected()) {
                            final Foundation foundation = w.getTopContainer();
                            // final ChangeFoundationWallHeightCommand c = new ChangeFoundationWallHeightCommand(foundation);
                            foundation.showOutlineOfWalls(miOutline.isSelected());
                            // SceneManager.getInstance().getUndoManager().addEdit(c);
                            selectedScopeIndex = 2;
                        } else if (rb4.isSelected()) {
                            // final ChangeHeightForAllWallsCommand c = new ChangeHeightForAllWallsCommand(w);
                            Scene.getInstance().showOutlineForAllWalls(miOutline.isSelected());
                            // SceneManager.getInstance().getUndoManager().addEdit(c);
                            selectedScopeIndex = 3;
                        }
                        updateAfterEdit();
                        if (choice == options[0]) {
                            break;
                        }
                    }
                }
            }
        });
        popupMenuForWall = createPopupMenu(false, false, new Runnable() {

            @Override
            public void run() {
                final HousePart copyBuffer = Scene.getInstance().getCopyBuffer();
                miPaste.setEnabled(copyBuffer instanceof Window || copyBuffer instanceof SolarPanel || copyBuffer instanceof Rack);
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Wall) {
                    final Wall w = (Wall) selectedPart;
                    Util.selectSilently(miOutline, w.outlineShown());
                }
            }
        });
        popupMenuForWall.add(miPaste);
        popupMenuForWall.add(miDeleteAllConnectedWalls);
        popupMenuForWall.add(miClear);
        popupMenuForWall.addSeparator();
        popupMenuForWall.add(colorAction);
        popupMenuForWall.add(miOutline);
        popupMenuForWall.add(miThickness);
        popupMenuForWall.add(miHeight);
        popupMenuForWall.add(createInsulationMenuItem(false));
        popupMenuForWall.add(createVolumetricHeatCapacityMenuItem());
        popupMenuForWall.addSeparator();
        final JMenu textureMenu = new JMenu("Texture");
        popupMenuForWall.add(textureMenu);
        final ButtonGroup textureGroup = new ButtonGroup();
        final JRadioButtonMenuItem rbmiTextureNone = new JRadioButtonMenuItem("No Texture");
        rbmiTextureNone.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeBuildingTextureCommand c = new ChangeBuildingTextureCommand();
                    Scene.getInstance().setTextureMode(TextureMode.None);
                    Scene.getInstance().setEdited(true);
                    if (MainPanel.getInstance().getEnergyButton().isSelected()) {
                        MainPanel.getInstance().getEnergyButton().setSelected(false);
                    }
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        textureGroup.add(rbmiTextureNone);
        textureMenu.add(rbmiTextureNone);
        final JRadioButtonMenuItem rbmiTextureOutline = new JRadioButtonMenuItem("Outline Texture");
        rbmiTextureOutline.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeBuildingTextureCommand c = new ChangeBuildingTextureCommand();
                    Scene.getInstance().setTextureMode(TextureMode.Simple);
                    Scene.getInstance().setEdited(true);
                    if (MainPanel.getInstance().getEnergyButton().isSelected()) {
                        MainPanel.getInstance().getEnergyButton().setSelected(false);
                    }
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        textureGroup.add(rbmiTextureOutline);
        textureMenu.add(rbmiTextureOutline);
        textureMenu.addSeparator();
        final JRadioButtonMenuItem rbmiTexture01 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_01, "icons/wall_01.png");
        final JRadioButtonMenuItem rbmiTexture02 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_02, "icons/wall_02.png");
        final JRadioButtonMenuItem rbmiTexture03 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_03, "icons/wall_03.png");
        final JRadioButtonMenuItem rbmiTexture04 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_04, "icons/wall_04.png");
        final JRadioButtonMenuItem rbmiTexture05 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_05, "icons/wall_05.png");
        final JRadioButtonMenuItem rbmiTexture06 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_06, "icons/wall_06.png");
        textureGroup.add(rbmiTexture01);
        textureGroup.add(rbmiTexture02);
        textureGroup.add(rbmiTexture03);
        textureGroup.add(rbmiTexture04);
        textureGroup.add(rbmiTexture05);
        textureGroup.add(rbmiTexture06);
        textureMenu.add(rbmiTexture01);
        textureMenu.add(rbmiTexture02);
        textureMenu.add(rbmiTexture03);
        textureMenu.add(rbmiTexture04);
        textureMenu.add(rbmiTexture05);
        textureMenu.add(rbmiTexture06);
        textureMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuSelected(final MenuEvent e) {
                if (Scene.getInstance().getTextureMode() == TextureMode.None) {
                    Util.selectSilently(rbmiTextureNone, true);
                    return;
                }
                if (Scene.getInstance().getTextureMode() == TextureMode.Simple) {
                    Util.selectSilently(rbmiTextureOutline, true);
                    return;
                }
                switch(Scene.getInstance().getWallTextureType()) {
                    case Wall.TEXTURE_01:
                        Util.selectSilently(rbmiTexture01, true);
                        break;
                    case Wall.TEXTURE_02:
                        Util.selectSilently(rbmiTexture02, true);
                        break;
                    case Wall.TEXTURE_03:
                        Util.selectSilently(rbmiTexture03, true);
                        break;
                    case Wall.TEXTURE_04:
                        Util.selectSilently(rbmiTexture04, true);
                        break;
                    case Wall.TEXTURE_05:
                        Util.selectSilently(rbmiTexture05, true);
                        break;
                    case Wall.TEXTURE_06:
                        Util.selectSilently(rbmiTexture06, true);
                        break;
                }
            }

            @Override
            public void menuDeselected(final MenuEvent e) {
                textureMenu.setEnabled(true);
            }

            @Override
            public void menuCanceled(final MenuEvent e) {
                textureMenu.setEnabled(true);
            }
        });
        final JMenu typeMenu = new JMenu("Type");
        popupMenuForWall.add(typeMenu);
        popupMenuForWall.addSeparator();
        final ButtonGroup typeGroup = new ButtonGroup();
        final JRadioButtonMenuItem rbmiSolidWall = new JRadioButtonMenuItem("Solid Wall");
        rbmiSolidWall.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.SOLID_WALL);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiSolidWall);
        typeGroup.add(rbmiSolidWall);
        final JRadioButtonMenuItem rbmiEmpty = new JRadioButtonMenuItem("Empty");
        rbmiEmpty.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.EMPTY);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiEmpty);
        typeGroup.add(rbmiEmpty);
        final JRadioButtonMenuItem rbmiEdges = new JRadioButtonMenuItem("Vertical Edges");
        rbmiEdges.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.VERTICAL_EDGES_ONLY);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiEdges);
        typeGroup.add(rbmiEdges);
        final JRadioButtonMenuItem rbmiColumns = new JRadioButtonMenuItem("Columns");
        rbmiColumns.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.COLUMNS_ONLY);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiColumns);
        typeGroup.add(rbmiColumns);
        final JRadioButtonMenuItem rbmiRails = new JRadioButtonMenuItem("Rails");
        rbmiRails.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.RAILS_ONLY);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiRails);
        typeGroup.add(rbmiRails);
        final JRadioButtonMenuItem rbmiColumnsAndRailings = new JRadioButtonMenuItem("Columns & Railings");
        rbmiColumnsAndRailings.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.COLUMNS_RAILS);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiColumnsAndRailings);
        typeGroup.add(rbmiColumnsAndRailings);
        final JRadioButtonMenuItem rbmiFence = new JRadioButtonMenuItem("Fence");
        rbmiFence.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.FENCE);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiFence);
        typeGroup.add(rbmiFence);
        final JRadioButtonMenuItem rbmiSteelFrame = new JRadioButtonMenuItem("Steel Frame");
        rbmiSteelFrame.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.STEEL_FRAME);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiSteelFrame);
        typeGroup.add(rbmiSteelFrame);
        typeMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuSelected(final MenuEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Wall) {
                    final Wall wall = (Wall) selectedPart;
                    switch(wall.getType()) {
                        case Wall.SOLID_WALL:
                            Util.selectSilently(rbmiSolidWall, true);
                            break;
                        case Wall.EMPTY:
                            Util.selectSilently(rbmiEmpty, true);
                            break;
                        case Wall.VERTICAL_EDGES_ONLY:
                            Util.selectSilently(rbmiEdges, true);
                            break;
                        case Wall.COLUMNS_ONLY:
                            Util.selectSilently(rbmiColumns, true);
                            break;
                        case Wall.RAILS_ONLY:
                            Util.selectSilently(rbmiRails, true);
                            break;
                        case Wall.COLUMNS_RAILS:
                            Util.selectSilently(rbmiColumnsAndRailings, true);
                            break;
                        case Wall.STEEL_FRAME:
                            Util.selectSilently(rbmiSteelFrame, true);
                            break;
                    }
                }
            }

            @Override
            public void menuDeselected(final MenuEvent e) {
                typeMenu.setEnabled(true);
            }

            @Override
            public void menuCanceled(final MenuEvent e) {
                typeMenu.setEnabled(true);
            }
        });
        JMenuItem mi = new JMenuItem("Daily Energy Analysis...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().adjustCellSize()) {
                    return;
                }
                if (SceneManager.getInstance().getSelectedPart() instanceof Wall) {
                    new EnergyDailyAnalysis().show("Daily Energy for Wall");
                }
            }
        });
        popupMenuForWall.add(mi);
        mi = new JMenuItem("Annual Energy Analysis...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().adjustCellSize()) {
                    return;
                }
                if (SceneManager.getInstance().getSelectedPart() instanceof Wall) {
                    new EnergyAnnualAnalysis().show("Annual Energy for Wall");
                }
            }
        });
        popupMenuForWall.add(mi);
    }
    return popupMenuForWall;
}
Also used : JPanel(javax.swing.JPanel) EnergyAnnualAnalysis(org.concord.energy3d.simulation.EnergyAnnualAnalysis) ChangeWallHeightCommand(org.concord.energy3d.undo.ChangeWallHeightCommand) ItemEvent(java.awt.event.ItemEvent) Wall(org.concord.energy3d.model.Wall) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) MenuListener(javax.swing.event.MenuListener) BoxLayout(javax.swing.BoxLayout) JTextField(javax.swing.JTextField) Snap(org.concord.energy3d.model.Snap) Callable(java.util.concurrent.Callable) ChangeHeightForConnectedWallsCommand(org.concord.energy3d.undo.ChangeHeightForConnectedWallsCommand) ChangeFoundationWallThicknessCommand(org.concord.energy3d.undo.ChangeFoundationWallThicknessCommand) WallVisitor(org.concord.energy3d.util.WallVisitor) Rack(org.concord.energy3d.model.Rack) BorderLayout(java.awt.BorderLayout) Foundation(org.concord.energy3d.model.Foundation) JMenuItem(javax.swing.JMenuItem) HousePart(org.concord.energy3d.model.HousePart) MenuEvent(javax.swing.event.MenuEvent) Window(org.concord.energy3d.model.Window) FresnelReflector(org.concord.energy3d.model.FresnelReflector) ChangeThicknessForAllWallsCommand(org.concord.energy3d.undo.ChangeThicknessForAllWallsCommand) ChangeWallThicknessCommand(org.concord.energy3d.undo.ChangeWallThicknessCommand) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) ChangeHeightForAllWallsCommand(org.concord.energy3d.undo.ChangeHeightForAllWallsCommand) JOptionPane(javax.swing.JOptionPane) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) ChangeWallTypeCommand(org.concord.energy3d.undo.ChangeWallTypeCommand) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ChangeFoundationWallHeightCommand(org.concord.energy3d.undo.ChangeFoundationWallHeightCommand) SolarPanel(org.concord.energy3d.model.SolarPanel) EnergyDailyAnalysis(org.concord.energy3d.simulation.EnergyDailyAnalysis) ItemListener(java.awt.event.ItemListener) ChangeBuildingTextureCommand(org.concord.energy3d.undo.ChangeBuildingTextureCommand) Mirror(org.concord.energy3d.model.Mirror) JDialog(javax.swing.JDialog) JMenu(javax.swing.JMenu)

Example 10 with WallVisitor

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

the class Wall method drawRails.

private void drawRails(final double distance, final boolean fence) {
    rails.setDefaultColor(getColor());
    final FloatBuffer vertexBuffer = rails.getMeshData().getVertexBuffer();
    final FloatBuffer normalBuffer = rails.getMeshData().getNormalBuffer();
    vertexBuffer.rewind();
    normalBuffer.rewind();
    vertexBuffer.limit(vertexBuffer.capacity());
    normalBuffer.limit(normalBuffer.capacity());
    final ReadOnlyVector3 o = getAbsPoint(0);
    final ReadOnlyVector3 u = getAbsPoint(2).subtract(o, null);
    final Vector3 v = getAbsPoint(1).subtract(o, null);
    final int cols = (int) Math.max(2, u.length() / distance);
    if (fence) {
        Vector3 dir = v.clone().normalizeLocal().multiplyLocal(railRadius * 2);
        final Vector3 p10 = v.clone();
        final Vector3 p32 = getAbsPoint(3).subtractLocal(getAbsPoint(2));
        p10.multiplyLocal(1, 1, 0.3);
        p32.multiplyLocal(1, 1, 0.3);
        Util.addPointToQuad(normal, getAbsPoint(0).addLocal(p10), getAbsPoint(2).addLocal(p32), dir, vertexBuffer, normalBuffer);
        Util.addPointToQuad(normal, getAbsPoint(1).subtractLocal(p10), getAbsPoint(3).subtractLocal(p32), dir, vertexBuffer, normalBuffer);
        dir = new Vector3(u).normalizeLocal().multiplyLocal(railRadius);
        final Vector3 dir5 = new Vector3(u).normalizeLocal().multiplyLocal(railRadius * 3);
        // v.multiplyLocal(1.2);
        final Vector3 p = new Vector3();
        for (int col = 0; col <= cols; col++) {
            u.multiply((double) col / cols, p).addLocal(o.getX(), o.getY(), o.getZ());
            Util.addPointToQuad(normal, p, p.add(v, null), col % 10 == 0 ? dir5 : dir, vertexBuffer, normalBuffer);
        }
    } else {
        floor = getFloor();
        if (floor == null) {
            visitNeighbors(new WallVisitor() {

                @Override
                public void visit(final Wall currentWall, final Snap prev, final Snap next) {
                    final Floor f = currentWall.getFloor();
                    if (f != null) {
                        floor = f;
                    }
                }
            });
        }
        if (floor == null) {
            Vector3 dir = v.clone().normalizeLocal().multiplyLocal(railRadius * 3);
            final double heightRatio = 0.33;
            final Vector3 p10 = v.clone();
            final Vector3 p32 = getAbsPoint(3).subtractLocal(getAbsPoint(2));
            p10.multiplyLocal(1, 1, heightRatio);
            p32.multiplyLocal(1, 1, heightRatio);
            Util.addPointToQuad(normal, getAbsPoint(0).addLocal(p10), getAbsPoint(2).addLocal(p32), dir, vertexBuffer, normalBuffer);
            dir = new Vector3(u).normalizeLocal().multiplyLocal(railRadius);
            v.multiplyLocal(heightRatio);
            final Vector3 p = new Vector3();
            for (int col = 0; col <= cols; col++) {
                u.multiply((double) col / cols, p).addLocal(o.getX(), o.getY(), o.getZ());
                Util.addPointToQuad(normal, p, p.add(v, null), dir, vertexBuffer, normalBuffer);
            }
        } else {
            final double z0 = floor.getAbsPoint(0).getZ();
            Vector3 dir = new Vector3(v).normalizeLocal().multiplyLocal(railRadius * 3);
            Util.addPointToQuad(normal, getAbsPoint(1), getAbsPoint(3), dir, vertexBuffer, normalBuffer);
            dir = new Vector3(u).normalizeLocal().multiplyLocal(railRadius);
            Vector3 q = getAbsPoint(1);
            Util.addPointToQuad(normal, q, new Vector3(q.getX(), q.getY(), z0), dir, vertexBuffer, normalBuffer);
            q = getAbsPoint(3);
            Util.addPointToQuad(normal, q, new Vector3(q.getX(), q.getY(), z0), dir, vertexBuffer, normalBuffer);
            q = new Vector3(0, 0, q.getZ() - z0);
            final Vector3 p = new Vector3();
            for (int col = 1; col < cols; col++) {
                u.multiply((double) col / cols, p).addLocal(o.getX(), o.getY(), z0);
                Util.addPointToQuad(normal, p, p.add(q, null), dir, vertexBuffer, normalBuffer);
            }
        }
    }
    vertexBuffer.limit(vertexBuffer.position());
    normalBuffer.limit(normalBuffer.position());
    rails.getMeshData().updateVertexCount();
    rails.updateModelBound();
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArdorVector3Point(org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point) PickingHint(com.ardor3d.scenegraph.hint.PickingHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point)

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