1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
23 // File : BlocksGUI_TrsfDlg.cxx
24 // Author : Julia DOROVSKIKH
28 #include "BlocksGUI_TrsfDlg.h"
30 #include "DlgRef_SpinBox.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
35 #include "OCCViewer_ViewModel.h"
37 #include <TColStd_IndexedMapOfInteger.hxx>
41 //=================================================================================
42 // class : BlocksGUI_TrsfDlg()
43 // purpose : Constructs a BlocksGUI_TrsfDlg which is a child of 'parent'.
44 //=================================================================================
45 BlocksGUI_TrsfDlg::BlocksGUI_TrsfDlg (QWidget* parent,
47 : GEOMBase_Skeleton(parent, "TrsfDlg", modal,
48 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BLOCK_MULTITRSF_SIMPLE")));
51 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BLOCK_MULTITRSF_DOUBLE")));
52 QPixmap imageS (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_BLOCK_MULTITRSF_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_BLOCK_MULTITRSF"));
59 RadioButton1->setPixmap(image1);
60 RadioButton2->setPixmap(image2);
61 RadioButton3->close(TRUE);
64 myGrp1 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_BLOCK_MULTITRSF_SIMPLE"), this);
66 QGroupBox* aSelGrp1 = new QGroupBox(3, Qt::Horizontal, myGrp1);
67 aSelGrp1->setFrameStyle(QFrame::NoFrame);
68 aSelGrp1->setInsideMargin(0);
70 createSelWg(tr("GEOM_MAIN_OBJECT"), imageS, aSelGrp1, MainObj1);
71 createSelWg(tr("FACE_1"), imageS, aSelGrp1, Face1);
72 createSelWg(tr("FACE_2"), imageS, aSelGrp1, Face2);
74 QGroupBox* aSpinGrp1 = new QGroupBox(1, Qt::Vertical, myGrp1);
75 aSpinGrp1->setFrameStyle(QFrame::NoFrame);
76 aSpinGrp1->setInsideMargin(0);
78 new QLabel(tr("GEOM_NB_TIMES"), aSpinGrp1);
79 mySpinBox[SpinBox1] = new DlgRef_SpinBox(aSpinGrp1);
81 // Create second group
82 myGrp2 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_BLOCK_MULTITRSF_DOUBLE"), this);
85 QGroupBox* aSelGrp2U = new QGroupBox(3, Qt::Horizontal, myGrp2);
86 aSelGrp2U->setFrameStyle(QFrame::NoFrame);
87 aSelGrp2U->setInsideMargin(0);
89 createSelWg(tr("GEOM_MAIN_OBJECT"), imageS, aSelGrp2U, MainObj2);
90 createSelWg(tr("FACE_1U"), imageS, aSelGrp2U, Face1U);
91 createSelWg(tr("FACE_2U"), imageS, aSelGrp2U, Face2U);
93 QGroupBox* aSpinGrp2U = new QGroupBox(1, Qt::Vertical, myGrp2);
94 aSpinGrp2U->setFrameStyle(QFrame::NoFrame);
95 aSpinGrp2U->setInsideMargin(0);
97 new QLabel(tr("GEOM_NB_TIMES_U"), aSpinGrp2U);
98 mySpinBox[SpinBox2U] = new DlgRef_SpinBox(aSpinGrp2U);
101 QGroupBox* aSelGrp2V = new QGroupBox(3, Qt::Horizontal, myGrp2);
102 aSelGrp2V->setFrameStyle(QFrame::NoFrame);
103 aSelGrp2V->setInsideMargin(0);
105 createSelWg(tr("FACE_1V"), imageS, aSelGrp2V, Face1V);
106 createSelWg(tr("FACE_2V"), imageS, aSelGrp2V, Face2V);
108 QGroupBox* aSpinGrp2V = new QGroupBox(1, Qt::Vertical, myGrp2);
109 aSpinGrp2V->setFrameStyle(QFrame::NoFrame);
110 aSpinGrp2V->setInsideMargin(0);
112 new QLabel(tr("GEOM_NB_TIMES_V"), aSpinGrp2V);
113 mySpinBox[SpinBox2V] = new DlgRef_SpinBox(aSpinGrp2V);
115 (new QLabel(myGrp2))->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
117 // Add groups to layout
118 Layout1->addWidget( myGrp1, 2, 0 );
119 Layout1->addWidget( myGrp2, 2, 0 );
120 /***************************************************************/
125 //=================================================================================
126 // function : ~BlocksGUI_TrsfDlg()
127 // purpose : Destroys the object and frees any allocated resources
128 //=================================================================================
129 BlocksGUI_TrsfDlg::~BlocksGUI_TrsfDlg()
131 // no need to delete child widgets, Qt does it all for us
134 //=================================================================================
137 //=================================================================================
138 void BlocksGUI_TrsfDlg::Init()
140 // Set range of spinboxes
141 double SpecificStep = 1.0;
142 QMap<int, DlgRef_SpinBox*>::iterator anIter;
143 for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter) {
144 anIter.data()->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
147 // signals and slots connections
148 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
150 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
152 QMap<int, QPushButton*>::iterator anIterBtn;
153 for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
154 connect(anIterBtn.data(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 QMap<int, DlgRef_SpinBox*>::iterator anIterSpin;
157 for (anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin)
158 connect(anIterSpin.data(), SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
160 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
161 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
163 // init controls and fields
164 initName(tr("GEOM_BLOCK_MULTITRSF"));
166 myConstructorId = -1;
167 ConstructorsClicked(0);
170 //=================================================================================
171 // function : ConstructorsClicked()
172 // purpose : Radio button management
173 //=================================================================================
174 void BlocksGUI_TrsfDlg::ConstructorsClicked (int constructorId)
176 if (myConstructorId == constructorId)
179 myConstructorId = constructorId;
181 switch (constructorId) {
185 mySpinBox[SpinBox1]->SetValue(2.0);
186 myEditCurrentArgument = mySelName[MainObj1];
193 mySpinBox[SpinBox2U]->SetValue(2.0);
194 mySpinBox[SpinBox2V]->SetValue(2.0);
195 myEditCurrentArgument = mySelName[MainObj2];
196 myFaces[Face1U] = -1;
197 myFaces[Face2U] = -1;
198 myFaces[Face1V] = -1;
199 myFaces[Face2V] = -1;
206 QMap<int, QLineEdit*>::iterator anIterLE;
207 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
208 anIterLE.data()->setText("");
211 myShape = GEOM::GEOM_Object::_nil();
218 //=================================================================================
219 // function : ClickOnOk()
221 //=================================================================================
222 void BlocksGUI_TrsfDlg::ClickOnOk()
228 //=================================================================================
229 // function : ClickOnApply()
231 //=================================================================================
232 bool BlocksGUI_TrsfDlg::ClickOnApply()
241 //=================================================================================
242 // function : SelectionIntoArgument()
243 // purpose : Called when selection has changed
244 //=================================================================================
245 void BlocksGUI_TrsfDlg::SelectionIntoArgument()
248 myEditCurrentArgument->setText("");
250 // Get index of current selection focus
252 QMap<int, QLineEdit*>::iterator anIter;
253 for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
254 if (myEditCurrentArgument == anIter.data()) {
255 aCurrFocus = anIter.key();
260 // If selection of main object is activated
261 if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2) {
262 if (IObjectCount() == 1) {
263 Standard_Boolean aResult = Standard_False;
264 GEOM::GEOM_Object_var anObj =
265 GEOMBase::ConvertIOinGEOMObject(firstIObject(), aResult);
267 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
269 mySelName[aCurrFocus]->setText(GEOMBase::GetName(anObj));
275 myShape = GEOM::GEOM_Object::_nil();
278 // If face selection is activated
279 else if (aCurrFocus == Face1 || aCurrFocus == Face2 ||
280 aCurrFocus == Face1U || aCurrFocus == Face2U ||
281 aCurrFocus == Face1V || aCurrFocus == Face2V) {
282 if (IObjectCount() == 1) {
283 Standard_Boolean aResult = Standard_False;
284 GEOM::GEOM_Object_var anObj =
285 GEOMBase::ConvertIOinGEOMObject(firstIObject(), aResult);
287 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
288 TColStd_IndexedMapOfInteger anIndexes;
289 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
291 if (anIndexes.Extent() == 1) {
292 int anIndex = anIndexes(1);
293 QString aFaceName = QString(GEOMBase::GetName(anObj)) + ":%1";
294 myEditCurrentArgument->setText(aFaceName.arg(anIndex));
295 myFaces[aCurrFocus] = anIndex;
302 myFaces[aCurrFocus] = -1;
306 //=================================================================================
307 // function : SetEditCurrentArgument()
309 //=================================================================================
310 void BlocksGUI_TrsfDlg::SetEditCurrentArgument()
312 QPushButton* aSender = (QPushButton*)sender();
314 QMap<int, QPushButton*>::iterator anIter;
315 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
316 if (anIter.data() == aSender) {
317 mySelName[anIter.key()]->setFocus();
318 myEditCurrentArgument = mySelName[anIter.key()];
326 //=================================================================================
327 // function : ActivateThisDialog()
329 //=================================================================================
330 void BlocksGUI_TrsfDlg::ActivateThisDialog()
332 GEOMBase_Skeleton::ActivateThisDialog();
333 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
334 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
340 //=================================================================================
341 // function : enterEvent()
343 //=================================================================================
344 void BlocksGUI_TrsfDlg::enterEvent (QEvent* e)
346 if (!GroupConstructors->isEnabled())
347 this->ActivateThisDialog();
350 //=================================================================================
351 // function : DeactivateActiveDialog()
353 //=================================================================================
354 //void BlocksGUI_TrsfDlg::DeactivateActiveDialog()
356 // // disconnect selection
357 // GEOMBase_Skeleton::DeactivateActiveDialog();
360 //=================================================================================
361 // function : ValueChangedInSpinBox()
363 //=================================================================================
364 void BlocksGUI_TrsfDlg::ValueChangedInSpinBox (double newValue)
369 //=================================================================================
370 // function : createSelWg()
372 //=================================================================================
373 void BlocksGUI_TrsfDlg::createSelWg (const QString& theLbl,
378 new QLabel(theLbl, theParent);
379 mySelBtn[theId] = new QPushButton(theParent);
380 mySelBtn[theId]->setPixmap(thePix);
381 mySelName[theId] = new QLineEdit(theParent);
382 mySelName[theId]->setReadOnly(true);
385 //=================================================================================
386 // function : activateSelection
387 // purpose : Activate selection in accordance with myEditCurrentArgument
388 //=================================================================================
389 void BlocksGUI_TrsfDlg::activateSelection()
391 if (!myShape->_is_nil() &&
392 (myEditCurrentArgument == mySelName[ Face1 ] ||
393 myEditCurrentArgument == mySelName[ Face2 ] ||
394 myEditCurrentArgument == mySelName[ Face1U ] ||
395 myEditCurrentArgument == mySelName[ Face2U ] ||
396 myEditCurrentArgument == mySelName[ Face1V ] ||
397 myEditCurrentArgument == mySelName[ Face2V ])) {
399 // Local selection is available only in the OCC Viewer
400 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
401 == OCCViewer_Viewer::Type()) {
402 localSelection(myShape, TopAbs_FACE);
407 globalSelection( GEOM_ALLSHAPES );
410 SelectionIntoArgument();
413 //=================================================================================
414 // function : enableWidgets
415 // purpose : Enable widgets of faces in accordance with value of main object
416 //=================================================================================
417 void BlocksGUI_TrsfDlg::enableWidgets()
419 int anId = getConstructorId();
421 bool toEnable = !myShape->_is_nil();
424 mySelName[Face1]->setEnabled(toEnable);
425 mySelName[Face2]->setEnabled(toEnable);
426 mySelBtn[Face1]->setEnabled(toEnable);
427 mySelBtn[Face2]->setEnabled(toEnable);
430 mySelName[Face1]->setText("");
431 mySelName[Face2]->setText("");
435 } else if (anId == 1) {
436 mySelName[Face1U]->setEnabled(toEnable);
437 mySelName[Face2U]->setEnabled(toEnable);
438 mySelName[Face1V]->setEnabled(toEnable);
439 mySelName[Face2V]->setEnabled(toEnable);
440 mySelBtn[Face1U]->setEnabled(toEnable);
441 mySelBtn[Face2U]->setEnabled(toEnable);
442 mySelBtn[Face1V]->setEnabled(toEnable);
443 mySelBtn[Face2V]->setEnabled(toEnable);
446 mySelName[Face1U]->setText("");
447 mySelName[Face2U]->setText("");
448 mySelName[Face1V]->setText("");
449 mySelName[Face2V]->setText("");
450 myFaces[Face1U] = -1;
451 myFaces[Face2U] = -1;
452 myFaces[Face1V] = -1;
453 myFaces[Face2V] = -1;
458 //=================================================================================
459 // function : createOperation
461 //=================================================================================
462 GEOM::GEOM_IOperations_ptr BlocksGUI_TrsfDlg::createOperation()
464 return getGeomEngine()->GetIBlocksOperations(getStudyId());
467 //=================================================================================
468 // function : ClickOnApply()
469 // purpose : Verify validity of input data
470 //=================================================================================
471 bool BlocksGUI_TrsfDlg::isValid (QString&)
473 switch (getConstructorId()) {
475 return !myShape->_is_nil() && myFaces[Face1] > 0;
477 return !myShape->_is_nil() && myFaces[Face1U] > 0 && myFaces[Face1V] > 0;
484 //=================================================================================
485 // function : execute
487 //=================================================================================
488 bool BlocksGUI_TrsfDlg::execute (ObjectList& objects)
492 GEOM::GEOM_Object_var anObj;
494 switch (getConstructorId()) {
496 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->MakeMultiTransformation1D
500 (int)mySpinBox[SpinBox1]->GetValue());
504 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->MakeMultiTransformation2D
508 (int)mySpinBox[SpinBox2U]->GetValue(),
511 (int)mySpinBox[SpinBox2V]->GetValue());
516 if (!anObj->_is_nil())
517 objects.push_back(anObj._retn());