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