Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[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 <qpushbutton.h>
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, WFlags fl)
52   : DlgRef_Skeleton_QTD( parent, name, modal, WStyle_Customize | WStyle_NormalBorder
53                          | WStyle_Title | WStyle_SysMenu | WDestructiveClose ), 
54    GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
55    myGeomGUI( theGeometryGUI )
56 {
57   if (!name)
58     setName("GEOMBase_Skeleton");
59
60   buttonCancel->setText(tr("GEOM_BUT_CLOSE"));
61   buttonOk->setText(tr("GEOM_BUT_OK"));
62   buttonApply->setText(tr("GEOM_BUT_APPLY"));
63   buttonHelp->setText(tr("GEOM_BUT_HELP"));
64
65   GroupMedium->close(TRUE);
66   resize(0, 0);
67
68   Init();
69 }
70
71
72 //=================================================================================
73 // function : ~GEOMBase_Skeleton()
74 // purpose  : Destroys the object and frees any allocated resources
75 //=================================================================================
76 GEOMBase_Skeleton::~GEOMBase_Skeleton()
77 {
78   if (myGeomGUI)
79     myGeomGUI->SetActiveDialogBox( 0 );
80 }
81
82
83 //=================================================================================
84 // function : Init()
85 // purpose  :
86 //=================================================================================
87 void GEOMBase_Skeleton::Init()
88 {
89   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
90   if (!myGeomGUI && app)
91     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
92
93   /* init variables */
94   myGeomGUI->SetActiveDialogBox(this);
95
96   /* signals and slots connections */
97   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
98   if (myGeomGUI) 
99   {
100     connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
101     connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
102   }
103
104   // connect help button on a private slot that displays help information
105   connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
106
107   /* displays Dialog */
108   RadioButton1->setChecked(TRUE);
109   RadioButton4->hide();
110
111   return;
112 }
113
114
115 //=================================================================================
116 // function : ClickOnCancel()
117 // purpose  :
118 //=================================================================================
119 void GEOMBase_Skeleton::ClickOnCancel()
120 {
121   close();
122 }
123
124
125 //=================================================================================
126 // function : LineEditReturnPressed()
127 // purpose  :
128 //=================================================================================
129 void GEOMBase_Skeleton::LineEditReturnPressed()
130 {
131   if ( !myEditCurrentArgument )
132     return;
133
134   /* User name of object input management                          */
135   /* If successfull the selection is changed and signal emitted... */
136   /* so SelectionIntoArgument() is automatically called.           */
137   const QString objectUserName = myEditCurrentArgument->text();
138   QWidget* thisWidget = (QWidget*)this;
139   
140   if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
141      myEditCurrentArgument->setText(objectUserName);
142
143   return;
144 }
145
146
147 //=================================================================================
148 // function : DeactivateActiveDialog()
149 // purpose  :
150 //=================================================================================
151 void GEOMBase_Skeleton::DeactivateActiveDialog()
152 {
153   this->setEnabled(false);
154   globalSelection();
155   disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
156   if (myGeomGUI) myGeomGUI->SetActiveDialogBox(0);
157     
158   return;
159 }
160
161
162 //=================================================================================
163 // function : ActivateThisDialog()
164 // purpose  :
165 //=================================================================================
166 void GEOMBase_Skeleton::ActivateThisDialog()
167 {
168   /* Emit a signal to deactivate the active dialog */
169   if (myGeomGUI) myGeomGUI->EmitSignalDeactivateDialog();
170   this->setEnabled(true);
171   if (myGeomGUI) myGeomGUI->SetActiveDialogBox((QDialog*)this);
172   return;
173 }
174
175
176 //=================================================================================
177 // function : closeEvent()
178 // purpose  : same than click on cancel button
179 //=================================================================================
180 void GEOMBase_Skeleton::closeEvent(QCloseEvent* e)
181 {
182   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
183   if(app) {
184     disconnect( app->selectionMgr(), 0, this, 0);
185     app->updateActions();
186   }
187   QDialog::closeEvent( e );
188 }
189
190 //=================================================================================
191 // function : initName()
192 // purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
193 //=================================================================================
194 void GEOMBase_Skeleton::initName( const char* thePrefix )
195 {
196   if ( thePrefix )
197     setPrefix( thePrefix );
198   ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
199 }
200
201 //=================================================================================
202 // function : getNewObjectName()
203 // purpose  : returns contents of Name field
204 //=================================================================================
205 const char* GEOMBase_Skeleton::getNewObjectName() const
206 {
207   return ResultName->text();
208 }
209
210 //=================================================================================
211 // function : getConstructorId()
212 // purpose  :
213 //=================================================================================
214 int GEOMBase_Skeleton::getConstructorId() const
215 {
216   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
217     return GroupConstructors->id( GroupConstructors->selected() );
218   return -1;
219 }
220
221 //=================================================================================
222 // function : ClickOnHelp()
223 // purpose  :
224 //=================================================================================
225 void GEOMBase_Skeleton::ClickOnHelp()
226 {
227   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
228   if (app) 
229     app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
230   else {
231     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
232                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
233                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
234                            QObject::tr("BUT_OK"));
235   }
236 }
237 //=================================================================================
238 //  function : setHelpFileName()
239 //  purpose  : set name for help file html
240 //=================================================================================
241
242 void GEOMBase_Skeleton::setHelpFileName(const QString& theName)
243 {
244     myHelpFileName = theName;
245 }