Search in sources :

Example 21 with OrientedBoundingBox

use of com.ardor3d.bounding.OrientedBoundingBox in project energy3d by concord-consortium.

the class PopupMenuForMesh method getPopupMenu.

static JPopupMenu getPopupMenu() {
    if (popupMenuForMesh == null) {
        final JMenuItem miInfo = new JMenuItem("Mesh");
        miInfo.setEnabled(false);
        miInfo.setOpaque(true);
        miInfo.setBackground(Config.isMac() ? Color.BLACK : Color.GRAY);
        miInfo.setForeground(Color.WHITE);
        final JMenuItem miMessThickness = new JMenuItem("Thickness...");
        miMessThickness.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        final Node n = m.getParent();
                        final String title = "<html>Adjust the distance between two mesh faces to create some thickness<br>A larger thickness also mitigates the z-fighting effect.</html>";
                        while (true) {
                            final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), title, f.getMeshThickness(n) * Scene.getInstance().getAnnotationScale());
                            if (newValue == null) {
                                break;
                            } else {
                                try {
                                    final double val = Double.parseDouble(newValue);
                                    if (val < 0 || val > 1) {
                                        JOptionPane.showMessageDialog(MainFrame.getInstance(), "Thickness must be between 0 and 1 meter.", "Range Error", JOptionPane.ERROR_MESSAGE);
                                    } else {
                                        SceneManager.getTaskManager().update(new Callable<Object>() {

                                            @Override
                                            public Object call() throws Exception {
                                                f.setMeshThickness(n, val / Scene.getInstance().getAnnotationScale());
                                                f.draw();
                                                return null;
                                            }
                                        });
                                        break;
                                    }
                                } catch (final NumberFormatException exception) {
                                    JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
                                }
                            }
                        }
                    }
                }
            }
        });
        final JMenuItem miReverseNormalVector = new JMenuItem("Reverse Mesh Normal Vector");
        miReverseNormalVector.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    SceneManager.getTaskManager().update(new Callable<Object>() {

                        @Override
                        public Object call() throws Exception {
                            final Mesh m = f.getSelectedMesh();
                            if (m != null) {
                                Util.reverseFace(m);
                                f.getNodeState(m.getParent()).reverseNormalOfMesh(((UserData) m.getUserData()).getMeshIndex());
                                f.draw();
                                updateAfterEdit();
                            }
                            return null;
                        }
                    });
                }
            }
        });
        final JMenuItem miAlignBottom = new JMenuItem("Align Node Bottom with Ground Level");
        miAlignBottom.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                final Node n = m.getParent();
                                if (n != null) {
                                    final OrientedBoundingBox boundingBox = Util.getOrientedBoundingBox(n);
                                    final double zBottom = boundingBox.getCenter().getZ() - boundingBox.getZAxis().getZ() * boundingBox.getExtent().getZ() - f.getHeight();
                                    f.translateImportedNode(n, 0, 0, -zBottom);
                                    f.draw();
                                    updateAfterEdit();
                                }
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miAlignCenter = new JMenuItem("Align Node Center with Foundation Center");
        miAlignCenter.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                final Node n = m.getParent();
                                if (n != null) {
                                    final OrientedBoundingBox boundingBox = Util.getOrientedBoundingBox(n);
                                    final ReadOnlyVector3 shift = boundingBox.getCenter().subtract(f.getAbsCenter(), null);
                                    f.translateImportedNode(n, shift.getX(), shift.getY(), 0);
                                    f.setMeshSelectionVisible(false);
                                    f.draw();
                                    updateAfterEdit();
                                }
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miCopyNode = new JMenuItem("Copy Node");
        miCopyNode.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
        miCopyNode.addActionListener(new ActionListener() {

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

                    @Override
                    public Object call() throws Exception {
                        final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                        if (selectedPart instanceof Foundation) {
                            final Foundation f = (Foundation) selectedPart;
                            final Mesh m = f.getSelectedMesh();
                            if (m != null) {
                                final Node n = m.getParent();
                                Scene.getInstance().setCopyNode(n, f.getNodeState(n));
                            }
                        }
                        return 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 {
                        final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                        if (selectedPart instanceof Foundation) {
                            final Foundation f = (Foundation) selectedPart;
                            final Mesh m = f.getSelectedMesh();
                            if (m != null) {
                                Scene.getInstance().pasteToPickedLocationOnMesh(m);
                                Scene.getInstance().setEdited(true);
                                updateAfterEdit();
                            }
                        }
                        return null;
                    }
                });
            }
        });
        popupMenuForMesh = new JPopupMenu();
        popupMenuForMesh.setInvoker(MainPanel.getInstance().getCanvasPanel());
        popupMenuForMesh.addPopupMenuListener(new PopupMenuListener() {

            @Override
            public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        String name = f.getNodeState(m.getParent()).getName();
                        if (name == null) {
                            name = "Undefined";
                        }
                        miInfo.setText(m.getName() + " (" + name + ")");
                        final OrientedBoundingBox boundingBox = Util.getOrientedBoundingBox(m.getParent());
                        final ReadOnlyVector3 center = boundingBox.getCenter();
                        final double zBottom = center.getZ() - boundingBox.getZAxis().getZ() * boundingBox.getExtent().getZ();
                        miAlignBottom.setEnabled(!Util.isZero(zBottom - f.getHeight()));
                        final Vector3 foundationCenter = f.getAbsCenter();
                        miAlignCenter.setEnabled(!Util.isEqual(new Vector2(foundationCenter.getX(), foundationCenter.getY()), new Vector2(center.getX(), center.getY())));
                        final HousePart copyBuffer = Scene.getInstance().getCopyBuffer();
                        miPaste.setEnabled(copyBuffer instanceof SolarPanel || copyBuffer instanceof Rack);
                    }
                }
            }

            @Override
            public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
                miAlignBottom.setEnabled(true);
                miAlignCenter.setEnabled(true);
            }

            @Override
            public void popupMenuCanceled(final PopupMenuEvent e) {
                miAlignBottom.setEnabled(true);
                miAlignCenter.setEnabled(true);
            }
        });
        final JMenuItem miDeleteMesh = new JMenuItem("Delete Mesh");
        miDeleteMesh.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                f.deleteMesh(m);
                                updateAfterEdit();
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miRestoreDeletedMeshes = new JMenuItem("Restore Deleted Meshes (Reload Required)");
        miRestoreDeletedMeshes.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                f.restoreDeletedMeshes(m.getParent());
                                updateAfterEdit();
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miCutNode = new JMenuItem("Cut Node");
        miCutNode.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
        miCutNode.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                final Node n = m.getParent();
                                Scene.getInstance().setCopyNode(n, f.getNodeState(n));
                                f.deleteNode(n);
                                updateAfterEdit();
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miMeshProperties = new JMenuItem("Mesh Properties...");
        miMeshProperties.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        final UserData ud = (UserData) m.getUserData();
                        final JPanel gui = new JPanel(new BorderLayout());
                        final String title = "<html>A mesh is a basic unit (e.g., a triangle or a line) of geometry of a structure.</html>";
                        gui.add(new JLabel(title), BorderLayout.NORTH);
                        final JPanel propertiesPanel = new JPanel(new SpringLayout());
                        propertiesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
                        gui.add(propertiesPanel, BorderLayout.CENTER);
                        // index mode
                        JLabel label = new JLabel("Index Mode: ", JLabel.TRAILING);
                        propertiesPanel.add(label);
                        JTextField textField = new JTextField(m.getMeshData().getIndexMode(0) + "", 5);
                        textField.setEditable(false);
                        label.setLabelFor(textField);
                        propertiesPanel.add(textField);
                        // vertex count
                        label = new JLabel("Vertex Count: ", JLabel.TRAILING);
                        propertiesPanel.add(label);
                        textField = new JTextField(m.getMeshData().getVertexCount() + "", 5);
                        textField.setEditable(false);
                        label.setLabelFor(textField);
                        propertiesPanel.add(textField);
                        // normal
                        label = new JLabel("Normal Vector: ", JLabel.TRAILING);
                        propertiesPanel.add(label);
                        final ReadOnlyVector3 normal = ((UserData) m.getUserData()).getNormal();
                        textField = new JTextField("(" + threeDecimalsFormat.format(normal.getX()) + ", " + threeDecimalsFormat.format(normal.getY()) + ", " + threeDecimalsFormat.format(normal.getZ()) + "), relative", 5);
                        textField.setEditable(false);
                        label.setLabelFor(textField);
                        propertiesPanel.add(textField);
                        // color
                        label = new JLabel("Color: ", JLabel.TRAILING);
                        propertiesPanel.add(label);
                        final ReadOnlyColorRGBA rgb = m.getDefaultColor();
                        colorChooser.setColor(new Color(Math.round(rgb.getRed() * 255), Math.round(rgb.getGreen() * 255), Math.round(rgb.getBlue() * 255)));
                        label.setLabelFor(colorChooser);
                        propertiesPanel.add(colorChooser);
                        SpringUtilities.makeCompactGrid(propertiesPanel, 4, 2, 6, 6, 6, 6);
                        if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), gui, "Mesh Properties: " + miInfo.getText(), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
                            final Color color = colorChooser.getColor();
                            m.clearRenderState(StateType.Texture);
                            m.setDefaultColor(new ColorRGBA(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1));
                            final NodeState ns = f.getNodeState(m.getParent());
                            ns.setMeshColor(ud.getMeshIndex(), m.getDefaultColor());
                            f.draw();
                        }
                    }
                }
            }
        });
        final JMenuItem miNodeProperties = new JMenuItem("Node Properties...");
        miNodeProperties.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        final Node n = m.getParent();
                        if (n != null) {
                            final NodeState ns = f.getNodeState(n);
                            final JPanel gui = new JPanel(new BorderLayout());
                            final String title = "<html>A node contains a set of meshes that represent<br>the geometry of the structure.</html>";
                            gui.add(new JLabel(title), BorderLayout.NORTH);
                            final JPanel propertiesPanel = new JPanel(new SpringLayout());
                            propertiesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
                            gui.add(propertiesPanel, BorderLayout.CENTER);
                            // name
                            JLabel label = new JLabel("Name: ", JLabel.TRAILING);
                            propertiesPanel.add(label);
                            final JTextField nameField = new JTextField(ns.getName(), 5);
                            label.setLabelFor(nameField);
                            propertiesPanel.add(nameField);
                            // name
                            label = new JLabel("File: ", JLabel.TRAILING);
                            propertiesPanel.add(label);
                            final JTextField fileField = new JTextField(Util.getFileName(ns.getSourceURL().getPath()), 5);
                            label.setLabelFor(fileField);
                            propertiesPanel.add(fileField);
                            // children count
                            label = new JLabel("Children: ", JLabel.TRAILING);
                            propertiesPanel.add(label);
                            final JTextField textField = new JTextField(n.getNumberOfChildren() + "", 5);
                            textField.setEditable(false);
                            label.setLabelFor(textField);
                            propertiesPanel.add(textField);
                            SpringUtilities.makeCompactGrid(propertiesPanel, 3, 2, 6, 6, 6, 6);
                            if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), gui, "Node Properties", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
                                final String nodeName = nameField.getText();
                                if (nodeName != null && !nodeName.trim().equals("")) {
                                    n.setName(nodeName);
                                    f.getNodeState(n).setName(nodeName);
                                } else {
                                    JOptionPane.showMessageDialog(MainFrame.getInstance(), "Node must have a name!", "Name Error", JOptionPane.ERROR_MESSAGE);
                                }
                            }
                        }
                    }
                }
            }
        });
        popupMenuForMesh.add(miInfo);
        popupMenuForMesh.add(miCutNode);
        popupMenuForMesh.add(miPaste);
        popupMenuForMesh.add(miCopyNode);
        popupMenuForMesh.addSeparator();
        popupMenuForMesh.add(miAlignBottom);
        popupMenuForMesh.add(miAlignCenter);
        popupMenuForMesh.add(miMessThickness);
        popupMenuForMesh.add(miNodeProperties);
        popupMenuForMesh.addSeparator();
        popupMenuForMesh.add(miDeleteMesh);
        popupMenuForMesh.add(miReverseNormalVector);
        popupMenuForMesh.add(miRestoreDeletedMeshes);
        popupMenuForMesh.add(miMeshProperties);
    }
    return popupMenuForMesh;
}
Also used : JPanel(javax.swing.JPanel) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) NodeState(org.concord.energy3d.model.NodeState) UserData(org.concord.energy3d.model.UserData) ActionEvent(java.awt.event.ActionEvent) Node(com.ardor3d.scenegraph.Node) PopupMenuListener(javax.swing.event.PopupMenuListener) JTextField(javax.swing.JTextField) PopupMenuEvent(javax.swing.event.PopupMenuEvent) Callable(java.util.concurrent.Callable) 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) Color(java.awt.Color) Mesh(com.ardor3d.scenegraph.Mesh) JLabel(javax.swing.JLabel) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) JPopupMenu(javax.swing.JPopupMenu) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ActionListener(java.awt.event.ActionListener) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) Vector2(com.ardor3d.math.Vector2) SolarPanel(org.concord.energy3d.model.SolarPanel) SpringLayout(javax.swing.SpringLayout)

