CMS 3D CMS Logo

Ig3DAxisRotationControl.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/GLBrowsers/interface/IgControlCategory.h"
00004 #include "Iguana/GLBrowsers/interface/Ig3DAxisRotationControl.h"
00005 #include "Iguana/GLBrowsers/interface/IgQtRangeControlCommon.h"
00006 #include <classlib/utils/DebugAids.h>
00007 #include <qwhatsthis.h>
00008 
00009 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00010 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00011 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00012 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00013 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00014 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00015 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00016 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00017 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00018 
00020 Ig3DAxisRotationControl::Ig3DAxisRotationControl (IgControlCategory *pane,
00021                                           QString label, Ig3DPlaneControl* planeControl)
00022     : IgControlBase (pane), m_planeControl(planeControl)
00023 {
00024         ASSERT (pane);
00025         ASSERT (pane->bodyArea ());
00026         ASSERT (pane->bodyLayout ());
00027 
00028         std::vector<QString> labels;
00029         QString tmpLabels ("X:Y:Z");
00030         
00031         for(unsigned int i = 0; i < 3; i++)
00032         {
00033                 labels.push_back (IgQtRangeControlCommon::getSettingItem (tmpLabels));
00034         }
00035 
00036         QWidget     *area = pane->bodyArea ();
00037         
00038         // Add label to the grid
00039         QWidget     *vlab = makeIndentedLabel (label, area);
00040         addGridWidget (vlab, gridRows (), 0);
00041         
00042         QString tips ("Set the \"");
00043         tips += label + "\" of the item";
00044         QWhatsThis::add (vlab, tips.latin1 ());
00045  
00046         pane->pushIndent ();
00047 
00048         // create three thumbWheel controls for rotating around the axes
00049         for (int axis = X_Axis; axis <= Z_Axis; axis++)
00050         {
00051                 makeWheelControl(pane, vlab, axis, true);// und so weiter...
00052         }
00053         
00054         // Add alignment button group if requested
00055         m_alignment = new IgQtAxisAlignment (area);
00056         addGridWidget (makeSpacedBox (area, m_alignment->widget ()), gridRows (), 1);
00057         
00058         connect (m_alignment, SIGNAL (dirty ()), this, SLOT (alignToAxis ()));
00059         
00060         pane->popIndent ();
00061 }
00062 
00063 void
00064 Ig3DAxisRotationControl::setXAxisDirty (float angle)
00065 {
00066         // calculate the difference between the old and the new angle
00067         // and remember the new angle for the next call
00068         float change = angle - m_oldAngle[0];
00069         m_oldAngle[0] = angle;
00070         
00071         // get the plane's normal direction and rotate it by 'change' 
00072         // degrees (radians) around the X axis. Finally set the plane's 
00073         // new calculated direction.
00074         SbVec3f old_dir (m_planeControl->direction ());
00075         SbVec3f new_dir = rotateAboutAxis (old_dir[1], old_dir[2], old_dir[0], change);
00076         m_planeControl->setDirection (SbVec3f(new_dir[2], new_dir[0], new_dir[1]));
00077 }
00078 
00079 void
00080 Ig3DAxisRotationControl::setYAxisDirty (float angle)
00081 {
00082         float change = angle - m_oldAngle[1];
00083         m_oldAngle[1] = angle;
00084         
00085         SbVec3f old_dir (m_planeControl->direction ());
00086         SbVec3f new_dir = rotateAboutAxis (old_dir[2], old_dir[0], old_dir[1], change);
00087         m_planeControl->setDirection (SbVec3f(new_dir[1], new_dir[2], new_dir[0]));
00088 }
00089 
00090 void
00091 Ig3DAxisRotationControl::setZAxisDirty (float angle)
00092 {
00093         float change = angle - m_oldAngle[2];
00094         m_oldAngle[2] = angle;
00095         
00096         SbVec3f old_dir (m_planeControl->direction ());
00097         SbVec3f new_dir = rotateAboutAxis (old_dir[0], old_dir[1], old_dir[2], change);
00098         m_planeControl->setDirection (new_dir);
00099 }
00100 
00101 void
00102 Ig3DAxisRotationControl::alignToAxis ()
00103 {
00104         // gets the alignment vector on a signal event and sets the cutting plane 
00105         // accordingly. After that, the alignment buttons have to be cleaned again
00106         // to be able to use them again.
00107         m_planeControl->setDirection (m_alignment->value ().getValue ());
00108         m_alignment->setClean();
00109 }
00110 
00111 void
00112 Ig3DAxisRotationControl::makeWheelControl (IgControlCategory* pane, QWidget* parent, int axis, bool horizontal)
00113 {
00114         // get index of the last row
00115         int row = gridRows ();
00116         
00117         QWidget *area = pane->bodyArea ();
00118         
00119         // determine the orientation based on the passed boolean
00120         IgSoQtThumbWheel::Orientation orientation;
00121         orientation = (horizontal ? IgSoQtThumbWheel::Horizontal : IgSoQtThumbWheel::Vertical);
00122                 
00123         // create the thumbwheel and its label
00124         QString label;
00125         switch (axis)
00126     {
00127         case X_Axis:
00128                         label = "X Axis";
00129                         break;
00130                 case Y_Axis:
00131                         label = "Y Axis";
00132                         break;
00133                 default:
00134                         label = "Z Axis";
00135                         break;
00136     }
00137         m_thumbWheels[axis] = new IgSoQtThumbWheel (orientation, parent, label);
00138                 
00139         // create a label inside an area
00140         QWidget* vlab = makeIndentedLabel (label, area);
00141         
00142         // add label and thumbwheel control to the gridded widget
00143         addGridWidget (vlab, row, 0);
00144         addGridWidget (makeSpacedBox (area, m_thumbWheels[axis]), row, 1);
00145         
00146         // connect wheels       
00147         switch (axis)
00148     {
00149         case X_Axis:
00150                         connect (m_thumbWheels[axis], SIGNAL( wheelMoved (float) ), this, SLOT( setXAxisDirty (float) ));
00151                         break;
00152                 case Y_Axis:
00153                         connect (m_thumbWheels[axis], SIGNAL( wheelMoved (float) ), this, SLOT( setYAxisDirty (float) ));
00154                         break;
00155                 default:
00156                         connect (m_thumbWheels[axis], SIGNAL( wheelMoved (float) ), this, SLOT( setZAxisDirty (float) ));
00157                         break;
00158         }
00159 }
00160 
00161 IgSoQtThumbWheel*
00162 Ig3DAxisRotationControl::xWidget () const
00163 {
00164         return m_thumbWheels[X_Axis];
00165 }
00166 
00167 IgSoQtThumbWheel* 
00168 Ig3DAxisRotationControl::yWidget () const
00169 {
00170         return m_thumbWheels[Y_Axis];
00171 }
00172 
00173 IgSoQtThumbWheel* 
00174 Ig3DAxisRotationControl::zWidget () const
00175 {
00176         return m_thumbWheels[Z_Axis];
00177 }
00178 
00184 SbVec3f
00185 Ig3DAxisRotationControl::rotateAboutAxis (float x, float y, float z, float angle)
00186 {
00187         float new_x = x*cos(angle) - y*sin(angle);
00188         float new_y = x*sin(angle) + y*cos(angle);
00189         return SbVec3f(new_x, new_y, z);
00190 }
00191 
00195 void
00196 Ig3DAxisRotationControl::updateValue (void)
00197 {
00198     // We don't have a field for this control, so this method does
00199         // nothing.
00200 }
00201 
00202 void
00203 Ig3DAxisRotationControl::applyValue (void)
00204 {    
00205     // We don't have a field for this control, so this method does
00206         // nothing.
00207 }

Generated on Tue Jun 9 17:38:34 2009 for CMSSW by  doxygen 1.5.4