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_SewingDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_SewingDlg.h"
29 #include <GeometryGUI.h>
31 #include <QtxDoubleSpinBox.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ResourceMgr.h>
39 #include <GEOMImpl_Types.hxx>
42 #include <TColStd_MapOfInteger.hxx>
44 #define DEFAULT_TOLERANCE_VALUE 1e-07
46 //=================================================================================
47 // class : RepairGUI_SewingDlg()
48 // purpose : Constructs a RepairGUI_SewingDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 RepairGUI_SewingDlg::RepairGUI_SewingDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
57 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SEWING" ) ) );
58 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60 setWindowTitle( tr( "GEOM_SEWING_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SEWING_TITLE" ) );
64 mainFrame()->RadioButton1->setIcon( image0 );
65 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
66 mainFrame()->RadioButton2->close();
67 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 mainFrame()->RadioButton3->close();
70 GroupPoints = new DlgRef_1SelExt( centralWidget() );
71 GroupPoints->GroupBox1->setTitle( tr( "GEOM_SEWING" ) );
72 GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
73 GroupPoints->PushButton1->setIcon( image1 );
74 GroupPoints->LineEdit1->setReadOnly( true );
76 QGridLayout* aLay = new QGridLayout( GroupPoints->Box );
77 aLay->setMargin( 0 ); aLay->setSpacing( 6 );
78 myTolEdt = new QtxDoubleSpinBox( 0.0, 100.0, DEFAULT_TOLERANCE_VALUE, 7, 10, GroupPoints->Box );
79 myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
80 QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->Box );
81 myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GEOM_FREE_BOUNDARIES" ) ),
83 aLay->addWidget( aLbl1, 0, 0 );
84 aLay->addWidget( myTolEdt, 0, 1 );
85 aLay->addWidget( myFreeBoundBtn, 1, 0, 1, 2 );
87 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
88 layout->setMargin( 0 ); layout->setSpacing( 6 );
89 layout->addWidget( GroupPoints );
90 /***************************************************************/
92 setHelpFileName( "sewing_operation_page.html" );
98 //=================================================================================
99 // function : ~RepairGUI_SewingDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 RepairGUI_SewingDlg::~RepairGUI_SewingDlg()
107 //=================================================================================
110 //=================================================================================
111 void RepairGUI_SewingDlg::Init()
114 myEditCurrentArgument = GroupPoints->LineEdit1;
116 myObject = GEOM::GEOM_Object::_nil();
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->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
131 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
132 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
134 connect( myFreeBoundBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
136 initName( tr( "SEWING_NEW_OBJ_NAME" ) );
140 //=================================================================================
141 // function : ClickOnOk()
142 // purpose : Same than click on apply but close this dialog.
143 //=================================================================================
144 void RepairGUI_SewingDlg::ClickOnOk()
146 if ( ClickOnApply() )
150 //=================================================================================
151 // function : ClickOnApply()
153 //=================================================================================
154 bool RepairGUI_SewingDlg::ClickOnApply()
161 GroupPoints->LineEdit1->setText( "" );
162 myObject = GEOM::GEOM_Object::_nil();
170 //=================================================================================
171 // function : SelectionIntoArgument()
172 // purpose : Called when selection
173 //=================================================================================
174 void RepairGUI_SewingDlg::SelectionIntoArgument()
177 myEditCurrentArgument->setText( "" );
178 myObject = GEOM::GEOM_Object::_nil();
180 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
181 SALOME_ListIO aSelList;
182 aSelMgr->selectedObjects(aSelList);
184 if ( aSelList.Extent() == 1 ) {
185 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
186 Standard_Boolean aRes;
187 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
189 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
193 //=================================================================================
194 // function : SetEditCurrentArgument()
196 //=================================================================================
197 void RepairGUI_SewingDlg::SetEditCurrentArgument()
199 const QObject* send = sender();
200 if ( send == GroupPoints->PushButton1 ) {
201 myEditCurrentArgument->setFocus();
202 SelectionIntoArgument();
207 //=================================================================================
208 // function : LineEditReturnPressed()
210 //=================================================================================
211 void RepairGUI_SewingDlg::LineEditReturnPressed()
213 const QObject* send = sender();
214 if( send == GroupPoints->LineEdit1 ) {
215 myEditCurrentArgument = GroupPoints->LineEdit1;
216 GEOMBase_Skeleton::LineEditReturnPressed();
221 //=================================================================================
222 // function : ActivateThisDialog()
224 //=================================================================================
225 void RepairGUI_SewingDlg::ActivateThisDialog()
227 GEOMBase_Skeleton::ActivateThisDialog();
228 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
229 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
231 GroupPoints->LineEdit1->setText( "" );
232 myObject = GEOM::GEOM_Object::_nil();
237 //myGeomGUI->SetState( 0 );
242 //=================================================================================
243 // function : enterEvent()
244 // purpose : Mouse enter onto the dialog to activate it
245 //=================================================================================
246 void RepairGUI_SewingDlg::enterEvent( QEvent* )
248 if ( !mainFrame()->GroupConstructors->isEnabled() )
249 ActivateThisDialog();
253 //=================================================================================
254 // function : createOperation
256 //=================================================================================
257 GEOM::GEOM_IOperations_ptr RepairGUI_SewingDlg::createOperation()
259 return getGeomEngine()->GetIHealingOperations( getStudyId() );
262 //=================================================================================
263 // function : isValid
265 //=================================================================================
266 bool RepairGUI_SewingDlg::isValid( QString& )
269 return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
272 //=================================================================================
273 // function : execute
275 //=================================================================================
276 bool RepairGUI_SewingDlg::execute( ObjectList& objects )
278 bool aResult = false;
279 if ( IsPreview() ) { // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
280 GEOM::ListOfGO_var aClosed, anOpen;
282 aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
285 myClosed = aClosed->length();
286 myOpen = anOpen->length();
288 for ( i = 0; i < myClosed; i++ )
289 objects.push_back( aClosed[i]._retn() );
290 for ( i = 0; i < myOpen; i++ )
291 objects.push_back( anOpen[i]._retn() );
297 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->Sew( myObject, myTolEdt->value() );
298 aResult = !anObj->_is_nil();
300 objects.push_back( anObj._retn() );
306 //=================================================================================
307 // function : initSelection
309 //=================================================================================
310 void RepairGUI_SewingDlg::initSelection()
312 TColStd_MapOfInteger aTypes;
313 aTypes.Add( GEOM_SHELL );
314 aTypes.Add( GEOM_SOLID );
315 aTypes.Add( GEOM_COMPOUND );
316 globalSelection( aTypes );
319 //=================================================================================
320 // function : onDetect
322 //=================================================================================
323 void RepairGUI_SewingDlg::onDetect()
325 displayPreview( false, true, true, 3 );
327 // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
329 if ( myClosed != -1 )
330 msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
332 msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
333 SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg );