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_FreeBoundDlg.cxx
25 // Author : Sergey LITONIN
29 #include "RepairGUI_FreeBoundDlg.h"
31 #include "GeometryGUI.h"
32 #include "GEOM_Displayer.h"
33 #include "GEOMImpl_Types.hxx"
35 #include "SalomeApp_Application.h"
36 #include "LightApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
38 #include "SUIT_MessageBox.h"
39 #include "SUIT_Session.h"
41 #include <TColStd_MapOfInteger.hxx>
43 #include <qlineedit.h>
46 #include <qgroupbox.h>
47 #include <qpushbutton.h>
53 Class : RepairGUI_FreeBoundDlg
54 Description : Dialog for displaying free boundaries of selected face, shell or solid
57 //=================================================================================
58 // function : RepairGUI_FreeBoundDlg
59 // purpose : Constructor
60 //=================================================================================
61 RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg(GeometryGUI* theGUI, QWidget* theParent, const char*)
62 : QDialog( theParent, "RepairGUI_FreeBoundDlg", false,
63 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
64 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( theParent ) ),
67 setCaption( tr( "CAPTION" ) );
69 QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr( "ICON_SELECT" ) ) );
71 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FREE_BOUND" ), this );
73 QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
74 aSelGrp->setInsideMargin( 0 );
75 aSelGrp->setFrameStyle( QFrame::NoFrame );
76 new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
77 ( new QPushButton( aSelGrp ) )->setPixmap( iconSelect );
78 myEdit = new QLineEdit( aSelGrp );
79 myEdit->setReadOnly( true );
80 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
82 myClosedLbl = new QLabel( tr( "NUMBER_CLOSED" ), aMainGrp );
83 myOpenLbl = new QLabel( tr( "NUMBER_OPEN" ), aMainGrp );
85 QFrame* aFrame = new QFrame( this );
86 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
87 QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
88 QPushButton* aHelpBtn = new QPushButton( tr( "GEOM_BUT_HELP" ), aFrame );
89 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
90 aBtnLay->addWidget( aCloseBtn );
91 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
92 aBtnLay->addWidget( aHelpBtn );
94 QVBoxLayout* aLay = new QVBoxLayout( this );
95 aLay->setSpacing( SPACING );
96 aLay->setMargin( MARGIN );
97 aLay->addWidget( aMainGrp );
98 aLay->addWidget( aFrame );
100 //myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#free_boundaries";
101 myHelpFileName = "using_measurement_tools_page.html#boundaries_anchor";
103 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
104 connect( aHelpBtn, SIGNAL( clicked() ), SLOT( onHelp() ) );
109 //=================================================================================
110 // function : ~RepairGUI_FreeBoundDlg
111 // purpose : Destructor
112 //=================================================================================
113 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
117 //=================================================================================
118 // function : onClose
119 // purpose : SLOT. Called when "close" button pressed. Close dialog
120 //=================================================================================
121 void RepairGUI_FreeBoundDlg::onClose()
124 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
125 myGeomGUI->SetActiveDialogBox( 0 );
130 //=================================================================================
131 // function : onHelp()
133 //=================================================================================
134 void RepairGUI_FreeBoundDlg::onHelp()
136 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
138 app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
142 platform = "winapplication";
144 platform = "application";
146 SUIT_MessageBox::warn1
147 (0, tr("WRN_WARNING"), tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
148 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
153 //=================================================================================
154 // function : onDeactivate
155 // purpose : Deactivate this dialog
156 //=================================================================================
157 void RepairGUI_FreeBoundDlg::onDeactivate()
161 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
162 myGeomGUI->SetActiveDialogBox( 0 );
165 //=================================================================================
166 // function : onActivate
167 // purpose : Activate this dialog
168 //=================================================================================
169 void RepairGUI_FreeBoundDlg::onActivate()
171 myGeomGUI->EmitSignalDeactivateDialog();
173 myGeomGUI->SetActiveDialogBox( this );
174 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
175 SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
180 //=================================================================================
181 // function : onSelectionDone
182 // purpose : SLOT. Called when selection changed.
183 //=================================================================================
184 void RepairGUI_FreeBoundDlg::onSelectionDone()
186 if( IObjectCount() != 1 )
189 Standard_Boolean isOk = Standard_False;
190 GEOM::GEOM_Object_var anObj =
191 GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
193 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
198 displayPreview( false, true, true, 3 );
202 //=================================================================================
204 // purpose : Initialize dialog fields
205 //=================================================================================
206 void RepairGUI_FreeBoundDlg::Init()
208 myNbClosed = myNbOpen = 0;
209 myObj = GEOM::GEOM_Object::_nil();
211 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
212 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
213 SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
219 //=================================================================================
220 // function : enterEvent
221 // purpose : Activate dialog
222 //=================================================================================
223 void RepairGUI_FreeBoundDlg::enterEvent( QEvent* e )
228 //=================================================================================
229 // function : closeEvent
230 // purpose : Close dialog
231 //=================================================================================
232 void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* e )
237 //=================================================================================
238 // function : activateSelection
239 // purpose : activate selection of faces, shells, and solids
240 //=================================================================================
241 void RepairGUI_FreeBoundDlg::activateSelection()
243 TColStd_MapOfInteger aMap;
244 aMap.Add( GEOM_FACE );
245 aMap.Add( GEOM_SHELL );
246 aMap.Add( GEOM_SOLID );
247 aMap.Add( GEOM_COMPOUND );
248 globalSelection( aMap );
251 //=================================================================================
252 // function : createOperation
253 // purpose : Create operation
254 //=================================================================================
255 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
257 return getGeomEngine()->GetIHealingOperations( getStudyId() );
260 //=================================================================================
261 // function : isValid
263 //=================================================================================
264 bool RepairGUI_FreeBoundDlg::isValid( QString& msg )
266 return !myObj->_is_nil();
269 //=================================================================================
270 // function : execute
271 // purpose : Get free boundaries
272 //=================================================================================
273 bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
275 if ( !IsPreview() || myObj->_is_nil() )
278 GEOM::ListOfGO_var aClosed, anOpen;
280 bool result = GEOM::GEOM_IHealingOperations::_narrow(
281 getOperation() )->GetFreeBoundary( myObj, aClosed, anOpen );
285 myNbClosed = aClosed->length();
286 myNbOpen = anOpen->length();
288 for ( i = 0; i < myNbClosed; i++ )
289 objects.push_back( aClosed[i]._retn() );
290 for ( i = 0; i < myNbOpen; i++ )
291 objects.push_back( anOpen[i]._retn() );
293 myEdit->setText( GEOMBase::GetName( myObj ) );
294 QString aLabelText = tr( "NUMBER_CLOSED" ) + QString( "%1" ).arg( myNbClosed );
295 myClosedLbl->setText( aLabelText );
296 aLabelText = tr( "NUMBER_OPEN" ) + QString( "%1" ).arg( myNbOpen );
297 myOpenLbl->setText( aLabelText );
301 myEdit->setText( GEOMBase::GetName( myObj ) );
302 myClosedLbl->setText( tr( "NUMBER_CLOSED" ) );
303 myOpenLbl->setText( tr( "NUMBER_OPEN" ) );
309 //=================================================================================
310 // function : keyPressEvent()
312 //=================================================================================
313 void RepairGUI_FreeBoundDlg::keyPressEvent( QKeyEvent* e )
315 QDialog::keyPressEvent( e );
316 if ( e->isAccepted() )
319 if ( e->key() == Key_F1 )