1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BuildGUI_ShellDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "BuildGUI_ShellDlg.h"
30 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
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>
41 #include <TColStd_MapOfInteger.hxx>
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 )
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" ) ) );
56 setWindowTitle( tr( "GEOM_SHELL_TITLE" ) );
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();
66 GroupShell = new DlgRef_1Sel( centralWidget() );
68 GroupShell->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
69 GroupShell->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
70 GroupShell->PushButton1->setIcon( image1 );
71 GroupShell->LineEdit1->setReadOnly( true );
73 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74 layout->setMargin( 0 ); layout->setSpacing( 6 );
75 layout->addWidget( GroupShell );
76 /***************************************************************/
78 setHelpFileName("create_shell_page.html");
85 //=================================================================================
86 // function : ~BuildGUI_ShellDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BuildGUI_ShellDlg::~BuildGUI_ShellDlg()
91 // no need to delete child widgets, Qt does it all for us
95 //=================================================================================
98 //=================================================================================
99 void BuildGUI_ShellDlg::Init()
102 myEditCurrentArgument = GroupShell->LineEdit1;
103 GroupShell->LineEdit1->setReadOnly( true );
105 myFacesAndShells.clear();
107 TColStd_MapOfInteger aMap;
108 aMap.Add( GEOM_SHELL );
109 aMap.Add( GEOM_FACE );
110 aMap.Add( GEOM_COMPOUNDFILTER );
112 QList<int> aSubShapes;
113 aSubShapes.append( GEOM_FACE );
114 globalSelection( aMap, aSubShapes );
116 /* signals and slots connections */
117 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
118 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
120 connect( GroupShell->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
122 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
123 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
125 initName( tr( "GEOM_SHELL" ) );
126 SelectionIntoArgument();
130 //=================================================================================
131 // function : ClickOnOk()
133 //=================================================================================
134 void BuildGUI_ShellDlg::ClickOnOk()
136 setIsApplyAndClose( true );
137 if ( ClickOnApply() )
142 //=================================================================================
143 // function : ClickOnApply()
145 //=================================================================================
146 bool BuildGUI_ShellDlg::ClickOnApply()
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection as changed or other case
159 //=================================================================================
160 void BuildGUI_ShellDlg::SelectionIntoArgument()
162 myEditCurrentArgument->setText( "" );
164 QList<TopAbs_ShapeEnum> types;
165 types << TopAbs_FACE << TopAbs_SHELL << TopAbs_COMPOUND;
166 myFacesAndShells = getSelected( types, -1 );
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 );
175 //=================================================================================
176 // function : SetEditCurrentArgument()
178 //=================================================================================
179 void BuildGUI_ShellDlg::SetEditCurrentArgument()
181 QPushButton* send = (QPushButton*)sender();
182 if ( send != GroupShell->PushButton1 )
185 TColStd_MapOfInteger aMap;
186 aMap.Add( GEOM_SHELL );
187 aMap.Add( GEOM_FACE );
188 aMap.Add( GEOM_COMPOUNDFILTER );
190 QList<int> aSubShapes;
191 aSubShapes.append( GEOM_FACE );
192 globalSelection( aMap, aSubShapes );
194 myEditCurrentArgument = GroupShell->LineEdit1;
196 myEditCurrentArgument->setFocus();
197 SelectionIntoArgument();
201 //=================================================================================
202 // function : ActivateThisDialog()
204 //=================================================================================
205 void BuildGUI_ShellDlg::ActivateThisDialog()
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 );
215 QList<int> aSubShapes;
216 aSubShapes.append( GEOM_FACE );
217 globalSelection( aMap, aSubShapes );
221 //=================================================================================
222 // function : enterEvent()
224 //=================================================================================
225 void BuildGUI_ShellDlg::enterEvent( QEvent* )
227 if ( !mainFrame()->GroupConstructors->isEnabled() )
228 ActivateThisDialog();
231 //=================================================================================
232 // function : createOperation
234 //=================================================================================
235 GEOM::GEOM_IOperations_ptr BuildGUI_ShellDlg::createOperation()
237 return getGeomEngine()->GetIShapesOperations( getStudyId() );
240 //=================================================================================
241 // function : isValid
243 //=================================================================================
244 bool BuildGUI_ShellDlg::isValid( QString& )
246 return !myFacesAndShells.isEmpty();
249 //=================================================================================
250 // function : execute
252 //=================================================================================
253 bool BuildGUI_ShellDlg::execute( ObjectList& objects )
255 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
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();
262 GEOM::GEOM_Object_var anObj = anOper->MakeShell( objlist.in() );
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"));
270 objects.push_back( anObj._retn() );
276 //=================================================================================
277 // function : getSourceObjects
278 // purpose : virtual method to get source objects
279 //=================================================================================
280 QList<GEOM::GeomObjPtr> BuildGUI_ShellDlg::getSourceObjects()
282 return myFacesAndShells;