]> SALOME platform Git repositories - modules/geom.git/blob - src/BlocksGUI/BlocksGUI_QuadFaceDlg.cxx
Salome HOME
Additional fix of issue 0019875: to clarify the labels of the GUI panel for group...
[modules/geom.git] / src / BlocksGUI / BlocksGUI_QuadFaceDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  CEA
4 //
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.
9 //
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.
14 //
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
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 // File   : BlocksGUI_QuadFaceDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
23 //
24
25 #include "BlocksGUI_QuadFaceDlg.h"
26
27 #include <DlgRef.h>
28 #include <GeometryGUI.h>
29 #include <GEOMBase.h>
30
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35
36 #include <GEOMImpl_Types.hxx>
37
38 #include <qlabel.h>
39
40 // OCCT Includes
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopAbs.hxx>
43
44 //=================================================================================
45 // class    : BlocksGUI_QuadFaceDlg()
46 // purpose  : Constructs a BlocksGUI_QuadFaceDlg which is a child of 'parent'.
47 //=================================================================================
48 BlocksGUI_QuadFaceDlg::BlocksGUI_QuadFaceDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
49   : GEOMBase_Skeleton(theGeometryGUI, parent),
50     myInitial(true)
51 {
52   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
53   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_4_VERT")));
54   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_2_EDGE")));
55   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_4_EDGE")));
56   QPixmap imageS (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
57
58   setWindowTitle(tr("GEOM_QUAD_FACE_TITLE"));
59
60   /***************************************************************/
61   mainFrame()->GroupConstructors->setTitle(tr("GEOM_QUAD_FACE"));
62
63   mainFrame()->RadioButton1->setIcon(image1);
64   mainFrame()->RadioButton2->setIcon(image2);
65   mainFrame()->RadioButton3->setIcon(image3);
66
67   // Create first group
68   myGrp1 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
69
70   createSelWg(tr("VERTEX_1"), imageS, myGrp1, Vertex1);
71   createSelWg(tr("VERTEX_2"), imageS, myGrp1, Vertex2);
72   createSelWg(tr("VERTEX_3"), imageS, myGrp1, Vertex3);
73   createSelWg(tr("VERTEX_4"), imageS, myGrp1, Vertex4);
74
75   // Create second group
76   myGrp2 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
77
78   createSelWg(tr("EDGE_1"), imageS, myGrp2, Edge12);
79   createSelWg(tr("EDGE_2"), imageS, myGrp2, Edge22);
80
81   // Create fird group
82   myGrp3 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
83
84   createSelWg(tr("EDGE_1"), imageS, myGrp3, Edge14);
85   createSelWg(tr("EDGE_2"), imageS, myGrp3, Edge24);
86   createSelWg(tr("EDGE_3"), imageS, myGrp3, Edge34);
87   createSelWg(tr("EDGE_4"), imageS, myGrp3, Edge44);
88
89   // Add groups to layout
90   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
91   layout->setMargin(0); layout->setSpacing(6);
92   layout->addWidget(myGrp1);
93   layout->addWidget(myGrp2);
94   layout->addWidget(myGrp3);
95   /***************************************************************/
96
97   setHelpFileName("build_by_blocks_page.html#quad_face_anchor");
98
99   Init();
100 }
101
102 //=================================================================================
103 // function : ~BlocksGUI_QuadFaceDlg()
104 // purpose  : Destroys the object and frees any allocated resources
105 //=================================================================================
106 BlocksGUI_QuadFaceDlg::~BlocksGUI_QuadFaceDlg()
107 {
108   // no need to delete child widgets, Qt does it all for us
109 }
110
111 //=================================================================================
112 // function : Init()
113 // purpose  :
114 //=================================================================================
115 void BlocksGUI_QuadFaceDlg::Init()
116 {
117   // signals and slots connections
118   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120
121   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
122
123   QMap<int, QPushButton*>::iterator anIterBtn;
124   for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
125     connect(anIterBtn.value(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126
127   // init controls and fields
128   initName(tr("GEOM_QUAD_FACE"));
129
130   myConstructorId = -1;
131   ConstructorsClicked(0);
132 }
133
134 //=================================================================================
135 // function : ConstructorsClicked()
136 // purpose  : Radio button management
137 //=================================================================================
138 void BlocksGUI_QuadFaceDlg::ConstructorsClicked (int constructorId)
139 {
140   if (myConstructorId == constructorId)
141     return;
142
143   myConstructorId = constructorId;
144
145   // init fields
146   myShape1 = myShape2 = GEOM::GEOM_Object::_nil();
147   myShape3 = myShape4 = myShape1;
148
149   // clear line edits
150   QMap<int, QLineEdit*>::iterator anIterLE;
151   for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
152     anIterLE.value()->setText("");
153
154   switch (constructorId) {
155   case 0:
156     myGrp2->hide();
157     myGrp3->hide();
158     myGrp1->show();
159     mySelBtn[Vertex1]->click();
160     break;
161   case 1:
162     myGrp1->hide();
163     myGrp3->hide();
164     myGrp2->show();
165     mySelBtn[Edge12]->click();
166     break;
167   case 2:
168     myGrp1->hide();
169     myGrp2->hide();
170     myGrp3->show();
171     mySelBtn[Edge14]->click();
172     break;
173   default:
174     break;
175   }
176
177   qApp->processEvents();
178   updateGeometry();
179   resize(minimumSize());
180
181   // on dialog initialization we init the first field with a selected object (if any)
182   SelectionIntoArgument();
183 }
184
185 //=================================================================================
186 // function : ClickOnOk()
187 // purpose  :
188 //=================================================================================
189 void BlocksGUI_QuadFaceDlg::ClickOnOk()
190 {
191   if (ClickOnApply())
192     ClickOnCancel();
193 }
194
195 //=================================================================================
196 // function : ClickOnApply()
197 // purpose  :
198 //=================================================================================
199 bool BlocksGUI_QuadFaceDlg::ClickOnApply()
200 {
201   if (!onAccept())
202     return false;
203
204   initName();
205   return true;
206 }
207
208 //=================================================================================
209 // function : SelectionIntoArgument()
210 // purpose  : Called when selection is changed or on dialog initialization or activation
211 //=================================================================================
212 void BlocksGUI_QuadFaceDlg::SelectionIntoArgument()
213 {
214   erasePreview();
215
216   // Get index of current selection focus
217   int aCurrFocus = -1;
218   QMap<int, QLineEdit*>::iterator anIter;
219   for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
220     if (myEditCurrentArgument == anIter.value()) {
221       aCurrFocus = anIter.key();
222       break;
223     }
224   }
225
226   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
227   SALOME_ListIO aSelList;
228   aSelMgr->selectedObjects(aSelList);
229
230   TopAbs_ShapeEnum aType = TopAbs_EDGE;
231   if (aCurrFocus == Vertex1 || aCurrFocus == Vertex2 ||
232       aCurrFocus == Vertex3 || aCurrFocus == Vertex4)
233     aType = TopAbs_VERTEX;
234
235   QString aName;
236   GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_nil();
237
238   if (aSelList.Extent() == 1) {
239     Standard_Boolean aResult = Standard_False;
240     anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
241     if (aResult && !anObj->_is_nil()) {
242       aName = GEOMBase::GetName(anObj);
243
244       // Get Selected object if selected subshape
245       TopoDS_Shape aShape;
246       if (GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE) && !aShape.IsNull())
247       {
248         TColStd_IndexedMapOfInteger aMap;
249         aSelMgr->GetIndexes(aSelList.First(), aMap);
250         if (aMap.Extent() == 1) // Local Selection
251         {
252           int anIndex = aMap(1);
253           if (aType == TopAbs_VERTEX)
254             aName += QString(":vertex_%1").arg(anIndex);
255           else
256             aName += QString(":edge_%1").arg(anIndex);
257
258           //Find SubShape Object in Father
259           GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(anObj, aName);
260
261           if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
262             GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
263             anObj = aShapesOp->GetSubShape(anObj, anIndex);
264           }
265           else
266             anObj = aFindedObject; // get Object from study
267         }
268         else // Global Selection
269         {
270           if (aShape.ShapeType() != aType) {
271             anObj = GEOM::GEOM_Object::_nil();
272             aName = "";
273           }
274         }
275       }
276     }
277   }
278
279   myEditCurrentArgument->setText(aName);
280
281   switch (aCurrFocus) {
282     // four vertices
283   case Vertex1:
284     myShape1 = anObj;
285     if (!myShape1->_is_nil() && myShape2->_is_nil())
286       mySelBtn[Vertex2]->click();
287     break;
288   case Vertex2:
289     myShape2 = anObj;
290     if (!myShape2->_is_nil() && myShape3->_is_nil())
291       mySelBtn[Vertex3]->click();
292     break;
293   case Vertex3:
294     myShape3 = anObj;
295     if (!myShape3->_is_nil() && myShape4->_is_nil())
296       mySelBtn[Vertex4]->click();
297     break;
298   case Vertex4:
299     myShape4 = anObj;
300     if (!myShape4->_is_nil() && myShape1->_is_nil())
301       mySelBtn[Vertex1]->click();
302     break;
303
304     // two edges
305   case Edge12:
306     myShape1 = anObj;
307     if (!myShape1->_is_nil() && myShape2->_is_nil())
308       mySelBtn[Edge22]->click();
309     break;
310   case Edge22:
311     myShape2 = anObj;
312     if (!myShape2->_is_nil() && myShape1->_is_nil())
313       mySelBtn[Edge12]->click();
314     break;
315
316     // four edges
317   case Edge14:
318     myShape1 = anObj;
319     if (!myShape1->_is_nil() && myShape2->_is_nil())
320       mySelBtn[Edge24]->click();
321     break;
322   case Edge24:
323     myShape2 = anObj;
324     if (!myShape2->_is_nil() && myShape3->_is_nil())
325       mySelBtn[Edge34]->click();
326     break;
327   case Edge34:
328     myShape3 = anObj;
329     if (!myShape3->_is_nil() && myShape4->_is_nil())
330       mySelBtn[Edge44]->click();
331     break;
332   case Edge44:
333     myShape4 = anObj;
334     if (!myShape4->_is_nil() && myShape1->_is_nil())
335       mySelBtn[Edge14]->click();
336     break;
337
338   default:
339     break;
340   }
341
342   displayPreview();
343 }
344
345 //=================================================================================
346 // function : SetEditCurrentArgument()
347 // purpose  :
348 //=================================================================================
349 void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument()
350 {
351   QPushButton* aSender = (QPushButton*)sender();
352
353   // clear selection
354   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
355   if (myInitial)
356     myInitial = false;
357   else
358     myGeomGUI->getApp()->selectionMgr()->clearSelected();
359
360   // disable all
361   switch (myConstructorId) {
362   case 0:
363     mySelBtn[Vertex1]->setDown(false);
364     mySelBtn[Vertex2]->setDown(false);
365     mySelBtn[Vertex3]->setDown(false);
366     mySelBtn[Vertex4]->setDown(false);
367
368     mySelName[Vertex1]->setEnabled(false);
369     mySelName[Vertex2]->setEnabled(false);
370     mySelName[Vertex3]->setEnabled(false);
371     mySelName[Vertex4]->setEnabled(false);
372     break;
373   case 1:
374     mySelBtn[Edge12]->setDown(false);
375     mySelBtn[Edge22]->setDown(false);
376
377     mySelName[Edge12]->setEnabled(false);
378     mySelName[Edge22]->setEnabled(false);
379     break;
380   case 2:
381     mySelBtn[Edge14]->setDown(false);
382     mySelBtn[Edge24]->setDown(false);
383     mySelBtn[Edge34]->setDown(false);
384     mySelBtn[Edge44]->setDown(false);
385
386     mySelName[Edge14]->setEnabled(false);
387     mySelName[Edge24]->setEnabled(false);
388     mySelName[Edge34]->setEnabled(false);
389     mySelName[Edge44]->setEnabled(false);
390     break;
391   default:
392     break;
393   }
394
395   // enable push button
396   aSender->setDown(true);
397
398   // set line edit as current argument
399   QMap<int, QPushButton*>::iterator anIter;
400   for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
401     if (anIter.value() == aSender) {
402       myEditCurrentArgument = mySelName[anIter.key()];
403       break;
404     }
405   }
406
407   // enable line edit
408   myEditCurrentArgument->setEnabled(true);
409   myEditCurrentArgument->setFocus();
410
411   activateSelection();
412 }
413
414 //=================================================================================
415 // function : ActivateThisDialog()
416 // purpose  :
417 //=================================================================================
418 void BlocksGUI_QuadFaceDlg::ActivateThisDialog()
419 {
420   GEOMBase_Skeleton::ActivateThisDialog();
421   activateSelection();
422
423   // ??
424   displayPreview();
425 }
426
427 //=================================================================================
428 // function : enterEvent()
429 // purpose  :
430 //=================================================================================
431 void BlocksGUI_QuadFaceDlg::enterEvent (QEvent*)
432 {
433   if (!mainFrame()->GroupConstructors->isEnabled())
434     ActivateThisDialog();
435 }
436
437 //=================================================================================
438 // function : createSelWg()
439 // purpose  :
440 //=================================================================================
441 void BlocksGUI_QuadFaceDlg::createSelWg (const QString& theLbl,
442                                          QPixmap&       thePix,
443                                          QWidget*       theParent,
444                                          const int      theId)
445 {
446   QLabel* lab = new QLabel(theLbl, theParent);
447   mySelBtn[theId] = new QPushButton(theParent);
448   mySelBtn[theId]->setIcon(thePix);
449   mySelBtn[theId]->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
450   mySelName[theId] = new QLineEdit(theParent);
451   mySelName[theId]->setReadOnly(true);
452   QGridLayout* l = 0;
453   if (!theParent->layout()) {
454     l = new QGridLayout(theParent);
455     l->setMargin(9); l->setSpacing(6);
456   }
457   else {
458     l = qobject_cast<QGridLayout*>(theParent->layout());
459   }
460   int row = l->rowCount();
461   l->addWidget(lab,              row, 0);
462   l->addWidget(mySelBtn[theId],  row, 1);
463   l->addWidget(mySelName[theId], row, 2);
464 }
465
466 //=================================================================================
467 // function : activateSelection
468 // purpose  : Activate selection in accordance with myEditCurrentArgument
469 //=================================================================================
470 void BlocksGUI_QuadFaceDlg::activateSelection()
471 {
472   globalSelection(); // close local contexts, if any
473   if (myEditCurrentArgument == mySelName[Vertex1] ||
474       myEditCurrentArgument == mySelName[Vertex2] ||
475       myEditCurrentArgument == mySelName[Vertex3] ||
476       myEditCurrentArgument == mySelName[Vertex4])
477   {
478     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertices on All Shapes
479   }
480   else
481   {
482     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE); //Select Edges on All Shapes
483   }
484   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
485           this, SLOT(SelectionIntoArgument()));
486 }
487
488 //=================================================================================
489 // function : createOperation
490 // purpose  :
491 //=================================================================================
492 GEOM::GEOM_IOperations_ptr BlocksGUI_QuadFaceDlg::createOperation()
493 {
494   return getGeomEngine()->GetIBlocksOperations(getStudyId());
495 }
496
497 //=================================================================================
498 // function : isValid
499 // purpose  : Verify validity of input data
500 //=================================================================================
501 bool BlocksGUI_QuadFaceDlg::isValid (QString&)
502 {
503   bool ok = false;
504   switch (getConstructorId()) {
505   case 0:
506     ok = (!myShape1->_is_nil() && !myShape2->_is_nil() &&
507           !myShape3->_is_nil() && !myShape4->_is_nil());
508     break;
509   case 1:
510     ok = (!myShape1->_is_nil() && !myShape2->_is_nil());
511     break;
512   case 2:
513     ok = (!myShape1->_is_nil() && !myShape2->_is_nil() &&
514           !myShape3->_is_nil() && !myShape4->_is_nil());
515     break;
516   default:
517     break;
518   }
519   return ok;
520 }
521
522 //=================================================================================
523 // function : execute
524 // purpose  :
525 //=================================================================================
526 bool BlocksGUI_QuadFaceDlg::execute (ObjectList& objects)
527 {
528   bool res = false;
529
530   GEOM::GEOM_Object_var anObj;
531
532   switch (getConstructorId()) {
533   case 0:
534     anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
535       MakeQuad4Vertices(myShape1, myShape2, myShape3, myShape4);
536     res = true;
537     break;
538   case 1:
539     anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
540       MakeQuad2Edges(myShape1, myShape2);
541     res = true;
542     break;
543   case 2:
544     anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
545       MakeQuad(myShape1, myShape2, myShape3, myShape4);
546     res = true;
547     break;
548   default:
549     break;
550   }
551
552   if (!anObj->_is_nil())
553     objects.push_back(anObj._retn());
554
555   return res;
556 }
557
558 //=================================================================================
559 // function : addSubshapeToStudy
560 // purpose  : virtual method to add new SubObjects if local selection
561 //=================================================================================
562 void BlocksGUI_QuadFaceDlg::addSubshapesToStudy()
563 {
564   QMap<QString, GEOM::GEOM_Object_var> objMap;
565
566   switch (getConstructorId()) {
567   case 0:
568     objMap[mySelName[Vertex1]->text()] = myShape1;
569     objMap[mySelName[Vertex2]->text()] = myShape2;
570     objMap[mySelName[Vertex3]->text()] = myShape3;
571     objMap[mySelName[Vertex4]->text()] = myShape4;
572     break;
573   case 1:
574     objMap[mySelName[Edge12]->text()] = myShape1;
575     objMap[mySelName[Edge22]->text()] = myShape2;
576     break;
577   case 2:
578     objMap[mySelName[Edge14]->text()] = myShape1;
579     objMap[mySelName[Edge24]->text()] = myShape2;
580     objMap[mySelName[Edge34]->text()] = myShape3;
581     objMap[mySelName[Edge44]->text()] = myShape4;
582     break;
583   }
584   addSubshapesToFather(objMap);
585 }