]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_RemoveHolesDlg.cxx
Salome HOME
Fix issue 0020479: EDF 1116 GEOM: Create a group, "Add" button is inactive but "Selec...
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveHolesDlg.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   : RepairGUI_RemoveHolesDlg.cxx
24 //  Author : Lucien PIGNOLONI
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "RepairGUI_RemoveHolesDlg.h"
29
30 #include "SalomeApp_Application.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SUIT_MessageBox.h"
33 #include "SUIT_Session.h"
34
35 #include "SALOME_ListIteratorOfListIO.hxx"
36
37 #include "GEOMImpl_Types.hxx"
38
39 #include <TopAbs.hxx>
40 #include <TColStd_MapOfInteger.hxx>
41
42 using namespace std;
43
44 //=================================================================================
45 // class    : RepairGUI_RemoveHolesDlg()
46 // purpose  : Constructs a RepairGUI_RemoveHolesDlg  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 RepairGUI_RemoveHolesDlg::RepairGUI_RemoveHolesDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
52                                                    const char* name, bool modal, WFlags fl)
53   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
54                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 {
56   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPPRESS_HOLES")));
57   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58
59   setCaption(tr("GEOM_REMOVE_HOLES_TITLE"));
60
61   /***************************************************************/
62   GroupConstructors->setTitle(tr("GEOM_REMOVE_HOLES_TITLE"));
63   RadioButton1->setPixmap(image0);
64   RadioButton2->close(TRUE);
65   RadioButton3->close(TRUE);
66
67   GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
68   GroupPoints->GroupBox1->setTitle(tr("GEOM_HOLES"));
69   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
70   GroupPoints->PushButton1->setPixmap(image1);
71   GroupPoints->LineEdit1->setReadOnly( true );
72
73   Layout1->addWidget(GroupPoints, 2, 0);
74
75   myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_HOLES" ), GroupPoints->GroupBox1 );
76
77   QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
78
79   mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
80   mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
81   mySelectWiresBtn->setText( trUtf8( "" ) );
82   mySelectWiresBtn->setPixmap(image1);
83
84   mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
85   mySelectWiresEdt->setReadOnly( true );
86
87   mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
88   mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
89
90   aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
91         aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
92   aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
93   QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
94   aSelectWiresLay->addItem( spacer, 1, 2 );
95
96   QGridLayout* aDetectLay = new QGridLayout( 0, 1, 1, 0, 6, "aDetectLay" );  
97         myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ), GroupPoints->GroupBox1 );
98   QLabel* aLbl = new QLabel( tr( "GEOM_FREE_BOUNDARIES" ), GroupPoints->GroupBox1 );
99   aDetectLay->addWidget( aLbl, 0, 0 );
100   aDetectLay->addWidget( myFreeBoundBtn, 0, 1 );
101   
102   GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
103   GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );
104   GroupPoints->getGroupBoxLayout()->addLayout( aDetectLay, 3, 0 );
105   /***************************************************************/
106
107   setHelpFileName("suppress_holes_operation_page.html");
108
109   Init();
110 }
111
112
113 //=================================================================================
114 // function : ~RepairGUI_RemoveHolesDlg()
115 // purpose  : Destroys the object and frees any allocated resources
116 //=================================================================================
117 RepairGUI_RemoveHolesDlg::~RepairGUI_RemoveHolesDlg()
118 {
119 }
120
121
122 //=================================================================================
123 // function : Init()
124 // purpose  :
125 //=================================================================================
126 void RepairGUI_RemoveHolesDlg::Init()
127 {
128   /* init variables */
129   myEditCurrentArgument = GroupPoints->LineEdit1;
130   
131   myObject = GEOM::GEOM_Object::_nil();
132   myWiresInd = new GEOM::short_array();
133   myWiresInd->length( 0 );
134
135   //myGeomGUI->SetState( 0 );
136   initSelection();
137
138   myClosed = -1;
139   myOpen = -1;
140   
141   /* signals and slots connections */
142   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
143   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
144
145   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147   connect(mySelectWiresBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148   connect(mySelectWiresEdt, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149
150   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
151           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
152
153   connect( myAllChk, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
154   connect( myFreeBoundBtn, SIGNAL(clicked()), this, SLOT(onDetect()) );
155
156   initName( tr( "REMOVE_HOLES_NEW_OBJ_NAME" ) );
157 }
158
159
160 //=================================================================================
161 // function : ClickOnOk()
162 // purpose  : Same than click on apply but close this dialog.
163 //=================================================================================
164 void RepairGUI_RemoveHolesDlg::ClickOnOk()
165 {
166   if ( ClickOnApply() )
167     ClickOnCancel();
168 }
169
170 //=================================================================================
171 // function : ClickOnApply()
172 // purpose  :
173 //=================================================================================
174 bool RepairGUI_RemoveHolesDlg::ClickOnApply()
175 {
176   if ( !onAccept() )
177     return false;
178
179   initName();
180
181   myEditCurrentArgument = GroupPoints->LineEdit1;
182   myEditCurrentArgument->setText("");
183   mySelectWiresEdt->setText("");
184   myObject = GEOM::GEOM_Object::_nil();
185   myWiresInd->length( 0 );
186
187   initSelection();
188
189   return true;
190 }
191
192
193 //=================================================================================
194 // function : SelectionIntoArgument()
195 // purpose  : Called when selection
196 //=================================================================================
197 void RepairGUI_RemoveHolesDlg::SelectionIntoArgument()
198 {
199   erasePreview();
200   myEditCurrentArgument->setText("");
201   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
202   else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
203
204   if ( IObjectCount() == 1 )
205   {
206     Handle(SALOME_InteractiveObject) anIO = firstIObject();
207
208     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )      // face selection
209     {
210       Standard_Boolean aRes;
211       myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
212       if ( aRes && GEOMBase::IsShape( myObject ) )
213         myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
214       else
215         myObject = GEOM::GEOM_Object::_nil();
216     }
217     else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
218     {
219       TColStd_IndexedMapOfInteger aMap;
220       ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
221       const int n = aMap.Extent();
222       myWiresInd->length( n );
223       for ( int i = 1; i <= n; i++ )
224         myWiresInd[i-1] = aMap( i );
225       if ( n )
226         myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
227     }
228   }
229 }
230
231 //=================================================================================
232 // function : SetEditCurrentArgument()
233 // purpose  :
234 //=================================================================================
235 void RepairGUI_RemoveHolesDlg::SetEditCurrentArgument()
236 {
237   const QObject* send = sender();
238   if ( send == GroupPoints->PushButton1 )
239     myEditCurrentArgument = GroupPoints->LineEdit1; 
240   else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
241     myEditCurrentArgument = mySelectWiresEdt;
242   if ( myEditCurrentArgument )
243   {
244     initSelection();
245     myEditCurrentArgument->setFocus();
246     SelectionIntoArgument();
247   }
248 }
249
250
251 //=================================================================================
252 // function : LineEditReturnPressed()
253 // purpose  :
254 //=================================================================================
255 void RepairGUI_RemoveHolesDlg::LineEditReturnPressed()
256 {
257   const QObject* send = sender();
258   if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
259   {
260     myEditCurrentArgument = (QLineEdit*)send;
261     GEOMBase_Skeleton::LineEditReturnPressed();
262   }
263 }
264
265
266 //=================================================================================
267 // function : ActivateThisDialog()
268 // purpose  :
269 //=================================================================================
270 void RepairGUI_RemoveHolesDlg::ActivateThisDialog()
271 {
272   GEOMBase_Skeleton::ActivateThisDialog();
273   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
274           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
275
276   myEditCurrentArgument = GroupPoints->LineEdit1;
277   myEditCurrentArgument->setText("");
278   mySelectWiresEdt->setText("");
279   myObject = GEOM::GEOM_Object::_nil();
280   myWiresInd->length( 0 );
281
282   myClosed = -1;
283   myOpen = -1;
284
285   //myGeomGUI->SetState( 0 );
286   initSelection();
287 }
288
289
290 //=================================================================================
291 // function : enterEvent()
292 // purpose  : Mouse enter onto the dialog to activate it
293 //=================================================================================
294 void RepairGUI_RemoveHolesDlg::enterEvent(QEvent* e)
295 {
296   if ( !GroupConstructors->isEnabled() )
297     ActivateThisDialog();
298 }
299
300
301 //=================================================================================
302 // function : closeEvent()
303 // purpose  :
304 //=================================================================================
305 void RepairGUI_RemoveHolesDlg::closeEvent(QCloseEvent* e)
306 {
307   //myGeomGUI->SetState( -1 );
308   GEOMBase_Skeleton::closeEvent( e );
309 }
310
311 //=================================================================================
312 // function : createOperation
313 // purpose  :
314 //=================================================================================
315 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveHolesDlg::createOperation()
316 {
317   return getGeomEngine()->GetIHealingOperations( getStudyId() );
318 }
319
320 //=================================================================================
321 // function : isValid
322 // purpose  :
323 //=================================================================================
324 bool RepairGUI_RemoveHolesDlg::isValid( QString& msg )
325 {
326   myClosed = -1;
327   return !myObject->_is_nil() && ( IsPreview() || myAllChk->isChecked() || myWiresInd->length() );
328 }
329
330 //=================================================================================
331 // function : execute
332 // purpose  :
333 //=================================================================================
334 bool RepairGUI_RemoveHolesDlg::execute( ObjectList& objects )
335 {
336   bool aResult = false;
337   if ( IsPreview() ) // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
338   {
339     GEOM::ListOfGO_var aClosed, anOpen;
340
341     aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
342
343     if ( aResult )
344     {
345       myClosed = aClosed->length();
346       myOpen = anOpen->length();
347       int i;
348       for ( i = 0; i < myClosed; i++ )
349         objects.push_back( aClosed[i]._retn() );
350       for ( i = 0; i < myOpen; i++ )
351         objects.push_back( anOpen[i]._retn() );
352     }
353     else
354       myClosed = -1;
355   }
356   else
357   {
358     GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->FillHoles( myObject, myWiresInd );
359     aResult = !anObj->_is_nil();
360     if ( aResult )
361       objects.push_back( anObj._retn() );
362   }
363         
364   return aResult;
365 }
366
367 //=================================================================================
368 // function : onRemoveAllClicked
369 // purpose  :
370 //=================================================================================
371 void RepairGUI_RemoveHolesDlg::onRemoveAllClicked()
372 {
373   bool b = myAllChk->isOn();
374   mySelectWiresLbl->setEnabled( !b );
375   mySelectWiresBtn->setEnabled( !b );
376   mySelectWiresEdt->setEnabled( !b );
377   if ( b )
378   {
379     mySelectWiresEdt->setText( "" );
380     myWiresInd->length( 0 );
381   }
382 }
383
384 //=================================================================================
385 // function : initSelection
386 // purpose  :
387 //=================================================================================
388 void RepairGUI_RemoveHolesDlg::initSelection()
389 {
390   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
391   {
392     TColStd_MapOfInteger aTypes;
393     aTypes.Add( GEOM_COMPOUND );
394     aTypes.Add( GEOM_SOLID );
395     aTypes.Add( GEOM_SHELL );
396     aTypes.Add( GEOM_FACE );
397     
398     globalSelection( aTypes );
399   }
400   else if ( myEditCurrentArgument == mySelectWiresEdt )
401   {
402     localSelection( myObject, TopAbs_EDGE );
403     localSelection( myObject, TopAbs_WIRE );
404   }
405 }
406
407
408 //=================================================================================
409 // function : onDetect
410 // purpose  :
411 //=================================================================================
412 void RepairGUI_RemoveHolesDlg::onDetect()
413 {
414   displayPreview( false, true, true, 3 );
415
416   // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
417   QString msg;
418   if ( myClosed != -1 )
419     msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
420   else
421     msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
422   SUIT_MessageBox::info1( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, "Close" );
423 }
424