1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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>
34 #include <QGridLayout>
35 #include <QDoubleValidator>
37 #include <QHBoxLayout>
41 \param view - view window
42 \param parent - parent widget
43 \param name - dialog name
44 \param modal - is this dialog modal
47 OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWindow* view, const char* name, bool modal, Qt::WindowFlags fl )
48 : QDialog( view, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
51 setObjectName( "OCCViewer_SetRotationPointDlg" );
54 setWindowTitle(tr("CAPTION"));
55 setSizeGripEnabled(TRUE);
57 // Create layout for this dialog
58 QGridLayout* layoutDlg = new QGridLayout (this);
59 layoutDlg->setSpacing(6);
60 layoutDlg->setMargin(11);
62 // Create check box "Use Bounding Box Center"
63 QHBoxLayout* aCheckBox = new QHBoxLayout;
65 myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"));
66 myIsBBCenter->setChecked(true);
67 aCheckBox->addWidget(myIsBBCenter);
68 connect(myIsBBCenter, SIGNAL(stateChanged(int)), SLOT(onBBCenterChecked()));
70 // Create croup button with radio buttons
71 myGroupBoxSel = new QGroupBox( "", this );
72 QVBoxLayout *vbox = new QVBoxLayout;
76 // Create "Set to Origin" button
77 myToOrigin = new QPushButton(tr("LBL_TOORIGIN"));
78 vbox->addWidget(myToOrigin);
79 connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
81 // Create "Gravity Center of Select Object" button
82 mySelectPoint = new QPushButton(tr("LBL_SELECTPOINT"));
83 mySelectPoint->setCheckable(true);
85 QMenu* menuType = new QMenu( this );
86 mySelectActions[ menuType->addAction( tr("LBL_POINT") ) ] = TopAbs_VERTEX;
87 mySelectActions[ menuType->addAction( tr("LBL_EDGE") ) ] = TopAbs_EDGE;
88 mySelectActions[ menuType->addAction( tr("LBL_FACE") ) ] = TopAbs_FACE;
89 mySelectActions[ menuType->addAction( tr("LBL_SOLID") ) ] = TopAbs_SOLID;
90 connect( menuType, SIGNAL( triggered( QAction* ) ), this, SLOT( onSelectMenu( QAction* ) ) );
92 mySelectPoint->setMenu( menuType );
94 vbox->addWidget(mySelectPoint);
96 myGroupBoxSel->setLayout(vbox);
98 // Create croup box with grid layout
99 myGroupBoxCoord = new QGroupBox(this);
100 myGroupBoxCoord->setObjectName("GroupBox");
101 QHBoxLayout* aHBoxLayout = new QHBoxLayout(myGroupBoxCoord);
102 aHBoxLayout->setMargin(11);
103 aHBoxLayout->setSpacing(6);
106 QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord );
107 TextLabelX->setObjectName("TextLabelX");
108 TextLabelX->setFixedWidth(15);
109 myX = new QLineEdit(myGroupBoxCoord);
110 myX->setValidator(new QDoubleValidator(myX));
111 myX->setText(QString::number(0.0));
112 connect(myX, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
115 QLabel* TextLabelY = new QLabel (tr("LBL_Y"), myGroupBoxCoord );
116 TextLabelY->setObjectName("TextLabelY");
117 TextLabelY->setFixedWidth(15);
118 myY = new QLineEdit(myGroupBoxCoord);
119 myY->setValidator(new QDoubleValidator(myY));
120 myY->setText(QString::number(0.0));
121 connect(myY, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
124 QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord );
125 TextLabelZ->setObjectName("TextLabelZ");
126 TextLabelZ->setFixedWidth(15);
127 myZ = new QLineEdit(myGroupBoxCoord);
128 myZ->setValidator(new QDoubleValidator(myZ));
129 myZ->setText(QString::number(0.0));
130 connect(myZ, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
132 // Layout widgets in the horizontal group box
133 aHBoxLayout->addWidget(TextLabelX);
134 aHBoxLayout->addWidget(myX);
135 aHBoxLayout->addWidget(TextLabelY);
136 aHBoxLayout->addWidget(myY);
137 aHBoxLayout->addWidget(TextLabelZ);
138 aHBoxLayout->addWidget(myZ);
141 QGroupBox* aGroupBox = new QGroupBox(this);
142 QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
143 aHBoxLayout2->setMargin(11);
144 aHBoxLayout2->setSpacing(6);
146 QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox );
147 m_bClose->setObjectName("m_bClose");
148 m_bClose->setAutoDefault(TRUE);
149 m_bClose->setFixedSize(m_bClose->sizeHint());
150 connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
153 aHBoxLayout2->addWidget(m_bClose);
155 // Layout top level widgets
156 layoutDlg->addLayout(aCheckBox,0,0);
157 layoutDlg->addWidget(myGroupBoxSel,1,0);
158 layoutDlg->addWidget(myGroupBoxCoord,2,0);
159 layoutDlg->addWidget(aGroupBox,3,0);
161 setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
162 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
164 this->resize(400, this->sizeHint().height());
166 connect(view, SIGNAL(Show( QShowEvent * )), this, SLOT(onViewShow()));
167 connect(view, SIGNAL(Hide( QHideEvent * )), this, SLOT(onViewHide()));
171 * Destroys the object and frees any allocated resources
173 OCCViewer_SetRotationPointDlg
174 ::~OCCViewer_SetRotationPointDlg()
176 // no need to delete child widgets, Qt does it all for us
180 Return true if it is the first show for this dialog
183 OCCViewer_SetRotationPointDlg
186 return myIsBBCenter->isChecked() && myX->text().toDouble() == 0.
187 && myY->text().toDouble() == 0. && myZ->text().toDouble() == 0.;
191 OCCViewer_SetRotationPointDlg
192 ::setEnabled(QGroupBox* theGrp, const bool theState)
194 QObjectList aChildren(theGrp->children());
196 for(int i = 0; i < aChildren.size(); i++)
198 anObj = aChildren.at(i);
199 if (anObj !=0 && anObj->inherits("QLineEdit"))
200 ((QLineEdit*)anObj)->setReadOnly(!theState);
201 if (anObj !=0 && anObj->inherits("QPushButton"))
202 ((QLineEdit*)anObj)->setEnabled(theState);
208 OCCViewer_SetRotationPointDlg
209 ::onBBCenterChecked()
211 setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
212 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
214 if ( myIsBBCenter->isChecked() )
216 if ( mySelectPoint->isChecked() )
217 mySelectPoint->toggle();
218 myView->activateSetRotationGravity();
221 myView->activateSetRotationSelected(myX->text().toDouble(),
222 myY->text().toDouble(),
223 myZ->text().toDouble());
227 OCCViewer_SetRotationPointDlg
230 mySelectPoint->setChecked( false );
232 myView->activateSetRotationSelected(myX->text().toDouble(),
233 myY->text().toDouble(),
234 myZ->text().toDouble());
238 OCCViewer_SetRotationPointDlg
239 ::onSelectMenu( QAction* theAction )
241 mySelectPoint->setChecked( true );
242 myView->activateStartPointSelection( mySelectActions[theAction] );
246 OCCViewer_SetRotationPointDlg
249 if ( !myIsBBCenter->isChecked() )
251 if ( mySelectPoint->isChecked()
253 ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
254 mySelectPoint->toggle();
255 myView->activateSetRotationSelected(myX->text().toDouble(),
256 myY->text().toDouble(),
257 myZ->text().toDouble());
262 OCCViewer_SetRotationPointDlg
263 ::setCoords(double theX, double theY, double theZ)
265 myX->setText(QString::number(theX));
266 myY->setText(QString::number(theY));
267 myZ->setText(QString::number(theZ));
271 OCCViewer_SetRotationPointDlg
274 if ( !myIsBBCenter->isChecked() )
275 mySelectPoint->toggle();
279 OCCViewer_SetRotationPointDlg
282 myAction->setChecked( false );
287 OCCViewer_SetRotationPointDlg
290 if(myAction->isChecked())
297 OCCViewer_SetRotationPointDlg
304 Custom handling of close event: toggle action
307 OCCViewer_SetRotationPointDlg
308 ::closeEvent( QCloseEvent* e )
310 myAction->setChecked( false );
311 QDialog::closeEvent( e );