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_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_SelectionMgr.h"
37 #include "SUIT_Session.h"
39 #include <TColStd_MapOfInteger.hxx>
41 #include <qlineedit.h>
44 #include <qgroupbox.h>
45 #include <qpushbutton.h>
51 Calss : RepairGUI_FreeBoundDlg
52 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 )
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 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
88 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
89 aBtnLay->addWidget( aCloseBtn );
90 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
92 QVBoxLayout* aLay = new QVBoxLayout( this );
93 aLay->setSpacing( SPACING );
94 aLay->setMargin( MARGIN );
95 aLay->addWidget( aMainGrp );
96 aLay->addWidget( aFrame );
98 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
103 //=================================================================================
104 // function : ~RepairGUI_FreeBoundDlg
105 // purpose : Destructor
106 //=================================================================================
107 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
111 //=================================================================================
112 // function : onClose
113 // purpose : SLOT. Called when "close" button pressed. Close dialog
114 //=================================================================================
115 void RepairGUI_FreeBoundDlg::onClose()
118 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
119 myGeomGUI->SetActiveDialogBox( 0 );
124 //=================================================================================
125 // function : onDeactivate
126 // purpose : Deactivate this dialog
127 //=================================================================================
128 void RepairGUI_FreeBoundDlg::onDeactivate()
132 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
133 myGeomGUI->SetActiveDialogBox( 0 );
136 //=================================================================================
137 // function : onActivate
138 // purpose : Activate this dialog
139 //=================================================================================
140 void RepairGUI_FreeBoundDlg::onActivate()
142 myGeomGUI->EmitSignalDeactivateDialog();
144 myGeomGUI->SetActiveDialogBox( this );
145 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
146 SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
151 //=================================================================================
152 // function : onSelectionDone
153 // purpose : SLOT. Called when selection changed.
154 //=================================================================================
155 void RepairGUI_FreeBoundDlg::onSelectionDone()
157 if( IObjectCount() != 1 )
160 Standard_Boolean isOk = Standard_False;
161 GEOM::GEOM_Object_var anObj =
162 GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
164 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
169 displayPreview( false, true, true, 3 );
174 //=================================================================================
176 // purpose : Initialize dialog fields
177 //=================================================================================
178 void RepairGUI_FreeBoundDlg::Init()
180 myNbClosed = myNbOpen = 0;
181 myObj = GEOM::GEOM_Object::_nil();
183 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
184 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
185 SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
191 //=================================================================================
192 // function : enterEvent
193 // purpose : Activate dialog
194 //=================================================================================
195 void RepairGUI_FreeBoundDlg::enterEvent( QEvent* e )
200 //=================================================================================
201 // function : closeEvent
202 // purpose : Close dialog
203 //=================================================================================
204 void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* e )
209 //=================================================================================
210 // function : activateSelection
211 // purpose : activate selection of faces, shells, and solids
212 //=================================================================================
213 void RepairGUI_FreeBoundDlg::activateSelection()
215 TColStd_MapOfInteger aMap;
216 aMap.Add( GEOM_FACE );
217 aMap.Add( GEOM_SHELL );
218 aMap.Add( GEOM_SOLID );
219 aMap.Add( GEOM_COMPOUND );
220 globalSelection( aMap );
223 //=================================================================================
224 // function : createOperation
225 // purpose : Create operation
226 //=================================================================================
227 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
229 return getGeomEngine()->GetIHealingOperations( getStudyId() );
232 //=================================================================================
233 // function : isValid
235 //=================================================================================
236 bool RepairGUI_FreeBoundDlg::isValid( QString& msg )
238 return !myObj->_is_nil();
241 //=================================================================================
242 // function : execute
243 // purpose : Get free boundaries
244 //=================================================================================
245 bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
247 if ( !IsPreview() || myObj->_is_nil() )
250 GEOM::ListOfGO_var aClosed, anOpen;
252 bool result = GEOM::GEOM_IHealingOperations::_narrow(
253 getOperation() )->GetFreeBoundary( myObj, aClosed, anOpen );
257 myNbClosed = aClosed->length();
258 myNbOpen = anOpen->length();
260 for ( i = 0; i < myNbClosed; i++ )
261 objects.push_back( aClosed[i]._retn() );
262 for ( i = 0; i < myNbOpen; i++ )
263 objects.push_back( anOpen[i]._retn() );
265 myEdit->setText( GEOMBase::GetName( myObj ) );
266 QString aLabelText = tr( "NUMBER_CLOSED" ) + QString( "%1" ).arg( myNbClosed );
267 myClosedLbl->setText( aLabelText );
268 aLabelText = tr( "NUMBER_OPEN" ) + QString( "%1" ).arg( myNbOpen );
269 myOpenLbl->setText( aLabelText );
273 myEdit->setText( GEOMBase::GetName( myObj ) );
274 myClosedLbl->setText( tr( "NUMBER_CLOSED" ) );
275 myOpenLbl->setText( tr( "NUMBER_OPEN" ) );