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_SolidDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "BuildGUI_SolidDlg.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 //=================================================================================
40 // class : BuildGUI_SolidDlg()
41 // purpose : Constructs a BuildGUI_SolidDlg 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_SolidDlg::BuildGUI_SolidDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
47 : GEOMBase_Skeleton( theGeometryGUI, parent )
49 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_SOLID" ) ) );
50 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52 setWindowTitle( tr( "GEOM_SOLID_TITLE" ) );
54 /***************************************************************/
55 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SOLID" ) );
56 mainFrame()->RadioButton1->setIcon( image0 );
57 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
58 mainFrame()->RadioButton2->close();
59 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton3->close();
62 GroupSolid = new DlgRef_1Sel1Check( centralWidget() );
64 GroupSolid->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
65 GroupSolid->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
66 GroupSolid->CheckButton1->setText( tr( "GEOM_CREATE_SINGLE_SOLID" ) );
67 GroupSolid->PushButton1->setIcon( image1 );
68 GroupSolid->LineEdit1->setReadOnly( true );
70 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
71 layout->setMargin( 0 ); layout->setSpacing( 6 );
72 layout->addWidget( GroupSolid );
73 /***************************************************************/
75 setHelpFileName("create_solid_page.html");
82 //=================================================================================
83 // function : ~BuildGUI_SolidDlg()
84 // purpose : Destroys the object and frees any allocated resources
85 //=================================================================================
86 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
88 // no need to delete child widgets, Qt does it all for us
92 //=================================================================================
95 //=================================================================================
96 void BuildGUI_SolidDlg::Init()
99 myEditCurrentArgument = GroupSolid->LineEdit1;
100 GroupSolid->LineEdit1->setReadOnly( true );
101 GroupSolid->CheckButton1->setChecked( true );
105 globalSelection( GEOM_SHELL );
107 /* signals and slots connections */
108 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
109 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
111 connect( GroupSolid->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
112 connect( GroupSolid->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( EnableNameField( bool ) ) );
114 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
115 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
117 initName( tr( "GEOM_SOLID" ) );
121 //=================================================================================
122 // function : ClickOnOk()
124 //=================================================================================
125 void BuildGUI_SolidDlg::ClickOnOk()
127 if ( ClickOnApply() )
131 //=================================================================================
132 // function : ClickOnApply()
134 //=================================================================================
135 bool BuildGUI_SolidDlg::ClickOnApply()
145 //=================================================================================
146 // function : SelectionIntoArgument()
147 // purpose : Called when selection as changed or other case
148 //=================================================================================
149 void BuildGUI_SolidDlg::SelectionIntoArgument()
151 myEditCurrentArgument->setText( "" );
152 QString aString = "";
155 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString );
159 aString = tr( "%1_objects" ).arg( nbSel );
161 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myShells );
162 if ( !myShells.length() )
165 myEditCurrentArgument->setText( aString );
169 //=================================================================================
170 // function : SetEditCurrentArgument()
172 //=================================================================================
173 void BuildGUI_SolidDlg::SetEditCurrentArgument()
175 QPushButton* send = (QPushButton*)sender();
176 if ( send != GroupSolid->PushButton1 )
179 globalSelection( GEOM_SHELL );
180 myEditCurrentArgument = GroupSolid->LineEdit1;
182 myEditCurrentArgument->setFocus();
183 SelectionIntoArgument();
187 //=================================================================================
188 // function : ActivateThisDialog()
190 //=================================================================================
191 void BuildGUI_SolidDlg::ActivateThisDialog()
193 GEOMBase_Skeleton::ActivateThisDialog();
194 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
195 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
196 globalSelection( GEOM_SHELL );
200 //=================================================================================
201 // function : enterEvent()
203 //=================================================================================
204 void BuildGUI_SolidDlg::enterEvent( QEvent* )
206 if ( !mainFrame()->GroupConstructors->isEnabled() )
207 ActivateThisDialog();
211 //=================================================================================
212 // function : EnableNameField()
214 //=================================================================================
215 void BuildGUI_SolidDlg::EnableNameField( bool toEnable )
217 mainFrame()->GroupBoxName->setEnabled( toEnable );
220 //=================================================================================
221 // function : createOperation
223 //=================================================================================
224 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
226 return getGeomEngine()->GetIShapesOperations( getStudyId() );
229 //=================================================================================
230 // function : isValid
232 //=================================================================================
233 bool BuildGUI_SolidDlg::isValid( QString& )
238 //=================================================================================
239 // function : execute
241 //=================================================================================
242 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
244 bool toCreateSingleSolid = GroupSolid->CheckButton1->isChecked();
246 if ( toCreateSingleSolid ) {
247 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
248 getOperation() )->MakeSolidShells( myShells );
250 if ( !anObj->_is_nil() )
251 objects.push_back( anObj._retn() );
254 for ( int i = 0, n = myShells.length(); i< n; i++ ) {
255 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
256 getOperation() )->MakeSolidShell( myShells[ i ] );
258 if ( !anObj->_is_nil() )
259 objects.push_back( anObj._retn() );