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