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"
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( "create_explode_page.html" );
88 mainFrame()->GroupBoxName->hide();
94 //=================================================================================
95 // function : ~EntityGUI_SubShapeDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
103 //=================================================================================
106 //=================================================================================
107 void EntityGUI_SubShapeDlg::Init()
110 myEditCurrentArgument = GroupPoints->LineEdit1;
111 myObject = GEOM::GEOM_Object::_nil();
115 /* type for sub shape selection */
116 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compound" );
117 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compsolid" );
118 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Solid" );
119 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shell" );
120 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Face" );
121 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Wire" );
122 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Edge" );
123 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Vertex" );
124 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shape" );
126 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
127 != OCCViewer_Viewer::Type() )
128 GroupPoints->CheckButton1->setEnabled( false );
130 /* signals and slots connections */
131 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
133 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
134 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
136 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
137 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
139 connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
140 connect( GroupPoints->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( SubShapeToggled() ) );
142 connect( myGeomGUI->getApp()->selectionMgr(),
143 SIGNAL( currentSelectionChanged( )), this, SLOT( SelectionIntoArgument() ) );
147 SelectionIntoArgument();
151 //=================================================================================
152 // function : ClickOnOk()
154 //=================================================================================
155 void EntityGUI_SubShapeDlg::ClickOnOk()
157 if ( ClickOnApply() )
162 //=================================================================================
163 // function : ClickOnApply()
165 //=================================================================================
166 bool EntityGUI_SubShapeDlg::ClickOnApply()
168 SUIT_Session::session()->activeApplication()->putInfo( "" );
170 /* Explode all sub shapes */
171 if ( isAllSubShapes() ) {
172 /* More than 30 subshapes : ask confirmation */
173 unsigned int nb = NumberOfSubShapes( myShape, shapeType() );
175 const QString caption = tr( "GEOM_CONFIRM" );
176 const QString text = tr( "GEOM_CONFIRM_INFO" ).arg( nb );
177 const QString button0 = tr( "GEOM_BUT_EXPLODE" );
178 const QString button1 = tr( "GEOM_BUT_CANCEL" );
180 if ( QMessageBox::warning( this, caption, text, button0, button1 ) != 0 )
181 return false; /* aborted */
185 bool isOk = onAccept();
187 // restore selection, corresponding to current selection mode
194 //=================================================================================
195 // function : SelectionIntoArgument()
196 // purpose : Called when selection as changed or other case
197 // : used only by SelectButtonC1A1 (LineEditC1A1)
198 //=================================================================================
199 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
201 if ( !isAllSubShapes() )
204 ResetStateOfDialog();
206 QString aString = ""; /* name of selection */
208 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
213 Handle(SALOME_InteractiveObject) IO = firstIObject();
214 if ( !IO->hasEntry() ) {
215 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_SHAPE_IN_STUDY" ) );
220 if ( !GEOMBase::GetTopoFromSelection( selectedIO(), S ) ||
222 S.ShapeType() == TopAbs_VERTEX ) {
228 Standard_Boolean testResult;
229 myObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
230 if ( !testResult || myObject->_is_nil() ) {
236 GroupPoints->LineEdit1->setText( aString );
239 int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
240 int count = GroupPoints->ComboBox1->count();
247 if ( myShape.ShapeType() == TopAbs_COMPOUND ) {
248 unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
252 while ( i <= myShape.ShapeType() ) {
253 GroupPoints->ComboBox1->removeItem( 0 );
257 if ( myShape.ShapeType() == TopAbs_COMPOUND ) {
258 if ( myWithShape == false ) {
259 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shape" );
264 if ( myWithShape == true ) {
265 GroupPoints->ComboBox1->removeItem( GroupPoints->ComboBox1->count() - 1 );
270 int count1 = GroupPoints->ComboBox1->count();
274 if ( SelectedShapeType > myShape.ShapeType() ) {
275 if ( SelectedShapeType == 8 ) {
276 if ( myShape.ShapeType() != TopAbs_COMPOUND ) {
277 GroupPoints->ComboBox1->setCurrentIndex( 0 );
282 GroupPoints->ComboBox1->setCurrentIndex( count1 - count + SelectedShapeType );
285 GroupPoints->ComboBox1->setCurrentIndex( 0 );
293 //=================================================================================
294 // function : SetEditCurrentArgument()
296 //=================================================================================
297 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
299 GroupPoints->LineEdit1->setFocus();
300 myEditCurrentArgument = GroupPoints->LineEdit1;
302 GroupPoints->CheckButton1->setChecked( false );
304 SelectionIntoArgument();
308 //=================================================================================
309 // function : LineEditReturnPressed()
311 //=================================================================================
312 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
314 QLineEdit* send = (QLineEdit*)sender();
315 if ( send == GroupPoints->LineEdit1 )
316 SetEditCurrentArgument();
320 GEOMBase_Skeleton::LineEditReturnPressed();
324 //=================================================================================
325 // function : DeactivateActiveDialog()
327 //=================================================================================
328 void EntityGUI_SubShapeDlg::DeactivateActiveDialog()
330 if ( mainFrame()->GroupConstructors->isEnabled() ) {
331 GEOMBase_Skeleton::DeactivateActiveDialog();
336 //=================================================================================
337 // function : ActivateThisDialog()
339 //=================================================================================
340 void EntityGUI_SubShapeDlg::ActivateThisDialog()
342 GEOMBase_Skeleton::ActivateThisDialog();
343 connect( myGeomGUI->getApp()->selectionMgr(),
344 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
350 //=================================================================================
351 // function : enterEvent()
353 //=================================================================================
354 void EntityGUI_SubShapeDlg::enterEvent( QEvent* )
356 if ( !mainFrame()->GroupConstructors->isEnabled() )
357 ActivateThisDialog();
360 //=================================================================================
361 // function : ResetStateOfDialog()
362 // purpose : Completely reset the state of method including local context
363 //=================================================================================
364 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
366 myObject = GEOM::GEOM_Object::_nil();
368 myEditCurrentArgument->setText( "" );
370 int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
371 int count = GroupPoints->ComboBox1->count();
375 /* type for sub shape selection */
376 GroupPoints->ComboBox1->clear();
377 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compound" );
378 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compsolid" );
379 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Solid" );
380 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shell" );
381 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Face" );
382 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Wire" );
383 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Edge" );
384 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Vertex" );
385 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shape" );
389 GroupPoints->ComboBox1->setCurrentIndex( 8 - count + SelectedShapeType );
396 //=================================================================================
397 // function : SubShapeToggled()
398 // purpose : Allow user selection of all or only selected sub shapes
399 // : Called when 'CheckButton1' state change
400 //=================================================================================
401 void EntityGUI_SubShapeDlg::SubShapeToggled()
403 globalSelection( GEOM_ALLSHAPES );
405 if ( !isAllSubShapes() )
406 localSelection( myObject, shapeType() );
410 //=================================================================================
411 // function : ComboTextChanged()
413 //=================================================================================
414 void EntityGUI_SubShapeDlg::ComboTextChanged()
416 /* Select sub shapes mode not checked */
422 //=================================================================================
423 // function : NumberOfSubShapes()
425 //=================================================================================
426 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes( const TopoDS_Shape& S,
427 const int shapeType ) const
432 unsigned int index = 0;
433 TopTools_MapOfShape M;
435 if ( S.ShapeType() == TopAbs_COMPOUND &&
436 ( TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
437 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
438 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND ) ) {
439 TopoDS_Iterator It( S, Standard_True, Standard_True );
440 for ( ; It.More(); It.Next() ) {
441 if ( M.Add( It.Value() ) ) {
442 if ( TopAbs_ShapeEnum( shapeType ) == TopAbs_SHAPE ||
443 TopAbs_ShapeEnum( shapeType ) == It.Value().ShapeType() ) {
450 TopExp_Explorer Exp ( S, TopAbs_ShapeEnum( shapeType ) );
451 for ( ; Exp.More(); Exp.Next() ) {
452 if ( M.Add( Exp.Current() ) ) {
462 //=================================================================================
463 // function : updateButtonState
465 //=================================================================================
466 void EntityGUI_SubShapeDlg::updateButtonState()
468 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() ||
469 myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND ) {
470 GroupPoints->CheckButton1->setChecked( false );
471 GroupPoints->CheckButton1->setEnabled( false );
474 GroupPoints->CheckButton1->setEnabled( true );
477 //=================================================================================
478 // function : isAllSubShapes
480 //=================================================================================
481 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
483 return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
486 //=================================================================================
487 // function : shapeType
489 //=================================================================================
490 int EntityGUI_SubShapeDlg::shapeType() const
492 int type = GroupPoints->ComboBox1->currentIndex();
494 if ( myObject->_is_nil() )
498 type += myShape.ShapeType() + 1;
499 if ( myShape.ShapeType() == TopAbs_COMPOUND &&
500 NumberOfSubShapes( myShape, TopAbs_COMPOUND ) > 0 ) {
507 //=================================================================================
508 // function : createOperation
510 //=================================================================================
511 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
513 return getGeomEngine()->GetIShapesOperations( getStudyId() );
516 //=================================================================================
517 // function : isValid
519 //=================================================================================
520 bool EntityGUI_SubShapeDlg::isValid( QString& msg )
523 Handle(SALOME_InteractiveObject) IO = firstIObject();
524 Standard_Boolean testResult;
525 myObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
526 if ( !testResult || myObject->_is_nil() ) {
530 if ( !myObject->_is_nil() ) {
531 if ( isAllSubShapes() )
533 else if ( IObjectCount() == 1 ) {
534 Standard_Boolean aResult = Standard_False;
535 GEOM::GEOM_Object_var anObj =
536 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
538 if ( aResult && !anObj->_is_nil() ) {
539 TColStd_IndexedMapOfInteger aMapIndex;
540 myGeomGUI->getApp()->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
541 isOk = aMapIndex.Extent() > 0;
543 msg += tr( "NO_SUBSHAPES_SELECTED" );
550 //=================================================================================
551 // function : execute
553 //=================================================================================
554 bool EntityGUI_SubShapeDlg::execute( ObjectList& objects )
556 GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow(
557 getOperation() )->MakeExplode( myObject, shapeType(), true );
559 if ( !aList->length() )
562 // Throw away sub-shapes not selected by user if not in preview mode
563 // and manual selection is active
564 if ( !isAllSubShapes() ) {
565 if ( IObjectCount() == 1 ) {
566 Standard_Boolean aResult = Standard_False;
567 GEOM::GEOM_Object_var anObj =
568 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
570 if ( aResult && !anObj->_is_nil() ) {
571 TColStd_IndexedMapOfInteger aMapIndex;
572 myGeomGUI->getApp()->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
574 GEOM::GEOM_ILocalOperations_var aLocOp =
575 getGeomEngine()->GetILocalOperations( getStudyId() );
577 for ( int i = 0, n = aList->length(); i < n; i++ )
578 if ( aMapIndex.Contains( aLocOp->GetSubShapeIndex( myObject, aList[i] ) ) )
579 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
584 for ( int i = 0, n = aList->length(); i < n; i++ )
585 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
587 return objects.size();
590 //================================================================
591 // Function : getFather
592 // Purpose : Get father object for object to be added in study
593 // ( called with addInStudy method )
594 //================================================================
595 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather( GEOM::GEOM_Object_ptr )
600 const char* EntityGUI_SubShapeDlg::getNewObjectName() const