Back to index

salome-gui  6.5.0
SVTK_SetRotationPointDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME VTKViewer : build VTK viewer into Salome desktop
00024 //  File   : 
00025 //  Author : 
00026 
00027 #include "SVTK_SetRotationPointDlg.h"
00028 #include "SVTK_ViewWindow.h"
00029 #include "SVTK_RenderWindowInteractor.h"
00030 #include "SVTK_Event.h"
00031 #include "SVTK_InteractorStyle.h"
00032 
00033 #include "VTKViewer_Utilities.h"
00034 
00035 #include "QtxAction.h"
00036 
00037 #include <QLineEdit>
00038 #include <QGroupBox>
00039 #include <QLabel>
00040 #include <QPushButton>
00041 #include <QGridLayout>
00042 #include <QDoubleValidator>
00043 #include <QCheckBox>
00044 
00045 #include <vtkCallbackCommand.h>
00046 
00050 SVTK_SetRotationPointDlg
00051 ::SVTK_SetRotationPointDlg(QtxAction* theAction,
00052                            SVTK_ViewWindow* theParent,
00053                            const char* theName):
00054   ViewerTools_DialogBase(theAction,
00055                          theParent, 
00056                          theName),
00057   myMainWindow(theParent),
00058   myPriority(0.0),
00059   myEventCallbackCommand(vtkCallbackCommand::New()),
00060   myRWInteractor(theParent->GetInteractor())
00061 {
00062   setWindowTitle(tr("DLG_TITLE"));
00063   setSizeGripEnabled(TRUE);
00064 
00065   // Create layout for this dialog
00066   QGridLayout* layoutDlg = new QGridLayout (this);
00067   layoutDlg->setSpacing(6);
00068   layoutDlg->setMargin(11);
00069 
00070   // Create check box "Use Bounding Box Center"
00071   QHBoxLayout* aCheckBox = new QHBoxLayout;
00072 
00073   myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"));
00074   myIsBBCenter->setChecked(true);
00075   aCheckBox->addWidget(myIsBBCenter);
00076   connect(myIsBBCenter, SIGNAL(stateChanged(int)), SLOT(onBBCenterChecked()));
00077 
00078   // Create croup button with radio buttons
00079   myGroupBoxSel = new QGroupBox( "", this );
00080   QVBoxLayout *vbox = new QVBoxLayout( myGroupBoxSel );
00081   vbox->setMargin(11);
00082   vbox->addStretch(1);
00083   
00084   // Create "Set to Origin" button
00085   myToOrigin = new QPushButton(myGroupBoxSel);
00086   myToOrigin->setText(tr("LBL_TOORIGIN"));
00087   vbox->addWidget(myToOrigin);
00088   connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
00089 
00090   // Create "Select Point from View" button
00091   mySelectPoint = new QPushButton(myGroupBoxSel);
00092   mySelectPoint->setText(tr("LBL_SELECTPOINT"));
00093   mySelectPoint->setCheckable(true);
00094   vbox->addWidget(mySelectPoint);
00095   connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
00096 
00097   // Create croup box with grid layout
00098   myGroupBoxCoord = new QGroupBox(this);
00099   myGroupBoxCoord->setObjectName("GroupBox");
00100   QHBoxLayout* aHBoxLayout = new QHBoxLayout(myGroupBoxCoord);
00101   aHBoxLayout->setMargin(11);
00102   aHBoxLayout->setSpacing(6);
00103 
00104   // "X" coordinate
00105   QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord );
00106   TextLabelX->setObjectName("TextLabelX");
00107   TextLabelX->setFixedWidth(15);
00108   myX = new QLineEdit(myGroupBoxCoord);
00109   myX->setValidator(new QDoubleValidator(myX));
00110   myX->setText(QString::number(0.0));
00111   connect(myX, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
00112 
00113   // "Y" coordinate
00114   QLabel* TextLabelY = new QLabel (tr("LBL_Y"), myGroupBoxCoord );
00115   TextLabelY->setObjectName("TextLabelY");
00116   TextLabelY->setFixedWidth(15);
00117   myY = new QLineEdit(myGroupBoxCoord);
00118   myY->setValidator(new QDoubleValidator(myY));
00119   myY->setText(QString::number(0.0));
00120   connect(myY, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
00121 
00122   // "Z" coordinate
00123   QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord );
00124   TextLabelZ->setObjectName("TextLabelZ");
00125   TextLabelZ->setFixedWidth(15);
00126   myZ = new QLineEdit(myGroupBoxCoord);
00127   myZ->setValidator(new QDoubleValidator(myZ));
00128   myZ->setText(QString::number(0.0));
00129   connect(myZ, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
00130 
00131   // Layout widgets in the horizontal group box
00132   aHBoxLayout->addWidget(TextLabelX);
00133   aHBoxLayout->addWidget(myX);
00134   aHBoxLayout->addWidget(TextLabelY);
00135   aHBoxLayout->addWidget(myY);
00136   aHBoxLayout->addWidget(TextLabelZ);
00137   aHBoxLayout->addWidget(myZ);
00138 
00139   // "Close" button
00140   QGroupBox* aGroupBox = new QGroupBox(this);
00141   QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
00142   aHBoxLayout2->setMargin(11);
00143   aHBoxLayout2->setSpacing(6);
00144 
00145   QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox );
00146   m_bClose->setObjectName("m_bClose");
00147   m_bClose->setAutoDefault(TRUE);
00148   m_bClose->setFixedSize(m_bClose->sizeHint());
00149   connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
00150 
00151   // Layout buttons
00152   aHBoxLayout2->addWidget(m_bClose);
00153 
00154   // Layout top level widgets
00155   layoutDlg->addLayout(aCheckBox,0,0);
00156   layoutDlg->addWidget(myGroupBoxSel,1,0);
00157   layoutDlg->addWidget(myGroupBoxCoord,2,0);
00158   layoutDlg->addWidget(aGroupBox,3,0);
00159   
00160   setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
00161   setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
00162 
00163   this->resize(400, this->sizeHint().height());
00164 
00165   myEventCallbackCommand->Delete();
00166   myEventCallbackCommand->SetClientData(this);
00167   myEventCallbackCommand->SetCallback(SVTK_SetRotationPointDlg::ProcessEvents);
00168   myIsObserverAdded = false;
00169 }
00170 
00171 /*
00172  *  Destroys the object and frees any allocated resources
00173  */
00174 SVTK_SetRotationPointDlg
00175 ::~SVTK_SetRotationPointDlg()
00176 {
00177   // no need to delete child widgets, Qt does it all for us
00178 }
00179 
00180 void
00181 SVTK_SetRotationPointDlg
00182 ::addObserver()
00183 {
00184   if ( !myIsObserverAdded ) {
00185     vtkInteractorStyle* aIStyle = myRWInteractor->GetInteractorStyle();
00186     aIStyle->AddObserver(SVTK::BBCenterChanged, myEventCallbackCommand.GetPointer(), myPriority);
00187     aIStyle->AddObserver(SVTK::RotationPointChanged, myEventCallbackCommand.GetPointer(), myPriority);
00188     myIsObserverAdded = true;
00189   }
00190 }
00191 
00195 bool
00196 SVTK_SetRotationPointDlg
00197 ::IsFirstShown()
00198 {
00199   return myIsBBCenter->isChecked() && myX->text().toDouble() == 0.
00200     && myY->text().toDouble() == 0. && myZ->text().toDouble() == 0.;
00201 }
00202 
00206 void 
00207 SVTK_SetRotationPointDlg
00208 ::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
00209                 unsigned long theEvent,
00210                 void* theClientData, 
00211                 void* theCallData)
00212 {
00213   SVTK_SetRotationPointDlg* self = reinterpret_cast<SVTK_SetRotationPointDlg*>(theClientData);
00214   vtkFloatingPointType* aCoord = (vtkFloatingPointType*)theCallData;
00215   
00216   switch ( theEvent ) {
00217   case SVTK::BBCenterChanged:
00218     if ( self->myIsBBCenter->isChecked()
00219          ||
00220          IsBBEmpty(self->myMainWindow->getRenderer()) )
00221     {
00222       if ( aCoord )
00223       {
00224         self->myX->setText( QString::number(aCoord[0]) );
00225         self->myY->setText( QString::number(aCoord[1]) );
00226         self->myZ->setText( QString::number(aCoord[2]) );
00227       }
00228     }
00229     break;
00230   case SVTK::RotationPointChanged:
00231     if ( aCoord )
00232     {
00233       self->myX->setText( QString::number(aCoord[0]) );
00234       self->myY->setText( QString::number(aCoord[1]) );
00235       self->myZ->setText( QString::number(aCoord[2]) );
00236     }
00237     if ( !self->myIsBBCenter->isChecked() )
00238       self->mySelectPoint->toggle();
00239   }
00240 }
00241 
00242 void 
00243 SVTK_SetRotationPointDlg
00244 ::setEnabled(QGroupBox* theGrp, const bool theState)
00245 {
00246   QObjectList aChildren(theGrp->children());
00247   QObject* anObj;
00248   for(int i = 0; i < aChildren.size(); i++)
00249   {
00250     anObj = aChildren.at(i);
00251     if (anObj !=0 && anObj->inherits("QLineEdit"))
00252       ((QLineEdit*)anObj)->setReadOnly(!theState);
00253     if (anObj !=0 && anObj->inherits("QPushButton"))
00254       ((QLineEdit*)anObj)->setEnabled(theState);
00255   }
00256   
00257 }
00258 
00259 void 
00260 SVTK_SetRotationPointDlg
00261 ::onBBCenterChecked()
00262 {
00263   setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
00264   setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
00265   
00266   if ( myIsBBCenter->isChecked() )
00267   { 
00268     if ( mySelectPoint->isChecked() )
00269       mySelectPoint->toggle();
00270     // activate mode : the rotation point is the center of the bounding box
00271     // send the data to the SVTK_InteractorStyle: set the type of the rotation point
00272     //                                            calculate coordinates of the rotation point
00273     myMainWindow->activateSetRotationGravity();
00274   }
00275   else
00276   {
00277     QString aX = myX->text();
00278     myX->setText(QString::number(aX.toDouble()+1.));
00279     myX->setText(aX);
00280   }
00281 }
00282 
00283 void
00284 SVTK_SetRotationPointDlg
00285 ::onToOrigin()
00286 {
00287   if ( mySelectPoint->isChecked() )
00288     mySelectPoint->toggle();
00289   myX->setText(QString::number(0.0));
00290   myY->setText(QString::number(0.0));
00291   myZ->setText(QString::number(0.0));
00292 }
00293 
00294 void
00295 SVTK_SetRotationPointDlg
00296 ::onSelectPoint()
00297 {
00298   if ( mySelectPoint->isChecked() )
00299     myMainWindow->activateStartPointSelection();
00300   else
00301     mySelectPoint->toggle();
00302 }
00303 
00304 void
00305 SVTK_SetRotationPointDlg
00306 ::onCoordChanged()
00307 {
00308   if ( !myIsBBCenter->isChecked() ) {
00309     if ( mySelectPoint->isChecked()
00310          &&
00311          ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
00312       mySelectPoint->toggle();
00313     vtkFloatingPointType aCenter[3] = {myX->text().toDouble(), 
00314                                        myY->text().toDouble(), 
00315                                        myZ->text().toDouble()};
00316     myMainWindow->activateSetRotationSelected((void*)aCenter);
00317   }
00318   else
00319     myMainWindow->activateSetRotationGravity();
00320 }
00321 
00322 void
00323 SVTK_SetRotationPointDlg
00324 ::onClickClose()
00325 {
00326   reject();
00327 }
00328 
00329