1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.
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
22 // File : BuildGUI_ShellDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "BuildGUI_ShellDlg.h"
29 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
39 #include <TColStd_MapOfInteger.hxx>
41 //=================================================================================
42 // class : BuildGUI_ShellDlg()
43 // purpose : Constructs a BuildGUI_ShellDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 BuildGUI_ShellDlg::BuildGUI_ShellDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
49 : GEOMBase_Skeleton( theGeometryGUI, parent )
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" ) ) );
54 setWindowTitle( tr( "GEOM_SHELL_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SHELL" ) );
58 mainFrame()->RadioButton1->setIcon( image0 );
59 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton2->close();
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
64 GroupShell = new DlgRef_1Sel( centralWidget() );
66 GroupShell->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
67 GroupShell->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
68 GroupShell->PushButton1->setIcon( image1 );
69 GroupShell->LineEdit1->setReadOnly( true );
71 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
72 layout->setMargin( 0 ); layout->setSpacing( 6 );
73 layout->addWidget( GroupShell );
74 /***************************************************************/
76 setHelpFileName("create_shell_page.html");
83 //=================================================================================
84 // function : ~BuildGUI_ShellDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 BuildGUI_ShellDlg::~BuildGUI_ShellDlg()
89 // no need to delete child widgets, Qt does it all for us
93 //=================================================================================
96 //=================================================================================
97 void BuildGUI_ShellDlg::Init()
100 myEditCurrentArgument = GroupShell->LineEdit1;
101 GroupShell->LineEdit1->setReadOnly( true );
103 myOkFacesAndShells = false;
105 TColStd_MapOfInteger aMap;
106 aMap.Add( GEOM_SHELL );
107 aMap.Add( GEOM_FACE );
108 globalSelection( aMap );
110 /* signals and slots connections */
111 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
112 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
114 connect( GroupShell->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
116 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
117 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
119 initName( tr( "GEOM_SHELL" ) );
123 //=================================================================================
124 // function : ClickOnOk()
126 //=================================================================================
127 void BuildGUI_ShellDlg::ClickOnOk()
129 if ( ClickOnApply() )
134 //=================================================================================
135 // function : ClickOnApply()
137 //=================================================================================
138 bool BuildGUI_ShellDlg::ClickOnApply()
148 //=================================================================================
149 // function : SelectionIntoArgument()
150 // purpose : Called when selection as changed or other case
151 //=================================================================================
152 void BuildGUI_ShellDlg::SelectionIntoArgument()
154 myEditCurrentArgument->setText( "" );
157 myOkFacesAndShells = false;
158 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
162 aString = QString( "%1_objects ").arg( nbSel );
164 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myFacesAndShells, true );
165 if ( !myFacesAndShells.length() )
168 myEditCurrentArgument->setText( aString );
169 myOkFacesAndShells = true;
173 //=================================================================================
174 // function : SetEditCurrentArgument()
176 //=================================================================================
177 void BuildGUI_ShellDlg::SetEditCurrentArgument()
179 QPushButton* send = (QPushButton*)sender();
180 if ( send != GroupShell->PushButton1 )
183 TColStd_MapOfInteger aMap;
184 aMap.Add( GEOM_SHELL );
185 aMap.Add( GEOM_FACE );
186 globalSelection( aMap );
187 myEditCurrentArgument = GroupShell->LineEdit1;
189 myEditCurrentArgument->setFocus();
190 SelectionIntoArgument();
194 //=================================================================================
195 // function : ActivateThisDialog()
197 //=================================================================================
198 void BuildGUI_ShellDlg::ActivateThisDialog()
200 GEOMBase_Skeleton::ActivateThisDialog();
201 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
202 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
203 TColStd_MapOfInteger aMap;
204 aMap.Add( GEOM_SHELL );
205 aMap.Add( GEOM_FACE );
206 globalSelection( aMap );
210 //=================================================================================
211 // function : enterEvent()
213 //=================================================================================
214 void BuildGUI_ShellDlg::enterEvent( QEvent* )
216 if ( !mainFrame()->GroupConstructors->isEnabled() )
217 ActivateThisDialog();
220 //=================================================================================
221 // function : createOperation
223 //=================================================================================
224 GEOM::GEOM_IOperations_ptr BuildGUI_ShellDlg::createOperation()
226 return getGeomEngine()->GetIShapesOperations( getStudyId() );
229 //=================================================================================
230 // function : isValid
232 //=================================================================================
233 bool BuildGUI_ShellDlg::isValid( QString& )
235 return myOkFacesAndShells;
238 //=================================================================================
239 // function : execute
241 //=================================================================================
242 bool BuildGUI_ShellDlg::execute( ObjectList& objects )
244 GEOM::GEOM_Object_var anObj;
246 anObj = GEOM::GEOM_IShapesOperations::_narrow(
247 getOperation() )->MakeShell( myFacesAndShells );
249 if ( !anObj->_is_nil() )
250 objects.push_back( anObj._retn() );