1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "GEOMToolsGUI_ReduceStudyDlg.h"
27 #include <SUIT_Session.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_MessageBox.h>
31 #include <LightApp_SelectionMgr.h>
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_Study.h>
35 #include <SALOME_ListIO.hxx>
38 #include <QGridLayout>
39 #include <QPushButton>
40 #include <QRadioButton>
41 #include <QHeaderView>
42 #include <QMessageBox>
44 GEOMToolsGUI_ReduceStudyDlg::GEOMToolsGUI_ReduceStudyDlg( QWidget* parent )
45 :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
47 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
48 myVisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) );
49 myInvisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) ) );
51 myApp = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
54 myDisplayer = GEOM_Displayer();
56 setWindowTitle( tr( "GEOM_REDUCE_STUDY_TITLE" ) );
57 setAttribute(Qt::WA_DeleteOnClose);
59 QGridLayout* topLayout = new QGridLayout( this );
60 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
62 /********************** Objects to be kept **********************/
63 QGroupBox* groupKeptObjects = new QGroupBox( tr( "GEOM_REDUCE_STUDY_KEPT_OBJECTS" ) );
64 QGridLayout* layoutKeptObjects = new QGridLayout( groupKeptObjects );
65 createTreeWidget( myTreeKeptObjects = new QTreeWidget() );
66 layoutKeptObjects->addWidget( myTreeKeptObjects );
68 /********************** Objects to be removed **********************/
69 QGroupBox* groupRemoveObjects = new QGroupBox( tr( "GEOM_REDUCE_STUDY_REMOVE_OBJECTS" ) );
70 QGridLayout* layoutRemoveObjects = new QGridLayout( groupRemoveObjects );
71 createTreeWidget( myTreeRemoveObjects = new QTreeWidget() );
72 layoutRemoveObjects->addWidget( myTreeRemoveObjects );
74 /********************** Options **********************/
75 QGroupBox* groupOptions = new QGroupBox( tr( "GEOM_REDUCE_STUDY_OPTIONS" ) );
76 QVBoxLayout* layoutOptions = new QVBoxLayout( groupOptions );
78 // Intermediate objects
79 QGroupBox* groupIntermediates = createButtonGroup( myGroupIntermediates = new QButtonGroup() );
80 groupIntermediates->setTitle( tr( "GEOM_REDUCE_STUDY_INTERMEDIATES" ) );
83 QGroupBox* groupSubObjects = createButtonGroup( myGroupSubObjects = new QButtonGroup() );
84 groupSubObjects->setTitle( tr( "GEOM_REDUCE_STUDY_SUB_OBJECTS" ) );
87 myCBRemoveEmptyFolder = new QCheckBox( tr( "GEOM_REDUCE_STUDY_REMOVE_EMPTY_FOLDER" ) );
88 myCBRemoveEmptyFolder->setChecked( true );
89 myCBSoftRemoval = new QCheckBox( tr( "GEOM_REDUCE_STUDY_SOFT_REMOVAL" ) );
91 layoutOptions->addWidget( groupIntermediates );
92 layoutOptions->addWidget( groupSubObjects );
93 layoutOptions->addWidget( myCBRemoveEmptyFolder );
94 layoutOptions->addWidget( myCBSoftRemoval );
96 /********************** Buttons **********************/
97 QGroupBox* groupButtons = new QGroupBox();
98 QHBoxLayout* layoutButtons = new QHBoxLayout( groupButtons );
100 QPushButton* buttonOk = new QPushButton( tr( "GEOM_BUT_OK" ) );
101 QPushButton* buttonCancel = new QPushButton( tr( "GEOM_BUT_CANCEL" ) );
102 QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ) );
104 layoutButtons->addWidget( buttonOk );
105 layoutButtons->addStretch();
106 layoutButtons->addWidget( buttonCancel );
107 layoutButtons->addWidget( buttonHelp );
109 topLayout->addWidget( groupKeptObjects, 0, 0 );
110 topLayout->addWidget( groupRemoveObjects, 0, 1 );
111 topLayout->addWidget( groupOptions, 1, 0, 1, 2 );
112 topLayout->addWidget( groupButtons, 2, 0, 1, 2 );
114 // Signals and slots connections
116 connect( myTreeKeptObjects, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
117 connect( myTreeRemoveObjects, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
118 connect( myTreeKeptObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) );
119 connect( myTreeRemoveObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) );
121 connect( myGroupIntermediates, SIGNAL( buttonClicked( int ) ), this, SLOT( update() ) );
122 connect( myGroupSubObjects, SIGNAL( buttonClicked( int ) ), this, SLOT( update() ) );
124 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
125 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
126 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) );
128 connect( myApp->selectionMgr(), SIGNAL( currentSelectionChanged() ),
129 this, SLOT( selectionChanged() ) );
131 init( getSelectedObjects() );
134 GEOMToolsGUI_ReduceStudyDlg::~GEOMToolsGUI_ReduceStudyDlg()
136 // no need to delete child widgets, Qt does it all for us
139 //=================================================================================
141 // purpose : initialize dialog data
142 //=================================================================================
143 void GEOMToolsGUI_ReduceStudyDlg::init( const std::set<std::string>& theObjectEntries )
145 myMainEntries.clear();
147 myKeptObjects.clear();
148 myListParents.clear();
149 myListSubObjects.clear();
150 myRemovedObjects.clear();
152 myMainEntries = theObjectEntries;
154 GEOM::string_array_var keptObjects = new GEOM::string_array();
156 keptObjects->length( theObjectEntries.size() );
157 std::set<std::string>::iterator iter;
158 for( iter=theObjectEntries.begin(); iter!=theObjectEntries.end(); ++iter, It++ )
159 keptObjects[ It ] = (*iter).c_str();
161 GEOM::string_array_var parentsObjects = new GEOM::string_array();
162 GEOM::string_array_var subObjects = new GEOM::string_array();
163 GEOM::string_array_var otherObjects = new GEOM::string_array();
165 GeometryGUI::GetGeomGen()->GetEntriesToReduceStudy( keptObjects, parentsObjects,
166 subObjects, otherObjects );
168 for ( unsigned long i = 0; i < keptObjects->length(); i++ )
169 myKeptObjects.insert( keptObjects[i].in() );
170 for( unsigned long i = 0; i< otherObjects->length(); i++ )
171 myRemovedObjects.insert( otherObjects[i].in() );
172 for( unsigned long i = 0; i< parentsObjects->length(); i++ )
173 myListParents.insert( parentsObjects[i].in() );
174 for( unsigned long i = 0; i< subObjects->length(); i++ )
175 myListSubObjects.insert( subObjects[i].in() );
179 checkVisibleIcon( myTreeKeptObjects );
180 checkVisibleIcon( myTreeRemoveObjects );
183 //=================================================================================
184 // function : getSelectedObjects()
185 // purpose : get selected objects in object browser
186 //=================================================================================
187 std::set<std::string> GEOMToolsGUI_ReduceStudyDlg::getSelectedObjects() const
189 std::set<std::string> objects;
191 SALOME_ListIO selected;
192 myApp->selectionMgr()->selectedObjects( selected );
194 for( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
195 Handle( SALOME_InteractiveObject ) io = It.Value();
196 if( !io->hasEntry() )
198 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil();
199 geomObject = GEOMBase::ConvertIOinGEOMObject( io );
200 if( geomObject->_is_nil() )
202 QString entry = geomObject->GetEntry();
203 objects.insert( entry.toStdString().c_str() );
208 //=================================================================================
209 // function : createTreeWidget()
210 // purpose : create tree widget for unpublished or removed objects
211 //=================================================================================
212 void GEOMToolsGUI_ReduceStudyDlg::createTreeWidget( QTreeWidget* theTreeWidget )
214 theTreeWidget->setColumnCount( 2 );
215 QStringList columnNames;
216 columnNames.append(tr( "GEOM_REDUCE_STUDY_NAME" ));
217 columnNames.append("");
218 theTreeWidget->setHeaderLabels( columnNames );
219 QTreeWidgetItem * headerItem = new QTreeWidgetItem( columnNames );
220 theTreeWidget->setHeaderItem ( headerItem );
221 theTreeWidget->header()->moveSection( 1, 0 );
222 theTreeWidget->header()->setSectionsClickable( true );
223 theTreeWidget->header()->setSectionsMovable( false );
224 theTreeWidget->header()->setSectionResizeMode( 1, QHeaderView::ResizeToContents );
226 theTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
229 //=================================================================================
230 // function : createButtonGroup()
231 // purpose : create button group for intermediate objects or sub-objects
232 //=================================================================================
233 QGroupBox* GEOMToolsGUI_ReduceStudyDlg::createButtonGroup( QButtonGroup* theButtonGroup )
235 QGroupBox* groupObjects = new QGroupBox();
236 QHBoxLayout* layoutObjects = new QHBoxLayout( groupObjects );
238 QRadioButton* buttonKeep = new QRadioButton( tr( "GEOM_REDUCE_STUDY_KEEP") );
239 theButtonGroup->addButton( buttonKeep, 0 );
240 QRadioButton* buttonUnpublish = new QRadioButton( tr( "GEOM_REDUCE_STUDY_UNPUBLISH") );
241 theButtonGroup->addButton( buttonUnpublish, 1 );
242 QRadioButton* buttonRemove = new QRadioButton( tr( "GEOM_REDUCE_STUDY_REMOVE") );
243 theButtonGroup->addButton( buttonRemove, 2 );
245 theButtonGroup->button( 0 )->setChecked( true );
246 theButtonGroup->setExclusive( true );
248 layoutObjects->addWidget( buttonKeep );
249 layoutObjects->addWidget( buttonUnpublish );
250 layoutObjects->addWidget( buttonRemove );
255 //=================================================================================
256 // function : addObjectsToTree()
257 // purpose : add the list of objects to tree
258 //=================================================================================
259 void GEOMToolsGUI_ReduceStudyDlg::addObjectsToTree( QTreeWidget* theWidget, std::set<std::string>& theObjects )
261 std::set<std::string>::iterator it;
262 for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
263 std::string objectEntry = *it;
264 GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( objectEntry.c_str() );
265 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
266 QString studyEntry = GeomBaseObject->GetStudyEntry();
267 if( GeomObject->_is_nil() || studyEntry.isEmpty() || !isObjectDrawable( studyEntry.toStdString() ) )
269 addSubObject( theWidget, theObjects, GeomObject );
273 //=================================================================================
274 // function : addSubObject()
275 // purpose : add sub-object to parent object in the tree
276 //=================================================================================
277 GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::addSubObject( QTreeWidget* theWidget,
278 std::set<std::string>& theObjects,
279 GEOM::GEOM_Object_var theObject )
281 GEOMToolsGUI_TreeWidgetItem* item;
282 if( !theObject->IsMainShape() ) {
283 GEOM::GEOM_Object_var aMainShape = theObject->GetMainShape();
284 if ( CORBA::is_nil( aMainShape ) )
286 GEOMToolsGUI_TreeWidgetItem* parentItem = addSubObject( theWidget, theObjects, aMainShape );
287 item = findObjectInTree( theWidget, theObject );
289 item = new GEOMToolsGUI_TreeWidgetItem( parentItem, QStringList() << theObject->GetName(), theObject->GetStudyEntry() );
292 item = findObjectInTree( theWidget, theObject );
294 item = new GEOMToolsGUI_TreeWidgetItem( theWidget, QStringList() << theObject->GetName(), theObject->GetStudyEntry() );
297 bool isDisplayed = false;
298 if( theObjects.find( theObject->GetEntry() ) != theObjects.end() ) {
299 isDisplayed = myDisplayer.IsDisplayed( theObject->GetStudyEntry() );
301 item->setVisible( true, myVisible );
303 item->setVisible( false, myInvisible );
305 if( myMainEntries.find( theObject->GetEntry() ) != myMainEntries.end() ) {
306 QFont Textfont = item->font(0);
307 Textfont.setBold( true );
308 item->setFont( 0, Textfont );
312 item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
313 item->setTextColor( 0, QColor( 150, 150, 150 ) );
318 //=================================================================================
319 // function : findObjectInTree()
320 // purpose : find object in the tree
321 //=================================================================================
322 GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::findObjectInTree( QTreeWidget* theWidget, GEOM::GEOM_Object_var theObject )
324 QTreeWidgetItemIterator it( theWidget );
326 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
327 if( QString( item->getStudyEntry() ) == QString( theObject->GetStudyEntry() ) )
334 //=================================================================================
335 // function : checkVisibleIcon()
336 // purpose : set visible or invisible icon in the header of tree
337 //=================================================================================
338 void GEOMToolsGUI_ReduceStudyDlg::checkVisibleIcon( QTreeWidget* theWidget )
340 bool isInvisible = false;
341 QTreeWidgetItemIterator it( theWidget );
343 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
344 //const char* entry = item->getStudyEntry();
345 if( item->flags() & Qt::ItemIsSelectable )
346 if( !item->isVisible() )
352 theWidget->headerItem()->setIcon( 1, myInvisible );
353 myMapTreeSelectAll[ theWidget ] = false;
356 theWidget->headerItem()->setIcon( 1, myVisible );
357 myMapTreeSelectAll[ theWidget ] = true;
361 //=================================================================================
362 // function : isObjectDrawable()
363 // purpose : return true if object is drawable, and false if object is hidden in the study
364 //=================================================================================
365 bool GEOMToolsGUI_ReduceStudyDlg::isObjectDrawable( std::string theStudyEntry )
367 _PTR(Study) aStudy = SalomeApp_Application::getStudy();
368 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
369 //If object hasn't "AttributeDrawable" => it visible
370 bool isDrawable = true;
371 _PTR(SObject) SO ( aStudy->FindObjectID( theStudyEntry ) );
372 _PTR(GenericAttribute) anAttr;
373 if ( SO && SO->FindAttribute( anAttr, "AttributeDrawable" ) ) {
374 _PTR(AttributeDrawable) aDrw (anAttr);
375 isDrawable = aDrw->IsDrawable();
380 //=================================================================================
381 // function : unpublishObjects()
382 // purpose : unpublish(hide) objects in the study
383 //=================================================================================
384 void GEOMToolsGUI_ReduceStudyDlg::unpublishObjects( std::set<std::string>& theObjects )
386 _PTR(Study) aStudy = SalomeApp_Application::getStudy();
387 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
388 std::set<std::string>::iterator it;
389 for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
390 std::string objectEntry = *it;
391 GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( objectEntry.c_str() );
392 std::string studyEntry = GeomBaseObject->GetStudyEntry();
393 if ( studyEntry == "" || !isObjectDrawable( studyEntry ) )
395 _PTR(SObject) obj ( aStudy->FindObjectID( studyEntry.c_str() ) );
396 _PTR(GenericAttribute) anAttr;
398 _PTR(AttributeDrawable) aDrw = aStudyBuilder->FindOrCreateAttribute( obj, "AttributeDrawable" );
399 aDrw->SetDrawable( false );
400 myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( studyEntry.c_str(), "GEOM", "TEMP_IO" ) );
401 // hide references if any
402 std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
403 for ( int i = 0; i < (int)vso.size(); i++ ) {
404 _PTR(SObject) refObj = vso[i];
405 aDrw = aStudyBuilder->FindOrCreateAttribute( refObj, "AttributeDrawable" );
406 aDrw->SetDrawable( false );
410 myApp->updateObjectBrowser( false );
411 myApp->updateActions();
414 //=================================================================================
415 // function : removeObjects()
416 // purpose : remove objects from the study
417 //=================================================================================
418 void GEOMToolsGUI_ReduceStudyDlg::removeObjects( std::set<std::string>& theObjects )
420 std::set<std::string>::iterator it;
421 for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
422 std::string objectEntry = *it;
423 GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( objectEntry.c_str() );
424 std::string studyEntry = GeomBaseObject->GetStudyEntry();
425 if ( studyEntry == "" )
426 GeometryGUI::GetGeomGen()->RemoveObject( GeomBaseObject );
428 if( !isObjectDrawable( studyEntry ) )
430 removeObject( studyEntry );
433 myApp->updateObjectBrowser( false );
434 myApp->updateActions();
437 //=================================================================================
438 // function : removeObject()
439 // purpose : remove object with given study entry
440 //=================================================================================
441 void GEOMToolsGUI_ReduceStudyDlg::removeObject( std::string& theStudyEntry )
443 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
444 _PTR(Study) aStudy = SalomeApp_Application::getStudy();
445 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
446 _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
448 _PTR(SObject) obj ( aStudy->FindObjectID( theStudyEntry.c_str() ) );
450 // remove visual properties of the object
451 appStudy->removeObjectProperties(obj->GetID().c_str());
452 // remove references to this object
453 appStudy->deleteReferencesTo( obj );
454 // remove objects from study
455 aStudyBuilder->RemoveObjectWithChildren( obj );
456 // remove object from use case tree
457 aUseCaseBuilder->Remove( obj );
458 myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( theStudyEntry.c_str(), "GEOM", "TEMP_IO" ) );
462 //=================================================================================
463 // function : removeEmptyFolders()
464 // purpose : remove empty folders from the study
465 //=================================================================================
466 void GEOMToolsGUI_ReduceStudyDlg::removeEmptyFolders()
468 std::set<std::string> emptyFolders;
470 _PTR(Study) aStudy = SalomeApp_Application::getStudy();
471 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
474 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
475 anIter->InitEx( true );
476 while( anIter->More() ) {
477 _PTR(SObject) valSO ( anIter->Value() );
479 if ( !valSO->ReferencedObject( refSO ) )
480 getEmptyFolders( valSO, emptyFolders );
484 std::set<std::string>::iterator iter;
485 for( iter = emptyFolders.begin(); iter != emptyFolders.end(); ++iter ) {
486 std::string studyEntry = *iter;
487 removeObject( studyEntry );
489 myApp->updateObjectBrowser( false );
490 myApp->updateActions();
493 //=================================================================================
494 // function : removeEmptyFolders()
495 // purpose : remove empty folders from the study
496 //=================================================================================
497 void GEOMToolsGUI_ReduceStudyDlg::getEmptyFolders( _PTR(SObject) theSO, std::set<std::string>& theFolders )
499 _PTR(UseCaseBuilder) aUseCaseBuilder = SalomeApp_Application::getStudy()->GetUseCaseBuilder();
501 bool isFolder = false;
502 _PTR(GenericAttribute) anAttr;
503 if ( theSO->FindAttribute(anAttr, "AttributeLocalID") ) {
504 _PTR(AttributeLocalID) aLocalID( anAttr );
505 isFolder = aLocalID->Value() == 999;
507 QString studyEntry = theSO->GetID().c_str();
509 if( !aUseCaseBuilder->HasChildren( theSO ) )
510 theFolders.insert( studyEntry.toStdString() );
512 _PTR(UseCaseIterator) ucit ( aUseCaseBuilder->GetUseCaseIterator( theSO ) );
513 for ( ucit->Init( false ); ucit->More(); ucit->Next() )
514 getEmptyFolders( ucit->Value(), theFolders );
519 //=================================================================================
520 // function : onItemClicked()
521 // purpose : called when tree item was clicked
522 //=================================================================================
523 void GEOMToolsGUI_ReduceStudyDlg::onItemClicked( QTreeWidgetItem* theItem, int theColumn )
525 if( theColumn != 1 || !( theItem->flags() & Qt::ItemIsSelectable ) )
528 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>( theItem );
530 const char* entry = item->getStudyEntry();
531 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" );
532 if( myDisplayer.IsDisplayed( entry ) ) {
533 item->setVisible( false, myInvisible );
534 myDisplayer.Erase( io );
537 item->setVisible( true, myVisible );
538 myDisplayer.Display( io );
540 myDisplayer.UpdateViewer();
541 checkVisibleIcon( item->treeWidget() );
544 //=================================================================================
545 // function : onHeaderClicked()
546 // purpose : called when header item of tree was clicked
547 //=================================================================================
548 void GEOMToolsGUI_ReduceStudyDlg::onHeaderClicked( int theColumn )
553 QTreeWidget* treeWidget = dynamic_cast<QTreeWidget*>(sender()->parent());
554 if( myMapTreeSelectAll[ treeWidget ] ) {
555 myMapTreeSelectAll[ treeWidget ] = false;
556 treeWidget->headerItem()->setIcon( 1, myInvisible );
557 QTreeWidgetItemIterator it( treeWidget );
559 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
560 if( ( item->flags() & Qt::ItemIsSelectable ) && item->isVisible() ) {
561 const char* entry = item->getStudyEntry();
562 item->setVisible( false, myInvisible );
563 myDisplayer.Erase( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) );
569 myMapTreeSelectAll[ treeWidget ] = true;
570 treeWidget->headerItem()->setIcon( 1, myVisible );
571 QTreeWidgetItemIterator it( treeWidget );
573 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
574 if( ( item->flags() & Qt::ItemIsSelectable ) && !item->isVisible() ) {
575 const char* entry = item->getStudyEntry();
576 item->setVisible( true, myVisible );
577 myDisplayer.Display( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) );
582 myDisplayer.UpdateViewer();
585 //=================================================================================
586 // function : selectionChanged()
587 // purpose : called when selection of object browser was changed
588 //=================================================================================
589 void GEOMToolsGUI_ReduceStudyDlg::selectionChanged()
591 init( getSelectedObjects() );
594 //=================================================================================
595 // function : update()
596 // purpose : update tree data
597 //=================================================================================
598 void GEOMToolsGUI_ReduceStudyDlg::update()
600 myTreeKeptObjects->clear();
601 myTreeRemoveObjects->clear();
603 std::set<std::string> keptObjects( myKeptObjects );
604 std::set<std::string> removeObjects( myRemovedObjects );
606 // Intermediate objects
607 if( myGroupIntermediates->checkedId() == 2 ) { // remove
608 std::set<std::string>::iterator iter;
609 for( iter=myListParents.begin(); iter!=myListParents.end(); ++iter)
610 removeObjects.insert( *iter );
612 else { // keep or unpublish
613 std::set<std::string>::iterator iter;
614 for( iter=myListParents.begin(); iter!=myListParents.end(); ++iter)
615 keptObjects.insert( *iter );
619 if( myGroupSubObjects->checkedId() == 2 ) {
620 std::set<std::string>::iterator iter;
621 for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter)
622 removeObjects.insert( *iter );
625 std::set<std::string>::iterator iter;
626 for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter)
627 keptObjects.insert( *iter );
630 addObjectsToTree( myTreeKeptObjects, keptObjects );
631 addObjectsToTree( myTreeRemoveObjects, removeObjects );
633 myTreeKeptObjects->collapseAll();
634 myTreeRemoveObjects->collapseAll();
638 //=================================================================================
639 // function : clickOnOk()
640 // purpose : called when OK button was clicked
641 //=================================================================================
642 void GEOMToolsGUI_ReduceStudyDlg::clickOnOk()
644 std::set<std::string> objectsToBeRemoved = myRemovedObjects;
645 std::set<std::string> objectsToBeUnpublished;
647 // Create lists of intermediate objects to be removed or to be unpublished
648 std::set<std::string>::iterator iter;
649 if( myGroupIntermediates->checkedId() == 1 ) { // unpublish
650 for( iter = myListParents.begin(); iter != myListParents.end(); ++iter )
651 objectsToBeUnpublished.insert( *iter );
653 if( myGroupIntermediates->checkedId() == 2 ) { // remove
654 if( !myCBSoftRemoval->isChecked() &&
655 SUIT_MessageBox::question( this,
656 tr( "GEOM_WRN_WARNING" ),
657 tr( "GEOM_REDUCE_STUDY_WARNING_DELETE" ),
658 QMessageBox::Yes | QMessageBox::No,
659 QMessageBox::Yes ) == QMessageBox::No ) {
662 for( iter = myListParents.begin(); iter != myListParents.end(); ++iter )
663 objectsToBeRemoved.insert( *iter );
666 // Create lists of sub-objects to be removed or to be unpublished
667 if( myGroupSubObjects->checkedId() == 1 ) { // unpublish
668 for( iter = myListSubObjects.begin(); iter != myListSubObjects.end(); ++iter )
669 objectsToBeUnpublished.insert( *iter );
671 else if( myGroupSubObjects->checkedId() == 2 ) { // remove
672 for( iter = myListSubObjects.begin(); iter != myListSubObjects.end(); ++iter )
673 objectsToBeRemoved.insert( *iter );
676 // if user chosen the soft removal
677 if( myCBSoftRemoval->isChecked() ) {
678 for( iter = objectsToBeRemoved.begin(); iter != objectsToBeRemoved.end(); ++iter )
679 objectsToBeUnpublished.insert( *iter );
680 unpublishObjects( objectsToBeUnpublished );
683 unpublishObjects( objectsToBeUnpublished );
684 removeObjects( objectsToBeRemoved );
687 // if user want to delete the empty folders
688 if( myCBRemoveEmptyFolder->isChecked() )
689 removeEmptyFolders();
694 //=================================================================================
695 // function : clickOnHelp()
696 // purpose : called when Help button was clicked to open a help page
697 //=================================================================================
698 void GEOMToolsGUI_ReduceStudyDlg::clickOnHelp()
700 myApp->onHelpContextModule( "GEOM", "reduce_study_page.html" );
703 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidget* view, const QStringList &strings,
704 char* studyEntry, int type )
705 :QTreeWidgetItem( view, strings, type ),
707 myStudyEntry( studyEntry )
711 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidgetItem* parent, const QStringList &strings,
712 char* studyEntry, int type )
713 :QTreeWidgetItem( parent, strings, type ),
715 myStudyEntry( studyEntry )
719 GEOMToolsGUI_TreeWidgetItem::~GEOMToolsGUI_TreeWidgetItem()
723 bool GEOMToolsGUI_TreeWidgetItem::isVisible()
728 void GEOMToolsGUI_TreeWidgetItem::setVisible( bool theIsVisible, QIcon& theIcon )
730 myVisible = theIsVisible;
731 setIcon( 1, theIcon );
734 char* GEOMToolsGUI_TreeWidgetItem::getStudyEntry() const