1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // SALOME VTKViewer : build VTK viewer into Salome desktop
27 #include "SVTK_SetRotationPointDlg.h"
28 #include "SVTK_ViewWindow.h"
29 #include "SVTK_RenderWindowInteractor.h"
30 #include "SVTK_Event.h"
31 #include "SVTK_InteractorStyle.h"
33 #include "VTKViewer_Utilities.h"
35 #include "QtxAction.h"
40 #include <QPushButton>
41 #include <QGridLayout>
42 #include <QDoubleValidator>
45 #include <vtkCallbackCommand.h>
50 SVTK_SetRotationPointDlg
51 ::SVTK_SetRotationPointDlg(QtxAction* theAction,
52 SVTK_ViewWindow* theParent,
54 ViewerTools_DialogBase(theAction,
57 myMainWindow(theParent),
59 myEventCallbackCommand(vtkCallbackCommand::New()),
60 myRWInteractor(theParent->GetInteractor())
62 setWindowTitle(tr("DLG_TITLE"));
63 setSizeGripEnabled(TRUE);
65 // Create layout for this dialog
66 QGridLayout* layoutDlg = new QGridLayout (this);
67 layoutDlg->setSpacing(6);
68 layoutDlg->setMargin(11);
70 // Create check box "Use Bounding Box Center"
71 QHBoxLayout* aCheckBox = new QHBoxLayout;
73 myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"));
74 myIsBBCenter->setChecked(true);
75 aCheckBox->addWidget(myIsBBCenter);
76 connect(myIsBBCenter, SIGNAL(stateChanged(int)), SLOT(onBBCenterChecked()));
78 // Create croup button with radio buttons
79 myGroupBoxSel = new QGroupBox( "", this );
80 QVBoxLayout *vbox = new QVBoxLayout( myGroupBoxSel );
84 // Create "Set to Origin" button
85 myToOrigin = new QPushButton(myGroupBoxSel);
86 myToOrigin->setText(tr("LBL_TOORIGIN"));
87 vbox->addWidget(myToOrigin);
88 connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
90 // Create "Select Point from View" button
91 mySelectPoint = new QPushButton(myGroupBoxSel);
92 mySelectPoint->setText(tr("LBL_SELECTPOINT"));
93 mySelectPoint->setCheckable(true);
94 vbox->addWidget(mySelectPoint);
95 connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
97 // Create croup box with grid layout
98 myGroupBoxCoord = new QGroupBox(this);
99 myGroupBoxCoord->setObjectName("GroupBox");
100 QHBoxLayout* aHBoxLayout = new QHBoxLayout(myGroupBoxCoord);
101 aHBoxLayout->setMargin(11);
102 aHBoxLayout->setSpacing(6);
105 QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord );
106 TextLabelX->setObjectName("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 );
115 TextLabelY->setObjectName("TextLabelY");
116 TextLabelY->setFixedWidth(15);
117 myY = new QLineEdit(myGroupBoxCoord);
118 myY->setValidator(new QDoubleValidator(myY));
119 myY->setText(QString::number(0.0));
120 connect(myY, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
123 QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord );
124 TextLabelZ->setObjectName("TextLabelZ");
125 TextLabelZ->setFixedWidth(15);
126 myZ = new QLineEdit(myGroupBoxCoord);
127 myZ->setValidator(new QDoubleValidator(myZ));
128 myZ->setText(QString::number(0.0));
129 connect(myZ, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
131 // Layout widgets in the horizontal group box
132 aHBoxLayout->addWidget(TextLabelX);
133 aHBoxLayout->addWidget(myX);
134 aHBoxLayout->addWidget(TextLabelY);
135 aHBoxLayout->addWidget(myY);
136 aHBoxLayout->addWidget(TextLabelZ);
137 aHBoxLayout->addWidget(myZ);
140 QGroupBox* aGroupBox = new QGroupBox(this);
141 QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
142 aHBoxLayout2->setMargin(11);
143 aHBoxLayout2->setSpacing(6);
145 QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox );
146 m_bClose->setObjectName("m_bClose");
147 m_bClose->setAutoDefault(TRUE);
148 m_bClose->setFixedSize(m_bClose->sizeHint());
149 connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
152 aHBoxLayout2->addWidget(m_bClose);
154 // Layout top level widgets
155 layoutDlg->addLayout(aCheckBox,0,0);
156 layoutDlg->addWidget(myGroupBoxSel,1,0);
157 layoutDlg->addWidget(myGroupBoxCoord,2,0);
158 layoutDlg->addWidget(aGroupBox,3,0);
160 setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
161 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
163 this->resize(400, this->sizeHint().height());
165 myEventCallbackCommand->Delete();
166 myEventCallbackCommand->SetClientData(this);
167 myEventCallbackCommand->SetCallback(SVTK_SetRotationPointDlg::ProcessEvents);
168 myIsObserverAdded = false;
172 * Destroys the object and frees any allocated resources
174 SVTK_SetRotationPointDlg
175 ::~SVTK_SetRotationPointDlg()
177 // no need to delete child widgets, Qt does it all for us
181 SVTK_SetRotationPointDlg
184 if ( !myIsObserverAdded ) {
185 vtkInteractorStyle* aIStyle = myRWInteractor->GetInteractorStyle();
186 aIStyle->AddObserver(SVTK::BBCenterChanged, myEventCallbackCommand.GetPointer(), myPriority);
187 aIStyle->AddObserver(SVTK::RotationPointChanged, myEventCallbackCommand.GetPointer(), myPriority);
188 myIsObserverAdded = true;
193 Return true if it is the first show for this dialog
196 SVTK_SetRotationPointDlg
199 return myIsBBCenter->isChecked() && myX->text().toDouble() == 0.
200 && myY->text().toDouble() == 0. && myZ->text().toDouble() == 0.;
207 SVTK_SetRotationPointDlg
208 ::ProcessEvents(vtkObject* vtkNotUsed(theObject),
209 unsigned long theEvent,
213 SVTK_SetRotationPointDlg* self = reinterpret_cast<SVTK_SetRotationPointDlg*>(theClientData);
214 vtkFloatingPointType* aCoord = (vtkFloatingPointType*)theCallData;
216 switch ( theEvent ) {
217 case SVTK::BBCenterChanged:
218 if ( self->myIsBBCenter->isChecked()
220 IsBBEmpty(self->myMainWindow->getRenderer()) )
224 self->myX->setText( QString::number(aCoord[0]) );
225 self->myY->setText( QString::number(aCoord[1]) );
226 self->myZ->setText( QString::number(aCoord[2]) );
230 case SVTK::RotationPointChanged:
233 self->myX->setText( QString::number(aCoord[0]) );
234 self->myY->setText( QString::number(aCoord[1]) );
235 self->myZ->setText( QString::number(aCoord[2]) );
237 if ( !self->myIsBBCenter->isChecked() )
238 self->mySelectPoint->toggle();
243 SVTK_SetRotationPointDlg
244 ::setEnabled(QGroupBox* theGrp, const bool theState)
246 QObjectList aChildren(theGrp->children());
248 for(int i = 0; i < aChildren.size(); i++)
250 anObj = aChildren.at(i);
251 if (anObj !=0 && anObj->inherits("QLineEdit"))
252 ((QLineEdit*)anObj)->setReadOnly(!theState);
253 if (anObj !=0 && anObj->inherits("QPushButton"))
254 ((QLineEdit*)anObj)->setEnabled(theState);
260 SVTK_SetRotationPointDlg
261 ::onBBCenterChecked()
263 setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
264 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
266 if ( myIsBBCenter->isChecked() )
268 if ( mySelectPoint->isChecked() )
269 mySelectPoint->toggle();
270 // activate mode : the rotation point is the center of the bounding box
271 // send the data to the SVTK_InteractorStyle: set the type of the rotation point
272 // calculate coordinates of the rotation point
273 myMainWindow->activateSetRotationGravity();
277 QString aX = myX->text();
278 myX->setText(QString::number(aX.toDouble()+1.));
284 SVTK_SetRotationPointDlg
287 if ( mySelectPoint->isChecked() )
288 mySelectPoint->toggle();
289 myX->setText(QString::number(0.0));
290 myY->setText(QString::number(0.0));
291 myZ->setText(QString::number(0.0));
295 SVTK_SetRotationPointDlg
298 if ( mySelectPoint->isChecked() )
299 myMainWindow->activateStartPointSelection();
301 mySelectPoint->toggle();
305 SVTK_SetRotationPointDlg
308 if ( !myIsBBCenter->isChecked() ) {
309 if ( mySelectPoint->isChecked()
311 ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
312 mySelectPoint->toggle();
313 vtkFloatingPointType aCenter[3] = {myX->text().toDouble(),
314 myY->text().toDouble(),
315 myZ->text().toDouble()};
316 myMainWindow->activateSetRotationSelected((void*)aCenter);
319 myMainWindow->activateSetRotationGravity();
323 SVTK_SetRotationPointDlg