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.com
21 // File : BlocksGUI_TrsfDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
25 #include "BlocksGUI_TrsfDlg.h"
28 #include <GeometryGUI.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_ViewWindow.h>
35 #include <SUIT_ViewManager.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <OCCViewer_ViewModel.h>
41 #include <TColStd_IndexedMapOfInteger.hxx>
43 //=================================================================================
44 // class : BlocksGUI_TrsfDlg()
45 // purpose : Constructs a BlocksGUI_TrsfDlg which is a child of 'parent'.
46 //=================================================================================
47 BlocksGUI_TrsfDlg::BlocksGUI_TrsfDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
48 : GEOMBase_Skeleton(theGeometryGUI, parent),
51 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
52 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_MULTITRSF_SIMPLE")));
53 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_MULTITRSF_DOUBLE")));
54 QPixmap imageS (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
56 setWindowTitle(tr("GEOM_BLOCK_MULTITRSF_TITLE"));
58 /***************************************************************/
59 mainFrame()->GroupConstructors->setTitle(tr("GEOM_BLOCK_MULTITRSF"));
61 mainFrame()->RadioButton1->setIcon(image1);
62 mainFrame()->RadioButton2->setIcon(image2);
63 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
64 mainFrame()->RadioButton3->close();
67 myGrp1 = new QGroupBox(tr("GEOM_BLOCK_MULTITRSF_SIMPLE"), centralWidget());
69 createSelWg(tr("GEOM_MAIN_OBJECT"), imageS, myGrp1, MainObj1);
70 createSelWg(tr("FACE_1"), imageS, myGrp1, Face1);
71 createSelWg(tr("FACE_2"), imageS, myGrp1, Face2);
72 createSpinWg(tr("GEOM_NB_TIMES"), myGrp1, SpinBox1);
74 // Create second group
75 myGrp2 = new QGroupBox(tr("GEOM_BLOCK_MULTITRSF_DOUBLE"), centralWidget());
77 createSelWg(tr("GEOM_MAIN_OBJECT"), imageS, myGrp2, MainObj2);
78 createSelWg(tr("FACE_1U"), imageS, myGrp2, Face1U);
79 createSelWg(tr("FACE_2U"), imageS, myGrp2, Face2U);
80 createSpinWg(tr("GEOM_NB_TIMES_U"), myGrp2, SpinBox2U);
81 createSelWg(tr("FACE_1V"), imageS, myGrp2, Face1V);
82 createSelWg(tr("FACE_2V"), imageS, myGrp2, Face2V);
83 createSpinWg(tr("GEOM_NB_TIMES_V"), myGrp2, SpinBox2V);
85 // Add groups to layout
86 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
87 layout->setMargin(0); layout->setSpacing(6);
88 layout->addWidget(myGrp1);
89 layout->addWidget(myGrp2);
90 /***************************************************************/
92 setHelpFileName("multi_transformation_operation_page.html");
97 //=================================================================================
98 // function : ~BlocksGUI_TrsfDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 BlocksGUI_TrsfDlg::~BlocksGUI_TrsfDlg()
103 // no need to delete child widgets, Qt does it all for us
106 //=================================================================================
109 //=================================================================================
110 void BlocksGUI_TrsfDlg::Init()
112 // Set range of spinboxes
113 double SpecificStep = 1.0;
114 QMap<int, QDoubleSpinBox*>::iterator anIter;
115 for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter) {
116 //anIter.data()->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
117 initSpinBox(anIter.value(), 1.0, MAX_NUMBER, SpecificStep, 3);
120 // signals and slots connections
121 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
126 QMap<int, QPushButton*>::iterator anIterBtn;
127 for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
128 connect(anIterBtn.value(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 QMap<int, QDoubleSpinBox*>::iterator anIterSpin;
131 for (anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin)
132 connect(anIterSpin.value(), SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
134 // init controls and fields
135 initName(tr("GEOM_BLOCK_MULTITRSF"));
137 myConstructorId = -1;
138 ConstructorsClicked(0);
141 //=================================================================================
142 // function : ConstructorsClicked()
143 // purpose : Radio button management
144 //=================================================================================
145 void BlocksGUI_TrsfDlg::ConstructorsClicked (int constructorId)
147 if (myConstructorId == constructorId)
150 myConstructorId = constructorId;
153 myShape = GEOM::GEOM_Object::_nil();
154 myFaces[Face1] = myFaces[Face2] = -1;
155 myFaces[Face1U] = myFaces[Face2U] = -1;
156 myFaces[Face1V] = myFaces[Face2V] = -1;
159 QMap<int, QLineEdit*>::iterator anIterLE;
160 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
161 anIterLE.value()->setText("");
163 switch (constructorId) {
167 mySpinBox[SpinBox1]->setValue(2.0);
168 mySelBtn[MainObj1]->click();
173 mySpinBox[SpinBox2U]->setValue(2.0);
174 mySpinBox[SpinBox2V]->setValue(2.0);
175 mySelBtn[MainObj2]->click();
181 qApp->processEvents();
183 resize(minimumSize());
185 // on dialog initialization we init the first field with a selected object (if any)
186 SelectionIntoArgument();
189 //=================================================================================
190 // function : ClickOnOk()
192 //=================================================================================
193 void BlocksGUI_TrsfDlg::ClickOnOk()
199 //=================================================================================
200 // function : ClickOnApply()
202 //=================================================================================
203 bool BlocksGUI_TrsfDlg::ClickOnApply()
212 //=================================================================================
213 // function : SelectionIntoArgument()
214 // purpose : Called when selection is changed or on dialog initialization or activation
215 //=================================================================================
216 void BlocksGUI_TrsfDlg::SelectionIntoArgument()
219 myEditCurrentArgument->setText("");
221 // Get index of current selection focus
223 QMap<int, QLineEdit*>::iterator anIter;
224 for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
225 if (myEditCurrentArgument == anIter.value()) {
226 aCurrFocus = anIter.key();
231 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
232 SALOME_ListIO aSelList;
233 aSelMgr->selectedObjects(aSelList);
236 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_nil();
238 if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2)
240 // If selection of main object is activated
241 if (aSelList.Extent() == 1) {
242 Standard_Boolean aResult = Standard_False;
243 anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
245 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
246 aName = GEOMBase::GetName(anObj);
249 myEditCurrentArgument->setText(aName);
253 else if (aCurrFocus == Face1 || aCurrFocus == Face2 ||
254 aCurrFocus == Face1U || aCurrFocus == Face2U ||
255 aCurrFocus == Face1V || aCurrFocus == Face2V) {
256 // If face selection is activated
258 if (aSelList.Extent() == 1) {
259 Standard_Boolean aResult = Standard_False;
260 anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
261 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
262 aName = GEOMBase::GetName(anObj);
263 TColStd_IndexedMapOfInteger anIndexes;
264 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
266 if (anIndexes.Extent() == 1) {
267 anIndex = anIndexes(1);
268 aName += QString(":face_%1").arg(anIndex);
272 myEditCurrentArgument->setText(aName);
273 myFaces[aCurrFocus] = anIndex;
277 switch (aCurrFocus) {
280 if (!myShape->_is_nil() && myFaces[Face1] == -1)
281 mySelBtn[Face1]->click();
284 if (myFaces[Face1] != -1 && myFaces[Face2] == -1)
285 mySelBtn[Face2]->click();
288 if (myFaces[Face2] != -1 && myShape->_is_nil())
289 mySelBtn[MainObj1]->click();
294 if (!myShape->_is_nil() && myFaces[Face1U] == -1)
295 mySelBtn[Face1U]->click();
298 if (myFaces[Face1U] != -1 && myFaces[Face2U] == -1)
299 mySelBtn[Face2U]->click();
302 if (myFaces[Face2U] != -1 && myFaces[Face1V] == -1)
303 mySelBtn[Face1V]->click();
306 if (myFaces[Face1V] != -1 && myFaces[Face2V] == -1)
307 mySelBtn[Face2V]->click();
310 if (myFaces[Face2V] != -1 && myShape->_is_nil())
311 mySelBtn[MainObj1]->click();
319 //=================================================================================
320 // function : SetEditCurrentArgument()
322 //=================================================================================
323 void BlocksGUI_TrsfDlg::SetEditCurrentArgument()
325 QPushButton* aSender = (QPushButton*)sender();
328 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
332 myGeomGUI->getApp()->selectionMgr()->clearSelected();
335 switch (myConstructorId) {
337 mySelBtn[MainObj1]->setDown(false);
338 mySelBtn[Face1]->setDown(false);
339 mySelBtn[Face2]->setDown(false);
341 mySelName[MainObj1]->setEnabled(false);
342 mySelName[Face1]->setEnabled(false);
343 mySelName[Face2]->setEnabled(false);
346 mySelBtn[MainObj2]->setDown(false);
347 mySelBtn[Face1U]->setDown(false);
348 mySelBtn[Face2U]->setDown(false);
349 mySelBtn[Face1V]->setDown(false);
350 mySelBtn[Face2V]->setDown(false);
352 mySelName[MainObj2]->setEnabled(false);
353 mySelName[Face1U]->setEnabled(false);
354 mySelName[Face2U]->setEnabled(false);
355 mySelName[Face1V]->setEnabled(false);
356 mySelName[Face2V]->setEnabled(false);
362 // enable push button
363 aSender->setDown(true);
365 // set line edit as current argument
366 QMap<int, QPushButton*>::iterator anIter;
367 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
368 if (anIter.value() == aSender) {
369 myEditCurrentArgument = mySelName[anIter.key()];
375 myEditCurrentArgument->setEnabled(true);
376 myEditCurrentArgument->setFocus();
381 //=================================================================================
382 // function : ActivateThisDialog()
384 //=================================================================================
385 void BlocksGUI_TrsfDlg::ActivateThisDialog()
387 GEOMBase_Skeleton::ActivateThisDialog();
394 //=================================================================================
395 // function : enterEvent()
397 //=================================================================================
398 void BlocksGUI_TrsfDlg::enterEvent (QEvent*)
400 if (!mainFrame()->GroupConstructors->isEnabled())
401 ActivateThisDialog();
404 //=================================================================================
405 // function : ValueChangedInSpinBox()
407 //=================================================================================
408 void BlocksGUI_TrsfDlg::ValueChangedInSpinBox(double)
413 //=================================================================================
414 // function : createSelWg()
416 //=================================================================================
417 void BlocksGUI_TrsfDlg::createSelWg (const QString& theLbl,
422 QLabel* lab = new QLabel(theLbl, theParent);
423 mySelBtn[theId] = new QPushButton(theParent);
424 mySelBtn[theId]->setIcon(thePix);
425 mySelBtn[theId]->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
426 mySelName[theId] = new QLineEdit(theParent);
427 mySelName[theId]->setReadOnly(true);
429 if (!theParent->layout()) {
430 l = new QGridLayout(theParent);
431 l->setMargin(9); l->setSpacing(6);
434 l = qobject_cast<QGridLayout*>(theParent->layout());
436 int row = l->rowCount();
437 l->addWidget(lab, row, 0);
438 l->addWidget(mySelBtn[theId], row, 1);
439 l->addWidget(mySelName[theId], row, 2);
442 //=================================================================================
443 // function : createSpinWg()
445 //=================================================================================
446 void BlocksGUI_TrsfDlg::createSpinWg (const QString& theLbl,
450 QLabel* lab = new QLabel(theLbl, theParent);
451 mySpinBox[theId] = new QDoubleSpinBox(theParent);
453 if (!theParent->layout()) {
454 l = new QGridLayout(theParent);
455 l->setMargin(9); l->setSpacing(6);
458 l = qobject_cast<QGridLayout*>(theParent->layout());
460 int row = l->rowCount();
461 l->addWidget(lab, row, 0);
462 l->addWidget(mySpinBox[theId], row, 2);
465 //=================================================================================
466 // function : activateSelection
467 // purpose : Activate selection in accordance with myEditCurrentArgument
468 //=================================================================================
469 void BlocksGUI_TrsfDlg::activateSelection()
471 globalSelection(GEOM_ALLSHAPES);
472 if (!myShape->_is_nil() &&
473 (myEditCurrentArgument == mySelName[Face1 ] ||
474 myEditCurrentArgument == mySelName[Face2 ] ||
475 myEditCurrentArgument == mySelName[Face1U] ||
476 myEditCurrentArgument == mySelName[Face2U] ||
477 myEditCurrentArgument == mySelName[Face1V] ||
478 myEditCurrentArgument == mySelName[Face2V]))
480 // Local selection is available only in the OCC Viewer
481 if (getDesktop()->activeWindow()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
482 localSelection(myShape, TopAbs_FACE);
485 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
486 this, SLOT(SelectionIntoArgument()));
489 //=================================================================================
490 // function : enableWidgets
491 // purpose : Enable widgets of faces in accordance with value of main object
492 //=================================================================================
493 void BlocksGUI_TrsfDlg::enableWidgets()
495 int anId = getConstructorId();
497 bool toEnable = !myShape->_is_nil();
500 //mySelName[Face1]->setEnabled(toEnable);
501 //mySelName[Face2]->setEnabled(toEnable);
502 //mySelBtn[Face1]->setEnabled(toEnable);
503 //mySelBtn[Face2]->setEnabled(toEnable);
506 mySelName[Face1]->setText("");
507 mySelName[Face2]->setText("");
512 else if (anId == 1) {
513 //mySelName[Face1U]->setEnabled(toEnable);
514 //mySelName[Face2U]->setEnabled(toEnable);
515 //mySelName[Face1V]->setEnabled(toEnable);
516 //mySelName[Face2V]->setEnabled(toEnable);
517 //mySelBtn[Face1U]->setEnabled(toEnable);
518 //mySelBtn[Face2U]->setEnabled(toEnable);
519 //mySelBtn[Face1V]->setEnabled(toEnable);
520 //mySelBtn[Face2V]->setEnabled(toEnable);
523 mySelName[Face1U]->setText("");
524 mySelName[Face2U]->setText("");
525 mySelName[Face1V]->setText("");
526 mySelName[Face2V]->setText("");
527 myFaces[Face1U] = -1;
528 myFaces[Face2U] = -1;
529 myFaces[Face1V] = -1;
530 myFaces[Face2V] = -1;
535 //=================================================================================
536 // function : createOperation
538 //=================================================================================
539 GEOM::GEOM_IOperations_ptr BlocksGUI_TrsfDlg::createOperation()
541 return getGeomEngine()->GetIBlocksOperations(getStudyId());
544 //=================================================================================
545 // function : isValid
546 // purpose : Verify validity of input data
547 //=================================================================================
548 bool BlocksGUI_TrsfDlg::isValid (QString&)
551 switch (getConstructorId()) {
553 ok = !myShape->_is_nil() && myFaces[Face1] > 0;
556 ok = !myShape->_is_nil() && myFaces[Face1U] > 0 && myFaces[Face1V] > 0;
564 //=================================================================================
565 // function : execute
567 //=================================================================================
568 bool BlocksGUI_TrsfDlg::execute (ObjectList& objects)
572 GEOM::GEOM_Object_var anObj;
574 switch (getConstructorId()) {
576 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
577 MakeMultiTransformation1D(myShape,
578 myFaces[Face1], myFaces[Face2],
579 (int)mySpinBox[SpinBox1]->value());
583 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
584 MakeMultiTransformation2D (myShape,
585 myFaces[Face1U], myFaces[Face2U],
586 (int)mySpinBox[SpinBox2U]->value(),
587 myFaces[Face1V], myFaces[Face2V],
588 (int)mySpinBox[SpinBox2V]->value());
595 if (!anObj->_is_nil())
596 objects.push_back(anObj._retn());