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;
175 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
177 aSelMgr->selectedObjects(aList);
178 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
179 myEditCurrentArgument->setText(objectUserName);
182 //=================================================================================
183 // function : DeactivateActiveDialog()
185 //=================================================================================
186 void GEOMBase_Skeleton::DeactivateActiveDialog()
188 this->setEnabled( false );
191 myGeomGUI->SetActiveDialogBox( 0 );
192 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
197 //=================================================================================
198 // function : ActivateThisDialog()
200 //=================================================================================
201 void GEOMBase_Skeleton::ActivateThisDialog()
203 /* Emit a signal to deactivate the active dialog */
204 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
205 this->setEnabled( true );
206 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
210 //=================================================================================
211 // function : closeEvent()
212 // purpose : same than click on cancel button
213 //=================================================================================
214 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
217 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
218 myGeomGUI->getApp()->updateActions();
220 QDialog::closeEvent( e );
223 //=================================================================================
224 // function : initName()
225 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
226 //=================================================================================
227 void GEOMBase_Skeleton::initName( const QString& thePrefix )
229 if ( !thePrefix.isNull() )
230 setPrefix( thePrefix );
231 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
234 //=================================================================================
235 // function : getNewObjectName()
236 // purpose : returns contents of Name field
237 //=================================================================================
238 QString GEOMBase_Skeleton::getNewObjectName() const
240 return myMainFrame->ResultName->text();
243 //=================================================================================
244 // function : getConstructorId()
246 //=================================================================================
247 int GEOMBase_Skeleton::getConstructorId() const
250 return myRBGroup->checkedId();
254 void GEOMBase_Skeleton::setConstructorId( const int id )
256 if ( myRBGroup && myRBGroup->button( id ) )
257 myRBGroup->button( id )->setChecked( true );
260 //=================================================================================
261 // function : ClickOnHelp()
263 //=================================================================================
264 void GEOMBase_Skeleton::ClickOnHelp()
266 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
268 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
272 platform = "winapplication";
274 platform = "application";
276 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
277 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
278 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
279 QObject::tr( "BUT_OK" ) );
283 //=================================================================================
284 // function : setHelpFileName()
285 // purpose : set name for help file html
286 //=================================================================================
287 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
289 myHelpFileName = theName;
292 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
297 QWidget* GEOMBase_Skeleton::centralWidget()
299 return myMainFrame->GroupMedium;
302 QPushButton* GEOMBase_Skeleton::buttonCancel() const
304 return myMainFrame->buttonCancel;
307 QPushButton* GEOMBase_Skeleton::buttonOk() const
309 return myMainFrame->buttonOk;
312 QPushButton* GEOMBase_Skeleton::buttonApply() const
314 return myMainFrame->buttonApply;
317 QPushButton* GEOMBase_Skeleton::buttonHelp() const
319 return myMainFrame->buttonHelp;
322 //=================================================================================
323 // function : keyPressEvent()
325 //=================================================================================
326 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
328 QDialog::keyPressEvent( e );
329 if ( e->isAccepted() )
332 if ( e->key() == Qt::Key_F1 ) {