Salome HOME
Updated copyright comment
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_ReduceStudyDlg.cxx
index 4fa9d4efa8afe306251dc81f43500fa1453659cc..a4d819cc163984ab6f4f922c51d892e4c6fb6c33 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2014-2024  CEA, EDF, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -32,7 +32,7 @@
 
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
-#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_ListIO.hxx>
 
 // Qt includes
 #include <QGridLayout>
@@ -42,8 +42,7 @@
 #include <QMessageBox>
 
 GEOMToolsGUI_ReduceStudyDlg::GEOMToolsGUI_ReduceStudyDlg( QWidget* parent )
-:QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
-myDisplayer(NULL)
+:QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
 {
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
   myVisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) );
@@ -51,9 +50,8 @@ myDisplayer(NULL)
 
   myApp = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
   if ( !myApp ) return;
-  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
-  myStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() )->studyDS();
-  myDisplayer = GEOM_Displayer( study );
+
+  myDisplayer = GEOM_Displayer();
 
   setWindowTitle( tr( "GEOM_REDUCE_STUDY_TITLE" ) );
   setAttribute(Qt::WA_DeleteOnClose);
@@ -164,17 +162,16 @@ void GEOMToolsGUI_ReduceStudyDlg::init( const std::set<std::string>& theObjectEn
   GEOM::string_array_var subObjects = new GEOM::string_array();
   GEOM::string_array_var otherObjects = new GEOM::string_array();
 
-  GeometryGUI::GetGeomGen()->GetEntriesToReduceStudy( GeometryGUI::ClientStudyToStudy( myStudy ),
-                                                            keptObjects, parentsObjects,
-                                                            subObjects, otherObjects );
+  GeometryGUI::GetGeomGen()->GetEntriesToReduceStudy( keptObjects, parentsObjects,
+                                                             subObjects, otherObjects );
 
-  for ( int i = 0; i < keptObjects->length(); i++ )
+  for ( unsigned long i = 0; i < keptObjects->length(); i++ )
     myKeptObjects.insert( keptObjects[i].in() );
-  for( int i = 0; i< otherObjects->length(); i++ )
+  for( unsigned long i = 0; i< otherObjects->length(); i++ )
     myRemovedObjects.insert( otherObjects[i].in() );
-  for( int i = 0; i< parentsObjects->length(); i++ )
+  for( unsigned long i = 0; i< parentsObjects->length(); i++ )
     myListParents.insert( parentsObjects[i].in() );
-  for( int i = 0; i< subObjects->length(); i++ )
+  for( unsigned long i = 0; i< subObjects->length(); i++ )
     myListSubObjects.insert( subObjects[i].in() );
 
   update();
@@ -222,9 +219,10 @@ void GEOMToolsGUI_ReduceStudyDlg::createTreeWidget( QTreeWidget* theTreeWidget )
   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->header()->setSectionsClickable( true );
+  theTreeWidget->header()->setSectionsMovable( false );
+  theTreeWidget->header()->setSectionResizeMode( 1, QHeaderView::ResizeToContents );
+
   theTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
 }
 
@@ -263,7 +261,7 @@ void GEOMToolsGUI_ReduceStudyDlg::addObjectsToTree( QTreeWidget* theWidget, std:
   std::set<std::string>::iterator it;
   for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
     std::string objectEntry = *it;
-    GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudy->StudyId(), objectEntry.c_str() );
+    GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( objectEntry.c_str() );
     GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
     QString studyEntry = GeomBaseObject->GetStudyEntry();
     if( GeomObject->_is_nil() || studyEntry.isEmpty() || !isObjectDrawable( studyEntry.toStdString() ) )