Example 22 with OrientedBoundingBox

use of com.ardor3d.bounding.OrientedBoundingBox in project energy3d by concord-consortium.

the class Mirror method isDrawable.

@Override
public boolean isDrawable() {
    if (container == null) {
        return true;
    }
    if (mesh.getWorldBound() == null) {
        return true;
    }
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    if (selectedPart == null || selectedPart.isDrawCompleted()) {
        // if nothing is really selected, skip overlap check
        return true;
    }
    final OrientedBoundingBox bound = (OrientedBoundingBox) mesh.getWorldBound().clone(null);
    bound.setExtent(bound.getExtent().divide(1.1, null).addLocal(0, 0, 1));
    for (final HousePart child : container.getChildren()) {
        if (child != this && child instanceof Mirror && bound.intersects(child.mesh.getWorldBound())) {
            return false;
        }
    }
    return true;
}
Also used : OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox)

Example 23 with OrientedBoundingBox

use of com.ardor3d.bounding.OrientedBoundingBox in project energy3d by concord-consortium.

the class ParabolicDish method isDrawable.

@Override
public boolean isDrawable() {
    if (container == null) {
        return true;
    }
    if (mesh.getWorldBound() == null) {
        return true;
    }
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    if (selectedPart == null || selectedPart.isDrawCompleted()) {
        // if nothing is really selected, skip overlap check
        return true;
    }
    final OrientedBoundingBox bound = (OrientedBoundingBox) mesh.getWorldBound().clone(null);
    bound.setExtent(bound.getExtent().divide(1.1, null).addLocal(0, 0, 1));
    for (final HousePart child : container.getChildren()) {
        if (child != this && child instanceof ParabolicDish && bound.intersects(child.mesh.getWorldBound())) {
            return false;
        }
    }
    return true;
}
Also used : OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox)

