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
24 // File : RepairGUI_SewingDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "RepairGUI_SewingDlg.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_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(GeometryGUI* theGeometryGUI, QWidget* parent,
54 const char* name, bool modal, WFlags fl)
55 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
56 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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 setCaption(tr("GEOM_SEWING_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_SEWING_TITLE"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->close(TRUE);
67 RadioButton3->close(TRUE);
69 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_SEWING"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
72 GroupPoints->PushButton1->setPixmap(image1);
73 GroupPoints->LineEdit1->setReadOnly( true );
75 Layout1->addWidget(GroupPoints, 2, 0);
77 QGridLayout* aLay = new QGridLayout( 0, 2, 2, 0, 6, "aLay" );
78 myTolEdt = new QtxDblSpinBox( 0, 100, 1e-7, GroupPoints->GroupBox1 );//QAD_SpinBoxDbl( GroupPoints->GroupBox1, 0, 100, 1e-7, 10, 1e-10 );
79 myTolEdt->setPrecision( 10 );
80 myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
81 QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->GroupBox1 );
82 myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ), GroupPoints->GroupBox1 );
83 QLabel* aLbl2 = new QLabel( tr( "GEOM_FREE_BOUNDARIES" ), GroupPoints->GroupBox1 );
84 aLay->addWidget( aLbl1, 0, 0 );
85 aLay->addWidget( myTolEdt, 0, 1 );
86 aLay->addWidget( aLbl2, 1, 0 );
87 aLay->addWidget( myFreeBoundBtn, 1, 1 );
89 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 3, 0 );
90 /***************************************************************/
92 setHelpFileName("sewing.htm");
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 if ( IObjectCount() == 1 )
182 Handle(SALOME_InteractiveObject) anIO = firstIObject();
183 Standard_Boolean aRes;
184 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
186 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
190 //=================================================================================
191 // function : SetEditCurrentArgument()
193 //=================================================================================
194 void RepairGUI_SewingDlg::SetEditCurrentArgument()
196 const QObject* send = sender();
197 if ( send == GroupPoints->PushButton1 )
199 myEditCurrentArgument->setFocus();
200 SelectionIntoArgument();
205 //=================================================================================
206 // function : LineEditReturnPressed()
208 //=================================================================================
209 void RepairGUI_SewingDlg::LineEditReturnPressed()
211 const QObject* send = sender();
212 if( send == GroupPoints->LineEdit1 )
214 myEditCurrentArgument = GroupPoints->LineEdit1;
215 GEOMBase_Skeleton::LineEditReturnPressed();
220 //=================================================================================
221 // function : ActivateThisDialog()
223 //=================================================================================
224 void RepairGUI_SewingDlg::ActivateThisDialog()
226 GEOMBase_Skeleton::ActivateThisDialog();
227 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
228 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
230 GroupPoints->LineEdit1->setText("");
231 myObject = GEOM::GEOM_Object::_nil();
236 //myGeomGUI->SetState( 0 );
241 //=================================================================================
242 // function : enterEvent()
243 // purpose : Mouse enter onto the dialog to activate it
244 //=================================================================================
245 void RepairGUI_SewingDlg::enterEvent(QEvent* e)
247 if ( !GroupConstructors->isEnabled() )
248 ActivateThisDialog();
252 //=================================================================================
253 // function : closeEvent()
255 //=================================================================================
256 void RepairGUI_SewingDlg::closeEvent(QCloseEvent* e)
258 //myGeomGUI->SetState( -1 );
259 GEOMBase_Skeleton::closeEvent( e );
262 //=================================================================================
263 // function : createOperation
265 //=================================================================================
266 GEOM::GEOM_IOperations_ptr RepairGUI_SewingDlg::createOperation()
268 return getGeomEngine()->GetIHealingOperations( getStudyId() );
271 //=================================================================================
272 // function : isValid
274 //=================================================================================
275 bool RepairGUI_SewingDlg::isValid( QString& msg )
278 return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
281 //=================================================================================
282 // function : execute
284 //=================================================================================
285 bool RepairGUI_SewingDlg::execute( ObjectList& objects )
287 bool aResult = false;
288 if ( IsPreview() ) // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
290 GEOM::ListOfGO_var aClosed, anOpen;
292 aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
296 myClosed = aClosed->length();
297 myOpen = anOpen->length();
299 for ( i = 0; i < myClosed; i++ )
300 objects.push_back( aClosed[i]._retn() );
301 for ( i = 0; i < myOpen; i++ )
302 objects.push_back( anOpen[i]._retn() );
309 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->Sew( myObject, myTolEdt->value() );
310 aResult = !anObj->_is_nil();
312 objects.push_back( anObj._retn() );
318 //=================================================================================
319 // function : initSelection
321 //=================================================================================
322 void RepairGUI_SewingDlg::initSelection()
324 TColStd_MapOfInteger aTypes;
325 aTypes.Add( GEOM_SHELL );
326 aTypes.Add( GEOM_SOLID );
327 aTypes.Add( GEOM_COMPOUND );
328 globalSelection( aTypes );
331 //=================================================================================
332 // function : onDetect
334 //=================================================================================
335 void RepairGUI_SewingDlg::onDetect()
337 displayPreview( false, true, true, 3 );
339 // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
341 if ( myClosed != -1 )
342 msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
344 msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
345 SUIT_MessageBox::info1( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, "Close" );