1 // Copyright (C) 2007-2021 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 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BlocksGUI_TrsfDlg.cxx
25 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
27 #include "BlocksGUI_TrsfDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_ViewWindow.h>
37 #include <SUIT_ViewManager.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
40 #include <OCCViewer_ViewModel.h>
43 #include <TColStd_IndexedMapOfInteger.hxx>
45 //=================================================================================
46 // class : BlocksGUI_TrsfDlg()
47 // purpose : Constructs a BlocksGUI_TrsfDlg which is a child of 'parent'.
48 //=================================================================================
49 BlocksGUI_TrsfDlg::BlocksGUI_TrsfDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
50 : GEOMBase_Skeleton(theGeometryGUI, parent),
53 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
54 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_MULTITRSF_SIMPLE")));
55 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_MULTITRSF_DOUBLE")));
56 QPixmap imageS (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
58 setWindowTitle(tr("GEOM_BLOCK_MULTITRSF_TITLE"));
60 /***************************************************************/
61 mainFrame()->GroupConstructors->setTitle(tr("GEOM_BLOCK_MULTITRSF"));
63 mainFrame()->RadioButton1->setIcon(image1);
64 mainFrame()->RadioButton2->setIcon(image2);
65 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
66 mainFrame()->RadioButton3->close();
69 myGrp1 = new QGroupBox(tr("GEOM_BLOCK_MULTITRSF_SIMPLE"), centralWidget());
71 createSelWg(tr("GEOM_MAIN_OBJECT"), imageS, myGrp1, MainObj1);
72 createSelWg(tr("FACE_1"), imageS, myGrp1, Face1);
73 createSelWg(tr("FACE_2"), imageS, myGrp1, Face2);
74 createSpinWg(tr("GEOM_NB_TIMES"), myGrp1, SpinBox1);
76 // Create second group
77 myGrp2 = new QGroupBox(tr("GEOM_BLOCK_MULTITRSF_DOUBLE"), centralWidget());
79 createSelWg(tr("GEOM_MAIN_OBJECT"), imageS, myGrp2, MainObj2);
80 createSelWg(tr("FACE_1U"), imageS, myGrp2, Face1U);
81 createSelWg(tr("FACE_2U"), imageS, myGrp2, Face2U);
82 createSpinWg(tr("GEOM_NB_TIMES_U"), myGrp2, SpinBox2U);
83 createSelWg(tr("FACE_1V"), imageS, myGrp2, Face1V);
84 createSelWg(tr("FACE_2V"), imageS, myGrp2, Face2V);
85 createSpinWg(tr("GEOM_NB_TIMES_V"), myGrp2, SpinBox2V);
87 // Add groups to layout
88 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
89 layout->setMargin(0); layout->setSpacing(6);
90 layout->addWidget(myGrp1);
91 layout->addWidget(myGrp2);
92 /***************************************************************/
94 setHelpFileName("multi_transformation_operation_page.html");
99 //=================================================================================
100 // function : ~BlocksGUI_TrsfDlg()
101 // purpose : Destroys the object and frees any allocated resources
102 //=================================================================================
103 BlocksGUI_TrsfDlg::~BlocksGUI_TrsfDlg()
105 // no need to delete child widgets, Qt does it all for us
108 //=================================================================================
111 //=================================================================================
112 void BlocksGUI_TrsfDlg::Init()
114 // Set range of spinboxes
115 int SpecificStep = 1;
116 QMap<int, SalomeApp_IntSpinBox*>::iterator anIter;
117 for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter) {
118 initSpinBox(anIter.value(), 1, 999, SpecificStep);
121 showOnlyPreviewControl();
123 // signals and slots connections
124 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
127 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
129 QMap<int, QPushButton*>::iterator anIterBtn;
130 for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
131 connect(anIterBtn.value(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 QMap<int, SalomeApp_IntSpinBox*>::iterator anIterSpin;
134 for (anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin)
135 connect(anIterSpin.value(), SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
137 // init controls and fields
138 initName(tr("GEOM_BLOCK_MULTITRSF"));
140 myConstructorId = -1;
141 ConstructorsClicked(0);
144 //=================================================================================
145 // function : ConstructorsClicked()
146 // purpose : Radio button management
147 //=================================================================================
148 void BlocksGUI_TrsfDlg::ConstructorsClicked (int constructorId)
150 if (myConstructorId == constructorId)
153 myConstructorId = constructorId;
156 myShape = GEOM::GEOM_Object::_nil();
157 myFaces[Face1] = myFaces[Face2] = -1;
158 myFaces[Face1U] = myFaces[Face2U] = -1;
159 myFaces[Face1V] = myFaces[Face2V] = -1;
162 QMap<int, QLineEdit*>::iterator anIterLE;
163 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
164 anIterLE.value()->setText("");
166 switch (constructorId) {
170 mySpinBox[SpinBox1]->setValue(2);
171 mySelBtn[MainObj1]->click();
176 mySpinBox[SpinBox2U]->setValue(2);
177 mySpinBox[SpinBox2V]->setValue(2);
178 mySelBtn[MainObj2]->click();
184 qApp->processEvents();
186 resize(minimumSizeHint());
188 // on dialog initialization we init the first field with a selected object (if any)
189 SelectionIntoArgument();
192 //=================================================================================
193 // function : ClickOnOk()
195 //=================================================================================
196 void BlocksGUI_TrsfDlg::ClickOnOk()
198 setIsApplyAndClose( true );
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 bool BlocksGUI_TrsfDlg::ClickOnApply()
216 //=================================================================================
217 // function : SelectionIntoArgument()
218 // purpose : Called when selection is changed or on dialog initialization or activation
219 //=================================================================================
220 void BlocksGUI_TrsfDlg::SelectionIntoArgument()
222 myEditCurrentArgument->setText("");
224 // Get index of current selection focus
226 QMap<int, QLineEdit*>::iterator anIter;
227 for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
228 if (myEditCurrentArgument == anIter.value()) {
229 aCurrFocus = anIter.key();
234 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
235 SALOME_ListIO aSelList;
236 aSelMgr->selectedObjects(aSelList);
239 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_nil();
241 if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2)
243 // If selection of main object is activated
244 if (aSelList.Extent() == 1) {
245 anObj = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
247 if ( GEOMBase::IsShape(anObj) ) {
248 aName = GEOMBase::GetName(anObj);
251 myEditCurrentArgument->setText(aName);
255 else if (aCurrFocus == Face1 || aCurrFocus == Face2 ||
256 aCurrFocus == Face1U || aCurrFocus == Face2U ||
257 aCurrFocus == Face1V || aCurrFocus == Face2V) {
258 // If face selection is activated
260 if (aSelList.Extent() == 1) {
261 anObj = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
262 if ( GEOMBase::IsShape(anObj) ) {
263 aName = GEOMBase::GetName(anObj);
264 TColStd_IndexedMapOfInteger anIndexes;
265 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
267 if (anIndexes.Extent() == 1) {
268 anIndex = anIndexes(1);
269 aName += QString(":face_%1").arg(anIndex);
273 myEditCurrentArgument->setText(aName);
274 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();
321 //=================================================================================
322 // function : SetEditCurrentArgument()
324 //=================================================================================
325 void BlocksGUI_TrsfDlg::SetEditCurrentArgument()
327 QPushButton* aSender = (QPushButton*)sender();
330 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
334 myGeomGUI->getApp()->selectionMgr()->clearSelected();
337 switch (myConstructorId) {
339 mySelBtn[MainObj1]->setDown(false);
340 mySelBtn[Face1]->setDown(false);
341 mySelBtn[Face2]->setDown(false);
343 mySelName[MainObj1]->setEnabled(false);
344 mySelName[Face1]->setEnabled(false);
345 mySelName[Face2]->setEnabled(false);
348 mySelBtn[MainObj2]->setDown(false);
349 mySelBtn[Face1U]->setDown(false);
350 mySelBtn[Face2U]->setDown(false);
351 mySelBtn[Face1V]->setDown(false);
352 mySelBtn[Face2V]->setDown(false);
354 mySelName[MainObj2]->setEnabled(false);
355 mySelName[Face1U]->setEnabled(false);
356 mySelName[Face2U]->setEnabled(false);
357 mySelName[Face1V]->setEnabled(false);
358 mySelName[Face2V]->setEnabled(false);
364 // set line edit as current argument
365 QMap<int, QPushButton*>::iterator anIter;
366 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
367 if (anIter.value() == aSender) {
368 myEditCurrentArgument = mySelName[anIter.key()];
374 myEditCurrentArgument->setEnabled(true);
375 myEditCurrentArgument->setFocus();
377 // enable push button
378 // after setFocus(), because it will be setDown(false) when loses focus
379 aSender->setDown(true);
386 //=================================================================================
387 // function : ActivateThisDialog()
389 //=================================================================================
390 void BlocksGUI_TrsfDlg::ActivateThisDialog()
392 GEOMBase_Skeleton::ActivateThisDialog();
399 //=================================================================================
400 // function : enterEvent()
402 //=================================================================================
403 void BlocksGUI_TrsfDlg::enterEvent (QEvent*)
405 if (!mainFrame()->GroupConstructors->isEnabled())
406 ActivateThisDialog();
409 //=================================================================================
410 // function : ValueChangedInSpinBox()
412 //=================================================================================
413 void BlocksGUI_TrsfDlg::ValueChangedInSpinBox(int)
418 //=================================================================================
419 // function : createSelWg()
421 //=================================================================================
422 void BlocksGUI_TrsfDlg::createSelWg (const QString& theLbl,
427 QLabel* lab = new QLabel(theLbl, theParent);
428 mySelBtn[theId] = new QPushButton(theParent);
429 mySelBtn[theId]->setIcon(thePix);
430 mySelBtn[theId]->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
431 mySelName[theId] = new QLineEdit(theParent);
432 mySelName[theId]->setReadOnly(true);
434 if (!theParent->layout()) {
435 l = new QGridLayout(theParent);
436 l->setMargin(9); l->setSpacing(6);
439 l = qobject_cast<QGridLayout*>(theParent->layout());
441 int row = l->rowCount();
442 l->addWidget(lab, row, 0);
443 l->addWidget(mySelBtn[theId], row, 1);
444 l->addWidget(mySelName[theId], row, 2);
447 //=================================================================================
448 // function : createSpinWg()
450 //=================================================================================
451 void BlocksGUI_TrsfDlg::createSpinWg (const QString& theLbl,
455 QLabel* lab = new QLabel(theLbl, theParent);
456 mySpinBox[theId] = new SalomeApp_IntSpinBox(theParent);
458 if (!theParent->layout()) {
459 l = new QGridLayout(theParent);
460 l->setMargin(9); l->setSpacing(6);
463 l = qobject_cast<QGridLayout*>(theParent->layout());
465 int row = l->rowCount();
466 l->addWidget(lab, row, 0);
467 l->addWidget(mySpinBox[theId], row, 2);
470 //=================================================================================
471 // function : activateSelection
472 // purpose : Activate selection in accordance with myEditCurrentArgument
473 //=================================================================================
474 void BlocksGUI_TrsfDlg::activateSelection()
476 globalSelection(GEOM_ALLSHAPES);
477 if (!myShape->_is_nil() &&
478 (myEditCurrentArgument == mySelName[Face1 ] ||
479 myEditCurrentArgument == mySelName[Face2 ] ||
480 myEditCurrentArgument == mySelName[Face1U] ||
481 myEditCurrentArgument == mySelName[Face2U] ||
482 myEditCurrentArgument == mySelName[Face1V] ||
483 myEditCurrentArgument == mySelName[Face2V]))
485 // Local selection is available only in the OCC Viewer
486 if (getDesktop()->activeWindow()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
487 localSelection(myShape, TopAbs_FACE);
490 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
491 this, SLOT(SelectionIntoArgument()));
494 //=================================================================================
495 // function : enableWidgets
496 // purpose : Enable widgets of faces in accordance with value of main object
497 //=================================================================================
498 void BlocksGUI_TrsfDlg::enableWidgets()
500 int anId = getConstructorId();
502 bool toEnable = !myShape->_is_nil();
505 //mySelName[Face1]->setEnabled(toEnable);
506 //mySelName[Face2]->setEnabled(toEnable);
507 //mySelBtn[Face1]->setEnabled(toEnable);
508 //mySelBtn[Face2]->setEnabled(toEnable);
511 mySelName[Face1]->setText("");
512 mySelName[Face2]->setText("");
517 else if (anId == 1) {
518 //mySelName[Face1U]->setEnabled(toEnable);
519 //mySelName[Face2U]->setEnabled(toEnable);
520 //mySelName[Face1V]->setEnabled(toEnable);
521 //mySelName[Face2V]->setEnabled(toEnable);
522 //mySelBtn[Face1U]->setEnabled(toEnable);
523 //mySelBtn[Face2U]->setEnabled(toEnable);
524 //mySelBtn[Face1V]->setEnabled(toEnable);
525 //mySelBtn[Face2V]->setEnabled(toEnable);
528 mySelName[Face1U]->setText("");
529 mySelName[Face2U]->setText("");
530 mySelName[Face1V]->setText("");
531 mySelName[Face2V]->setText("");
532 myFaces[Face1U] = -1;
533 myFaces[Face2U] = -1;
534 myFaces[Face1V] = -1;
535 myFaces[Face2V] = -1;
540 //=================================================================================
541 // function : createOperation
543 //=================================================================================
544 GEOM::GEOM_IOperations_ptr BlocksGUI_TrsfDlg::createOperation()
546 return getGeomEngine()->GetIBlocksOperations();
549 //=================================================================================
550 // function : isValid
551 // purpose : Verify validity of input data
552 //=================================================================================
553 bool BlocksGUI_TrsfDlg::isValid (QString& msg)
555 bool ok = false, okSP = true;
556 switch (getConstructorId()) {
558 ok = !myShape->_is_nil() && myFaces[Face1] > 0;
559 okSP = mySpinBox[SpinBox1]->isValid( msg, !IsPreview() );
562 ok = !myShape->_is_nil() && myFaces[Face1U] > 0 && myFaces[Face1V] > 0;
563 okSP = mySpinBox[SpinBox2U]->isValid( msg, !IsPreview() ) && okSP;
564 okSP = mySpinBox[SpinBox2V]->isValid( msg, !IsPreview() ) && okSP;
572 //=================================================================================
573 // function : execute
575 //=================================================================================
576 bool BlocksGUI_TrsfDlg::execute (ObjectList& objects)
580 GEOM::GEOM_Object_var anObj;
582 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
584 switch (getConstructorId()) {
586 anObj = anOper->MakeMultiTransformation1D(myShape,
587 myFaces[Face1], myFaces[Face2],
588 mySpinBox[SpinBox1]->value());
589 if (!anObj->_is_nil() && !IsPreview())
591 QStringList aParameters;
592 aParameters << "" << "";
593 aParameters << mySpinBox[SpinBox1]->text();
594 anObj->SetParameters(aParameters.join(":").toUtf8().constData());
599 anObj = anOper->MakeMultiTransformation2D (myShape,
600 myFaces[Face1U], myFaces[Face2U],
601 mySpinBox[SpinBox2U]->value(),
602 myFaces[Face1V], myFaces[Face2V],
603 mySpinBox[SpinBox2V]->value());
604 if (!anObj->_is_nil() && !IsPreview())
606 QStringList aParameters;
607 aParameters << "" << "";
608 aParameters << mySpinBox[SpinBox2U]->text();
609 aParameters << "" << "";
610 aParameters << mySpinBox[SpinBox2V]->text();
611 anObj->SetParameters(aParameters.join(":").toUtf8().constData());
619 if (!anObj->_is_nil())
620 objects.push_back(anObj._retn());
625 //=================================================================================
626 // function : getSourceObjects
627 // purpose : virtual method to get source objects
628 //=================================================================================
629 QList<GEOM::GeomObjPtr> BlocksGUI_TrsfDlg::getSourceObjects()
631 QList<GEOM::GeomObjPtr> res;
632 GEOM::GeomObjPtr aGeomObjPtr(myShape);