Salome HOME
cdc78cb2b8d34dece3c2442afbe8407f969c72df
[modules/geom.git] / src / RepairGUI / RepairGUI_FreeBoundDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : RepairGUI_FreeBoundDlg.cxx
25 //  Author : Sergey LITONIN
26 //  Module : GEOM
27 //  $Header$
28
29 #include "RepairGUI_FreeBoundDlg.h"
30 #include "QAD_Desktop.h"
31 #include "GEOMBase.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"
38
39 #include <qlineedit.h>
40 #include <qlabel.h>
41 #include <qlayout.h>
42 #include <qgroupbox.h>
43 #include <qpushbutton.h>
44
45 #define SPACING 5
46 #define MARGIN 10
47
48 /*
49   Calss       : RepairGUI_FreeBoundDlg
50   Description : Dialog for displaying free boundaries of selected face, shell or solid
51 */
52
53
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 )
61 {
62   setCaption( tr( "CAPTION" ) );
63
64   QPixmap iconSelect( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr( "ICON_SELECT" ) ) );
65   
66   QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FREE_BOUND" ), this );
67   
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 ) );
76
77   myClosedLbl = new QLabel( tr( "NUMBER_CLOSED" ), aMainGrp );
78   myOpenLbl = new QLabel( tr( "NUMBER_OPEN" ), aMainGrp );
79
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 ) );
87
88   QVBoxLayout* aLay = new QVBoxLayout( this );
89   aLay->setSpacing( SPACING );
90   aLay->setMargin( MARGIN );
91   aLay->addWidget( aMainGrp );
92   aLay->addWidget( aFrame );
93   
94   connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
95
96   Init( theSelection );
97 }
98
99 //=================================================================================
100 // function : ~RepairGUI_FreeBoundDlg
101 // purpose  : Destructor
102 //=================================================================================
103 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
104 {
105 }
106
107 //=================================================================================
108 // function : onClose
109 // purpose  : SLOT. Called when "close" button pressed. Close dialog
110 //=================================================================================
111 void RepairGUI_FreeBoundDlg::onClose()
112 {
113   globalSelection();
114   disconnect( mySelection, 0, this, 0 );
115   GeometryGUI::GetGeomGUI()->SetActiveDialogBox( 0 );
116   reject();
117   erasePreview();
118 }
119
120 //=================================================================================
121 // function : onDeactivate
122 // purpose  : Deactivate this dialog
123 //=================================================================================
124 void RepairGUI_FreeBoundDlg::onDeactivate()
125 {
126   setEnabled(false);
127   globalSelection();
128   disconnect( mySelection, 0, this, 0 );
129   GeometryGUI::GetGeomGUI()->SetActiveDialogBox( 0 );
130 }
131
132 //=================================================================================
133 // function : onActivate
134 // purpose  : Activate this dialog
135 //=================================================================================
136 void RepairGUI_FreeBoundDlg::onActivate()
137 {
138   GeometryGUI::GetGeomGUI()->EmitSignalDeactivateDialog();
139   setEnabled( true );
140   GeometryGUI::GetGeomGUI()->SetActiveDialogBox( this );
141   connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT  ( onSelectionDone() ) );
142   activateSelection();
143   onSelectionDone();
144 }
145
146 //=================================================================================
147 // function : onSelectionDone
148 // purpose  : SLOT. Called when selection changed.
149 //=================================================================================
150 void RepairGUI_FreeBoundDlg::onSelectionDone()
151 {
152   if( mySelection->IObjectCount() != 1 )
153     return;
154
155   Standard_Boolean isOk = Standard_False;
156   GEOM::GEOM_Object_var anObj =
157     GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), isOk );
158
159   if ( !isOk || anObj->_is_nil() || anObj->GetType() == GEOM_MARKER )
160     return;
161   else
162   {
163     myObj = anObj;
164     displayPreview( false, true, true, 3 );
165   }
166
167 }
168
169 //=================================================================================
170 // function : Init
171 // purpose  : Initialize dialog fields
172 //=================================================================================
173 void RepairGUI_FreeBoundDlg::Init( SALOME_Selection* theSel )
174 {
175   myNbClosed = myNbOpen = 0;
176   myObj = GEOM::GEOM_Object::_nil();
177   mySelection = theSel;
178
179   GeometryGUI* aGeomGUI = GeometryGUI::GetGeomGUI();
180   connect( aGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT  ( onDeactivate() ) );
181   connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT  ( onSelectionDone() ) );
182
183   activateSelection();
184   onSelectionDone();
185 }
186
187 //=================================================================================
188 // function : enterEvent
189 // purpose  : Activate dialog
190 //=================================================================================
191 void RepairGUI_FreeBoundDlg::enterEvent( QEvent* e )
192 {
193   onActivate();
194 }
195
196 //=================================================================================
197 // function : closeEvent
198 // purpose  : Close dialog
199 //=================================================================================
200 void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* e )
201 {
202   onClose();
203 }
204
205 //=================================================================================
206 // function : activateSelection
207 // purpose  : activate selection of faces, shells, and solids
208 //=================================================================================
209 void RepairGUI_FreeBoundDlg::activateSelection()
210 {
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 );
217 }
218
219 //=================================================================================
220 // function : createOperation
221 // purpose  : Create operation
222 //=================================================================================
223 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
224 {
225   return getGeomEngine()->GetIHealingOperations( getStudyId() );
226 }
227
228 //=================================================================================
229 // function : isValid
230 // purpose  :
231 //=================================================================================
232 bool RepairGUI_FreeBoundDlg::isValid( QString& msg )
233 {
234   return !myObj->_is_nil();
235 }
236
237 //=================================================================================
238 // function : execute
239 // purpose  : Get free boundaries
240 //=================================================================================
241 bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
242 {
243   if ( !IsPreview() || myObj->_is_nil() )
244     return false;
245
246   GEOM::ListOfGO_var aClosed, anOpen;
247
248   bool result = GEOM::GEOM_IHealingOperations::_narrow(
249     getOperation() )->GetFreeBoundary( myObj, aClosed, anOpen );
250
251   if ( result )
252   {
253     myNbClosed = aClosed->length();
254     myNbOpen = anOpen->length();
255     int i;
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() );
260
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 );
266   }
267   else
268   {
269     myEdit->setText( GEOMBase::GetName( myObj ) );
270     myClosedLbl->setText( tr( "NUMBER_CLOSED" ) );
271     myOpenLbl->setText( tr( "NUMBER_OPEN" ) );
272   }
273
274   return result;
275 }
276
277
278
279
280
281
282
283
284
285
286
287
288
289