1 // Copyright (C) 2007-2010 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
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 // signals and slots connections
122 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
127 QMap<int, QPushButton*>::iterator anIterBtn;
128 for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
129 connect(anIterBtn.value(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 QMap<int, SalomeApp_IntSpinBox*>::iterator anIterSpin;
132 for (anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin)
133 connect(anIterSpin.value(), SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
135 // init controls and fields
136 initName(tr("GEOM_BLOCK_MULTITRSF"));
138 myConstructorId = -1;
139 ConstructorsClicked(0);
142 //=================================================================================
143 // function : ConstructorsClicked()
144 // purpose : Radio button management
145 //=================================================================================
146 void BlocksGUI_TrsfDlg::ConstructorsClicked (int constructorId)
148 if (myConstructorId == constructorId)
151 myConstructorId = constructorId;
154 myShape = GEOM::GEOM_Object::_nil();
155 myFaces[Face1] = myFaces[Face2] = -1;
156 myFaces[Face1U] = myFaces[Face2U] = -1;
157 myFaces[Face1V] = myFaces[Face2V] = -1;
160 QMap<int, QLineEdit*>::iterator anIterLE;
161 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
162 anIterLE.value()->setText("");
164 switch (constructorId) {
168 mySpinBox[SpinBox1]->setValue(2);
169 mySelBtn[MainObj1]->click();
174 mySpinBox[SpinBox2U]->setValue(2);
175 mySpinBox[SpinBox2V]->setValue(2);
176 mySelBtn[MainObj2]->click();
182 qApp->processEvents();
184 resize(minimumSizeHint());
186 // on dialog initialization we init the first field with a selected object (if any)
187 SelectionIntoArgument();
190 //=================================================================================
191 // function : ClickOnOk()
193 //=================================================================================
194 void BlocksGUI_TrsfDlg::ClickOnOk()
200 //=================================================================================
201 // function : ClickOnApply()
203 //=================================================================================
204 bool BlocksGUI_TrsfDlg::ClickOnApply()
213 //=================================================================================
214 // function : SelectionIntoArgument()
215 // purpose : Called when selection is changed or on dialog initialization or activation
216 //=================================================================================
217 void BlocksGUI_TrsfDlg::SelectionIntoArgument()
220 myEditCurrentArgument->setText("");
222 // Get index of current selection focus
224 QMap<int, QLineEdit*>::iterator anIter;
225 for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
226 if (myEditCurrentArgument == anIter.value()) {
227 aCurrFocus = anIter.key();
232 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
233 SALOME_ListIO aSelList;
234 aSelMgr->selectedObjects(aSelList);
237 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_nil();
239 if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2)
241 // If selection of main object is activated
242 if (aSelList.Extent() == 1) {
243 Standard_Boolean aResult = Standard_False;
244 anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
246 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
247 aName = GEOMBase::GetName(anObj);
250 myEditCurrentArgument->setText(aName);
254 else if (aCurrFocus == Face1 || aCurrFocus == Face2 ||
255 aCurrFocus == Face1U || aCurrFocus == Face2U ||
256 aCurrFocus == Face1V || aCurrFocus == Face2V) {
257 // If face selection is activated
259 if (aSelList.Extent() == 1) {
260 Standard_Boolean aResult = Standard_False;
261 anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
262 if (aResult && !anObj->_is_nil() && 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;
278 switch (aCurrFocus) {
281 if (!myShape->_is_nil() && myFaces[Face1] == -1)
282 mySelBtn[Face1]->click();
285 if (myFaces[Face1] != -1 && myFaces[Face2] == -1)
286 mySelBtn[Face2]->click();
289 if (myFaces[Face2] != -1 && myShape->_is_nil())
290 mySelBtn[MainObj1]->click();
295 if (!myShape->_is_nil() && myFaces[Face1U] == -1)
296 mySelBtn[Face1U]->click();
299 if (myFaces[Face1U] != -1 && myFaces[Face2U] == -1)
300 mySelBtn[Face2U]->click();
303 if (myFaces[Face2U] != -1 && myFaces[Face1V] == -1)
304 mySelBtn[Face1V]->click();
307 if (myFaces[Face1V] != -1 && myFaces[Face2V] == -1)
308 mySelBtn[Face2V]->click();
311 if (myFaces[Face2V] != -1 && myShape->_is_nil())
312 mySelBtn[MainObj1]->click();
320 //=================================================================================
321 // function : SetEditCurrentArgument()
323 //=================================================================================
324 void BlocksGUI_TrsfDlg::SetEditCurrentArgument()
326 QPushButton* aSender = (QPushButton*)sender();
329 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
333 myGeomGUI->getApp()->selectionMgr()->clearSelected();
336 switch (myConstructorId) {
338 mySelBtn[MainObj1]->setDown(false);
339 mySelBtn[Face1]->setDown(false);
340 mySelBtn[Face2]->setDown(false);
342 mySelName[MainObj1]->setEnabled(false);
343 mySelName[Face1]->setEnabled(false);
344 mySelName[Face2]->setEnabled(false);
347 mySelBtn[MainObj2]->setDown(false);
348 mySelBtn[Face1U]->setDown(false);
349 mySelBtn[Face2U]->setDown(false);
350 mySelBtn[Face1V]->setDown(false);
351 mySelBtn[Face2V]->setDown(false);
353 mySelName[MainObj2]->setEnabled(false);
354 mySelName[Face1U]->setEnabled(false);
355 mySelName[Face2U]->setEnabled(false);
356 mySelName[Face1V]->setEnabled(false);
357 mySelName[Face2V]->setEnabled(false);
363 // set line edit as current argument
364 QMap<int, QPushButton*>::iterator anIter;
365 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
366 if (anIter.value() == aSender) {
367 myEditCurrentArgument = mySelName[anIter.key()];
373 myEditCurrentArgument->setEnabled(true);
374 myEditCurrentArgument->setFocus();
376 // enable push button
377 // after setFocus(), because it will be setDown(false) when loses focus
378 aSender->setDown(true);
383 //=================================================================================
384 // function : ActivateThisDialog()
386 //=================================================================================
387 void BlocksGUI_TrsfDlg::ActivateThisDialog()
389 GEOMBase_Skeleton::ActivateThisDialog();
396 //=================================================================================
397 // function : enterEvent()
399 //=================================================================================
400 void BlocksGUI_TrsfDlg::enterEvent (QEvent*)
402 if (!mainFrame()->GroupConstructors->isEnabled())
403 ActivateThisDialog();
406 //=================================================================================
407 // function : ValueChangedInSpinBox()
409 //=================================================================================
410 void BlocksGUI_TrsfDlg::ValueChangedInSpinBox(int)
415 //=================================================================================
416 // function : createSelWg()
418 //=================================================================================
419 void BlocksGUI_TrsfDlg::createSelWg (const QString& theLbl,
424 QLabel* lab = new QLabel(theLbl, theParent);
425 mySelBtn[theId] = new QPushButton(theParent);
426 mySelBtn[theId]->setIcon(thePix);
427 mySelBtn[theId]->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
428 mySelName[theId] = new QLineEdit(theParent);
429 mySelName[theId]->setReadOnly(true);
431 if (!theParent->layout()) {
432 l = new QGridLayout(theParent);
433 l->setMargin(9); l->setSpacing(6);
436 l = qobject_cast<QGridLayout*>(theParent->layout());
438 int row = l->rowCount();
439 l->addWidget(lab, row, 0);
440 l->addWidget(mySelBtn[theId], row, 1);
441 l->addWidget(mySelName[theId], row, 2);
444 //=================================================================================
445 // function : createSpinWg()
447 //=================================================================================
448 void BlocksGUI_TrsfDlg::createSpinWg (const QString& theLbl,
452 QLabel* lab = new QLabel(theLbl, theParent);
453 mySpinBox[theId] = new SalomeApp_IntSpinBox(theParent);
455 if (!theParent->layout()) {
456 l = new QGridLayout(theParent);
457 l->setMargin(9); l->setSpacing(6);
460 l = qobject_cast<QGridLayout*>(theParent->layout());
462 int row = l->rowCount();
463 l->addWidget(lab, row, 0);
464 l->addWidget(mySpinBox[theId], row, 2);
467 //=================================================================================
468 // function : activateSelection
469 // purpose : Activate selection in accordance with myEditCurrentArgument
470 //=================================================================================
471 void BlocksGUI_TrsfDlg::activateSelection()
473 globalSelection(GEOM_ALLSHAPES);
474 if (!myShape->_is_nil() &&
475 (myEditCurrentArgument == mySelName[Face1 ] ||
476 myEditCurrentArgument == mySelName[Face2 ] ||
477 myEditCurrentArgument == mySelName[Face1U] ||
478 myEditCurrentArgument == mySelName[Face2U] ||
479 myEditCurrentArgument == mySelName[Face1V] ||
480 myEditCurrentArgument == mySelName[Face2V]))
482 // Local selection is available only in the OCC Viewer
483 if (getDesktop()->activeWindow()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
484 localSelection(myShape, TopAbs_FACE);
487 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
488 this, SLOT(SelectionIntoArgument()));
491 //=================================================================================
492 // function : enableWidgets
493 // purpose : Enable widgets of faces in accordance with value of main object
494 //=================================================================================
495 void BlocksGUI_TrsfDlg::enableWidgets()
497 int anId = getConstructorId();
499 bool toEnable = !myShape->_is_nil();
502 //mySelName[Face1]->setEnabled(toEnable);
503 //mySelName[Face2]->setEnabled(toEnable);
504 //mySelBtn[Face1]->setEnabled(toEnable);
505 //mySelBtn[Face2]->setEnabled(toEnable);
508 mySelName[Face1]->setText("");
509 mySelName[Face2]->setText("");
514 else if (anId == 1) {
515 //mySelName[Face1U]->setEnabled(toEnable);
516 //mySelName[Face2U]->setEnabled(toEnable);
517 //mySelName[Face1V]->setEnabled(toEnable);
518 //mySelName[Face2V]->setEnabled(toEnable);
519 //mySelBtn[Face1U]->setEnabled(toEnable);
520 //mySelBtn[Face2U]->setEnabled(toEnable);
521 //mySelBtn[Face1V]->setEnabled(toEnable);
522 //mySelBtn[Face2V]->setEnabled(toEnable);
525 mySelName[Face1U]->setText("");
526 mySelName[Face2U]->setText("");
527 mySelName[Face1V]->setText("");
528 mySelName[Face2V]->setText("");
529 myFaces[Face1U] = -1;
530 myFaces[Face2U] = -1;
531 myFaces[Face1V] = -1;
532 myFaces[Face2V] = -1;
537 //=================================================================================
538 // function : createOperation
540 //=================================================================================
541 GEOM::GEOM_IOperations_ptr BlocksGUI_TrsfDlg::createOperation()
543 return getGeomEngine()->GetIBlocksOperations(getStudyId());
546 //=================================================================================
547 // function : isValid
548 // purpose : Verify validity of input data
549 //=================================================================================
550 bool BlocksGUI_TrsfDlg::isValid (QString& msg)
552 bool ok = false, okSP = true;
553 switch (getConstructorId()) {
555 ok = !myShape->_is_nil() && myFaces[Face1] > 0;
556 okSP = mySpinBox[SpinBox1]->isValid( msg, !IsPreview() );
559 ok = !myShape->_is_nil() && myFaces[Face1U] > 0 && myFaces[Face1V] > 0;
560 okSP = mySpinBox[SpinBox2U]->isValid( msg, !IsPreview() ) && okSP;
561 okSP = mySpinBox[SpinBox2V]->isValid( msg, !IsPreview() ) && okSP;
569 //=================================================================================
570 // function : execute
572 //=================================================================================
573 bool BlocksGUI_TrsfDlg::execute (ObjectList& objects)
577 GEOM::GEOM_Object_var anObj;
579 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
581 switch (getConstructorId()) {
583 anObj = anOper->MakeMultiTransformation1D(myShape,
584 myFaces[Face1], myFaces[Face2],
585 mySpinBox[SpinBox1]->value());
586 if (!anObj->_is_nil() && !IsPreview())
588 QStringList aParameters;
589 aParameters << "" << "";
590 aParameters << mySpinBox[SpinBox1]->text();
591 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
596 anObj = anOper->MakeMultiTransformation2D (myShape,
597 myFaces[Face1U], myFaces[Face2U],
598 mySpinBox[SpinBox2U]->value(),
599 myFaces[Face1V], myFaces[Face2V],
600 mySpinBox[SpinBox2V]->value());
601 if (!anObj->_is_nil() && !IsPreview())
603 QStringList aParameters;
604 aParameters << "" << "";
605 aParameters << mySpinBox[SpinBox2U]->text();
606 aParameters << "" << "";
607 aParameters << mySpinBox[SpinBox2V]->text();
608 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
616 if (!anObj->_is_nil())
617 objects.push_back(anObj._retn());