1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : RepairGUI_FreeBoundDlg.cxx
24 // Author : Sergey LITONIN
28 #include "RepairGUI_FreeBoundDlg.h"
30 #include "GeometryGUI.h"
31 #include "GEOM_Displayer.h"
32 #include "GEOMImpl_Types.hxx"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_Application.h"
36 #include "LightApp_SelectionMgr.h"
37 #include "SUIT_MessageBox.h"
38 #include "SUIT_Session.h"
40 #include <TColStd_MapOfInteger.hxx>
42 #include <qlineedit.h>
45 #include <qgroupbox.h>
46 #include <qpushbutton.h>
52 Class : RepairGUI_FreeBoundDlg
53 Description : Dialog for displaying free boundaries of selected face, shell or solid
56 //=================================================================================
57 // function : RepairGUI_FreeBoundDlg
58 // purpose : Constructor
59 //=================================================================================
60 RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg(GeometryGUI* theGUI, QWidget* theParent, const char*)
61 : QDialog( theParent, "RepairGUI_FreeBoundDlg", false,
62 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
63 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( theParent ) ),
66 setCaption( tr( "CAPTION" ) );
68 QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr( "ICON_SELECT" ) ) );
70 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FREE_BOUND" ), this );
72 QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
73 aSelGrp->setInsideMargin( 0 );
74 aSelGrp->setFrameStyle( QFrame::NoFrame );
75 new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
76 ( new QPushButton( aSelGrp ) )->setPixmap( iconSelect );
77 myEdit = new QLineEdit( aSelGrp );
78 myEdit->setReadOnly( true );
79 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
81 myClosedLbl = new QLabel( tr( "NUMBER_CLOSED" ), aMainGrp );
82 myOpenLbl = new QLabel( tr( "NUMBER_OPEN" ), aMainGrp );
84 QFrame* aFrame = new QFrame( this );
85 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
86 QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
87 QPushButton* aHelpBtn = new QPushButton( tr( "GEOM_BUT_HELP" ), aFrame );
88 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
89 aBtnLay->addWidget( aCloseBtn );
90 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
91 aBtnLay->addWidget( aHelpBtn );
93 QVBoxLayout* aLay = new QVBoxLayout( this );
94 aLay->setSpacing( SPACING );
95 aLay->setMargin( MARGIN );
96 aLay->addWidget( aMainGrp );
97 aLay->addWidget( aFrame );
99 //myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#free_boundaries";
100 myHelpFileName = "using_measurement_tools_page.html#boundaries_anchor";
102 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
103 connect( aHelpBtn, SIGNAL( clicked() ), SLOT( onHelp() ) );
108 //=================================================================================
109 // function : ~RepairGUI_FreeBoundDlg
110 // purpose : Destructor
111 //=================================================================================
112 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
116 //=================================================================================
117 // function : onClose
118 // purpose : SLOT. Called when "close" button pressed. Close dialog
119 //=================================================================================
120 void RepairGUI_FreeBoundDlg::onClose()
123 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
124 myGeomGUI->SetActiveDialogBox( 0 );
129 //=================================================================================
130 // function : onHelp()
132 //=================================================================================
133 void RepairGUI_FreeBoundDlg::onHelp()
135 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
137 app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
141 platform = "winapplication";
143 platform = "application";
145 SUIT_MessageBox::warn1
146 (0, tr("WRN_WARNING"), tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
147 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
152 //=================================================================================
153 // function : onDeactivate
154 // purpose : Deactivate this dialog
155 //=================================================================================
156 void RepairGUI_FreeBoundDlg::onDeactivate()
160 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
161 myGeomGUI->SetActiveDialogBox( 0 );
164 //=================================================================================
165 // function : onActivate
166 // purpose : Activate this dialog
167 //=================================================================================
168 void RepairGUI_FreeBoundDlg::onActivate()
170 myGeomGUI->EmitSignalDeactivateDialog();
172 myGeomGUI->SetActiveDialogBox( this );
173 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
174 SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
179 //=================================================================================
180 // function : onSelectionDone
181 // purpose : SLOT. Called when selection changed.
182 //=================================================================================
183 void RepairGUI_FreeBoundDlg::onSelectionDone()
185 if( IObjectCount() != 1 )
188 Standard_Boolean isOk = Standard_False;
189 GEOM::GEOM_Object_var anObj =
190 GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
192 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
197 displayPreview( false, true, true, 3 );
201 //=================================================================================
203 // purpose : Initialize dialog fields
204 //=================================================================================
205 void RepairGUI_FreeBoundDlg::Init()
207 myNbClosed = myNbOpen = 0;
208 myObj = GEOM::GEOM_Object::_nil();
210 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
211 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
212 SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
218 //=================================================================================
219 // function : enterEvent
220 // purpose : Activate dialog
221 //=================================================================================
222 void RepairGUI_FreeBoundDlg::enterEvent( QEvent* e )
227 //=================================================================================
228 // function : closeEvent
229 // purpose : Close dialog
230 //=================================================================================
231 void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* e )
236 //=================================================================================
237 // function : activateSelection
238 // purpose : activate selection of faces, shells, and solids
239 //=================================================================================
240 void RepairGUI_FreeBoundDlg::activateSelection()
242 TColStd_MapOfInteger aMap;
243 aMap.Add( GEOM_FACE );
244 aMap.Add( GEOM_SHELL );
245 aMap.Add( GEOM_SOLID );
246 aMap.Add( GEOM_COMPOUND );
247 globalSelection( aMap );
250 //=================================================================================
251 // function : createOperation
252 // purpose : Create operation
253 //=================================================================================
254 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
256 return getGeomEngine()->GetIHealingOperations( getStudyId() );
259 //=================================================================================
260 // function : isValid
262 //=================================================================================
263 bool RepairGUI_FreeBoundDlg::isValid( QString& msg )
265 return !myObj->_is_nil();
268 //=================================================================================
269 // function : execute
270 // purpose : Get free boundaries
271 //=================================================================================
272 bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
274 if ( !IsPreview() || myObj->_is_nil() )
277 GEOM::ListOfGO_var aClosed, anOpen;
279 bool result = GEOM::GEOM_IHealingOperations::_narrow(
280 getOperation() )->GetFreeBoundary( myObj, aClosed, anOpen );
284 myNbClosed = aClosed->length();
285 myNbOpen = anOpen->length();
287 for ( i = 0; i < myNbClosed; i++ )
288 objects.push_back( aClosed[i]._retn() );
289 for ( i = 0; i < myNbOpen; i++ )
290 objects.push_back( anOpen[i]._retn() );
292 myEdit->setText( GEOMBase::GetName( myObj ) );
293 QString aLabelText = tr( "NUMBER_CLOSED" ) + QString( "%1" ).arg( myNbClosed );
294 myClosedLbl->setText( aLabelText );
295 aLabelText = tr( "NUMBER_OPEN" ) + QString( "%1" ).arg( myNbOpen );
296 myOpenLbl->setText( aLabelText );
300 myEdit->setText( GEOMBase::GetName( myObj ) );
301 myClosedLbl->setText( tr( "NUMBER_CLOSED" ) );
302 myOpenLbl->setText( tr( "NUMBER_OPEN" ) );
308 //=================================================================================
309 // function : keyPressEvent()
311 //=================================================================================
312 void RepairGUI_FreeBoundDlg::keyPressEvent( QKeyEvent* e )
314 QDialog::keyPressEvent( e );
315 if ( e->isAccepted() )
318 if ( e->key() == Key_F1 )