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 myIsMainDocument = Standard_True;
52 // getting the subcomponents.
54 myIsMainDocument = Standard_False;
56 for ( myList->Init(); myList->More(); myList->Next()) {
57 myCurrentDocument = myList->Value();
58 if(myCurrentDocument != myMainDocument) {
59 myHasSubComponents = Standard_True;
64 myIsMainDocument = Standard_True;
65 myCurrentDocument = myMainDocument;
68 CDF_TryStoreStatus CDF_Store::Check() {
69 if(!PCDM::FindStorageDriver(myMainDocument)) return CDF_TS_NoDriver;
72 // Checking the subcomponent.
73 Handle(CDM_Document) theCurrentDocument;
75 for ( myList->Init(); myList->More(); myList->Next()) {
76 theCurrentDocument = myList->Value();
78 if(theCurrentDocument != myMainDocument) {
79 if( theCurrentDocument->IsModified()) {
81 myLastName = theCurrentDocument->Presentation();
83 if(!PCDM::FindStorageDriver(theCurrentDocument)) return CDF_TS_NoDriver;
92 Standard_ExtString CDF_Store::LastName() const {
93 return myLastName.ToExtString();
96 Standard_ExtString CDF_Store::Folder() const {
97 static TCollection_ExtendedString retv;
98 if(myCurrentDocument->HasRequestedFolder())
99 retv = myCurrentDocument->RequestedFolder();
102 return retv.ToExtString();
105 Standard_ExtString CDF_Store::Name() const {
106 static TCollection_ExtendedString retv;
107 retv = myCurrentDocument->RequestedName();
108 return retv.ToExtString();
112 Standard_Boolean CDF_Store::SetFolder(const Standard_ExtString aFolder) {
113 TCollection_ExtendedString f(aFolder);
116 Standard_Boolean CDF_Store::SetFolder(const TCollection_ExtendedString& aFolder) {
118 TCollection_ExtendedString theFolder(aFolder);
119 Standard_Integer l = theFolder.Length();
121 // if the last character is the folder separator (which is always the first character)
123 // This is correct for Unix systems but not for Windows! VMS and MAC? Thomas Haller, 23.11.01
126 if(theFolder.Value(l) == theFolder.Value(1)) theFolder.Trunc(l-1);
128 if (theFolder.Value(l) == '/' || theFolder.Value(l) == '\\')
129 theFolder.Trunc(l-1);
133 if(theMetaDataDriver->FindFolder(theFolder)) {
134 myCurrentDocument->SetRequestedFolder(theFolder);
135 return Standard_True;
137 return Standard_False;
141 CDF_StoreSetNameStatus CDF_Store::RecheckName () {
142 return SetName(myCurrentDocument->RequestedName());
145 CDF_StoreSetNameStatus CDF_Store::SetName(const TCollection_ExtendedString& aName)
147 TCollection_ExtendedString theName=theMetaDataDriver->SetName(myCurrentDocument,aName);
149 if(myCurrentDocument->IsStored ()) {
150 Handle(CDM_MetaData) E = myCurrentDocument->MetaData();
151 if( E->Folder() == myCurrentDocument->RequestedFolder()
152 && E->Name() == theName) return CDF_SSNS_OK;
155 if(myCurrentDocument->HasRequestedFolder()) {
156 if (theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),theName)) {
157 if(theMetaDataDriver->MetaData(myCurrentDocument->RequestedFolder(),theName)->IsRetrieved())
158 return CDF_SSNS_OpenDocument;
160 myCurrentDocument->SetRequestedName(theName);
161 return CDF_SSNS_ReplacingAnExistentDocument;
165 myCurrentDocument->SetRequestedName(theName);
168 CDF_StoreSetNameStatus CDF_Store::SetName(const Standard_ExtString aName)
170 TCollection_ExtendedString theName(aName);
171 return SetName(theName);
174 void CDF_Store::Realize() {
175 Standard_ProgramError_Raise_if(!myList->IsConsistent(),"information are missing");
176 Handle(CDM_MetaData) m;
178 myStatus = myList->Store(m,myText);
179 if(myStatus==PCDM_SS_OK) myPath = m->Path();
181 Standard_ExtString CDF_Store::Path() const {
182 return myPath.ToExtString();
184 Standard_ExtString CDF_Store::MetaDataPath() const {
185 static TCollection_ExtendedString retv;
187 if(myCurrentDocument->IsStored()) retv=myCurrentDocument->MetaData()->Path();
188 return retv.ToExtString();
190 Standard_ExtString CDF_Store::Description() const {
191 static TCollection_ExtendedString retv;
193 if(myMainDocument->FindDescription())
194 retv = myMainDocument->Description();
198 return retv.ToExtString();
201 Standard_Boolean CDF_Store::IsStored() const {
202 return myCurrentDocument->IsStored();
204 Standard_Boolean CDF_Store::IsModified() const {
205 return myCurrentDocument->IsModified();
207 Standard_Boolean CDF_Store::CurrentIsConsistent() const {
208 if(!myCurrentDocument->IsStored())
209 return myCurrentDocument->HasRequestedFolder();
210 return Standard_True;
213 Standard_Boolean CDF_Store::IsConsistent() const {
214 return myList->IsConsistent();
216 Standard_Boolean CDF_Store::HasAPreviousVersion() const {
217 return myCurrentDocument->HasRequestedPreviousVersion();
220 Standard_ExtString CDF_Store::PreviousVersion() const {
221 static TCollection_ExtendedString retv;
222 if(myCurrentDocument->HasRequestedPreviousVersion())
223 retv= myCurrentDocument->RequestedPreviousVersion();
226 return retv.ToExtString();
229 Standard_Boolean CDF_Store::SetPreviousVersion (const Standard_ExtString aPreviousVersion) {
230 if(theMetaDataDriver->HasVersionCapability()) {
231 if(myCurrentDocument->HasRequestedFolder()) {
232 if(theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),myCurrentDocument->RequestedName(),aPreviousVersion)){
234 myCurrentDocument->SetRequestedPreviousVersion(aPreviousVersion);
235 return Standard_True;
238 return Standard_False;
241 return Standard_False;
243 return Standard_True;
246 void CDF_Store::InitComponent() {
250 Standard_Boolean CDF_Store::MoreComponent() const {
251 return myList->More();
254 void CDF_Store::NextComponent() {
257 void CDF_Store::SetCurrent() {
258 myCurrentDocument = myList->Value();
259 myIsMainDocument = myCurrentDocument == myMainDocument;
264 Standard_ExtString CDF_Store::Component() const {
266 static TCollection_ExtendedString retv;
267 retv=myList->Value()->Presentation();
268 return retv.ToExtString();
270 Standard_Boolean CDF_Store::HasSubComponents () const {
271 return myHasSubComponents;
274 void CDF_Store::SetCurrent(const Standard_ExtString aPresentation) {
275 myCurrentDocument = CDM_Document::FindFromPresentation(aPresentation);
276 myIsMainDocument = myCurrentDocument == myMainDocument;
278 void CDF_Store::SetMain() {
279 myCurrentDocument = myMainDocument;
280 myIsMainDocument = Standard_True;
283 Standard_Boolean CDF_Store::IsMainDocument() const {
284 return myIsMainDocument;
287 CDF_SubComponentStatus CDF_Store::SubComponentStatus(const Standard_ExtString aPresentation) const {
288 Handle(CDM_Document) d = CDM_Document::FindFromPresentation(aPresentation);
291 return d->HasRequestedFolder()? CDF_SCS_Consistent : CDF_SCS_Unconsistent;
293 if(d->IsModified()) return CDF_SCS_Modified;
294 return CDF_SCS_Stored;
299 PCDM_StoreStatus CDF_Store::StoreStatus() const {
302 Standard_ExtString CDF_Store::AssociatedStatusText() const {
303 return myText.ToExtString();
307 void CDF_Store::FindDefault() {
308 if (!myCurrentDocument->IsStored ()) {
309 myCurrentDocument->SetRequestedFolder(CDF_Session::CurrentSession()->CurrentApplication()->DefaultFolder());
310 // myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->Presentation()));
311 myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->RequestedName()));
314 void CDF_Store::SetComment(const Standard_ExtString aComment) {
315 myCurrentDocument->SetRequestedComment(aComment);
318 Standard_ExtString CDF_Store::Comment() const {
319 static TCollection_ExtendedString retv;
320 retv=myCurrentDocument->RequestedComment();
321 return retv.ToExtString();