]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMBase/GEOMBase_Skeleton.cxx
Salome HOME
BugID: 9377, modifed method closeEvent
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GEOMBase_Skeleton.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GEOMBase_Skeleton.h"
31 #include "GeometryGUI.h"
32
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_SelectionMgr.h"
36
37 #include <qpushbutton.h>
38
39 //=================================================================================
40 // class    : GEOMBase_Skeleton()
41 // purpose  : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the 
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 GEOMBase_Skeleton::GEOMBase_Skeleton(QWidget* parent, const char* name, bool modal, WFlags fl)
47 :DlgRef_Skeleton_QTD(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ), GEOMBase_Helper()
48 {
49   if (!name)
50     setName("GEOMBase_Skeleton");
51
52   buttonCancel->setText(tr("GEOM_BUT_CLOSE"));
53   buttonOk->setText(tr("GEOM_BUT_OK"));
54   buttonApply->setText(tr("GEOM_BUT_APPLY"));
55
56   GroupMedium->close(TRUE);
57   resize(0, 0);
58
59   Init();
60 }
61
62
63 //=================================================================================
64 // function : ~GEOMBase_Skeleton()
65 // purpose  : Destroys the object and frees any allocated resources
66 //=================================================================================
67 GEOMBase_Skeleton::~GEOMBase_Skeleton()
68 {
69   if (myGeomGUI)
70     myGeomGUI->SetActiveDialogBox( 0 );
71 }
72
73
74 //=================================================================================
75 // function : Init()
76 // purpose  :
77 //=================================================================================
78 void GEOMBase_Skeleton::Init()
79 {
80   myGeomGUI = 0;
81   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
82   if (app)
83     {
84       SalomeApp_Module* module = dynamic_cast<SalomeApp_Module*>(app->loadModule("Geometry"));
85       if (module)
86         myGeomGUI =  dynamic_cast<GeometryGUI*>(module);
87     }
88   
89   /* init variables */
90   myGeomBase = new GEOMBase();  // SAN -- TO BE REMOVED !!!
91   myGeomGUI->SetActiveDialogBox(this);
92   
93   /* signals and slots connections */
94   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
95   if (myGeomGUI) 
96     {
97       connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
98       connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
99     }
100   
101   /* Move widget on the botton right corner of main widget */
102 //   int x, y;
103 //   myGeomBase->DefineDlgPosition( this, x, y );
104
105   /* displays Dialog */
106   RadioButton1->setChecked(TRUE);
107   RadioButton4->hide();
108
109   return;
110 }
111
112
113 //=================================================================================
114 // function : ClickOnCancel()
115 // purpose  :
116 //=================================================================================
117 void GEOMBase_Skeleton::ClickOnCancel()
118 {
119   close();
120 }
121
122
123 //=================================================================================
124 // function : LineEditReturnPressed()
125 // purpose  :
126 //=================================================================================
127 void GEOMBase_Skeleton::LineEditReturnPressed()
128 {
129   if ( !myEditCurrentArgument )
130     return;
131
132   /* User name of object input management                          */
133   /* If successfull the selection is changed and signal emitted... */
134   /* so SelectionIntoArgument() is automatically called.           */
135   const QString objectUserName = myEditCurrentArgument->text();
136   QWidget* thisWidget = (QWidget*)this;
137   
138   if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
139      myEditCurrentArgument->setText(objectUserName);
140
141   return;
142 }
143
144
145 //=================================================================================
146 // function : DeactivateActiveDialog()
147 // purpose  :
148 //=================================================================================
149 void GEOMBase_Skeleton::DeactivateActiveDialog()
150 {
151   this->setEnabled(false);
152   globalSelection();
153   disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
154   if (myGeomGUI) myGeomGUI->SetActiveDialogBox(0);
155     
156   return;
157 }
158
159
160 //=================================================================================
161 // function : ActivateThisDialog()
162 // purpose  :
163 //=================================================================================
164 void GEOMBase_Skeleton::ActivateThisDialog()
165 {
166   /* Emit a signal to deactivate the active dialog */
167   if (myGeomGUI) myGeomGUI->EmitSignalDeactivateDialog();
168   this->setEnabled(true);
169   if (myGeomGUI) myGeomGUI->SetActiveDialogBox((QDialog*)this);
170   return;
171 }
172
173
174 //=================================================================================
175 // function : closeEvent()
176 // purpose  : same than click on cancel button
177 //=================================================================================
178 void GEOMBase_Skeleton::closeEvent(QCloseEvent* e)
179 {
180   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
181   if(app) {
182     disconnect( app->selectionMgr(), 0, this, 0);
183     app->updateActions();
184   }
185   QDialog::closeEvent( e );
186 }
187
188 //=================================================================================
189 // function : initName()
190 // purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
191 //=================================================================================
192 void GEOMBase_Skeleton::initName( const char* thePrefix )
193 {
194   if ( thePrefix )
195     setPrefix( thePrefix );
196   ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
197 }
198
199 //=================================================================================
200 // function : getNewObjectName()
201 // purpose  : returns contents of Name field
202 //=================================================================================
203 const char* GEOMBase_Skeleton::getNewObjectName() const
204 {
205   return ResultName->text();
206 }
207
208 //=================================================================================
209 // function : getConstructorId()
210 // purpose  :
211 //=================================================================================
212 int GEOMBase_Skeleton::getConstructorId() const
213 {
214   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
215     return GroupConstructors->id( GroupConstructors->selected() );
216   return -1;
217 }
218
219 //=================================================================================
220 // function : getDesktop()
221 // purpose  :
222 //=================================================================================
223 SUIT_Desktop* GEOMBase_Skeleton::getDesktop() const
224 {
225   return dynamic_cast<SUIT_Desktop*>( parentWidget() );
226 }