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 : Damine COQUERET, Open CASCADE S.A.S.
26 #include "MeasureGUI_Skeleton.h"
27 #include "MeasureGUI_Widgets.h"
30 #include <GEOM_Displayer.h>
31 #include <GeometryGUI.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_Tools.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_OverrideCursor.h>
44 //=================================================================================
45 // class : MeasureGUI_Skeleton()
46 // purpose : Constructs a MeasureGUI_Skeleton which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI* GUI, QWidget* parent,
52 bool modal, Qt::WindowFlags f )
53 : QDialog( parent, f ),
54 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
57 myMainFrame = new MeasureGUI_SkeletonBox( this );
58 QVBoxLayout* topLayout = new QVBoxLayout( this );
59 topLayout->setMargin( 9 ); topLayout->setSpacing( 0 );
60 topLayout->addWidget( myMainFrame );
62 setAttribute( Qt::WA_DeleteOnClose );
69 buttonClose()->setText( tr( "GEOM_BUT_CLOSE" ) );
70 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
74 //=================================================================================
75 // function : ~MeasureGUI_Skeleton()
76 // purpose : Destroys the object and frees any allocated resources
77 //=================================================================================
78 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
81 myGeomGUI->SetActiveDialogBox( 0 );
86 //=================================================================================
89 //=================================================================================
90 void MeasureGUI_Skeleton::Init()
94 myGeomGUI->SetActiveDialogBox( (QDialog*)this );
96 /* signals and slots connections */
98 connect( buttonClose(), SIGNAL( clicked() ),
99 this, SLOT( ClickOnCancel() ) );
101 connect( buttonHelp(), SIGNAL( clicked() ),
102 this, SLOT( ClickOnHelp() ) );
105 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
106 this, SLOT ( DeactivateActiveDialog() ) );
108 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
109 this, SLOT ( ClickOnCancel() ) );
113 connect( mySelEdit, SIGNAL( returnPressed() ),
114 this, SLOT( LineEditReturnPressed() ) );
118 connect( mySelBtn, SIGNAL( clicked() ),
119 this, SLOT ( SetEditCurrentArgument() ) );
122 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
124 connect( aSel, SIGNAL( currentSelectionChanged() ),
125 this, SLOT ( SelectionIntoArgument() ) ) ;
128 /* displays Dialog */
129 mainFrame()->RadioButton1->setChecked( true );
132 SelectionIntoArgument();
136 //=================================================================================
137 // function : ClickOnCancel()
139 //=================================================================================
140 void MeasureGUI_Skeleton::ClickOnCancel()
145 //=================================================================================
146 // function : ClickOnHelp()
148 //=================================================================================
149 void MeasureGUI_Skeleton::ClickOnHelp()
151 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
153 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString( "" ), myHelpFileName );
158 platform = "winapplication";
160 platform = "application";
162 SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
163 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
164 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ) );
168 //=================================================================================
169 // function : LineEditReturnPressed()
171 //=================================================================================
172 void MeasureGUI_Skeleton::LineEditReturnPressed()
174 /* User name of object input management */
175 /* If successfull the selection is changed and signal emitted... */
176 /* so SelectionIntoArgument() is automatically called. */
179 const QString objectUserName = mySelEdit->text();
180 QWidget* thisWidget = ( QWidget* )this;
182 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
183 SALOME_ListIO aSelList;
184 aSelMgr->selectedObjects(aSelList);
186 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
187 mySelEdit->setText(objectUserName);
192 //=================================================================================
193 // function : DeactivateActiveDialog()
195 //=================================================================================
196 void MeasureGUI_Skeleton::DeactivateActiveDialog()
200 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
202 disconnect( aSel, 0, this, 0 );
204 myGeomGUI->SetActiveDialogBox( 0 );
210 //=================================================================================
211 // function : ActivateThisDialog()
213 //=================================================================================
214 void MeasureGUI_Skeleton::ActivateThisDialog()
216 myGeomGUI->EmitSignalDeactivateDialog();
220 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
222 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
224 connect( aSel, SIGNAL( currentSelectionChanged() ),
225 this, SLOT ( SelectionIntoArgument() ) ) ;
231 //=================================================================================
232 // function : SetEditCurrentArgument
234 //=================================================================================
235 void MeasureGUI_Skeleton::SetEditCurrentArgument()
237 mySelEdit->setFocus();
238 SelectionIntoArgument();
241 //=================================================================================
242 // function : SelectionIntoArgument
244 //=================================================================================
245 void MeasureGUI_Skeleton::SelectionIntoArgument()
247 myObj = GEOM::GEOM_Object::_nil();
249 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
250 SALOME_ListIO aSelList;
251 aSelMgr->selectedObjects(aSelList);
253 GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil();
255 if (aSelList.Extent() > 0) {
256 Standard_Boolean testResult = Standard_False;
257 aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
259 aSelectedObject = GEOM::GEOM_Object::_nil();
262 if (aSelectedObject->_is_nil()) {
263 mySelEdit->setText("");
269 myObj = aSelectedObject;
270 mySelEdit->setText(GEOMBase::GetName(myObj));
275 //=================================================================================
276 // function : processObject
278 //=================================================================================
279 void MeasureGUI_Skeleton::processObject()
284 //=================================================================================
285 // function : closeEvent
287 //=================================================================================
288 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
290 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
292 disconnect( aSel, 0, this, 0 );
293 QDialog::closeEvent( e );
296 //=================================================================================
297 // function : enterEvent()
299 //=================================================================================
300 void MeasureGUI_Skeleton::enterEvent( QEvent* )
302 if ( mainFrame()->GroupConstructors->isEnabled() )
305 ActivateThisDialog();
308 //=================================================================================
309 // function : buildPrs
310 // purpose : Build presentation for "preview"
311 //=================================================================================
312 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
317 //=================================================================================
318 // function : closeEvent()
319 // purpose : Build presentation for "preview"
320 //=================================================================================
321 void MeasureGUI_Skeleton::redisplayPreview()
324 if ( !isValid( aMess ) ) {
325 erasePreview( true );
329 erasePreview( false );
332 SUIT_OverrideCursor();
334 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
335 getDisplayer()->SetToActivate( false );
337 if ( SALOME_Prs* aPrs = buildPrs() )
338 displayPreview( aPrs );
340 catch ( const SALOME::SALOME_Exception& e ) {
341 SalomeApp_Tools::QtCatchCorbaException( e );
346 //=================================================================================
347 // function : activateSelection
349 //=================================================================================
350 void MeasureGUI_Skeleton::activateSelection()
352 globalSelection( GEOM_ALLSHAPES );
355 //=================================================================================
356 // function : isValid
358 //=================================================================================
359 bool MeasureGUI_Skeleton::isValid( QString& )
361 return !myObj->_is_nil();
364 //================================================================
365 // Function : getDisplayer
367 //================================================================
368 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
371 myDisplayer = new GEOM_Displayer( getStudy() );
375 //=================================================================================
376 // function : createOperation
378 //=================================================================================
379 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
381 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
384 //=================================================================================
385 // function : keyPressEvent()
387 //=================================================================================
388 void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
390 QDialog::keyPressEvent( e );
391 if ( e->isAccepted() )
394 if ( e->key() == Qt::Key_F1 ) {
400 MeasureGUI_SkeletonBox* MeasureGUI_Skeleton::mainFrame() const
405 QWidget* MeasureGUI_Skeleton::centralWidget() const
407 return mainFrame()->GroupMedium;
410 QPushButton* MeasureGUI_Skeleton::buttonClose() const
412 return mainFrame()->buttonClose;
415 QPushButton* MeasureGUI_Skeleton::buttonHelp() const
417 return mainFrame()->buttonHelp;