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"
30 #include <GeometryGUI.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>
44 //=================================================================================
45 // class : GEOMBase_Skeleton()
46 // purpose : Constructs a GEOMBase_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 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
52 bool modal, Qt::WindowFlags fl )
53 : QDialog( parent, fl ),
54 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
55 myGeomGUI( theGeometryGUI ),
58 setAttribute( Qt::WA_DeleteOnClose );
62 myMainFrame = new DlgRef_Skeleton( this );
63 QVBoxLayout* topLayout = new QVBoxLayout( this );
64 topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
65 topLayout->addWidget( myMainFrame );
67 myMainFrame->GroupBoxName->setTitle( tr( "GEOM_RESULT_NAME_GRP" ) );
68 myMainFrame->NameLabel->setText( tr( "GEOM_RESULT_NAME_LBL" ) );
70 myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
71 myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
73 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
74 buttonOk()->setText( tr( "GEOM_BUT_APPLY_AND_CLOSE" ) );
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, 3 );
83 myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
85 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 );
100 //=================================================================================
103 //=================================================================================
104 void GEOMBase_Skeleton::Init()
106 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
107 if ( !myGeomGUI && app )
108 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();
127 myMainFrame->RadioButton5->hide();
129 myMainFrame->CheckBoxRestoreSS->setChecked( false );
130 myMainFrame->GroupBoxPublish->hide();
133 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
134 int min, int max, int step )
136 spinBox->setRange( min, max );
137 spinBox->setSingleStep( step );
140 void GEOMBase_Skeleton::initSpinBox( QDoubleSpinBox* spinBox,
141 double min, double max,
142 double step, int decimals )
144 spinBox->setDecimals( decimals ); // it's necessary to set decimals before the range setting,
145 // by default Qt rounds boundaries to 2 decimals at setRange
146 spinBox->setRange( min, max );
147 spinBox->setSingleStep( step );
150 //=================================================================================
151 // function : ClickOnCancel()
153 //=================================================================================
154 void GEOMBase_Skeleton::ClickOnCancel()
159 //=================================================================================
160 // function : LineEditReturnPressed()
162 //=================================================================================
163 void GEOMBase_Skeleton::LineEditReturnPressed()
165 if ( !myEditCurrentArgument )
168 /* User name of object input management */
169 /* If successfull the selection is changed and signal emitted... */
170 /* so SelectionIntoArgument() is automatically called. */
171 const QString objectUserName = myEditCurrentArgument->text();
172 QWidget* thisWidget = (QWidget*)this;
174 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
175 myEditCurrentArgument->setText( objectUserName );
178 //=================================================================================
179 // function : DeactivateActiveDialog()
181 //=================================================================================
182 void GEOMBase_Skeleton::DeactivateActiveDialog()
184 this->setEnabled( false );
187 myGeomGUI->SetActiveDialogBox( 0 );
188 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
192 //=================================================================================
193 // function : ActivateThisDialog()
195 //=================================================================================
196 void GEOMBase_Skeleton::ActivateThisDialog()
198 /* Emit a signal to deactivate the active dialog */
199 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
200 this->setEnabled( true );
201 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
205 //=================================================================================
206 // function : closeEvent()
207 // purpose : same than click on cancel button
208 //=================================================================================
209 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
212 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
213 myGeomGUI->getApp()->updateActions();
215 QDialog::closeEvent( e );
218 //=================================================================================
219 // function : initName()
220 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
221 //=================================================================================
222 void GEOMBase_Skeleton::initName( const QString& thePrefix )
224 if ( !thePrefix.isNull() )
225 setPrefix( thePrefix );
226 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
229 //=================================================================================
230 // function : getNewObjectName()
231 // purpose : returns contents of Name field
232 //=================================================================================
233 QString GEOMBase_Skeleton::getNewObjectName() const
235 return myMainFrame->ResultName->text();
238 //=================================================================================
239 // function : getConstructorId()
241 //=================================================================================
242 int GEOMBase_Skeleton::getConstructorId() const
245 return myRBGroup->checkedId();
249 void GEOMBase_Skeleton::setConstructorId( const int id )
251 if ( myRBGroup && myRBGroup->button( id ) )
252 myRBGroup->button( id )->setChecked( true );
255 //=================================================================================
256 // function : ClickOnHelp()
258 //=================================================================================
259 void GEOMBase_Skeleton::ClickOnHelp()
261 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
263 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
267 platform = "winapplication";
269 platform = "application";
271 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
272 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
273 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
274 QObject::tr( "BUT_OK" ) );
278 //=================================================================================
279 // function : setHelpFileName()
280 // purpose : set name for help file html
281 //=================================================================================
282 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
284 myHelpFileName = theName;
287 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
292 QWidget* GEOMBase_Skeleton::centralWidget()
294 return myMainFrame->GroupMedium;
297 QPushButton* GEOMBase_Skeleton::buttonCancel() const
299 return myMainFrame->buttonCancel;
302 QPushButton* GEOMBase_Skeleton::buttonOk() const
304 return myMainFrame->buttonOk;
307 QPushButton* GEOMBase_Skeleton::buttonApply() const
309 return myMainFrame->buttonApply;
312 QPushButton* GEOMBase_Skeleton::buttonHelp() const
314 return myMainFrame->buttonHelp;
317 //=================================================================================
318 // function : keyPressEvent()
320 //=================================================================================
321 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
323 QDialog::keyPressEvent( e );
324 if ( e->isAccepted() )
327 if ( e->key() == Qt::Key_F1 ) {