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>
41 #include <QDoubleSpinBox>
45 //=================================================================================
46 // class : GEOMBase_Skeleton()
47 // purpose : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // true to construct a modal dialog.
51 //=================================================================================
52 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
53 const char* name, bool modal, Qt::WindowFlags fl )
54 : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
55 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
56 myGeomGUI( theGeometryGUI ),
60 setObjectName( "GEOMBase_Skeleton" );
62 setObjectName( name );
64 setAttribute( Qt::WA_DeleteOnClose );
68 myMainFrame = new DlgRef_Skeleton( this );
69 QVBoxLayout* topLayout = new QVBoxLayout( this );
70 topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
71 topLayout->addWidget( myMainFrame );
73 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
74 buttonOk()->setText( tr( "GEOM_BUT_OK" )) ;
75 buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
76 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
78 myRBGroup = new QButtonGroup( this );
79 myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
80 myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
81 myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
82 myRBGroup->addButton( myMainFrame->RadioButton4, 4 );
84 connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
90 //=================================================================================
91 // function : ~GEOMBase_Skeleton()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 GEOMBase_Skeleton::~GEOMBase_Skeleton()
97 myGeomGUI->SetActiveDialogBox( 0 );
101 //=================================================================================
104 //=================================================================================
105 void GEOMBase_Skeleton::Init()
107 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
108 if ( !myGeomGUI && app )
109 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
112 myGeomGUI->SetActiveDialogBox( this );
114 /* signals and slots connections */
115 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
117 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
118 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
121 // connect help button on a private slot that displays help information
122 connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
124 /* displays Dialog */
125 myMainFrame->RadioButton1->setChecked( true );
126 myMainFrame->RadioButton4->hide();
129 void GEOMBase_Skeleton::initSpinBox( QDoubleSpinBox* spinBox,
130 double min, double max,
131 double step, int decimals )
133 spinBox->setRange( min, max );
134 spinBox->setSingleStep( step );
135 spinBox->setDecimals( decimals );
138 //=================================================================================
139 // function : ClickOnCancel()
141 //=================================================================================
142 void GEOMBase_Skeleton::ClickOnCancel()
148 //=================================================================================
149 // function : LineEditReturnPressed()
151 //=================================================================================
152 void GEOMBase_Skeleton::LineEditReturnPressed()
154 if ( !myEditCurrentArgument )
157 /* User name of object input management */
158 /* If successfull the selection is changed and signal emitted... */
159 /* so SelectionIntoArgument() is automatically called. */
160 const QString objectUserName = myEditCurrentArgument->text();
161 QWidget* thisWidget = (QWidget*)this;
163 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
164 myEditCurrentArgument->setText( objectUserName );
168 //=================================================================================
169 // function : DeactivateActiveDialog()
171 //=================================================================================
172 void GEOMBase_Skeleton::DeactivateActiveDialog()
174 this->setEnabled( false );
176 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
177 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( 0 );
181 //=================================================================================
182 // function : ActivateThisDialog()
184 //=================================================================================
185 void GEOMBase_Skeleton::ActivateThisDialog()
187 /* Emit a signal to deactivate the active dialog */
188 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
189 this->setEnabled( true );
190 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
195 //=================================================================================
196 // function : closeEvent()
197 // purpose : same than click on cancel button
198 //=================================================================================
199 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
201 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
203 disconnect( app->selectionMgr(), 0, this, 0 );
204 app->updateActions();
206 QDialog::closeEvent( e );
209 //=================================================================================
210 // function : initName()
211 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
212 //=================================================================================
213 void GEOMBase_Skeleton::initName( const QString& thePrefix )
215 if ( !thePrefix.isNull() )
216 setPrefix( thePrefix );
217 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
220 //=================================================================================
221 // function : getNewObjectName()
222 // purpose : returns contents of Name field
223 //=================================================================================
224 const char* GEOMBase_Skeleton::getNewObjectName() const
226 return myMainFrame->ResultName->text().toLatin1().constData();
229 //=================================================================================
230 // function : getConstructorId()
232 //=================================================================================
233 int GEOMBase_Skeleton::getConstructorId() const
235 /*if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
236 return GroupConstructors->id( GroupConstructors->selected() );
239 if ( myRBGroup != NULL )
240 return myRBGroup->checkedId();
244 //=================================================================================
245 // function : ClickOnHelp()
247 //=================================================================================
248 void GEOMBase_Skeleton::ClickOnHelp()
250 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
252 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
256 platform = "winapplication";
258 platform = "application";
260 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
261 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
262 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
263 QObject::tr( "BUT_OK" ) );
266 //=================================================================================
267 // function : setHelpFileName()
268 // purpose : set name for help file html
269 //=================================================================================
271 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
273 myHelpFileName = theName;
276 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
281 QWidget* GEOMBase_Skeleton::centralWidget()
283 return myMainFrame->GroupMedium;
286 QPushButton* GEOMBase_Skeleton::buttonCancel() const
288 return myMainFrame->buttonCancel;
291 QPushButton* GEOMBase_Skeleton::buttonOk() const
293 return myMainFrame->buttonOk;
296 QPushButton* GEOMBase_Skeleton::buttonApply() const
298 return myMainFrame->buttonApply;
301 QPushButton* GEOMBase_Skeleton::buttonHelp() const
303 return myMainFrame->buttonHelp;
306 //=================================================================================
307 // function : keyPressEvent()
309 //=================================================================================
310 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
312 QDialog::keyPressEvent( e );
313 if ( e->isAccepted() )
316 if ( e->key() == Qt::Key_F1 ) {