Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/geom.git] / src / BlocksGUI / BlocksGUI_BlockDlg.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.org
20 //
21 //
22 //
23 //  File   : BlocksGUI_BlockDlg.cxx
24 //  Author : Julia DOROVSKIKH
25 //  Module : GEOM
26 //  $Header$
27
28 #include "BlocksGUI_BlockDlg.h"
29
30 #include "SUIT_Session.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33
34 #include "GEOMImpl_Types.hxx"
35
36 using namespace std;
37
38 #include <qlabel.h>
39
40 //=================================================================================
41 // class    : BlocksGUI_BlockDlg()
42 // purpose  : Constructs a BlocksGUI_BlockDlg which is a child of 'parent'.
43 //=================================================================================
44 BlocksGUI_BlockDlg::BlocksGUI_BlockDlg (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal)
45      : GEOMBase_Skeleton(theGeometryGUI, parent, "BlockDlg", modal,
46                          WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
47 {
48   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_2F")));
49   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_6F")));
50   QPixmap imageS (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
51
52   setCaption(tr("GEOM_BLOCK_TITLE"));
53
54   /***************************************************************/
55   GroupConstructors->setTitle(tr("GEOM_BLOCK"));
56
57   RadioButton1->setPixmap(image0);
58   RadioButton2->setPixmap(image1);
59   RadioButton3->close(TRUE);
60
61   // Create first group
62   Group2F = new DlgRef_2Sel_QTD(this, "Group2F");
63   Group2F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64   Group2F->TextLabel1->setText(tr("FACE_1"));
65   Group2F->TextLabel2->setText(tr("FACE_2"));
66   Group2F->PushButton1->setPixmap(imageS);
67   Group2F->PushButton2->setPixmap(imageS);
68
69   // Create second group
70   Group6F = new DlgRef_6Sel_QTD(this, "Group2F");
71   Group6F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72   Group6F->TextLabel1->setText(tr("FACE_1"));
73   Group6F->TextLabel2->setText(tr("FACE_2"));
74   Group6F->TextLabel3->setText(tr("FACE_3"));
75   Group6F->TextLabel4->setText(tr("FACE_4"));
76   Group6F->TextLabel5->setText(tr("FACE_5"));
77   Group6F->TextLabel6->setText(tr("FACE_6"));
78   Group6F->PushButton1->setPixmap(imageS);
79   Group6F->PushButton2->setPixmap(imageS);
80   Group6F->PushButton3->setPixmap(imageS);
81   Group6F->PushButton4->setPixmap(imageS);
82   Group6F->PushButton5->setPixmap(imageS);
83   Group6F->PushButton6->setPixmap(imageS);
84
85   // Add groups to layout
86   Layout1->addWidget(Group2F, 2, 0);
87   Layout1->addWidget(Group6F, 2, 0);
88   /***************************************************************/
89
90   setHelpFileName("newentity_blocks.htm#HexahedralSolid");
91
92   Init();
93 }
94
95 //=================================================================================
96 // function : ~BlocksGUI_BlockDlg()
97 // purpose  : Destroys the object and frees any allocated resources
98 //=================================================================================
99 BlocksGUI_BlockDlg::~BlocksGUI_BlockDlg()
100 {
101   // no need to delete child widgets, Qt does it all for us
102 }
103
104 //=================================================================================
105 // function : Init()
106 // purpose  :
107 //=================================================================================
108 void BlocksGUI_BlockDlg::Init()
109 {
110   // init variables
111   Group2F->LineEdit1->setReadOnly(true);
112   Group2F->LineEdit2->setReadOnly(true);
113
114   Group6F->LineEdit1->setReadOnly(true);
115   Group6F->LineEdit2->setReadOnly(true);
116   Group6F->LineEdit3->setReadOnly(true);
117   Group6F->LineEdit4->setReadOnly(true);
118   Group6F->LineEdit5->setReadOnly(true);
119   Group6F->LineEdit6->setReadOnly(true);
120
121   // signals and slots connections
122   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
125
126   connect(Group2F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127   connect(Group2F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128
129   connect(Group6F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130   connect(Group6F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131   connect(Group6F->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132   connect(Group6F->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133   connect(Group6F->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134   connect(Group6F->PushButton6, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135
136   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
137           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
138
139   // init controls and fields
140   initName(tr("GEOM_BLOCK"));
141
142   myConstructorId = -1;
143   ConstructorsClicked(0);
144 }
145
146 //=================================================================================
147 // function : ConstructorsClicked()
148 // purpose  : Radio button management
149 //=================================================================================
150 void BlocksGUI_BlockDlg::ConstructorsClicked (int constructorId)
151 {
152   if (myConstructorId == constructorId)
153     return;
154
155   myConstructorId = constructorId;
156
157   switch (constructorId) {
158   case 0:
159     Group6F->hide();
160     resize(0, 0);
161     Group2F->show();
162
163     myEditCurrentArgument = Group2F->LineEdit1;
164     Group2F->LineEdit1->setText(tr(""));
165     Group2F->LineEdit2->setText(tr(""));
166     break;
167   case 1:
168     Group2F->hide();
169     resize(0, 0);
170     Group6F->show();
171
172     myEditCurrentArgument = Group6F->LineEdit1;
173     Group6F->LineEdit1->setText(tr(""));
174     Group6F->LineEdit2->setText(tr(""));
175     Group6F->LineEdit3->setText(tr(""));
176     Group6F->LineEdit4->setText(tr(""));
177     Group6F->LineEdit5->setText(tr(""));
178     Group6F->LineEdit6->setText(tr(""));
179     break;
180   default:
181     break;
182   }
183
184   // init fields
185   myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
186   myFace3 = myFace4 = myFace5 = myFace6 = myFace1;
187
188   globalSelection(GEOM_FACE);
189   SelectionIntoArgument();
190   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
191           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
192 }
193
194 //=================================================================================
195 // function : ClickOnOk()
196 // purpose  :
197 //=================================================================================
198 void BlocksGUI_BlockDlg::ClickOnOk()
199 {
200   if (ClickOnApply())
201     ClickOnCancel();
202 }
203
204 //=================================================================================
205 // function : ClickOnApply()
206 // purpose  :
207 //=================================================================================
208 bool BlocksGUI_BlockDlg::ClickOnApply()
209 {
210   if (!onAccept())
211     return false;
212
213   initName();
214   return true;
215 }
216
217 //=================================================================================
218 // function : SelectionIntoArgument()
219 // purpose  : Called when selection as changed or other case
220 //=================================================================================
221 void BlocksGUI_BlockDlg::SelectionIntoArgument()
222 {
223   erasePreview();
224   myEditCurrentArgument->setText("");
225
226   if (IObjectCount() != 1)
227   {
228     if (myEditCurrentArgument == Group2F->LineEdit1 ||
229         myEditCurrentArgument == Group6F->LineEdit1)
230       myFace1 = GEOM::GEOM_Object::_nil();
231     else if (myEditCurrentArgument == Group2F->LineEdit2 ||
232              myEditCurrentArgument == Group6F->LineEdit2)
233       myFace2 = GEOM::GEOM_Object::_nil();
234     else if (myEditCurrentArgument == Group6F->LineEdit3)
235       myFace3 = GEOM::GEOM_Object::_nil();
236     else if (myEditCurrentArgument == Group6F->LineEdit4)
237       myFace4 = GEOM::GEOM_Object::_nil();
238     else if (myEditCurrentArgument == Group6F->LineEdit5)
239       myFace5 = GEOM::GEOM_Object::_nil();
240     else if (myEditCurrentArgument == Group6F->LineEdit6)
241       myFace6 = GEOM::GEOM_Object::_nil();
242     return;
243   }
244
245   // nbSel == 1
246   Standard_Boolean testResult = Standard_False;
247   GEOM::GEOM_Object_var aSelectedObject =
248     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
249
250   if (!testResult || CORBA::is_nil( aSelectedObject ))
251     return;
252
253   if (myEditCurrentArgument == Group2F->LineEdit1 ||
254       myEditCurrentArgument == Group6F->LineEdit1)
255     myFace1 = aSelectedObject;
256   else if (myEditCurrentArgument == Group2F->LineEdit2 ||
257            myEditCurrentArgument == Group6F->LineEdit2)
258     myFace2 = aSelectedObject;
259   else if (myEditCurrentArgument == Group6F->LineEdit3)
260     myFace3 = aSelectedObject;
261   else if (myEditCurrentArgument == Group6F->LineEdit4)
262     myFace4 = aSelectedObject;
263   else if (myEditCurrentArgument == Group6F->LineEdit5)
264     myFace5 = aSelectedObject;
265   else if (myEditCurrentArgument == Group6F->LineEdit6)
266     myFace6 = aSelectedObject;
267
268   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
269
270   displayPreview();
271 }
272
273 //=================================================================================
274 // function : SetEditCurrentArgument()
275 // purpose  :
276 //=================================================================================
277 void BlocksGUI_BlockDlg::SetEditCurrentArgument()
278 {
279   QPushButton* aSender = (QPushButton*)sender();
280
281   if (aSender == Group2F->PushButton1) {
282     myEditCurrentArgument = Group2F->LineEdit1;
283   } else if (aSender == Group2F->PushButton2) {
284     myEditCurrentArgument = Group2F->LineEdit2;
285
286   } else if (aSender == Group6F->PushButton1) {
287     myEditCurrentArgument = Group6F->LineEdit1;
288   } else if (aSender == Group6F->PushButton2) {
289     myEditCurrentArgument = Group6F->LineEdit2;
290   } else if (aSender == Group6F->PushButton3) {
291     myEditCurrentArgument = Group6F->LineEdit3;
292   } else if (aSender == Group6F->PushButton4) {
293     myEditCurrentArgument = Group6F->LineEdit4;
294   } else if (aSender == Group6F->PushButton5) {
295     myEditCurrentArgument = Group6F->LineEdit5;
296   } else if (aSender == Group6F->PushButton6) {
297     myEditCurrentArgument = Group6F->LineEdit6;
298   }
299
300   globalSelection(GEOM_FACE);
301
302   myEditCurrentArgument->setFocus();
303   SelectionIntoArgument();
304 }
305
306 //=================================================================================
307 // function : ActivateThisDialog()
308 // purpose  :
309 //=================================================================================
310 void BlocksGUI_BlockDlg::ActivateThisDialog()
311 {
312   GEOMBase_Skeleton::ActivateThisDialog();
313   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
314           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315
316   globalSelection(GEOM_FACE);
317
318   SelectionIntoArgument();
319 }
320
321 //=================================================================================
322 // function : enterEvent()
323 // purpose  :
324 //=================================================================================
325 void BlocksGUI_BlockDlg::enterEvent (QEvent* e)
326 {
327   if (!GroupConstructors->isEnabled())
328     ActivateThisDialog();
329 }
330
331 //=================================================================================
332 // function : createOperation
333 // purpose  :
334 //=================================================================================
335 GEOM::GEOM_IOperations_ptr BlocksGUI_BlockDlg::createOperation()
336 {
337   return getGeomEngine()->GetIBlocksOperations(getStudyId());
338 }
339
340 //=================================================================================
341 // function : isValid
342 // purpose  :
343 //=================================================================================
344 bool BlocksGUI_BlockDlg::isValid (QString&)
345 {
346   switch (getConstructorId()) {
347     case 0:
348       return !(myFace1->_is_nil() || myFace2->_is_nil());
349     case 1:
350       return !(myFace1->_is_nil() || myFace2->_is_nil() ||
351                myFace3->_is_nil() || myFace4->_is_nil() ||
352                myFace5->_is_nil() || myFace6->_is_nil());
353     default:
354       return false;
355   }
356   return false;
357 }
358
359 //=================================================================================
360 // function : execute
361 // purpose  :
362 //=================================================================================
363 bool BlocksGUI_BlockDlg::execute (ObjectList& objects)
364 {
365   bool res = false;
366
367   GEOM::GEOM_Object_var anObj;
368
369   switch (getConstructorId()) {
370     case 0:
371       if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2)) {
372         anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
373           MakeHexa2Faces(myFace1, myFace2);
374         res = true;
375       }
376       break;
377     case 1:
378       if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2) &&
379           !CORBA::is_nil(myFace3) && !CORBA::is_nil(myFace4) &&
380           !CORBA::is_nil(myFace5) && !CORBA::is_nil(myFace6)) {
381         anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
382           MakeHexa(myFace1, myFace2, myFace3, myFace4, myFace5, myFace6);
383         res = true;
384       }
385       break;
386   }
387
388   if (!anObj->_is_nil())
389     objects.push_back(anObj._retn());
390
391   return res;
392 }