Salome HOME
getDesktop() method is changed: now it is NOT virtual, it is implemented in GEOMBase_...
[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 "GEOMBase.h"
31 #include "GeometryGUI.h"
32 #include "GEOM_Displayer.h"
33 #include "GEOMImpl_Types.hxx"
34
35 #include "SalomeApp_Application.h"
36 #include "SalomeApp_SelectionMgr.h"
37 #include "SUIT_Session.h"
38
39 #include <TColStd_MapOfInteger.hxx>
40
41 #include <qlineedit.h>
42 #include <qlabel.h>
43 #include <qlayout.h>
44 #include <qgroupbox.h>
45 #include <qpushbutton.h>
46
47 #define SPACING 5
48 #define MARGIN 10
49
50 /*
51   Calss       : RepairGUI_FreeBoundDlg
52   Description : Dialog for displaying free boundaries of selected face, shell or solid
53 */
54
55
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 ) ),
64   myGeomGUI ( theGUI )
65 {
66   setCaption( tr( "CAPTION" ) );
67
68   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr( "ICON_SELECT" ) ) );
69   
70   QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FREE_BOUND" ), this );
71   
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 ) );
80
81   myClosedLbl = new QLabel( tr( "NUMBER_CLOSED" ), aMainGrp );
82   myOpenLbl = new QLabel( tr( "NUMBER_OPEN" ), aMainGrp );
83
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 ) );
91
92   QVBoxLayout* aLay = new QVBoxLayout( this );
93   aLay->setSpacing( SPACING );
94   aLay->setMargin( MARGIN );
95   aLay->addWidget( aMainGrp );
96   aLay->addWidget( aFrame );
97   
98   connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
99
100   Init();
101 }
102
103 //=================================================================================
104 // function : ~RepairGUI_FreeBoundDlg
105 // purpose  : Destructor
106 //=================================================================================
107 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
108 {
109 }
110
111 //=================================================================================
112 // function : onClose
113 // purpose  : SLOT. Called when "close" button pressed. Close dialog
114 //=================================================================================
115 void RepairGUI_FreeBoundDlg::onClose()
116 {
117   globalSelection();
118   disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
119   myGeomGUI->SetActiveDialogBox( 0 );
120   reject();
121   erasePreview();
122 }
123
124 //=================================================================================
125 // function : onDeactivate
126 // purpose  : Deactivate this dialog
127 //=================================================================================
128 void RepairGUI_FreeBoundDlg::onDeactivate()
129 {
130   setEnabled(false);
131   globalSelection();
132   disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
133   myGeomGUI->SetActiveDialogBox( 0 );
134 }
135
136 //=================================================================================
137 // function : onActivate
138 // purpose  : Activate this dialog
139 //=================================================================================
140 void RepairGUI_FreeBoundDlg::onActivate()
141 {
142   myGeomGUI->EmitSignalDeactivateDialog();
143   setEnabled( true );
144   myGeomGUI->SetActiveDialogBox( this );
145   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
146            SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
147   activateSelection();
148   onSelectionDone();
149 }
150
151 //=================================================================================
152 // function : onSelectionDone
153 // purpose  : SLOT. Called when selection changed.
154 //=================================================================================
155 void RepairGUI_FreeBoundDlg::onSelectionDone()
156 {
157   if( IObjectCount() != 1 )
158     return;
159
160   Standard_Boolean isOk = Standard_False;
161   GEOM::GEOM_Object_var anObj =
162     GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
163
164   if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
165     return;
166   else
167   {
168     myObj = anObj;
169     displayPreview( false, true, true, 3 );
170   }
171
172 }
173
174 //=================================================================================
175 // function : Init
176 // purpose  : Initialize dialog fields
177 //=================================================================================
178 void RepairGUI_FreeBoundDlg::Init()
179 {
180   myNbClosed = myNbOpen = 0;
181   myObj = GEOM::GEOM_Object::_nil();
182
183   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT  ( onDeactivate() ) );
184   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
185            SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
186
187   activateSelection();
188   onSelectionDone();
189 }
190
191 //=================================================================================
192 // function : enterEvent
193 // purpose  : Activate dialog
194 //=================================================================================
195 void RepairGUI_FreeBoundDlg::enterEvent( QEvent* e )
196 {
197   onActivate();
198 }
199
200 //=================================================================================
201 // function : closeEvent
202 // purpose  : Close dialog
203 //=================================================================================
204 void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* e )
205 {
206   onClose();
207 }
208
209 //=================================================================================
210 // function : activateSelection
211 // purpose  : activate selection of faces, shells, and solids
212 //=================================================================================
213 void RepairGUI_FreeBoundDlg::activateSelection()
214 {
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 );
221 }
222
223 //=================================================================================
224 // function : createOperation
225 // purpose  : Create operation
226 //=================================================================================
227 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
228 {
229   return getGeomEngine()->GetIHealingOperations( getStudyId() );
230 }
231
232 //=================================================================================
233 // function : isValid
234 // purpose  :
235 //=================================================================================
236 bool RepairGUI_FreeBoundDlg::isValid( QString& msg )
237 {
238   return !myObj->_is_nil();
239 }
240
241 //=================================================================================
242 // function : execute
243 // purpose  : Get free boundaries
244 //=================================================================================
245 bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
246 {
247   if ( !IsPreview() || myObj->_is_nil() )
248     return false;
249
250   GEOM::ListOfGO_var aClosed, anOpen;
251
252   bool result = GEOM::GEOM_IHealingOperations::_narrow(
253     getOperation() )->GetFreeBoundary( myObj, aClosed, anOpen );
254
255   if ( result )
256   {
257     myNbClosed = aClosed->length();
258     myNbOpen = anOpen->length();
259     int i;
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() );
264
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 );
270   }
271   else
272   {
273     myEdit->setText( GEOMBase::GetName( myObj ) );
274     myClosedLbl->setText( tr( "NUMBER_CLOSED" ) );
275     myOpenLbl->setText( tr( "NUMBER_OPEN" ) );
276   }
277
278   return result;
279 }
280
281
282