]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_PartitionDlg.cxx
Salome HOME
Fix bug 13058: 'Remove webs' functionality works incorrectly.
[modules/geom.git] / src / OperationGUI / OperationGUI_PartitionDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : OperationGUI_PartitionDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "OperationGUI_PartitionDlg.h"
30 #include "OperationGUI_MaterialDlg.h"
31
32 #include "GEOMImpl_Types.hxx"
33
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Session.h"
36 #include "SalomeApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
38
39 #include <qcheckbox.h>
40 #include <qcombobox.h>
41 #include <qlabel.h>
42
43 #include "utilities.h"
44
45 //=================================================================================
46 // class    : OperationGUI_PartitionDlg()
47 // purpose  : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the 
48 //            name 'name' and widget flags set to 'f'.
49 //            The dialog will by default be modeless, unless you set 'modal' to
50 //            TRUE to construct a modal dialog.
51 //=================================================================================
52 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg(GeometryGUI* theGeometryGUI, QWidget* parent)
53   :GEOMBase_Skeleton(theGeometryGUI, parent, "OperationGUI_PartitionDlg", false,
54                      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 {
56   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
57   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION")));
58   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION_PLANE")));
59   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
60
61   setCaption(tr("GEOM_PARTITION_TITLE"));
62
63   /***************************************************************/
64   GroupConstructors->setTitle(tr("GEOM_PARTITION"));
65   RadioButton1->setPixmap(image0);
66   RadioButton2->setPixmap(image1);
67   RadioButton3->close(TRUE);
68
69   // Full partition (contains half-space partition)
70   GroupPoints = new DlgRef_4Sel1List1Check_QTD(this, "GroupPoints");
71   GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
72   GroupPoints->GroupBox2->setTitle(tr("SUPPRESS_RESULT"));
73   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
74   GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
75   GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
76   GroupPoints->TextLabel4->setText(tr("GEOM_SUPPRESS_RESULT_INSIDE"));
77   GroupPoints->TextLabel5->setText(tr("GEOM_SUPPRESS_RESULT_OUTSIDE"));
78   GroupPoints->CheckBox1->setText(tr("GEOM_REMOVE_WEBS"));
79   GroupPoints->PushButton1->setPixmap(image2);
80   GroupPoints->PushButton2->setPixmap(image2);
81   GroupPoints->PushButton3->setPixmap(image2);
82   GroupPoints->PushButton4->setPixmap(image2);
83   GroupPoints->PushButton5->setText(tr("GEOM_SET_MATERIALS"));
84   GroupPoints->LineEdit1->setReadOnly( true );
85   GroupPoints->LineEdit2->setReadOnly( true );
86   GroupPoints->LineEdit3->setReadOnly( true );
87   GroupPoints->LineEdit4->setReadOnly( true );
88
89   Layout1->addWidget(GroupPoints, 2, 0);
90   /***************************************************************/
91
92   setHelpFileName("partition.htm"); 
93  
94   Init();
95 }
96
97
98 //=================================================================================
99 // function : ~OperationGUI_PartitionDlg()
100 // purpose  : Destroys the object and frees any allocated resources
101 //=================================================================================
102 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
103 {
104   // no need to delete child widgets, Qt does it all for us
105 }
106
107
108 //=================================================================================
109 // function : Init()
110 // purpose  :
111 //=================================================================================
112 void OperationGUI_PartitionDlg::Init()
113 {
114   /* type for sub shape selection */
115   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
116   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
117   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
118   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
119   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
120   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
121   
122   /* signals and slots connections */
123   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
126   
127   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130   connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131   connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetMaterials()));
132   
133   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135   connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136   connect(GroupPoints->LineEdit4, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137   
138   connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(onRemoveWebs(bool)));
139   
140   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
141   
142   connect(myGeomGUI->getApp()->selectionMgr(), 
143           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
144   
145   initName( tr( "GEOM_PARTITION" ) );
146   ConstructorsClicked( 0 );
147 }
148
149
150 //=================================================================================
151 // function : ConstructorsClicked()
152 // purpose  : Radio button management
153 //=================================================================================
154 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
155 {
156   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
157   globalSelection();
158   
159   myListShapes.length(0);
160   myListTools.length(0);  
161   myListKeepInside.length(0);
162   myListRemoveInside.length(0);
163   myListMaterials.length(0);
164   
165   switch (constructorId)
166     {
167     case 0: /*Full partition */
168       {
169         GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
170         GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
171         resize(0, 0);
172         GroupPoints->TextLabel3->show();
173         GroupPoints->ComboBox1->show();
174         GroupPoints->GroupBox2->show();
175         
176         GroupPoints->ComboBox1->setCurrentItem(0);
177         GroupPoints->LineEdit3->clear();
178         GroupPoints->LineEdit4->clear();
179         break;
180       }
181     case 1: /*Half-space partition */
182       {
183
184         GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
185         GroupPoints->GroupBox2->hide();
186         GroupPoints->TextLabel3->hide();
187         GroupPoints->ComboBox1->hide();
188         GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
189         resize(0, 0);
190         break;
191       } 
192     }
193
194   myEditCurrentArgument = GroupPoints->LineEdit1;
195   GroupPoints->LineEdit1->clear();
196   GroupPoints->LineEdit2->clear();
197   onRemoveWebs(false);
198
199   myEditCurrentArgument->setFocus();
200   connect(myGeomGUI->getApp()->selectionMgr(), 
201           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
202   MESSAGE(width()<<" "<<height());
203 }
204
205
206 //=================================================================================
207 // function : ClickOnOk()
208 // purpose  :
209 //=================================================================================
210 void OperationGUI_PartitionDlg::ClickOnOk()
211 {
212   if ( ClickOnApply() )
213     ClickOnCancel();
214 }
215
216
217 //=================================================================================
218 // function : ClickOnApply()
219 // purpose  :
220 //=================================================================================
221 bool OperationGUI_PartitionDlg::ClickOnApply()
222 {
223   if ( !onAccept() )
224     return false;
225   
226   initName();
227   ConstructorsClicked( getConstructorId() );
228   return true;
229 }
230
231
232 //=================================================================================
233 // function : SelectionIntoArgument()
234 // purpose  : Called when selection as changed or other case
235 //=================================================================================
236 void OperationGUI_PartitionDlg::SelectionIntoArgument()
237 {
238   myEditCurrentArgument->setText( "" );
239   QString aString = "";
240   
241   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
242     
243   if ( nbSel < 1 )
244   {
245     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
246     {
247       myListShapes.length( 0 );
248       myListMaterials.length( 0 );
249     }
250     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
251       myListTools.length( 0 );
252     else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
253       myListRemoveInside.length( 0 );
254     else if ( myEditCurrentArgument == GroupPoints->LineEdit4 )
255       myListKeepInside.length( 0 );
256   }
257   
258   // One and only one plane can be selected
259   
260   if ( getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel != 1 )
261   {
262     myListTools.length( 0 );
263     return;
264   }
265   
266   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
267   {
268     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListShapes, true );
269     myListMaterials.length( 0 );
270     if ( !myListShapes.length() )
271       return;
272   }
273   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
274   {
275     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListTools, true );
276     if ( !myListTools.length() )
277       return;
278   }
279   else if(myEditCurrentArgument == GroupPoints->LineEdit3)
280   {
281     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListRemoveInside, true );
282     if (!myListRemoveInside.length())
283       return;
284   }
285   else if(myEditCurrentArgument == GroupPoints->LineEdit4)
286   {
287     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(),  myListKeepInside, true );
288     if ( !myListKeepInside.length() )
289       return;
290   }
291   
292   myEditCurrentArgument->setText( aString );
293 }
294
295
296 //=================================================================================
297 // function : SetEditCurrentArgument()
298 // purpose  :
299 //=================================================================================
300 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
301 {
302   QPushButton* send = (QPushButton*)sender();
303   
304   if(send == GroupPoints->PushButton1) 
305     myEditCurrentArgument = GroupPoints->LineEdit1;
306   else if(send == GroupPoints->PushButton2)
307   {
308     myEditCurrentArgument = GroupPoints->LineEdit2;
309     if( getConstructorId()==1 )
310       globalSelection( GEOM_PLANE  );
311   }
312   else if(send == GroupPoints->PushButton3)
313     myEditCurrentArgument = GroupPoints->LineEdit3;
314   else if(send == GroupPoints->PushButton4)
315     myEditCurrentArgument = GroupPoints->LineEdit4;
316  
317   globalSelection( GEOM_ALLSHAPES );
318       
319   myEditCurrentArgument->setFocus();
320   SelectionIntoArgument();
321 }
322
323
324 //=================================================================================
325 // function : LineEditReturnPressed()
326 // purpose  :
327 //=================================================================================
328 void OperationGUI_PartitionDlg::LineEditReturnPressed()
329 {
330   QLineEdit* send = (QLineEdit*)sender();
331
332   if(send == GroupPoints->LineEdit1 || 
333      send == GroupPoints->LineEdit2 ||
334      send == GroupPoints->LineEdit3 ||
335      send == GroupPoints->LineEdit4 )
336     {
337       myEditCurrentArgument = send;
338       GEOMBase_Skeleton::LineEditReturnPressed();
339     }
340 }
341
342
343 //=================================================================================
344 // function : ActivateThisDialog()
345 // purpose  :
346 //=================================================================================
347 void OperationGUI_PartitionDlg::ActivateThisDialog()
348 {
349   GEOMBase_Skeleton::ActivateThisDialog();
350   connect(myGeomGUI->getApp()->selectionMgr(), 
351           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
352
353   ConstructorsClicked( getConstructorId() ); 
354 }
355
356
357 //=================================================================================
358 // function : enterEvent()
359 // purpose  :
360 //=================================================================================
361 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
362 {
363   if (!GroupConstructors->isEnabled())
364     this->ActivateThisDialog();
365 }
366
367
368 //=================================================================================
369 // function : createOperation
370 // purpose  :
371 //=================================================================================
372 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
373 {
374   return getGeomEngine()->GetIBooleanOperations( getStudyId() );
375 }
376
377
378 //=================================================================================
379 // function : isValid
380 // purpose  :
381 //=================================================================================
382 bool OperationGUI_PartitionDlg::isValid( QString& msg )
383 {
384   return (myListShapes.length()     || myListTools.length() ||
385           myListKeepInside.length() || myListRemoveInside.length());
386 }
387
388
389 //=================================================================================
390 // function : execute
391 // purpose  :
392 //=================================================================================
393 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
394 {
395   bool res = false;
396
397   GEOM::GEOM_Object_var anObj;
398   QString msg;
399
400   int aLimit = GetLimit();
401   int aConstructorId = getConstructorId();
402
403   if (aConstructorId == 1)
404     aLimit = GEOM::SHAPE;
405
406   if (isValid( msg )) {
407     if (aConstructorId == 0 && !toRemoveWebs())
408       myListMaterials.length(0);
409
410     anObj = GEOM::GEOM_IBooleanOperations::_narrow(getOperation())->
411       MakePartition(myListShapes, myListTools,
412                     myListKeepInside, myListRemoveInside,
413                     aLimit, toRemoveWebs(), myListMaterials);
414     res = true;
415   }
416
417   if (!anObj->_is_nil())
418     objects.push_back( anObj._retn() );
419
420   return res;
421 }
422
423
424 //=================================================================================
425 // function : closeEvent
426 // purpose  :
427 //=================================================================================
428 void OperationGUI_PartitionDlg::closeEvent( QCloseEvent* e )
429 {
430   GEOMBase_Skeleton::closeEvent( e );
431 }
432
433
434 //=======================================================================
435 //function : ComboTextChanged
436 //purpose  : 
437 //=======================================================================
438 void OperationGUI_PartitionDlg::ComboTextChanged()
439 {
440   bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
441   GroupPoints->LineEdit3->setEnabled(IsEnabled);
442   GroupPoints->LineEdit4->setEnabled(IsEnabled);
443   GroupPoints->TextLabel4->setEnabled(IsEnabled);
444   GroupPoints->TextLabel5->setEnabled(IsEnabled);
445   GroupPoints->PushButton3->setEnabled(IsEnabled);
446   GroupPoints->PushButton4->setEnabled(IsEnabled);
447 }
448
449
450 //=================================================================================
451 // function : SetMaterials()
452 // purpose  : 
453 //=================================================================================
454 void OperationGUI_PartitionDlg::SetMaterials()
455 {
456   OperationGUI_MaterialDlg* aDlg =
457     new OperationGUI_MaterialDlg(myGeomGUI, this, "", myListShapes, true);
458   aDlg->show();
459 }
460
461
462 //=================================================================================
463 // function : onRemoveWebs()
464 // purpose  : 
465 //=================================================================================
466 void OperationGUI_PartitionDlg::onRemoveWebs(bool isChecked)
467 {
468   if (GroupPoints->CheckBox1->isChecked() != isChecked)
469     GroupPoints->CheckBox1->setChecked(isChecked);
470   
471   GroupPoints->PushButton5->setEnabled(isChecked);
472 }
473
474
475 //=================================================================================
476 // function : toRemoveWebs()
477 // purpose  : 
478 //=================================================================================
479 bool OperationGUI_PartitionDlg::toRemoveWebs() const
480 {
481   return GroupPoints->CheckBox1->isChecked();
482 }
483
484
485 //=================================================================================
486 // function : GetLimit()
487 // purpose  : 
488 //=================================================================================
489 int OperationGUI_PartitionDlg::GetLimit() const
490 {
491   int aLimit = GroupPoints->ComboBox1->currentItem();
492
493   switch(aLimit)
494   {
495   case 0:  aLimit = GEOM::SOLID ; break;
496   case 1:  aLimit = GEOM::SHELL ; break;
497   case 2:  aLimit = GEOM::FACE  ; break;
498   case 3:  aLimit = GEOM::WIRE  ; break;
499   case 4:  aLimit = GEOM::EDGE  ; break;
500   case 5:  aLimit = GEOM::VERTEX; break;
501   default: aLimit = GEOM::SHAPE ;
502   }
503
504   return aLimit;
505 }