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
277 else // Global Selection
279 if (aShape.ShapeType() != TopAbs_FACE) {
280 aSelectedObject = GEOM::GEOM_Object::_nil();
286 myEditCurrentArgument->setText(aName);
288 if (myEditCurrentArgument == Group2F->LineEdit1) {
289 myFace1 = aSelectedObject;
290 if (!myFace1->_is_nil() && myFace2->_is_nil())
291 Group2F->PushButton2->click();
293 else if (myEditCurrentArgument == Group2F->LineEdit2) {
294 myFace2 = aSelectedObject;
295 if (!myFace2->_is_nil() && myFace1->_is_nil())
296 Group2F->PushButton1->click();
298 else if (myEditCurrentArgument == Group6F->LineEdit1) {
299 myFace1 = aSelectedObject;
300 if (!myFace1->_is_nil() && myFace2->_is_nil())
301 Group6F->PushButton2->click();
303 else if (myEditCurrentArgument == Group6F->LineEdit2) {
304 myFace2 = aSelectedObject;
305 if (!myFace2->_is_nil() && myFace3->_is_nil())
306 Group6F->PushButton3->click();
308 else if (myEditCurrentArgument == Group6F->LineEdit3) {
309 myFace3 = aSelectedObject;
310 if (!myFace3->_is_nil() && myFace4->_is_nil())
311 Group6F->PushButton4->click();
313 else if (myEditCurrentArgument == Group6F->LineEdit4) {
314 myFace4 = aSelectedObject;
315 if (!myFace4->_is_nil() && myFace5->_is_nil())
316 Group6F->PushButton5->click();
318 else if (myEditCurrentArgument == Group6F->LineEdit5) {
319 myFace5 = aSelectedObject;
320 if (!myFace5->_is_nil() && myFace6->_is_nil())
321 Group6F->PushButton6->click();
323 else if (myEditCurrentArgument == Group6F->LineEdit6) {
324 myFace6 = aSelectedObject;
325 if (!myFace6->_is_nil() && myFace1->_is_nil())
326 Group6F->PushButton1->click();
332 //=================================================================================
333 // function : SetEditCurrentArgument()
335 //=================================================================================
336 void BlocksGUI_BlockDlg::SetEditCurrentArgument()
338 QPushButton* aSender = (QPushButton*)sender();
341 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
345 myGeomGUI->getApp()->selectionMgr()->clearSelected();
348 switch (myConstructorId) {
350 Group2F->PushButton1->setDown(false);
351 Group2F->PushButton2->setDown(false);
353 Group2F->LineEdit1->setEnabled(false);
354 Group2F->LineEdit2->setEnabled(false);
357 Group6F->PushButton1->setDown(false);
358 Group6F->PushButton2->setDown(false);
359 Group6F->PushButton3->setDown(false);
360 Group6F->PushButton4->setDown(false);
361 Group6F->PushButton5->setDown(false);
362 Group6F->PushButton6->setDown(false);
364 Group6F->LineEdit1->setEnabled(false);
365 Group6F->LineEdit2->setEnabled(false);
366 Group6F->LineEdit3->setEnabled(false);
367 Group6F->LineEdit4->setEnabled(false);
368 Group6F->LineEdit5->setEnabled(false);
369 Group6F->LineEdit6->setEnabled(false);
375 // enable push button
376 aSender->setDown(true);
378 // set line edit as current argument
379 if (aSender == Group2F->PushButton1) {
380 myEditCurrentArgument = Group2F->LineEdit1;
382 else if (aSender == Group2F->PushButton2) {
383 myEditCurrentArgument = Group2F->LineEdit2;
385 else if (aSender == Group6F->PushButton1) {
386 myEditCurrentArgument = Group6F->LineEdit1;
388 else if (aSender == Group6F->PushButton2) {
389 myEditCurrentArgument = Group6F->LineEdit2;
391 else if (aSender == Group6F->PushButton3) {
392 myEditCurrentArgument = Group6F->LineEdit3;
394 else if (aSender == Group6F->PushButton4) {
395 myEditCurrentArgument = Group6F->LineEdit4;
397 else if (aSender == Group6F->PushButton5) {
398 myEditCurrentArgument = Group6F->LineEdit5;
400 else if (aSender == Group6F->PushButton6) {
401 myEditCurrentArgument = Group6F->LineEdit6;
405 myEditCurrentArgument->setEnabled(true);
406 myEditCurrentArgument->setFocus();
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()));
427 //=================================================================================
428 // function : enterEvent()
430 //=================================================================================
431 void BlocksGUI_BlockDlg::enterEvent (QEvent*)
433 if (!mainFrame()->GroupConstructors->isEnabled())
434 ActivateThisDialog();
437 //=================================================================================
438 // function : createOperation
440 //=================================================================================
441 GEOM::GEOM_IOperations_ptr BlocksGUI_BlockDlg::createOperation()
443 return getGeomEngine()->GetIBlocksOperations(getStudyId());
446 //=================================================================================
447 // function : isValid
449 //=================================================================================
450 bool BlocksGUI_BlockDlg::isValid (QString&)
453 switch (getConstructorId()) {
455 ok = !(myFace1->_is_nil() || myFace2->_is_nil());
458 ok = !(myFace1->_is_nil() || myFace2->_is_nil() ||
459 myFace3->_is_nil() || myFace4->_is_nil() ||
460 myFace5->_is_nil() || myFace6->_is_nil());
468 //=================================================================================
469 // function : execute
471 //=================================================================================
472 bool BlocksGUI_BlockDlg::execute (ObjectList& objects)
476 GEOM::GEOM_Object_var anObj;
478 switch (getConstructorId()) {
480 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2)) {
481 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
482 MakeHexa2Faces(myFace1, myFace2);
487 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2) &&
488 !CORBA::is_nil(myFace3) && !CORBA::is_nil(myFace4) &&
489 !CORBA::is_nil(myFace5) && !CORBA::is_nil(myFace6)) {
490 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
491 MakeHexa(myFace1, myFace2, myFace3, myFace4, myFace5, myFace6);
497 if (!anObj->_is_nil())
498 objects.push_back(anObj._retn());
503 //=================================================================================
504 // function : addSubshapeToStudy
505 // purpose : virtual method to add new SubObjects if local selection
506 //=================================================================================
507 void BlocksGUI_BlockDlg::addSubshapesToStudy()
509 QMap<QString, GEOM::GEOM_Object_var> objMap;
511 switch (getConstructorId()) {
513 objMap[Group2F->LineEdit1->text()] = myFace1;
514 objMap[Group2F->LineEdit2->text()] = myFace2;
517 objMap[Group6F->LineEdit1->text()] = myFace1;
518 objMap[Group6F->LineEdit2->text()] = myFace2;
519 objMap[Group6F->LineEdit3->text()] = myFace3;
520 objMap[Group6F->LineEdit4->text()] = myFace4;
521 objMap[Group6F->LineEdit5->text()] = myFace5;
522 objMap[Group6F->LineEdit6->text()] = myFace6;
525 addSubshapesToFather(objMap);