]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMBase/GEOMBase_Skeleton.cxx
Salome HOME
NPAL13898 Ok Apply Close laborious for User...
[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 //
23 //
24 //  File   : GEOMBase_Skeleton.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GEOMBase_Skeleton.h"
30
31 #include "GeometryGUI.h"
32
33 #include "SalomeApp_Application.h"
34 #include "LightApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36 #include "SUIT_Session.h"
37 #include "SUIT_MessageBox.h"
38
39 #include <qlabel.h>
40 #include <qpushbutton.h>
41
42 using namespace std;
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                                      const char* name, bool modal, WFlags fl)
53   : DlgRef_Skeleton_QTD( parent, name, modal, WStyle_Customize | WStyle_NormalBorder
54                          | WStyle_Title | WStyle_SysMenu | WDestructiveClose ), 
55    GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
56    myGeomGUI( theGeometryGUI )
57 {
58   if (!name)
59     setName("GEOMBase_Skeleton");
60
61   GroupBoxName->setTitle(tr("GEOM_RESULT_NAME_GRP"));
62   NameLabel->setText(tr("GEOM_RESULT_NAME_LBL"));
63
64   buttonCancel->setText(tr("GEOM_BUT_CLOSE"));
65   buttonOk->setText(tr("GEOM_BUT_APPLY_AND_CLOSE"));
66   buttonApply->setText(tr("GEOM_BUT_APPLY"));
67   buttonHelp->setText(tr("GEOM_BUT_HELP"));
68
69   resize(0, 0);
70
71   Init();
72 }
73
74
75 //=================================================================================
76 // function : ~GEOMBase_Skeleton()
77 // purpose  : Destroys the object and frees any allocated resources
78 //=================================================================================
79 GEOMBase_Skeleton::~GEOMBase_Skeleton()
80 {
81   if (myGeomGUI)
82     myGeomGUI->SetActiveDialogBox( 0 );
83 }
84
85
86 //=================================================================================
87 // function : Init()
88 // purpose  :
89 //=================================================================================
90 void GEOMBase_Skeleton::Init()
91 {
92   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
93   if (!myGeomGUI && app)
94     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
95
96   /* init variables */
97   myGeomGUI->SetActiveDialogBox(this);
98
99   /* signals and slots connections */
100   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
101   if (myGeomGUI) 
102   {
103     connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
104     connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
105   }
106
107   // connect help button on a private slot that displays help information
108   connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
109
110   /* displays Dialog */
111   RadioButton1->setChecked(TRUE);
112   RadioButton4->hide();
113
114   return;
115 }
116
117
118 //=================================================================================
119 // function : ClickOnCancel()
120 // purpose  :
121 //=================================================================================
122 void GEOMBase_Skeleton::ClickOnCancel()
123 {
124   close();
125 }
126
127
128 //=================================================================================
129 // function : LineEditReturnPressed()
130 // purpose  :
131 //=================================================================================
132 void GEOMBase_Skeleton::LineEditReturnPressed()
133 {
134   if ( !myEditCurrentArgument )
135     return;
136
137   /* User name of object input management                          */
138   /* If successfull the selection is changed and signal emitted... */
139   /* so SelectionIntoArgument() is automatically called.           */
140   const QString objectUserName = myEditCurrentArgument->text();
141   QWidget* thisWidget = (QWidget*)this;
142   
143   if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
144      myEditCurrentArgument->setText(objectUserName);
145
146   return;
147 }
148
149
150 //=================================================================================
151 // function : DeactivateActiveDialog()
152 // purpose  :
153 //=================================================================================
154 void GEOMBase_Skeleton::DeactivateActiveDialog()
155 {
156   this->setEnabled(false);
157   globalSelection();
158   disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
159   if (myGeomGUI) myGeomGUI->SetActiveDialogBox(0);
160     
161   return;
162 }
163
164
165 //=================================================================================
166 // function : ActivateThisDialog()
167 // purpose  :
168 //=================================================================================
169 void GEOMBase_Skeleton::ActivateThisDialog()
170 {
171   /* Emit a signal to deactivate the active dialog */
172   if (myGeomGUI) myGeomGUI->EmitSignalDeactivateDialog();
173   this->setEnabled(true);
174   if (myGeomGUI) myGeomGUI->SetActiveDialogBox((QDialog*)this);
175   return;
176 }
177
178
179 //=================================================================================
180 // function : closeEvent()
181 // purpose  : same than click on cancel button
182 //=================================================================================
183 void GEOMBase_Skeleton::closeEvent(QCloseEvent* e)
184 {
185   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
186   if(app) {
187     disconnect( app->selectionMgr(), 0, this, 0);
188     app->updateActions();
189   }
190   QDialog::closeEvent( e );
191 }
192
193 //=================================================================================
194 // function : initName()
195 // purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
196 //=================================================================================
197 void GEOMBase_Skeleton::initName( const char* thePrefix )
198 {
199   if ( thePrefix )
200     setPrefix( thePrefix );
201   ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
202 }
203
204 //=================================================================================
205 // function : getNewObjectName()
206 // purpose  : returns contents of Name field
207 //=================================================================================
208 const char* GEOMBase_Skeleton::getNewObjectName() const
209 {
210   return ResultName->text();
211 }
212
213 //=================================================================================
214 // function : getConstructorId()
215 // purpose  :
216 //=================================================================================
217 int GEOMBase_Skeleton::getConstructorId() const
218 {
219   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
220     return GroupConstructors->id( GroupConstructors->selected() );
221   return -1;
222 }
223
224 //=================================================================================
225 // function : ClickOnHelp()
226 // purpose  :
227 //=================================================================================
228 void GEOMBase_Skeleton::ClickOnHelp()
229 {
230   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
231   if (app) 
232     app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
233   else {
234                 QString platform;
235 #ifdef WIN32
236                 platform = "winapplication";
237 #else
238                 platform = "application";
239 #endif
240     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
241                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
242                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
243                            QObject::tr("BUT_OK"));
244   }
245 }
246 //=================================================================================
247 //  function : setHelpFileName()
248 //  purpose  : set name for help file html
249 //=================================================================================
250
251 void GEOMBase_Skeleton::setHelpFileName(const QString& theName)
252 {
253     myHelpFileName = theName;
254 }
255
256 //=================================================================================
257 // function : keyPressEvent()
258 // purpose  :
259 //=================================================================================
260 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
261 {
262   QDialog::keyPressEvent( e );
263   if ( e->isAccepted() )
264     return;
265
266   if ( e->key() == Key_F1 )
267     {
268       e->accept();
269       ClickOnHelp();
270     }
271 }