Salome HOME
Implementation of NPAL16149 (EDF 442 GEOM : Create a shell from a compound containing...
[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("create_shell_page.html");
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   aMap.Add(GEOM_COMPOUNDFILTER);
105   
106   QValueList<int> aSubShapes;
107   aSubShapes.append(GEOM_FACE);
108   globalSelection( aMap, aSubShapes );
109   
110   /* signals and slots connections */
111   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
112   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
113
114   connect(GroupShell->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115
116   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
117           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
118
119   initName(tr("GEOM_SHELL"));
120 }
121
122
123 //=================================================================================
124 // function : ClickOnOk()
125 // purpose  :
126 //=================================================================================
127 void BuildGUI_ShellDlg::ClickOnOk()
128 {
129   if ( ClickOnApply() )
130     ClickOnCancel();
131 }
132
133
134 //=================================================================================
135 // function : ClickOnApply()
136 // purpose  :
137 //=================================================================================
138 bool BuildGUI_ShellDlg::ClickOnApply()
139 {
140   if ( !onAccept() )
141     return false;
142
143   initName();
144   return true;
145 }
146
147
148 //=================================================================================
149 // function : SelectionIntoArgument()
150 // purpose  : Called when selection as changed or other case
151 //=================================================================================
152 void BuildGUI_ShellDlg::SelectionIntoArgument()
153 {
154   myEditCurrentArgument->setText( "" );
155   QString aString;
156
157   myOkFacesAndShells = false;
158   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
159   if ( nbSel == 0 )
160     return;
161   if ( nbSel != 1 )
162     aString = QString( "%1_objects ").arg( nbSel );
163
164   GEOMBase::ConvertListOfIOInListOfGO( selectedIO(),  myFacesAndShells, true );
165   if ( !myFacesAndShells.length() )
166     return;
167
168   myEditCurrentArgument->setText( aString );
169   myOkFacesAndShells = true;
170 }
171
172
173 //=================================================================================
174 // function : SetEditCurrentArgument()
175 // purpose  :
176 //=================================================================================
177 void BuildGUI_ShellDlg::SetEditCurrentArgument()
178 {
179   QPushButton* send = (QPushButton*)sender();
180   if (send != GroupShell->PushButton1)
181     return;
182
183   TColStd_MapOfInteger aMap;
184   aMap.Add(GEOM_SHELL);
185   aMap.Add(GEOM_FACE);
186   aMap.Add(GEOM_COMPOUNDFILTER);
187
188   QValueList<int> aSubShapes;
189   aSubShapes.append(GEOM_FACE);
190   globalSelection( aMap, aSubShapes );
191   
192   myEditCurrentArgument = GroupShell->LineEdit1;
193
194   myEditCurrentArgument->setFocus();
195   SelectionIntoArgument();
196 }
197
198
199 //=================================================================================
200 // function : ActivateThisDialog()
201 // purpose  :
202 //=================================================================================
203 void BuildGUI_ShellDlg::ActivateThisDialog()
204 {
205   GEOMBase_Skeleton::ActivateThisDialog();
206   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
207           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
208
209   TColStd_MapOfInteger aMap;
210   aMap.Add(GEOM_SHELL);
211   aMap.Add(GEOM_FACE);
212   aMap.Add(GEOM_COMPOUNDFILTER);
213   
214   QValueList<int> aSubShapes;
215   aSubShapes.append(GEOM_FACE);
216   globalSelection( aMap, aSubShapes );
217   
218 }
219
220
221 //=================================================================================
222 // function : enterEvent()
223 // purpose  :
224 //=================================================================================
225 void BuildGUI_ShellDlg::enterEvent(QEvent* e)
226 {
227   if ( !GroupConstructors->isEnabled() )
228     ActivateThisDialog();
229 }
230
231 //=================================================================================
232 // function : createOperation
233 // purpose  :
234 //=================================================================================
235 GEOM::GEOM_IOperations_ptr BuildGUI_ShellDlg::createOperation()
236 {
237   return getGeomEngine()->GetIShapesOperations( getStudyId() );
238 }
239
240 //=================================================================================
241 // function : isValid
242 // purpose  :
243 //=================================================================================
244 bool BuildGUI_ShellDlg::isValid( QString& )
245 {
246   return myOkFacesAndShells;
247 }
248
249 //=================================================================================
250 // function : execute
251 // purpose  :
252 //=================================================================================
253 bool BuildGUI_ShellDlg::execute( ObjectList& objects )
254 {
255   GEOM::GEOM_Object_var anObj;
256
257   anObj = GEOM::GEOM_IShapesOperations::_narrow(
258     getOperation() )->MakeShell( myFacesAndShells );
259
260   if ( !anObj->_is_nil() )
261     objects.push_back( anObj._retn() );
262
263   return true;
264 }
265