]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMBase/GEOMBase_Skeleton.cxx
Salome HOME
Remove some methods of GEOMBase_Helper (IObjectCount(), firstIObject(), lastIObject...
[modules/geom.git] / src / GEOMBase / GEOMBase_Skeleton.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : GEOMBase_Skeleton.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
24 //
25
26 #include "GEOMBase_Skeleton.h"
27 #include "GEOMBase.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31
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>
39
40 #include <QKeyEvent>
41 #include <QSpinBox>
42 #include <QDoubleSpinBox>
43
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 ),
56     myRBGroup( 0 )
57 {
58   setAttribute( Qt::WA_DeleteOnClose );
59
60   setModal( modal );
61
62   myMainFrame = new DlgRef_Skeleton( this );
63   QVBoxLayout* topLayout = new QVBoxLayout( this );
64   topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
65   topLayout->addWidget( myMainFrame );
66
67   myMainFrame->GroupBoxName->setTitle( tr( "GEOM_RESULT_NAME_GRP" ) );
68   myMainFrame->NameLabel->setText( tr( "GEOM_RESULT_NAME_LBL" ) );
69
70   myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
71   myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
72
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" ) );
77
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 );
84
85   connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
86
87   Init();
88 }
89
90 //=================================================================================
91 // function : ~GEOMBase_Skeleton()
92 // purpose  : Destroys the object and frees any allocated resources
93 //=================================================================================
94 GEOMBase_Skeleton::~GEOMBase_Skeleton()
95 {
96   if ( myGeomGUI )
97     myGeomGUI->SetActiveDialogBox( 0 );
98 }
99
100 //=================================================================================
101 // function : Init()
102 // purpose  :
103 //=================================================================================
104 void GEOMBase_Skeleton::Init()
105 {
106   SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
107   if ( !myGeomGUI && app )
108     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
109
110   /* init variables */
111   if ( myGeomGUI )
112     myGeomGUI->SetActiveDialogBox( this );
113
114   /* signals and slots connections */
115   connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
116   if ( myGeomGUI ) {
117     connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
118     connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
119   }
120
121   // connect help button on a private slot that displays help information
122   connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
123
124   /* displays Dialog */
125   myMainFrame->RadioButton1->setChecked( true );
126   myMainFrame->RadioButton4->hide();
127   myMainFrame->RadioButton5->hide();
128
129   myMainFrame->CheckBoxRestoreSS->setChecked( false );
130   myMainFrame->GroupBoxPublish->hide();
131 }
132
133 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox, 
134                                      int min,  int max, int step )
135 {
136   spinBox->setRange( min, max );
137   spinBox->setSingleStep( step );
138 }
139
140 void GEOMBase_Skeleton::initSpinBox( QDoubleSpinBox* spinBox, 
141                                      double min,  double max, 
142                                      double step, int decimals )
143 {
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 );
148 }
149
150 //=================================================================================
151 // function : ClickOnCancel()
152 // purpose  :
153 //=================================================================================
154 void GEOMBase_Skeleton::ClickOnCancel()
155 {
156   close();
157 }
158
159 //=================================================================================
160 // function : LineEditReturnPressed()
161 // purpose  :
162 //=================================================================================
163 void GEOMBase_Skeleton::LineEditReturnPressed()
164 {
165   if (!myEditCurrentArgument)
166     return;
167
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;
173
174   SALOME_ListIO aList;
175   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
176   if (aSelMgr)
177     aSelMgr->selectedObjects(aList);
178   if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
179     myEditCurrentArgument->setText(objectUserName);
180 }
181
182 //=================================================================================
183 // function : DeactivateActiveDialog()
184 // purpose  :
185 //=================================================================================
186 void GEOMBase_Skeleton::DeactivateActiveDialog()
187 {
188   this->setEnabled( false );
189   globalSelection();
190   if ( myGeomGUI ) {
191     myGeomGUI->SetActiveDialogBox( 0 );
192     disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
193   }
194 }
195
196 //=================================================================================
197 // function : ActivateThisDialog()
198 // purpose  :
199 //=================================================================================
200 void GEOMBase_Skeleton::ActivateThisDialog()
201 {
202   /* Emit a signal to deactivate the active dialog */
203   if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
204   this->setEnabled( true );
205   if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
206   return;
207 }
208
209 //=================================================================================
210 // function : closeEvent()
211 // purpose  : same than click on cancel button
212 //=================================================================================
213 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
214 {
215   if ( myGeomGUI ) {
216     disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
217     myGeomGUI->getApp()->updateActions();
218   }
219   QDialog::closeEvent( e );
220 }
221
222 //=================================================================================
223 // function : initName()
224 // purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
225 //=================================================================================
226 void GEOMBase_Skeleton::initName( const QString& thePrefix )
227 {
228   if ( !thePrefix.isNull() )
229     setPrefix( thePrefix );
230   myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
231 }
232
233 //=================================================================================
234 // function : getNewObjectName()
235 // purpose  : returns contents of Name field
236 //=================================================================================
237 QString GEOMBase_Skeleton::getNewObjectName() const
238 {
239   return myMainFrame->ResultName->text();
240 }
241
242 //=================================================================================
243 // function : getConstructorId()
244 // purpose  :
245 //=================================================================================
246 int GEOMBase_Skeleton::getConstructorId() const
247 {
248   if ( myRBGroup )
249     return myRBGroup->checkedId();
250   return -1;
251 }
252
253 void GEOMBase_Skeleton::setConstructorId( const int id )
254 {
255   if ( myRBGroup && myRBGroup->button( id ) )
256     myRBGroup->button( id )->setChecked( true );
257 }
258
259 //=================================================================================
260 // function : ClickOnHelp()
261 // purpose  :
262 //=================================================================================
263 void GEOMBase_Skeleton::ClickOnHelp()
264 {
265   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
266   if ( app ) 
267     app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
268   else {
269     QString platform;
270 #ifdef WIN32
271     platform = "winapplication";
272 #else
273     platform = "application";
274 #endif
275     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
276                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
277                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
278                               QObject::tr( "BUT_OK" ) );
279   }
280 }
281
282 //=================================================================================
283 //  function : setHelpFileName()
284 //  purpose  : set name for help file html
285 //=================================================================================
286 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
287 {
288   myHelpFileName = theName;
289 }
290
291 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
292 {
293   return myMainFrame;
294 }
295
296 QWidget* GEOMBase_Skeleton::centralWidget()
297 {
298   return myMainFrame->GroupMedium;
299 }
300
301 QPushButton* GEOMBase_Skeleton::buttonCancel() const
302 {
303   return myMainFrame->buttonCancel;
304 }
305
306 QPushButton* GEOMBase_Skeleton::buttonOk() const
307 {
308   return myMainFrame->buttonOk;
309 }
310
311 QPushButton* GEOMBase_Skeleton::buttonApply() const
312 {
313   return myMainFrame->buttonApply;
314 }
315
316 QPushButton* GEOMBase_Skeleton::buttonHelp() const
317 {
318   return myMainFrame->buttonHelp;
319 }
320
321 //=================================================================================
322 // function : keyPressEvent()
323 // purpose  :
324 //=================================================================================
325 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
326 {
327   QDialog::keyPressEvent( e );
328   if ( e->isAccepted() )
329     return;
330
331   if ( e->key() == Qt::Key_F1 ) {
332     e->accept();
333     ClickOnHelp();
334   }
335 }