]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMBase/GEOMBase_Skeleton.cxx
Salome HOME
3a1cd3217b98cea805adec3411e0169c9d476e90
[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
31 #include <SalomeApp_Application.h>
32 #include <LightApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_MessageBox.h>
38
39 #include <QKeyEvent>
40
41 using namespace std;
42
43 //=================================================================================
44 // class    : GEOMBase_Skeleton()
45 // purpose  : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the 
46 //            name 'name' and widget flags set to 'f'.
47 //            The dialog will by default be modeless, unless you set 'modal' to
48 //            TRUE to construct a modal dialog.
49 //=================================================================================
50 GEOMBase_Skeleton::GEOMBase_Skeleton(GeometryGUI* theGeometryGUI, QWidget* parent,
51                                      const char* name, bool modal, Qt::WindowFlags fl)
52   : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ), 
53     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
54     myGeomGUI( theGeometryGUI ),
55     myRBGroup( 0 )
56 {
57   setupUi(this);
58
59   if (!name)
60     setObjectName("GEOMBase_Skeleton");
61   else
62     setObjectName(name);
63
64   setModal( modal );
65   setAttribute( Qt::WA_DeleteOnClose );
66
67   buttonCancel->setText(tr("GEOM_BUT_CLOSE"));
68   buttonOk->setText(tr("GEOM_BUT_OK"));
69   buttonApply->setText(tr("GEOM_BUT_APPLY"));
70   buttonHelp->setText(tr("GEOM_BUT_HELP"));
71
72   GroupMedium->setAttribute( Qt::WA_DeleteOnClose );
73   GroupMedium->close();
74   resize(0, 0);
75
76   if ( GroupConstructors != NULL ) {
77     myRBGroup = new QButtonGroup(GroupConstructors);
78     QList<QObject*> aRadioButtons = GroupConstructors->children();
79     QListIterator<QObject*> it( aRadioButtons );
80     int anId = 0;
81     while ( it.hasNext() )
82       if ( QRadioButton* aRB = ::qobject_cast<QRadioButton*>( it.next() ) ) {
83         myRBGroup->addButton( aRB, anId );
84         anId++;
85       }
86   }
87
88   Init();
89 }
90
91
92 //=================================================================================
93 // function : ~GEOMBase_Skeleton()
94 // purpose  : Destroys the object and frees any allocated resources
95 //=================================================================================
96 GEOMBase_Skeleton::~GEOMBase_Skeleton()
97 {
98   if (myGeomGUI)
99     myGeomGUI->SetActiveDialogBox( 0 );
100 }
101
102
103 //=================================================================================
104 // function : Init()
105 // purpose  :
106 //=================================================================================
107 void GEOMBase_Skeleton::Init()
108 {
109   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
110   if (!myGeomGUI && app)
111     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
112
113   /* init variables */
114   myGeomGUI->SetActiveDialogBox(this);
115
116   /* signals and slots connections */
117   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
118   if (myGeomGUI) 
119   {
120     connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
121     connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
122   }
123
124   // connect help button on a private slot that displays help information
125   connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
126
127   /* displays Dialog */
128   RadioButton1->setChecked(TRUE);
129   RadioButton4->hide();
130
131   return;
132 }
133
134
135 //=================================================================================
136 // function : ClickOnCancel()
137 // purpose  :
138 //=================================================================================
139 void GEOMBase_Skeleton::ClickOnCancel()
140 {
141   close();
142 }
143
144
145 //=================================================================================
146 // function : LineEditReturnPressed()
147 // purpose  :
148 //=================================================================================
149 void GEOMBase_Skeleton::LineEditReturnPressed()
150 {
151   if ( !myEditCurrentArgument )
152     return;
153
154   /* User name of object input management                          */
155   /* If successfull the selection is changed and signal emitted... */
156   /* so SelectionIntoArgument() is automatically called.           */
157   const QString objectUserName = myEditCurrentArgument->text();
158   QWidget* thisWidget = (QWidget*)this;
159   
160   if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
161      myEditCurrentArgument->setText(objectUserName);
162
163   return;
164 }
165
166
167 //=================================================================================
168 // function : DeactivateActiveDialog()
169 // purpose  :
170 //=================================================================================
171 void GEOMBase_Skeleton::DeactivateActiveDialog()
172 {
173   this->setEnabled(false);
174   globalSelection();
175   disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
176   if (myGeomGUI) myGeomGUI->SetActiveDialogBox(0);
177     
178   return;
179 }
180
181
182 //=================================================================================
183 // function : ActivateThisDialog()
184 // purpose  :
185 //=================================================================================
186 void GEOMBase_Skeleton::ActivateThisDialog()
187 {
188   /* Emit a signal to deactivate the active dialog */
189   if (myGeomGUI) myGeomGUI->EmitSignalDeactivateDialog();
190   this->setEnabled(true);
191   if (myGeomGUI) myGeomGUI->SetActiveDialogBox((QDialog*)this);
192   return;
193 }
194
195
196 //=================================================================================
197 // function : closeEvent()
198 // purpose  : same than click on cancel button
199 //=================================================================================
200 void GEOMBase_Skeleton::closeEvent(QCloseEvent* e)
201 {
202   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
203   if(app) {
204     disconnect( app->selectionMgr(), 0, this, 0);
205     app->updateActions();
206   }
207   QDialog::closeEvent( e );
208 }
209
210 //=================================================================================
211 // function : initName()
212 // purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
213 //=================================================================================
214 void GEOMBase_Skeleton::initName( const char* thePrefix )
215 {
216   if ( thePrefix )
217     setPrefix( thePrefix );
218   ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
219 }
220
221 //=================================================================================
222 // function : getNewObjectName()
223 // purpose  : returns contents of Name field
224 //=================================================================================
225 const char* GEOMBase_Skeleton::getNewObjectName() const
226 {
227   return ResultName->text().toLatin1().constData();
228 }
229
230 //=================================================================================
231 // function : getConstructorId()
232 // purpose  :
233 //=================================================================================
234 int GEOMBase_Skeleton::getConstructorId() const
235 {
236   /*if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
237     return GroupConstructors->id( GroupConstructors->selected() );
238     return -1;*/
239
240   if ( myRBGroup != NULL )
241     return myRBGroup->checkedId();
242   return -1;
243 }
244
245 //=================================================================================
246 // function : ClickOnHelp()
247 // purpose  :
248 //=================================================================================
249 void GEOMBase_Skeleton::ClickOnHelp()
250 {
251   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
252   if (app) 
253     app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
254   else {
255                 QString platform;
256 #ifdef WIN32
257                 platform = "winapplication";
258 #else
259                 platform = "application";
260 #endif
261     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
262                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
263                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
264                              QObject::tr("BUT_OK"));
265   }
266 }
267 //=================================================================================
268 //  function : setHelpFileName()
269 //  purpose  : set name for help file html
270 //=================================================================================
271
272 void GEOMBase_Skeleton::setHelpFileName(const QString& theName)
273 {
274     myHelpFileName = theName;
275 }
276
277 //=================================================================================
278 // function : keyPressEvent()
279 // purpose  :
280 //=================================================================================
281 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
282 {
283   QDialog::keyPressEvent( e );
284   if ( e->isAccepted() )
285     return;
286
287   if ( e->key() == Qt::Key_F1 )
288     {
289       e->accept();
290       ClickOnHelp();
291     }
292 }