Salome HOME
*** empty log message ***
[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 <GeometryGUI.h>
30 #include <GEOM_DlgRef.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 <QDoubleSpinBox>
42
43 using namespace std;
44
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 ),
57     myRBGroup( 0 )
58 {
59   if ( !name )
60     setObjectName( "GEOMBase_Skeleton" );
61   else
62     setObjectName( name );
63
64   setAttribute( Qt::WA_DeleteOnClose );
65
66   setModal( modal );
67
68   myMainFrame = new DlgRef_Skeleton( this );
69   QVBoxLayout* topLayout = new QVBoxLayout( this );
70   topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
71   topLayout->addWidget( myMainFrame );
72
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" ) );
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, 4 );
83
84   connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
85
86   Init();
87 }
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 //=================================================================================
102 // function : Init()
103 // purpose  :
104 //=================================================================================
105 void GEOMBase_Skeleton::Init()
106 {
107   SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
108   if ( !myGeomGUI && app )
109     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
110
111   /* init variables */
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 }
128
129 void GEOMBase_Skeleton::initSpinBox( QDoubleSpinBox* spinBox, 
130                                      double min,  double max, 
131                                      double step, int decimals )
132 {
133   spinBox->setRange( min, max );
134   spinBox->setSingleStep( step );
135   spinBox->setDecimals( decimals );
136 }
137
138 //=================================================================================
139 // function : ClickOnCancel()
140 // purpose  :
141 //=================================================================================
142 void GEOMBase_Skeleton::ClickOnCancel()
143 {
144   close();
145 }
146
147
148 //=================================================================================
149 // function : LineEditReturnPressed()
150 // purpose  :
151 //=================================================================================
152 void GEOMBase_Skeleton::LineEditReturnPressed()
153 {
154   if ( !myEditCurrentArgument )
155     return;
156
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;
162   
163   if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
164      myEditCurrentArgument->setText( objectUserName );
165 }
166
167
168 //=================================================================================
169 // function : DeactivateActiveDialog()
170 // purpose  :
171 //=================================================================================
172 void GEOMBase_Skeleton::DeactivateActiveDialog()
173 {
174   this->setEnabled( false );
175   globalSelection();
176   disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
177   if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( 0 );
178 }
179
180
181 //=================================================================================
182 // function : ActivateThisDialog()
183 // purpose  :
184 //=================================================================================
185 void GEOMBase_Skeleton::ActivateThisDialog()
186 {
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 );
191   return;
192 }
193
194
195 //=================================================================================
196 // function : closeEvent()
197 // purpose  : same than click on cancel button
198 //=================================================================================
199 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
200 {
201   SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
202   if( app ) {
203     disconnect( app->selectionMgr(), 0, this, 0 );
204     app->updateActions();
205   }
206   QDialog::closeEvent( e );
207 }
208
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 )
214 {
215   if ( !thePrefix.isNull() )
216     setPrefix( thePrefix );
217   myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
218 }
219
220 //=================================================================================
221 // function : getNewObjectName()
222 // purpose  : returns contents of Name field
223 //=================================================================================
224 const char* GEOMBase_Skeleton::getNewObjectName() const
225 {
226   return myMainFrame->ResultName->text().toLatin1().constData();
227 }
228
229 //=================================================================================
230 // function : getConstructorId()
231 // purpose  :
232 //=================================================================================
233 int GEOMBase_Skeleton::getConstructorId() const
234 {
235   /*if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
236     return GroupConstructors->id( GroupConstructors->selected() );
237     return -1;*/
238
239   if ( myRBGroup != NULL )
240     return myRBGroup->checkedId();
241   return -1;
242 }
243
244 //=================================================================================
245 // function : ClickOnHelp()
246 // purpose  :
247 //=================================================================================
248 void GEOMBase_Skeleton::ClickOnHelp()
249 {
250   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
251   if ( app ) 
252     app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
253   else {
254     QString platform;
255 #ifdef WIN32
256     platform = "winapplication";
257 #else
258     platform = "application";
259 #endif
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" ) );
264   }
265 }
266 //=================================================================================
267 //  function : setHelpFileName()
268 //  purpose  : set name for help file html
269 //=================================================================================
270
271 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
272 {
273   myHelpFileName = theName;
274 }
275
276 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
277 {
278   return myMainFrame;
279 }
280
281 QWidget* GEOMBase_Skeleton::centralWidget()
282 {
283   return myMainFrame->GroupMedium;
284 }
285
286 QPushButton* GEOMBase_Skeleton::buttonCancel() const
287 {
288   return myMainFrame->buttonCancel;
289 }
290
291 QPushButton* GEOMBase_Skeleton::buttonOk() const
292 {
293   return myMainFrame->buttonOk;
294 }
295
296 QPushButton* GEOMBase_Skeleton::buttonApply() const
297 {
298   return myMainFrame->buttonApply;
299 }
300
301 QPushButton* GEOMBase_Skeleton::buttonHelp() const
302 {
303   return myMainFrame->buttonHelp;
304 }
305
306 //=================================================================================
307 // function : keyPressEvent()
308 // purpose  :
309 //=================================================================================
310 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
311 {
312   QDialog::keyPressEvent( e );
313   if ( e->isAccepted() )
314     return;
315
316   if ( e->key() == Qt::Key_F1 ) {
317     e->accept();
318     ClickOnHelp();
319   }
320 }