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
24 // File : RepairGUI_RemoveHolesDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "RepairGUI_RemoveHolesDlg.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33 #include "SUIT_MessageBox.h"
34 #include "SUIT_Session.h"
36 #include "SALOME_ListIteratorOfListIO.hxx"
38 #include "GEOMImpl_Types.hxx"
41 #include <TColStd_MapOfInteger.hxx>
45 //=================================================================================
46 // class : RepairGUI_RemoveHolesDlg()
47 // purpose : Constructs a RepairGUI_RemoveHolesDlg 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 RepairGUI_RemoveHolesDlg::RepairGUI_RemoveHolesDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
53 const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPPRESS_HOLES")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_REMOVE_HOLES_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_REMOVE_HOLES_TITLE"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->close(TRUE);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_HOLES"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
71 GroupPoints->PushButton1->setPixmap(image1);
72 GroupPoints->LineEdit1->setReadOnly( true );
74 Layout1->addWidget(GroupPoints, 2, 0);
76 myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_HOLES" ), GroupPoints->GroupBox1 );
78 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
80 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
81 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
82 mySelectWiresBtn->setText( trUtf8( "" ) );
83 mySelectWiresBtn->setPixmap(image1);
85 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
86 mySelectWiresEdt->setReadOnly( true );
88 mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
89 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
91 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
92 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
93 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
94 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
95 aSelectWiresLay->addItem( spacer, 1, 2 );
97 QGridLayout* aDetectLay = new QGridLayout( 0, 1, 1, 0, 6, "aDetectLay" );
98 myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ), GroupPoints->GroupBox1 );
99 QLabel* aLbl = new QLabel( tr( "GEOM_FREE_BOUNDARIES" ), GroupPoints->GroupBox1 );
100 aDetectLay->addWidget( aLbl, 0, 0 );
101 aDetectLay->addWidget( myFreeBoundBtn, 0, 1 );
103 GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
104 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );
105 GroupPoints->getGroupBoxLayout()->addLayout( aDetectLay, 3, 0 );
106 /***************************************************************/
108 setHelpFileName("suppress_holes_operation_page.html");
114 //=================================================================================
115 // function : ~RepairGUI_RemoveHolesDlg()
116 // purpose : Destroys the object and frees any allocated resources
117 //=================================================================================
118 RepairGUI_RemoveHolesDlg::~RepairGUI_RemoveHolesDlg()
123 //=================================================================================
126 //=================================================================================
127 void RepairGUI_RemoveHolesDlg::Init()
130 myEditCurrentArgument = GroupPoints->LineEdit1;
132 myObject = GEOM::GEOM_Object::_nil();
133 myWiresInd = new GEOM::short_array();
134 myWiresInd->length( 0 );
136 //myGeomGUI->SetState( 0 );
142 /* signals and slots connections */
143 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
146 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(mySelectWiresBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(mySelectWiresEdt, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
152 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
154 connect( myAllChk, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
155 connect( myFreeBoundBtn, SIGNAL(clicked()), this, SLOT(onDetect()) );
157 initName( tr( "REMOVE_HOLES_NEW_OBJ_NAME" ) );
161 //=================================================================================
162 // function : ClickOnOk()
163 // purpose : Same than click on apply but close this dialog.
164 //=================================================================================
165 void RepairGUI_RemoveHolesDlg::ClickOnOk()
167 if ( ClickOnApply() )
171 //=================================================================================
172 // function : ClickOnApply()
174 //=================================================================================
175 bool RepairGUI_RemoveHolesDlg::ClickOnApply()
182 myEditCurrentArgument = GroupPoints->LineEdit1;
183 myEditCurrentArgument->setText("");
184 mySelectWiresEdt->setText("");
185 myObject = GEOM::GEOM_Object::_nil();
186 myWiresInd->length( 0 );
194 //=================================================================================
195 // function : SelectionIntoArgument()
196 // purpose : Called when selection
197 //=================================================================================
198 void RepairGUI_RemoveHolesDlg::SelectionIntoArgument()
201 myEditCurrentArgument->setText("");
202 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
203 else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
205 if ( IObjectCount() == 1 )
207 Handle(SALOME_InteractiveObject) anIO = firstIObject();
209 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
211 Standard_Boolean aRes;
212 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
213 if ( aRes && GEOMBase::IsShape( myObject ) )
214 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
216 myObject = GEOM::GEOM_Object::_nil();
218 else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
220 TColStd_IndexedMapOfInteger aMap;
221 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
222 const int n = aMap.Extent();
223 myWiresInd->length( n );
224 for ( int i = 1; i <= n; i++ )
225 myWiresInd[i-1] = aMap( i );
227 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
232 //=================================================================================
233 // function : SetEditCurrentArgument()
235 //=================================================================================
236 void RepairGUI_RemoveHolesDlg::SetEditCurrentArgument()
238 const QObject* send = sender();
239 if ( send == GroupPoints->PushButton1 )
240 myEditCurrentArgument = GroupPoints->LineEdit1;
241 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
242 myEditCurrentArgument = mySelectWiresEdt;
243 if ( myEditCurrentArgument )
246 myEditCurrentArgument->setFocus();
247 SelectionIntoArgument();
252 //=================================================================================
253 // function : LineEditReturnPressed()
255 //=================================================================================
256 void RepairGUI_RemoveHolesDlg::LineEditReturnPressed()
258 const QObject* send = sender();
259 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
261 myEditCurrentArgument = (QLineEdit*)send;
262 GEOMBase_Skeleton::LineEditReturnPressed();
267 //=================================================================================
268 // function : ActivateThisDialog()
270 //=================================================================================
271 void RepairGUI_RemoveHolesDlg::ActivateThisDialog()
273 GEOMBase_Skeleton::ActivateThisDialog();
274 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
275 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
277 myEditCurrentArgument = GroupPoints->LineEdit1;
278 myEditCurrentArgument->setText("");
279 mySelectWiresEdt->setText("");
280 myObject = GEOM::GEOM_Object::_nil();
281 myWiresInd->length( 0 );
286 //myGeomGUI->SetState( 0 );
291 //=================================================================================
292 // function : enterEvent()
293 // purpose : Mouse enter onto the dialog to activate it
294 //=================================================================================
295 void RepairGUI_RemoveHolesDlg::enterEvent(QEvent* e)
297 if ( !GroupConstructors->isEnabled() )
298 ActivateThisDialog();
302 //=================================================================================
303 // function : closeEvent()
305 //=================================================================================
306 void RepairGUI_RemoveHolesDlg::closeEvent(QCloseEvent* e)
308 //myGeomGUI->SetState( -1 );
309 GEOMBase_Skeleton::closeEvent( e );
312 //=================================================================================
313 // function : createOperation
315 //=================================================================================
316 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveHolesDlg::createOperation()
318 return getGeomEngine()->GetIHealingOperations( getStudyId() );
321 //=================================================================================
322 // function : isValid
324 //=================================================================================
325 bool RepairGUI_RemoveHolesDlg::isValid( QString& msg )
328 return !myObject->_is_nil() && ( IsPreview() || myAllChk->isChecked() || myWiresInd->length() );
331 //=================================================================================
332 // function : execute
334 //=================================================================================
335 bool RepairGUI_RemoveHolesDlg::execute( ObjectList& objects )
337 bool aResult = false;
338 if ( IsPreview() ) // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
340 GEOM::ListOfGO_var aClosed, anOpen;
342 aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
346 myClosed = aClosed->length();
347 myOpen = anOpen->length();
349 for ( i = 0; i < myClosed; i++ )
350 objects.push_back( aClosed[i]._retn() );
351 for ( i = 0; i < myOpen; i++ )
352 objects.push_back( anOpen[i]._retn() );
359 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->FillHoles( myObject, myWiresInd );
360 aResult = !anObj->_is_nil();
362 objects.push_back( anObj._retn() );
368 //=================================================================================
369 // function : onRemoveAllClicked
371 //=================================================================================
372 void RepairGUI_RemoveHolesDlg::onRemoveAllClicked()
374 bool b = myAllChk->isOn();
375 mySelectWiresLbl->setEnabled( !b );
376 mySelectWiresBtn->setEnabled( !b );
377 mySelectWiresEdt->setEnabled( !b );
380 mySelectWiresEdt->setText( "" );
381 myWiresInd->length( 0 );
385 //=================================================================================
386 // function : initSelection
388 //=================================================================================
389 void RepairGUI_RemoveHolesDlg::initSelection()
391 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
393 TColStd_MapOfInteger aTypes;
394 aTypes.Add( GEOM_COMPOUND );
395 aTypes.Add( GEOM_SOLID );
396 aTypes.Add( GEOM_SHELL );
397 aTypes.Add( GEOM_FACE );
399 globalSelection( aTypes );
401 else if ( myEditCurrentArgument == mySelectWiresEdt )
403 localSelection( myObject, TopAbs_EDGE );
404 localSelection( myObject, TopAbs_WIRE );
409 //=================================================================================
410 // function : onDetect
412 //=================================================================================
413 void RepairGUI_RemoveHolesDlg::onDetect()
415 displayPreview( false, true, true, 3 );
417 // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
419 if ( myClosed != -1 )
420 msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
422 msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
423 SUIT_MessageBox::info1( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, "Close" );