From b7bc1406d3990aecf226fa249e7a9a4269671ff2 Mon Sep 17 00:00:00 2001 From: mpa Date: Fri, 20 Jun 2014 14:19:06 +0400 Subject: [PATCH] Merge of GUI and Engine functionalities --- src/GEOMGUI/GEOM_msg_en.ts | 20 +- src/GEOMGUI/GEOM_msg_fr.ts | 20 +- src/GEOMGUI/GEOM_msg_ja.ts | 20 +- src/GEOMToolsGUI/GEOMToolsGUI_1.cxx | 6 +- .../GEOMToolsGUI_ReduceStudyDlg.cxx | 609 +++++++++++------- .../GEOMToolsGUI_ReduceStudyDlg.h | 31 +- 6 files changed, 440 insertions(+), 266 deletions(-) diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index fdd89f838..31d38cda8 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -6912,16 +6912,24 @@ Do you want to create new material? Options - GEOM_REDUCE_STUDY_UNPUB_INTERMEDIATE - Unpublish intermediate objects + GEOM_REDUCE_STUDY_INTERMEDIATES + Intermediate objects - GEOM_REDUCE_STUDY_REMOVE_INTERMEDIATE - Remove intermediate objects + GEOM_REDUCE_STUDY_SUB_OBJECTS + Sub-objects - GEOM_REDUCE_STUDY_KEEP_SUB_OBJECTS - Keep sub-objects in result + GEOM_REDUCE_STUDY_KEEP + Keep + + + GEOM_REDUCE_STUDY_UNPUBLISH + Unpublish + + + GEOM_REDUCE_STUDY_REMOVE + Remove GEOM_REDUCE_STUDY_REMOVE_EMPTY_FOLDER diff --git a/src/GEOMGUI/GEOM_msg_fr.ts b/src/GEOMGUI/GEOM_msg_fr.ts index 86867a75a..9f9c5e595 100644 --- a/src/GEOMGUI/GEOM_msg_fr.ts +++ b/src/GEOMGUI/GEOM_msg_fr.ts @@ -6912,16 +6912,24 @@ Voulez-vous en créer un nouveau ? Options - GEOM_REDUCE_STUDY_UNPUB_INTERMEDIATE - Unpublish intermediate objects + GEOM_REDUCE_STUDY_INTERMEDIATES + Intermediate objects - GEOM_REDUCE_STUDY_REMOVE_INTERMEDIATE - Remove intermediate objects + GEOM_REDUCE_STUDY_SUB_OBJECTS + Sub-objects - GEOM_REDUCE_STUDY_KEEP_SUB_OBJECTS - Keep sub-objects in result + GEOM_REDUCE_STUDY_KEEP + Keep + + + GEOM_REDUCE_STUDY_UNPUBLISH + Unpublish + + + GEOM_REDUCE_STUDY_REMOVE + Remove GEOM_REDUCE_STUDY_REMOVE_EMPTY_FOLDER diff --git a/src/GEOMGUI/GEOM_msg_ja.ts b/src/GEOMGUI/GEOM_msg_ja.ts index 01014e9f6..c38b16922 100644 --- a/src/GEOMGUI/GEOM_msg_ja.ts +++ b/src/GEOMGUI/GEOM_msg_ja.ts @@ -6721,16 +6721,24 @@ Please specify suitable arguments. Options - GEOM_REDUCE_STUDY_UNPUB_INTERMEDIATE - Unpublish intermediate objects + GEOM_REDUCE_STUDY_INTERMEDIATES + Intermediate objects - GEOM_REDUCE_STUDY_REMOVE_INTERMEDIATE - Remove intermediate objects + GEOM_REDUCE_STUDY_SUB_OBJECTS + Sub-objects - GEOM_REDUCE_STUDY_KEEP_SUB_OBJECTS - Keep sub-objects in result + GEOM_REDUCE_STUDY_KEEP + Keep + + + GEOM_REDUCE_STUDY_UNPUBLISH + Unpublish + + + GEOM_REDUCE_STUDY_REMOVE + Remove GEOM_REDUCE_STUDY_REMOVE_EMPTY_FOLDER diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index bf91fef8d..f160407ff 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -921,6 +921,8 @@ void GEOMToolsGUI::OnReduceStudy() QString entry = geomObject->GetEntry(); objectsEntry[ iter ] = entry.toLatin1().constData(); } - GEOMToolsGUI_ReduceStudyDlg dlg( objectsEntry, SUIT_Session::session()->activeApplication()->desktop() ); - dlg.exec(); + QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( objectsEntry, SUIT_Session::session()->activeApplication()->desktop() ); + if ( dlg != NULL ) + dlg->show(); + } diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_ReduceStudyDlg.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_ReduceStudyDlg.cxx index 621d16ce6..5b5529ff7 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_ReduceStudyDlg.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_ReduceStudyDlg.cxx @@ -25,175 +25,87 @@ #include #include #include +#include + // GUI includes #include #include +#include #include #include #include +#include +#include // GEOM includes #include #include CORBA_CLIENT_HEADER(GEOM_Gen) #include -#include - -GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidget* view, const QStringList &strings, - char* studyEntry, bool visible, int type ) -:QTreeWidgetItem( view, strings, type ), - myStudyEntry( studyEntry ), - myVisible( visible ) -{ - -} - -GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidgetItem* parent, const QStringList &strings, - char* studyEntry, bool visible, int type ) -:QTreeWidgetItem( parent, strings, type ), - myStudyEntry( studyEntry ), - myVisible( visible ) -{ - -} - -GEOMToolsGUI_TreeWidgetItem::~GEOMToolsGUI_TreeWidgetItem() -{ -} - -bool GEOMToolsGUI_TreeWidgetItem::isVisible() -{ - return myVisible; -} +#include +#include -void GEOMToolsGUI_TreeWidgetItem::setVisible( bool theIsVisible, QIcon& theIcon ) -{ - myVisible = theIsVisible; - setIcon( 1, theIcon ); -} +// GEOM includes +#include -char* GEOMToolsGUI_TreeWidgetItem::getStudyEntry() const -{ - return myStudyEntry; -} +#include GEOMToolsGUI_ReduceStudyDlg::GEOMToolsGUI_ReduceStudyDlg( const GEOM::string_array& theObjectEntries, QWidget* parent ) :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ), -mySelectAll( false ), myDisplayer(NULL) { - for( int i = 0; i < theObjectEntries.length(); i++ ) - myMainEntries.insert( theObjectEntries[i].in() ); - - myParents.insert( "0:1:21" ); - myParents.insert( "0:1:17" ); - myParents.insert( "0:1:20" ); - myParents.insert( "0:1:13" ); - myParents.insert( "0:1:12" ); - - mySubObjects.insert( "0:1:24" ); - mySubObjects.insert( "0:1:28" ); - mySubObjects.insert( "0:1:29" ); - mySubObjects.insert( "0:1:34" ); - - myOthers.insert( "0:1:35" ); - myOthers.insert( "0:1:36" ); - myOthers.insert( "0:1:37" ); - myOthers.insert( "0:1:38" ); - myOthers.insert( "0:1:39" ); - - std::set::iterator it; - for ( it=myParents.begin(); it!=myParents.end(); ++it) - std::cout << ' ' << *it; - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); myVisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) ); myInvisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) ) ); SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); if ( !app ) return; - SalomeApp_Study* study = dynamic_cast(app->activeStudy()); - int studyId = GeometryGUI::ClientStudyToStudy( study->studyDS())->StudyId(); - + SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); + myStudyId = GeometryGUI::ClientStudyToStudy( study->studyDS() )->StudyId(); myDisplayer = GEOM_Displayer( study ); - // setModal( true ); setWindowTitle( tr( "GEOM_REDUCE_STUDY_TITLE" ) ); - setSizeGripEnabled( TRUE ); QGridLayout* topLayout = new QGridLayout( this ); topLayout->setMargin( 11 ); topLayout->setSpacing( 6 ); + /********************** Objects to be kept **********************/ QGroupBox* groupKeptObjects = new QGroupBox( tr( "GEOM_REDUCE_STUDY_KEPT_OBJECTS" ) ); - - if(true) { - myTreeKeptObjects = new QTreeWidget(); - myTreeKeptObjects->setColumnCount( 2 ); - myTreeKeptObjects->setAllColumnsShowFocus(true); - QStringList columnNames; - columnNames.append(tr( "GEOM_REDUCE_STUDY_NAME" )); - columnNames.append(""); - myTreeKeptObjects->setHeaderLabels( columnNames ); - QTreeWidgetItem * headerItem = new QTreeWidgetItem( columnNames ); - myTreeKeptObjects->setHeaderItem ( headerItem ); - myTreeKeptObjects->header()->moveSection( 1, 0 ); - myTreeKeptObjects->header()->setClickable( true ); - myTreeKeptObjects->header()->setMovable( false ); - myTreeKeptObjects->header()->setResizeMode( 1, QHeaderView::ResizeToContents ); - myTreeKeptObjects->setSelectionMode( QAbstractItemView::ExtendedSelection ); - - } - -// myTreeWidget->header()->setSortIndicatorShown( true ); -// myTreeWidget->header()->moveSection( 2, 0 ); -// myTreeWidget->setSortingEnabled( true ); -// myTreeWidget->setColumnWidth( 2, VISIBILITY_COLUMN_WIDTH ); - - QLayout* layoutKeptObjects = new QGridLayout( groupKeptObjects ); + QGridLayout* layoutKeptObjects = new QGridLayout( groupKeptObjects ); + createTreeWidget( myTreeKeptObjects = new QTreeWidget() ); layoutKeptObjects->addWidget( myTreeKeptObjects ); + /********************** Objects to be removed **********************/ QGroupBox* groupRemoveObjects = new QGroupBox( tr( "GEOM_REDUCE_STUDY_REMOVE_OBJECTS" ) ); - - if(true) { - myTreeRemoveObjects = new QTreeWidget(); - myTreeRemoveObjects->setColumnCount( 2 ); - myTreeRemoveObjects->setAllColumnsShowFocus(true); - QStringList columnNames; - columnNames.append(tr( "GEOM_REDUCE_STUDY_NAME" )); - columnNames.append(""); - myTreeRemoveObjects->setHeaderLabels( columnNames ); - QTreeWidgetItem* headerItem = new QTreeWidgetItem( columnNames ); - myTreeRemoveObjects->setHeaderItem ( headerItem ); - myTreeRemoveObjects->header()->moveSection( 1, 0 ); - myTreeRemoveObjects->header()->setClickable( true ); - myTreeRemoveObjects->header()->setMovable( false ); - myTreeRemoveObjects->header()->setResizeMode( 1, QHeaderView::ResizeToContents ); - myTreeRemoveObjects->setSelectionMode( QAbstractItemView::ExtendedSelection ); - } - QGridLayout* layoutRemoveObjects = new QGridLayout( groupRemoveObjects ); + createTreeWidget( myTreeRemoveObjects = new QTreeWidget() ); layoutRemoveObjects->addWidget( myTreeRemoveObjects ); + /********************** Options **********************/ QGroupBox* groupOptions = new QGroupBox( tr( "GEOM_REDUCE_STUDY_OPTIONS" ) ); + QVBoxLayout* layoutOptions = new QVBoxLayout( groupOptions ); - QGridLayout* layoutOptions = new QGridLayout( groupOptions ); + // Intermidiate objects + QGroupBox* groupIntermediates = createButtonGroup( myIntermediates = new QButtonGroup() ); + groupIntermediates->setTitle( tr( "GEOM_REDUCE_STUDY_INTERMEDIATES" ) ); - myCBUnpublishIntermediate = new QCheckBox( tr( "GEOM_REDUCE_STUDY_UNPUB_INTERMEDIATE" ) ); - myCBRemoveIntermediate = new QCheckBox( tr( "GEOM_REDUCE_STUDY_REMOVE_INTERMEDIATE" ) ); - myCBKeepSubObjects = new QCheckBox( tr( "GEOM_REDUCE_STUDY_KEEP_SUB_OBJECTS" ) ); + // Sub-objects + QGroupBox* groupSubObjects = createButtonGroup( mySubObjects = new QButtonGroup() ); + groupSubObjects->setTitle( tr( "GEOM_REDUCE_STUDY_SUB_OBJECTS" ) ); + + // Others myCBRemoveEmptyFolder = new QCheckBox( tr( "GEOM_REDUCE_STUDY_REMOVE_EMPTY_FOLDER" ) ); myCBRemoveEmptyFolder->setChecked( true ); myCBSoftRemoval = new QCheckBox( tr( "GEOM_REDUCE_STUDY_SOFT_REMOVAL" ) ); - layoutOptions->addWidget( myCBUnpublishIntermediate, 0, 0 ); - layoutOptions->addWidget( myCBRemoveIntermediate, 0, 1 ); - layoutOptions->addWidget( myCBKeepSubObjects, 1, 0, 1, 2 ); - layoutOptions->addWidget( myCBRemoveEmptyFolder, 2, 0, 1, 2 ); - layoutOptions->addWidget( myCBSoftRemoval, 3, 0, 1, 2 ); + layoutOptions->addWidget( groupIntermediates ); + layoutOptions->addWidget( groupSubObjects ); + layoutOptions->addWidget( myCBRemoveEmptyFolder ); + layoutOptions->addWidget( myCBSoftRemoval ); + /********************** Buttons **********************/ QGroupBox* groupButtons = new QGroupBox(); - QHBoxLayout* layoutButtons = new QHBoxLayout( groupButtons ); QPushButton* buttonOk = new QPushButton( tr( "GEOM_BUT_OK" ) ); @@ -210,67 +122,185 @@ myDisplayer(NULL) topLayout->addWidget( groupOptions, 1, 0, 1, 2 ); topLayout->addWidget( groupButtons, 2, 0, 1, 2 ); -// connect( myCBUnpublishIntermediate, SIGNAL( toggled( bool ) ), this, SLOT( onUnpublishIntermediate( bool ) ) ); -// connect( myCBRemoveIntermediate, SIGNAL( toggled ( bool ) ), this, SLOT( onRemoveIntermediate( bool ) ) ); -// connect( myCBKeepSubObjects, SIGNAL( toggled ( bool ) ), this, SLOT( onKeepSubObjects( bool ) ) ); -// connect( myCBRemoveEmptyFolder, SIGNAL( toggled ( bool ) ), this, SLOT( onRemoveEmptyFolder( bool ) ) ); -// connect( myCBSoftRemoval, SIGNAL( toggled ( bool ) ), this, SLOT( onSoftRemoval( bool ) ) ); + // Signals and slots connections + + connect( myTreeKeptObjects, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) ); + connect( myTreeRemoveObjects, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) ); + connect( myTreeKeptObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) ); + connect( myTreeRemoveObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) ); + + connect( myIntermediates, SIGNAL( buttonClicked( int ) ), this, SLOT( update() ) ); + connect( mySubObjects, SIGNAL( buttonClicked( int ) ), this, SLOT( update() ) ); connect( buttonOk, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) ); connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( clickOnCancel() ) ); connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) ); - connect( myTreeKeptObjects, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(onItemClicked(QTreeWidgetItem*, int)) ); - connect( myTreeRemoveObjects, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(onItemClicked(QTreeWidgetItem*, int)) ); + connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), + SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) ); - connect( myTreeKeptObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) ); - connect( myTreeRemoveObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) ); + init( theObjectEntries ); +} + +GEOMToolsGUI_ReduceStudyDlg::~GEOMToolsGUI_ReduceStudyDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +void GEOMToolsGUI_ReduceStudyDlg::init( const GEOM::string_array& theObjectEntries ) +{ + for( int i = 0; i < theObjectEntries.length(); i++ ) + myMainEntries.insert( theObjectEntries[i].in() ); + + + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + if ( !app ) return; + + SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); + SALOMEDS::Study_var myStudy = GeometryGUI::ClientStudyToStudy( study->studyDS()); - connect( myCBKeepSubObjects, SIGNAL( toggled(bool)), this, SLOT( update() ) ); - connect( myCBRemoveIntermediate, SIGNAL( toggled(bool)), this, SLOT( update() ) ); - connect( myCBUnpublishIntermediate, SIGNAL( toggled(bool) ), this, SLOT( update() ) ); + + myKeptObjects.clear(); + myParents.clear(); + myListSubObjects.clear(); + myOthers.clear(); + + GEOM::string_array_var selectedObjects = new GEOM::string_array(); + selectedObjects->length( theObjectEntries.length() ); + for( int i = 0; i < theObjectEntries.length(); i++ ) + selectedObjects[ i ] = theObjectEntries[i].in(); + + GEOM::string_array_var parentsObjects = new GEOM::string_array(); +// parentsObjects->length( 5 ); +// parentsObjects[0] = "0:1:21"; +// parentsObjects[1] = "0:1:17"; +// parentsObjects[2] = "0:1:20"; +// parentsObjects[3] = "0:1:13"; +// parentsObjects[4] = "0:1:12"; + + GEOM::string_array_var subObjects = new GEOM::string_array(); +// subObjects->length( 4 ); +// subObjects[0] = "0:1:24"; +// subObjects[1] = "0:1:28"; +// subObjects[2] = "0:1:29"; +// subObjects[3] = "0:1:34"; + + GEOM::string_array_var oters = new GEOM::string_array(); +// oters->length( 5 ); +// oters[0] = "0:1:35"; +// oters[1] = "0:1:36"; +// oters[2] = "0:1:37"; +// oters[3] = "0:1:38"; +// oters[4] = "0:1:39"; + +////// PUT ALGORITHM HERE + GeometryGUI::GetGeomGen()->GetEntriesToCleanStudy( myStudy, selectedObjects, + parentsObjects, subObjects, oters ); + + for ( int i = 0; i < selectedObjects->length(); i++ ) + myKeptObjects.insert( selectedObjects[i].in() ); + + for( int i = 0; i< parentsObjects->length(); i++ ) + myParents.insert( parentsObjects[i].in() ); + + for( int i = 0; i< subObjects->length(); i++ ) + myListSubObjects.insert( subObjects[i].in() ); + + for( int i = 0; i< oters->length(); i++ ) + myOthers.insert( oters[i].in() ); + +// myParents.insert( "0:1:21" ); +// myParents.insert( "0:1:17" ); +// myParents.insert( "0:1:20" ); +// myParents.insert( "0:1:13" ); +// myParents.insert( "0:1:12" ); +// +// myListSubObjects.insert( "0:1:24" ); +// myListSubObjects.insert( "0:1:28" ); +// myListSubObjects.insert( "0:1:29" ); +// myListSubObjects.insert( "0:1:34" ); +// +// myOthers.insert( "0:1:35" ); +// myOthers.insert( "0:1:36" ); +// myOthers.insert( "0:1:37" ); +// myOthers.insert( "0:1:38" ); +// myOthers.insert( "0:1:39" ); update(); checkVisibleIcon( myTreeKeptObjects ); checkVisibleIcon( myTreeRemoveObjects ); +} - +void GEOMToolsGUI_ReduceStudyDlg::createTreeWidget( QTreeWidget* theTreeWidget ) +{ + theTreeWidget->setColumnCount( 2 ); + QStringList columnNames; + columnNames.append(tr( "GEOM_REDUCE_STUDY_NAME" )); + columnNames.append(""); + theTreeWidget->setHeaderLabels( columnNames ); + QTreeWidgetItem * headerItem = new QTreeWidgetItem( columnNames ); + theTreeWidget->setHeaderItem ( headerItem ); + theTreeWidget->header()->moveSection( 1, 0 ); + theTreeWidget->header()->setClickable( true ); + theTreeWidget->header()->setMovable( false ); + theTreeWidget->header()->setResizeMode( 1, QHeaderView::ResizeToContents ); + theTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection ); } -GEOMToolsGUI_ReduceStudyDlg::~GEOMToolsGUI_ReduceStudyDlg() +QGroupBox* GEOMToolsGUI_ReduceStudyDlg::createButtonGroup( QButtonGroup* theButtonGroup ) { - // no need to delete child widgets, Qt does it all for us + QGroupBox* groupObjects = new QGroupBox(); + QHBoxLayout* layoutObjects = new QHBoxLayout( groupObjects ); + + QRadioButton* buttonKeep = new QRadioButton( tr( "GEOM_REDUCE_STUDY_KEEP") ); + theButtonGroup->addButton( buttonKeep, 0 ); + QRadioButton* buttonUnpublish = new QRadioButton( tr( "GEOM_REDUCE_STUDY_UNPUBLISH") ); + theButtonGroup->addButton( buttonUnpublish, 1 ); + QRadioButton* buttonRemove = new QRadioButton( tr( "GEOM_REDUCE_STUDY_REMOVE") ); + theButtonGroup->addButton( buttonRemove, 2 ); + + theButtonGroup->button( 0 )->setChecked( true ); + theButtonGroup->setExclusive( true ); + + layoutObjects->addWidget( buttonKeep ); + layoutObjects->addWidget( buttonUnpublish ); + layoutObjects->addWidget( buttonRemove ); + + return groupObjects; } void GEOMToolsGUI_ReduceStudyDlg::update() { + myTreeKeptObjects->clear(); myTreeRemoveObjects->clear(); - std::set keptObjects(myMainEntries); + std::set keptObjects(myKeptObjects); std::set removeObjects(myOthers); - if( myCBUnpublishIntermediate->isChecked() || myCBRemoveIntermediate->isChecked() ) { + // Intermediate objects + if( myIntermediates->checkedId() == 2 ) { // remove std::set::iterator iter; for( iter=myParents.begin(); iter!=myParents.end(); ++iter) removeObjects.insert( *iter ); } - else { + else { // keep or unpublish std::set::iterator iter; for( iter=myParents.begin(); iter!=myParents.end(); ++iter) keptObjects.insert( *iter ); } - if( myCBKeepSubObjects->isChecked() ) { + // Sub-objects + if( mySubObjects->checkedId() == 2 ) { std::set::iterator iter; - for( iter=mySubObjects.begin(); iter!=mySubObjects.end(); ++iter) - keptObjects.insert( *iter ); + for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter) + removeObjects.insert( *iter ); } else { std::set::iterator iter; - for( iter=mySubObjects.begin(); iter!=mySubObjects.end(); ++iter) - removeObjects.insert( *iter ); + for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter) + keptObjects.insert( *iter ); } std::cout<<"\n\n\n Objects to be kept: "; @@ -285,39 +315,161 @@ void GEOMToolsGUI_ReduceStudyDlg::update() std::cout << ", " << *it_remove; std::cout << std::endl; - sortObjects( myTreeKeptObjects, keptObjects ); - sortObjects( myTreeRemoveObjects, removeObjects ); + sortObjects( myTreeKeptObjects, keptObjects ); + sortObjects( myTreeRemoveObjects, removeObjects ); - myTreeKeptObjects->update(); myTreeKeptObjects->collapseAll(); - myTreeRemoveObjects->update(); myTreeRemoveObjects->collapseAll(); } -void GEOMToolsGUI_ReduceStudyDlg::onUnpublishIntermediate( bool ) +void GEOMToolsGUI_ReduceStudyDlg::selectionChanged() { + myMainEntries.clear(); + GEOM::string_array_var objectsEntry = new GEOM::string_array(); + SALOME_ListIO mainObjects; + int iter = 0; + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + if ( !app ) return; + app->selectionMgr()->selectedObjects( mainObjects ); + // create a list of selected object entry + objectsEntry->length( mainObjects.Extent() ); + for ( SALOME_ListIteratorOfListIO It( mainObjects ); It.More(); It.Next(), iter++ ) { + Handle( SALOME_InteractiveObject ) io = It.Value(); + if( !io->hasEntry() ) + continue; + GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil(); + geomObject = GEOMBase::ConvertIOinGEOMObject( io ); + QString entry = geomObject->GetEntry(); + objectsEntry[ iter ] = entry.toLatin1().constData(); + } + init(objectsEntry); } -void GEOMToolsGUI_ReduceStudyDlg::onRemoveIntermediate( bool theIsRemove ) -{ - myCBUnpublishIntermediate->setEnabled( !theIsRemove ); -} -void GEOMToolsGUI_ReduceStudyDlg::onKeepSubObjects( bool ) -{ -} -void GEOMToolsGUI_ReduceStudyDlg::onRemoveEmptyFolder( bool ) +void GEOMToolsGUI_ReduceStudyDlg::clickOnOk() { -} -void GEOMToolsGUI_ReduceStudyDlg::onSoftRemoval( bool ) -{ + std::set ObjectsToBeRemove = myOthers; + std::set ObjectsToBeUnpublish; + + if( myIntermediates->checkedId() == 2 ) { + std::set::iterator iter; + for( iter=myParents.begin(); iter!=myParents.end(); ++iter) + ObjectsToBeRemove.insert( *iter ); + } + else if( myIntermediates->checkedId() == 1 ) { + std::set::iterator iter; + for( iter=myParents.begin(); iter!=myParents.end(); ++iter) + ObjectsToBeUnpublish.insert( *iter ); + } + + if( mySubObjects->checkedId() == 2 ) { + std::set::iterator iter; + for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter) + ObjectsToBeRemove.insert( *iter ); + } + else if( mySubObjects->checkedId() == 1 ) { + std::set::iterator iter; + for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter) + ObjectsToBeUnpublish.insert( *iter ); + } + + unpublishObjects( ObjectsToBeUnpublish ); + removeObjects( ObjectsToBeRemove ); + + +// std::cout<< "\n\n REMOVE:" << std::endl; +// std::set::iterator it; +// for( it = ObjectsToBeRemove.begin(); it != ObjectsToBeRemove.end(); ++it ) +// std::cout <<" " << (*it) << std::endl; +// +// SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); +// if ( !app ) return; +// SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); +// // get currently opened views +// QList views; +// SALOME_View* view; +// ViewManagerList vmans = app->viewManagers(); +// SUIT_ViewManager* vman; +// foreach ( vman, vmans ) { +// SUIT_ViewModel* vmod = vman->getViewModel(); +// view = dynamic_cast ( vmod ); // must work for OCC and VTK views +// if ( view ) +// views.append( view ); +// } +// _PTR(Study) aStudy = study->studyDS(); + + +// _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder()); +// _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder(); +// +// for( it = ObjectsToBeRemove.begin(); it != ObjectsToBeRemove.end(); ++it ) { +// std::string objectEntry = *it; +// GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudyId, objectEntry.c_str() ); +// GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject ); +// _PTR(SObject) obj = aStudy->FindObjectID( objectEntry.c_str() ); +// +// //Remove visual properties of the object +// study->removeObjectFromAll(objectEntry.c_str()); +// +// // remove object from study +// aStudyBuilder->RemoveObjectWithChildren( obj ); +//// // remove object from use case tree +//// aUseCaseBuilder->Remove( obj ); +// +// // Erase graphical object +// QListIterator it( views ); +// while ( it.hasNext() ) +// if ( SALOME_View* view = it.next() ) +// myDisplayer.Erase( GeomObject, true, true, view); +// +// GeometryGUI::GetGeomGen()->RemoveObject( GeomBaseObject ); +// } +// +// myDisplayer.UpdateViewer(); +// GeometryGUI* aGeomGUI = dynamic_cast( app->module( "Geometry" ) ); +// aGeomGUI->updateObjBrowser(); +// app->updateActions(); //SRN: To update a Save button in the toolbar + + +// _PTR(StudyBuilder) B = aStudy->NewBuilder(); +// for( it = ObjectsToBeUnpublish.begin(); it != ObjectsToBeUnpublish.end(); ++it ) { +// std::string objectEntry = *it; +// _PTR(SObject) obj ( aStudy->FindObjectID( objectEntry ) ); +// _PTR(GenericAttribute) anAttr; +// if ( obj ) { +// _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" ); +// aDrw->SetDrawable( false ); +// myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( objectEntry.c_str(), "GEOM", "TEMP_IO" ) ); +// } // if ( obj ) +// } // iterator +// +// app->updateObjectBrowser( false ); +// app->updateActions(); +// + +// LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); +// SALOME_ListIO aSelList; +// +// for( it = ObjectsToBeUnpublish.begin(); it != ObjectsToBeUnpublish.end(); ++it ) { +// std::string objectEntry = *it; +// GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudyId, objectEntry.c_str() ); +// GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject ); +// QString studyEntry = GeomBaseObject->GetStudyEntry(); +// Handle(SALOME_InteractiveObject) tmpIO = +// new SALOME_InteractiveObject( studyEntry.toStdString().c_str(), "GEOM", "TEMP_IO"); +// aSelList.Append(tmpIO); +// +// } +// aSelMgr->clearSelected(); +// aSelMgr->setSelectedObjects(aSelList); +// GEOMToolsGUI::OnUnpublishObject(); + + accept(); + -} -void GEOMToolsGUI_ReduceStudyDlg::clickOnOk() -{ // if( myCBRemoveEmptyFolder->isChecked() ) { // // SALOME_ListIO selected; @@ -383,52 +535,26 @@ void GEOMToolsGUI_ReduceStudyDlg::clickOnOk() // } //} -void GEOMToolsGUI_ReduceStudyDlg::clickOnCancel() -{ - accept(); -} -void GEOMToolsGUI_ReduceStudyDlg::clickOnHelp() + +void GEOMToolsGUI_ReduceStudyDlg::unpublishObjects( std::set& theObjects ) { } -void GEOMToolsGUI_ReduceStudyDlg::onSelectionChanged() +void GEOMToolsGUI_ReduceStudyDlg::removeObjects( std::set& theObjects ) { - onShowOnlySelected(); + } -void GEOMToolsGUI_ReduceStudyDlg::onShowOnlySelected() + +void GEOMToolsGUI_ReduceStudyDlg::clickOnCancel() { -// SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); -// if ( !app ) return; -// -// SalomeApp_Study* appStudy = dynamic_cast( app->activeStudy() ); -// GEOM_Displayer* disp = new GEOM_Displayer( appStudy ); -// -// OCCViewer_ViewManager* anOCCVM = (OCCViewer_ViewManager*) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true ); -// -// std::cout << "\n\n\n onShowOnlySelected = " << std::endl; -// if ( SUIT_ViewModel* viewModel = anOCCVM->getViewModel() ) -// if ( SALOME_View* viewFrame = dynamic_cast( viewModel ) ) { -// disp->EraseAll( true, false, viewFrame ); -// -// std::cout << "\n\n\n EraseAll = " << std::endl; -// -// QList selected = myTreeKeptObjects->selectedItems(); -// for( int i = 0; i< selected.size(); i++ ) { -// const char* entry = myMap[selected[i]].first.c_str(); -// std::cout << "\n\n\n entry = " << QString( entry ).toStdString() << std::endl; -// const char* name = "TEMP_IO"; -// -// Handle(SALOME_InteractiveObject) tmpIO = -// new SALOME_InteractiveObject( entry, "GEOM", name ); -// -// disp->Display( tmpIO, false, viewFrame ); -// } -// viewFrame->Repaint(); -// } + close(); } +void GEOMToolsGUI_ReduceStudyDlg::clickOnHelp() +{ +} //================================================================================= // function : onItemClicked() @@ -459,44 +585,39 @@ void GEOMToolsGUI_ReduceStudyDlg::onHeaderClicked( int theColumn ) { if( theColumn != 1 ) return; + QTreeWidget* treeData = dynamic_cast(sender()->parent()); if( myMapTreeSelectAll[ treeData ] ) { - myMapTreeSelectAll[ treeData ] = false; - treeData->headerItem()->setIcon( 1, myInvisible ); + myMapTreeSelectAll[ treeData ] = false; + treeData->headerItem()->setIcon( 1, myInvisible ); QTreeWidgetItemIterator it( treeData ); while(*it) { GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast(*it); - if( item->flags() & Qt::ItemIsSelectable ) { - const char* entry = item->getStudyEntry(); - if( item->isVisible() ) { + if( ( item->flags() & Qt::ItemIsSelectable ) && item->isVisible() ) { + const char* entry = item->getStudyEntry(); item->setVisible( false, myInvisible ); myDisplayer.Erase( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) ); } - } ++it; - } } else { - myMapTreeSelectAll[ treeData ] = true; - treeData->headerItem()->setIcon( 1, myVisible ); - QTreeWidgetItemIterator it(treeData); + myMapTreeSelectAll[ treeData ] = true; + treeData->headerItem()->setIcon( 1, myVisible ); + QTreeWidgetItemIterator it( treeData ); while(*it) { - GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast(*it); - if( item->flags() & Qt::ItemIsSelectable ) { - const char* entry = item->getStudyEntry(); - if( !item->isVisible() ) { - item->setVisible( true, myVisible ); + GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast(*it); + if( ( item->flags() & Qt::ItemIsSelectable ) && !item->isVisible() ) { + const char* entry = item->getStudyEntry(); + item->setVisible( true, myVisible ); myDisplayer.Display( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) ); } - } ++it; } } myDisplayer.UpdateViewer(); } - void GEOMToolsGUI_ReduceStudyDlg::checkVisibleIcon( QTreeWidget* theWidget ) { bool isInvisible = false; @@ -522,17 +643,13 @@ void GEOMToolsGUI_ReduceStudyDlg::checkVisibleIcon( QTreeWidget* theWidget ) void GEOMToolsGUI_ReduceStudyDlg::sortObjects( QTreeWidget* theWidget, std::set& theObjects ) { - SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); - if ( !app ) return; - SalomeApp_Study* study = dynamic_cast(app->activeStudy()); - int studyId = GeometryGUI::ClientStudyToStudy( study->studyDS())->StudyId(); - std::set::iterator it; for( it = theObjects.begin(); it != theObjects.end(); ++it ) { std::string objectEntry = *it; - GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( studyId, objectEntry.c_str() ); + GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudyId, objectEntry.c_str() ); GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject ); - if( GeomObject->_is_nil() ) + QString studyEntry = GeomBaseObject->GetStudyEntry(); + if( GeomObject->_is_nil() || studyEntry.isEmpty() ) continue; addSubObject( theWidget, theObjects, GeomObject ); } @@ -540,18 +657,14 @@ void GEOMToolsGUI_ReduceStudyDlg::sortObjects( QTreeWidget* theWidget, std::set< GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::addSubObject( QTreeWidget* theWidget, std::set& theObjects, GEOM::GEOM_Object_var theObject ) { - std::cout<<"\n\n ----------------- addSubObject ---------------------" << std::endl; - std::cout <<"\nObject = " << theObject->GetName() << std::endl; GEOMToolsGUI_TreeWidgetItem* item; if( !theObject->IsMainShape() ) { GEOMToolsGUI_TreeWidgetItem* parentItem = addSubObject( theWidget, theObjects, theObject->GetMainShape() ); - std::cout <<"\nParentItem = " << parentItem->text(0).toStdString() << std::endl; item = findObjectInTree( theWidget, theObject ); if( !item ) item = new GEOMToolsGUI_TreeWidgetItem( parentItem, QStringList() << theObject->GetName(), theObject->GetStudyEntry(), false ); } else { - std::cout <<"\nParentItem = ROOT" << std::endl; item = findObjectInTree( theWidget, theObject ); if( !item ) item = new GEOMToolsGUI_TreeWidgetItem( theWidget, QStringList() << theObject->GetName(), theObject->GetStudyEntry(), false ); @@ -559,7 +672,6 @@ GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::addSubObject( QTreeWid bool isDisplayed = false; if( theObjects.find( theObject->GetEntry() ) != theObjects.end() ) { - std::cout << "\n FOUND " << std::endl; isDisplayed = myDisplayer.IsDisplayed( theObject->GetStudyEntry() ); if ( isDisplayed ) { item->setVisible( true, myVisible ); @@ -575,26 +687,59 @@ GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::addSubObject( QTreeWid } else { - std::cout << "\n NOT FOUND " << std::endl; item->setFlags( item->flags() & ~Qt::ItemIsSelectable ); item->setTextColor( 0, QColor( 150, 150, 150 ) ); } - std::cout<<"\n\n ----------------- FINISH addSubObject ---------------------" << std::endl; return item; } GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::findObjectInTree( QTreeWidget* theWidget, GEOM::GEOM_Object_var theObject ) { QTreeWidgetItemIterator it( theWidget ); - std::cout <<"\n\n\n theObject->GetStudyEntry() = " << theObject->GetStudyEntry() << std::endl; while(*it) { GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast(*it); - std::cout <<"\n\n\n item->getStudyEntry() = " << item->getStudyEntry() << std::endl; if( QString( item->getStudyEntry() ) == QString( theObject->GetStudyEntry() ) ) return item; ++it; } - std::cout <<"\n\n\n RETURN NULL " << std::endl; return NULL; } + +GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidget* view, const QStringList &strings, + char* studyEntry, bool visible, int type ) +:QTreeWidgetItem( view, strings, type ), + myStudyEntry( studyEntry ), + myVisible( visible ) +{ + +} + +GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidgetItem* parent, const QStringList &strings, + char* studyEntry, bool visible, int type ) +:QTreeWidgetItem( parent, strings, type ), + myStudyEntry( studyEntry ), + myVisible( visible ) +{ + +} + +GEOMToolsGUI_TreeWidgetItem::~GEOMToolsGUI_TreeWidgetItem() +{ +} + +bool GEOMToolsGUI_TreeWidgetItem::isVisible() +{ + return myVisible; +} + +void GEOMToolsGUI_TreeWidgetItem::setVisible( bool theIsVisible, QIcon& theIcon ) +{ + myVisible = theIsVisible; + setIcon( 1, theIcon ); +} + +char* GEOMToolsGUI_TreeWidgetItem::getStudyEntry() const +{ + return myStudyEntry; +} diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_ReduceStudyDlg.h b/src/GEOMToolsGUI/GEOMToolsGUI_ReduceStudyDlg.h index e477e4605..6f0c0c85b 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_ReduceStudyDlg.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI_ReduceStudyDlg.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include @@ -33,6 +35,7 @@ class GEOMToolsGUI_TreeWidgetItem : public QTreeWidgetItem { + public: GEOMToolsGUI_TreeWidgetItem( QTreeWidget*, const QStringList&, char*, bool, int = Type ); GEOMToolsGUI_TreeWidgetItem( QTreeWidgetItem*, const QStringList&, char*, bool, int = Type ); @@ -58,36 +61,36 @@ public: private slots: - void onUnpublishIntermediate( bool ); - void onRemoveIntermediate( bool ); - void onKeepSubObjects( bool ); - void onRemoveEmptyFolder( bool ); - void onSoftRemoval( bool ); - void clickOnOk(); void clickOnCancel(); void clickOnHelp(); - void onSelectionChanged(); void onItemClicked(QTreeWidgetItem*, int ); void onHeaderClicked( int ); + void selectionChanged(); + void update(); private: - void onShowOnlySelected(); + void init( const GEOM::string_array& theObjectEntries ); + void createTreeWidget( QTreeWidget* ); + QGroupBox* createButtonGroup( QButtonGroup* ); void checkVisibleIcon( QTreeWidget* ); void sortObjects( QTreeWidget*, std::set& ); GEOMToolsGUI_TreeWidgetItem* addSubObject( QTreeWidget*, std::set&, GEOM::GEOM_Object_var ); GEOMToolsGUI_TreeWidgetItem* findObjectInTree( QTreeWidget*, GEOM::GEOM_Object_var ); + void unpublishObjects( std::set& ); + void removeObjects( std::set& ); + QTreeWidget* myTreeKeptObjects; QTreeWidget* myTreeRemoveObjects; - QCheckBox* myCBUnpublishIntermediate; - QCheckBox* myCBRemoveIntermediate; - QCheckBox* myCBKeepSubObjects; + QButtonGroup* myIntermediates; + QButtonGroup* mySubObjects; + QCheckBox* myCBRemoveEmptyFolder; QCheckBox* myCBSoftRemoval; @@ -96,12 +99,12 @@ private: QIcon myVisible; QIcon myInvisible; - bool mySelectAll; - GEOM_Displayer myDisplayer; + int myStudyId; + std::set myKeptObjects; std::set myParents; - std::set mySubObjects; + std::set myListSubObjects; std::set myOthers; std::map myMapTreeSelectAll; -- 2.39.2