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