0029195: OCAF - ensure thread safety for different documents.
[occt.git] / src / CDF / CDF_Store.cxx
index fe91752..7098df5 100644 (file)
 #include <PCDM_StorageDriver.hxx>
 #include <PCDM_StoreStatus.hxx>
 #include <Standard_ProgramError.hxx>
-#include <TCollection_ExtendedString.hxx>
-
-#define theMetaDataDriver CDF_Session::CurrentSession()->MetaDataDriver()
-
-
-static TCollection_ExtendedString blank("");
 
+#define theMetaDataDriver Handle(CDF_Application)::DownCast((myCurrentDocument->Application()))->MetaDataDriver()
 
+static const Handle(TCollection_HExtendedString) blank = new TCollection_HExtendedString("");
 
 CDF_Store::CDF_Store()
 : myHasSubComponents(Standard_False),
@@ -67,19 +63,14 @@ void CDF_Store::Init() {
   myCurrentDocument = myMainDocument;
 }
 
-Standard_ExtString CDF_Store::Folder() const {
-  static TCollection_ExtendedString retv;
+Handle(TCollection_HExtendedString) CDF_Store::Folder() const {
   if(myCurrentDocument->HasRequestedFolder())
-    retv =  myCurrentDocument->RequestedFolder();
-  else
-    retv= blank;
-  return retv.ToExtString();
+    return new TCollection_HExtendedString(myCurrentDocument->RequestedFolder());
+  return blank;
 }
 
-Standard_ExtString CDF_Store::Name() const {
-  static TCollection_ExtendedString retv;
-  retv = myCurrentDocument->RequestedName();
-  return retv.ToExtString();
+Handle(TCollection_HExtendedString) CDF_Store::Name() const {
+  return new TCollection_HExtendedString(myCurrentDocument->RequestedName());
 }
 
 
@@ -156,21 +147,15 @@ void CDF_Store::Realize (const Handle(Message_ProgressIndicator)& theProgress)
 Standard_ExtString CDF_Store::Path() const {
   return myPath.ToExtString();
 }
-Standard_ExtString CDF_Store::MetaDataPath() const {
-  static TCollection_ExtendedString retv;
-  retv="";
-  if(myCurrentDocument->IsStored()) retv=myCurrentDocument->MetaData()->Path();
-  return retv.ToExtString();
+Handle(TCollection_HExtendedString) CDF_Store::MetaDataPath() const {
+  if(myCurrentDocument->IsStored())
+    return new TCollection_HExtendedString(myCurrentDocument->MetaData()->Path());
+  return blank;
 }
-Standard_ExtString CDF_Store::Description() const {
-  static TCollection_ExtendedString retv;
-
+Handle(TCollection_HExtendedString) CDF_Store::Description() const {
   if(myMainDocument->FindDescription())
-    retv = myMainDocument->Description();
-  else
-    retv= blank;
-
-  return retv.ToExtString();
+    return new TCollection_HExtendedString(myMainDocument->Description());
+  return blank;
 }
 
 Standard_Boolean CDF_Store::IsStored() const {
@@ -192,13 +177,10 @@ Standard_Boolean CDF_Store::HasAPreviousVersion() const {
   return myCurrentDocument->HasRequestedPreviousVersion();
 }
 
-Standard_ExtString CDF_Store::PreviousVersion() const {
-  static TCollection_ExtendedString retv;
+Handle(TCollection_HExtendedString) CDF_Store::PreviousVersion() const {
   if(myCurrentDocument->HasRequestedPreviousVersion())
-    retv= myCurrentDocument->RequestedPreviousVersion();
-  else
-    retv=blank;
-  return retv.ToExtString();
+    return new TCollection_HExtendedString(myCurrentDocument->RequestedPreviousVersion());
+  return blank;
 }
 
 Standard_Boolean CDF_Store::SetPreviousVersion (const Standard_ExtString aPreviousVersion) {
@@ -218,36 +200,7 @@ Standard_Boolean CDF_Store::SetPreviousVersion (const Standard_ExtString aPrevio
   return Standard_True;
 }
 
-void CDF_Store::InitComponent() {
-   myList->Init();
-}
-
-Standard_Boolean CDF_Store::MoreComponent() const {
-  return myList->More();
-}
-
-void CDF_Store::NextComponent()  {
-  myList->Next();
-}
-void CDF_Store::SetCurrent() {
-  myCurrentDocument = myList->Value();
-  myIsMainDocument = myCurrentDocument == myMainDocument;
-
-
-}
-
-Standard_ExtString CDF_Store::Component() const {
-  
-  static TCollection_ExtendedString retv;
-  retv=myList->Value()->Presentation();
-  return retv.ToExtString();
-}
-Standard_Boolean CDF_Store::HasSubComponents () const {
-   return myHasSubComponents;
-}
-
-void CDF_Store::SetCurrent(const Standard_ExtString aPresentation) {
-  myCurrentDocument = CDM_Document::FindFromPresentation(aPresentation);
+void CDF_Store::SetCurrent(const Standard_ExtString /*aPresentation*/) {
   myIsMainDocument = myCurrentDocument == myMainDocument;
 }
 void CDF_Store::SetMain() {
@@ -259,18 +212,6 @@ Standard_Boolean CDF_Store::IsMainDocument() const {
   return myIsMainDocument;
 }
 
-CDF_SubComponentStatus CDF_Store::SubComponentStatus(const Standard_ExtString aPresentation) const {
-   Handle(CDM_Document) d = CDM_Document::FindFromPresentation(aPresentation);
-
-  if(!d->IsStored()) 
-    return d->HasRequestedFolder()? CDF_SCS_Consistent : CDF_SCS_Unconsistent;
-
-  if(d->IsModified()) return CDF_SCS_Modified;
-  return CDF_SCS_Stored;
-}
-
-
-
 PCDM_StoreStatus CDF_Store::StoreStatus() const {
   return myStatus;
 }
@@ -281,8 +222,7 @@ Standard_ExtString CDF_Store::AssociatedStatusText() const {
 
 void CDF_Store::FindDefault() {
   if (!myCurrentDocument->IsStored ()) {
-    myCurrentDocument->SetRequestedFolder(CDF_Session::CurrentSession()->CurrentApplication()->DefaultFolder());
-//    myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->Presentation()));
+    myCurrentDocument->SetRequestedFolder(Handle(CDF_Application)::DownCast((myCurrentDocument->Application()))->DefaultFolder());
     myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->RequestedName()));
   }
 }
@@ -290,8 +230,6 @@ void CDF_Store::SetComment(const Standard_ExtString aComment) {
   myCurrentDocument->SetRequestedComment(aComment);
 }
 
-Standard_ExtString CDF_Store::Comment() const {
-  static TCollection_ExtendedString retv;
-  retv=myCurrentDocument->RequestedComment();
-  return retv.ToExtString();
+Handle(TCollection_HExtendedString) CDF_Store::Comment() const {
+  return new TCollection_HExtendedString(myCurrentDocument->RequestedComment());
 }