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