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"
30 #include "QAD_Desktop.h"
32 #include "GeometryGUI.h"
33 #include "GEOM_Displayer.h"
34 #include "SALOMEGUI_QtCatchCorbaException.hxx"
35 #include "GEOMImpl_Types.hxx"
36 #include "SALOME_Prs.h"
37 #include "SALOME_Selection.h"
39 #include <qlineedit.h>
42 #include <qgroupbox.h>
43 #include <qpushbutton.h>
49 Calss : RepairGUI_FreeBoundDlg
50 Description : Dialog for displaying free boundaries of selected face, shell or solid
54 //=================================================================================
55 // function : RepairGUI_FreeBoundDlg
56 // purpose : Constructor
57 //=================================================================================
58 RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg( QWidget* theParen, SALOME_Selection* theSelection )
59 : QDialog( theParen, "RepairGUI_FreeBoundDlg", false,
60 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
62 setCaption( tr( "CAPTION" ) );
64 QPixmap iconSelect( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr( "ICON_SELECT" ) ) );
66 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FREE_BOUND" ), this );
68 QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
69 aSelGrp->setInsideMargin( 0 );
70 aSelGrp->setFrameStyle( QFrame::NoFrame );
71 new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
72 ( new QPushButton( aSelGrp ) )->setPixmap( iconSelect );
73 myEdit = new QLineEdit( aSelGrp );
74 myEdit->setReadOnly( true );
75 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
77 myClosedLbl = new QLabel( tr( "NUMBER_CLOSED" ), aMainGrp );
78 myOpenLbl = new QLabel( tr( "NUMBER_OPEN" ), aMainGrp );
80 QFrame* aFrame = new QFrame( this );
81 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
82 QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
83 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
84 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
85 aBtnLay->addWidget( aCloseBtn );
86 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
88 QVBoxLayout* aLay = new QVBoxLayout( this );
89 aLay->setSpacing( SPACING );
90 aLay->setMargin( MARGIN );
91 aLay->addWidget( aMainGrp );
92 aLay->addWidget( aFrame );
94 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
99 //=================================================================================
100 // function : ~RepairGUI_FreeBoundDlg
101 // purpose : Destructor
102 //=================================================================================
103 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
107 //=================================================================================
108 // function : onClose
109 // purpose : SLOT. Called when "close" button pressed. Close dialog
110 //=================================================================================
111 void RepairGUI_FreeBoundDlg::onClose()
114 disconnect( mySelection, 0, this, 0 );
115 GeometryGUI::GetGeomGUI()->SetActiveDialogBox( 0 );
120 //=================================================================================
121 // function : onDeactivate
122 // purpose : Deactivate this dialog
123 //=================================================================================
124 void RepairGUI_FreeBoundDlg::onDeactivate()
128 disconnect( mySelection, 0, this, 0 );
129 GeometryGUI::GetGeomGUI()->SetActiveDialogBox( 0 );
132 //=================================================================================
133 // function : onActivate
134 // purpose : Activate this dialog
135 //=================================================================================
136 void RepairGUI_FreeBoundDlg::onActivate()
138 GeometryGUI::GetGeomGUI()->EmitSignalDeactivateDialog();
140 GeometryGUI::GetGeomGUI()->SetActiveDialogBox( this );
141 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
146 //=================================================================================
147 // function : onSelectionDone
148 // purpose : SLOT. Called when selection changed.
149 //=================================================================================
150 void RepairGUI_FreeBoundDlg::onSelectionDone()
152 if( mySelection->IObjectCount() != 1 )
155 Standard_Boolean isOk = Standard_False;
156 GEOM::GEOM_Object_var anObj =
157 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), isOk );
159 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
164 displayPreview( false, true, true, 3 );
169 //=================================================================================
171 // purpose : Initialize dialog fields
172 //=================================================================================
173 void RepairGUI_FreeBoundDlg::Init( SALOME_Selection* theSel )
175 myNbClosed = myNbOpen = 0;
176 myObj = GEOM::GEOM_Object::_nil();
177 mySelection = theSel;
179 GeometryGUI* aGeomGUI = GeometryGUI::GetGeomGUI();
180 connect( aGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
181 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
187 //=================================================================================
188 // function : enterEvent
189 // purpose : Activate dialog
190 //=================================================================================
191 void RepairGUI_FreeBoundDlg::enterEvent( QEvent* e )
196 //=================================================================================
197 // function : closeEvent
198 // purpose : Close dialog
199 //=================================================================================
200 void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* e )
205 //=================================================================================
206 // function : activateSelection
207 // purpose : activate selection of faces, shells, and solids
208 //=================================================================================
209 void RepairGUI_FreeBoundDlg::activateSelection()
211 TColStd_MapOfInteger aMap;
212 aMap.Add( GEOM_FACE );
213 aMap.Add( GEOM_SHELL );
214 aMap.Add( GEOM_SOLID );
215 aMap.Add( GEOM_COMPOUND );
216 globalSelection( aMap );
219 //=================================================================================
220 // function : createOperation
221 // purpose : Create operation
222 //=================================================================================
223 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
225 return getGeomEngine()->GetIHealingOperations( getStudyId() );
228 //=================================================================================
229 // function : isValid
231 //=================================================================================
232 bool RepairGUI_FreeBoundDlg::isValid( QString& msg )
234 return !myObj->_is_nil();
237 //=================================================================================
238 // function : execute
239 // purpose : Get free boundaries
240 //=================================================================================
241 bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
243 if ( !IsPreview() || myObj->_is_nil() )
246 GEOM::ListOfGO_var aClosed, anOpen;
248 bool result = GEOM::GEOM_IHealingOperations::_narrow(
249 getOperation() )->GetFreeBoundary( myObj, aClosed, anOpen );
253 myNbClosed = aClosed->length();
254 myNbOpen = anOpen->length();
256 for ( i = 0; i < myNbClosed; i++ )
257 objects.push_back( aClosed[i]._retn() );
258 for ( i = 0; i < myNbOpen; i++ )
259 objects.push_back( anOpen[i]._retn() );
261 myEdit->setText( GEOMBase::GetName( myObj ) );
262 QString aLabelText = tr( "NUMBER_CLOSED" ) + QString( "%1" ).arg( myNbClosed );
263 myClosedLbl->setText( aLabelText );
264 aLabelText = tr( "NUMBER_OPEN" ) + QString( "%1" ).arg( myNbOpen );
265 myOpenLbl->setText( aLabelText );
269 myEdit->setText( GEOMBase::GetName( myObj ) );
270 myClosedLbl->setText( tr( "NUMBER_CLOSED" ) );
271 myOpenLbl->setText( tr( "NUMBER_OPEN" ) );