1 // Copyright (C) 2007-2010 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.
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_SolidDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "BuildGUI_SolidDlg.h"
30 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Session.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 //=================================================================================
42 // class : BuildGUI_SolidDlg()
43 // purpose : Constructs a BuildGUI_SolidDlg 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_SolidDlg::BuildGUI_SolidDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
49 : GEOMBase_Skeleton( theGeometryGUI, parent )
51 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_SOLID" ) ) );
52 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_SOLID_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SOLID" ) );
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 GroupSolid = new DlgRef_1Sel1Check( centralWidget() );
66 GroupSolid->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
67 GroupSolid->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
68 GroupSolid->CheckButton1->setText( tr( "GEOM_CREATE_SINGLE_SOLID" ) );
69 GroupSolid->PushButton1->setIcon( image1 );
70 GroupSolid->LineEdit1->setReadOnly( true );
72 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
73 layout->setMargin( 0 ); layout->setSpacing( 6 );
74 layout->addWidget( GroupSolid );
75 /***************************************************************/
77 setHelpFileName("create_solid_page.html");
84 //=================================================================================
85 // function : ~BuildGUI_SolidDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
90 // no need to delete child widgets, Qt does it all for us
94 //=================================================================================
97 //=================================================================================
98 void BuildGUI_SolidDlg::Init()
101 myEditCurrentArgument = GroupSolid->LineEdit1;
102 GroupSolid->LineEdit1->setReadOnly( true );
103 GroupSolid->CheckButton1->setChecked( true );
107 globalSelection( GEOM_SHELL );
109 /* signals and slots connections */
110 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
111 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
113 connect( GroupSolid->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
114 connect( GroupSolid->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( EnableNameField( bool ) ) );
116 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
117 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
119 initName( tr( "GEOM_SOLID" ) );
120 SelectionIntoArgument();
124 //=================================================================================
125 // function : ClickOnOk()
127 //=================================================================================
128 void BuildGUI_SolidDlg::ClickOnOk()
130 if ( ClickOnApply() )
134 //=================================================================================
135 // function : ClickOnApply()
137 //=================================================================================
138 bool BuildGUI_SolidDlg::ClickOnApply()
148 //=================================================================================
149 // function : SelectionIntoArgument()
150 // purpose : Called when selection as changed or other case
151 //=================================================================================
152 void BuildGUI_SolidDlg::SelectionIntoArgument()
154 myEditCurrentArgument->setText( "" );
156 myShells = getSelected( TopAbs_SHELL, -1 );
158 if ( !myShells.isEmpty() ) {
159 QString aName = myShells.count() > 1 ? QString( "%1_objects").arg( myShells.count() ) : GEOMBase::GetName( myShells[0].get() );
160 myEditCurrentArgument->setText( aName );
164 //=================================================================================
165 // function : SetEditCurrentArgument()
167 //=================================================================================
168 void BuildGUI_SolidDlg::SetEditCurrentArgument()
170 QPushButton* send = (QPushButton*)sender();
171 if ( send != GroupSolid->PushButton1 )
174 globalSelection( GEOM_SHELL );
175 myEditCurrentArgument = GroupSolid->LineEdit1;
177 myEditCurrentArgument->setFocus();
178 SelectionIntoArgument();
182 //=================================================================================
183 // function : ActivateThisDialog()
185 //=================================================================================
186 void BuildGUI_SolidDlg::ActivateThisDialog()
188 GEOMBase_Skeleton::ActivateThisDialog();
189 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
190 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
191 globalSelection( GEOM_SHELL );
195 //=================================================================================
196 // function : enterEvent()
198 //=================================================================================
199 void BuildGUI_SolidDlg::enterEvent( QEvent* )
201 if ( !mainFrame()->GroupConstructors->isEnabled() )
202 ActivateThisDialog();
206 //=================================================================================
207 // function : EnableNameField()
209 //=================================================================================
210 void BuildGUI_SolidDlg::EnableNameField( bool toEnable )
212 mainFrame()->GroupBoxName->setEnabled( toEnable );
215 //=================================================================================
216 // function : createOperation
218 //=================================================================================
219 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
221 return getGeomEngine()->GetIShapesOperations( getStudyId() );
224 //=================================================================================
225 // function : isValid
227 //=================================================================================
228 bool BuildGUI_SolidDlg::isValid( QString& msg )
230 bool ok = !myShells.isEmpty();
231 for ( int i = 0, n = myShells.count(); i < n && ok; i++ ) {
232 ok = isClosed( myShells[i].get() );
234 msg = QObject::tr("WRN_SHAPE_UNCLOSED").arg( GEOMBase::GetName( myShells[i].get() ) );
239 //=================================================================================
240 // function : isClosed
241 // purpose : Check the object 'i' in myShells list is closed or unclosed
242 //=================================================================================
243 bool BuildGUI_SolidDlg::isClosed( GEOM::GEOM_Object_ptr shell )
247 GEOM::GEOM_IKindOfShape::shape_kind aKind;
248 GEOM::ListOfLong_var anInts;
249 GEOM::ListOfDouble_var aDbls;
251 if ( !CORBA::is_nil( shell ) ) {
252 GEOM::MeasureOpPtr anOp;
253 anOp.take( myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() ) );
255 // Detect kind of shape and parameters
256 aKind = anOp->KindOfShape(shell, anInts, aDbls);
258 if ( anOp->IsDone() ) {
259 if ( anInts[0] == 1 )
261 else if ( anInts[0] == 2 )
265 MESSAGE ("KindOfShape Operation is NOT DONE!!!");
269 MESSAGE ("Shape is NULL!!!");
275 //=================================================================================
276 // function : execute
278 //=================================================================================
279 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
281 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
283 if ( GroupSolid->CheckButton1->isChecked() ) {
284 GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
285 objlist->length( myShells.count() );
286 for ( int i = 0; i < myShells.count(); i++ )
287 objlist[i] = myShells[i].copy();
289 GEOM::GEOM_Object_var anObj = anOper->MakeSolidShells( objlist.in() );
291 if ( !anObj->_is_nil() )
292 objects.push_back( anObj._retn() );
295 for ( int i = 0, n = myShells.count(); i< n; i++ ) {
296 GEOM::GEOM_Object_var anObj = anOper->MakeSolidShell( myShells[ i ].get() );
298 if ( !anObj->_is_nil() )
299 objects.push_back( anObj._retn() );