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 : EntityGUI_SubShapeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "EntityGUI_SubShapeDlg.h"
28 #include <GEOM_DlgRef.h>
29 #include <GeometryGUI.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ViewManager.h>
36 #include <SUIT_ViewWindow.h>
37 #include <OCCViewer_ViewModel.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopoDS_Iterator.hxx>
43 #include <TopExp_Explorer.hxx>
44 #include <TopTools_MapOfShape.hxx>
46 #include <QMessageBox>
48 //=================================================================================
49 // class : EntityGUI_SubShapeDlg
50 // purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
56 bool modal, Qt::WindowFlags fl )
57 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
59 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SUBSHAPE" ) ) );
60 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 setWindowTitle( tr( "GEOM_SUBSHAPE_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SUB_SHAPE" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
68 mainFrame()->RadioButton2->close();
69 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
70 mainFrame()->RadioButton3->close();
72 GroupPoints = new DlgRef_1Sel1Check1List( centralWidget() );
74 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
75 GroupPoints->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
76 GroupPoints->TextLabel2->setText( tr( "GEOM_SUBSHAPE_TYPE" ) );
77 GroupPoints->CheckButton1->setText( tr( "GEOM_SUBSHAPE_SELECT" ) );
78 GroupPoints->PushButton1->setIcon( image1 );
79 GroupPoints->LineEdit1->setReadOnly( true );
81 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
82 layout->setMargin( 0 ); layout->setSpacing( 6 );
83 layout->addWidget( GroupPoints );
84 /***************************************************************/
86 setHelpFileName( "explode.htm" );
92 //=================================================================================
93 // function : ~EntityGUI_SubShapeDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
101 //=================================================================================
104 //=================================================================================
105 void EntityGUI_SubShapeDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
109 myObject = GEOM::GEOM_Object::_nil();
113 /* type for sub shape selection */
114 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compound" );
115 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compsolid" );
116 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Solid" );
117 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shell" );
118 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Face" );
119 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Wire" );
120 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Edge" );
121 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Vertex" );
122 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shape" );
124 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
125 != OCCViewer_Viewer::Type() )
126 GroupPoints->CheckButton1->setEnabled( false );
128 /* signals and slots connections */
129 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
131 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
132 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
134 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
135 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
137 connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
138 connect( GroupPoints->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( SubShapeToggled() ) );
140 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
141 SIGNAL( currentSelectionChanged( )), this, SLOT( SelectionIntoArgument() ) );
145 SelectionIntoArgument();
149 //=================================================================================
150 // function : ClickOnOk()
152 //=================================================================================
153 void EntityGUI_SubShapeDlg::ClickOnOk()
155 if ( ClickOnApply() )
160 //=================================================================================
161 // function : ClickOnApply()
163 //=================================================================================
164 bool EntityGUI_SubShapeDlg::ClickOnApply()
166 SUIT_Session::session()->activeApplication()->putInfo( "" );
168 /* Explode all sub shapes */
169 if ( isAllSubShapes() ) {
170 /* More than 30 subshapes : ask confirmation */
171 unsigned int nb = NumberOfSubShapes( myShape, shapeType() );
173 const QString caption = tr( "GEOM_CONFIRM" );
174 const QString text = tr( "GEOM_CONFIRM_INFO" ).arg( nb );
175 const QString button0 = tr( "GEOM_BUT_EXPLODE" );
176 const QString button1 = tr( "GEOM_BUT_CANCEL" );
178 if ( QMessageBox::warning( this, caption, text, button0, button1 ) != 0 )
179 return false; /* aborted */
187 //=================================================================================
188 // function : SelectionIntoArgument()
189 // purpose : Called when selection as changed or other case
190 // : used only by SelectButtonC1A1 (LineEditC1A1)
191 //=================================================================================
192 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
194 if ( !isAllSubShapes() )
197 ResetStateOfDialog();
199 QString aString = ""; /* name of selection */
201 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
206 Handle(SALOME_InteractiveObject) IO = firstIObject();
207 if ( !IO->hasEntry() ) {
208 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_SHAPE_IN_STUDY" ) );
213 if ( !GEOMBase::GetTopoFromSelection( selectedIO(), S ) ||
215 S.ShapeType() == TopAbs_VERTEX ) {
221 Standard_Boolean testResult;
222 myObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
223 if ( !testResult || myObject->_is_nil() ) {
229 GroupPoints->LineEdit1->setText( aString );
232 int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
233 int count = GroupPoints->ComboBox1->count();
240 if ( myShape.ShapeType() == TopAbs_COMPOUND ) {
241 unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
245 while ( i <= myShape.ShapeType() ) {
246 GroupPoints->ComboBox1->removeItem( 0 );
250 if ( myShape.ShapeType() == TopAbs_COMPOUND ) {
251 if ( myWithShape == false ) {
252 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shape" );
257 if ( myWithShape == true ) {
258 GroupPoints->ComboBox1->removeItem( GroupPoints->ComboBox1->count() - 1 );
263 int count1 = GroupPoints->ComboBox1->count();
267 if ( SelectedShapeType > myShape.ShapeType() ) {
268 if ( SelectedShapeType == 8 ) {
269 if ( myShape.ShapeType() != TopAbs_COMPOUND ) {
270 GroupPoints->ComboBox1->setCurrentIndex( 0 );
275 GroupPoints->ComboBox1->setCurrentIndex( count1 - count + SelectedShapeType );
278 GroupPoints->ComboBox1->setCurrentIndex( 0 );
286 //=================================================================================
287 // function : SetEditCurrentArgument()
289 //=================================================================================
290 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
292 GroupPoints->LineEdit1->setFocus();
293 myEditCurrentArgument = GroupPoints->LineEdit1;
295 GroupPoints->CheckButton1->setChecked( false );
297 SelectionIntoArgument();
301 //=================================================================================
302 // function : LineEditReturnPressed()
304 //=================================================================================
305 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
307 QLineEdit* send = (QLineEdit*)sender();
308 if ( send == GroupPoints->LineEdit1 )
309 SetEditCurrentArgument();
313 GEOMBase_Skeleton::LineEditReturnPressed();
317 //=================================================================================
318 // function : DeactivateActiveDialog()
320 //=================================================================================
321 void EntityGUI_SubShapeDlg::DeactivateActiveDialog()
323 if ( mainFrame()->GroupConstructors->isEnabled() ) {
324 GEOMBase_Skeleton::DeactivateActiveDialog();
329 //=================================================================================
330 // function : ActivateThisDialog()
332 //=================================================================================
333 void EntityGUI_SubShapeDlg::ActivateThisDialog()
335 GEOMBase_Skeleton::ActivateThisDialog();
336 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( ) ) )->selectionMgr(),
337 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ) ;
343 //=================================================================================
344 // function : enterEvent()
346 //=================================================================================
347 void EntityGUI_SubShapeDlg::enterEvent( QEvent* )
349 if ( !mainFrame()->GroupConstructors->isEnabled() )
350 ActivateThisDialog();
353 //=================================================================================
354 // function : ResetStateOfDialog()
355 // purpose : Completely reset the state of method including local context
356 //=================================================================================
357 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
359 myObject = GEOM::GEOM_Object::_nil();
361 myEditCurrentArgument->setText( "" );
363 int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
364 int count = GroupPoints->ComboBox1->count();
368 /* type for sub shape selection */
369 GroupPoints->ComboBox1->clear();
370 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compound" );
371 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compsolid" );
372 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Solid" );
373 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shell" );
374 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Face" );
375 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Wire" );
376 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Edge" );
377 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Vertex" );
378 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shape" );
382 GroupPoints->ComboBox1->setCurrentIndex( 8 - count + SelectedShapeType );
389 //=================================================================================
390 // function : SubShapeToggled()
391 // purpose : Allow user selection of all or only selected sub shapes
392 // : Called when 'CheckButton1' state change
393 //=================================================================================
394 void EntityGUI_SubShapeDlg::SubShapeToggled()
396 if ( isAllSubShapes() )
397 globalSelection( GEOM_ALLSHAPES );
399 localSelection( myObject, shapeType() );
403 //=================================================================================
404 // function : ComboTextChanged()
406 //=================================================================================
407 void EntityGUI_SubShapeDlg::ComboTextChanged()
409 /* Select sub shapes mode not checked */
415 //=================================================================================
416 // function : NumberOfSubShapes()
418 //=================================================================================
419 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes( const TopoDS_Shape& S,
420 const int shapeType ) const
425 unsigned int index = 0;
426 TopTools_MapOfShape M;
428 if ( S.ShapeType() == TopAbs_COMPOUND &&
429 ( TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
430 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
431 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND ) ) {
432 TopoDS_Iterator It( S, Standard_True, Standard_True );
433 for ( ; It.More(); It.Next() ) {
434 if ( M.Add( It.Value() ) ) {
435 if ( TopAbs_ShapeEnum( shapeType ) == TopAbs_SHAPE ||
436 TopAbs_ShapeEnum( shapeType ) == It.Value().ShapeType() ) {
443 TopExp_Explorer Exp ( S, TopAbs_ShapeEnum( shapeType ) );
444 for ( ; Exp.More(); Exp.Next() ) {
445 if ( M.Add( Exp.Current() ) ) {
455 //=================================================================================
456 // function : updateButtonState
458 //=================================================================================
459 void EntityGUI_SubShapeDlg::updateButtonState()
461 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() ||
462 myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND ) {
463 GroupPoints->CheckButton1->setChecked( false );
464 GroupPoints->CheckButton1->setEnabled( false );
467 GroupPoints->CheckButton1->setEnabled( true );
470 //=================================================================================
471 // function : isAllSubShapes
473 //=================================================================================
474 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
476 return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
479 //=================================================================================
480 // function : shapeType
482 //=================================================================================
483 int EntityGUI_SubShapeDlg::shapeType() const
485 int type = GroupPoints->ComboBox1->currentIndex();
487 if ( myObject->_is_nil() )
491 type += myShape.ShapeType() + 1;
492 if ( myShape.ShapeType() == TopAbs_COMPOUND &&
493 NumberOfSubShapes( myShape, TopAbs_COMPOUND ) > 0 ) {
500 //=================================================================================
501 // function : createOperation
503 //=================================================================================
504 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
506 return getGeomEngine()->GetIShapesOperations( getStudyId() );
509 //=================================================================================
510 // function : isValid
512 //=================================================================================
513 bool EntityGUI_SubShapeDlg::isValid( QString& msg )
516 if ( !myObject->_is_nil() ) {
517 if ( isAllSubShapes() )
519 else if ( IObjectCount() == 1 ) {
520 Standard_Boolean aResult = Standard_False;
521 GEOM::GEOM_Object_var anObj =
522 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
524 if ( aResult && !anObj->_is_nil() ) {
525 TColStd_IndexedMapOfInteger aMapIndex;
526 ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
527 isOk = aMapIndex.Extent() > 0;
529 msg += tr( "NO_SUBSHAPES_SELECTED" );
536 //=================================================================================
537 // function : execute
539 //=================================================================================
540 bool EntityGUI_SubShapeDlg::execute( ObjectList& objects )
542 GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow(
543 getOperation() )->MakeExplode( myObject, shapeType(), true );
545 if ( !aList->length() )
548 // Throw away sub-shapes not selected by user if not in preview mode
549 // and manual selection is active
550 if ( !isAllSubShapes() ) {
551 if ( IObjectCount() == 1 ) {
552 Standard_Boolean aResult = Standard_False;
553 GEOM::GEOM_Object_var anObj =
554 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
556 if ( aResult && !anObj->_is_nil() ) {
557 TColStd_IndexedMapOfInteger aMapIndex;
558 ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
560 GEOM::GEOM_ILocalOperations_var aLocOp =
561 getGeomEngine()->GetILocalOperations( getStudyId() );
563 for ( int i = 0, n = aList->length(); i < n; i++ )
564 if ( aMapIndex.Contains( aLocOp->GetSubShapeIndex( myObject, aList[i] ) ) )
565 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
570 for ( int i = 0, n = aList->length(); i < n; i++ )
571 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
573 return objects.size();
576 //================================================================
577 // Function : getFather
578 // Purpose : Get father object for object to be added in study
579 // ( called with addInStudy method )
580 //================================================================
581 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather( GEOM::GEOM_Object_ptr )
586 const char* EntityGUI_SubShapeDlg::getNewObjectName() const