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_QuadFaceDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
25 #include "BlocksGUI_QuadFaceDlg.h"
28 #include <GeometryGUI.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
41 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <GEOMImpl_Types.hxx>
45 //=================================================================================
46 // class : BlocksGUI_QuadFaceDlg()
47 // purpose : Constructs a BlocksGUI_QuadFaceDlg which is a child of 'parent'.
48 //=================================================================================
49 BlocksGUI_QuadFaceDlg::BlocksGUI_QuadFaceDlg (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_QUAD_FACE_4_VERT")));
55 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_2_EDGE")));
56 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_4_EDGE")));
57 QPixmap imageS (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
59 setWindowTitle(tr("GEOM_QUAD_FACE_TITLE"));
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle(tr("GEOM_QUAD_FACE"));
64 mainFrame()->RadioButton1->setIcon(image1);
65 mainFrame()->RadioButton2->setIcon(image2);
66 mainFrame()->RadioButton3->setIcon(image3);
69 myGrp1 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
71 createSelWg(tr("VERTEX_1"), imageS, myGrp1, Vertex1);
72 createSelWg(tr("VERTEX_2"), imageS, myGrp1, Vertex2);
73 createSelWg(tr("VERTEX_3"), imageS, myGrp1, Vertex3);
74 createSelWg(tr("VERTEX_4"), imageS, myGrp1, Vertex4);
76 // Create second group
77 myGrp2 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
79 createSelWg(tr("EDGE_1"), imageS, myGrp2, Edge12);
80 createSelWg(tr("EDGE_2"), imageS, myGrp2, Edge22);
83 myGrp3 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
85 createSelWg(tr("EDGE_1"), imageS, myGrp3, Edge14);
86 createSelWg(tr("EDGE_2"), imageS, myGrp3, Edge24);
87 createSelWg(tr("EDGE_3"), imageS, myGrp3, Edge34);
88 createSelWg(tr("EDGE_4"), imageS, myGrp3, Edge44);
90 // Add groups to layout
91 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
92 layout->setMargin(0); layout->setSpacing(6);
93 layout->addWidget(myGrp1);
94 layout->addWidget(myGrp2);
95 layout->addWidget(myGrp3);
96 /***************************************************************/
98 setHelpFileName("build_by_blocks_page.html#quad_face_anchor");
103 //=================================================================================
104 // function : ~BlocksGUI_QuadFaceDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 BlocksGUI_QuadFaceDlg::~BlocksGUI_QuadFaceDlg()
109 // no need to delete child widgets, Qt does it all for us
112 //=================================================================================
115 //=================================================================================
116 void BlocksGUI_QuadFaceDlg::Init()
118 // signals and slots connections
119 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
120 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
122 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
124 QMap<int, QPushButton*>::iterator anIterBtn;
125 for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
126 connect(anIterBtn.value(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 // init controls and fields
129 initName(tr("GEOM_QUAD_FACE"));
131 myConstructorId = -1;
132 ConstructorsClicked(0);
135 //=================================================================================
136 // function : ConstructorsClicked()
137 // purpose : Radio button management
138 //=================================================================================
139 void BlocksGUI_QuadFaceDlg::ConstructorsClicked (int constructorId)
141 if (myConstructorId == constructorId)
144 myConstructorId = constructorId;
147 myShape1 = myShape2 = GEOM::GEOM_Object::_nil();
148 myShape3 = myShape4 = myShape1;
151 QMap<int, QLineEdit*>::iterator anIterLE;
152 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
153 anIterLE.value()->setText("");
155 switch (constructorId) {
160 mySelBtn[Vertex1]->click();
166 mySelBtn[Edge12]->click();
172 mySelBtn[Edge14]->click();
178 qApp->processEvents();
180 resize(minimumSize());
182 // on dialog initialization we init the first field with a selected object (if any)
183 SelectionIntoArgument();
186 //=================================================================================
187 // function : ClickOnOk()
189 //=================================================================================
190 void BlocksGUI_QuadFaceDlg::ClickOnOk()
196 //=================================================================================
197 // function : ClickOnApply()
199 //=================================================================================
200 bool BlocksGUI_QuadFaceDlg::ClickOnApply()
209 //=================================================================================
210 // function : SelectionIntoArgument()
211 // purpose : Called when selection is changed or on dialog initialization or activation
212 //=================================================================================
213 void BlocksGUI_QuadFaceDlg::SelectionIntoArgument()
217 // Get index of current selection focus
219 QMap<int, QLineEdit*>::iterator anIter;
220 for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
221 if (myEditCurrentArgument == anIter.value()) {
222 aCurrFocus = anIter.key();
227 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
228 SALOME_ListIO aSelList;
229 aSelMgr->selectedObjects(aSelList);
231 TopAbs_ShapeEnum aType = TopAbs_EDGE;
232 if (aCurrFocus == Vertex1 || aCurrFocus == Vertex2 ||
233 aCurrFocus == Vertex3 || aCurrFocus == Vertex4)
234 aType = TopAbs_VERTEX;
237 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_nil();
239 if (aSelList.Extent() == 1) {
240 Standard_Boolean aResult = Standard_False;
241 anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
242 if (aResult && !anObj->_is_nil()) {
243 aName = GEOMBase::GetName(anObj);
245 // Get Selected object if selected subshape
247 if (GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE) && !aShape.IsNull())
249 TColStd_IndexedMapOfInteger aMap;
250 aSelMgr->GetIndexes(aSelList.First(), aMap);
251 if (aMap.Extent() == 1) // Local Selection
253 int anIndex = aMap(1);
254 if (aType == TopAbs_VERTEX)
255 aName += QString(":vertex_%1").arg(anIndex);
257 aName += QString(":edge_%1").arg(anIndex);
259 //Find SubShape Object in Father
260 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(anObj, aName);
262 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
263 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
264 anObj = aShapesOp->GetSubShape(anObj, anIndex);
267 anObj = aFindedObject; // get Object from study
269 else // Global Selection
271 if (aShape.ShapeType() != aType) {
272 anObj = GEOM::GEOM_Object::_nil();
280 myEditCurrentArgument->setText(aName);
282 switch (aCurrFocus) {
286 if (!myShape1->_is_nil() && myShape2->_is_nil())
287 mySelBtn[Vertex2]->click();
291 if (!myShape2->_is_nil() && myShape3->_is_nil())
292 mySelBtn[Vertex3]->click();
296 if (!myShape3->_is_nil() && myShape4->_is_nil())
297 mySelBtn[Vertex4]->click();
301 if (!myShape4->_is_nil() && myShape1->_is_nil())
302 mySelBtn[Vertex1]->click();
308 if (!myShape1->_is_nil() && myShape2->_is_nil())
309 mySelBtn[Edge22]->click();
313 if (!myShape2->_is_nil() && myShape1->_is_nil())
314 mySelBtn[Edge12]->click();
320 if (!myShape1->_is_nil() && myShape2->_is_nil())
321 mySelBtn[Edge24]->click();
325 if (!myShape2->_is_nil() && myShape3->_is_nil())
326 mySelBtn[Edge34]->click();
330 if (!myShape3->_is_nil() && myShape4->_is_nil())
331 mySelBtn[Edge44]->click();
335 if (!myShape4->_is_nil() && myShape1->_is_nil())
336 mySelBtn[Edge14]->click();
346 //=================================================================================
347 // function : SetEditCurrentArgument()
349 //=================================================================================
350 void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument()
352 QPushButton* aSender = (QPushButton*)sender();
355 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
359 myGeomGUI->getApp()->selectionMgr()->clearSelected();
362 switch (myConstructorId) {
364 mySelBtn[Vertex1]->setDown(false);
365 mySelBtn[Vertex2]->setDown(false);
366 mySelBtn[Vertex3]->setDown(false);
367 mySelBtn[Vertex4]->setDown(false);
369 mySelName[Vertex1]->setEnabled(false);
370 mySelName[Vertex2]->setEnabled(false);
371 mySelName[Vertex3]->setEnabled(false);
372 mySelName[Vertex4]->setEnabled(false);
375 mySelBtn[Edge12]->setDown(false);
376 mySelBtn[Edge22]->setDown(false);
378 mySelName[Edge12]->setEnabled(false);
379 mySelName[Edge22]->setEnabled(false);
382 mySelBtn[Edge14]->setDown(false);
383 mySelBtn[Edge24]->setDown(false);
384 mySelBtn[Edge34]->setDown(false);
385 mySelBtn[Edge44]->setDown(false);
387 mySelName[Edge14]->setEnabled(false);
388 mySelName[Edge24]->setEnabled(false);
389 mySelName[Edge34]->setEnabled(false);
390 mySelName[Edge44]->setEnabled(false);
396 // set line edit as current argument
397 QMap<int, QPushButton*>::iterator anIter;
398 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
399 if (anIter.value() == aSender) {
400 myEditCurrentArgument = mySelName[anIter.key()];
406 myEditCurrentArgument->setEnabled(true);
407 myEditCurrentArgument->setFocus();
409 // enable push button
410 // after setFocus(), because it will be setDown(false) when loses focus
411 aSender->setDown(true);
416 //=================================================================================
417 // function : ActivateThisDialog()
419 //=================================================================================
420 void BlocksGUI_QuadFaceDlg::ActivateThisDialog()
422 GEOMBase_Skeleton::ActivateThisDialog();
429 //=================================================================================
430 // function : enterEvent()
432 //=================================================================================
433 void BlocksGUI_QuadFaceDlg::enterEvent (QEvent*)
435 if (!mainFrame()->GroupConstructors->isEnabled())
436 ActivateThisDialog();
439 //=================================================================================
440 // function : createSelWg()
442 //=================================================================================
443 void BlocksGUI_QuadFaceDlg::createSelWg (const QString& theLbl,
448 QLabel* lab = new QLabel(theLbl, theParent);
449 mySelBtn[theId] = new QPushButton(theParent);
450 mySelBtn[theId]->setIcon(thePix);
451 mySelBtn[theId]->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
452 mySelName[theId] = new QLineEdit(theParent);
453 mySelName[theId]->setReadOnly(true);
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(mySelBtn[theId], row, 1);
465 l->addWidget(mySelName[theId], row, 2);
468 //=================================================================================
469 // function : activateSelection
470 // purpose : Activate selection in accordance with myEditCurrentArgument
471 //=================================================================================
472 void BlocksGUI_QuadFaceDlg::activateSelection()
474 globalSelection(); // close local contexts, if any
475 if (myEditCurrentArgument == mySelName[Vertex1] ||
476 myEditCurrentArgument == mySelName[Vertex2] ||
477 myEditCurrentArgument == mySelName[Vertex3] ||
478 myEditCurrentArgument == mySelName[Vertex4])
480 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertices on All Shapes
484 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE); //Select Edges on All Shapes
486 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
487 this, SLOT(SelectionIntoArgument()));
490 //=================================================================================
491 // function : createOperation
493 //=================================================================================
494 GEOM::GEOM_IOperations_ptr BlocksGUI_QuadFaceDlg::createOperation()
496 return getGeomEngine()->GetIBlocksOperations(getStudyId());
499 //=================================================================================
500 // function : isValid
501 // purpose : Verify validity of input data
502 //=================================================================================
503 bool BlocksGUI_QuadFaceDlg::isValid (QString&)
506 switch (getConstructorId()) {
508 ok = (!myShape1->_is_nil() && !myShape2->_is_nil() &&
509 !myShape3->_is_nil() && !myShape4->_is_nil());
512 ok = (!myShape1->_is_nil() && !myShape2->_is_nil());
515 ok = (!myShape1->_is_nil() && !myShape2->_is_nil() &&
516 !myShape3->_is_nil() && !myShape4->_is_nil());
524 //=================================================================================
525 // function : execute
527 //=================================================================================
528 bool BlocksGUI_QuadFaceDlg::execute (ObjectList& objects)
532 GEOM::GEOM_Object_var anObj;
534 switch (getConstructorId()) {
536 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
537 MakeQuad4Vertices(myShape1, myShape2, myShape3, myShape4);
541 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
542 MakeQuad2Edges(myShape1, myShape2);
546 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
547 MakeQuad(myShape1, myShape2, myShape3, myShape4);
554 if (!anObj->_is_nil())
555 objects.push_back(anObj._retn());
560 //=================================================================================
561 // function : addSubshapeToStudy
562 // purpose : virtual method to add new SubObjects if local selection
563 //=================================================================================
564 void BlocksGUI_QuadFaceDlg::addSubshapesToStudy()
566 QMap<QString, GEOM::GEOM_Object_var> objMap;
568 switch (getConstructorId()) {
570 objMap[mySelName[Vertex1]->text()] = myShape1;
571 objMap[mySelName[Vertex2]->text()] = myShape2;
572 objMap[mySelName[Vertex3]->text()] = myShape3;
573 objMap[mySelName[Vertex4]->text()] = myShape4;
576 objMap[mySelName[Edge12]->text()] = myShape1;
577 objMap[mySelName[Edge22]->text()] = myShape2;
580 objMap[mySelName[Edge14]->text()] = myShape1;
581 objMap[mySelName[Edge24]->text()] = myShape2;
582 objMap[mySelName[Edge34]->text()] = myShape3;
583 objMap[mySelName[Edge44]->text()] = myShape4;
586 addSubshapesToFather(objMap);