1 // Copyright (C) 2014-2016 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 ( int i = 0; i < keptObjects->length(); i++ )
169 myKeptObjects.insert( keptObjects[i].in() );
170 for( int i = 0; i< otherObjects->length(); i++ )
171 myRemovedObjects.insert( otherObjects[i].in() );
172 for( int i = 0; i< parentsObjects->length(); i++ )
173 myListParents.insert( parentsObjects[i].in() );
174 for( int 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 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
223 theTreeWidget->header()->setClickable( true );
224 theTreeWidget->header()->setMovable( false );
225 theTreeWidget->header()->setResizeMode( 1, QHeaderView::ResizeToContents );
227 theTreeWidget->header()->setSectionsClickable( true );
228 theTreeWidget->header()->setSectionsMovable( false );
229 theTreeWidget->header()->setSectionResizeMode( 1, QHeaderView::ResizeToContents );
231 theTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
234 //=================================================================================
235 // function : createButtonGroup()
236 // purpose : create button group for intermediate objects or sub-objects
237 //=================================================================================
238 QGroupBox* GEOMToolsGUI_ReduceStudyDlg::createButtonGroup( QButtonGroup* theButtonGroup )
240 QGroupBox* groupObjects = new QGroupBox();
241 QHBoxLayout* layoutObjects = new QHBoxLayout( groupObjects );
243 QRadioButton* buttonKeep = new QRadioButton( tr( "GEOM_REDUCE_STUDY_KEEP") );
244 theButtonGroup->addButton( buttonKeep, 0 );
245 QRadioButton* buttonUnpublish = new QRadioButton( tr( "GEOM_REDUCE_STUDY_UNPUBLISH") );
246 theButtonGroup->addButton( buttonUnpublish, 1 );
247 QRadioButton* buttonRemove = new QRadioButton( tr( "GEOM_REDUCE_STUDY_REMOVE") );
248 theButtonGroup->addButton( buttonRemove, 2 );
250 theButtonGroup->button( 0 )->setChecked( true );
251 theButtonGroup->setExclusive( true );
253 layoutObjects->addWidget( buttonKeep );
254 layoutObjects->addWidget( buttonUnpublish );
255 layoutObjects->addWidget( buttonRemove );
260 //=================================================================================
261 // function : addObjectsToTree()
262 // purpose : add the list of objects to tree
263 //=================================================================================
264 void GEOMToolsGUI_ReduceStudyDlg::addObjectsToTree( QTreeWidget* theWidget, std::set<std::string>& theObjects )
266 std::set<std::string>::iterator it;
267 for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
268 std::string objectEntry = *it;
269 GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( objectEntry.c_str() );
270 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
271 QString studyEntry = GeomBaseObject->GetStudyEntry();
272 if( GeomObject->_is_nil() || studyEntry.isEmpty() || !isObjectDrawable( studyEntry.toStdString() ) )
274 addSubObject( theWidget, theObjects, GeomObject );
278 //=================================================================================
279 // function : addSubObject()
280 // purpose : add sub-object to parent object in the tree
281 //=================================================================================
282 GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::addSubObject( QTreeWidget* theWidget,
283 std::set<std::string>& theObjects,
284 GEOM::GEOM_Object_var theObject )
286 GEOMToolsGUI_TreeWidgetItem* item;
287 if( !theObject->IsMainShape() ) {
288 GEOM::GEOM_Object_var aMainShape = theObject->GetMainShape();
289 if ( CORBA::is_nil( aMainShape ) )
291 GEOMToolsGUI_TreeWidgetItem* parentItem = addSubObject( theWidget, theObjects, aMainShape );
292 item = findObjectInTree( theWidget, theObject );
294 item = new GEOMToolsGUI_TreeWidgetItem( parentItem, QStringList() << theObject->GetName(), theObject->GetStudyEntry() );
297 item = findObjectInTree( theWidget, theObject );
299 item = new GEOMToolsGUI_TreeWidgetItem( theWidget, QStringList() << theObject->GetName(), theObject->GetStudyEntry() );
302 bool isDisplayed = false;
303 if( theObjects.find( theObject->GetEntry() ) != theObjects.end() ) {
304 isDisplayed = myDisplayer.IsDisplayed( theObject->GetStudyEntry() );
306 item->setVisible( true, myVisible );
308 item->setVisible( false, myInvisible );
310 if( myMainEntries.find( theObject->GetEntry() ) != myMainEntries.end() ) {
311 QFont Textfont = item->font(0);
312 Textfont.setBold( true );
313 item->setFont( 0, Textfont );
317 item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
318 item->setTextColor( 0, QColor( 150, 150, 150 ) );
323 //=================================================================================
324 // function : findObjectInTree()
325 // purpose : find object in the tree
326 //=================================================================================
327 GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::findObjectInTree( QTreeWidget* theWidget, GEOM::GEOM_Object_var theObject )
329 QTreeWidgetItemIterator it( theWidget );
331 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
332 if( QString( item->getStudyEntry() ) == QString( theObject->GetStudyEntry() ) )
339 //=================================================================================
340 // function : checkVisibleIcon()
341 // purpose : set visible or invisible icon in the header of tree
342 //=================================================================================
343 void GEOMToolsGUI_ReduceStudyDlg::checkVisibleIcon( QTreeWidget* theWidget )
345 bool isInvisible = false;
346 QTreeWidgetItemIterator it( theWidget );
348 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
349 //const char* entry = item->getStudyEntry();
350 if( item->flags() & Qt::ItemIsSelectable )
351 if( !item->isVisible() )
357 theWidget->headerItem()->setIcon( 1, myInvisible );
358 myMapTreeSelectAll[ theWidget ] = false;
361 theWidget->headerItem()->setIcon( 1, myVisible );
362 myMapTreeSelectAll[ theWidget ] = true;
366 //=================================================================================
367 // function : isObjectDrawable()
368 // purpose : return true if object is drawable, and false if object is hidden in the study
369 //=================================================================================
370 bool GEOMToolsGUI_ReduceStudyDlg::isObjectDrawable( std::string theStudyEntry )
372 _PTR(Study) aStudy = SalomeApp_Application::getStudy();
373 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
374 //If object hasn't "AttributeDrawable" => it visible
375 bool isDrawable = true;
376 _PTR(SObject) SO ( aStudy->FindObjectID( theStudyEntry ) );
377 _PTR(GenericAttribute) anAttr;
378 if ( SO && SO->FindAttribute( anAttr, "AttributeDrawable" ) ) {
379 _PTR(AttributeDrawable) aDrw (anAttr);
380 isDrawable = aDrw->IsDrawable();
385 //=================================================================================
386 // function : unpublishObjects()
387 // purpose : unpublish(hide) objects in the study
388 //=================================================================================
389 void GEOMToolsGUI_ReduceStudyDlg::unpublishObjects( std::set<std::string>& theObjects )
391 _PTR(Study) aStudy = SalomeApp_Application::getStudy();
392 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
393 std::set<std::string>::iterator it;
394 for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
395 std::string objectEntry = *it;
396 GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( objectEntry.c_str() );
397 std::string studyEntry = GeomBaseObject->GetStudyEntry();
398 if ( studyEntry == "" || !isObjectDrawable( studyEntry ) )
400 _PTR(SObject) obj ( aStudy->FindObjectID( studyEntry.c_str() ) );
401 _PTR(GenericAttribute) anAttr;
403 _PTR(AttributeDrawable) aDrw = aStudyBuilder->FindOrCreateAttribute( obj, "AttributeDrawable" );
404 aDrw->SetDrawable( false );
405 myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( studyEntry.c_str(), "GEOM", "TEMP_IO" ) );
406 // hide references if any
407 std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
408 for ( int i = 0; i < vso.size(); i++ ) {
409 _PTR(SObject) refObj = vso[i];
410 aDrw = aStudyBuilder->FindOrCreateAttribute( refObj, "AttributeDrawable" );
411 aDrw->SetDrawable( false );
415 myApp->updateObjectBrowser( false );
416 myApp->updateActions();
419 //=================================================================================
420 // function : removeObjects()
421 // purpose : remove objects from the study
422 //=================================================================================
423 void GEOMToolsGUI_ReduceStudyDlg::removeObjects( std::set<std::string>& theObjects )
425 std::set<std::string>::iterator it;
426 for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
427 std::string objectEntry = *it;
428 GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( objectEntry.c_str() );
429 std::string studyEntry = GeomBaseObject->GetStudyEntry();
430 if ( studyEntry == "" )
431 GeometryGUI::GetGeomGen()->RemoveObject( GeomBaseObject );
433 if( !isObjectDrawable( studyEntry ) )
435 removeObject( studyEntry );
438 myApp->updateObjectBrowser( false );
439 myApp->updateActions();
442 //=================================================================================
443 // function : removeObject()
444 // purpose : remove object with given study entry
445 //=================================================================================
446 void GEOMToolsGUI_ReduceStudyDlg::removeObject( std::string& theStudyEntry )
448 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
449 _PTR(Study) aStudy = SalomeApp_Application::getStudy();
450 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
451 _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
453 _PTR(SObject) obj ( aStudy->FindObjectID( theStudyEntry.c_str() ) );
455 // remove visual properties of the object
456 appStudy->removeObjectProperties(obj->GetID().c_str());
457 // remove references to this object
458 appStudy->deleteReferencesTo( obj );
459 // remove objects from study
460 aStudyBuilder->RemoveObjectWithChildren( obj );
461 // remove object from use case tree
462 aUseCaseBuilder->Remove( obj );
463 myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( theStudyEntry.c_str(), "GEOM", "TEMP_IO" ) );
467 //=================================================================================
468 // function : removeEmptyFolders()
469 // purpose : remove empty folders from the study
470 //=================================================================================
471 void GEOMToolsGUI_ReduceStudyDlg::removeEmptyFolders()
473 std::set<std::string> emptyFolders;
475 _PTR(Study) aStudy = SalomeApp_Application::getStudy();
476 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
479 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
480 anIter->InitEx( true );
481 while( anIter->More() ) {
482 _PTR(SObject) valSO ( anIter->Value() );
484 if ( !valSO->ReferencedObject( refSO ) )
485 getEmptyFolders( valSO, emptyFolders );
489 std::set<std::string>::iterator iter;
490 for( iter = emptyFolders.begin(); iter != emptyFolders.end(); ++iter ) {
491 std::string studyEntry = *iter;
492 removeObject( studyEntry );
494 myApp->updateObjectBrowser( false );
495 myApp->updateActions();
498 //=================================================================================
499 // function : removeEmptyFolders()
500 // purpose : remove empty folders from the study
501 //=================================================================================
502 void GEOMToolsGUI_ReduceStudyDlg::getEmptyFolders( _PTR(SObject) theSO, std::set<std::string>& theFolders )
504 _PTR(UseCaseBuilder) aUseCaseBuilder = SalomeApp_Application::getStudy()->GetUseCaseBuilder();
506 bool isFolder = false;
507 _PTR(GenericAttribute) anAttr;
508 if ( theSO->FindAttribute(anAttr, "AttributeLocalID") ) {
509 _PTR(AttributeLocalID) aLocalID( anAttr );
510 isFolder = aLocalID->Value() == 999;
512 QString studyEntry = theSO->GetID().c_str();
514 if( !aUseCaseBuilder->HasChildren( theSO ) )
515 theFolders.insert( studyEntry.toStdString() );
517 _PTR(UseCaseIterator) ucit ( aUseCaseBuilder->GetUseCaseIterator( theSO ) );
518 for ( ucit->Init( false ); ucit->More(); ucit->Next() )
519 getEmptyFolders( ucit->Value(), theFolders );
524 //=================================================================================
525 // function : onItemClicked()
526 // purpose : called when tree item was clicked
527 //=================================================================================
528 void GEOMToolsGUI_ReduceStudyDlg::onItemClicked( QTreeWidgetItem* theItem, int theColumn )
530 if( theColumn != 1 || !( theItem->flags() & Qt::ItemIsSelectable ) )
533 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>( theItem );
535 const char* entry = item->getStudyEntry();
536 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" );
537 if( myDisplayer.IsDisplayed( entry ) ) {
538 item->setVisible( false, myInvisible );
539 myDisplayer.Erase( io );
542 item->setVisible( true, myVisible );
543 myDisplayer.Display( io );
545 myDisplayer.UpdateViewer();
546 checkVisibleIcon( item->treeWidget() );
549 //=================================================================================
550 // function : onHeaderClicked()
551 // purpose : called when header item of tree was clicked
552 //=================================================================================
553 void GEOMToolsGUI_ReduceStudyDlg::onHeaderClicked( int theColumn )
558 QTreeWidget* treeWidget = dynamic_cast<QTreeWidget*>(sender()->parent());
559 if( myMapTreeSelectAll[ treeWidget ] ) {
560 myMapTreeSelectAll[ treeWidget ] = false;
561 treeWidget->headerItem()->setIcon( 1, myInvisible );
562 QTreeWidgetItemIterator it( treeWidget );
564 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
565 if( ( item->flags() & Qt::ItemIsSelectable ) && item->isVisible() ) {
566 const char* entry = item->getStudyEntry();
567 item->setVisible( false, myInvisible );
568 myDisplayer.Erase( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) );
574 myMapTreeSelectAll[ treeWidget ] = true;
575 treeWidget->headerItem()->setIcon( 1, myVisible );
576 QTreeWidgetItemIterator it( treeWidget );
578 GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
579 if( ( item->flags() & Qt::ItemIsSelectable ) && !item->isVisible() ) {
580 const char* entry = item->getStudyEntry();
581 item->setVisible( true, myVisible );
582 myDisplayer.Display( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) );
587 myDisplayer.UpdateViewer();
590 //=================================================================================
591 // function : selectionChanged()
592 // purpose : called when selection of object browser was changed
593 //=================================================================================
594 void GEOMToolsGUI_ReduceStudyDlg::selectionChanged()
596 init( getSelectedObjects() );
599 //=================================================================================
600 // function : update()
601 // purpose : update tree data
602 //=================================================================================
603 void GEOMToolsGUI_ReduceStudyDlg::update()
605 myTreeKeptObjects->clear();
606 myTreeRemoveObjects->clear();
608 std::set<std::string> keptObjects( myKeptObjects );
609 std::set<std::string> removeObjects( myRemovedObjects );
611 // Intermediate objects
612 if( myGroupIntermediates->checkedId() == 2 ) { // remove
613 std::set<std::string>::iterator iter;
614 for( iter=myListParents.begin(); iter!=myListParents.end(); ++iter)
615 removeObjects.insert( *iter );
617 else { // keep or unpublish
618 std::set<std::string>::iterator iter;
619 for( iter=myListParents.begin(); iter!=myListParents.end(); ++iter)
620 keptObjects.insert( *iter );
624 if( myGroupSubObjects->checkedId() == 2 ) {
625 std::set<std::string>::iterator iter;
626 for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter)
627 removeObjects.insert( *iter );
630 std::set<std::string>::iterator iter;
631 for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter)
632 keptObjects.insert( *iter );
635 addObjectsToTree( myTreeKeptObjects, keptObjects );
636 addObjectsToTree( myTreeRemoveObjects, removeObjects );
638 myTreeKeptObjects->collapseAll();
639 myTreeRemoveObjects->collapseAll();
643 //=================================================================================
644 // function : clickOnOk()
645 // purpose : called when OK button was clicked
646 //=================================================================================
647 void GEOMToolsGUI_ReduceStudyDlg::clickOnOk()
649 std::set<std::string> objectsToBeRemoved = myRemovedObjects;
650 std::set<std::string> objectsToBeUnpublished;
652 // Create lists of intermediate objects to be removed or to be unpublished
653 std::set<std::string>::iterator iter;
654 if( myGroupIntermediates->checkedId() == 1 ) { // unpublish
655 for( iter = myListParents.begin(); iter != myListParents.end(); ++iter )
656 objectsToBeUnpublished.insert( *iter );
658 if( myGroupIntermediates->checkedId() == 2 ) { // remove
659 if( !myCBSoftRemoval->isChecked() &&
660 SUIT_MessageBox::question( this,
661 tr( "GEOM_WRN_WARNING" ),
662 tr( "GEOM_REDUCE_STUDY_WARNING_DELETE" ),
663 QMessageBox::Yes | QMessageBox::No,
664 QMessageBox::Yes ) == QMessageBox::No ) {
667 for( iter = myListParents.begin(); iter != myListParents.end(); ++iter )
668 objectsToBeRemoved.insert( *iter );
671 // Create lists of sub-objects to be removed or to be unpublished
672 if( myGroupSubObjects->checkedId() == 1 ) { // unpublish
673 for( iter = myListSubObjects.begin(); iter != myListSubObjects.end(); ++iter )
674 objectsToBeUnpublished.insert( *iter );
676 else if( myGroupSubObjects->checkedId() == 2 ) { // remove
677 for( iter = myListSubObjects.begin(); iter != myListSubObjects.end(); ++iter )
678 objectsToBeRemoved.insert( *iter );
681 // if user chosen the soft removal
682 if( myCBSoftRemoval->isChecked() ) {
683 for( iter = objectsToBeRemoved.begin(); iter != objectsToBeRemoved.end(); ++iter )
684 objectsToBeUnpublished.insert( *iter );
685 unpublishObjects( objectsToBeUnpublished );
688 unpublishObjects( objectsToBeUnpublished );
689 removeObjects( objectsToBeRemoved );
692 // if user want to delete the empty folders
693 if( myCBRemoveEmptyFolder->isChecked() )
694 removeEmptyFolders();
699 //=================================================================================
700 // function : clickOnHelp()
701 // purpose : called when Help button was clicked to open a help page
702 //=================================================================================
703 void GEOMToolsGUI_ReduceStudyDlg::clickOnHelp()
705 myApp->onHelpContextModule( "GEOM", "reduce_study_page.html" );
708 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidget* view, const QStringList &strings,
709 char* studyEntry, int type )
710 :QTreeWidgetItem( view, strings, type ),
711 myStudyEntry( studyEntry ),
716 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidgetItem* parent, const QStringList &strings,
717 char* studyEntry, int type )
718 :QTreeWidgetItem( parent, strings, type ),
719 myStudyEntry( studyEntry ),
724 GEOMToolsGUI_TreeWidgetItem::~GEOMToolsGUI_TreeWidgetItem()
728 bool GEOMToolsGUI_TreeWidgetItem::isVisible()
733 void GEOMToolsGUI_TreeWidgetItem::setVisible( bool theIsVisible, QIcon& theIcon )
735 myVisible = theIsVisible;
736 setIcon( 1, theIcon );
739 char* GEOMToolsGUI_TreeWidgetItem::getStudyEntry() const