]> SALOME platform Git repositories - modules/geom.git/blob - src/BuildGUI/BuildGUI_ShellDlg.cxx
Salome HOME
Correct wrong addition
[modules/geom.git] / src / BuildGUI / BuildGUI_ShellDlg.cxx
1 //  Copyright (C) 2007-2010  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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : BuildGUI_ShellDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 //
27 #include "BuildGUI_ShellDlg.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31 #include <GEOMBase.h>
32
33 #include <GEOMImpl_Types.hxx>
34
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39
40 #include <TColStd_MapOfInteger.hxx>
41
42 //=================================================================================
43 // class    : BuildGUI_ShellDlg()
44 // purpose  : Constructs a BuildGUI_ShellDlg which is a child of 'parent', with the 
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 BuildGUI_ShellDlg::BuildGUI_ShellDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
50   : GEOMBase_Skeleton( theGeometryGUI, parent )
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   setWindowTitle( tr( "GEOM_SHELL_TITLE" ) );
56     
57   /***************************************************************/
58   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SHELL" ) );
59   mainFrame()->RadioButton1->setIcon( image0 );
60   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton2->close();
62   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63   mainFrame()->RadioButton3->close();
64
65   GroupShell = new DlgRef_1Sel( centralWidget() );
66
67   GroupShell->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
68   GroupShell->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
69   GroupShell->PushButton1->setIcon( image1 );
70   GroupShell->LineEdit1->setReadOnly( true );
71   
72   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
73   layout->setMargin( 0 ); layout->setSpacing( 6 );
74   layout->addWidget( GroupShell );
75   /***************************************************************/
76
77   setHelpFileName("create_shell_page.html");
78
79   /* Initialisations */
80   Init();
81 }
82
83
84 //=================================================================================
85 // function : ~BuildGUI_ShellDlg()
86 // purpose  : Destroys the object and frees any allocated resources
87 //=================================================================================
88 BuildGUI_ShellDlg::~BuildGUI_ShellDlg()
89 {
90     // no need to delete child widgets, Qt does it all for us
91 }
92
93
94 //=================================================================================
95 // function : Init()
96 // purpose  :
97 //=================================================================================
98 void BuildGUI_ShellDlg::Init()
99 {
100   /* init variables */
101   myEditCurrentArgument = GroupShell->LineEdit1;
102   GroupShell->LineEdit1->setReadOnly( true );
103   
104   myFacesAndShells.clear();
105   
106   TColStd_MapOfInteger aMap;
107   aMap.Add( GEOM_SHELL );
108   aMap.Add( GEOM_FACE );
109   aMap.Add( GEOM_COMPOUNDFILTER );
110   
111   QList<int> aSubShapes;
112   aSubShapes.append( GEOM_FACE );
113   globalSelection( aMap, aSubShapes );
114
115   /* signals and slots connections */
116   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
117   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
118
119   connect( GroupShell->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
120
121   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
122            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
123
124   initName( tr( "GEOM_SHELL" ) );
125   SelectionIntoArgument();
126 }
127
128
129 //=================================================================================
130 // function : ClickOnOk()
131 // purpose  :
132 //=================================================================================
133 void BuildGUI_ShellDlg::ClickOnOk()
134 {
135   if ( ClickOnApply() )
136     ClickOnCancel();
137 }
138
139
140 //=================================================================================
141 // function : ClickOnApply()
142 // purpose  :
143 //=================================================================================
144 bool BuildGUI_ShellDlg::ClickOnApply()
145 {
146   if ( !onAccept() )
147     return false;
148
149   initName();
150   return true;
151 }
152
153
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose  : Called when selection as changed or other case
157 //=================================================================================
158 void BuildGUI_ShellDlg::SelectionIntoArgument()
159 {
160   myEditCurrentArgument->setText( "" );
161
162   QList<TopAbs_ShapeEnum> types;
163   types << TopAbs_FACE << TopAbs_SHELL << TopAbs_COMPOUND;
164   myFacesAndShells = getSelected( types, -1 );
165
166   if ( !myFacesAndShells.isEmpty() ) {
167     QString aName = myFacesAndShells.count() > 1 ? QString( "%1_objects").arg( myFacesAndShells.count() ) : GEOMBase::GetName( myFacesAndShells[0].get() );
168     myEditCurrentArgument->setText( aName );
169   }
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   QList<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   TColStd_MapOfInteger aMap;
209   aMap.Add( GEOM_SHELL );
210   aMap.Add( GEOM_FACE );
211   aMap.Add( GEOM_COMPOUNDFILTER );
212   
213   QList<int> aSubShapes;
214   aSubShapes.append( GEOM_FACE );
215   globalSelection( aMap, aSubShapes );
216 }
217
218
219 //=================================================================================
220 // function : enterEvent()
221 // purpose  :
222 //=================================================================================
223 void BuildGUI_ShellDlg::enterEvent( QEvent* )
224 {
225   if ( !mainFrame()->GroupConstructors->isEnabled() )
226     ActivateThisDialog();
227 }
228
229 //=================================================================================
230 // function : createOperation
231 // purpose  :
232 //=================================================================================
233 GEOM::GEOM_IOperations_ptr BuildGUI_ShellDlg::createOperation()
234 {
235   return getGeomEngine()->GetIShapesOperations( getStudyId() );
236 }
237
238 //=================================================================================
239 // function : isValid
240 // purpose  :
241 //=================================================================================
242 bool BuildGUI_ShellDlg::isValid( QString& )
243 {
244   return !myFacesAndShells.isEmpty();
245 }
246
247 //=================================================================================
248 // function : execute
249 // purpose  :
250 //=================================================================================
251 bool BuildGUI_ShellDlg::execute( ObjectList& objects )
252 {
253   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
254
255   GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
256   objlist->length( myFacesAndShells.count() );
257   for ( int i = 0; i < myFacesAndShells.count(); i++ )
258     objlist[i] = myFacesAndShells[i].copy();
259
260   GEOM::GEOM_Object_var anObj = anOper->MakeShell( objlist.in() );
261
262   if ( !anObj->_is_nil() )
263     objects.push_back( anObj._retn() );
264
265   return true;
266 }
267