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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BuildGUI_SolidDlg.cxx
24 // 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 #include <TColStd_MapOfInteger.hxx>
42 //=================================================================================
43 // class : BuildGUI_SolidDlg()
44 // purpose : Constructs a BuildGUI_SolidDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 BuildGUI_SolidDlg::BuildGUI_SolidDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
50 : GEOMBase_Skeleton( theGeometryGUI, parent )
52 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_SOLID" ) ) );
53 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55 setWindowTitle( tr( "GEOM_SOLID_TITLE" ) );
57 /***************************************************************/
58 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SOLID" ) );
59 mainFrame()->RadioButton1->setIcon( image0 );
60 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton2->close();
62 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63 mainFrame()->RadioButton3->close();
65 GroupSolid = new DlgRef_1Sel1Check( centralWidget() );
67 GroupSolid->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
68 GroupSolid->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
69 GroupSolid->CheckButton1->setText( tr( "GEOM_CREATE_SINGLE_SOLID" ) );
70 GroupSolid->PushButton1->setIcon( image1 );
71 GroupSolid->LineEdit1->setReadOnly( true );
73 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74 layout->setMargin( 0 ); layout->setSpacing( 6 );
75 layout->addWidget( GroupSolid );
76 /***************************************************************/
78 setHelpFileName("create_solid_page.html");
85 //=================================================================================
86 // function : ~BuildGUI_SolidDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
91 // no need to delete child widgets, Qt does it all for us
95 //=================================================================================
98 //=================================================================================
99 void BuildGUI_SolidDlg::Init()
102 myEditCurrentArgument = GroupSolid->LineEdit1;
103 GroupSolid->LineEdit1->setReadOnly( true );
104 GroupSolid->CheckButton1->setChecked( true );
108 //globalSelection( GEOM_SHELL );
109 TColStd_MapOfInteger aMap;
110 aMap.Add( GEOM_SHELL );
111 aMap.Add( GEOM_COMPOUNDFILTER );
112 QList<int> aSubShapes;
113 aSubShapes.append( GEOM_SHELL );
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( GroupSolid->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
121 connect( GroupSolid->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( EnableNameField( bool ) ) );
123 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
124 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
126 initName( tr( "GEOM_SOLID" ) );
127 SelectionIntoArgument();
131 //=================================================================================
132 // function : ClickOnOk()
134 //=================================================================================
135 void BuildGUI_SolidDlg::ClickOnOk()
137 setIsApplyAndClose( true );
138 if ( ClickOnApply() )
142 //=================================================================================
143 // function : ClickOnApply()
145 //=================================================================================
146 bool BuildGUI_SolidDlg::ClickOnApply()
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection as changed or other case
159 //=================================================================================
160 void BuildGUI_SolidDlg::SelectionIntoArgument()
162 myEditCurrentArgument->setText( "" );
164 //myShells = getSelected( TopAbs_SHELL, -1 );
165 QList<TopAbs_ShapeEnum> types;
166 types << TopAbs_SHELL << TopAbs_COMPOUND;
167 myShells = getSelected( types, -1 );
169 if ( !myShells.isEmpty() ) {
170 QString aName = myShells.count() > 1 ? QString( "%1_objects").arg( myShells.count() ) : GEOMBase::GetName( myShells[0].get() );
171 myEditCurrentArgument->setText( aName );
175 //=================================================================================
176 // function : SetEditCurrentArgument()
178 //=================================================================================
179 void BuildGUI_SolidDlg::SetEditCurrentArgument()
181 QPushButton* send = (QPushButton*)sender();
182 if ( send != GroupSolid->PushButton1 )
185 //globalSelection( GEOM_SHELL );
186 TColStd_MapOfInteger aMap;
187 aMap.Add( GEOM_SHELL );
188 aMap.Add( GEOM_COMPOUNDFILTER );
189 QList<int> aSubShapes;
190 aSubShapes.append( GEOM_SHELL );
191 globalSelection( aMap, aSubShapes );
193 myEditCurrentArgument = GroupSolid->LineEdit1;
195 myEditCurrentArgument->setFocus();
196 SelectionIntoArgument();
200 //=================================================================================
201 // function : ActivateThisDialog()
203 //=================================================================================
204 void BuildGUI_SolidDlg::ActivateThisDialog()
206 GEOMBase_Skeleton::ActivateThisDialog();
207 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
208 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
210 //globalSelection( GEOM_SHELL );
211 TColStd_MapOfInteger aMap;
212 aMap.Add( GEOM_SHELL );
213 aMap.Add( GEOM_COMPOUNDFILTER );
214 QList<int> aSubShapes;
215 aSubShapes.append( GEOM_SHELL );
216 globalSelection( aMap, aSubShapes );
220 //=================================================================================
221 // function : enterEvent()
223 //=================================================================================
224 void BuildGUI_SolidDlg::enterEvent( QEvent* )
226 if ( !mainFrame()->GroupConstructors->isEnabled() )
227 ActivateThisDialog();
231 //=================================================================================
232 // function : EnableNameField()
234 //=================================================================================
235 void BuildGUI_SolidDlg::EnableNameField( bool toEnable )
237 mainFrame()->GroupBoxName->setEnabled( toEnable );
240 //=================================================================================
241 // function : createOperation
243 //=================================================================================
244 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
246 return getGeomEngine()->GetIShapesOperations( getStudyId() );
249 //=================================================================================
250 // function : isValid
252 //=================================================================================
253 bool BuildGUI_SolidDlg::isValid (QString& msg)
255 bool ok = !myShells.isEmpty();
257 GEOM::MeasureOpPtr anOp;
258 anOp.take(myGeomGUI->GetGeomGen()->GetIMeasureOperations(getStudyId()));
260 for ( int i = 0, n = myShells.count(); i < n && ok; i++ ) {
261 CORBA::String_var aRes = anOp->IsGoodForSolid(myShells[i].get());
262 if (strlen(aRes.in())) {
263 msg = QObject::tr(aRes.in()).arg(GEOMBase::GetName(myShells[i].get()));
271 //=================================================================================
272 // function : isClosed
273 // purpose : Check the object 'i' in myShells list is closed or unclosed
274 //=================================================================================
275 bool BuildGUI_SolidDlg::isClosed( GEOM::GEOM_Object_ptr shell )
279 GEOM::GEOM_IKindOfShape::shape_kind aKind;
280 GEOM::ListOfLong_var anInts;
281 GEOM::ListOfDouble_var aDbls;
283 if ( !CORBA::is_nil( shell ) ) {
284 GEOM::MeasureOpPtr anOp;
285 anOp.take( myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() ) );
287 // Detect kind of shape and parameters
288 aKind = anOp->KindOfShape(shell, anInts, aDbls);
290 if ( anOp->IsDone() ) {
291 if ( anInts[0] == 1 )
293 else if ( anInts[0] == 2 )
297 MESSAGE ("KindOfShape Operation is NOT DONE!!!");
301 MESSAGE ("Shape is NULL!!!");
308 //=================================================================================
309 // function : execute
311 //=================================================================================
312 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
314 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
316 if ( GroupSolid->CheckButton1->isChecked() ) {
317 GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
318 objlist->length( myShells.count() );
319 for ( int i = 0; i < myShells.count(); i++ )
320 objlist[i] = myShells[i].copy();
322 GEOM::GEOM_Object_var anObj = anOper->MakeSolidShells( objlist.in() );
324 if ( !anObj->_is_nil() )
325 objects.push_back( anObj._retn() );
328 for ( int i = 0, n = myShells.count(); i< n; i++ ) {
329 GEOM::GEOM_Object_var anObj = anOper->MakeSolidShell( myShells[ i ].get() );
331 if ( !anObj->_is_nil() )
332 objects.push_back( anObj._retn() );