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