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_MessageBox.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
40 //=================================================================================
41 // class : BuildGUI_SolidDlg()
42 // purpose : Constructs a BuildGUI_SolidDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 BuildGUI_SolidDlg::BuildGUI_SolidDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
48 : GEOMBase_Skeleton( theGeometryGUI, parent )
50 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_SOLID" ) ) );
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
53 setWindowTitle( tr( "GEOM_SOLID_TITLE" ) );
55 /***************************************************************/
56 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SOLID" ) );
57 mainFrame()->RadioButton1->setIcon( image0 );
58 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->RadioButton2->close();
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
63 GroupSolid = new DlgRef_1Sel1Check( centralWidget() );
65 GroupSolid->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66 GroupSolid->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
67 GroupSolid->CheckButton1->setText( tr( "GEOM_CREATE_SINGLE_SOLID" ) );
68 GroupSolid->PushButton1->setIcon( image1 );
69 GroupSolid->LineEdit1->setReadOnly( true );
71 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
72 layout->setMargin( 0 ); layout->setSpacing( 6 );
73 layout->addWidget( GroupSolid );
74 /***************************************************************/
76 setHelpFileName("create_solid_page.html");
83 //=================================================================================
84 // function : ~BuildGUI_SolidDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
89 // no need to delete child widgets, Qt does it all for us
93 //=================================================================================
96 //=================================================================================
97 void BuildGUI_SolidDlg::Init()
100 myEditCurrentArgument = GroupSolid->LineEdit1;
101 GroupSolid->LineEdit1->setReadOnly( true );
102 GroupSolid->CheckButton1->setChecked( true );
106 globalSelection( GEOM_SHELL );
108 /* signals and slots connections */
109 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
110 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
112 connect( GroupSolid->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
113 connect( GroupSolid->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( EnableNameField( bool ) ) );
115 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
116 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
118 initName( tr( "GEOM_SOLID" ) );
122 //=================================================================================
123 // function : ClickOnOk()
125 //=================================================================================
126 void BuildGUI_SolidDlg::ClickOnOk()
128 if ( ClickOnApply() )
132 //=================================================================================
133 // function : ClickOnApply()
135 //=================================================================================
136 bool BuildGUI_SolidDlg::ClickOnApply()
138 for ( int i = 0, n = myShells.length(); i< n; i++ ) {
140 QString aName = GEOMBase::GetName( myShells[i] );
141 SUIT_MessageBox::warning( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
142 QObject::tr("WRN_WARNING"),
143 QObject::tr("WRN_SHAPE_UNCLOSED").arg(aName) ,
144 QObject::tr("BUT_OK") );
157 //=================================================================================
158 // function : SelectionIntoArgument()
159 // purpose : Called when selection as changed or other case
160 //=================================================================================
161 void BuildGUI_SolidDlg::SelectionIntoArgument()
163 myEditCurrentArgument->setText( "" );
164 QString aString = "";
167 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString );
171 aString = tr( "%1_objects" ).arg( nbSel );
173 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myShells );
174 if ( !myShells.length() )
177 myEditCurrentArgument->setText( aString );
181 //=================================================================================
182 // function : SetEditCurrentArgument()
184 //=================================================================================
185 void BuildGUI_SolidDlg::SetEditCurrentArgument()
187 QPushButton* send = (QPushButton*)sender();
188 if ( send != GroupSolid->PushButton1 )
191 globalSelection( GEOM_SHELL );
192 myEditCurrentArgument = GroupSolid->LineEdit1;
194 myEditCurrentArgument->setFocus();
195 SelectionIntoArgument();
199 //=================================================================================
200 // function : ActivateThisDialog()
202 //=================================================================================
203 void BuildGUI_SolidDlg::ActivateThisDialog()
205 GEOMBase_Skeleton::ActivateThisDialog();
206 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
207 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
208 globalSelection( GEOM_SHELL );
212 //=================================================================================
213 // function : enterEvent()
215 //=================================================================================
216 void BuildGUI_SolidDlg::enterEvent( QEvent* )
218 if ( !mainFrame()->GroupConstructors->isEnabled() )
219 ActivateThisDialog();
223 //=================================================================================
224 // function : EnableNameField()
226 //=================================================================================
227 void BuildGUI_SolidDlg::EnableNameField( bool toEnable )
229 mainFrame()->GroupBoxName->setEnabled( toEnable );
232 //=================================================================================
233 // function : createOperation
235 //=================================================================================
236 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
238 return getGeomEngine()->GetIShapesOperations( getStudyId() );
241 //=================================================================================
242 // function : isValid
244 //=================================================================================
245 bool BuildGUI_SolidDlg::isValid( QString& )
250 //=================================================================================
251 // function : isClosed
252 // purpose : Check the object 'i' in myShells list is closed or unclosed
253 //=================================================================================
254 bool BuildGUI_SolidDlg::isClosed(int i)
256 GEOM::GEOM_Object_var aShape = myShells[i];
257 GEOM::GEOM_IKindOfShape::shape_kind aKind;
258 GEOM::ListOfLong_var anInts;
259 GEOM::ListOfDouble_var aDbls;
261 if (aShape->_is_nil()) {
262 MESSAGE ("Shape is NULL!!!");
266 GEOM::GEOM_IMeasureOperations_ptr anOp = myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
268 // GEOM::GEOM_IMeasureOperations_var anOp = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
270 // Detect kind of shape and parameters
271 aKind = anOp->KindOfShape(aShape, anInts, aDbls);
273 if ( !anOp->IsDone() ) {
274 MESSAGE ("KindOfShape Operation is NOT DONE!!!");
278 if ( anInts[0] == 1 )
280 else if ( anInts[0] == 2 )
286 //=================================================================================
287 // function : execute
289 //=================================================================================
290 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
292 bool toCreateSingleSolid = GroupSolid->CheckButton1->isChecked();
294 if ( toCreateSingleSolid ) {
295 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
296 getOperation() )->MakeSolidShells( myShells );
298 if ( !anObj->_is_nil() )
299 objects.push_back( anObj._retn() );
302 for ( int i = 0, n = myShells.length(); i< n; i++ ) {
303 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
304 getOperation() )->MakeSolidShell( myShells[ i ] );
306 if ( !anObj->_is_nil() )
307 objects.push_back( anObj._retn() );