From e903af847e601148fda1ef0c9b0d6f1faa322d79 Mon Sep 17 00:00:00 2001 From: mzn Date: Fri, 26 Aug 2005 06:19:26 +0000 Subject: [PATCH] Fix for problem: broken reference objects after delete originals. --- src/SalomeApp/SalomeApp_Application.cxx | 65 ++++++++++++++++++++++++- src/SalomeApp/SalomeApp_Application.h | 1 + src/SalomeApp/SalomeApp_DataObject.cxx | 21 ++++++-- 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index d36516b01..1dcf08d22 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -764,6 +764,33 @@ void SalomeApp_Application::onRefresh() updateObjectBrowser( true ); } +/*!Delete references.*/ +void SalomeApp_Application::onDeleteReferences() +{ + SALOME_ListIO aList; + SalomeApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects(aList); + + if (aList.Extent() < 1) return; + + SalomeApp_Study* aStudy = dynamic_cast(activeStudy()); + _PTR(Study) aStudyDS = aStudy->studyDS(); + _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder(); + _PTR(SObject) anObj; + + for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) + { + if ( it.Value()->hasEntry() ) + { + _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() ); + if ( aSObject->ReferencedObject(anObj) ) + aStudyBuilder->RemoveReference(aSObject); + } + } + + updateObjectBrowser(); +} + /*!Private SLOT. */ void SalomeApp_Application::onOpenWith() { @@ -1942,10 +1969,45 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* t thePopup->insertSeparator(); thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) ); - // "Activate module" item should appear only if it's necessary + // Get selected objects SALOME_ListIO aList; SalomeApp_SelectionMgr* mgr = selectionMgr(); mgr->selectedObjects(aList); + + // "Delete reference" item should appear only for invalid references + + // Check if selected objects is invalid references + bool isInvalidRefs = true; + + if ( aList.Extent() < 1 ) + isInvalidRefs = false; + + if ( isInvalidRefs ) + { + SalomeApp_Study* aStudy = dynamic_cast(activeStudy()); + _PTR(Study) aStudyDS = aStudy->studyDS(); + _PTR(SObject) anObj; + + for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() ) + { + if ( it.Value()->hasEntry() ) + { + _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() ); + if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetIOR().c_str()).isEmpty() ) + isInvalidRefs = false; + } + } + } + + // Add "Delete refrence" item to popup + if ( isInvalidRefs ) + { + thePopup->insertSeparator(); + thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) ); + return; + } + + // "Activate module" item should appear only if it's necessary if (aList.Extent() != 1) return; Handle(SALOME_InteractiveObject) aIObj = aList.First(); @@ -1955,6 +2017,7 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* t if (currentModule && currentModule->moduleName() == aModuleTitle) return; thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) ); + } /*!Update obect browser*/ diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 43fa56db2..969d54890 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -130,6 +130,7 @@ public slots: private slots: void onSelection(); void onRefresh(); + void onDeleteReferences(); protected: virtual void createActions(); diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index 235115a12..d04114d3e 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -113,7 +113,12 @@ QString SalomeApp_DataObject::name() const } if ( isReference() ) - str = QString( "* " ) + str; + { + if ( !(text(CT_IOR).isEmpty()) ) + str = QString( "* " ) + str; + else + str = QString( "" ); + } return str; } @@ -181,7 +186,12 @@ QColor SalomeApp_DataObject::color( const ColorRole cr ) const { case Text: if ( isReference() ) - clr = QColor( 255, 0, 0 ); + { + if ( !(text(CT_IOR).isEmpty()) ) + clr = QColor( 255, 0, 0 ); + else + clr = QColor( 200, 200, 200 ); + } else if ( myObject ) { _PTR(GenericAttribute) anAttr; @@ -194,7 +204,12 @@ QColor SalomeApp_DataObject::color( const ColorRole cr ) const break; case Highlight: if ( isReference() ) - clr = QColor( 255, 0, 0 ); + { + if ( !(text(CT_IOR).isEmpty()) ) + clr = QColor( 255, 0, 0 ); + else + clr = QColor( 200, 200, 200 ); + } break; case HighlightedText: if ( isReference() ) -- 2.39.2