Salome HOME
4a51094b18295d2947617f9d42cadce570e57a8d
[modules/geom.git] / src / BuildGUI / BuildGUI_ShellDlg.cxx
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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_MessageBox.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_Session.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
40
41 #include <TColStd_MapOfInteger.hxx>
42
43 //=================================================================================
44 // class    : BuildGUI_ShellDlg()
45 // purpose  : Constructs a BuildGUI_ShellDlg which is a child of 'parent', with the 
46 //            name 'name' and widget flags set to 'f'.
47 //            The dialog will by default be modeless, unless you set 'modal' to
48 //            TRUE to construct a modal dialog.
49 //=================================================================================
50 BuildGUI_ShellDlg::BuildGUI_ShellDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
51   : GEOMBase_Skeleton( theGeometryGUI, parent )
52 {
53   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_SHELL" ) ) );
54   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55
56   setWindowTitle( tr( "GEOM_SHELL_TITLE" ) );
57     
58   /***************************************************************/
59   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SHELL" ) );
60   mainFrame()->RadioButton1->setIcon( image0 );
61   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62   mainFrame()->RadioButton2->close();
63   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64   mainFrame()->RadioButton3->close();
65
66   GroupShell = new DlgRef_1Sel( centralWidget() );
67
68   GroupShell->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
69   GroupShell->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
70   GroupShell->PushButton1->setIcon( image1 );
71   GroupShell->LineEdit1->setReadOnly( true );
72   
73   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74   layout->setMargin( 0 ); layout->setSpacing( 6 );
75   layout->addWidget( GroupShell );
76   /***************************************************************/
77
78   setHelpFileName("create_shell_page.html");
79
80   /* Initialisations */
81   Init();
82 }
83
84
85 //=================================================================================
86 // function : ~BuildGUI_ShellDlg()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BuildGUI_ShellDlg::~BuildGUI_ShellDlg()
90 {
91     // no need to delete child widgets, Qt does it all for us
92 }
93
94
95 //=================================================================================
96 // function : Init()
97 // purpose  :
98 //=================================================================================
99 void BuildGUI_ShellDlg::Init()
100 {
101   /* init variables */
102   myEditCurrentArgument = GroupShell->LineEdit1;
103   GroupShell->LineEdit1->setReadOnly( true );
104   
105   myFacesAndShells.clear();
106   
107   TColStd_MapOfInteger aMap;
108   aMap.Add( GEOM_SHELL );
109   aMap.Add( GEOM_FACE );
110   aMap.Add( GEOM_COMPOUNDFILTER );
111   
112   QList<int> aSubShapes;
113   aSubShapes.append( GEOM_FACE );
114   globalSelection( aMap, aSubShapes );
115
116   /* signals and slots connections */
117   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
118   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
119
120   connect( GroupShell->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
121
122   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
123            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
124
125   initName( tr( "GEOM_SHELL" ) );
126   SelectionIntoArgument();
127 }
128
129
130 //=================================================================================
131 // function : ClickOnOk()
132 // purpose  :
133 //=================================================================================
134 void BuildGUI_ShellDlg::ClickOnOk()
135 {
136   setIsApplyAndClose( true );
137   if ( ClickOnApply() )
138     ClickOnCancel();
139 }
140
141
142 //=================================================================================
143 // function : ClickOnApply()
144 // purpose  :
145 //=================================================================================
146 bool BuildGUI_ShellDlg::ClickOnApply()
147 {
148   if ( !onAccept() )
149     return false;
150
151   initName();
152   return true;
153 }
154
155
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose  : Called when selection as changed or other case
159 //=================================================================================
160 void BuildGUI_ShellDlg::SelectionIntoArgument()
161 {
162   myEditCurrentArgument->setText( "" );
163
164   QList<TopAbs_ShapeEnum> types;
165   types << TopAbs_FACE << TopAbs_SHELL << TopAbs_COMPOUND;
166   myFacesAndShells = getSelected( types, -1 );
167
168   if ( !myFacesAndShells.isEmpty() ) {
169     QString aName = myFacesAndShells.count() > 1 ? QString( "%1_objects").arg( myFacesAndShells.count() ) : GEOMBase::GetName( myFacesAndShells[0].get() );
170     myEditCurrentArgument->setText( aName );
171   }
172 }
173
174
175 //=================================================================================
176 // function : SetEditCurrentArgument()
177 // purpose  :
178 //=================================================================================
179 void BuildGUI_ShellDlg::SetEditCurrentArgument()
180 {
181   QPushButton* send = (QPushButton*)sender();
182   if ( send != GroupShell->PushButton1 )
183     return;
184
185   TColStd_MapOfInteger aMap;
186   aMap.Add( GEOM_SHELL );
187   aMap.Add( GEOM_FACE );
188   aMap.Add( GEOM_COMPOUNDFILTER );
189
190   QList<int> aSubShapes;
191   aSubShapes.append( GEOM_FACE );
192   globalSelection( aMap, aSubShapes );
193   
194   myEditCurrentArgument = GroupShell->LineEdit1;
195
196   myEditCurrentArgument->setFocus();
197   SelectionIntoArgument();
198 }
199
200
201 //=================================================================================
202 // function : ActivateThisDialog()
203 // purpose  :
204 //=================================================================================
205 void BuildGUI_ShellDlg::ActivateThisDialog()
206 {
207   GEOMBase_Skeleton::ActivateThisDialog();
208   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
209            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
210   TColStd_MapOfInteger aMap;
211   aMap.Add( GEOM_SHELL );
212   aMap.Add( GEOM_FACE );
213   aMap.Add( GEOM_COMPOUNDFILTER );
214   
215   QList<int> aSubShapes;
216   aSubShapes.append( GEOM_FACE );
217   globalSelection( aMap, aSubShapes );
218 }
219
220
221 //=================================================================================
222 // function : enterEvent()
223 // purpose  :
224 //=================================================================================
225 void BuildGUI_ShellDlg::enterEvent( QEvent* )
226 {
227   if ( !mainFrame()->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();
238 }
239
240 //=================================================================================
241 // function : isValid
242 // purpose  :
243 //=================================================================================
244 bool BuildGUI_ShellDlg::isValid( QString& )
245 {
246   return !myFacesAndShells.isEmpty();
247 }
248
249 //=================================================================================
250 // function : execute
251 // purpose  :
252 //=================================================================================
253 bool BuildGUI_ShellDlg::execute( ObjectList& objects )
254 {
255   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
256
257   GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
258   objlist->length( myFacesAndShells.count() );
259   for ( int i = 0; i < myFacesAndShells.count(); i++ )
260     objlist[i] = myFacesAndShells[i].copy();
261
262   GEOM::GEOM_Object_var anObj = anOper->MakeShell( objlist.in() );
263
264   if ( !anObj->_is_nil() ) {
265     if (anObj->GetShapeType() == GEOM::COMPOUND) {
266       SUIT_MessageBox::warning(this,
267                                QObject::tr("GEOM_WRN_WARNING"),
268                                QObject::tr("GEOM_WRN_FACES_NOT_SHELL"));
269     }
270     objects.push_back( anObj._retn() );
271   }
272
273   return true;
274 }
275
276 //=================================================================================
277 // function : getSourceObjects
278 // purpose  : virtual method to get source objects
279 //=================================================================================
280 QList<GEOM::GeomObjPtr> BuildGUI_ShellDlg::getSourceObjects()
281 {
282   return myFacesAndShells;
283 }
284