Salome HOME
NPAL17431: About WhatIs dialog box. Set font-dependent height.
[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_2Sel1List1Check_QTD(this, "GroupPoints");
71   GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
72   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
73   GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
74   GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
75   GroupPoints->PushButton1->setPixmap(image2);
76   GroupPoints->PushButton2->setPixmap(image2);
77   GroupPoints->LineEdit1->setReadOnly( true );
78   GroupPoints->LineEdit2->setReadOnly( true );
79   GroupPoints->radioButton4->setText(tr("GEOM_KEEP_NONLIMIT_SHAPES"));
80
81   Layout1->addWidget(GroupPoints, 2, 0);
82   /***************************************************************/
83
84   setHelpFileName("partition.htm"); 
85  
86   Init();
87 }
88
89
90 //=================================================================================
91 // function : ~OperationGUI_PartitionDlg()
92 // purpose  : Destroys the object and frees any allocated resources
93 //=================================================================================
94 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
95 {
96   // no need to delete child widgets, Qt does it all for us
97 }
98
99
100 //=================================================================================
101 // function : Init()
102 // purpose  :
103 //=================================================================================
104 void OperationGUI_PartitionDlg::Init()
105 {
106   /* type for sub shape selection */
107   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
108   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
109   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
110   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
111   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
112   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
113   GroupPoints->radioButton4->setChecked(FALSE);
114   
115   /* signals and slots connections */
116   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
117   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
118   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
119   
120   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122   
123   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125   
126   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
127   
128   connect(GroupPoints->radioButton4, SIGNAL(stateChanged(int)), this, SLOT(ReverseSense(int)));
129
130   connect(myGeomGUI->getApp()->selectionMgr(), 
131           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
132   
133   initName( tr( "GEOM_PARTITION" ) );
134   ConstructorsClicked( 0 );
135 }
136
137
138 //=================================================================================
139 // function : ConstructorsClicked()
140 // purpose  : Radio button management
141 //=================================================================================
142 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
143 {
144   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
145   globalSelection();
146   
147   myListShapes.length(0);
148   myListTools.length(0);  
149   myListKeepInside.length(0);
150   myListRemoveInside.length(0);
151   myListMaterials.length(0);
152
153   switch (constructorId)
154     {
155     case 0: /*Full partition */
156       {
157         GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
158         GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
159         resize(0, 0);
160         GroupPoints->TextLabel3->show();
161         GroupPoints->ComboBox1->show();
162         GroupPoints->ComboBox1->setCurrentItem(0);
163         GroupPoints->radioButton4->show();
164         break;
165       }
166     case 1: /*Half-space partition */
167       {
168
169         GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
170         GroupPoints->TextLabel3->hide();
171         GroupPoints->ComboBox1->hide();
172         GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
173         GroupPoints->radioButton4->hide();
174         resize(0, 0);
175         break;
176       } 
177     }
178
179   myEditCurrentArgument = GroupPoints->LineEdit1;
180   GroupPoints->LineEdit1->clear();
181   GroupPoints->LineEdit2->clear();
182
183   myEditCurrentArgument->setFocus();
184   connect(myGeomGUI->getApp()->selectionMgr(), 
185           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
186   MESSAGE(width()<<" "<<height());
187 }
188
189
190 //=================================================================================
191 // function : ClickOnOk()
192 // purpose  :
193 //=================================================================================
194 void OperationGUI_PartitionDlg::ClickOnOk()
195 {
196   if ( ClickOnApply() )
197     ClickOnCancel();
198 }
199
200
201 //=================================================================================
202 // function : ClickOnApply()
203 // purpose  :
204 //=================================================================================
205 bool OperationGUI_PartitionDlg::ClickOnApply()
206 {
207   if ( !onAccept() )
208     return false;
209   
210   initName();
211   ConstructorsClicked( getConstructorId() );
212   return true;
213 }
214
215
216 //=================================================================================
217 // function : SelectionIntoArgument()
218 // purpose  : Called when selection as changed or other case
219 //=================================================================================
220 void OperationGUI_PartitionDlg::SelectionIntoArgument()
221 {
222   myEditCurrentArgument->setText( "" );
223   QString aString = "";
224   
225   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
226     
227   if ( nbSel < 1 )
228   {
229     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
230     {
231       myListShapes.length( 0 );
232       myListMaterials.length( 0 );
233     }
234     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
235       myListTools.length( 0 );
236   }
237   
238   // One and only one plane can be selected
239   
240   if ( getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel != 1 )
241   {
242     myListTools.length( 0 );
243     return;
244   }
245   
246   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
247   {
248     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListShapes, true );
249     myListMaterials.length( 0 );
250     if ( !myListShapes.length() )
251       return;
252   }
253   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
254   {
255     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListTools, true );
256     if ( !myListTools.length() )
257       return;
258   }
259   
260   myEditCurrentArgument->setText( aString );
261 }
262
263
264 //=================================================================================
265 // function : SetEditCurrentArgument()
266 // purpose  :
267 //=================================================================================
268 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
269 {
270   QPushButton* send = (QPushButton*)sender();
271   
272   if(send == GroupPoints->PushButton1) 
273     myEditCurrentArgument = GroupPoints->LineEdit1;
274   else if(send == GroupPoints->PushButton2)
275   {
276     myEditCurrentArgument = GroupPoints->LineEdit2;
277     if( getConstructorId()==1 )
278       globalSelection( GEOM_PLANE  );
279   }
280  
281   globalSelection( GEOM_ALLSHAPES );
282       
283   myEditCurrentArgument->setFocus();
284   SelectionIntoArgument();
285 }
286
287
288 //=================================================================================
289 // function : LineEditReturnPressed()
290 // purpose  :
291 //=================================================================================
292 void OperationGUI_PartitionDlg::LineEditReturnPressed()
293 {
294   QLineEdit* send = (QLineEdit*)sender();
295
296   if(send == GroupPoints->LineEdit1 || 
297      send == GroupPoints->LineEdit2 )
298     {
299       myEditCurrentArgument = send;
300       GEOMBase_Skeleton::LineEditReturnPressed();
301     }
302 }
303
304
305 //=================================================================================
306 // function : ActivateThisDialog()
307 // purpose  :
308 //=================================================================================
309 void OperationGUI_PartitionDlg::ActivateThisDialog()
310 {
311   GEOMBase_Skeleton::ActivateThisDialog();
312   connect(myGeomGUI->getApp()->selectionMgr(), 
313           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
314
315   ConstructorsClicked( getConstructorId() ); 
316 }
317
318
319 //=================================================================================
320 // function : enterEvent()
321 // purpose  :
322 //=================================================================================
323 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
324 {
325   if (!GroupConstructors->isEnabled())
326     this->ActivateThisDialog();
327 }
328
329
330 //=================================================================================
331 // function : createOperation
332 // purpose  :
333 //=================================================================================
334 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
335 {
336   return getGeomEngine()->GetIBooleanOperations( getStudyId() );
337 }
338
339
340 //=================================================================================
341 // function : isValid
342 // purpose  :
343 //=================================================================================
344 bool OperationGUI_PartitionDlg::isValid( QString& msg )
345 {
346   return (myListShapes.length()     || myListTools.length() ||
347           myListKeepInside.length() || myListRemoveInside.length());
348 }
349
350
351 //=================================================================================
352 // function : execute
353 // purpose  :
354 //=================================================================================
355 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
356 {
357   bool res = false;
358
359   GEOM::GEOM_Object_var anObj;
360   QString msg;
361
362   int aLimit = GetLimit();
363   int aConstructorId = getConstructorId();
364
365   int aKeepNonlimitShapes = 0;
366   if (aConstructorId == 1) {
367     aLimit = GEOM::SHAPE;
368   }
369   else {
370     if(GroupPoints->radioButton4->isChecked()) {
371       aKeepNonlimitShapes = 1;
372     }
373     else {
374       aKeepNonlimitShapes = 0;
375     }
376   }
377
378   if (isValid( msg )) {
379
380     anObj = GEOM::GEOM_IBooleanOperations::_narrow(getOperation())->
381       MakePartition(myListShapes, myListTools,
382                     myListKeepInside, myListRemoveInside,
383                     aLimit, false, myListMaterials, aKeepNonlimitShapes);
384     res = true;
385   }
386
387   if (!anObj->_is_nil())
388     objects.push_back( anObj._retn() );
389
390   return res;
391 }
392
393
394 //=================================================================================
395 // function : closeEvent
396 // purpose  :
397 //=================================================================================
398 void OperationGUI_PartitionDlg::closeEvent( QCloseEvent* e )
399 {
400   GEOMBase_Skeleton::closeEvent( e );
401 }
402
403
404 //=======================================================================
405 //function : ComboTextChanged
406 //purpose  : 
407 //=======================================================================
408 void OperationGUI_PartitionDlg::ComboTextChanged()
409 {
410   bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
411   //GroupPoints->LineEdit3->setEnabled(IsEnabled);
412   //GroupPoints->LineEdit4->setEnabled(IsEnabled);
413   //GroupPoints->TextLabel4->setEnabled(IsEnabled);
414   //GroupPoints->TextLabel5->setEnabled(IsEnabled);
415   //GroupPoints->PushButton3->setEnabled(IsEnabled);
416   //GroupPoints->PushButton4->setEnabled(IsEnabled);
417 }
418
419
420 //=================================================================================
421 // function : GetLimit()
422 // purpose  : 
423 //=================================================================================
424 int OperationGUI_PartitionDlg::GetLimit() const
425 {
426   int aLimit = GroupPoints->ComboBox1->currentItem();
427
428   switch(aLimit)
429   {
430   case 0:  aLimit = GEOM::SOLID ; break;
431   case 1:  aLimit = GEOM::SHELL ; break;
432   case 2:  aLimit = GEOM::FACE  ; break;
433   case 3:  aLimit = GEOM::WIRE  ; break;
434   case 4:  aLimit = GEOM::EDGE  ; break;
435   case 5:  aLimit = GEOM::VERTEX; break;
436   default: aLimit = GEOM::SHAPE ;
437   }
438
439   return aLimit;
440 }