1 // Copyright (C) 2007-2008 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
22 #include "OCCViewer_SetRotationPointDlg.h"
24 #include <QtxAction.h>
26 #include "OCCViewer_ViewWindow.h"
31 #include <QPushButton>
32 #include <QGridLayout>
33 #include <QDoubleValidator>
35 #include <QHBoxLayout>
39 \param view - view window
40 \param parent - parent widget
41 \param name - dialog name
42 \param modal - is this dialog modal
45 OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWindow* view, QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl )
46 : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
49 setObjectName( "OCCViewer_SetRotationPointDlg" );
52 setWindowTitle(tr("CAPTION"));
53 setSizeGripEnabled(TRUE);
55 // Create layout for this dialog
56 QGridLayout* layoutDlg = new QGridLayout (this);
57 layoutDlg->setSpacing(6);
58 layoutDlg->setMargin(11);
60 // Create check box "Use Bounding Box Center"
61 QHBoxLayout* aCheckBox = new QHBoxLayout;
63 myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"));
64 myIsBBCenter->setChecked(true);
65 aCheckBox->addWidget(myIsBBCenter);
66 connect(myIsBBCenter, SIGNAL(stateChanged(int)), SLOT(onBBCenterChecked()));
68 // Create croup button with radio buttons
69 myGroupBoxSel = new QGroupBox( "", this );
70 QVBoxLayout *vbox = new QVBoxLayout;
74 // Create "Set to Origin" button
75 myToOrigin = new QPushButton(tr("LBL_TOORIGIN"));
76 vbox->addWidget(myToOrigin);
77 connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
79 // Create "Select Point from View" button
80 mySelectPoint = new QPushButton(tr("LBL_SELECTPOINT"));
81 mySelectPoint->setCheckable(true);
82 vbox->addWidget(mySelectPoint);
83 connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
85 myGroupBoxSel->setLayout(vbox);
87 // Create croup box with grid layout
88 myGroupBoxCoord = new QGroupBox(this);
89 myGroupBoxCoord->setObjectName("GroupBox");
90 QHBoxLayout* aHBoxLayout = new QHBoxLayout(myGroupBoxCoord);
91 aHBoxLayout->setMargin(11);
92 aHBoxLayout->setSpacing(6);
95 QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord );
96 TextLabelX->setObjectName("TextLabelX");
97 TextLabelX->setFixedWidth(15);
98 myX = new QLineEdit(myGroupBoxCoord);
99 myX->setValidator(new QDoubleValidator(myX));
100 myX->setText(QString::number(0.0));
101 connect(myX, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
104 QLabel* TextLabelY = new QLabel (tr("LBL_Y"), myGroupBoxCoord );
105 TextLabelY->setObjectName("TextLabelY");
106 TextLabelY->setFixedWidth(15);
107 myY = new QLineEdit(myGroupBoxCoord);
108 myY->setValidator(new QDoubleValidator(myY));
109 myY->setText(QString::number(0.0));
110 connect(myY, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
113 QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord );
114 TextLabelZ->setObjectName("TextLabelZ");
115 TextLabelZ->setFixedWidth(15);
116 myZ = new QLineEdit(myGroupBoxCoord);
117 myZ->setValidator(new QDoubleValidator(myZ));
118 myZ->setText(QString::number(0.0));
119 connect(myZ, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
121 // Layout widgets in the horizontal group box
122 aHBoxLayout->addWidget(TextLabelX);
123 aHBoxLayout->addWidget(myX);
124 aHBoxLayout->addWidget(TextLabelY);
125 aHBoxLayout->addWidget(myY);
126 aHBoxLayout->addWidget(TextLabelZ);
127 aHBoxLayout->addWidget(myZ);
130 QGroupBox* aGroupBox = new QGroupBox(this);
131 QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
132 aHBoxLayout2->setMargin(11);
133 aHBoxLayout2->setSpacing(6);
135 QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox );
136 m_bClose->setObjectName("m_bClose");
137 m_bClose->setAutoDefault(TRUE);
138 m_bClose->setFixedSize(m_bClose->sizeHint());
139 connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
142 aHBoxLayout2->addWidget(m_bClose);
144 // Layout top level widgets
145 layoutDlg->addLayout(aCheckBox,0,0);
146 layoutDlg->addWidget(myGroupBoxSel,1,0);
147 layoutDlg->addWidget(myGroupBoxCoord,2,0);
148 layoutDlg->addWidget(aGroupBox,3,0);
150 setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
151 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
153 this->resize(400, this->sizeHint().height());
155 connect(view, SIGNAL(Show( QShowEvent * )), this, SLOT(onViewShow()));
156 connect(view, SIGNAL(Hide( QHideEvent * )), this, SLOT(onViewHide()));
160 * Destroys the object and frees any allocated resources
162 OCCViewer_SetRotationPointDlg
163 ::~OCCViewer_SetRotationPointDlg()
165 // no need to delete child widgets, Qt does it all for us
169 Return true if it is the first show for this dialog
172 OCCViewer_SetRotationPointDlg
175 return myIsBBCenter->isChecked() && myX->text().toDouble() == 0.
176 && myY->text().toDouble() == 0. && myZ->text().toDouble() == 0.;
180 OCCViewer_SetRotationPointDlg
181 ::setEnabled(QGroupBox* theGrp, const bool theState)
183 QObjectList aChildren(theGrp->children());
185 for(int i = 0; i < aChildren.size(); i++)
187 anObj = aChildren.at(i);
188 if (anObj !=0 && anObj->inherits("QLineEdit"))
189 ((QLineEdit*)anObj)->setReadOnly(!theState);
190 if (anObj !=0 && anObj->inherits("QPushButton"))
191 ((QLineEdit*)anObj)->setEnabled(theState);
197 OCCViewer_SetRotationPointDlg
198 ::onBBCenterChecked()
200 setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
201 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
203 if ( myIsBBCenter->isChecked() )
205 if ( mySelectPoint->isChecked() )
206 mySelectPoint->toggle();
207 myView->activateSetRotationGravity();
210 myView->activateSetRotationSelected(myX->text().toDouble(),
211 myY->text().toDouble(),
212 myZ->text().toDouble());
216 OCCViewer_SetRotationPointDlg
219 if ( mySelectPoint->isChecked() )
220 mySelectPoint->toggle();
222 myView->activateSetRotationSelected(myX->text().toDouble(),
223 myY->text().toDouble(),
224 myZ->text().toDouble());
228 OCCViewer_SetRotationPointDlg
231 if ( mySelectPoint->isChecked() )
232 myView->activateStartPointSelection();
234 mySelectPoint->toggle();
238 OCCViewer_SetRotationPointDlg
241 if ( !myIsBBCenter->isChecked() )
243 if ( mySelectPoint->isChecked()
245 ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
246 mySelectPoint->toggle();
247 myView->activateSetRotationSelected(myX->text().toDouble(),
248 myY->text().toDouble(),
249 myZ->text().toDouble());
254 OCCViewer_SetRotationPointDlg
255 ::setCoords(double theX, double theY, double theZ)
257 myX->setText(QString::number(theX));
258 myY->setText(QString::number(theY));
259 myZ->setText(QString::number(theZ));
263 OCCViewer_SetRotationPointDlg
266 if ( !myIsBBCenter->isChecked() )
267 mySelectPoint->toggle();
271 OCCViewer_SetRotationPointDlg
274 myAction->setChecked( false );
279 OCCViewer_SetRotationPointDlg
282 if(myAction->isChecked())
289 OCCViewer_SetRotationPointDlg
296 Custom handling of close event: toggle action
299 OCCViewer_SetRotationPointDlg
300 ::closeEvent( QCloseEvent* e )
302 myAction->setChecked( false );
303 QDialog::closeEvent( e );