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