1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : RepairGUI_RemoveHolesDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_RemoveHolesDlg.h"
29 #include <GeometryGUI.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
38 #include <GEOMImpl_Types.hxx>
41 #include <TColStd_MapOfInteger.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
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,
53 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
55 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SUPPRESS_HOLES" ) ) );
56 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
58 setWindowTitle( tr( "GEOM_REMOVE_HOLES_TITLE" ) );
60 /***************************************************************/
61 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_REMOVE_HOLES_TITLE" ) );
62 mainFrame()->RadioButton1->setIcon( image0 );
63 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton2->close();
65 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66 mainFrame()->RadioButton3->close();
68 GroupPoints = new DlgRef_1Sel1Check1Sel( centralWidget() );
69 GroupPoints->GroupBox1->setTitle( tr( "GEOM_HOLES" ) );
70 GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
71 GroupPoints->PushButton1->setIcon( image1 );
72 GroupPoints->LineEdit1->setReadOnly( true );
73 GroupPoints->CheckButton1->setText( tr( "GEOM_REMOVE_ALL_HOLES" ) );
74 GroupPoints->TextLabel2->setText( tr( "GEOM_WIRES_TO_REMOVE" ) );
75 GroupPoints->PushButton2->setIcon( image1 );
76 GroupPoints->LineEdit2->setReadOnly( true );
78 myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GEOM_FREE_BOUNDARIES" ) ),
80 QVBoxLayout* l = new QVBoxLayout( GroupPoints->Box );
81 l->setMargin( 0 ); l->setSpacing( 0 );
82 l->addWidget( myFreeBoundBtn );
84 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
85 layout->setMargin( 0 ); layout->setSpacing( 6 );
86 layout->addWidget( GroupPoints );
88 /***************************************************************/
90 setHelpFileName( "suppress_holes_operation_page.html" );
96 //=================================================================================
97 // function : ~RepairGUI_RemoveHolesDlg()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 RepairGUI_RemoveHolesDlg::~RepairGUI_RemoveHolesDlg()
105 //=================================================================================
108 //=================================================================================
109 void RepairGUI_RemoveHolesDlg::Init()
112 myEditCurrentArgument = GroupPoints->LineEdit1;
114 myObject = GEOM::GEOM_Object::_nil();
115 myWiresInd = new GEOM::short_array();
116 myWiresInd->length( 0 );
118 //myGeomGUI->SetState( 0 );
124 /* signals and slots connections */
125 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
126 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
128 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
129 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
130 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
131 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
133 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
134 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
136 connect( GroupPoints->CheckButton1, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
137 connect( myFreeBoundBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
139 initName( tr( "REMOVE_HOLES_NEW_OBJ_NAME" ) );
143 //=================================================================================
144 // function : ClickOnOk()
145 // purpose : Same than click on apply but close this dialog.
146 //=================================================================================
147 void RepairGUI_RemoveHolesDlg::ClickOnOk()
149 if ( ClickOnApply() )
153 //=================================================================================
154 // function : ClickOnApply()
156 //=================================================================================
157 bool RepairGUI_RemoveHolesDlg::ClickOnApply()
164 myEditCurrentArgument = GroupPoints->LineEdit1;
165 myEditCurrentArgument->setText( "" );
166 GroupPoints->LineEdit2->setText( "" );
167 myObject = GEOM::GEOM_Object::_nil();
168 myWiresInd->length( 0 );
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose : Called when selection
179 //=================================================================================
180 void RepairGUI_RemoveHolesDlg::SelectionIntoArgument()
183 myEditCurrentArgument->setText( "" );
184 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
185 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myWiresInd->length( 0 );
187 if ( IObjectCount() == 1 ) {
188 Handle(SALOME_InteractiveObject) anIO = firstIObject();
190 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) { // face selection
191 Standard_Boolean aRes;
192 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
193 if ( aRes && GEOMBase::IsShape( myObject ) )
194 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
196 myObject = GEOM::GEOM_Object::_nil();
198 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 &&
199 !GroupPoints->CheckButton1->isChecked() ) {
200 TColStd_IndexedMapOfInteger aMap;
201 ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr()->GetIndexes( anIO, aMap );
202 const int n = aMap.Extent();
203 myWiresInd->length( n );
204 for ( int i = 1; i <= n; i++ )
205 myWiresInd[i-1] = aMap( i );
207 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
212 //=================================================================================
213 // function : SetEditCurrentArgument()
215 //=================================================================================
216 void RepairGUI_RemoveHolesDlg::SetEditCurrentArgument()
218 const QObject* send = sender();
219 if ( send == GroupPoints->PushButton1 )
220 myEditCurrentArgument = GroupPoints->LineEdit1;
221 else if ( send == GroupPoints->PushButton2 && !myObject->_is_nil() )
222 myEditCurrentArgument = GroupPoints->LineEdit2;
223 if ( myEditCurrentArgument ) {
225 myEditCurrentArgument->setFocus();
226 SelectionIntoArgument();
231 //=================================================================================
232 // function : LineEditReturnPressed()
234 //=================================================================================
235 void RepairGUI_RemoveHolesDlg::LineEditReturnPressed()
237 const QObject* send = sender();
238 if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
239 myEditCurrentArgument = (QLineEdit*)send;
240 GEOMBase_Skeleton::LineEditReturnPressed();
245 //=================================================================================
246 // function : ActivateThisDialog()
248 //=================================================================================
249 void RepairGUI_RemoveHolesDlg::ActivateThisDialog()
251 GEOMBase_Skeleton::ActivateThisDialog();
252 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
253 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
255 myEditCurrentArgument = GroupPoints->LineEdit1;
256 myEditCurrentArgument->setText( "" );
257 GroupPoints->LineEdit2->setText( "" );
258 myObject = GEOM::GEOM_Object::_nil();
259 myWiresInd->length( 0 );
264 //myGeomGUI->SetState( 0 );
269 //=================================================================================
270 // function : enterEvent()
271 // purpose : Mouse enter onto the dialog to activate it
272 //=================================================================================
273 void RepairGUI_RemoveHolesDlg::enterEvent( QEvent* )
275 if ( !mainFrame()->GroupConstructors->isEnabled() )
276 ActivateThisDialog();
280 //=================================================================================
281 // function : createOperation
283 //=================================================================================
284 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveHolesDlg::createOperation()
286 return getGeomEngine()->GetIHealingOperations( getStudyId() );
289 //=================================================================================
290 // function : isValid
292 //=================================================================================
293 bool RepairGUI_RemoveHolesDlg::isValid( QString& )
296 return !myObject->_is_nil() && ( IsPreview() || GroupPoints->CheckButton1->isChecked() || myWiresInd->length() );
299 //=================================================================================
300 // function : execute
302 //=================================================================================
303 bool RepairGUI_RemoveHolesDlg::execute( ObjectList& objects )
305 bool aResult = false;
306 if ( IsPreview() ) { // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
307 GEOM::ListOfGO_var aClosed, anOpen;
309 aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
312 myClosed = aClosed->length();
313 myOpen = anOpen->length();
315 for ( i = 0; i < myClosed; i++ )
316 objects.push_back( aClosed[i]._retn() );
317 for ( i = 0; i < myOpen; i++ )
318 objects.push_back( anOpen[i]._retn() );
324 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->FillHoles( myObject, myWiresInd );
325 aResult = !anObj->_is_nil();
327 objects.push_back( anObj._retn() );
333 //=================================================================================
334 // function : onRemoveAllClicked
336 //=================================================================================
337 void RepairGUI_RemoveHolesDlg::onRemoveAllClicked()
339 bool b = GroupPoints->CheckButton1->isChecked();
340 GroupPoints->TextLabel2->setEnabled( !b );
341 GroupPoints->PushButton2->setEnabled( !b );
342 GroupPoints->LineEdit2->setEnabled( !b );
344 GroupPoints->LineEdit2->setText( "" );
345 myWiresInd->length( 0 );
349 //=================================================================================
350 // function : initSelection
352 //=================================================================================
353 void RepairGUI_RemoveHolesDlg::initSelection()
355 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
356 TColStd_MapOfInteger aTypes;
357 aTypes.Add( GEOM_COMPOUND );
358 aTypes.Add( GEOM_SOLID );
359 aTypes.Add( GEOM_SHELL );
360 aTypes.Add( GEOM_FACE );
362 globalSelection( aTypes );
364 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
365 localSelection( myObject, TopAbs_EDGE );
366 localSelection( myObject, TopAbs_WIRE );
371 //=================================================================================
372 // function : onDetect
374 //=================================================================================
375 void RepairGUI_RemoveHolesDlg::onDetect()
377 displayPreview( false, true, true, 3 );
379 // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
381 if ( myClosed != -1 )
382 msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
384 msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
385 SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg );