1 // Copyright (C) 2007-2013 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 #include "OCCViewer_SetRotationPointDlg.h"
25 #include <QtxAction.h>
27 #include "OCCViewer_ViewWindow.h"
32 #include <QPushButton>
33 #include <QGridLayout>
34 #include <QDoubleValidator>
36 #include <QHBoxLayout>
40 \param view - view window
41 \param parent - parent widget
42 \param name - dialog name
43 \param modal - is this dialog modal
46 OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWindow* view, const char* name, bool modal, Qt::WindowFlags fl )
47 : QDialog( view, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
50 setObjectName( "OCCViewer_SetRotationPointDlg" );
53 setWindowTitle(tr("CAPTION"));
54 setSizeGripEnabled(TRUE);
56 // Create layout for this dialog
57 QGridLayout* layoutDlg = new QGridLayout (this);
58 layoutDlg->setSpacing(6);
59 layoutDlg->setMargin(11);
61 // Create check box "Use Bounding Box Center"
62 QHBoxLayout* aCheckBox = new QHBoxLayout;
64 myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"));
65 myIsBBCenter->setChecked(true);
66 aCheckBox->addWidget(myIsBBCenter);
67 connect(myIsBBCenter, SIGNAL(stateChanged(int)), SLOT(onBBCenterChecked()));
69 // Create croup button with radio buttons
70 myGroupBoxSel = new QGroupBox( "", this );
71 QVBoxLayout *vbox = new QVBoxLayout;
75 // Create "Set to Origin" button
76 myToOrigin = new QPushButton(tr("LBL_TOORIGIN"));
77 vbox->addWidget(myToOrigin);
78 connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
80 // Create "Select Point from View" button
81 mySelectPoint = new QPushButton(tr("LBL_SELECTPOINT"));
82 mySelectPoint->setCheckable(true);
83 vbox->addWidget(mySelectPoint);
84 connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
86 myGroupBoxSel->setLayout(vbox);
88 // Create croup box with grid layout
89 myGroupBoxCoord = new QGroupBox(this);
90 myGroupBoxCoord->setObjectName("GroupBox");
91 QHBoxLayout* aHBoxLayout = new QHBoxLayout(myGroupBoxCoord);
92 aHBoxLayout->setMargin(11);
93 aHBoxLayout->setSpacing(6);
96 QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord );
97 TextLabelX->setObjectName("TextLabelX");
98 TextLabelX->setFixedWidth(15);
99 myX = new QLineEdit(myGroupBoxCoord);
100 myX->setValidator(new QDoubleValidator(myX));
101 myX->setText(QString::number(0.0));
102 connect(myX, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
105 QLabel* TextLabelY = new QLabel (tr("LBL_Y"), myGroupBoxCoord );
106 TextLabelY->setObjectName("TextLabelY");
107 TextLabelY->setFixedWidth(15);
108 myY = new QLineEdit(myGroupBoxCoord);
109 myY->setValidator(new QDoubleValidator(myY));
110 myY->setText(QString::number(0.0));
111 connect(myY, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
114 QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord );
115 TextLabelZ->setObjectName("TextLabelZ");
116 TextLabelZ->setFixedWidth(15);
117 myZ = new QLineEdit(myGroupBoxCoord);
118 myZ->setValidator(new QDoubleValidator(myZ));
119 myZ->setText(QString::number(0.0));
120 connect(myZ, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
122 // Layout widgets in the horizontal group box
123 aHBoxLayout->addWidget(TextLabelX);
124 aHBoxLayout->addWidget(myX);
125 aHBoxLayout->addWidget(TextLabelY);
126 aHBoxLayout->addWidget(myY);
127 aHBoxLayout->addWidget(TextLabelZ);
128 aHBoxLayout->addWidget(myZ);
131 QGroupBox* aGroupBox = new QGroupBox(this);
132 QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
133 aHBoxLayout2->setMargin(11);
134 aHBoxLayout2->setSpacing(6);
136 QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox );
137 m_bClose->setObjectName("m_bClose");
138 m_bClose->setAutoDefault(TRUE);
139 m_bClose->setFixedSize(m_bClose->sizeHint());
140 connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
143 aHBoxLayout2->addWidget(m_bClose);
145 // Layout top level widgets
146 layoutDlg->addLayout(aCheckBox,0,0);
147 layoutDlg->addWidget(myGroupBoxSel,1,0);
148 layoutDlg->addWidget(myGroupBoxCoord,2,0);
149 layoutDlg->addWidget(aGroupBox,3,0);
151 setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
152 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
154 this->resize(400, this->sizeHint().height());
156 connect(view, SIGNAL(Show( QShowEvent * )), this, SLOT(onViewShow()));
157 connect(view, SIGNAL(Hide( QHideEvent * )), this, SLOT(onViewHide()));
161 * Destroys the object and frees any allocated resources
163 OCCViewer_SetRotationPointDlg
164 ::~OCCViewer_SetRotationPointDlg()
166 // no need to delete child widgets, Qt does it all for us
170 Return true if it is the first show for this dialog
173 OCCViewer_SetRotationPointDlg
176 return myIsBBCenter->isChecked() && myX->text().toDouble() == 0.
177 && myY->text().toDouble() == 0. && myZ->text().toDouble() == 0.;
181 OCCViewer_SetRotationPointDlg
182 ::setEnabled(QGroupBox* theGrp, const bool theState)
184 QObjectList aChildren(theGrp->children());
186 for(int i = 0; i < aChildren.size(); i++)
188 anObj = aChildren.at(i);
189 if (anObj !=0 && anObj->inherits("QLineEdit"))
190 ((QLineEdit*)anObj)->setReadOnly(!theState);
191 if (anObj !=0 && anObj->inherits("QPushButton"))
192 ((QLineEdit*)anObj)->setEnabled(theState);
198 OCCViewer_SetRotationPointDlg
199 ::onBBCenterChecked()
201 setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
202 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
204 if ( myIsBBCenter->isChecked() )
206 if ( mySelectPoint->isChecked() )
207 mySelectPoint->toggle();
208 myView->activateSetRotationGravity();
211 myView->activateSetRotationSelected(myX->text().toDouble(),
212 myY->text().toDouble(),
213 myZ->text().toDouble());
217 OCCViewer_SetRotationPointDlg
220 if ( mySelectPoint->isChecked() )
221 mySelectPoint->toggle();
223 myView->activateSetRotationSelected(myX->text().toDouble(),
224 myY->text().toDouble(),
225 myZ->text().toDouble());
229 OCCViewer_SetRotationPointDlg
232 if ( mySelectPoint->isChecked() )
233 myView->activateStartPointSelection();
235 mySelectPoint->toggle();
239 OCCViewer_SetRotationPointDlg
242 if ( !myIsBBCenter->isChecked() )
244 if ( mySelectPoint->isChecked()
246 ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
247 mySelectPoint->toggle();
248 myView->activateSetRotationSelected(myX->text().toDouble(),
249 myY->text().toDouble(),
250 myZ->text().toDouble());
255 OCCViewer_SetRotationPointDlg
256 ::setCoords(double theX, double theY, double theZ)
258 myX->setText(QString::number(theX));
259 myY->setText(QString::number(theY));
260 myZ->setText(QString::number(theZ));
264 OCCViewer_SetRotationPointDlg
267 if ( !myIsBBCenter->isChecked() )
268 mySelectPoint->toggle();
272 OCCViewer_SetRotationPointDlg
275 myAction->setChecked( false );
280 OCCViewer_SetRotationPointDlg
283 if(myAction->isChecked())
290 OCCViewer_SetRotationPointDlg
297 Custom handling of close event: toggle action
300 OCCViewer_SetRotationPointDlg
301 ::closeEvent( QCloseEvent* e )
303 myAction->setChecked( false );
304 QDialog::closeEvent( e );