Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/geom.git] / src / BuildGUI / BuildGUI_ShellDlg.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   : BuildGUI_ShellDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BuildGUI_ShellDlg.h"
30 #include "GEOMImpl_Types.hxx"
31
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35
36 #include "TColStd_MapOfInteger.hxx"
37
38 #include <qlabel.h>
39
40 //=================================================================================
41 // class    : BuildGUI_ShellDlg()
42 // purpose  : Constructs a BuildGUI_ShellDlg 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 BuildGUI_ShellDlg::BuildGUI_ShellDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
48                                      const char* name, bool modal, WFlags fl)
49   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
50                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 {
52   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BUILD_SHELL")));
53   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
54
55   setCaption(tr("GEOM_SHELL_TITLE"));
56     
57   /***************************************************************/
58   GroupConstructors->setTitle(tr("GEOM_SHELL"));
59   RadioButton1->setPixmap(image0);
60   RadioButton2->close(TRUE);
61   RadioButton3->close(TRUE);
62
63   GroupShell = new DlgRef_1Sel_QTD(this, "GroupShell");
64   GroupShell->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
65   GroupShell->TextLabel1->setText(tr("GEOM_OBJECTS"));
66   GroupShell->PushButton1->setPixmap(image1);
67   GroupShell->LineEdit1->setReadOnly( true );
68   
69   Layout1->addWidget(GroupShell, 2, 0);
70   /***************************************************************/
71
72   setHelpFileName("shell.htm");
73
74   /* Initialisations */
75   Init();
76 }
77
78
79 //=================================================================================
80 // function : ~BuildGUI_ShellDlg()
81 // purpose  : Destroys the object and frees any allocated resources
82 //=================================================================================
83 BuildGUI_ShellDlg::~BuildGUI_ShellDlg()
84 {
85     // no need to delete child widgets, Qt does it all for us
86 }
87
88
89 //=================================================================================
90 // function : Init()
91 // purpose  :
92 //=================================================================================
93 void BuildGUI_ShellDlg::Init()
94 {
95   /* init variables */
96   myEditCurrentArgument = GroupShell->LineEdit1;
97   GroupShell->LineEdit1->setReadOnly( true );
98   
99   myOkFacesAndShells = false;
100   
101   TColStd_MapOfInteger aMap;
102   aMap.Add(GEOM_SHELL);
103   aMap.Add(GEOM_FACE);
104   globalSelection( aMap );
105
106   /* signals and slots connections */
107   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
108   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
109
110   connect(GroupShell->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111
112   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
113           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
114
115   initName(tr("GEOM_SHELL"));
116 }
117
118
119 //=================================================================================
120 // function : ClickOnOk()
121 // purpose  :
122 //=================================================================================
123 void BuildGUI_ShellDlg::ClickOnOk()
124 {
125   if ( ClickOnApply() )
126     ClickOnCancel();
127 }
128
129
130 //=================================================================================
131 // function : ClickOnApply()
132 // purpose  :
133 //=================================================================================
134 bool BuildGUI_ShellDlg::ClickOnApply()
135 {
136   if ( !onAccept() )
137     return false;
138
139   initName();
140   return true;
141 }
142
143
144 //=================================================================================
145 // function : SelectionIntoArgument()
146 // purpose  : Called when selection as changed or other case
147 //=================================================================================
148 void BuildGUI_ShellDlg::SelectionIntoArgument()
149 {
150   myEditCurrentArgument->setText( "" );
151   QString aString;
152
153   myOkFacesAndShells = false;
154   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
155   if ( nbSel == 0 )
156     return;
157   if ( nbSel != 1 )
158     aString = QString( "%1_objects ").arg( nbSel );
159
160   GEOMBase::ConvertListOfIOInListOfGO( selectedIO(),  myFacesAndShells, true );
161   if ( !myFacesAndShells.length() )
162     return;
163
164   myEditCurrentArgument->setText( aString );
165   myOkFacesAndShells = true;
166 }
167
168
169 //=================================================================================
170 // function : SetEditCurrentArgument()
171 // purpose  :
172 //=================================================================================
173 void BuildGUI_ShellDlg::SetEditCurrentArgument()
174 {
175   QPushButton* send = (QPushButton*)sender();
176   if (send != GroupShell->PushButton1)
177     return;
178
179   TColStd_MapOfInteger aMap;
180   aMap.Add(GEOM_SHELL);
181   aMap.Add(GEOM_FACE);
182   globalSelection( aMap );
183   myEditCurrentArgument = GroupShell->LineEdit1;
184
185   myEditCurrentArgument->setFocus();
186   SelectionIntoArgument();
187 }
188
189
190 //=================================================================================
191 // function : ActivateThisDialog()
192 // purpose  :
193 //=================================================================================
194 void BuildGUI_ShellDlg::ActivateThisDialog()
195 {
196   GEOMBase_Skeleton::ActivateThisDialog();
197   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
198           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
199   TColStd_MapOfInteger aMap;
200   aMap.Add(GEOM_SHELL);
201   aMap.Add(GEOM_FACE);
202   globalSelection( aMap );
203 }
204
205
206 //=================================================================================
207 // function : enterEvent()
208 // purpose  :
209 //=================================================================================
210 void BuildGUI_ShellDlg::enterEvent(QEvent* e)
211 {
212   if ( !GroupConstructors->isEnabled() )
213     ActivateThisDialog();
214 }
215
216 //=================================================================================
217 // function : createOperation
218 // purpose  :
219 //=================================================================================
220 GEOM::GEOM_IOperations_ptr BuildGUI_ShellDlg::createOperation()
221 {
222   return getGeomEngine()->GetIShapesOperations( getStudyId() );
223 }
224
225 //=================================================================================
226 // function : isValid
227 // purpose  :
228 //=================================================================================
229 bool BuildGUI_ShellDlg::isValid( QString& )
230 {
231   return myOkFacesAndShells;
232 }
233
234 //=================================================================================
235 // function : execute
236 // purpose  :
237 //=================================================================================
238 bool BuildGUI_ShellDlg::execute( ObjectList& objects )
239 {
240   GEOM::GEOM_Object_var anObj;
241
242   anObj = GEOM::GEOM_IShapesOperations::_narrow(
243     getOperation() )->MakeShell( myFacesAndShells );
244
245   if ( !anObj->_is_nil() )
246     objects.push_back( anObj._retn() );
247
248   return true;
249 }
250