]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_PartitionDlg.cxx
Salome HOME
IPAL20715 impossible to select sub-shape after apply group
[modules/geom.git] / src / OperationGUI / OperationGUI_PartitionDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : OperationGUI_PartitionDlg.cxx
24 //  Author : Lucien PIGNOLONI
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "OperationGUI_PartitionDlg.h"
29
30 #include "GEOMImpl_Types.hxx"
31
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36
37 #include <qcheckbox.h>
38 #include <qradiobutton.h>
39 #include <qcombobox.h>
40 #include <qlabel.h>
41
42 #include "utilities.h"
43
44 //=================================================================================
45 // class    : OperationGUI_PartitionDlg()
46 // purpose  : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg(GeometryGUI* theGeometryGUI, QWidget* parent)
52   :GEOMBase_Skeleton(theGeometryGUI, parent, "OperationGUI_PartitionDlg", false,
53                      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 {
55   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
56   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION")));
57   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION_PLANE")));
58   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
59
60   setCaption(tr("GEOM_PARTITION_TITLE"));
61
62   /***************************************************************/
63   GroupConstructors->setTitle(tr("GEOM_PARTITION"));
64   RadioButton1->setPixmap(image0);
65   RadioButton2->setPixmap(image1);
66   RadioButton3->close(TRUE);
67
68   // Full partition (contains half-space partition)
69   GroupPoints = new DlgRef_2Sel1List1Check_QTD(this, "GroupPoints");
70   GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
71   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
72   GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
73   GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
74   GroupPoints->PushButton1->setPixmap(image2);
75   GroupPoints->PushButton2->setPixmap(image2);
76   GroupPoints->LineEdit1->setReadOnly( true );
77   GroupPoints->LineEdit2->setReadOnly( true );
78   GroupPoints->radioButton4->setText(tr("GEOM_KEEP_NONLIMIT_SHAPES"));
79
80   Layout1->addWidget(GroupPoints, 2, 0);
81   /***************************************************************/
82
83   setHelpFileName("partition_page.html");
84
85   Init();
86 }
87
88
89 //=================================================================================
90 // function : ~OperationGUI_PartitionDlg()
91 // purpose  : Destroys the object and frees any allocated resources
92 //=================================================================================
93 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
94 {
95   // no need to delete child widgets, Qt does it all for us
96 }
97
98
99 //=================================================================================
100 // function : Init()
101 // purpose  :
102 //=================================================================================
103 void OperationGUI_PartitionDlg::Init()
104 {
105   /* type for sub shape selection */
106   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
107   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
108   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
109   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
110   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
111   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
112   GroupPoints->radioButton4->setChecked(FALSE);
113
114   GroupBoxPublish->show();
115
116   /* signals and slots connections */
117   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
119   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
120
121   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123
124   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126
127   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
128
129   connect(myGeomGUI->getApp()->selectionMgr(),
130           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
131
132   initName( tr( "GEOM_PARTITION" ) );
133   ConstructorsClicked( 0 );
134 }
135
136
137 //=================================================================================
138 // function : ConstructorsClicked()
139 // purpose  : Radio button management
140 //=================================================================================
141 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
142 {
143   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
144   globalSelection();
145
146   myListShapes.length(0);
147   myListTools.length(0);
148   myListKeepInside.length(0);
149   myListRemoveInside.length(0);
150   myListMaterials.length(0);
151
152   switch (constructorId)
153     {
154     case 0: /*Full partition */
155       {
156         GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
157         GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
158         resize(0, 0);
159         GroupPoints->TextLabel3->show();
160         GroupPoints->ComboBox1->show();
161         GroupPoints->ComboBox1->setCurrentItem(0);
162         GroupPoints->radioButton4->show();
163         break;
164       }
165     case 1: /*Half-space partition */
166       {
167
168         GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
169         GroupPoints->TextLabel3->hide();
170         GroupPoints->ComboBox1->hide();
171         GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
172         GroupPoints->radioButton4->hide();
173         resize(0, 0);
174         break;
175       }
176     }
177
178   myEditCurrentArgument = GroupPoints->LineEdit1;
179   GroupPoints->LineEdit1->clear();
180   GroupPoints->LineEdit2->clear();
181
182   myEditCurrentArgument->setFocus();
183   connect(myGeomGUI->getApp()->selectionMgr(),
184           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185   MESSAGE(width()<<" "<<height());
186 }
187
188
189 //=================================================================================
190 // function : ClickOnOk()
191 // purpose  :
192 //=================================================================================
193 void OperationGUI_PartitionDlg::ClickOnOk()
194 {
195   if ( ClickOnApply() )
196     ClickOnCancel();
197 }
198
199
200 //=================================================================================
201 // function : ClickOnApply()
202 // purpose  :
203 //=================================================================================
204 bool OperationGUI_PartitionDlg::ClickOnApply()
205 {
206   if (!onAccept())
207     return false;
208
209   initName();
210   ConstructorsClicked( getConstructorId() );
211   return true;
212 }
213
214
215 //=================================================================================
216 // function : SelectionIntoArgument()
217 // purpose  : Called when selection as changed or other case
218 //=================================================================================
219 void OperationGUI_PartitionDlg::SelectionIntoArgument()
220 {
221   myEditCurrentArgument->setText( "" );
222   QString aString = "";
223
224   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
225
226   if ( nbSel < 1 )
227   {
228     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
229     {
230       myListShapes.length( 0 );
231       myListMaterials.length( 0 );
232     }
233     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
234       myListTools.length( 0 );
235   }
236
237   // One and only one plane can be selected
238
239   if ( getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel != 1 )
240   {
241     myListTools.length( 0 );
242     return;
243   }
244
245   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
246   {
247     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListShapes, true );
248     myListMaterials.length( 0 );
249     if ( !myListShapes.length() )
250       return;
251   }
252   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
253   {
254     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListTools, true );
255     if ( !myListTools.length() )
256       return;
257   }
258
259   myEditCurrentArgument->setText( aString );
260 }
261
262
263 //=================================================================================
264 // function : SetEditCurrentArgument()
265 // purpose  :
266 //=================================================================================
267 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
268 {
269   QPushButton* send = (QPushButton*)sender();
270
271   if(send == GroupPoints->PushButton1)
272     myEditCurrentArgument = GroupPoints->LineEdit1;
273   else if(send == GroupPoints->PushButton2)
274   {
275     myEditCurrentArgument = GroupPoints->LineEdit2;
276     if( getConstructorId()==1 )
277       globalSelection( GEOM_PLANE  );
278   }
279
280   globalSelection( GEOM_ALLSHAPES );
281
282   myEditCurrentArgument->setFocus();
283   SelectionIntoArgument();
284 }
285
286
287 //=================================================================================
288 // function : LineEditReturnPressed()
289 // purpose  :
290 //=================================================================================
291 void OperationGUI_PartitionDlg::LineEditReturnPressed()
292 {
293   QLineEdit* send = (QLineEdit*)sender();
294
295   if(send == GroupPoints->LineEdit1 ||
296      send == GroupPoints->LineEdit2 )
297     {
298       myEditCurrentArgument = send;
299       GEOMBase_Skeleton::LineEditReturnPressed();
300     }
301 }
302
303
304 //=================================================================================
305 // function : ActivateThisDialog()
306 // purpose  :
307 //=================================================================================
308 void OperationGUI_PartitionDlg::ActivateThisDialog()
309 {
310   GEOMBase_Skeleton::ActivateThisDialog();
311   connect(myGeomGUI->getApp()->selectionMgr(),
312           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
313
314   ConstructorsClicked( getConstructorId() );
315 }
316
317
318 //=================================================================================
319 // function : enterEvent()
320 // purpose  :
321 //=================================================================================
322 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
323 {
324   if (!GroupConstructors->isEnabled())
325     this->ActivateThisDialog();
326 }
327
328
329 //=================================================================================
330 // function : createOperation
331 // purpose  :
332 //=================================================================================
333 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
334 {
335   return getGeomEngine()->GetIBooleanOperations( getStudyId() );
336 }
337
338
339 //=================================================================================
340 // function : isValid
341 // purpose  :
342 //=================================================================================
343 bool OperationGUI_PartitionDlg::isValid( QString& msg )
344 {
345   return (myListShapes.length()     || myListTools.length() ||
346           myListKeepInside.length() || myListRemoveInside.length());
347 }
348
349
350 //=================================================================================
351 // function : execute
352 // purpose  :
353 //=================================================================================
354 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
355 {
356   bool res = false;
357
358   GEOM::GEOM_Object_var anObj;
359   QString msg;
360
361   int aLimit = GetLimit();
362   int aConstructorId = getConstructorId();
363
364   int aKeepNonlimitShapes = 0;
365   if (aConstructorId == 1) {
366     aLimit = GEOM::SHAPE;
367   }
368   else {
369     if(GroupPoints->radioButton4->isChecked()) {
370       aKeepNonlimitShapes = 1;
371     }
372     else {
373       aKeepNonlimitShapes = 0;
374     }
375   }
376
377   if (isValid( msg )) {
378
379     anObj = GEOM::GEOM_IBooleanOperations::_narrow(getOperation())->
380       MakePartition(myListShapes, myListTools,
381                     myListKeepInside, myListRemoveInside,
382                     aLimit, false, myListMaterials, aKeepNonlimitShapes);
383     res = true;
384   }
385
386   if (!anObj->_is_nil())
387     objects.push_back( anObj._retn() );
388
389   return res;
390 }
391
392 //=================================================================================
393 // function : restoreSubShapes
394 // purpose  :
395 //=================================================================================
396 void OperationGUI_PartitionDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
397                                                   SALOMEDS::SObject_ptr theSObject)
398 {
399   if (CheckBoxRestoreSS->isChecked()) {
400     // empty list of arguments means that all arguments should be restored
401     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
402                                         /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
403                                         /*theInheritFirstArg=*/myListShapes.length() == 1); // ? false
404   }
405 }
406
407 //=======================================================================
408 //function : ComboTextChanged
409 //purpose  :
410 //=======================================================================
411 void OperationGUI_PartitionDlg::ComboTextChanged()
412 {
413   bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
414   //GroupPoints->LineEdit3->setEnabled(IsEnabled);
415   //GroupPoints->LineEdit4->setEnabled(IsEnabled);
416   //GroupPoints->TextLabel4->setEnabled(IsEnabled);
417   //GroupPoints->TextLabel5->setEnabled(IsEnabled);
418   //GroupPoints->PushButton3->setEnabled(IsEnabled);
419   //GroupPoints->PushButton4->setEnabled(IsEnabled);
420 }
421
422 //=================================================================================
423 // function : GetLimit()
424 // purpose  :
425 //=================================================================================
426 int OperationGUI_PartitionDlg::GetLimit() const
427 {
428   int aLimit = GroupPoints->ComboBox1->currentItem();
429
430   switch (aLimit)
431   {
432   case 0:  aLimit = GEOM::SOLID ; break;
433   case 1:  aLimit = GEOM::SHELL ; break;
434   case 2:  aLimit = GEOM::FACE  ; break;
435   case 3:  aLimit = GEOM::WIRE  ; break;
436   case 4:  aLimit = GEOM::EDGE  ; break;
437   case 5:  aLimit = GEOM::VERTEX; break;
438   default: aLimit = GEOM::SHAPE ;
439   }
440
441   return aLimit;
442 }