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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BlocksGUI_TrsfDlg.cxx
24 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
26 #include "BlocksGUI_TrsfDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewManager.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39 #include <OCCViewer_ViewModel.h>
42 #include <TColStd_IndexedMapOfInteger.hxx>
44 //=================================================================================
45 // class : BlocksGUI_TrsfDlg()
46 // purpose : Constructs a BlocksGUI_TrsfDlg which is a child of 'parent'.
47 //=================================================================================
48 BlocksGUI_TrsfDlg::BlocksGUI_TrsfDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
49 : GEOMBase_Skeleton(theGeometryGUI, parent),
52 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
53 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_MULTITRSF_SIMPLE")));
54 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_MULTITRSF_DOUBLE")));
55 QPixmap imageS (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
57 setWindowTitle(tr("GEOM_BLOCK_MULTITRSF_TITLE"));
59 /***************************************************************/
60 mainFrame()->GroupConstructors->setTitle(tr("GEOM_BLOCK_MULTITRSF"));
62 mainFrame()->RadioButton1->setIcon(image1);
63 mainFrame()->RadioButton2->setIcon(image2);
64 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
65 mainFrame()->RadioButton3->close();
68 myGrp1 = new QGroupBox(tr("GEOM_BLOCK_MULTITRSF_SIMPLE"), centralWidget());
70 createSelWg(tr("GEOM_MAIN_OBJECT"), imageS, myGrp1, MainObj1);
71 createSelWg(tr("FACE_1"), imageS, myGrp1, Face1);
72 createSelWg(tr("FACE_2"), imageS, myGrp1, Face2);
73 createSpinWg(tr("GEOM_NB_TIMES"), myGrp1, SpinBox1);
75 // Create second group
76 myGrp2 = new QGroupBox(tr("GEOM_BLOCK_MULTITRSF_DOUBLE"), centralWidget());
78 createSelWg(tr("GEOM_MAIN_OBJECT"), imageS, myGrp2, MainObj2);
79 createSelWg(tr("FACE_1U"), imageS, myGrp2, Face1U);
80 createSelWg(tr("FACE_2U"), imageS, myGrp2, Face2U);
81 createSpinWg(tr("GEOM_NB_TIMES_U"), myGrp2, SpinBox2U);
82 createSelWg(tr("FACE_1V"), imageS, myGrp2, Face1V);
83 createSelWg(tr("FACE_2V"), imageS, myGrp2, Face2V);
84 createSpinWg(tr("GEOM_NB_TIMES_V"), myGrp2, SpinBox2V);
86 // Add groups to layout
87 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
88 layout->setMargin(0); layout->setSpacing(6);
89 layout->addWidget(myGrp1);
90 layout->addWidget(myGrp2);
91 /***************************************************************/
93 setHelpFileName("multi_transformation_operation_page.html");
98 //=================================================================================
99 // function : ~BlocksGUI_TrsfDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 BlocksGUI_TrsfDlg::~BlocksGUI_TrsfDlg()
104 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void BlocksGUI_TrsfDlg::Init()
113 // Set range of spinboxes
114 int SpecificStep = 1;
115 QMap<int, SalomeApp_IntSpinBox*>::iterator anIter;
116 for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter) {
117 initSpinBox(anIter.value(), 1, 999, SpecificStep);
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, SalomeApp_IntSpinBox*>::iterator anIterSpin;
131 for (anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin)
132 connect(anIterSpin.value(), SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
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);
168 mySelBtn[MainObj1]->click();
173 mySpinBox[SpinBox2U]->setValue(2);
174 mySpinBox[SpinBox2V]->setValue(2);
175 mySelBtn[MainObj2]->click();
181 qApp->processEvents();
183 resize(minimumSizeHint());
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 // set line edit as current argument
363 QMap<int, QPushButton*>::iterator anIter;
364 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
365 if (anIter.value() == aSender) {
366 myEditCurrentArgument = mySelName[anIter.key()];
372 myEditCurrentArgument->setEnabled(true);
373 myEditCurrentArgument->setFocus();
375 // enable push button
376 // after setFocus(), because it will be setDown(false) when loses focus
377 aSender->setDown(true);
382 //=================================================================================
383 // function : ActivateThisDialog()
385 //=================================================================================
386 void BlocksGUI_TrsfDlg::ActivateThisDialog()
388 GEOMBase_Skeleton::ActivateThisDialog();
395 //=================================================================================
396 // function : enterEvent()
398 //=================================================================================
399 void BlocksGUI_TrsfDlg::enterEvent (QEvent*)
401 if (!mainFrame()->GroupConstructors->isEnabled())
402 ActivateThisDialog();
405 //=================================================================================
406 // function : ValueChangedInSpinBox()
408 //=================================================================================
409 void BlocksGUI_TrsfDlg::ValueChangedInSpinBox(int)
414 //=================================================================================
415 // function : createSelWg()
417 //=================================================================================
418 void BlocksGUI_TrsfDlg::createSelWg (const QString& theLbl,
423 QLabel* lab = new QLabel(theLbl, theParent);
424 mySelBtn[theId] = new QPushButton(theParent);
425 mySelBtn[theId]->setIcon(thePix);
426 mySelBtn[theId]->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
427 mySelName[theId] = new QLineEdit(theParent);
428 mySelName[theId]->setReadOnly(true);
430 if (!theParent->layout()) {
431 l = new QGridLayout(theParent);
432 l->setMargin(9); l->setSpacing(6);
435 l = qobject_cast<QGridLayout*>(theParent->layout());
437 int row = l->rowCount();
438 l->addWidget(lab, row, 0);
439 l->addWidget(mySelBtn[theId], row, 1);
440 l->addWidget(mySelName[theId], row, 2);
443 //=================================================================================
444 // function : createSpinWg()
446 //=================================================================================
447 void BlocksGUI_TrsfDlg::createSpinWg (const QString& theLbl,
451 QLabel* lab = new QLabel(theLbl, theParent);
452 mySpinBox[theId] = new SalomeApp_IntSpinBox(theParent);
454 if (!theParent->layout()) {
455 l = new QGridLayout(theParent);
456 l->setMargin(9); l->setSpacing(6);
459 l = qobject_cast<QGridLayout*>(theParent->layout());
461 int row = l->rowCount();
462 l->addWidget(lab, row, 0);
463 l->addWidget(mySpinBox[theId], row, 2);
466 //=================================================================================
467 // function : activateSelection
468 // purpose : Activate selection in accordance with myEditCurrentArgument
469 //=================================================================================
470 void BlocksGUI_TrsfDlg::activateSelection()
472 globalSelection(GEOM_ALLSHAPES);
473 if (!myShape->_is_nil() &&
474 (myEditCurrentArgument == mySelName[Face1 ] ||
475 myEditCurrentArgument == mySelName[Face2 ] ||
476 myEditCurrentArgument == mySelName[Face1U] ||
477 myEditCurrentArgument == mySelName[Face2U] ||
478 myEditCurrentArgument == mySelName[Face1V] ||
479 myEditCurrentArgument == mySelName[Face2V]))
481 // Local selection is available only in the OCC Viewer
482 if (getDesktop()->activeWindow()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
483 localSelection(myShape, TopAbs_FACE);
486 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
487 this, SLOT(SelectionIntoArgument()));
490 //=================================================================================
491 // function : enableWidgets
492 // purpose : Enable widgets of faces in accordance with value of main object
493 //=================================================================================
494 void BlocksGUI_TrsfDlg::enableWidgets()
496 int anId = getConstructorId();
498 bool toEnable = !myShape->_is_nil();
501 //mySelName[Face1]->setEnabled(toEnable);
502 //mySelName[Face2]->setEnabled(toEnable);
503 //mySelBtn[Face1]->setEnabled(toEnable);
504 //mySelBtn[Face2]->setEnabled(toEnable);
507 mySelName[Face1]->setText("");
508 mySelName[Face2]->setText("");
513 else if (anId == 1) {
514 //mySelName[Face1U]->setEnabled(toEnable);
515 //mySelName[Face2U]->setEnabled(toEnable);
516 //mySelName[Face1V]->setEnabled(toEnable);
517 //mySelName[Face2V]->setEnabled(toEnable);
518 //mySelBtn[Face1U]->setEnabled(toEnable);
519 //mySelBtn[Face2U]->setEnabled(toEnable);
520 //mySelBtn[Face1V]->setEnabled(toEnable);
521 //mySelBtn[Face2V]->setEnabled(toEnable);
524 mySelName[Face1U]->setText("");
525 mySelName[Face2U]->setText("");
526 mySelName[Face1V]->setText("");
527 mySelName[Face2V]->setText("");
528 myFaces[Face1U] = -1;
529 myFaces[Face2U] = -1;
530 myFaces[Face1V] = -1;
531 myFaces[Face2V] = -1;
536 //=================================================================================
537 // function : createOperation
539 //=================================================================================
540 GEOM::GEOM_IOperations_ptr BlocksGUI_TrsfDlg::createOperation()
542 return getGeomEngine()->GetIBlocksOperations(getStudyId());
545 //=================================================================================
546 // function : isValid
547 // purpose : Verify validity of input data
548 //=================================================================================
549 bool BlocksGUI_TrsfDlg::isValid (QString& msg)
551 bool ok = false, okSP = true;
552 switch (getConstructorId()) {
554 ok = !myShape->_is_nil() && myFaces[Face1] > 0;
555 okSP = mySpinBox[SpinBox1]->isValid( msg, !IsPreview() );
558 ok = !myShape->_is_nil() && myFaces[Face1U] > 0 && myFaces[Face1V] > 0;
559 okSP = mySpinBox[SpinBox2U]->isValid( msg, !IsPreview() ) && okSP;
560 okSP = mySpinBox[SpinBox2V]->isValid( msg, !IsPreview() ) && okSP;
568 //=================================================================================
569 // function : execute
571 //=================================================================================
572 bool BlocksGUI_TrsfDlg::execute (ObjectList& objects)
576 GEOM::GEOM_Object_var anObj;
578 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
580 switch (getConstructorId()) {
582 anObj = anOper->MakeMultiTransformation1D(myShape,
583 myFaces[Face1], myFaces[Face2],
584 mySpinBox[SpinBox1]->value());
585 if (!anObj->_is_nil() && !IsPreview())
587 QStringList aParameters;
588 aParameters << "" << "";
589 aParameters << mySpinBox[SpinBox1]->text();
590 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
595 anObj = anOper->MakeMultiTransformation2D (myShape,
596 myFaces[Face1U], myFaces[Face2U],
597 mySpinBox[SpinBox2U]->value(),
598 myFaces[Face1V], myFaces[Face2V],
599 mySpinBox[SpinBox2V]->value());
600 if (!anObj->_is_nil() && !IsPreview())
602 QStringList aParameters;
603 aParameters << "" << "";
604 aParameters << mySpinBox[SpinBox2U]->text();
605 aParameters << "" << "";
606 aParameters << mySpinBox[SpinBox2V]->text();
607 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
615 if (!anObj->_is_nil())
616 objects.push_back(anObj._retn());