1 // Copyright (C) 2007-2013 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : RepairGUI_SewingDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "RepairGUI_SewingDlg.h"
30 #include <GeometryGUI.h>
32 #include <SalomeApp_DoubleSpinBox.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_ResourceMgr.h>
40 #include <GEOMImpl_Types.hxx>
43 #include <TColStd_MapOfInteger.hxx>
45 #define DEFAULT_TOLERANCE_VALUE 1e-07
47 //=================================================================================
48 // class : RepairGUI_SewingDlg()
49 // purpose : Constructs a RepairGUI_SewingDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 RepairGUI_SewingDlg::RepairGUI_SewingDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
56 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
58 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SEWING" ) ) );
59 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
61 setWindowTitle( tr( "GEOM_SEWING_TITLE" ) );
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SEWING_TITLE" ) );
65 mainFrame()->RadioButton1->setIcon( image0 );
66 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton2->close();
68 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton3->close();
71 GroupPoints = new DlgRef_1SelExt( centralWidget() );
72 GroupPoints->GroupBox1->setTitle( tr( "GEOM_SEWING" ) );
73 GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
74 GroupPoints->PushButton1->setIcon( image1 );
75 GroupPoints->LineEdit1->setReadOnly( true );
77 QGridLayout* aLay = new QGridLayout( GroupPoints->Box );
78 aLay->setMargin( 0 ); aLay->setSpacing( 6 );
79 myAllowNonManifoldChk = new QCheckBox (tr("GEOM_ALLOW_NON_MANIFOLD"), GroupPoints->Box);
80 myTolEdt = new SalomeApp_DoubleSpinBox( GroupPoints->Box );
81 initSpinBox( myTolEdt, 0.0, 100.0, DEFAULT_TOLERANCE_VALUE, "len_tol_precision" );
82 myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
83 QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->Box );
84 myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GEOM_FREE_BOUNDARIES" ) ),
86 aLay->addWidget( myAllowNonManifoldChk, 0, 0 );
87 aLay->addWidget( aLbl1, 1, 0 );
88 aLay->addWidget( myTolEdt, 1, 1 );
89 aLay->addWidget( myFreeBoundBtn, 2, 0, 1, 2 );
91 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
92 layout->setMargin( 0 ); layout->setSpacing( 6 );
93 layout->addWidget( GroupPoints );
94 /***************************************************************/
96 setHelpFileName( "sewing_operation_page.html" );
102 //=================================================================================
103 // function : ~RepairGUI_SewingDlg()
104 // purpose : Destroys the object and frees any allocated resources
105 //=================================================================================
106 RepairGUI_SewingDlg::~RepairGUI_SewingDlg()
111 //=================================================================================
114 //=================================================================================
115 void RepairGUI_SewingDlg::Init()
118 myEditCurrentArgument = GroupPoints->LineEdit1;
120 myObject = GEOM::GEOM_Object::_nil();
122 //myGeomGUI->SetState( 0 );
128 /* signals and slots connections */
129 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
130 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
132 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
133 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
135 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
136 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
138 connect( myFreeBoundBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
140 initName( tr( "SEWING_NEW_OBJ_NAME" ) );
142 SelectionIntoArgument();
146 //=================================================================================
147 // function : ClickOnOk()
148 // purpose : Same than click on apply but close this dialog.
149 //=================================================================================
150 void RepairGUI_SewingDlg::ClickOnOk()
152 setIsApplyAndClose( true );
153 if ( ClickOnApply() )
157 //=================================================================================
158 // function : ClickOnApply()
160 //=================================================================================
161 bool RepairGUI_SewingDlg::ClickOnApply()
168 GroupPoints->LineEdit1->setText( "" );
169 myObject = GEOM::GEOM_Object::_nil();
177 //=================================================================================
178 // function : SelectionIntoArgument()
179 // purpose : Called when selection
180 //=================================================================================
181 void RepairGUI_SewingDlg::SelectionIntoArgument()
184 myEditCurrentArgument->setText( "" );
185 myObject = GEOM::GEOM_Object::_nil();
187 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
188 SALOME_ListIO aSelList;
189 aSelMgr->selectedObjects(aSelList);
191 if ( aSelList.Extent() == 1 ) {
192 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
193 myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
194 if ( !CORBA::is_nil( myObject ) )
195 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
199 //=================================================================================
200 // function : SetEditCurrentArgument()
202 //=================================================================================
203 void RepairGUI_SewingDlg::SetEditCurrentArgument()
205 const QObject* send = sender();
206 if ( send == GroupPoints->PushButton1 ) {
207 myEditCurrentArgument->setFocus();
208 SelectionIntoArgument();
213 //=================================================================================
214 // function : LineEditReturnPressed()
216 //=================================================================================
217 void RepairGUI_SewingDlg::LineEditReturnPressed()
219 const QObject* send = sender();
220 if( send == GroupPoints->LineEdit1 ) {
221 myEditCurrentArgument = GroupPoints->LineEdit1;
222 GEOMBase_Skeleton::LineEditReturnPressed();
227 //=================================================================================
228 // function : ActivateThisDialog()
230 //=================================================================================
231 void RepairGUI_SewingDlg::ActivateThisDialog()
233 GEOMBase_Skeleton::ActivateThisDialog();
234 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
235 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
237 GroupPoints->LineEdit1->setText( "" );
238 myObject = GEOM::GEOM_Object::_nil();
243 //myGeomGUI->SetState( 0 );
248 //=================================================================================
249 // function : enterEvent()
250 // purpose : Mouse enter onto the dialog to activate it
251 //=================================================================================
252 void RepairGUI_SewingDlg::enterEvent( QEvent* )
254 if ( !mainFrame()->GroupConstructors->isEnabled() )
255 ActivateThisDialog();
259 //=================================================================================
260 // function : createOperation
262 //=================================================================================
263 GEOM::GEOM_IOperations_ptr RepairGUI_SewingDlg::createOperation()
265 return getGeomEngine()->GetIHealingOperations( getStudyId() );
268 //=================================================================================
269 // function : isValid
271 //=================================================================================
272 bool RepairGUI_SewingDlg::isValid( QString& msg )
275 bool ok = myTolEdt->isValid( msg, !IsPreview() );
276 return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. ) && ok;
279 //=================================================================================
280 // function : execute
282 //=================================================================================
283 bool RepairGUI_SewingDlg::execute( ObjectList& objects )
285 bool aResult = false;
286 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
288 if ( IsPreview() ) { // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
289 GEOM::ListOfGO_var aClosed, anOpen;
291 aResult = anOper->GetFreeBoundary( myObject, aClosed, anOpen );
294 myClosed = aClosed->length();
295 myOpen = anOpen->length();
297 for ( i = 0; i < myClosed; i++ )
298 objects.push_back( aClosed[i]._retn() );
299 for ( i = 0; i < myOpen; i++ )
300 objects.push_back( anOpen[i]._retn() );
306 GEOM::GEOM_Object_var anObj;
308 if (myAllowNonManifoldChk->isChecked()) {
309 anObj = anOper->SewAllowNonManifold( myObject, myTolEdt->value() );
311 anObj = anOper->Sew( myObject, myTolEdt->value() );
314 aResult = !anObj->_is_nil();
319 QStringList aParameters;
320 aParameters << myTolEdt->text();
321 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
323 objects.push_back( anObj._retn() );
330 //=================================================================================
331 // function : initSelection
333 //=================================================================================
334 void RepairGUI_SewingDlg::initSelection()
336 TColStd_MapOfInteger aTypes;
337 aTypes.Add( GEOM_SHELL );
338 aTypes.Add( GEOM_SOLID );
339 aTypes.Add( GEOM_COMPOUND );
340 globalSelection( aTypes );
343 //=================================================================================
344 // function : onDetect
346 //=================================================================================
347 void RepairGUI_SewingDlg::onDetect()
349 displayPreview( true, false, true, true, 3 );
351 // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
353 if ( myClosed != -1 )
354 msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
356 msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
357 SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg );