Back to index

salome-gui  6.5.0
OCCViewer_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 #include "OCCViewer_SetRotationPointDlg.h"
00024 
00025 #include <QtxAction.h>
00026 
00027 #include "OCCViewer_ViewWindow.h"
00028 
00029 #include <QLineEdit>
00030 #include <QGroupBox>
00031 #include <QLabel>
00032 #include <QPushButton>
00033 #include <QGridLayout>
00034 #include <QDoubleValidator>
00035 #include <QCheckBox>
00036 #include <QHBoxLayout>
00037 
00046 OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWindow* view, const char* name, bool modal, Qt::WindowFlags fl )
00047 : QDialog( view, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
00048   myView( view )
00049 {
00050   setObjectName( "OCCViewer_SetRotationPointDlg" );
00051   setModal( modal );
00052 
00053   setWindowTitle(tr("CAPTION"));
00054   setSizeGripEnabled(TRUE);
00055 
00056   // Create layout for this dialog
00057   QGridLayout* layoutDlg = new QGridLayout (this);
00058   layoutDlg->setSpacing(6);
00059   layoutDlg->setMargin(11);
00060 
00061   // Create check box "Use Bounding Box Center"
00062   QHBoxLayout* aCheckBox = new QHBoxLayout;
00063 
00064   myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"));
00065   myIsBBCenter->setChecked(true);
00066   aCheckBox->addWidget(myIsBBCenter);
00067   connect(myIsBBCenter, SIGNAL(stateChanged(int)), SLOT(onBBCenterChecked()));
00068 
00069   // Create croup button with radio buttons
00070   myGroupBoxSel = new QGroupBox( "", this );
00071   QVBoxLayout *vbox = new QVBoxLayout;
00072   vbox->setMargin(11);
00073   vbox->addStretch(1);
00074   
00075   // Create "Set to Origin" button
00076   myToOrigin = new QPushButton(tr("LBL_TOORIGIN"));
00077   vbox->addWidget(myToOrigin);
00078   connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
00079 
00080   // Create "Select Point from View" button
00081   mySelectPoint = new QPushButton(tr("LBL_SELECTPOINT"));
00082   mySelectPoint->setCheckable(true);
00083   vbox->addWidget(mySelectPoint);
00084   connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
00085 
00086   myGroupBoxSel->setLayout(vbox);
00087 
00088   // Create croup box with grid layout
00089   myGroupBoxCoord = new QGroupBox(this);
00090   myGroupBoxCoord->setObjectName("GroupBox");
00091   QHBoxLayout* aHBoxLayout = new QHBoxLayout(myGroupBoxCoord);
00092   aHBoxLayout->setMargin(11);
00093   aHBoxLayout->setSpacing(6);
00094 
00095   // "X" coordinate
00096   QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord );
00097   TextLabelX->setObjectName("TextLabelX");
00098   TextLabelX->setFixedWidth(15);
00099   myX = new QLineEdit(myGroupBoxCoord);
00100   myX->setValidator(new QDoubleValidator(myX));
00101   myX->setText(QString::number(0.0));
00102   connect(myX, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
00103 
00104   // "Y" coordinate
00105   QLabel* TextLabelY = new QLabel (tr("LBL_Y"), myGroupBoxCoord );
00106   TextLabelY->setObjectName("TextLabelY");
00107   TextLabelY->setFixedWidth(15);
00108   myY = new QLineEdit(myGroupBoxCoord);
00109   myY->setValidator(new QDoubleValidator(myY));
00110   myY->setText(QString::number(0.0));
00111   connect(myY, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
00112 
00113   // "Z" coordinate
00114   QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord );
00115   TextLabelZ->setObjectName("TextLabelZ");
00116   TextLabelZ->setFixedWidth(15);
00117   myZ = new QLineEdit(myGroupBoxCoord);
00118   myZ->setValidator(new QDoubleValidator(myZ));
00119   myZ->setText(QString::number(0.0));
00120   connect(myZ, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
00121 
00122   // Layout widgets in the horizontal group box
00123   aHBoxLayout->addWidget(TextLabelX);
00124   aHBoxLayout->addWidget(myX);
00125   aHBoxLayout->addWidget(TextLabelY);
00126   aHBoxLayout->addWidget(myY);
00127   aHBoxLayout->addWidget(TextLabelZ);
00128   aHBoxLayout->addWidget(myZ);
00129 
00130   // "Close" button
00131   QGroupBox* aGroupBox = new QGroupBox(this);
00132   QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
00133   aHBoxLayout2->setMargin(11);
00134   aHBoxLayout2->setSpacing(6);
00135 
00136   QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox );
00137   m_bClose->setObjectName("m_bClose");
00138   m_bClose->setAutoDefault(TRUE);
00139   m_bClose->setFixedSize(m_bClose->sizeHint());
00140   connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
00141 
00142   // Layout buttons
00143   aHBoxLayout2->addWidget(m_bClose);
00144 
00145   // Layout top level widgets
00146   layoutDlg->addLayout(aCheckBox,0,0);
00147   layoutDlg->addWidget(myGroupBoxSel,1,0);
00148   layoutDlg->addWidget(myGroupBoxCoord,2,0);
00149   layoutDlg->addWidget(aGroupBox,3,0);
00150   
00151   setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
00152   setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
00153 
00154   this->resize(400, this->sizeHint().height());
00155 
00156   connect(view, SIGNAL(Show( QShowEvent * )), this, SLOT(onViewShow()));
00157   connect(view, SIGNAL(Hide( QHideEvent * )), this, SLOT(onViewHide()));
00158 }
00159 
00160 /*
00161  *  Destroys the object and frees any allocated resources
00162  */
00163 OCCViewer_SetRotationPointDlg
00164 ::~OCCViewer_SetRotationPointDlg()
00165 {
00166   // no need to delete child widgets, Qt does it all for us
00167 }
00168 
00172 bool
00173 OCCViewer_SetRotationPointDlg
00174 ::IsFirstShown()
00175 {
00176   return myIsBBCenter->isChecked() && myX->text().toDouble() == 0.
00177     && myY->text().toDouble() == 0. && myZ->text().toDouble() == 0.;
00178 }
00179 
00180 void 
00181 OCCViewer_SetRotationPointDlg
00182 ::setEnabled(QGroupBox* theGrp, const bool theState)
00183 {
00184   QObjectList aChildren(theGrp->children());
00185   QObject* anObj;
00186   for(int i = 0; i < aChildren.size(); i++)
00187   {
00188     anObj = aChildren.at(i);
00189     if (anObj !=0 && anObj->inherits("QLineEdit"))
00190       ((QLineEdit*)anObj)->setReadOnly(!theState);
00191     if (anObj !=0 && anObj->inherits("QPushButton"))
00192       ((QLineEdit*)anObj)->setEnabled(theState);
00193   }
00194   
00195 }
00196 
00197 void 
00198 OCCViewer_SetRotationPointDlg
00199 ::onBBCenterChecked()
00200 {
00201   setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
00202   setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
00203   
00204   if ( myIsBBCenter->isChecked() )
00205   {
00206     if ( mySelectPoint->isChecked() )
00207       mySelectPoint->toggle();
00208     myView->activateSetRotationGravity();
00209   }
00210   else
00211     myView->activateSetRotationSelected(myX->text().toDouble(), 
00212                                         myY->text().toDouble(), 
00213                                         myZ->text().toDouble());
00214 }
00215 
00216 void
00217 OCCViewer_SetRotationPointDlg
00218 ::onToOrigin()
00219 {
00220   if ( mySelectPoint->isChecked() )
00221     mySelectPoint->toggle();
00222   setCoords();
00223   myView->activateSetRotationSelected(myX->text().toDouble(), 
00224                                       myY->text().toDouble(), 
00225                                       myZ->text().toDouble());
00226 }
00227 
00228 void
00229 OCCViewer_SetRotationPointDlg
00230 ::onSelectPoint()
00231 {
00232   if ( mySelectPoint->isChecked() )
00233     myView->activateStartPointSelection();
00234   else
00235     mySelectPoint->toggle();
00236 }
00237 
00238 void
00239 OCCViewer_SetRotationPointDlg
00240 ::onCoordChanged()
00241 {
00242   if ( !myIsBBCenter->isChecked() )
00243   {
00244     if ( mySelectPoint->isChecked()
00245          &&
00246          ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
00247       mySelectPoint->toggle();
00248     myView->activateSetRotationSelected(myX->text().toDouble(), 
00249                                         myY->text().toDouble(), 
00250                                         myZ->text().toDouble());
00251   }
00252 }
00253 
00254 void
00255 OCCViewer_SetRotationPointDlg
00256 ::setCoords(double theX, double theY, double theZ)
00257 {
00258   myX->setText(QString::number(theX));
00259   myY->setText(QString::number(theY));
00260   myZ->setText(QString::number(theZ));
00261 }
00262 
00263 void
00264 OCCViewer_SetRotationPointDlg
00265 ::toggleChange()
00266 {
00267   if ( !myIsBBCenter->isChecked() )
00268     mySelectPoint->toggle();
00269 }
00270 
00271 void
00272 OCCViewer_SetRotationPointDlg
00273 ::onClickClose()
00274 {
00275   myAction->setChecked( false );
00276   reject();
00277 }
00278 
00279 void 
00280 OCCViewer_SetRotationPointDlg
00281 ::onViewShow()
00282 {
00283   if(myAction->isChecked())
00284     show();
00285   else
00286     hide();
00287 }
00288 
00289 void 
00290 OCCViewer_SetRotationPointDlg
00291 ::onViewHide()
00292 {
00293   hide();
00294 }
00295 
00299 void
00300 OCCViewer_SetRotationPointDlg
00301 ::closeEvent( QCloseEvent* e )
00302 {
00303   myAction->setChecked( false );
00304   QDialog::closeEvent( e );
00305 }