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 "SalomeApp_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 ),
65 setCaption( tr( "CAPTION" ) );
67 QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr( "ICON_SELECT" ) ) );
69 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FREE_BOUND" ), this );
71 QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
72 aSelGrp->setInsideMargin( 0 );
73 aSelGrp->setFrameStyle( QFrame::NoFrame );
74 new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
75 ( new QPushButton( aSelGrp ) )->setPixmap( iconSelect );
76 myEdit = new QLineEdit( aSelGrp );
77 myEdit->setReadOnly( true );
78 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
80 myClosedLbl = new QLabel( tr( "NUMBER_CLOSED" ), aMainGrp );
81 myOpenLbl = new QLabel( tr( "NUMBER_OPEN" ), aMainGrp );
83 QFrame* aFrame = new QFrame( this );
84 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
85 QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
86 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
87 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
88 aBtnLay->addWidget( aCloseBtn );
89 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
91 QVBoxLayout* aLay = new QVBoxLayout( this );
92 aLay->setSpacing( SPACING );
93 aLay->setMargin( MARGIN );
94 aLay->addWidget( aMainGrp );
95 aLay->addWidget( aFrame );
97 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
102 //=================================================================================
103 // function : ~RepairGUI_FreeBoundDlg
104 // purpose : Destructor
105 //=================================================================================
106 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
110 //=================================================================================
111 // function : onClose
112 // purpose : SLOT. Called when "close" button pressed. Close dialog
113 //=================================================================================
114 void RepairGUI_FreeBoundDlg::onClose()
117 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
118 myGeomGUI->SetActiveDialogBox( 0 );
123 //=================================================================================
124 // function : onDeactivate
125 // purpose : Deactivate this dialog
126 //=================================================================================
127 void RepairGUI_FreeBoundDlg::onDeactivate()
131 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
132 myGeomGUI->SetActiveDialogBox( 0 );
135 //=================================================================================
136 // function : onActivate
137 // purpose : Activate this dialog
138 //=================================================================================
139 void RepairGUI_FreeBoundDlg::onActivate()
141 myGeomGUI->EmitSignalDeactivateDialog();
143 myGeomGUI->SetActiveDialogBox( this );
144 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
145 SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
150 //=================================================================================
151 // function : onSelectionDone
152 // purpose : SLOT. Called when selection changed.
153 //=================================================================================
154 void RepairGUI_FreeBoundDlg::onSelectionDone()
156 if( IObjectCount() != 1 )
159 Standard_Boolean isOk = Standard_False;
160 GEOM::GEOM_Object_var anObj =
161 GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
163 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
168 displayPreview( false, true, true, 3 );
173 //=================================================================================
175 // purpose : Initialize dialog fields
176 //=================================================================================
177 void RepairGUI_FreeBoundDlg::Init()
179 myNbClosed = myNbOpen = 0;
180 myObj = GEOM::GEOM_Object::_nil();
182 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
183 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
184 SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
190 //=================================================================================
191 // function : enterEvent
192 // purpose : Activate dialog
193 //=================================================================================
194 void RepairGUI_FreeBoundDlg::enterEvent( QEvent* e )
199 //=================================================================================
200 // function : closeEvent
201 // purpose : Close dialog
202 //=================================================================================
203 void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* e )
208 //=================================================================================
209 // function : activateSelection
210 // purpose : activate selection of faces, shells, and solids
211 //=================================================================================
212 void RepairGUI_FreeBoundDlg::activateSelection()
214 TColStd_MapOfInteger aMap;
215 aMap.Add( GEOM_FACE );
216 aMap.Add( GEOM_SHELL );
217 aMap.Add( GEOM_SOLID );
218 aMap.Add( GEOM_COMPOUND );
219 globalSelection( aMap );
222 //=================================================================================
223 // function : createOperation
224 // purpose : Create operation
225 //=================================================================================
226 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
228 return getGeomEngine()->GetIHealingOperations( getStudyId() );
231 //=================================================================================
232 // function : isValid
234 //=================================================================================
235 bool RepairGUI_FreeBoundDlg::isValid( QString& msg )
237 return !myObj->_is_nil();
240 //=================================================================================
241 // function : execute
242 // purpose : Get free boundaries
243 //=================================================================================
244 bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
246 if ( !IsPreview() || myObj->_is_nil() )
249 GEOM::ListOfGO_var aClosed, anOpen;
251 bool result = GEOM::GEOM_IHealingOperations::_narrow(
252 getOperation() )->GetFreeBoundary( myObj, aClosed, anOpen );
256 myNbClosed = aClosed->length();
257 myNbOpen = anOpen->length();
259 for ( i = 0; i < myNbClosed; i++ )
260 objects.push_back( aClosed[i]._retn() );
261 for ( i = 0; i < myNbOpen; i++ )
262 objects.push_back( anOpen[i]._retn() );
264 myEdit->setText( GEOMBase::GetName( myObj ) );
265 QString aLabelText = tr( "NUMBER_CLOSED" ) + QString( "%1" ).arg( myNbClosed );
266 myClosedLbl->setText( aLabelText );
267 aLabelText = tr( "NUMBER_OPEN" ) + QString( "%1" ).arg( myNbOpen );
268 myOpenLbl->setText( aLabelText );
272 myEdit->setText( GEOMBase::GetName( myObj ) );
273 myClosedLbl->setText( tr( "NUMBER_CLOSED" ) );
274 myOpenLbl->setText( tr( "NUMBER_OPEN" ) );
280 //=================================================================================
281 // function : getDesktop()
283 //=================================================================================
284 SUIT_Desktop* RepairGUI_FreeBoundDlg::getDesktop() const
286 return dynamic_cast<SUIT_Desktop*>( parentWidget() );