Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISU_I / VISUConfig.cc
index 3d2174ba2195f24c308f78b5b86b14794434788d..d1e4c58e1487db8dbfe403195e4e9ae37f76a3a8 100644 (file)
@@ -49,7 +49,7 @@ namespace VISU{
   {
     return SUIT_Session::session();
   }
-  
+
   SUIT_ResourceMgr*
   GetResourceMgr()
   {
@@ -69,7 +69,7 @@ namespace VISU{
 
   Base_i::~Base_i() {}
 
-  char* Base_i::GetID(){ 
+  char* Base_i::GetID(){
     if(myID == ""){
       CORBA::Object_var anObject = _this();
       CORBA::String_var anIOR = myOrb->object_to_string(anObject);
@@ -84,7 +84,7 @@ namespace VISU{
 
   Mutex::Mutex(QMutex* theMutex): myMutex(&aMutex){
     if(MYDEBUG) MESSAGE("Mutex::Mutex : "<<!mySCnt);
-    if(!mySCnt++) 
+    if(!mySCnt++)
       myMutex->lock();
   }
 
@@ -103,7 +103,7 @@ namespace VISU{
     ToStream(strOut);
     strOut<<ends;
     if(MYDEBUG) MESSAGE("Storable::ToString - "<<strOut.str());
-    return strOut.str(); 
+    return strOut.str();
   }
 
   void Storable::Registry(const char* theComment, TStorableEngine theEngine)
@@ -113,7 +113,7 @@ namespace VISU{
       throw std::logic_error("Storable::Registry >> dupliacte registring !!!");
     }
   }
-  
+
   void Storable::StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap){
     if(0 && MYDEBUG) MESSAGE("Storable::StrToMap : string="<<theStr);
     QStringList strList = QStringList::split( ";", theStr, false );
@@ -132,36 +132,36 @@ namespace VISU{
          aValue = "";
       }
       if ( !aName.isEmpty() )
-       theMap.insert( TRestoringMap::value_type( aName.latin1(), aValue ) );   
+       theMap.insert( TRestoringMap::value_type( aName.latin1(), aValue ) );
     }
   }
 
   void Storable::DataToStream(ostringstream& theStr, const QString& theName, const QString& theVal) {
-    QString output = ( !theName.isNull() ? theName : QString("") ) 
-                   + QString( "=" ) 
+    QString output = ( !theName.isNull() ? theName : QString("") )
+                   + QString( "=" )
                   + ( !theVal.isNull()  ? theVal  : QString("") );
     theStr<<output.latin1()<<";";
   }
 
   void Storable::DataToStream(ostringstream& theStr, const QString& theName, const int theVal) {
-    QString output = ( !theName.isNull() ? theName : QString("") ) 
-                   + QString( "=" ) 
+    QString output = ( !theName.isNull() ? theName : QString("") )
+                   + QString( "=" )
                   + QString::number( theVal );
     theStr<<output.latin1()<<";";
   }
 
   void Storable::DataToStream(ostringstream& theStr, const QString& theName, const double theVal) {
-    QString output = ( !theName.isNull() ? theName : QString("") ) 
-                   + QString( "=" ) 
+    QString output = ( !theName.isNull() ? theName : QString("") )
+                   + QString( "=" )
                   + QString::number( theVal );
     theStr<<output.latin1()<<";";
   }
   Storable* Storable::Create(SALOMEDS::SObject_ptr theSObject,
-                            const string& thePrefix, const string& theLocalPersistentID) 
+                            const string& thePrefix, const string& theLocalPersistentID)
   {
     try{
       QString strIn( theLocalPersistentID.c_str() );
-      TRestoringMap aMap;        
+      TRestoringMap aMap;
       StrToMap(strIn,aMap);
       bool isExist;
       QString aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist);
@@ -178,7 +178,7 @@ namespace VISU{
     }
     return NULL;
   }
-  
+
   QString Storable::FindValue(const TRestoringMap& theMap, const string& theArg, bool* isFind)
   {
     TRestoringMap::const_iterator i = theMap.find(theArg);
@@ -192,7 +192,17 @@ namespace VISU{
     if(isFind != NULL) *isFind = true;
     return i->second;
   }
-  
+
+
+  QString Storable::FindValue(const TRestoringMap& theMap, const string& theArg, const QString& theDefaultValue)
+  {
+    bool anIsFound = false;
+    QString aValue = FindValue(theMap,theArg,&anIsFound);
+    if(anIsFound)
+      return aValue;
+    return theDefaultValue;
+  }
+
 
   //===========================================================================
   PortableServer::ServantBase_var GetServant(CORBA::Object_ptr theObject){
@@ -202,7 +212,7 @@ namespace VISU{
       PortableServer::Servant aServant = aPOA->reference_to_servant(theObject);
       return aServant;
     } catch (...) {
-      INFOS("GetServant - Unknown exception was occured!!!"); 
+      INFOS("GetServant - Unknown exception was occured!!!");
       return NULL;
     }
   }
@@ -249,7 +259,7 @@ namespace VISU{
   string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry,
                              const char* theComment, int IsAllLevels)
   {
-    SALOMEDS::ChildIterator_var anIter = 
+    SALOMEDS::ChildIterator_var anIter =
       theStudyDocument->NewChildIterator(theStudyDocument->FindObjectID(theStartEntry));
     anIter->InitEx(IsAllLevels);
     SALOMEDS::SObject_var aFieldSO;
@@ -270,9 +280,9 @@ namespace VISU{
     return "";
   }
   //===========================================================================
-  string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument, 
+  string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
                          const char* theFatherEntry, const char* theRefFatherEntry,
-                         const char* theIOR, const char* theName, 
+                         const char* theIOR, const char* theName,
                          const char* thePersistentRef, const char* theComment,
                          CORBA::Boolean theCreateNew)
   {
@@ -285,17 +295,17 @@ namespace VISU{
     if(strcmp(theIOR,"") != 0){
       anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-      anIOR->SetValue(theIOR); 
+      anIOR->SetValue(theIOR);
     }
     if(strcmp(theName,"") != 0){
       anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
-      aName->SetValue(theName); 
+      aName->SetValue(theName);
     }
     if(strcmp(thePersistentRef,"") != 0){
       anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef");
       SALOMEDS::AttributePersistentRef_var aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
-      aPRef->SetValue(thePersistentRef); 
+      aPRef->SetValue(thePersistentRef);
     }
     if(strcmp(theComment,"") != 0){
       anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
@@ -310,13 +320,13 @@ namespace VISU{
     }
     CORBA::String_var anEntry = newObj->GetID();
     string aRet(anEntry);
-    if(MYDEBUG) 
+    if(MYDEBUG)
       INFOS("CreateAttributes - StudyId = "<<theStudyDocument->StudyId()<<"; anEntry = "<<aRet<<"; IOR = '"<<theIOR<<"'");
     return aRet;
   }
-  string CreateAttributes(_PTR(Study) theStudyDocument, 
+  string CreateAttributes(_PTR(Study) theStudyDocument,
                          const char* theFatherEntry, const char* theRefFatherEntry,
-                         const char* theIOR, const char* theName, 
+                         const char* theIOR, const char* theName,
                          const char* thePersistentRef, const char* theComment,
                          CORBA::Boolean theCreateNew)
   {
@@ -332,17 +342,17 @@ namespace VISU{
     if (strcmp(theIOR, "") != 0) {
       anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
       _PTR(AttributeIOR) anIOR (anAttr);
-      anIOR->SetValue(theIOR); 
+      anIOR->SetValue(theIOR);
     }
     if (strcmp(theName, "") != 0) {
       anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
       _PTR(AttributeName) aName (anAttr);
-      aName->SetValue(theName); 
+      aName->SetValue(theName);
     }
     if (strcmp(thePersistentRef, "") != 0) {
       anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef");
       _PTR(AttributePersistentRef) aPRef (anAttr);
-      aPRef->SetValue(thePersistentRef); 
+      aPRef->SetValue(thePersistentRef);
     }
     if (strcmp(theComment, "") != 0) {
       anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
@@ -356,7 +366,7 @@ namespace VISU{
       aStudyBuilder->Addreference(anObj, newObj);
     }
     string aRet = newObj->GetID();
-    if (MYDEBUG) 
+    if (MYDEBUG)
       INFOS("CreateAttributes - StudyId = " << theStudyDocument->StudyId()
            << "; anEntry = " << aRet << "; IOR = '" << theIOR << "'");
     return aRet;
@@ -406,4 +416,79 @@ namespace VISU{
     return study->FindObjectID( obj->GetID() );
 
   }
+
+
+  void RemoveFromStudy (SALOMEDS::SObject_ptr theSObject,
+                       bool theIsAttrOnly,
+                       bool theDestroySubObjects)
+  {
+    if (theSObject->_is_nil()) return;
+
+    SALOMEDS::Study_var aStudyDocument = theSObject->GetStudy();
+    SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
+    if (theIsAttrOnly) {
+      aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR");
+      return;
+    }
+
+    // Remove possible sub-objects
+    SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(theSObject);
+    for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
+      SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
+      CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
+      if (CORBA::is_nil(aChildObj)) continue;
+
+      VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
+      if (CORBA::is_nil(aRemovableObject)) continue;
+
+      aRemovableObject->RemoveFromStudy();
+    }
+
+    // asl, fix for PAL10455: Remove references to SObject
+    SALOMEDS::Study::ListOfSObject* aRefs = aStudyDocument->FindDependances( theSObject );
+    for( int i=0, n=aRefs->length(); i<n; i++ )
+    {
+      SALOMEDS::SObject_var o = (*aRefs)[i];
+      if( o->GetFatherComponent()->ComponentDataType()==theSObject->GetFatherComponent()->ComponentDataType() )
+      {
+       aStudyBuilder->RemoveReference( o );
+       aStudyBuilder->RemoveObjectWithChildren( o );
+      }
+    }
+
+    // Remove the SObject itself
+    aStudyBuilder->RemoveObjectWithChildren(theSObject);
+  }
+
+  void RemoveFromStudy (_PTR(SObject) theSObject,
+                       bool theIsAttrOnly,
+                       bool theDestroySubObjects)
+  {
+    if (!theSObject) return;
+
+    _PTR(Study) aStudyDocument = theSObject->GetStudy();
+    _PTR(StudyBuilder) aStudyBuilder = aStudyDocument->NewBuilder();
+    if (theIsAttrOnly) {
+      aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR");
+      return;
+    }
+
+    // Remove possible sub-objects
+    _PTR(ChildIterator) aChildIter = aStudyDocument->NewChildIterator(theSObject);
+    for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
+      _PTR(SObject) aChildSObject = aChildIter->Value();
+      CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
+      if (CORBA::is_nil(aChildObj)) 
+       continue;
+
+      VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
+      if (CORBA::is_nil(aRemovableObject))
+       continue;
+
+      aRemovableObject->RemoveFromStudy();
+    }
+
+    // Remove the SObject itself
+    aStudyBuilder->RemoveObjectWithChildren(theSObject);
+  }
 }