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