]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMBase/GEOMBase_Skeleton.cxx
Salome HOME
0014047: EDF PAL 334 : Problem to select merged face with Create group window
[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   erasePreview();
195 }
196
197 //=================================================================================
198 // function : ActivateThisDialog()
199 // purpose  :
200 //=================================================================================
201 void GEOMBase_Skeleton::ActivateThisDialog()
202 {
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 );
207   return;
208 }
209
210 //=================================================================================
211 // function : closeEvent()
212 // purpose  : same than click on cancel button
213 //=================================================================================
214 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
215 {
216   if ( myGeomGUI ) {
217     disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
218     myGeomGUI->getApp()->updateActions();
219   }
220   QDialog::closeEvent( e );
221 }
222
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 )
228 {
229   if ( !thePrefix.isNull() )
230     setPrefix( thePrefix );
231   myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
232 }
233
234 //=================================================================================
235 // function : getNewObjectName()
236 // purpose  : returns contents of Name field
237 //=================================================================================
238 QString GEOMBase_Skeleton::getNewObjectName() const
239 {
240   return myMainFrame->ResultName->text();
241 }
242
243 //=================================================================================
244 // function : getConstructorId()
245 // purpose  :
246 //=================================================================================
247 int GEOMBase_Skeleton::getConstructorId() const
248 {
249   if ( myRBGroup )
250     return myRBGroup->checkedId();
251   return -1;
252 }
253
254 void GEOMBase_Skeleton::setConstructorId( const int id )
255 {
256   if ( myRBGroup && myRBGroup->button( id ) )
257     myRBGroup->button( id )->setChecked( true );
258 }
259
260 //=================================================================================
261 // function : ClickOnHelp()
262 // purpose  :
263 //=================================================================================
264 void GEOMBase_Skeleton::ClickOnHelp()
265 {
266   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
267   if ( app ) 
268     app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
269   else {
270     QString platform;
271 #ifdef WIN32
272     platform = "winapplication";
273 #else
274     platform = "application";
275 #endif
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" ) );
280   }
281 }
282
283 //=================================================================================
284 //  function : setHelpFileName()
285 //  purpose  : set name for help file html
286 //=================================================================================
287 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
288 {
289   myHelpFileName = theName;
290 }
291
292 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
293 {
294   return myMainFrame;
295 }
296
297 QWidget* GEOMBase_Skeleton::centralWidget()
298 {
299   return myMainFrame->GroupMedium;
300 }
301
302 QPushButton* GEOMBase_Skeleton::buttonCancel() const
303 {
304   return myMainFrame->buttonCancel;
305 }
306
307 QPushButton* GEOMBase_Skeleton::buttonOk() const
308 {
309   return myMainFrame->buttonOk;
310 }
311
312 QPushButton* GEOMBase_Skeleton::buttonApply() const
313 {
314   return myMainFrame->buttonApply;
315 }
316
317 QPushButton* GEOMBase_Skeleton::buttonHelp() const
318 {
319   return myMainFrame->buttonHelp;
320 }
321
322 //=================================================================================
323 // function : keyPressEvent()
324 // purpose  :
325 //=================================================================================
326 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
327 {
328   QDialog::keyPressEvent( e );
329   if ( e->isAccepted() )
330     return;
331
332   if ( e->key() == Qt::Key_F1 ) {
333     e->accept();
334     ClickOnHelp();
335   }
336 }