Salome HOME
Bug fixes.
[modules/geom.git] / src / MeasureGUI / MeasureGUI_Skeleton.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   : MeasureGUI_Skeleton.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "MeasureGUI_Skeleton.h"
30 #include "GEOMBase.h"
31 #include "GEOM_Displayer.h"
32 #include "GeometryGUI.h"
33
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_SelectionMgr.h"
36 #include "SalomeApp_Tools.h"
37 #include "SUIT_Session.h"
38 #include "SUIT_OverrideCursor.h"
39
40 #include <qlineedit.h>
41 #include <qlayout.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
44 #include <qbuttongroup.h>
45 #include <qapplication.h>
46
47 //=================================================================================
48 // class    : MeasureGUI_Skeleton()
49 // purpose  : Constructs a MeasureGUI_Skeleton which is a child of 'parent', with the 
50 //            name 'name' and widget flags set to 'f'.
51 //            The dialog will by default be modeless, unless you set 'modal' to
52 //            TRUE to construct a modal dialog.
53 //=================================================================================
54 MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI*      GUI,
55                                           QWidget*          parent,
56                                           const char*       name )
57 : MeasureGUI_Skeleton_QTD( parent, name, false,
58                            WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
59   myGeomGUI( GUI )
60 {
61
62   mySelBtn = 0;
63   mySelEdit = 0;
64   myDisplayer = 0;
65   
66   if ( !name )
67     setName( "MeasureGUI_Skeleton" );
68
69   buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
70
71   buttonClose->setAutoDefault( false );
72
73   GroupMedium->close( TRUE );
74   resize( 350, 0 );
75 }
76
77
78 //=================================================================================
79 // function : ~MeasureGUI_Skeleton()
80 // purpose  : Destroys the object and frees any allocated resources
81 //=================================================================================
82 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
83 {
84   myGeomGUI->SetActiveDialogBox( 0 );
85   delete myDisplayer;
86 }
87
88
89 //=================================================================================
90 // function : Init()
91 // purpose  :
92 //=================================================================================
93 void MeasureGUI_Skeleton::Init()
94 {
95   /* init variables */
96   myGeomGUI->SetActiveDialogBox((QDialog*)this);
97
98   /* signals and slots connections */
99   
100   connect( buttonClose, SIGNAL( clicked() ),
101           this,         SLOT( ClickOnCancel() ) );
102   
103   connect( myGeomGUI,   SIGNAL( SignalDeactivateActiveDialog() ),
104            this,        SLOT  ( DeactivateActiveDialog() ) );
105            
106   connect( myGeomGUI,   SIGNAL( SignalCloseAllDialogs() ),
107            this,        SLOT  ( ClickOnCancel() ) );
108
109   connect( mySelEdit,   SIGNAL( returnPressed() ),
110            this,        SLOT( LineEditReturnPressed() ) );
111            
112   connect( mySelBtn,    SIGNAL( clicked() ),
113            this,        SLOT  ( SetEditCurrentArgument() ) );
114
115   SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
116   if ( aSel )
117     connect( aSel, SIGNAL( currentSelectionChanged() ), 
118              this, SLOT  ( SelectionIntoArgument() ) ) ;
119
120   /* displays Dialog */
121   RadioButton1->setChecked( TRUE );
122
123   activateSelection();
124   SelectionIntoArgument();
125   show();
126 }
127
128
129 //=================================================================================
130 // function : ClickOnCancel()
131 // purpose  :
132 //=================================================================================
133 void MeasureGUI_Skeleton::ClickOnCancel()
134 {
135   close();
136 }
137
138
139 //=================================================================================
140 // function : LineEditReturnPressed()
141 // purpose  :
142 //=================================================================================
143 void MeasureGUI_Skeleton::LineEditReturnPressed()
144 {
145   /* User name of object input management                          */
146   /* If successfull the selection is changed and signal emitted... */
147   /* so SelectionIntoArgument() is automatically called.           */
148   
149   const QString objectUserName = mySelEdit->text();
150   QWidget* thisWidget = ( QWidget* )this;
151   
152   if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
153     mySelEdit->setText( objectUserName );
154 }
155
156
157 //=================================================================================
158 // function : DeactivateActiveDialog()
159 // purpose  :
160 //=================================================================================
161 void MeasureGUI_Skeleton::DeactivateActiveDialog()
162 {
163   setEnabled( false );
164   
165   SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
166   if ( aSel )
167     disconnect( aSel, 0, this, 0 );
168   
169   myGeomGUI->SetActiveDialogBox( 0 );
170
171   globalSelection();
172 }
173
174
175 //=================================================================================
176 // function : ActivateThisDialog()
177 // purpose  :
178 //=================================================================================
179 void MeasureGUI_Skeleton::ActivateThisDialog()
180 {
181   myGeomGUI->EmitSignalDeactivateDialog();
182   
183   setEnabled( true );
184   
185   myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
186
187   SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
188   if ( aSel )
189     connect( aSel, SIGNAL( currentSelectionChanged() ), 
190              this, SLOT  ( SelectionIntoArgument() ) ) ;
191   
192   redisplayPreview();
193   activateSelection();
194 }
195
196 //=================================================================================
197 // function : SetEditCurrentArgument
198 // purpose  :
199 //=================================================================================
200 void MeasureGUI_Skeleton::SetEditCurrentArgument()
201 {
202   mySelEdit->setFocus();
203   SelectionIntoArgument();
204 }
205
206 //=================================================================================
207 // function : SelectionIntoArgument
208 // purpose  :
209 //=================================================================================
210 void MeasureGUI_Skeleton::SelectionIntoArgument()
211 {
212   myObj = GEOM::GEOM_Object::_nil();
213   
214   Standard_Boolean testResult = Standard_False;
215   GEOM::GEOM_Object_var aSelectedObject =
216     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
217   
218   if( !testResult || aSelectedObject->_is_nil() )
219   {
220     mySelEdit->setText( "" );
221     processObject();
222     erasePreview();
223     return;
224   }
225
226   myObj = aSelectedObject;
227   mySelEdit->setText( GEOMBase::GetName( myObj ) );
228   processObject();
229   redisplayPreview();
230 }
231
232 //=================================================================================
233 // function : processObject
234 // purpose  :
235 //=================================================================================
236 void MeasureGUI_Skeleton::processObject()
237 {  
238 }
239
240
241 //=================================================================================
242 // function : closeEvent
243 // purpose  :
244 //=================================================================================
245 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
246 {
247   SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
248   if ( aSel )
249     disconnect( aSel, 0, this, 0 );
250   QDialog::closeEvent( e );
251 }
252
253 //=================================================================================
254 // function : enterEvent()
255 // purpose  :
256 //=================================================================================
257 void MeasureGUI_Skeleton::enterEvent(QEvent* e)
258 {
259   if ( GroupConstructors->isEnabled() )
260     return;
261     
262   ActivateThisDialog();
263 }
264
265 //=================================================================================
266 // function : buildPrs
267 // purpose  : Build presentation for "preview"
268 //=================================================================================
269 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
270 {
271   return 0;
272 }
273
274 //=================================================================================
275 // function : closeEvent()
276 // purpose  : Build presentation for "preview"
277 //=================================================================================
278 void MeasureGUI_Skeleton::redisplayPreview()
279 {
280   QString aMess;
281   if ( !isValid( aMess ) )
282   {
283     erasePreview( true );
284     return;
285   }
286
287   erasePreview( false );
288
289   try
290   {
291     SUIT_OverrideCursor();
292
293     getDisplayer()->SetColor( Quantity_NOC_VIOLET );
294     getDisplayer()->SetToActivate( false );
295     
296     if ( SALOME_Prs* aPrs = buildPrs() )
297       displayPreview( aPrs );
298   }
299   catch( const SALOME::SALOME_Exception& e )
300   {
301     SalomeApp_Tools::QtCatchCorbaException( e );
302   }
303   
304 }
305
306 //=================================================================================
307 // function : activateSelection
308 // purpose  : 
309 //=================================================================================
310 void MeasureGUI_Skeleton::activateSelection()
311 {
312   globalSelection( GEOM_ALLSHAPES );
313 }
314
315 //=================================================================================
316 // function : isValid
317 // purpose  :
318 //=================================================================================
319 bool MeasureGUI_Skeleton::isValid( QString& )
320 {
321   return !myObj->_is_nil();
322 }
323
324 //================================================================
325 // Function : getDisplayer
326 // Purpose  :
327 //================================================================
328 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
329 {
330   if ( !myDisplayer )
331     myDisplayer = new GEOM_Displayer( getStudy() );
332   return myDisplayer;
333 }
334
335 //=================================================================================
336 // function : createOperation
337 // purpose  :
338 //=================================================================================
339 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
340 {
341   return getGeomEngine()->GetIMeasureOperations( getStudyId() );
342 }
343
344 //=================================================================================
345 // function : getDesktop()
346 // purpose  :
347 //=================================================================================
348 SUIT_Desktop*  MeasureGUI_Skeleton::getDesktop() const
349 {
350   return dynamic_cast<SUIT_Desktop*>( parentWidget() );
351 }