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