Salome HOME
Fix for problem: broken reference objects after delete originals.
authormzn <mzn@opencascade.com>
Fri, 26 Aug 2005 06:19:26 +0000 (06:19 +0000)
committermzn <mzn@opencascade.com>
Fri, 26 Aug 2005 06:19:26 +0000 (06:19 +0000)
src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/SalomeApp_Application.h
src/SalomeApp/SalomeApp_DataObject.cxx

index d36516b01c1f25b010da46642082a32f029ba47b..1dcf08d2234d6660ace57a9e345f86afa0001b03 100644 (file)
@@ -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<SalomeApp_Study*>(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<SalomeApp_Study*>(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*/
index 43fa56db2d7cdce649bcbeb4f6e22cfbcf7a6a6a..969d5489060e7548837ca7e74b9ac6a6738df955 100644 (file)
@@ -130,6 +130,7 @@ public slots:
 private slots:
   void                                onSelection();
   void                                onRefresh();
+  void                                onDeleteReferences();
 
 protected:
   virtual void                        createActions();
index 235115a12d3e850ea4554beb6533badddfbc6088..d04114d3e60a6fffcd1cf083f7d275f7d2904d37 100644 (file)
@@ -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( "<Invalid Reference>" );
+    }
 
   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() )