1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : RepairGUI_RemoveHolesDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "RepairGUI_RemoveHolesDlg.h"
30 #include "SalomeApp_Application.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SUIT_MessageBox.h"
33 #include "SUIT_Session.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "GEOMImpl_Types.hxx"
40 #include <TColStd_MapOfInteger.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,
52 const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
54 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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")));
59 setCaption(tr("GEOM_REMOVE_HOLES_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_REMOVE_HOLES_TITLE"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->close(TRUE);
65 RadioButton3->close(TRUE);
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 );
73 Layout1->addWidget(GroupPoints, 2, 0);
75 myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_HOLES" ), GroupPoints->GroupBox1 );
77 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
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);
84 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
85 mySelectWiresEdt->setReadOnly( true );
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() ) );
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 );
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 );
102 GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
103 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );
104 GroupPoints->getGroupBoxLayout()->addLayout( aDetectLay, 3, 0 );
105 /***************************************************************/
107 setHelpFileName("suppress_holes_operation_page.html");
113 //=================================================================================
114 // function : ~RepairGUI_RemoveHolesDlg()
115 // purpose : Destroys the object and frees any allocated resources
116 //=================================================================================
117 RepairGUI_RemoveHolesDlg::~RepairGUI_RemoveHolesDlg()
122 //=================================================================================
125 //=================================================================================
126 void RepairGUI_RemoveHolesDlg::Init()
129 myEditCurrentArgument = GroupPoints->LineEdit1;
131 myObject = GEOM::GEOM_Object::_nil();
132 myWiresInd = new GEOM::short_array();
133 myWiresInd->length( 0 );
135 //myGeomGUI->SetState( 0 );
141 /* signals and slots connections */
142 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
143 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
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()));
150 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
151 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
153 connect( myAllChk, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
154 connect( myFreeBoundBtn, SIGNAL(clicked()), this, SLOT(onDetect()) );
156 initName( tr( "REMOVE_HOLES_NEW_OBJ_NAME" ) );
160 //=================================================================================
161 // function : ClickOnOk()
162 // purpose : Same than click on apply but close this dialog.
163 //=================================================================================
164 void RepairGUI_RemoveHolesDlg::ClickOnOk()
166 if ( ClickOnApply() )
170 //=================================================================================
171 // function : ClickOnApply()
173 //=================================================================================
174 bool RepairGUI_RemoveHolesDlg::ClickOnApply()
181 myEditCurrentArgument = GroupPoints->LineEdit1;
182 myEditCurrentArgument->setText("");
183 mySelectWiresEdt->setText("");
184 myObject = GEOM::GEOM_Object::_nil();
185 myWiresInd->length( 0 );
193 //=================================================================================
194 // function : SelectionIntoArgument()
195 // purpose : Called when selection
196 //=================================================================================
197 void RepairGUI_RemoveHolesDlg::SelectionIntoArgument()
200 myEditCurrentArgument->setText("");
201 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
202 else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
204 if ( IObjectCount() == 1 )
206 Handle(SALOME_InteractiveObject) anIO = firstIObject();
208 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
210 Standard_Boolean aRes;
211 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
212 if ( aRes && GEOMBase::IsShape( myObject ) )
213 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
215 myObject = GEOM::GEOM_Object::_nil();
217 else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
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 );
226 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
231 //=================================================================================
232 // function : SetEditCurrentArgument()
234 //=================================================================================
235 void RepairGUI_RemoveHolesDlg::SetEditCurrentArgument()
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 )
245 myEditCurrentArgument->setFocus();
246 SelectionIntoArgument();
251 //=================================================================================
252 // function : LineEditReturnPressed()
254 //=================================================================================
255 void RepairGUI_RemoveHolesDlg::LineEditReturnPressed()
257 const QObject* send = sender();
258 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
260 myEditCurrentArgument = (QLineEdit*)send;
261 GEOMBase_Skeleton::LineEditReturnPressed();
266 //=================================================================================
267 // function : ActivateThisDialog()
269 //=================================================================================
270 void RepairGUI_RemoveHolesDlg::ActivateThisDialog()
272 GEOMBase_Skeleton::ActivateThisDialog();
273 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
274 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
276 myEditCurrentArgument = GroupPoints->LineEdit1;
277 myEditCurrentArgument->setText("");
278 mySelectWiresEdt->setText("");
279 myObject = GEOM::GEOM_Object::_nil();
280 myWiresInd->length( 0 );
285 //myGeomGUI->SetState( 0 );
290 //=================================================================================
291 // function : enterEvent()
292 // purpose : Mouse enter onto the dialog to activate it
293 //=================================================================================
294 void RepairGUI_RemoveHolesDlg::enterEvent(QEvent* e)
296 if ( !GroupConstructors->isEnabled() )
297 ActivateThisDialog();
301 //=================================================================================
302 // function : closeEvent()
304 //=================================================================================
305 void RepairGUI_RemoveHolesDlg::closeEvent(QCloseEvent* e)
307 //myGeomGUI->SetState( -1 );
308 GEOMBase_Skeleton::closeEvent( e );
311 //=================================================================================
312 // function : createOperation
314 //=================================================================================
315 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveHolesDlg::createOperation()
317 return getGeomEngine()->GetIHealingOperations( getStudyId() );
320 //=================================================================================
321 // function : isValid
323 //=================================================================================
324 bool RepairGUI_RemoveHolesDlg::isValid( QString& msg )
327 return !myObject->_is_nil() && ( IsPreview() || myAllChk->isChecked() || myWiresInd->length() );
330 //=================================================================================
331 // function : execute
333 //=================================================================================
334 bool RepairGUI_RemoveHolesDlg::execute( ObjectList& objects )
336 bool aResult = false;
337 if ( IsPreview() ) // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
339 GEOM::ListOfGO_var aClosed, anOpen;
341 aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
345 myClosed = aClosed->length();
346 myOpen = anOpen->length();
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() );
358 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->FillHoles( myObject, myWiresInd );
359 aResult = !anObj->_is_nil();
361 objects.push_back( anObj._retn() );
367 //=================================================================================
368 // function : onRemoveAllClicked
370 //=================================================================================
371 void RepairGUI_RemoveHolesDlg::onRemoveAllClicked()
373 bool b = myAllChk->isOn();
374 mySelectWiresLbl->setEnabled( !b );
375 mySelectWiresBtn->setEnabled( !b );
376 mySelectWiresEdt->setEnabled( !b );
379 mySelectWiresEdt->setText( "" );
380 myWiresInd->length( 0 );
384 //=================================================================================
385 // function : initSelection
387 //=================================================================================
388 void RepairGUI_RemoveHolesDlg::initSelection()
390 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
392 TColStd_MapOfInteger aTypes;
393 aTypes.Add( GEOM_COMPOUND );
394 aTypes.Add( GEOM_SOLID );
395 aTypes.Add( GEOM_SHELL );
396 aTypes.Add( GEOM_FACE );
398 globalSelection( aTypes );
400 else if ( myEditCurrentArgument == mySelectWiresEdt )
402 localSelection( myObject, TopAbs_EDGE );
403 localSelection( myObject, TopAbs_WIRE );
408 //=================================================================================
409 // function : onDetect
411 //=================================================================================
412 void RepairGUI_RemoveHolesDlg::onDetect()
414 displayPreview( false, true, true, 3 );
416 // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
418 if ( myClosed != -1 )
419 msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
421 msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
422 SUIT_MessageBox::info1( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, "Close" );