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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOMBase_Skeleton.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "GEOMBase_Skeleton.h"
29 #include <GeometryGUI.h>
30 #include <GEOM_DlgRef.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_MessageBox.h>
42 #include <QDoubleSpinBox>
46 //=================================================================================
47 // class : GEOMBase_Skeleton()
48 // purpose : Constructs a GEOMBase_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 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : QDialog( parent, fl ),
56 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
57 myGeomGUI( theGeometryGUI ),
60 setAttribute( Qt::WA_DeleteOnClose );
64 myMainFrame = new DlgRef_Skeleton( this );
65 QVBoxLayout* topLayout = new QVBoxLayout( this );
66 topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
67 topLayout->addWidget( myMainFrame );
69 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
70 buttonOk()->setText( tr( "GEOM_BUT_OK" )) ;
71 buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
72 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
74 myRBGroup = new QButtonGroup( this );
75 myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
76 myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
77 myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
78 myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
80 connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
86 //=================================================================================
87 // function : ~GEOMBase_Skeleton()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 GEOMBase_Skeleton::~GEOMBase_Skeleton()
93 myGeomGUI->SetActiveDialogBox( 0 );
97 //=================================================================================
100 //=================================================================================
101 void GEOMBase_Skeleton::Init()
103 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
104 if ( !myGeomGUI && app )
105 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
108 myGeomGUI->SetActiveDialogBox( this );
110 /* signals and slots connections */
111 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
113 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
114 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
117 // connect help button on a private slot that displays help information
118 connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
120 /* displays Dialog */
121 myMainFrame->RadioButton1->setChecked( true );
122 myMainFrame->RadioButton4->hide();
125 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
126 int min, int max, int step )
128 spinBox->setRange( min, max );
129 spinBox->setSingleStep( step );
132 void GEOMBase_Skeleton::initSpinBox( QDoubleSpinBox* spinBox,
133 double min, double max,
134 double step, int decimals )
136 spinBox->setRange( min, max );
137 spinBox->setSingleStep( step );
138 spinBox->setDecimals( decimals );
141 //=================================================================================
142 // function : ClickOnCancel()
144 //=================================================================================
145 void GEOMBase_Skeleton::ClickOnCancel()
151 //=================================================================================
152 // function : LineEditReturnPressed()
154 //=================================================================================
155 void GEOMBase_Skeleton::LineEditReturnPressed()
157 if ( !myEditCurrentArgument )
160 /* User name of object input management */
161 /* If successfull the selection is changed and signal emitted... */
162 /* so SelectionIntoArgument() is automatically called. */
163 const QString objectUserName = myEditCurrentArgument->text();
164 QWidget* thisWidget = (QWidget*)this;
166 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
167 myEditCurrentArgument->setText( objectUserName );
171 //=================================================================================
172 // function : DeactivateActiveDialog()
174 //=================================================================================
175 void GEOMBase_Skeleton::DeactivateActiveDialog()
177 this->setEnabled( false );
179 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
180 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( 0 );
184 //=================================================================================
185 // function : ActivateThisDialog()
187 //=================================================================================
188 void GEOMBase_Skeleton::ActivateThisDialog()
190 /* Emit a signal to deactivate the active dialog */
191 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
192 this->setEnabled( true );
193 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
198 //=================================================================================
199 // function : closeEvent()
200 // purpose : same than click on cancel button
201 //=================================================================================
202 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
204 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
206 disconnect( app->selectionMgr(), 0, this, 0 );
207 app->updateActions();
209 QDialog::closeEvent( e );
212 //=================================================================================
213 // function : initName()
214 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
215 //=================================================================================
216 void GEOMBase_Skeleton::initName( const QString& thePrefix )
218 if ( !thePrefix.isNull() )
219 setPrefix( thePrefix );
220 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
223 //=================================================================================
224 // function : getNewObjectName()
225 // purpose : returns contents of Name field
226 //=================================================================================
227 const char* GEOMBase_Skeleton::getNewObjectName() const
229 return myMainFrame->ResultName->text().toLatin1().constData();
232 //=================================================================================
233 // function : getConstructorId()
235 //=================================================================================
236 int GEOMBase_Skeleton::getConstructorId() const
239 return myRBGroup->checkedId();
243 void GEOMBase_Skeleton::setConstructorId( const int id )
245 if ( myRBGroup && myRBGroup->button( id ) )
246 myRBGroup->button( id )->setChecked( true );
249 //=================================================================================
250 // function : ClickOnHelp()
252 //=================================================================================
253 void GEOMBase_Skeleton::ClickOnHelp()
255 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
257 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
261 platform = "winapplication";
263 platform = "application";
265 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
266 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
267 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
268 QObject::tr( "BUT_OK" ) );
271 //=================================================================================
272 // function : setHelpFileName()
273 // purpose : set name for help file html
274 //=================================================================================
276 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
278 myHelpFileName = theName;
281 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
286 QWidget* GEOMBase_Skeleton::centralWidget()
288 return myMainFrame->GroupMedium;
291 QPushButton* GEOMBase_Skeleton::buttonCancel() const
293 return myMainFrame->buttonCancel;
296 QPushButton* GEOMBase_Skeleton::buttonOk() const
298 return myMainFrame->buttonOk;
301 QPushButton* GEOMBase_Skeleton::buttonApply() const
303 return myMainFrame->buttonApply;
306 QPushButton* GEOMBase_Skeleton::buttonHelp() const
308 return myMainFrame->buttonHelp;
311 //=================================================================================
312 // function : keyPressEvent()
314 //=================================================================================
315 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
317 QDialog::keyPressEvent( e );
318 if ( e->isAccepted() )
321 if ( e->key() == Qt::Key_F1 ) {