1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 // Modified by rmi, Thu Dec 4 14:24:24 1997
16 #include <CDF_Application.hxx>
17 #include <CDF_MetaDataDriver.hxx>
18 #include <CDF_Session.hxx>
19 #include <CDF_Store.hxx>
20 #include <CDF_StoreList.hxx>
21 #include <CDF_StoreSetNameStatus.hxx>
22 #include <CDM_Document.hxx>
23 #include <CDM_MetaData.hxx>
25 #include <PCDM_StorageDriver.hxx>
26 #include <PCDM_StoreStatus.hxx>
27 #include <Standard_ProgramError.hxx>
28 #include <TCollection_ExtendedString.hxx>
30 #define theMetaDataDriver CDF_Session::CurrentSession()->MetaDataDriver()
33 static TCollection_ExtendedString blank("");
37 CDF_Store::CDF_Store() {}
38 CDF_Store::CDF_Store(const Handle(CDM_Document)& aDocument):myHasSubComponents(Standard_False) {
40 myMainDocument = aDocument;
44 void CDF_Store::Init() {
46 myCurrentDocument = myMainDocument;
47 myList = new CDF_StoreList(myCurrentDocument);
49 // getting the subcomponents.
51 myIsMainDocument = Standard_False;
53 for ( myList->Init(); myList->More(); myList->Next()) {
54 myCurrentDocument = myList->Value();
55 if(myCurrentDocument != myMainDocument) {
56 myHasSubComponents = Standard_True;
61 myIsMainDocument = Standard_True;
62 myCurrentDocument = myMainDocument;
65 Standard_ExtString CDF_Store::Folder() const {
66 static TCollection_ExtendedString retv;
67 if(myCurrentDocument->HasRequestedFolder())
68 retv = myCurrentDocument->RequestedFolder();
71 return retv.ToExtString();
74 Standard_ExtString CDF_Store::Name() const {
75 static TCollection_ExtendedString retv;
76 retv = myCurrentDocument->RequestedName();
77 return retv.ToExtString();
81 Standard_Boolean CDF_Store::SetFolder(const Standard_ExtString aFolder) {
82 TCollection_ExtendedString f(aFolder);
85 Standard_Boolean CDF_Store::SetFolder(const TCollection_ExtendedString& aFolder) {
87 TCollection_ExtendedString theFolder(aFolder);
88 Standard_Integer l = theFolder.Length();
90 // if the last character is the folder separator (which is always the first character)
92 // This is correct for Unix systems but not for Windows! VMS and MAC? Thomas Haller, 23.11.01
95 if(theFolder.Value(l) == theFolder.Value(1)) theFolder.Trunc(l-1);
97 if (theFolder.Value(l) == '/' || theFolder.Value(l) == '\\')
102 if(theMetaDataDriver->FindFolder(theFolder)) {
103 myCurrentDocument->SetRequestedFolder(theFolder);
104 return Standard_True;
106 return Standard_False;
110 CDF_StoreSetNameStatus CDF_Store::RecheckName () {
111 return SetName(myCurrentDocument->RequestedName());
114 CDF_StoreSetNameStatus CDF_Store::SetName(const TCollection_ExtendedString& aName)
116 TCollection_ExtendedString theName=theMetaDataDriver->SetName(myCurrentDocument,aName);
118 if(myCurrentDocument->IsStored ()) {
119 Handle(CDM_MetaData) E = myCurrentDocument->MetaData();
120 if( E->Folder() == myCurrentDocument->RequestedFolder()
121 && E->Name() == theName) return CDF_SSNS_OK;
124 if(myCurrentDocument->HasRequestedFolder()) {
125 if (theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),theName)) {
126 if(theMetaDataDriver->MetaData(myCurrentDocument->RequestedFolder(),theName)->IsRetrieved())
127 return CDF_SSNS_OpenDocument;
129 myCurrentDocument->SetRequestedName(theName);
130 return CDF_SSNS_ReplacingAnExistentDocument;
134 myCurrentDocument->SetRequestedName(theName);
137 CDF_StoreSetNameStatus CDF_Store::SetName(const Standard_ExtString aName)
139 TCollection_ExtendedString theName(aName);
140 return SetName(theName);
143 void CDF_Store::Realize() {
144 Standard_ProgramError_Raise_if(!myList->IsConsistent(),"information are missing");
145 Handle(CDM_MetaData) m;
147 myStatus = myList->Store(m,myText);
148 if(myStatus==PCDM_SS_OK) myPath = m->Path();
150 Standard_ExtString CDF_Store::Path() const {
151 return myPath.ToExtString();
153 Standard_ExtString CDF_Store::MetaDataPath() const {
154 static TCollection_ExtendedString retv;
156 if(myCurrentDocument->IsStored()) retv=myCurrentDocument->MetaData()->Path();
157 return retv.ToExtString();
159 Standard_ExtString CDF_Store::Description() const {
160 static TCollection_ExtendedString retv;
162 if(myMainDocument->FindDescription())
163 retv = myMainDocument->Description();
167 return retv.ToExtString();
170 Standard_Boolean CDF_Store::IsStored() const {
171 return myCurrentDocument->IsStored();
173 Standard_Boolean CDF_Store::IsModified() const {
174 return myCurrentDocument->IsModified();
176 Standard_Boolean CDF_Store::CurrentIsConsistent() const {
177 if(!myCurrentDocument->IsStored())
178 return myCurrentDocument->HasRequestedFolder();
179 return Standard_True;
182 Standard_Boolean CDF_Store::IsConsistent() const {
183 return myList->IsConsistent();
185 Standard_Boolean CDF_Store::HasAPreviousVersion() const {
186 return myCurrentDocument->HasRequestedPreviousVersion();
189 Standard_ExtString CDF_Store::PreviousVersion() const {
190 static TCollection_ExtendedString retv;
191 if(myCurrentDocument->HasRequestedPreviousVersion())
192 retv= myCurrentDocument->RequestedPreviousVersion();
195 return retv.ToExtString();
198 Standard_Boolean CDF_Store::SetPreviousVersion (const Standard_ExtString aPreviousVersion) {
199 if(theMetaDataDriver->HasVersionCapability()) {
200 if(myCurrentDocument->HasRequestedFolder()) {
201 if(theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),myCurrentDocument->RequestedName(),aPreviousVersion)){
203 myCurrentDocument->SetRequestedPreviousVersion(aPreviousVersion);
204 return Standard_True;
207 return Standard_False;
210 return Standard_False;
212 return Standard_True;
215 void CDF_Store::InitComponent() {
219 Standard_Boolean CDF_Store::MoreComponent() const {
220 return myList->More();
223 void CDF_Store::NextComponent() {
226 void CDF_Store::SetCurrent() {
227 myCurrentDocument = myList->Value();
228 myIsMainDocument = myCurrentDocument == myMainDocument;
233 Standard_ExtString CDF_Store::Component() const {
235 static TCollection_ExtendedString retv;
236 retv=myList->Value()->Presentation();
237 return retv.ToExtString();
239 Standard_Boolean CDF_Store::HasSubComponents () const {
240 return myHasSubComponents;
243 void CDF_Store::SetCurrent(const Standard_ExtString aPresentation) {
244 myCurrentDocument = CDM_Document::FindFromPresentation(aPresentation);
245 myIsMainDocument = myCurrentDocument == myMainDocument;
247 void CDF_Store::SetMain() {
248 myCurrentDocument = myMainDocument;
249 myIsMainDocument = Standard_True;
252 Standard_Boolean CDF_Store::IsMainDocument() const {
253 return myIsMainDocument;
256 CDF_SubComponentStatus CDF_Store::SubComponentStatus(const Standard_ExtString aPresentation) const {
257 Handle(CDM_Document) d = CDM_Document::FindFromPresentation(aPresentation);
260 return d->HasRequestedFolder()? CDF_SCS_Consistent : CDF_SCS_Unconsistent;
262 if(d->IsModified()) return CDF_SCS_Modified;
263 return CDF_SCS_Stored;
268 PCDM_StoreStatus CDF_Store::StoreStatus() const {
271 Standard_ExtString CDF_Store::AssociatedStatusText() const {
272 return myText.ToExtString();
276 void CDF_Store::FindDefault() {
277 if (!myCurrentDocument->IsStored ()) {
278 myCurrentDocument->SetRequestedFolder(CDF_Session::CurrentSession()->CurrentApplication()->DefaultFolder());
279 // myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->Presentation()));
280 myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->RequestedName()));
283 void CDF_Store::SetComment(const Standard_ExtString aComment) {
284 myCurrentDocument->SetRequestedComment(aComment);
287 Standard_ExtString CDF_Store::Comment() const {
288 static TCollection_ExtendedString retv;
289 retv=myCurrentDocument->RequestedComment();
290 return retv.ToExtString();