1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : MeasureGUI_Skeleton.cxx
24 // Author : Damien COQUERET
28 #include "MeasureGUI_Skeleton.h"
30 #include "GEOM_Displayer.h"
31 #include "GeometryGUI.h"
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"
41 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
45 #include <qbuttongroup.h>
46 #include <qapplication.h>
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,
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 ) ),
69 setName( "MeasureGUI_Skeleton" );
71 buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
72 buttonHelp->setText(tr("GEOM_BUT_HELP"));
74 buttonClose->setAutoDefault( false );
80 //=================================================================================
81 // function : ~MeasureGUI_Skeleton()
82 // purpose : Destroys the object and frees any allocated resources
83 //=================================================================================
84 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
86 myGeomGUI->SetActiveDialogBox( 0 );
91 //=================================================================================
94 //=================================================================================
95 void MeasureGUI_Skeleton::Init()
98 myGeomGUI->SetActiveDialogBox((QDialog*)this);
100 /* signals and slots connections */
102 connect( buttonClose, SIGNAL( clicked() ),
103 this, SLOT( ClickOnCancel() ) );
105 connect( buttonHelp, SIGNAL( clicked() ),
106 this, SLOT( ClickOnHelp() ) );
108 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
109 this, SLOT ( DeactivateActiveDialog() ) );
111 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
112 this, SLOT ( ClickOnCancel() ) );
114 connect( mySelEdit, SIGNAL( returnPressed() ),
115 this, SLOT( LineEditReturnPressed() ) );
117 connect( mySelBtn, SIGNAL( clicked() ),
118 this, SLOT ( SetEditCurrentArgument() ) );
120 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
122 connect( aSel, SIGNAL( currentSelectionChanged() ),
123 this, SLOT ( SelectionIntoArgument() ) ) ;
125 /* displays Dialog */
126 RadioButton1->setChecked( TRUE );
129 SelectionIntoArgument();
134 //=================================================================================
135 // function : ClickOnCancel()
137 //=================================================================================
138 void MeasureGUI_Skeleton::ClickOnCancel()
143 //=================================================================================
144 // function : ClickOnHelp()
146 //=================================================================================
147 void MeasureGUI_Skeleton::ClickOnHelp()
149 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
151 app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
155 platform = "winapplication";
157 platform = "application";
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"));
166 //=================================================================================
167 // function : LineEditReturnPressed()
169 //=================================================================================
170 void MeasureGUI_Skeleton::LineEditReturnPressed()
172 /* User name of object input management */
173 /* If successfull the selection is changed and signal emitted... */
174 /* so SelectionIntoArgument() is automatically called. */
176 const QString objectUserName = mySelEdit->text();
177 QWidget* thisWidget = ( QWidget* )this;
179 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
180 mySelEdit->setText( objectUserName );
184 //=================================================================================
185 // function : DeactivateActiveDialog()
187 //=================================================================================
188 void MeasureGUI_Skeleton::DeactivateActiveDialog()
192 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
194 disconnect( aSel, 0, this, 0 );
196 myGeomGUI->SetActiveDialogBox( 0 );
202 //=================================================================================
203 // function : ActivateThisDialog()
205 //=================================================================================
206 void MeasureGUI_Skeleton::ActivateThisDialog()
208 myGeomGUI->EmitSignalDeactivateDialog();
212 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
214 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
216 connect( aSel, SIGNAL( currentSelectionChanged() ),
217 this, SLOT ( SelectionIntoArgument() ) ) ;
223 //=================================================================================
224 // function : SetEditCurrentArgument
226 //=================================================================================
227 void MeasureGUI_Skeleton::SetEditCurrentArgument()
229 mySelEdit->setFocus();
230 SelectionIntoArgument();
233 //=================================================================================
234 // function : SelectionIntoArgument
236 //=================================================================================
237 void MeasureGUI_Skeleton::SelectionIntoArgument()
239 myObj = GEOM::GEOM_Object::_nil();
241 Standard_Boolean testResult = Standard_False;
242 GEOM::GEOM_Object_var aSelectedObject =
243 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
245 if( !testResult || aSelectedObject->_is_nil() )
247 mySelEdit->setText( "" );
253 myObj = aSelectedObject;
254 mySelEdit->setText( GEOMBase::GetName( myObj ) );
259 //=================================================================================
260 // function : processObject
262 //=================================================================================
263 void MeasureGUI_Skeleton::processObject()
268 //=================================================================================
269 // function : closeEvent
271 //=================================================================================
272 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
274 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
276 disconnect( aSel, 0, this, 0 );
277 QDialog::closeEvent( e );
280 //=================================================================================
281 // function : enterEvent()
283 //=================================================================================
284 void MeasureGUI_Skeleton::enterEvent(QEvent* e)
286 if ( GroupConstructors->isEnabled() )
289 ActivateThisDialog();
292 //=================================================================================
293 // function : buildPrs
294 // purpose : Build presentation for "preview"
295 //=================================================================================
296 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
301 //=================================================================================
302 // function : closeEvent()
303 // purpose : Build presentation for "preview"
304 //=================================================================================
305 void MeasureGUI_Skeleton::redisplayPreview()
308 if ( !isValid( aMess ) )
310 erasePreview( true );
314 erasePreview( false );
318 SUIT_OverrideCursor();
320 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
321 getDisplayer()->SetToActivate( false );
323 if ( SALOME_Prs* aPrs = buildPrs() )
324 displayPreview( aPrs );
326 catch( const SALOME::SALOME_Exception& e )
328 SalomeApp_Tools::QtCatchCorbaException( e );
333 //=================================================================================
334 // function : activateSelection
336 //=================================================================================
337 void MeasureGUI_Skeleton::activateSelection()
339 globalSelection( GEOM_ALLSHAPES );
342 //=================================================================================
343 // function : isValid
345 //=================================================================================
346 bool MeasureGUI_Skeleton::isValid( QString& )
348 return !myObj->_is_nil();
351 //================================================================
352 // Function : getDisplayer
354 //================================================================
355 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
358 myDisplayer = new GEOM_Displayer( getStudy() );
362 //=================================================================================
363 // function : createOperation
365 //=================================================================================
366 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
368 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
371 //=================================================================================
372 // function : keyPressEvent()
374 //=================================================================================
375 void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
377 QDialog::keyPressEvent( e );
378 if ( e->isAccepted() )
381 if ( e->key() == Key_F1 )