1 // Copyright (C) 2014-2015 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 ),
48 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
49 myVisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) );
50 myInvisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) ) );
52 myApp = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
54 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
55 myStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() )->studyDS();
56 myDisplayer = GEOM_Displayer( study );
58 setWindowTitle( tr( "GEOM_REDUCE_STUDY_TITLE" ) );
59 setAttribute(Qt::WA_DeleteOnClose);
61 QGridLayout* topLayout = new QGridLayout( this );
62 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
64 /********************** Objects to be kept **********************/
65 QGroupBox* groupKeptObjects = new QGroupBox( tr( "GEOM_REDUCE_STUDY_KEPT_OBJECTS" ) );
66 QGridLayout* layoutKeptObjects = new QGridLayout( groupKeptObjects );
67 createTreeWidget( myTreeKeptObjects = new QTreeWidget() );
68 layoutKeptObjects->addWidget( myTreeKeptObjects );
70 /********************** Objects to be removed **********************/
71 QGroupBox* groupRemoveObjects = new QGroupBox( tr( "GEOM_REDUCE_STUDY_REMOVE_OBJECTS" ) );
72 QGridLayout* layoutRemoveObjects = new QGridLayout( groupRemoveObjects );
73 createTreeWidget( myTreeRemoveObjects = new QTreeWidget() );
74 layoutRemoveObjects->addWidget( myTreeRemoveObjects );
76 /********************** Options **********************/
77 QGroupBox* groupOptions = new QGroupBox( tr( "GEOM_REDUCE_STUDY_OPTIONS" ) );
78 QVBoxLayout* layoutOptions = new QVBoxLayout( groupOptions );
80 // Intermediate objects
81 QGroupBox* groupIntermediates = createButtonGroup( myGroupIntermediates = new QButtonGroup() );
82 groupIntermediates->setTitle( tr( "GEOM_REDUCE_STUDY_INTERMEDIATES" ) );
85 QGroupBox* groupSubObjects = createButtonGroup( myGroupSubObjects = new QButtonGroup() );
86 groupSubObjects->setTitle( tr( "GEOM_REDUCE_STUDY_SUB_OBJECTS" ) );
89 myCBRemoveEmptyFolder = new QCheckBox( tr( "GEOM_REDUCE_STUDY_REMOVE_EMPTY_FOLDER" ) );
90 myCBRemoveEmptyFolder->setChecked( true );
91 myCBSoftRemoval = new QCheckBox( tr( "GEOM_REDUCE_STUDY_SOFT_REMOVAL" ) );
93 layoutOptions->addWidget( groupIntermediates );
94 layoutOptions->addWidget( groupSubObjects );
95 layoutOptions->addWidget( myCBRemoveEmptyFolder );
96 layoutOptions->addWidget( myCBSoftRemoval );
98 /********************** Buttons **********************/
99 QGroupBox* groupButtons = new QGroupBox();
100 QHBoxLayout* layoutButtons = new QHBoxLayout( groupButtons );
102 QPushButton* buttonOk = new QPushButton( tr( "GEOM_BUT_OK" ) );
103 QPushButton* buttonCancel = new QPushButton( tr( "GEOM_BUT_CANCEL" ) );
104 QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ) );
106 layoutButtons->addWidget( buttonOk );
107 layoutButtons->addStretch();
108 layoutButtons->addWidget( buttonCancel );
109 layoutButtons->addWidget( buttonHelp );
111 topLayout->addWidget( groupKeptObjects, 0, 0 );
112 topLayout->addWidget( groupRemoveObjects, 0, 1 );
113 topLayout->addWidget( groupOptions, 1, 0, 1, 2 );
114 topLayout->addWidget( groupButtons, 2, 0, 1, 2 );
116 // Signals and slots connections
118 connect( myTreeKeptObjects, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
119 connect( myTreeRemoveObjects, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
120 connect( myTreeKeptObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) );
121 connect( myTreeRemoveObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) );
123 connect( myGroupIntermediates, SIGNAL( buttonClicked( int ) ), this, SLOT( update() ) );
124 connect( myGroupSubObjects, SIGNAL( buttonClicked( int ) ), this, SLOT( update() ) );
126 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
127 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
128 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) );
130 connect( myApp->selectionMgr(), SIGNAL( currentSelectionChanged() ),
131 this, SLOT( selectionChanged() ) );
133 init( getSelectedObjects() );
136 GEOMToolsGUI_ReduceStudyDlg::~GEOMToolsGUI_ReduceStudyDlg()
138 // no need to delete child widgets, Qt does it all for us
141 //=================================================================================
143 // purpose : initialize dialog data
144 //=================================================================================
145 void GEOMToolsGUI_ReduceStudyDlg::init( const std::set<std::string>& theObjectEntries )
147 myMainEntries.clear();
149 myKeptObjects.clear();
150 myListParents.clear();
151 myListSubObjects.clear();
152 myRemovedObjects.clear();
154 myMainEntries = theObjectEntries;
156 GEOM::string_array_var keptObjects = new GEOM::string_array();
158 keptObjects->length( theObjectEntries.size() );
159 std::set<std::string>::iterator iter;
160 for( iter=theObjectEntries.begin(); iter!=theObjectEntries.end(); ++iter, It++ )
161 keptObjects[ It ] = (*iter).c_str();
163 GEOM::string_array_var parentsObjects = new GEOM::string_array();
164 GEOM::string_array_var subObjects = new GEOM::string_array();
165 GEOM::string_array_var otherObjects = new GEOM::string_array();
167 GeometryGUI::GetGeomGen()->GetEntriesToReduceStudy( GeometryGUI::ClientStudyToStudy( myStudy ),
168 keptObjects, parentsObjects,
169 subObjects, otherObjects );
171 for ( int i = 0; i < keptObjects->length(); i++ )
172 myKeptObjects.insert( keptObjects[i].in() );
173 for( int i = 0; i< otherObjects->length(); i++ )
174 myRemovedObjects.insert( otherObjects[i].in() );
175 for( int i = 0; i< parentsObjects->length(); i++ )
176 myListParents.insert( parentsObjects[i].in() );
177 for( int i = 0; i< subObjects->length(); i++ )
178 myListSubObjects.insert( subObjects[i].in() );
182 checkVisibleIcon( myTreeKeptObjects );
183 checkVisibleIcon( myTreeRemoveObjects );
186 //=================================================================================
187 // function : getSelectedObjects()
188 // purpose : get selected objects in object browser
189 //=================================================================================
190 std::set<std::string> GEOMToolsGUI_ReduceStudyDlg::getSelectedObjects() const
192 std::set<std::string> objects;
194 SALOME_ListIO selected;
195 myApp->selectionMgr()->selectedObjects( selected );
197 for( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
198 Handle( SALOME_InteractiveObject ) io = It.Value();
199 if( !io->hasEntry() )
201 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil();
202 geomObject = GEOMBase::ConvertIOinGEOMObject( io );
203 if( geomObject->_is_nil() )
205 QString entry = geomObject->GetEntry();
206 objects.insert( entry.toStdString().c_str() );
211 //=================================================================================
212 // function : createTreeWidget()
213 // purpose : create tree widget for unpublished or removed objects
214 //=================================================================================
215 void GEOMToolsGUI_ReduceStudyDlg::createTreeWidget( QTreeWidget* theTreeWidget )
217 theTreeWidget->setColumnCount( 2 );
218 QStringList columnNames;
219 columnNames.append(tr( "GEOM_REDUCE_STUDY_NAME" ));
220 columnNames.append("");
221 theTreeWidget->setHeaderLabels( columnNames );
222 QTreeWidgetItem * headerItem = new QTreeWidgetItem( columnNames );
223 theTreeWidget->setHeaderItem ( headerItem );
224 theTreeWidget->header()->moveSection( 1, 0 );
225 theTreeWidget->header()->setClickable( true );
226 theTreeWidget->header()->setMovable( false );
227 theTreeWidget->header()->setResizeMode( 1, QHeaderView::ResizeToContents );
228 theTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
231 //=================================================================================
232 // function : createButtonGroup()
233 // purpose : create button group for intermediate objects or sub-objects
234 //=================================================================================
235 QGroupBox* GEOMToolsGUI_ReduceStudyDlg::createButtonGroup( QButtonGroup* theButtonGroup )
237 QGroupBox* groupObjects = new QGroupBox();
238 QHBoxLayout* layoutObjects = new QHBoxLayout( groupObjects );
240 QRadioButton* buttonKeep = new QRadioButton( tr( "GEOM_REDUCE_STUDY_KEEP") );
241 theButtonGroup->addButton( buttonKeep, 0 );
242 QRadioButton* buttonUnpublish = new QRadioButton( tr( "GEOM_REDUCE_STUDY_UNPUBLISH") );
243 theButtonGroup->addButton( buttonUnpublish, 1 );
244 QRadioButton* buttonRemove = new QRadioButton( tr( "GEOM_REDUCE_STUDY_REMOVE") );
245 theButtonGroup->addButton( buttonRemove, 2 );
247 theButtonGroup->button( 0 )->setChecked( true );
248 theButtonGroup->setExclusive( true );
250 layoutObjects->addWidget( buttonKeep );
251 layoutObjects->addWidget( buttonUnpublish );
252 layoutObjects->addWidget( buttonRemove );
257 //=================================================================================
258 // function : addObjectsToTree()
259 // purpose : add the list of objects to tree
260 //=================================================================================
261 void GEOMToolsGUI_ReduceStudyDlg::addObjectsToTree( QTreeWidget* theWidget, std::set<std::string>& theObjects )
263 std::set<std::string>::iterator it;
264 for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
265 std::string objectEntry = *it;
266 GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudy->StudyId(), objectEntry.c_str() );
267 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
268 QString studyEntry = GeomBaseObject->GetStudyEntry();
269 if( GeomObject->_is_nil() || studyEntry.isEmpty() || !isObjectDrawable( studyEntry.toStdString() ) )
271 addSubObject( theWidget, theObjects, GeomObject );
275 //=================================================================================
276 // function : addSubObject()
277 // purpose : add sub-object to parent object in the tree
278 //=================================================================================
279 GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::addSubObject( QTreeWidget* theWidget,
280 std::set<std::string>& theObjects,
281 GEOM::GEOM_Object_var theObject )
283 GEOMToolsGUI_TreeWidgetItem* item;
284 if( !theObject->IsMainShape() ) {
285 GEOMToolsGUI_TreeWidgetItem* parentItem = addSubObject( theWidget, theObjects, theObject->GetMainShape() );
286 item = findObjectInTree( theWidget, theObject );
288 item = new GEOMToolsGUI_TreeWidgetItem( parentItem, QStringList() << theObject->GetName(), theObject->GetStudyEntry() );
291 item = findObjectInTree( theWidget, theObject );
293 item = new GEOMToolsGUI_TreeWidgetItem( theWidget, QStringList() << theObject->GetName(), theObject->GetStudyEntry() );
296 bool isDisplayed = false;
297 if( theObjects.find( theObject->GetEntry() ) != theObjects.end() ) {
298 isDisplayed = myDisplayer.IsDisplayed( theObject->GetStudyEntry() );
300 item->setVisible( true, myVisible );
302 item->setVisible( false, myInvisible );
304 if( myMainEntries.find( theObject->GetEntry() ) != myMainEntries.end() ) {
305 QFont Textfont = item->font(0);
306 Textfont.setBold( true );
307 item->setFont( 0, Textfont );
311 item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
312 item->setTextColor( 0, QColor( 150, 150, 150 ) );
317 //=================================================================================
318 // function : findObjectInTree()
319 // purpose : find object in the tree
320 //=================================================================================
321 GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::findObjectInTree( QTreeWidget* theWidget, GEOM::GEOM_Object_var theObject )
323 QTreeWidgetItemIterator it( theWidget );
325 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
326 if( QString( item->getStudyEntry() ) == QString( theObject->GetStudyEntry() ) )
333 //=================================================================================
334 // function : checkVisibleIcon()
335 // purpose : set visible or invisible icon in the header of tree
336 //=================================================================================
337 void GEOMToolsGUI_ReduceStudyDlg::checkVisibleIcon( QTreeWidget* theWidget )
339 bool isInvisible = false;
340 QTreeWidgetItemIterator it( theWidget );
342 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
343 const char* entry = item->getStudyEntry();
344 if( item->flags() & Qt::ItemIsSelectable )
345 if( !item->isVisible() )
351 theWidget->headerItem()->setIcon( 1, myInvisible );
352 myMapTreeSelectAll[ theWidget ] = false;
355 theWidget->headerItem()->setIcon( 1, myVisible );
356 myMapTreeSelectAll[ theWidget ] = true;
360 //=================================================================================
361 // function : isObjectDrawable()
362 // purpose : return true if object is drawable, and false if object is hidden in the study
363 //=================================================================================
364 bool GEOMToolsGUI_ReduceStudyDlg::isObjectDrawable( std::string theStudyEntry )
366 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
367 //If object hasn't "AttributeDrawable" => it visible
368 bool isDrawable = true;
369 _PTR(SObject) SO ( myStudy->FindObjectID( theStudyEntry ) );
370 _PTR(GenericAttribute) anAttr;
371 if ( SO && SO->FindAttribute( anAttr, "AttributeDrawable" ) ) {
372 _PTR(AttributeDrawable) aDrw (anAttr);
373 isDrawable = aDrw->IsDrawable();
378 //=================================================================================
379 // function : unpublishObjects()
380 // purpose : unpublish(hide) objects in the study
381 //=================================================================================
382 void GEOMToolsGUI_ReduceStudyDlg::unpublishObjects( std::set<std::string>& theObjects )
384 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
385 std::set<std::string>::iterator it;
386 for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
387 std::string objectEntry = *it;
388 GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudy->StudyId(),
389 objectEntry.c_str() );
390 std::string studyEntry = GeomBaseObject->GetStudyEntry();
391 if ( studyEntry == "" || !isObjectDrawable( studyEntry ) )
393 _PTR(SObject) obj ( myStudy->FindObjectID( studyEntry.c_str() ) );
394 _PTR(GenericAttribute) anAttr;
396 _PTR(AttributeDrawable) aDrw = aStudyBuilder->FindOrCreateAttribute( obj, "AttributeDrawable" );
397 aDrw->SetDrawable( false );
398 myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( studyEntry.c_str(), "GEOM", "TEMP_IO" ) );
399 // hide references if any
400 std::vector< _PTR(SObject) > vso = myStudy->FindDependances(obj);
401 for ( int i = 0; i < vso.size(); i++ ) {
402 _PTR(SObject) refObj = vso[i];
403 aDrw = aStudyBuilder->FindOrCreateAttribute( refObj, "AttributeDrawable" );
404 aDrw->SetDrawable( false );
408 myApp->updateObjectBrowser( false );
409 myApp->updateActions();
412 //=================================================================================
413 // function : removeObjects()
414 // purpose : remove objects from the study
415 //=================================================================================
416 void GEOMToolsGUI_ReduceStudyDlg::removeObjects( std::set<std::string>& theObjects )
418 std::set<std::string>::iterator it;
419 for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
420 std::string objectEntry = *it;
421 GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudy->StudyId(),
422 objectEntry.c_str() );
423 std::string studyEntry = GeomBaseObject->GetStudyEntry();
424 if ( studyEntry == "" )
425 GeometryGUI::GetGeomGen()->RemoveObject( GeomBaseObject );
427 if( !isObjectDrawable( studyEntry ) )
429 removeObject( studyEntry );
432 myApp->updateObjectBrowser( false );
433 myApp->updateActions();
436 //=================================================================================
437 // function : removeObject()
438 // purpose : remove object with given study entry
439 //=================================================================================
440 void GEOMToolsGUI_ReduceStudyDlg::removeObject( std::string& theStudyEntry )
442 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
443 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
444 _PTR(UseCaseBuilder) aUseCaseBuilder = myStudy->GetUseCaseBuilder();
446 _PTR(SObject) obj ( myStudy->FindObjectID( theStudyEntry.c_str() ) );
448 // remove visual properties of the object
449 appStudy->removeObjectProperties(obj->GetID().c_str());
450 // remove references to this object
451 appStudy->deleteReferencesTo( obj );
452 // remove objects from study
453 aStudyBuilder->RemoveObjectWithChildren( obj );
454 // remove object from use case tree
455 aUseCaseBuilder->Remove( obj );
456 myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( theStudyEntry.c_str(), "GEOM", "TEMP_IO" ) );
460 //=================================================================================
461 // function : removeEmptyFolders()
462 // purpose : remove empty folders from the study
463 //=================================================================================
464 void GEOMToolsGUI_ReduceStudyDlg::removeEmptyFolders()
466 std::set<std::string> emptyFolders;
468 _PTR(SComponent) SC ( myStudy->FindComponent( "GEOM" ) );
471 _PTR(ChildIterator) anIter ( myStudy->NewChildIterator( SC ) );
472 anIter->InitEx( true );
473 while( anIter->More() ) {
474 _PTR(SObject) valSO ( anIter->Value() );
476 if ( !valSO->ReferencedObject( refSO ) )
477 getEmptyFolders( valSO, emptyFolders );
481 std::set<std::string>::iterator iter;
482 for( iter = emptyFolders.begin(); iter != emptyFolders.end(); ++iter ) {
483 std::string studyEntry = *iter;
484 removeObject( studyEntry );
486 myApp->updateObjectBrowser( false );
487 myApp->updateActions();
490 //=================================================================================
491 // function : removeEmptyFolders()
492 // purpose : remove empty folders from the study
493 //=================================================================================
494 void GEOMToolsGUI_ReduceStudyDlg::getEmptyFolders( _PTR(SObject) theSO, std::set<std::string>& theFolders )
496 _PTR(UseCaseBuilder) aUseCaseBuilder = myStudy->GetUseCaseBuilder();
498 bool isFolder = false;
499 _PTR(GenericAttribute) anAttr;
500 if ( theSO->FindAttribute(anAttr, "AttributeLocalID") ) {
501 _PTR(AttributeLocalID) aLocalID( anAttr );
502 isFolder = aLocalID->Value() == 999;
504 QString studyEntry = theSO->GetID().c_str();
506 if( !aUseCaseBuilder->HasChildren( theSO ) )
507 theFolders.insert( studyEntry.toStdString() );
509 _PTR(UseCaseIterator) ucit ( aUseCaseBuilder->GetUseCaseIterator( theSO ) );
510 for ( ucit->Init( false ); ucit->More(); ucit->Next() )
511 getEmptyFolders( ucit->Value(), theFolders );
516 //=================================================================================
517 // function : onItemClicked()
518 // purpose : called when tree item was clicked
519 //=================================================================================
520 void GEOMToolsGUI_ReduceStudyDlg::onItemClicked( QTreeWidgetItem* theItem, int theColumn )
522 if( theColumn != 1 || !( theItem->flags() & Qt::ItemIsSelectable ) )
525 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>( theItem );
527 const char* entry = item->getStudyEntry();
528 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" );
529 if( myDisplayer.IsDisplayed( entry ) ) {
530 item->setVisible( false, myInvisible );
531 myDisplayer.Erase( io );
534 item->setVisible( true, myVisible );
535 myDisplayer.Display( io );
537 myDisplayer.UpdateViewer();
538 checkVisibleIcon( item->treeWidget() );
541 //=================================================================================
542 // function : onHeaderClicked()
543 // purpose : called when header item of tree was clicked
544 //=================================================================================
545 void GEOMToolsGUI_ReduceStudyDlg::onHeaderClicked( int theColumn )
550 QTreeWidget* treeWidget = dynamic_cast<QTreeWidget*>(sender()->parent());
551 if( myMapTreeSelectAll[ treeWidget ] ) {
552 myMapTreeSelectAll[ treeWidget ] = false;
553 treeWidget->headerItem()->setIcon( 1, myInvisible );
554 QTreeWidgetItemIterator it( treeWidget );
556 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
557 if( ( item->flags() & Qt::ItemIsSelectable ) && item->isVisible() ) {
558 const char* entry = item->getStudyEntry();
559 item->setVisible( false, myInvisible );
560 myDisplayer.Erase( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) );
566 myMapTreeSelectAll[ treeWidget ] = true;
567 treeWidget->headerItem()->setIcon( 1, myVisible );
568 QTreeWidgetItemIterator it( treeWidget );
570 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
571 if( ( item->flags() & Qt::ItemIsSelectable ) && !item->isVisible() ) {
572 const char* entry = item->getStudyEntry();
573 item->setVisible( true, myVisible );
574 myDisplayer.Display( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) );
579 myDisplayer.UpdateViewer();
582 //=================================================================================
583 // function : selectionChanged()
584 // purpose : called when selection of object browser was changed
585 //=================================================================================
586 void GEOMToolsGUI_ReduceStudyDlg::selectionChanged()
588 init( getSelectedObjects() );
591 //=================================================================================
592 // function : update()
593 // purpose : update tree data
594 //=================================================================================
595 void GEOMToolsGUI_ReduceStudyDlg::update()
597 myTreeKeptObjects->clear();
598 myTreeRemoveObjects->clear();
600 std::set<std::string> keptObjects( myKeptObjects );
601 std::set<std::string> removeObjects( myRemovedObjects );
603 // Intermediate objects
604 if( myGroupIntermediates->checkedId() == 2 ) { // remove
605 std::set<std::string>::iterator iter;
606 for( iter=myListParents.begin(); iter!=myListParents.end(); ++iter)
607 removeObjects.insert( *iter );
609 else { // keep or unpublish
610 std::set<std::string>::iterator iter;
611 for( iter=myListParents.begin(); iter!=myListParents.end(); ++iter)
612 keptObjects.insert( *iter );
616 if( myGroupSubObjects->checkedId() == 2 ) {
617 std::set<std::string>::iterator iter;
618 for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter)
619 removeObjects.insert( *iter );
622 std::set<std::string>::iterator iter;
623 for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter)
624 keptObjects.insert( *iter );
627 addObjectsToTree( myTreeKeptObjects, keptObjects );
628 addObjectsToTree( myTreeRemoveObjects, removeObjects );
630 myTreeKeptObjects->collapseAll();
631 myTreeRemoveObjects->collapseAll();
635 //=================================================================================
636 // function : clickOnOk()
637 // purpose : called when OK button was clicked
638 //=================================================================================
639 void GEOMToolsGUI_ReduceStudyDlg::clickOnOk()
641 std::set<std::string> objectsToBeRemoved = myRemovedObjects;
642 std::set<std::string> objectsToBeUnpublished;
644 // Create lists of intermediate objects to be removed or to be unpublished
645 std::set<std::string>::iterator iter;
646 if( myGroupIntermediates->checkedId() == 1 ) { // unpublish
647 for( iter = myListParents.begin(); iter != myListParents.end(); ++iter )
648 objectsToBeUnpublished.insert( *iter );
650 if( myGroupIntermediates->checkedId() == 2 ) { // remove
651 if( !myCBSoftRemoval->isChecked() &&
652 SUIT_MessageBox::question( this,
653 tr( "GEOM_WRN_WARNING" ),
654 tr( "GEOM_REDUCE_STUDY_WARNING_DELETE" ),
655 QMessageBox::Yes | QMessageBox::No,
656 QMessageBox::Yes ) == QMessageBox::No ) {
659 for( iter = myListParents.begin(); iter != myListParents.end(); ++iter )
660 objectsToBeRemoved.insert( *iter );
663 // Create lists of sub-objects to be removed or to be unpublished
664 if( myGroupSubObjects->checkedId() == 1 ) { // unpublish
665 for( iter = myListSubObjects.begin(); iter != myListSubObjects.end(); ++iter )
666 objectsToBeUnpublished.insert( *iter );
668 else if( myGroupSubObjects->checkedId() == 2 ) { // remove
669 for( iter = myListSubObjects.begin(); iter != myListSubObjects.end(); ++iter )
670 objectsToBeRemoved.insert( *iter );
673 // if user chosen the soft removal
674 if( myCBSoftRemoval->isChecked() ) {
675 for( iter = objectsToBeRemoved.begin(); iter != objectsToBeRemoved.end(); ++iter )
676 objectsToBeUnpublished.insert( *iter );
677 unpublishObjects( objectsToBeUnpublished );
680 unpublishObjects( objectsToBeUnpublished );
681 removeObjects( objectsToBeRemoved );
684 // if user want to delete the empty folders
685 if( myCBRemoveEmptyFolder->isChecked() )
686 removeEmptyFolders();
691 //=================================================================================
692 // function : clickOnHelp()
693 // purpose : called when Help button was clicked to open a help page
694 //=================================================================================
695 void GEOMToolsGUI_ReduceStudyDlg::clickOnHelp()
697 myApp->onHelpContextModule( "GEOM", "reduce_study_page.html" );
700 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidget* view, const QStringList &strings,
701 char* studyEntry, int type )
702 :QTreeWidgetItem( view, strings, type ),
703 myStudyEntry( studyEntry ),
708 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidgetItem* parent, const QStringList &strings,
709 char* studyEntry, int type )
710 :QTreeWidgetItem( parent, strings, type ),
711 myStudyEntry( studyEntry ),
716 GEOMToolsGUI_TreeWidgetItem::~GEOMToolsGUI_TreeWidgetItem()
720 bool GEOMToolsGUI_TreeWidgetItem::isVisible()
725 void GEOMToolsGUI_TreeWidgetItem::setVisible( bool theIsVisible, QIcon& theIcon )
727 myVisible = theIsVisible;
728 setIcon( 1, theIcon );
731 char* GEOMToolsGUI_TreeWidgetItem::getStudyEntry() const