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