Example 24 with OrientedBoundingBox

use of com.ardor3d.bounding.OrientedBoundingBox in project energy3d by concord-consortium.

the class ParabolicTrough method isDrawable.

@Override
public boolean isDrawable() {
    if (container == null) {
        return true;
    }
    if (mesh.getWorldBound() == null) {
        return true;
    }
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    if (selectedPart == null || selectedPart.isDrawCompleted()) {
        // if nothing is really selected, skip overlap check
        return true;
    }
    final OrientedBoundingBox bound = (OrientedBoundingBox) mesh.getWorldBound().clone(null);
    bound.setExtent(bound.getExtent().divide(1.1, null).addLocal(0, 0, 1));
    for (final HousePart child : container.getChildren()) {
        if (child != this && child instanceof ParabolicTrough && bound.intersects(child.mesh.getWorldBound())) {
            return false;
        }
    }
    return true;
}
Also used : OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox)

Aggregations

OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)24 Mesh (com.ardor3d.scenegraph.Mesh)9 Node (com.ardor3d.scenegraph.Node)8 BMText (com.ardor3d.ui.text.BMText)8 ColorRGBA (com.ardor3d.math.ColorRGBA)7 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)7 Line (com.ardor3d.scenegraph.Line)7 Vector3 (com.ardor3d.math.Vector3)6 BoundingBox (com.ardor3d.bounding.BoundingBox)5 OffsetState (com.ardor3d.renderer.state.OffsetState)5 Box (com.ardor3d.scenegraph.shape.Box)5 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)4 Spatial (com.ardor3d.scenegraph.Spatial)4 CullHint (com.ardor3d.scenegraph.hint.CullHint)4 UserData (org.concord.energy3d.model.UserData)4 Cylinder (com.ardor3d.scenegraph.shape.Cylinder)3 FloatBuffer (java.nio.FloatBuffer)3 HousePart (org.concord.energy3d.model.HousePart)3 CullState (com.ardor3d.renderer.state.CullState)2 Foundation (org.concord.energy3d.model.Foundation)2