@@ -282,7 +280,10 @@ GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::addSubObject( QTreeWid
 {
   GEOMToolsGUI_TreeWidgetItem* item;
   if( !theObject->IsMainShape() ) {
-    GEOMToolsGUI_TreeWidgetItem* parentItem = addSubObject( theWidget, theObjects, theObject->GetMainShape() );
+    GEOM::GEOM_Object_var aMainShape = theObject->GetMainShape();
+    if ( CORBA::is_nil( aMainShape ) )
+      return NULL;
+    GEOMToolsGUI_TreeWidgetItem* parentItem = addSubObject( theWidget, theObjects, aMainShape );
     item = findObjectInTree( theWidget, theObject );
     if( !item )
       item = new GEOMToolsGUI_TreeWidgetItem( parentItem, QStringList() << theObject->GetName(), theObject->GetStudyEntry() );
@@ -340,7 +341,7 @@ void GEOMToolsGUI_ReduceStudyDlg::checkVisibleIcon( QTreeWidget* theWidget )
   QTreeWidgetItemIterator it( theWidget );
   while(*it) {
     GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
-    const char* entry = item->getStudyEntry();
+    //const char* entry = item->getStudyEntry();
     if( item->flags() & Qt::ItemIsSelectable )
       if( !item->isVisible() )
         isInvisible = true;
@@ -363,10 +364,11 @@ void GEOMToolsGUI_ReduceStudyDlg::checkVisibleIcon( QTreeWidget* theWidget )
 //=================================================================================
 bool GEOMToolsGUI_ReduceStudyDlg::isObjectDrawable( std::string theStudyEntry )
 {
-  _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
+  _PTR(Study) aStudy = SalomeApp_Application::getStudy();
+  _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
   //If object hasn't "AttributeDrawable" => it visible
   bool isDrawable = true;
-  _PTR(SObject) SO ( myStudy->FindObjectID( theStudyEntry ) );
+  _PTR(SObject) SO ( aStudy->FindObjectID( theStudyEntry ) );
   _PTR(GenericAttribute) anAttr;
   if ( SO && SO->FindAttribute( anAttr, "AttributeDrawable" ) ) {
     _PTR(AttributeDrawable) aDrw (anAttr);
@@ -381,21 +383,28 @@ bool GEOMToolsGUI_ReduceStudyDlg::isObjectDrawable( std::string theStudyEntry )
 //=================================================================================
 void GEOMToolsGUI_ReduceStudyDlg::unpublishObjects( std::set<std::string>& theObjects )
 {
-  _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
+  _PTR(Study) aStudy = SalomeApp_Application::getStudy();
+  _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
   std::set<std::string>::iterator it;
   for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
     std::string objectEntry = *it;
-    GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudy->StudyId(),
-                                                                                     objectEntry.c_str() );
+    GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( objectEntry.c_str() );
     std::string studyEntry = GeomBaseObject->GetStudyEntry();
     if ( studyEntry == "" || !isObjectDrawable( studyEntry ) )
       continue;
-    _PTR(SObject) obj ( myStudy->FindObjectID( studyEntry.c_str() ) );
+    _PTR(SObject) obj ( aStudy->FindObjectID( studyEntry.c_str() ) );
     _PTR(GenericAttribute) anAttr;
     if ( obj ) {
       _PTR(AttributeDrawable) aDrw = aStudyBuilder->FindOrCreateAttribute( obj, "AttributeDrawable" );
       aDrw->SetDrawable( false );
       myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( studyEntry.c_str(), "GEOM", "TEMP_IO" ) );
+      // hide references if any
+      std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
+      for ( int i = 0; i < (int)vso.size(); i++ ) {
+        _PTR(SObject) refObj = vso[i];
+        aDrw = aStudyBuilder->FindOrCreateAttribute( refObj, "AttributeDrawable" );
+        aDrw->SetDrawable( false );
+      }
     }
   }
   myApp->updateObjectBrowser( false );
@@ -411,8 +420,7 @@ void GEOMToolsGUI_ReduceStudyDlg::removeObjects( std::set<std::string>& theObjec
   std::set<std::string>::iterator it;
   for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
     std::string objectEntry = *it;
-    GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudy->StudyId(),
-                                                                                     objectEntry.c_str() );
+    GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( objectEntry.c_str() );
     std::string studyEntry = GeomBaseObject->GetStudyEntry();
     if ( studyEntry == "" )
       GeometryGUI::GetGeomGen()->RemoveObject( GeomBaseObject );
@@ -433,13 +441,14 @@ void GEOMToolsGUI_ReduceStudyDlg::removeObjects( std::set<std::string>& theObjec
 void GEOMToolsGUI_ReduceStudyDlg::removeObject( std::string& theStudyEntry )
 {
   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
-  _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
-  _PTR(UseCaseBuilder) aUseCaseBuilder = myStudy->GetUseCaseBuilder();
+  _PTR(Study) aStudy = SalomeApp_Application::getStudy();
+  _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
+  _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
 
-  _PTR(SObject) obj ( myStudy->FindObjectID( theStudyEntry.c_str() ) );
+  _PTR(SObject) obj ( aStudy->FindObjectID( theStudyEntry.c_str() ) );
   if ( obj ) {
     // remove visual properties of the object
-    appStudy->removeObjectFromAll(obj->GetID().c_str());
+    appStudy->removeObjectProperties(obj->GetID().c_str());
     // remove references to this object
     appStudy->deleteReferencesTo( obj );
     // remove objects from study
@@ -458,10 +467,11 @@ void GEOMToolsGUI_ReduceStudyDlg::removeEmptyFolders()
 {
   std::set<std::string> emptyFolders;
 
-  _PTR(SComponent) SC ( myStudy->FindComponent( "GEOM" ) );
+  _PTR(Study) aStudy = SalomeApp_Application::getStudy();
+  _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
   if ( !SC )
     return;
-  _PTR(ChildIterator) anIter ( myStudy->NewChildIterator( SC ) );
+  _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
   anIter->InitEx( true );
   while( anIter->More() ) {
     _PTR(SObject) valSO ( anIter->Value() );
@@ -486,7 +496,7 @@ void GEOMToolsGUI_ReduceStudyDlg::removeEmptyFolders()
 //=================================================================================
 void GEOMToolsGUI_ReduceStudyDlg::getEmptyFolders( _PTR(SObject) theSO, std::set<std::string>& theFolders )
 {
-  _PTR(UseCaseBuilder) aUseCaseBuilder = myStudy->GetUseCaseBuilder();
+  _PTR(UseCaseBuilder) aUseCaseBuilder = SalomeApp_Application::getStudy()->GetUseCaseBuilder();
 
   bool isFolder = false;
   _PTR(GenericAttribute) anAttr;
@@ -642,11 +652,11 @@ void GEOMToolsGUI_ReduceStudyDlg::clickOnOk()
   }
   if( myGroupIntermediates->checkedId() == 2 ) { // remove
     if( !myCBSoftRemoval->isChecked() && 
-       SUIT_MessageBox::question( this,
-                                  tr( "GEOM_WRN_WARNING" ),
-                                  tr( "GEOM_REDUCE_STUDY_WARNING_DELETE" ),
-                                  QMessageBox::Yes | QMessageBox::No,
-                                  QMessageBox::Yes ) == QMessageBox::No ) {
+        SUIT_MessageBox::question( this,
+                                   tr( "GEOM_WRN_WARNING" ),
+                                   tr( "GEOM_REDUCE_STUDY_WARNING_DELETE" ),
+                                   QMessageBox::Yes | QMessageBox::No,
+                                   QMessageBox::Yes ) == QMessageBox::No ) {
       return;
     }
     for( iter = myListParents.begin(); iter != myListParents.end(); ++iter )
@@ -693,16 +703,16 @@ void GEOMToolsGUI_ReduceStudyDlg::clickOnHelp()
 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidget* view, const QStringList &strings,
                                                           char* studyEntry, int type )
 :QTreeWidgetItem( view, strings, type ),
- myStudyEntry( studyEntry ),
- myVisible( false )
+ myVisible( false ),
+ myStudyEntry( studyEntry )
 {
 }
 
 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidgetItem* parent, const QStringList &strings,
                                                           char* studyEntry, int type )
 :QTreeWidgetItem( parent, strings, type ),
- myStudyEntry( studyEntry ),
- myVisible( false )
+ myVisible( false ),
+ myStudyEntry( studyEntry )
 {
 }