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