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 : myHasSubComponents(Standard_False),
39 myIsMainDocument(Standard_False),
40 myStatus(PCDM_SS_No_Obj)
43 CDF_Store::CDF_Store(const Handle(CDM_Document)& aDocument):myHasSubComponents(Standard_False) {
45 myMainDocument = aDocument;
49 void CDF_Store::Init() {
51 myCurrentDocument = myMainDocument;
52 myList = new CDF_StoreList(myCurrentDocument);
54 // getting the subcomponents.
56 myIsMainDocument = Standard_False;
58 for ( myList->Init(); myList->More(); myList->Next()) {
59 myCurrentDocument = myList->Value();
60 if(myCurrentDocument != myMainDocument) {
61 myHasSubComponents = Standard_True;
66 myIsMainDocument = Standard_True;
67 myCurrentDocument = myMainDocument;
70 Standard_ExtString CDF_Store::Folder() const {
71 static TCollection_ExtendedString retv;
72 if(myCurrentDocument->HasRequestedFolder())
73 retv = myCurrentDocument->RequestedFolder();
76 return retv.ToExtString();
79 Standard_ExtString CDF_Store::Name() const {
80 static TCollection_ExtendedString retv;
81 retv = myCurrentDocument->RequestedName();
82 return retv.ToExtString();
86 Standard_Boolean CDF_Store::SetFolder(const Standard_ExtString aFolder) {
87 TCollection_ExtendedString f(aFolder);
90 Standard_Boolean CDF_Store::SetFolder(const TCollection_ExtendedString& aFolder) {
92 TCollection_ExtendedString theFolder(aFolder);
93 Standard_Integer l = theFolder.Length();
95 // if the last character is the folder separator (which is always the first character)
97 // This is correct for Unix systems but not for Windows! VMS and MAC? Thomas Haller, 23.11.01
100 if(theFolder.Value(l) == theFolder.Value(1)) theFolder.Trunc(l-1);
102 if (theFolder.Value(l) == '/' || theFolder.Value(l) == '\\')
103 theFolder.Trunc(l-1);
107 if(theMetaDataDriver->FindFolder(theFolder)) {
108 myCurrentDocument->SetRequestedFolder(theFolder);
109 return Standard_True;
111 return Standard_False;
115 CDF_StoreSetNameStatus CDF_Store::RecheckName () {
116 return SetName(myCurrentDocument->RequestedName());
119 CDF_StoreSetNameStatus CDF_Store::SetName(const TCollection_ExtendedString& aName)
121 TCollection_ExtendedString theName=theMetaDataDriver->SetName(myCurrentDocument,aName);
123 if(myCurrentDocument->IsStored ()) {
124 Handle(CDM_MetaData) E = myCurrentDocument->MetaData();
125 if( E->Folder() == myCurrentDocument->RequestedFolder()
126 && E->Name() == theName) return CDF_SSNS_OK;
129 if(myCurrentDocument->HasRequestedFolder()) {
130 if (theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),theName)) {
131 if(theMetaDataDriver->MetaData(myCurrentDocument->RequestedFolder(),theName)->IsRetrieved())
132 return CDF_SSNS_OpenDocument;
134 myCurrentDocument->SetRequestedName(theName);
135 return CDF_SSNS_ReplacingAnExistentDocument;
139 myCurrentDocument->SetRequestedName(theName);
142 CDF_StoreSetNameStatus CDF_Store::SetName(const Standard_ExtString aName)
144 TCollection_ExtendedString theName(aName);
145 return SetName(theName);
148 void CDF_Store::Realize() {
149 Standard_ProgramError_Raise_if(!myList->IsConsistent(),"information are missing");
150 Handle(CDM_MetaData) m;
152 myStatus = myList->Store(m,myText);
153 if(myStatus==PCDM_SS_OK) myPath = m->Path();
155 Standard_ExtString CDF_Store::Path() const {
156 return myPath.ToExtString();
158 Standard_ExtString CDF_Store::MetaDataPath() const {
159 static TCollection_ExtendedString retv;
161 if(myCurrentDocument->IsStored()) retv=myCurrentDocument->MetaData()->Path();
162 return retv.ToExtString();
164 Standard_ExtString CDF_Store::Description() const {
165 static TCollection_ExtendedString retv;
167 if(myMainDocument->FindDescription())
168 retv = myMainDocument->Description();
172 return retv.ToExtString();
175 Standard_Boolean CDF_Store::IsStored() const {
176 return myCurrentDocument->IsStored();
178 Standard_Boolean CDF_Store::IsModified() const {
179 return myCurrentDocument->IsModified();
181 Standard_Boolean CDF_Store::CurrentIsConsistent() const {
182 if(!myCurrentDocument->IsStored())
183 return myCurrentDocument->HasRequestedFolder();
184 return Standard_True;
187 Standard_Boolean CDF_Store::IsConsistent() const {
188 return myList->IsConsistent();
190 Standard_Boolean CDF_Store::HasAPreviousVersion() const {
191 return myCurrentDocument->HasRequestedPreviousVersion();
194 Standard_ExtString CDF_Store::PreviousVersion() const {
195 static TCollection_ExtendedString retv;
196 if(myCurrentDocument->HasRequestedPreviousVersion())
197 retv= myCurrentDocument->RequestedPreviousVersion();
200 return retv.ToExtString();
203 Standard_Boolean CDF_Store::SetPreviousVersion (const Standard_ExtString aPreviousVersion) {
204 if(theMetaDataDriver->HasVersionCapability()) {
205 if(myCurrentDocument->HasRequestedFolder()) {
206 if(theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),myCurrentDocument->RequestedName(),aPreviousVersion)){
208 myCurrentDocument->SetRequestedPreviousVersion(aPreviousVersion);
209 return Standard_True;
212 return Standard_False;
215 return Standard_False;
217 return Standard_True;
220 void CDF_Store::InitComponent() {
224 Standard_Boolean CDF_Store::MoreComponent() const {
225 return myList->More();
228 void CDF_Store::NextComponent() {
231 void CDF_Store::SetCurrent() {
232 myCurrentDocument = myList->Value();
233 myIsMainDocument = myCurrentDocument == myMainDocument;
238 Standard_ExtString CDF_Store::Component() const {
240 static TCollection_ExtendedString retv;
241 retv=myList->Value()->Presentation();
242 return retv.ToExtString();
244 Standard_Boolean CDF_Store::HasSubComponents () const {
245 return myHasSubComponents;
248 void CDF_Store::SetCurrent(const Standard_ExtString aPresentation) {
249 myCurrentDocument = CDM_Document::FindFromPresentation(aPresentation);
250 myIsMainDocument = myCurrentDocument == myMainDocument;
252 void CDF_Store::SetMain() {
253 myCurrentDocument = myMainDocument;
254 myIsMainDocument = Standard_True;
257 Standard_Boolean CDF_Store::IsMainDocument() const {
258 return myIsMainDocument;
261 CDF_SubComponentStatus CDF_Store::SubComponentStatus(const Standard_ExtString aPresentation) const {
262 Handle(CDM_Document) d = CDM_Document::FindFromPresentation(aPresentation);
265 return d->HasRequestedFolder()? CDF_SCS_Consistent : CDF_SCS_Unconsistent;
267 if(d->IsModified()) return CDF_SCS_Modified;
268 return CDF_SCS_Stored;
273 PCDM_StoreStatus CDF_Store::StoreStatus() const {
276 Standard_ExtString CDF_Store::AssociatedStatusText() const {
277 return myText.ToExtString();
281 void CDF_Store::FindDefault() {
282 if (!myCurrentDocument->IsStored ()) {
283 myCurrentDocument->SetRequestedFolder(CDF_Session::CurrentSession()->CurrentApplication()->DefaultFolder());
284 // myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->Presentation()));
285 myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->RequestedName()));
288 void CDF_Store::SetComment(const Standard_ExtString aComment) {
289 myCurrentDocument->SetRequestedComment(aComment);
292 Standard_ExtString CDF_Store::Comment() const {
293 static TCollection_ExtendedString retv;
294 retv=myCurrentDocument->RequestedComment();
295 return retv.ToExtString();