]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Added 3 mthods to work with SALOMEDSClients
authorsrn <srn@opencascade.com>
Wed, 6 Apr 2005 09:14:53 +0000 (09:14 +0000)
committersrn <srn@opencascade.com>
Wed, 6 Apr 2005 09:14:53 +0000 (09:14 +0000)
src/TOOLSDS/SALOMEDS_Tool.cxx
src/TOOLSDS/SALOMEDS_Tool.hxx

index e250257af13543478515d606348f082965e72b12..18ae883eaea7438ee4ac93f479cdd87d7f2bf57c 100644 (file)
@@ -409,6 +409,102 @@ void SALOMEDS_Tool::GetAllChildren( SALOMEDS::Study_var               theStudy,
 
 
 
+//=======================================================================
+// name    : GetFlag
+// Purpose : Retrieve specified flaf from "AttributeFlags" attribute
+//=======================================================================
+bool SALOMEDS_Tool::GetFlag( const int               theFlag,
+                             SALOMEDSClient_Study*   theStudy,
+                             SALOMEDSClient_SObject* theObj )
+{
+  SALOMEDSClient_GenericAttribute* anAttr = NULL;
+  if ( theObj && theObj->FindAttribute( anAttr, "AttributeFlags" ) )
+  {
+    SALOMEDSClient_AttributeFlags* aFlags = dynamic_cast<SALOMEDSClient_AttributeFlags*>( anAttr );
+    bool ret = aFlags->Get( theFlag );
+    delete aFlags;
+    return ret;
+  }
+
+  return false;
+}
+
+//=======================================================================
+// name    : SetFlag
+// Purpose : Set/Unset specified flaf from "AttributeFlags" attribute
+//=======================================================================
+bool SALOMEDS_Tool::SetFlag( const int             theFlag,
+                             SALOMEDSClient_Study* theStudy,
+                             const std::string&    theEntry,
+                             const bool            theValue )
+{
+  SALOMEDSClient_SObject* anObj = theStudy->FindObjectID(theEntry.c_str());
+
+  if ( anObj )
+  {
+    SALOMEDSClient_GenericAttribute* aGAttr;
+    if ( anObj->FindAttribute( aGAttr, "AttributeFlags" ) )
+    {
+      SALOMEDSClient_AttributeFlags* anAttr = dynamic_cast<SALOMEDSClient_AttributeFlags*>( aGAttr );
+      anAttr->Set( theFlag, theValue );
+      delete anAttr;
+    }
+    else if ( theValue )
+    {
+      SALOMEDSClient_StudyBuilder* aBuilder = theStudy->NewBuilder();
+      SALOMEDSClient_AttributeFlags* anAttr = dynamic_cast<SALOMEDSClient_AttributeFlags*>(
+        aBuilder->FindOrCreateAttribute( anObj, "AttributeFlags" ) );
+      anAttr->Set( theFlag, theValue );
+      delete anAttr;
+      delete aBuilder;
+    }
+    return true;
+  }
+
+  return false;
+}
+
+//=======================================================================
+// name    : getAllChildren
+// Purpose : Get all entries of children of object.
+//           If theObj is null all entries of objects of study are returned
+//=======================================================================
+void SALOMEDS_Tool::GetAllChildren( SALOMEDSClient_Study*               theStudy,
+                                    SALOMEDSClient_SObject*             theObj,
+                                    std::list<std::string>& theList )
+{
+  if ( !theObj )
+  {
+    SALOMEDSClient_SComponentIterator* anIter = theStudy->NewComponentIterator();
+    for ( ; anIter->More(); anIter->Next() )
+    {
+      SALOMEDSClient_SObject* anObj = anIter->Value();
+      if ( anObj )
+      {
+        theList.push_back( anObj->GetID() );
+        GetAllChildren( theStudy, anObj, theList );
+       delete anObj;
+      }
+    }
+    delete anIter;
+  }
+  else
+  {
+    SALOMEDSClient_ChildIterator* anIter = theStudy->NewChildIterator( theObj );
+    for ( ; anIter->More(); anIter->Next() )
+    {
+      SALOMEDSClient_SObject* anObj = anIter->Value();
+      SALOMEDSClient_SObject* aRef;
+      if ( !anObj->ReferencedObject( aRef ) )
+      {
+        theList.push_back( anObj->GetID() );
+        GetAllChildren( theStudy, anObj, theList );
+       delete anObj;
+      }
+      else delete aRef;
+    }
+  }
+}
 
 
 
index e3d1d39930add8b3e25f9c14ff6fcf5b3523ba8c..f6465a8e6c35836e502ed621434b2a248ff14b09 100644 (file)
@@ -13,6 +13,8 @@
 #include <string>
 #include <list> 
 
+#include "SALOMEDSClient.hxx"
+
 // IDL headers
 #include "SALOMEconfig.h"
 #include CORBA_SERVER_HEADER(SALOMEDS)
@@ -67,6 +69,23 @@ public:
                               SALOMEDS::SObject_var             theObj,
                               std::list<SALOMEDS::SObject_var>& theList );
 
+
+  // Retrieves specified flaf from "AttributeFlags" attribute
+  static bool GetFlag( const int             theFlag,
+                       SALOMEDSClient_Study*   theStudy,
+                       SALOMEDSClient_SObject* theObj );
+
+  // Sets/Unsets specified flaf from "AttributeFlags" attribute
+  static bool SetFlag( const int             theFlag,
+                       SALOMEDSClient_Study* theStudy,
+                       const std::string&    theEntry,
+                       const bool            theValue );
+
+  // Get all entries of children of object. If theObj is null all entries of objects of study are returned
+  static void GetAllChildren( SALOMEDSClient_Study*               theStudy,
+                              SALOMEDSClient_SObject*             theObj,
+                              std::list<std::string>& theList );
+
 };
 #endif