1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MeasureGUI_Skeleton.cxx
25 // Author : Damien COQUERET
29 #include "MeasureGUI_Skeleton.h"
31 #include "GEOM_Displayer.h"
32 #include "GeometryGUI.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_SelectionMgr.h"
36 #include "SalomeApp_Tools.h"
37 #include "SUIT_Session.h"
39 #include <qlineedit.h>
41 #include <qpushbutton.h>
42 #include <qradiobutton.h>
43 #include <qbuttongroup.h>
44 #include <qapplication.h>
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,
56 : MeasureGUI_Skeleton_QTD( parent, name, false,
57 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
66 setName( "MeasureGUI_Skeleton" );
68 buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
70 buttonClose->setAutoDefault( false );
72 GroupMedium->close( TRUE );
77 //=================================================================================
78 // function : ~MeasureGUI_Skeleton()
79 // purpose : Destroys the object and frees any allocated resources
80 //=================================================================================
81 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
83 myGeomGUI->SetActiveDialogBox( 0 );
88 //=================================================================================
91 //=================================================================================
92 void MeasureGUI_Skeleton::Init()
95 myGeomGUI->SetActiveDialogBox((QDialog*)this);
97 /* signals and slots connections */
99 connect( buttonClose, SIGNAL( clicked() ),
100 this, SLOT( ClickOnCancel() ) );
102 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
103 this, SLOT ( DeactivateActiveDialog() ) );
105 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
106 this, SLOT ( ClickOnCancel() ) );
108 connect( mySelEdit, SIGNAL( returnPressed() ),
109 this, SLOT( LineEditReturnPressed() ) );
111 connect( mySelBtn, SIGNAL( clicked() ),
112 this, SLOT ( SetEditCurrentArgument() ) );
114 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
116 connect( aSel, SIGNAL( currentSelectionChanged() ),
117 this, SLOT ( SelectionIntoArgument() ) ) ;
119 /* displays Dialog */
120 RadioButton1->setChecked( TRUE );
123 SelectionIntoArgument();
128 //=================================================================================
129 // function : ClickOnCancel()
131 //=================================================================================
132 void MeasureGUI_Skeleton::ClickOnCancel()
138 //=================================================================================
139 // function : LineEditReturnPressed()
141 //=================================================================================
142 void MeasureGUI_Skeleton::LineEditReturnPressed()
144 /* User name of object input management */
145 /* If successfull the selection is changed and signal emitted... */
146 /* so SelectionIntoArgument() is automatically called. */
148 const QString objectUserName = mySelEdit->text();
149 QWidget* thisWidget = ( QWidget* )this;
151 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
152 mySelEdit->setText( objectUserName );
156 //=================================================================================
157 // function : DeactivateActiveDialog()
159 //=================================================================================
160 void MeasureGUI_Skeleton::DeactivateActiveDialog()
164 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
166 disconnect( aSel, 0, this, 0 );
168 myGeomGUI->SetActiveDialogBox( 0 );
174 //=================================================================================
175 // function : ActivateThisDialog()
177 //=================================================================================
178 void MeasureGUI_Skeleton::ActivateThisDialog()
180 myGeomGUI->EmitSignalDeactivateDialog();
184 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
186 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
188 connect( aSel, SIGNAL( currentSelectionChanged() ),
189 this, SLOT ( SelectionIntoArgument() ) ) ;
195 //=================================================================================
196 // function : SetEditCurrentArgument
198 //=================================================================================
199 void MeasureGUI_Skeleton::SetEditCurrentArgument()
201 mySelEdit->setFocus();
202 SelectionIntoArgument();
205 //=================================================================================
206 // function : SelectionIntoArgument
208 //=================================================================================
209 void MeasureGUI_Skeleton::SelectionIntoArgument()
211 myObj = GEOM::GEOM_Object::_nil();
213 Standard_Boolean testResult = Standard_False;
214 GEOM::GEOM_Object_var aSelectedObject =
215 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
217 if( !testResult || aSelectedObject->_is_nil() )
219 mySelEdit->setText( "" );
225 myObj = aSelectedObject;
226 mySelEdit->setText( GEOMBase::GetName( myObj ) );
231 //=================================================================================
232 // function : processObject
234 //=================================================================================
235 void MeasureGUI_Skeleton::processObject()
240 //=================================================================================
241 // function : closeEvent
243 //=================================================================================
244 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
246 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
248 disconnect( aSel, 0, this, 0 );
249 QDialog::closeEvent( e );
252 //=================================================================================
253 // function : enterEvent()
255 //=================================================================================
256 void MeasureGUI_Skeleton::enterEvent(QEvent* e)
258 if ( GroupConstructors->isEnabled() )
261 ActivateThisDialog();
264 //=================================================================================
265 // function : buildPrs
266 // purpose : Build presentation for "preview"
267 //=================================================================================
268 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
273 //=================================================================================
274 // function : closeEvent()
275 // purpose : Build presentation for "preview"
276 //=================================================================================
277 void MeasureGUI_Skeleton::redisplayPreview()
280 if ( !isValid( aMess ) )
282 erasePreview( true );
286 erasePreview( false );
290 QApplication::setOverrideCursor( Qt::waitCursor );
292 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
293 getDisplayer()->SetToActivate( false );
295 if ( SALOME_Prs* aPrs = buildPrs() )
296 displayPreview( aPrs );
298 catch( const SALOME::SALOME_Exception& e )
300 SalomeApp_Tools::QtCatchCorbaException( e );
305 //=================================================================================
306 // function : activateSelection
308 //=================================================================================
309 void MeasureGUI_Skeleton::activateSelection()
311 globalSelection( GEOM_ALLSHAPES );
314 //=================================================================================
315 // function : isValid
317 //=================================================================================
318 bool MeasureGUI_Skeleton::isValid( QString& )
320 return !myObj->_is_nil();
323 //================================================================
324 // Function : getDisplayer
326 //================================================================
327 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
330 myDisplayer = new GEOM_Displayer( getStudy() );
334 //=================================================================================
335 // function : createOperation
337 //=================================================================================
338 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
340 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
343 //=================================================================================
344 // function : getDesktop()
346 //=================================================================================
347 SUIT_Desktop* MeasureGUI_Skeleton::getDesktop() const
349 return dynamic_cast<SUIT_Desktop*>( parentWidget() );