1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
29 #include "SVTK_SetRotationPointDlg.h"
30 #include "SVTK_MainWindow.h"
31 #include "SVTK_RenderWindowInteractor.h"
32 #include "SVTK_Event.h"
33 #include "SVTK_InteractorStyle.h"
35 #include "VTKViewer_Utilities.h"
37 #include "QtxAction.h"
39 #include <qlineedit.h>
40 #include <qgroupbox.h>
42 #include <qpushbutton.h>
44 #include <qvalidator.h>
45 #include <qbuttongroup.h>
46 #include <qobjectlist.h>
47 #include <qcheckbox.h>
50 #include <vtkCallbackCommand.h>
57 SVTK_SetRotationPointDlg
58 ::SVTK_SetRotationPointDlg(QtxAction* theAction,
59 SVTK_MainWindow* theParent,
61 SVTK_DialogBase(theAction,
64 myMainWindow(theParent),
66 myEventCallbackCommand(vtkCallbackCommand::New()),
67 myRWInteractor(theParent->GetInteractor())
69 setCaption(tr("DLG_TITLE"));
70 setSizeGripEnabled(TRUE);
72 // Create layout for this dialog
73 QGridLayout* layoutDlg = new QGridLayout (this);
74 layoutDlg->setSpacing(6);
75 layoutDlg->setMargin(11);
77 // Create check box "Use Bounding Box Center"
78 QHBox* aCheckBox = new QHBox(this);
80 myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"), aCheckBox);
81 myIsBBCenter->setChecked(true);
82 connect(myIsBBCenter, SIGNAL(stateChanged(int)), SLOT(onBBCenterChecked()));
84 // Create croup button with radio buttons
85 myGroupSelButton = new QButtonGroup(2,Qt::Vertical,"",this);
86 myGroupSelButton->setMargin(11);
88 // Create "Set to Origin" button
89 myToOrigin = new QPushButton(myGroupSelButton);
90 myToOrigin->setText(tr("LBL_TOORIGIN"));
91 connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
93 // Create "Select Point from View" button
94 mySelectPoint = new QPushButton(myGroupSelButton);
95 mySelectPoint->setText(tr("LBL_SELECTPOINT"));
96 mySelectPoint->setToggleButton(true);
97 connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
99 // Create croup box with grid layout
100 myGroupBoxCoord = new QGroupBox(this, "GroupBox");
101 QHBoxLayout* aHBoxLayout = new QHBoxLayout(myGroupBoxCoord);
102 aHBoxLayout->setMargin(11);
103 aHBoxLayout->setSpacing(6);
106 QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord, "TextLabelX");
107 TextLabelX->setFixedWidth(15);
108 myX = new QLineEdit(myGroupBoxCoord);
109 myX->setValidator(new QDoubleValidator(myX));
110 myX->setText(QString::number(0.0));
111 connect(myX, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
114 QLabel* TextLabelY = new QLabel (tr("LBL_Y"), myGroupBoxCoord, "TextLabelY");
115 TextLabelY->setFixedWidth(15);
116 myY = new QLineEdit(myGroupBoxCoord);
117 myY->setValidator(new QDoubleValidator(myY));
118 myY->setText(QString::number(0.0));
119 connect(myY, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
122 QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord, "TextLabelZ");
123 TextLabelZ->setFixedWidth(15);
124 myZ = new QLineEdit(myGroupBoxCoord);
125 myZ->setValidator(new QDoubleValidator(myZ));
126 myZ->setText(QString::number(0.0));
127 connect(myZ, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
129 // Layout widgets in the horizontal group box
130 aHBoxLayout->addWidget(TextLabelX);
131 aHBoxLayout->addWidget(myX);
132 aHBoxLayout->addWidget(TextLabelY);
133 aHBoxLayout->addWidget(myY);
134 aHBoxLayout->addWidget(TextLabelZ);
135 aHBoxLayout->addWidget(myZ);
138 QGroupBox* aGroupBox = new QGroupBox(this);
139 QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
140 aHBoxLayout2->setMargin(11);
141 aHBoxLayout2->setSpacing(6);
143 QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox, "m_bClose");
144 m_bClose->setAutoDefault(TRUE);
145 m_bClose->setFixedSize(m_bClose->sizeHint());
146 connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
149 aHBoxLayout2->addWidget(m_bClose);
151 // Layout top level widgets
152 layoutDlg->addWidget(aCheckBox,0,0);
153 layoutDlg->addWidget(myGroupSelButton,1,0);
154 layoutDlg->addWidget(myGroupBoxCoord,2,0);
155 layoutDlg->addWidget(aGroupBox,3,0);
157 setEnabled(myGroupSelButton,!myIsBBCenter->isChecked());
158 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
160 this->resize(400, this->sizeHint().height());
162 myEventCallbackCommand->Delete();
163 myEventCallbackCommand->SetClientData(this);
164 myEventCallbackCommand->SetCallback(SVTK_SetRotationPointDlg::ProcessEvents);
165 myIsObserverAdded = false;
169 * Destroys the object and frees any allocated resources
171 SVTK_SetRotationPointDlg
172 ::~SVTK_SetRotationPointDlg()
174 // no need to delete child widgets, Qt does it all for us
178 SVTK_SetRotationPointDlg
181 if ( !myIsObserverAdded ) {
182 vtkInteractorStyle* aIStyle = myRWInteractor->GetInteractorStyle();
183 aIStyle->AddObserver(SVTK::BBCenterChanged, myEventCallbackCommand.GetPointer(), myPriority);
184 aIStyle->AddObserver(SVTK::RotationPointChanged, myEventCallbackCommand.GetPointer(), myPriority);
185 myIsObserverAdded = true;
190 Return true if it is the first show for this dialog
193 SVTK_SetRotationPointDlg
196 return myIsBBCenter->isChecked() && myX->text().toDouble() == 0.
197 && myY->text().toDouble() == 0. && myZ->text().toDouble() == 0.;
204 SVTK_SetRotationPointDlg
205 ::ProcessEvents(vtkObject* vtkNotUsed(theObject),
206 unsigned long theEvent,
210 SVTK_SetRotationPointDlg* self = reinterpret_cast<SVTK_SetRotationPointDlg*>(theClientData);
211 vtkFloatingPointType* aCoord = (vtkFloatingPointType*)theCallData;
213 switch ( theEvent ) {
214 case SVTK::BBCenterChanged:
215 if ( self->myIsBBCenter->isChecked()
217 IsBBEmpty(self->myMainWindow->getRenderer()) )
221 self->myX->setText( QString::number(aCoord[0]) );
222 self->myY->setText( QString::number(aCoord[1]) );
223 self->myZ->setText( QString::number(aCoord[2]) );
227 case SVTK::RotationPointChanged:
230 self->myX->setText( QString::number(aCoord[0]) );
231 self->myY->setText( QString::number(aCoord[1]) );
232 self->myZ->setText( QString::number(aCoord[2]) );
234 if ( !self->myIsBBCenter->isChecked() )
235 self->mySelectPoint->toggle();
240 SVTK_SetRotationPointDlg
241 ::setEnabled(QGroupBox* theGrp, const bool theState)
243 QObjectList aChildren(*theGrp->children());
245 for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next())
247 if (anObj !=0 && anObj->inherits("QLineEdit"))
248 ((QLineEdit*)anObj)->setReadOnly(!theState);
249 if (anObj !=0 && anObj->inherits("QPushButton"))
250 ((QLineEdit*)anObj)->setEnabled(theState);
256 SVTK_SetRotationPointDlg
257 ::onBBCenterChecked()
259 setEnabled(myGroupSelButton,!myIsBBCenter->isChecked());
260 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
262 if ( myIsBBCenter->isChecked() )
264 if ( mySelectPoint->state() == QButton::On )
265 mySelectPoint->toggle();
266 // activate mode : the rotation point is the center of the bounding box
267 // send the data to the SVTK_InteractorStyle: set the type of the rotation point
268 // calculate coordinates of the rotation point
269 myMainWindow->activateSetRotationGravity();
273 QString aX = myX->text();
274 myX->setText(QString::number(aX.toDouble()+1.));
280 SVTK_SetRotationPointDlg
283 if ( mySelectPoint->state() == QButton::On )
284 mySelectPoint->toggle();
285 myX->setText(QString::number(0.0));
286 myY->setText(QString::number(0.0));
287 myZ->setText(QString::number(0.0));
291 SVTK_SetRotationPointDlg
294 if ( mySelectPoint->state() == QButton::On )
295 myMainWindow->activateStartPointSelection();
297 mySelectPoint->toggle();
301 SVTK_SetRotationPointDlg
304 if ( !myIsBBCenter->isChecked() ) {
305 if ( mySelectPoint->state() == QButton::On
307 ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
308 mySelectPoint->toggle();
309 vtkFloatingPointType aCenter[3] = {myX->text().toDouble(),
310 myY->text().toDouble(),
311 myZ->text().toDouble()};
312 myMainWindow->activateSetRotationSelected((void*)aCenter);
315 myMainWindow->activateSetRotationGravity();
319 SVTK_SetRotationPointDlg