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 bool modal, Qt::WindowFlags fl )
54 : QDialog( parent, fl ),
55 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
56 myGeomGUI( theGeometryGUI ),
59 setAttribute( Qt::WA_DeleteOnClose );
63 myMainFrame = new DlgRef_Skeleton( this );
64 QVBoxLayout* topLayout = new QVBoxLayout( this );
65 topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
66 topLayout->addWidget( myMainFrame );
68 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
69 buttonOk()->setText( tr( "GEOM_BUT_OK" )) ;
70 buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
71 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
73 myRBGroup = new QButtonGroup( this );
74 myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
75 myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
76 myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
77 myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
79 connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
85 //=================================================================================
86 // function : ~GEOMBase_Skeleton()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 GEOMBase_Skeleton::~GEOMBase_Skeleton()
92 myGeomGUI->SetActiveDialogBox( 0 );
96 //=================================================================================
99 //=================================================================================
100 void GEOMBase_Skeleton::Init()
102 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
103 if ( !myGeomGUI && app )
104 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
107 myGeomGUI->SetActiveDialogBox( this );
109 /* signals and slots connections */
110 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
112 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
113 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
116 // connect help button on a private slot that displays help information
117 connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
119 /* displays Dialog */
120 myMainFrame->RadioButton1->setChecked( true );
121 myMainFrame->RadioButton4->hide();
124 void GEOMBase_Skeleton::initSpinBox( QDoubleSpinBox* spinBox,
125 double min, double max,
126 double step, int decimals )
128 spinBox->setRange( min, max );
129 spinBox->setSingleStep( step );
130 spinBox->setDecimals( decimals );
133 //=================================================================================
134 // function : ClickOnCancel()
136 //=================================================================================
137 void GEOMBase_Skeleton::ClickOnCancel()
143 //=================================================================================
144 // function : LineEditReturnPressed()
146 //=================================================================================
147 void GEOMBase_Skeleton::LineEditReturnPressed()
149 if ( !myEditCurrentArgument )
152 /* User name of object input management */
153 /* If successfull the selection is changed and signal emitted... */
154 /* so SelectionIntoArgument() is automatically called. */
155 const QString objectUserName = myEditCurrentArgument->text();
156 QWidget* thisWidget = (QWidget*)this;
158 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
159 myEditCurrentArgument->setText( objectUserName );
163 //=================================================================================
164 // function : DeactivateActiveDialog()
166 //=================================================================================
167 void GEOMBase_Skeleton::DeactivateActiveDialog()
169 this->setEnabled( false );
171 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
172 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( 0 );
176 //=================================================================================
177 // function : ActivateThisDialog()
179 //=================================================================================
180 void GEOMBase_Skeleton::ActivateThisDialog()
182 /* Emit a signal to deactivate the active dialog */
183 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
184 this->setEnabled( true );
185 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
190 //=================================================================================
191 // function : closeEvent()
192 // purpose : same than click on cancel button
193 //=================================================================================
194 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
196 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
198 disconnect( app->selectionMgr(), 0, this, 0 );
199 app->updateActions();
201 QDialog::closeEvent( e );
204 //=================================================================================
205 // function : initName()
206 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
207 //=================================================================================
208 void GEOMBase_Skeleton::initName( const QString& thePrefix )
210 if ( !thePrefix.isNull() )
211 setPrefix( thePrefix );
212 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
215 //=================================================================================
216 // function : getNewObjectName()
217 // purpose : returns contents of Name field
218 //=================================================================================
219 const char* GEOMBase_Skeleton::getNewObjectName() const
221 return myMainFrame->ResultName->text().toLatin1().constData();
224 //=================================================================================
225 // function : getConstructorId()
227 //=================================================================================
228 int GEOMBase_Skeleton::getConstructorId() const
230 /*if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
231 return GroupConstructors->id( GroupConstructors->selected() );
234 if ( myRBGroup != NULL )
235 return myRBGroup->checkedId();
239 //=================================================================================
240 // function : ClickOnHelp()
242 //=================================================================================
243 void GEOMBase_Skeleton::ClickOnHelp()
245 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
247 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
251 platform = "winapplication";
253 platform = "application";
255 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
256 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
257 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
258 QObject::tr( "BUT_OK" ) );
261 //=================================================================================
262 // function : setHelpFileName()
263 // purpose : set name for help file html
264 //=================================================================================
266 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
268 myHelpFileName = theName;
271 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
276 QWidget* GEOMBase_Skeleton::centralWidget()
278 return myMainFrame->GroupMedium;
281 QPushButton* GEOMBase_Skeleton::buttonCancel() const
283 return myMainFrame->buttonCancel;
286 QPushButton* GEOMBase_Skeleton::buttonOk() const
288 return myMainFrame->buttonOk;
291 QPushButton* GEOMBase_Skeleton::buttonApply() const
293 return myMainFrame->buttonApply;
296 QPushButton* GEOMBase_Skeleton::buttonHelp() const
298 return myMainFrame->buttonHelp;
301 //=================================================================================
302 // function : keyPressEvent()
304 //=================================================================================
305 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
307 QDialog::keyPressEvent( e );
308 if ( e->isAccepted() )
311 if ( e->key() == Qt::Key_F1 ) {