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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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(QWidget* parent, const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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 setCaption(tr("GEOM_REMOVE_HOLES_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_REMOVE_HOLES_TITLE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_HOLES"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
69 GroupPoints->PushButton1->setPixmap(image1);
70 GroupPoints->LineEdit1->setReadOnly( true );
72 Layout1->addWidget(GroupPoints, 2, 0);
74 myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_HOLES" ), GroupPoints->GroupBox1 );
76 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
78 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
79 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
80 mySelectWiresBtn->setText( trUtf8( "" ) );
81 mySelectWiresBtn->setPixmap(image1);
83 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
84 mySelectWiresEdt->setReadOnly( true );
86 mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
87 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
89 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
90 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
91 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
92 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
93 aSelectWiresLay->addItem( spacer, 1, 2 );
95 QGridLayout* aDetectLay = new QGridLayout( 0, 1, 1, 0, 6, "aDetectLay" );
96 myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ), GroupPoints->GroupBox1 );
97 QLabel* aLbl = new QLabel( tr( "GEOM_FREE_BOUNDARIES" ), GroupPoints->GroupBox1 );
98 aDetectLay->addWidget( aLbl, 0, 0 );
99 aDetectLay->addWidget( myFreeBoundBtn, 0, 1 );
101 GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
102 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );
103 GroupPoints->getGroupBoxLayout()->addLayout( aDetectLay, 3, 0 );
104 /***************************************************************/
110 //=================================================================================
111 // function : ~RepairGUI_RemoveHolesDlg()
112 // purpose : Destroys the object and frees any allocated resources
113 //=================================================================================
114 RepairGUI_RemoveHolesDlg::~RepairGUI_RemoveHolesDlg()
119 //=================================================================================
122 //=================================================================================
123 void RepairGUI_RemoveHolesDlg::Init()
126 myEditCurrentArgument = GroupPoints->LineEdit1;
128 myObject = GEOM::GEOM_Object::_nil();
129 myWiresInd = new GEOM::short_array();
130 myWiresInd->length( 0 );
132 //myGeomGUI->SetState( 0 );
138 /* signals and slots connections */
139 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
140 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
141 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
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() )
173 //=================================================================================
174 // function : ClickOnApply()
176 //=================================================================================
177 bool RepairGUI_RemoveHolesDlg::ClickOnApply()
184 myEditCurrentArgument = GroupPoints->LineEdit1;
185 myEditCurrentArgument->setText("");
186 mySelectWiresEdt->setText("");
187 myObject = GEOM::GEOM_Object::_nil();
188 myWiresInd->length( 0 );
196 //=================================================================================
197 // function : ClickOnCancel()
199 //=================================================================================
200 void RepairGUI_RemoveHolesDlg::ClickOnCancel()
202 GEOMBase_Skeleton::ClickOnCancel();
206 //=================================================================================
207 // function : SelectionIntoArgument()
208 // purpose : Called when selection
209 //=================================================================================
210 void RepairGUI_RemoveHolesDlg::SelectionIntoArgument()
213 myEditCurrentArgument->setText("");
214 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
215 else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
217 if ( IObjectCount() == 1 )
219 Handle(SALOME_InteractiveObject) anIO = firstIObject();
221 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
223 Standard_Boolean aRes;
224 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
225 if ( aRes && GEOMBase::IsShape( myObject ) )
226 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
228 myObject = GEOM::GEOM_Object::_nil();
230 else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
232 TColStd_IndexedMapOfInteger aMap;
233 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
234 const int n = aMap.Extent();
235 myWiresInd->length( n );
236 for ( int i = 1; i <= n; i++ )
237 myWiresInd[i-1] = aMap( i );
239 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
244 //=================================================================================
245 // function : SetEditCurrentArgument()
247 //=================================================================================
248 void RepairGUI_RemoveHolesDlg::SetEditCurrentArgument()
250 const QObject* send = sender();
251 if ( send == GroupPoints->PushButton1 )
252 myEditCurrentArgument = GroupPoints->LineEdit1;
253 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
254 myEditCurrentArgument = mySelectWiresEdt;
255 if ( myEditCurrentArgument )
258 myEditCurrentArgument->setFocus();
259 SelectionIntoArgument();
264 //=================================================================================
265 // function : LineEditReturnPressed()
267 //=================================================================================
268 void RepairGUI_RemoveHolesDlg::LineEditReturnPressed()
270 const QObject* send = sender();
271 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
273 myEditCurrentArgument = (QLineEdit*)send;
274 GEOMBase_Skeleton::LineEditReturnPressed();
279 //=================================================================================
280 // function : DeactivateActiveDialog()
282 //=================================================================================
283 void RepairGUI_RemoveHolesDlg::DeactivateActiveDialog()
285 //myGeomGUI->SetState( -1 );
286 GEOMBase_Skeleton::DeactivateActiveDialog();
290 //=================================================================================
291 // function : ActivateThisDialog()
293 //=================================================================================
294 void RepairGUI_RemoveHolesDlg::ActivateThisDialog()
296 GEOMBase_Skeleton::ActivateThisDialog();
297 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
298 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
300 myEditCurrentArgument = GroupPoints->LineEdit1;
301 myEditCurrentArgument->setText("");
302 mySelectWiresEdt->setText("");
303 myObject = GEOM::GEOM_Object::_nil();
304 myWiresInd->length( 0 );
309 //myGeomGUI->SetState( 0 );
314 //=================================================================================
315 // function : enterEvent()
316 // purpose : Mouse enter onto the dialog to activate it
317 //=================================================================================
318 void RepairGUI_RemoveHolesDlg::enterEvent(QEvent* e)
320 if ( !GroupConstructors->isEnabled() )
321 ActivateThisDialog();
325 //=================================================================================
326 // function : closeEvent()
328 //=================================================================================
329 void RepairGUI_RemoveHolesDlg::closeEvent(QCloseEvent* e)
331 //myGeomGUI->SetState( -1 );
332 GEOMBase_Skeleton::closeEvent( e );
335 //=================================================================================
336 // function : createOperation
338 //=================================================================================
339 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveHolesDlg::createOperation()
341 return getGeomEngine()->GetIHealingOperations( getStudyId() );
344 //=================================================================================
345 // function : isValid
347 //=================================================================================
348 bool RepairGUI_RemoveHolesDlg::isValid( QString& msg )
351 return !myObject->_is_nil() && ( IsPreview() || myAllChk->isChecked() || myWiresInd->length() );
354 //=================================================================================
355 // function : execute
357 //=================================================================================
358 bool RepairGUI_RemoveHolesDlg::execute( ObjectList& objects )
360 bool aResult = false;
361 if ( IsPreview() ) // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
363 GEOM::ListOfGO_var aClosed, anOpen;
365 aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
369 myClosed = aClosed->length();
370 myOpen = anOpen->length();
372 for ( i = 0; i < myClosed; i++ )
373 objects.push_back( aClosed[i]._retn() );
374 for ( i = 0; i < myOpen; i++ )
375 objects.push_back( anOpen[i]._retn() );
382 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->FillHoles( myObject, myWiresInd );
383 aResult = !anObj->_is_nil();
385 objects.push_back( anObj._retn() );
391 //=================================================================================
392 // function : onRemoveAllClicked
394 //=================================================================================
395 void RepairGUI_RemoveHolesDlg::onRemoveAllClicked()
397 bool b = myAllChk->isOn();
398 mySelectWiresLbl->setEnabled( !b );
399 mySelectWiresBtn->setEnabled( !b );
400 mySelectWiresEdt->setEnabled( !b );
403 mySelectWiresEdt->setText( "" );
404 myWiresInd->length( 0 );
408 //=================================================================================
409 // function : initSelection
411 //=================================================================================
412 void RepairGUI_RemoveHolesDlg::initSelection()
414 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
416 TColStd_MapOfInteger aTypes;
417 aTypes.Add( GEOM_COMPOUND );
418 aTypes.Add( GEOM_SOLID );
419 aTypes.Add( GEOM_SHELL );
420 aTypes.Add( GEOM_FACE );
422 globalSelection( aTypes );
424 else if ( myEditCurrentArgument == mySelectWiresEdt )
426 localSelection( myObject, TopAbs_EDGE );
427 localSelection( myObject, TopAbs_WIRE );
432 //=================================================================================
433 // function : onDetect
435 //=================================================================================
436 void RepairGUI_RemoveHolesDlg::onDetect()
438 displayPreview( false, true, true, 3 );
440 // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
442 if ( myClosed != -1 )
443 msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
445 msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
446 SUIT_MessageBox::info1( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, "Close" );