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_SewingDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "RepairGUI_SewingDlg.h"
31 #include "SalomeApp_Application.h"
32 #include "SalomeApp_SelectionMgr.h"
33 #include "SUIT_Session.h"
34 #include "SUIT_MessageBox.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "GEOMImpl_Types.hxx"
40 #include <TColStd_MapOfInteger.hxx>
42 #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(QWidget* parent, const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SEWING")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_SEWING_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_SEWING_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_SEWING"));
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 QGridLayout* aLay = new QGridLayout( 0, 2, 2, 0, 6, "aLay" );
76 myTolEdt = new QtxDblSpinBox( 0, 100, 1e-7, GroupPoints->GroupBox1 );//QAD_SpinBoxDbl( GroupPoints->GroupBox1, 0, 100, 1e-7, 10, 1e-10 );
77 myTolEdt->setPrecision( 10 );
78 myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
79 QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->GroupBox1 );
80 myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ), GroupPoints->GroupBox1 );
81 QLabel* aLbl2 = new QLabel( tr( "GEOM_FREE_BOUNDARIES" ), GroupPoints->GroupBox1 );
82 aLay->addWidget( aLbl1, 0, 0 );
83 aLay->addWidget( myTolEdt, 0, 1 );
84 aLay->addWidget( aLbl2, 1, 0 );
85 aLay->addWidget( myFreeBoundBtn, 1, 1 );
87 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 3, 0 );
88 /***************************************************************/
94 //=================================================================================
95 // function : ~RepairGUI_SewingDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 RepairGUI_SewingDlg::~RepairGUI_SewingDlg()
103 //=================================================================================
106 //=================================================================================
107 void RepairGUI_SewingDlg::Init()
110 myEditCurrentArgument = GroupPoints->LineEdit1;
112 myObject = GEOM::GEOM_Object::_nil();
114 //myGeomGUI->SetState( 0 );
120 /* signals and slots connections */
121 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
122 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
123 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
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() )
152 //=================================================================================
153 // function : ClickOnApply()
155 //=================================================================================
156 bool RepairGUI_SewingDlg::ClickOnApply()
163 GroupPoints->LineEdit1->setText("");
164 myObject = GEOM::GEOM_Object::_nil();
172 //=================================================================================
173 // function : ClickOnCancel()
175 //=================================================================================
176 void RepairGUI_SewingDlg::ClickOnCancel()
178 GEOMBase_Skeleton::ClickOnCancel();
182 //=================================================================================
183 // function : SelectionIntoArgument()
184 // purpose : Called when selection
185 //=================================================================================
186 void RepairGUI_SewingDlg::SelectionIntoArgument()
189 myEditCurrentArgument->setText("");
190 myObject = GEOM::GEOM_Object::_nil();
192 if ( IObjectCount() == 1 )
194 Handle(SALOME_InteractiveObject) anIO = firstIObject();
195 Standard_Boolean aRes;
196 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
198 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
202 //=================================================================================
203 // function : SetEditCurrentArgument()
205 //=================================================================================
206 void RepairGUI_SewingDlg::SetEditCurrentArgument()
208 const QObject* send = sender();
209 if ( send == GroupPoints->PushButton1 )
211 myEditCurrentArgument->setFocus();
212 SelectionIntoArgument();
217 //=================================================================================
218 // function : LineEditReturnPressed()
220 //=================================================================================
221 void RepairGUI_SewingDlg::LineEditReturnPressed()
223 const QObject* send = sender();
224 if( send == GroupPoints->LineEdit1 )
226 myEditCurrentArgument = GroupPoints->LineEdit1;
227 GEOMBase_Skeleton::LineEditReturnPressed();
232 //=================================================================================
233 // function : DeactivateActiveDialog()
235 //=================================================================================
236 void RepairGUI_SewingDlg::DeactivateActiveDialog()
238 //myGeomGUI->SetState( -1 );
239 GEOMBase_Skeleton::DeactivateActiveDialog();
243 //=================================================================================
244 // function : ActivateThisDialog()
246 //=================================================================================
247 void RepairGUI_SewingDlg::ActivateThisDialog()
249 GEOMBase_Skeleton::ActivateThisDialog();
250 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
251 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
253 GroupPoints->LineEdit1->setText("");
254 myObject = GEOM::GEOM_Object::_nil();
259 //myGeomGUI->SetState( 0 );
264 //=================================================================================
265 // function : enterEvent()
266 // purpose : Mouse enter onto the dialog to activate it
267 //=================================================================================
268 void RepairGUI_SewingDlg::enterEvent(QEvent* e)
270 if ( !GroupConstructors->isEnabled() )
271 ActivateThisDialog();
275 //=================================================================================
276 // function : closeEvent()
278 //=================================================================================
279 void RepairGUI_SewingDlg::closeEvent(QCloseEvent* e)
281 //myGeomGUI->SetState( -1 );
282 GEOMBase_Skeleton::closeEvent( e );
285 //=================================================================================
286 // function : createOperation
288 //=================================================================================
289 GEOM::GEOM_IOperations_ptr RepairGUI_SewingDlg::createOperation()
291 return getGeomEngine()->GetIHealingOperations( getStudyId() );
294 //=================================================================================
295 // function : isValid
297 //=================================================================================
298 bool RepairGUI_SewingDlg::isValid( QString& msg )
301 return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
304 //=================================================================================
305 // function : execute
307 //=================================================================================
308 bool RepairGUI_SewingDlg::execute( ObjectList& objects )
310 bool aResult = false;
311 if ( IsPreview() ) // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
313 GEOM::ListOfGO_var aClosed, anOpen;
315 aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
319 myClosed = aClosed->length();
320 myOpen = anOpen->length();
322 for ( i = 0; i < myClosed; i++ )
323 objects.push_back( aClosed[i]._retn() );
324 for ( i = 0; i < myOpen; i++ )
325 objects.push_back( anOpen[i]._retn() );
332 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->Sew( myObject, myTolEdt->value() );
333 aResult = !anObj->_is_nil();
335 objects.push_back( anObj._retn() );
341 //=================================================================================
342 // function : initSelection
344 //=================================================================================
345 void RepairGUI_SewingDlg::initSelection()
347 TColStd_MapOfInteger aTypes;
348 aTypes.Add( GEOM_SHELL );
349 aTypes.Add( GEOM_SOLID );
350 aTypes.Add( GEOM_COMPOUND );
351 globalSelection( aTypes );
354 //=================================================================================
355 // function : onDetect
357 //=================================================================================
358 void RepairGUI_SewingDlg::onDetect()
360 displayPreview( false, true, true, 3 );
362 // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
364 if ( myClosed != -1 )
365 msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
367 msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
368 SUIT_MessageBox::info1( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, "Close" );