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_BlockDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
25 #include "BlocksGUI_BlockDlg.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>
36 #include <GEOMImpl_Types.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
41 //=================================================================================
42 // class : BlocksGUI_BlockDlg()
43 // purpose : Constructs a BlocksGUI_BlockDlg which is a child of 'parent'.
44 //=================================================================================
45 BlocksGUI_BlockDlg::BlocksGUI_BlockDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
46 : GEOMBase_Skeleton(theGeometryGUI, parent),
49 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_2F")));
50 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_6F")));
51 QPixmap imageS (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
53 setWindowTitle(tr("GEOM_BLOCK_TITLE"));
55 /***************************************************************/
56 mainFrame()->GroupConstructors->setTitle(tr("GEOM_BLOCK"));
58 mainFrame()->RadioButton1->setIcon(image0);
59 mainFrame()->RadioButton2->setIcon(image1);
60 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
61 mainFrame()->RadioButton3->close();
64 Group2F = new DlgRef_2Sel (centralWidget());
65 Group2F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
66 Group2F->TextLabel1->setText(tr("FACE_1"));
67 Group2F->TextLabel2->setText(tr("FACE_2"));
68 Group2F->PushButton1->setIcon(imageS);
69 Group2F->PushButton2->setIcon(imageS);
71 // Create second group
72 Group6F = new DlgRef_6Sel (centralWidget());
73 Group6F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
74 Group6F->TextLabel1->setText(tr("FACE_1"));
75 Group6F->TextLabel2->setText(tr("FACE_2"));
76 Group6F->TextLabel3->setText(tr("FACE_3"));
77 Group6F->TextLabel4->setText(tr("FACE_4"));
78 Group6F->TextLabel5->setText(tr("FACE_5"));
79 Group6F->TextLabel6->setText(tr("FACE_6"));
80 Group6F->PushButton1->setIcon(imageS);
81 Group6F->PushButton2->setIcon(imageS);
82 Group6F->PushButton3->setIcon(imageS);
83 Group6F->PushButton4->setIcon(imageS);
84 Group6F->PushButton5->setIcon(imageS);
85 Group6F->PushButton6->setIcon(imageS);
87 // Add groups to layout
88 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
90 layout->setSpacing(6);
91 layout->addWidget(Group2F);
92 layout->addWidget(Group6F);
93 /***************************************************************/
95 setHelpFileName("build_by_blocks_page.html#hexa_solid_anchor");
100 //=================================================================================
101 // function : ~BlocksGUI_BlockDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 BlocksGUI_BlockDlg::~BlocksGUI_BlockDlg()
106 // no need to delete child widgets, Qt does it all for us
109 //=================================================================================
112 //=================================================================================
113 void BlocksGUI_BlockDlg::Init()
116 Group2F->LineEdit1->setReadOnly(true);
117 Group2F->LineEdit2->setReadOnly(true);
119 Group6F->LineEdit1->setReadOnly(true);
120 Group6F->LineEdit2->setReadOnly(true);
121 Group6F->LineEdit3->setReadOnly(true);
122 Group6F->LineEdit4->setReadOnly(true);
123 Group6F->LineEdit5->setReadOnly(true);
124 Group6F->LineEdit6->setReadOnly(true);
126 // signals and slots connections
127 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
132 connect(Group2F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(Group2F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(Group6F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(Group6F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(Group6F->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(Group6F->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(Group6F->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(Group6F->PushButton6, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 // init controls and fields
143 initName(tr("GEOM_BLOCK"));
145 myConstructorId = -1;
146 ConstructorsClicked(0);
149 //=================================================================================
150 // function : ConstructorsClicked()
151 // purpose : Radio button management
152 //=================================================================================
153 void BlocksGUI_BlockDlg::ConstructorsClicked (int constructorId)
155 if (myConstructorId == constructorId)
158 myConstructorId = constructorId;
161 myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
162 myFace3 = myFace4 = myFace5 = myFace6 = myFace1;
164 switch (constructorId) {
169 Group2F->LineEdit1->setText(tr(""));
170 Group2F->LineEdit2->setText(tr(""));
172 Group2F->PushButton1->click();
178 Group6F->LineEdit1->setText(tr(""));
179 Group6F->LineEdit2->setText(tr(""));
180 Group6F->LineEdit3->setText(tr(""));
181 Group6F->LineEdit4->setText(tr(""));
182 Group6F->LineEdit5->setText(tr(""));
183 Group6F->LineEdit6->setText(tr(""));
185 Group6F->PushButton1->click();
191 qApp->processEvents();
193 resize(minimumSize());
195 // on dialog initialization we init the first field with a selected object (if any)
196 SelectionIntoArgument();
199 //=================================================================================
200 // function : ClickOnOk()
202 //=================================================================================
203 void BlocksGUI_BlockDlg::ClickOnOk()
209 //=================================================================================
210 // function : ClickOnApply()
212 //=================================================================================
213 bool BlocksGUI_BlockDlg::ClickOnApply()
222 //=================================================================================
223 // function : SelectionIntoArgument()
224 // purpose : Called when selection is changed or on dialog initialization or activation
225 //=================================================================================
226 void BlocksGUI_BlockDlg::SelectionIntoArgument()
229 myEditCurrentArgument->setText("");
231 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
232 SALOME_ListIO aSelList;
233 aSelMgr->selectedObjects(aSelList);
235 if (aSelList.Extent() != 1) {
236 if (myEditCurrentArgument == Group2F->LineEdit1) myFace1 = GEOM::GEOM_Object::_nil();
237 else if (myEditCurrentArgument == Group2F->LineEdit2) myFace2 = GEOM::GEOM_Object::_nil();
238 else if (myEditCurrentArgument == Group6F->LineEdit1) myFace1 = GEOM::GEOM_Object::_nil();
239 else if (myEditCurrentArgument == Group6F->LineEdit2) myFace2 = GEOM::GEOM_Object::_nil();
240 else if (myEditCurrentArgument == Group6F->LineEdit3) myFace3 = GEOM::GEOM_Object::_nil();
241 else if (myEditCurrentArgument == Group6F->LineEdit4) myFace4 = GEOM::GEOM_Object::_nil();
242 else if (myEditCurrentArgument == Group6F->LineEdit5) myFace5 = GEOM::GEOM_Object::_nil();
243 else if (myEditCurrentArgument == Group6F->LineEdit6) myFace6 = GEOM::GEOM_Object::_nil();
248 Standard_Boolean testResult = Standard_False;
249 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
251 if (!testResult || CORBA::is_nil(aSelectedObject))
254 QString aName = GEOMBase::GetName(aSelectedObject);
256 // Get Selected object if selected subshape
258 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
260 TColStd_IndexedMapOfInteger aMap;
261 aSelMgr->GetIndexes(aSelList.First(), aMap);
262 if (aMap.Extent() == 1) // Local Selection
264 int anIndex = aMap(1);
265 aName += QString(":face_%1").arg(anIndex);
267 //Find SubShape Object in Father
268 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
270 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
271 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
272 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
275 aSelectedObject = aFindedObject; // get Object from study
278 else // Global Selection
280 if (aShape.ShapeType() != TopAbs_FACE) {
281 aSelectedObject = GEOM::GEOM_Object::_nil();
287 myEditCurrentArgument->setText(aName);
289 if (myEditCurrentArgument == Group2F->LineEdit1) {
290 myFace1 = aSelectedObject;
291 if (!myFace1->_is_nil() && myFace2->_is_nil())
292 Group2F->PushButton2->click();
294 else if (myEditCurrentArgument == Group2F->LineEdit2) {
295 myFace2 = aSelectedObject;
296 if (!myFace2->_is_nil() && myFace1->_is_nil())
297 Group2F->PushButton1->click();
299 else if (myEditCurrentArgument == Group6F->LineEdit1) {
300 myFace1 = aSelectedObject;
301 if (!myFace1->_is_nil() && myFace2->_is_nil())
302 Group6F->PushButton2->click();
304 else if (myEditCurrentArgument == Group6F->LineEdit2) {
305 myFace2 = aSelectedObject;
306 if (!myFace2->_is_nil() && myFace3->_is_nil())
307 Group6F->PushButton3->click();
309 else if (myEditCurrentArgument == Group6F->LineEdit3) {
310 myFace3 = aSelectedObject;
311 if (!myFace3->_is_nil() && myFace4->_is_nil())
312 Group6F->PushButton4->click();
314 else if (myEditCurrentArgument == Group6F->LineEdit4) {
315 myFace4 = aSelectedObject;
316 if (!myFace4->_is_nil() && myFace5->_is_nil())
317 Group6F->PushButton5->click();
319 else if (myEditCurrentArgument == Group6F->LineEdit5) {
320 myFace5 = aSelectedObject;
321 if (!myFace5->_is_nil() && myFace6->_is_nil())
322 Group6F->PushButton6->click();
324 else if (myEditCurrentArgument == Group6F->LineEdit6) {
325 myFace6 = aSelectedObject;
326 if (!myFace6->_is_nil() && myFace1->_is_nil())
327 Group6F->PushButton1->click();
333 //=================================================================================
334 // function : SetEditCurrentArgument()
336 //=================================================================================
337 void BlocksGUI_BlockDlg::SetEditCurrentArgument()
339 QPushButton* aSender = (QPushButton*)sender();
342 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
346 myGeomGUI->getApp()->selectionMgr()->clearSelected();
349 switch (myConstructorId) {
351 Group2F->PushButton1->setDown(false);
352 Group2F->PushButton2->setDown(false);
354 Group2F->LineEdit1->setEnabled(false);
355 Group2F->LineEdit2->setEnabled(false);
358 Group6F->PushButton1->setDown(false);
359 Group6F->PushButton2->setDown(false);
360 Group6F->PushButton3->setDown(false);
361 Group6F->PushButton4->setDown(false);
362 Group6F->PushButton5->setDown(false);
363 Group6F->PushButton6->setDown(false);
365 Group6F->LineEdit1->setEnabled(false);
366 Group6F->LineEdit2->setEnabled(false);
367 Group6F->LineEdit3->setEnabled(false);
368 Group6F->LineEdit4->setEnabled(false);
369 Group6F->LineEdit5->setEnabled(false);
370 Group6F->LineEdit6->setEnabled(false);
376 // set line edit as current argument
377 if (aSender == Group2F->PushButton1) {
378 myEditCurrentArgument = Group2F->LineEdit1;
380 else if (aSender == Group2F->PushButton2) {
381 myEditCurrentArgument = Group2F->LineEdit2;
383 else if (aSender == Group6F->PushButton1) {
384 myEditCurrentArgument = Group6F->LineEdit1;
386 else if (aSender == Group6F->PushButton2) {
387 myEditCurrentArgument = Group6F->LineEdit2;
389 else if (aSender == Group6F->PushButton3) {
390 myEditCurrentArgument = Group6F->LineEdit3;
392 else if (aSender == Group6F->PushButton4) {
393 myEditCurrentArgument = Group6F->LineEdit4;
395 else if (aSender == Group6F->PushButton5) {
396 myEditCurrentArgument = Group6F->LineEdit5;
398 else if (aSender == Group6F->PushButton6) {
399 myEditCurrentArgument = Group6F->LineEdit6;
402 // enable push button and line edit
403 myEditCurrentArgument->setEnabled(true);
404 myEditCurrentArgument->setFocus();
405 // after setFocus(), because it will be setDown(false) then loses focus
406 aSender->setDown(true);
408 globalSelection(); // close local contexts, if any
409 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE); //Select Faces on All Shapes
410 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
411 this, SLOT(SelectionIntoArgument()));
414 //=================================================================================
415 // function : ActivateThisDialog()
417 //=================================================================================
418 void BlocksGUI_BlockDlg::ActivateThisDialog()
420 GEOMBase_Skeleton::ActivateThisDialog();
421 globalSelection(); // close local contexts, if any
422 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE); //Select Faces on All Shapes
423 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
424 this, SLOT(SelectionIntoArgument()));
428 //=================================================================================
429 // function : enterEvent()
431 //=================================================================================
432 void BlocksGUI_BlockDlg::enterEvent (QEvent*)
434 if (!mainFrame()->GroupConstructors->isEnabled())
435 ActivateThisDialog();
438 //=================================================================================
439 // function : createOperation
441 //=================================================================================
442 GEOM::GEOM_IOperations_ptr BlocksGUI_BlockDlg::createOperation()
444 return getGeomEngine()->GetIBlocksOperations(getStudyId());
447 //=================================================================================
448 // function : isValid
450 //=================================================================================
451 bool BlocksGUI_BlockDlg::isValid (QString&)
454 switch (getConstructorId()) {
456 ok = !(myFace1->_is_nil() || myFace2->_is_nil());
459 ok = !(myFace1->_is_nil() || myFace2->_is_nil() ||
460 myFace3->_is_nil() || myFace4->_is_nil() ||
461 myFace5->_is_nil() || myFace6->_is_nil());
469 //=================================================================================
470 // function : execute
472 //=================================================================================
473 bool BlocksGUI_BlockDlg::execute (ObjectList& objects)
477 GEOM::GEOM_Object_var anObj;
479 switch (getConstructorId()) {
481 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2)) {
482 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
483 MakeHexa2Faces(myFace1, myFace2);
488 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2) &&
489 !CORBA::is_nil(myFace3) && !CORBA::is_nil(myFace4) &&
490 !CORBA::is_nil(myFace5) && !CORBA::is_nil(myFace6)) {
491 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
492 MakeHexa(myFace1, myFace2, myFace3, myFace4, myFace5, myFace6);
498 if (!anObj->_is_nil())
499 objects.push_back(anObj._retn());
504 //=================================================================================
505 // function : addSubshapesToStudy
506 // purpose : virtual method to add new SubObjects if local selection
507 //=================================================================================
508 void BlocksGUI_BlockDlg::addSubshapesToStudy()
510 QMap<QString, GEOM::GEOM_Object_var> objMap;
512 switch (getConstructorId()) {
514 objMap[Group2F->LineEdit1->text()] = myFace1;
515 objMap[Group2F->LineEdit2->text()] = myFace2;
518 objMap[Group6F->LineEdit1->text()] = myFace1;
519 objMap[Group6F->LineEdit2->text()] = myFace2;
520 objMap[Group6F->LineEdit3->text()] = myFace3;
521 objMap[Group6F->LineEdit4->text()] = myFace4;
522 objMap[Group6F->LineEdit5->text()] = myFace5;
523 objMap[Group6F->LineEdit6->text()] = myFace6;
526 addSubshapesToFather(objMap);