/* * Project Info: http://jcae.sourceforge.net * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * (C) Copyright 2007, by EADS France */ package org.jcae.netbeans.cad; import org.jcae.opencascade.jni.BRepBuilderAPI_Transform; import org.jcae.opencascade.jni.GP_Trsf; import org.jcae.opencascade.jni.TopoDS_Shape; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.nodes.Node; import org.openide.util.HelpCtx; import org.openide.util.actions.CookieAction; /** * @author Jerome Robert */ public class RotateDialog extends javax.swing.JPanel { public final static class RotateAction extends CookieAction { protected int mode() { return CookieAction.MODE_ALL; } public String getName() { return "Rotate"; } protected Class[] cookieClasses() { return new Class[] { NbShape.class }; } protected void initialize() { super.initialize(); // see org.openide.util.actions.SystemAction.iconResource() javadoc for more details putValue("noIconInMenu", Boolean.TRUE); } public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } @Override protected boolean asynchronous() { return false; } protected void performAction(Node[] nodes) { RotateDialog dialog=new RotateDialog(); if (dialog.showDialog()) { GP_Trsf trsf = new GP_Trsf(); trsf.setRotation(dialog.getAxis(), dialog.getAngle()*Math.PI/180); for (Node n:nodes) { TopoDS_Shape s = GeomUtils.getShape(n).getImpl(); BRepBuilderAPI_Transform bt = new BRepBuilderAPI_Transform(s, trsf, true); TopoDS_Shape newShape=bt.shape(); GeomUtils.insertShape(newShape, getName(), n.getParentNode()); GeomUtils.getParentBrep(n).getDataObject().setModified(true); } } } } /** * Creates new form RotateDialog */ public RotateDialog() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { javax.swing.JLabel angleLabel; javax.swing.JLabel directionLabel; java.awt.GridBagConstraints gridBagConstraints; javax.swing.JPanel jPanel1; javax.swing.JLabel locationLabel; javax.swing.JLabel xLabel; javax.swing.JLabel yLabel; javax.swing.JLabel zLabel; angleLabel = new javax.swing.JLabel(); locationLabel = new javax.swing.JLabel(); directionLabel = new javax.swing.JLabel(); locationX = new javax.swing.JTextField(); locationY = new javax.swing.JTextField(); locationZ = new javax.swing.JTextField(); directionX = new javax.swing.JTextField(); directionY = new javax.swing.JTextField(); directionZ = new javax.swing.JTextField(); angle = new javax.swing.JTextField(); jPanel1 = new javax.swing.JPanel(); xLabel = new javax.swing.JLabel(); yLabel = new javax.swing.JLabel(); zLabel = new javax.swing.JLabel(); setLayout(new java.awt.GridBagLayout()); setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); setFocusable(false); setInheritsPopupMenu(true); angleLabel.setText("Angle (deg)"); add(angleLabel, new java.awt.GridBagConstraints()); locationLabel.setText("Axis location"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; add(locationLabel, gridBagConstraints); directionLabel.setText("Axis direction"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 3); add(directionLabel, gridBagConstraints); locationX.setText("0"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); add(locationX, gridBagConstraints); locationY.setText("0"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); add(locationY, gridBagConstraints); locationZ.setText("0"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); add(locationZ, gridBagConstraints); directionX.setText("0"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); add(directionX, gridBagConstraints); directionY.setText("0"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); add(directionY, gridBagConstraints); directionZ.setText("1"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); add(directionZ, gridBagConstraints); angle.setText("0"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; add(angle, gridBagConstraints); jPanel1.setLayout(new java.awt.GridLayout()); xLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); xLabel.setText(" x "); jPanel1.add(xLabel); yLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); yLabel.setText("y"); jPanel1.add(yLabel); zLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); zLabel.setText("z"); jPanel1.add(zLabel); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; add(jPanel1, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField angle; private javax.swing.JTextField directionX; private javax.swing.JTextField directionY; private javax.swing.JTextField directionZ; private javax.swing.JTextField locationX; private javax.swing.JTextField locationY; private javax.swing.JTextField locationZ; // End of variables declaration//GEN-END:variables public boolean showDialog() { DialogDescriptor dd=new DialogDescriptor(this, "Rotate"); do { DialogDisplayer.getDefault().createDialog(dd).setVisible(true); } while(dd.getValue()==NotifyDescriptor.OK_OPTION && !check()); return dd.getValue()==NotifyDescriptor.OK_OPTION; } public double getAngle() { return Double.parseDouble(angle.getText()); } public double[] getAxis() { return new double[]{ Double.parseDouble(locationX.getText()), Double.parseDouble(locationY.getText()), Double.parseDouble(locationZ.getText()), Double.parseDouble(directionX.getText()), Double.parseDouble(directionY.getText()), Double.parseDouble(directionZ.getText())}; } private boolean check() { String msg=null; double[] d=null; try { getAngle(); d=getAxis(); } catch(NumberFormatException ex) { msg="Invalid number format. "+ex.getMessage(); } if(d!=null && d[3]==0 && d[4]==0 && d[5]==0) { msg="Direction cannot be a zero vector"; } if(msg==null) { return true; } else { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg)); return false; } } }