0025812: Replace dynamic loading mechanism of OCAF persistence with dynamic-link one
[occt.git] / src / CDF / CDF_Store.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14// Modified by rmi, Thu Dec 4 14:24:24 1997
42cf5bc1 15
7fd59977 16#include <CDF_Application.hxx>
7fd59977 17#include <CDF_MetaDataDriver.hxx>
42cf5bc1 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>
7fd59977 24#include <PCDM.hxx>
42cf5bc1 25#include <PCDM_StorageDriver.hxx>
26#include <PCDM_StoreStatus.hxx>
27#include <Standard_ProgramError.hxx>
7fd59977 28#include <TCollection_ExtendedString.hxx>
7fd59977 29
30#define theMetaDataDriver CDF_Session::CurrentSession()->MetaDataDriver()
31
32
33static TCollection_ExtendedString blank("");
34
35
36
37CDF_Store::CDF_Store() {}
38CDF_Store::CDF_Store(const Handle(CDM_Document)& aDocument):myHasSubComponents(Standard_False) {
39
40 myMainDocument = aDocument;
41 Init();
42}
43
44void CDF_Store::Init() {
45
46 myCurrentDocument = myMainDocument;
47 myList = new CDF_StoreList(myCurrentDocument);
48
49 myIsMainDocument = Standard_True;
50 FindDefault();
51
52// getting the subcomponents.
53 //
54 myIsMainDocument = Standard_False;
55 myList->Init();
56 for ( myList->Init(); myList->More(); myList->Next()) {
57 myCurrentDocument = myList->Value();
58 if(myCurrentDocument != myMainDocument) {
59 myHasSubComponents = Standard_True;
60 FindDefault();
61
62 }
63 }
64 myIsMainDocument = Standard_True;
65 myCurrentDocument = myMainDocument;
66}
67
7fd59977 68Standard_ExtString CDF_Store::Folder() const {
69 static TCollection_ExtendedString retv;
70 if(myCurrentDocument->HasRequestedFolder())
71 retv = myCurrentDocument->RequestedFolder();
72 else
73 retv= blank;
74 return retv.ToExtString();
75}
76
77Standard_ExtString CDF_Store::Name() const {
78 static TCollection_ExtendedString retv;
79 retv = myCurrentDocument->RequestedName();
80 return retv.ToExtString();
81}
82
83
84Standard_Boolean CDF_Store::SetFolder(const Standard_ExtString aFolder) {
85 TCollection_ExtendedString f(aFolder);
86 return SetFolder(f);
87}
88Standard_Boolean CDF_Store::SetFolder(const TCollection_ExtendedString& aFolder) {
89
90 TCollection_ExtendedString theFolder(aFolder);
91 Standard_Integer l = theFolder.Length();
92
93 // if the last character is the folder separator (which is always the first character)
94 // it is removed.
95 // This is correct for Unix systems but not for Windows! VMS and MAC? Thomas Haller, 23.11.01
96 if(l > 1) {
57c28b61 97#ifndef _WIN32
7fd59977 98 if(theFolder.Value(l) == theFolder.Value(1)) theFolder.Trunc(l-1);
99#else
100 if (theFolder.Value(l) == '/' || theFolder.Value(l) == '\\')
101 theFolder.Trunc(l-1);
102#endif
103 }
104
105 if(theMetaDataDriver->FindFolder(theFolder)) {
106 myCurrentDocument->SetRequestedFolder(theFolder);
107 return Standard_True;
108 }
109 return Standard_False;
110}
111
112
113CDF_StoreSetNameStatus CDF_Store::RecheckName () {
114 return SetName(myCurrentDocument->RequestedName());
115}
116
117CDF_StoreSetNameStatus CDF_Store::SetName(const TCollection_ExtendedString& aName)
118{
119 TCollection_ExtendedString theName=theMetaDataDriver->SetName(myCurrentDocument,aName);
120
121 if(myCurrentDocument->IsStored ()) {
122 Handle(CDM_MetaData) E = myCurrentDocument->MetaData();
123 if( E->Folder() == myCurrentDocument->RequestedFolder()
124 && E->Name() == theName) return CDF_SSNS_OK;
125 }
126
127 if(myCurrentDocument->HasRequestedFolder()) {
128 if (theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),theName)) {
129 if(theMetaDataDriver->MetaData(myCurrentDocument->RequestedFolder(),theName)->IsRetrieved())
130 return CDF_SSNS_OpenDocument;
131 else {
132 myCurrentDocument->SetRequestedName(theName);
133 return CDF_SSNS_ReplacingAnExistentDocument;
134 }
135 }
136 }
137 myCurrentDocument->SetRequestedName(theName);
138 return CDF_SSNS_OK;
139}
140CDF_StoreSetNameStatus CDF_Store::SetName(const Standard_ExtString aName)
141{
142 TCollection_ExtendedString theName(aName);
143 return SetName(theName);
144}
145
146void CDF_Store::Realize() {
147 Standard_ProgramError_Raise_if(!myList->IsConsistent(),"information are missing");
148 Handle(CDM_MetaData) m;
149 myText = "";
150 myStatus = myList->Store(m,myText);
15e8b082 151 if(myStatus==PCDM_SS_OK) myPath = m->Path();
7fd59977 152}
153Standard_ExtString CDF_Store::Path() const {
154 return myPath.ToExtString();
155}
156Standard_ExtString CDF_Store::MetaDataPath() const {
157 static TCollection_ExtendedString retv;
158 retv="";
159 if(myCurrentDocument->IsStored()) retv=myCurrentDocument->MetaData()->Path();
160 return retv.ToExtString();
161}
162Standard_ExtString CDF_Store::Description() const {
163 static TCollection_ExtendedString retv;
164
165 if(myMainDocument->FindDescription())
166 retv = myMainDocument->Description();
167 else
168 retv= blank;
169
170 return retv.ToExtString();
171}
172
173Standard_Boolean CDF_Store::IsStored() const {
174 return myCurrentDocument->IsStored();
175}
176Standard_Boolean CDF_Store::IsModified() const {
177 return myCurrentDocument->IsModified();
178}
179Standard_Boolean CDF_Store::CurrentIsConsistent() const {
180 if(!myCurrentDocument->IsStored())
181 return myCurrentDocument->HasRequestedFolder();
182 return Standard_True;
183}
184
185Standard_Boolean CDF_Store::IsConsistent() const {
186 return myList->IsConsistent();
187}
188Standard_Boolean CDF_Store::HasAPreviousVersion() const {
189 return myCurrentDocument->HasRequestedPreviousVersion();
190}
191
192Standard_ExtString CDF_Store::PreviousVersion() const {
193 static TCollection_ExtendedString retv;
194 if(myCurrentDocument->HasRequestedPreviousVersion())
195 retv= myCurrentDocument->RequestedPreviousVersion();
196 else
197 retv=blank;
198 return retv.ToExtString();
199}
200
201Standard_Boolean CDF_Store::SetPreviousVersion (const Standard_ExtString aPreviousVersion) {
202 if(theMetaDataDriver->HasVersionCapability()) {
203 if(myCurrentDocument->HasRequestedFolder()) {
204 if(theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),myCurrentDocument->RequestedName(),aPreviousVersion)){
205
206 myCurrentDocument->SetRequestedPreviousVersion(aPreviousVersion);
207 return Standard_True;
208 }
209 else
210 return Standard_False;
211 }
212 else
213 return Standard_False;
214 }
215 return Standard_True;
216}
217
218void CDF_Store::InitComponent() {
219 myList->Init();
220}
221
222Standard_Boolean CDF_Store::MoreComponent() const {
223 return myList->More();
224}
225
226void CDF_Store::NextComponent() {
227 myList->Next();
228}
229void CDF_Store::SetCurrent() {
230 myCurrentDocument = myList->Value();
231 myIsMainDocument = myCurrentDocument == myMainDocument;
232
233
234}
235
236Standard_ExtString CDF_Store::Component() const {
237
238 static TCollection_ExtendedString retv;
239 retv=myList->Value()->Presentation();
240 return retv.ToExtString();
241}
242Standard_Boolean CDF_Store::HasSubComponents () const {
243 return myHasSubComponents;
244}
245
246void CDF_Store::SetCurrent(const Standard_ExtString aPresentation) {
247 myCurrentDocument = CDM_Document::FindFromPresentation(aPresentation);
248 myIsMainDocument = myCurrentDocument == myMainDocument;
249}
250void CDF_Store::SetMain() {
251 myCurrentDocument = myMainDocument;
252 myIsMainDocument = Standard_True;
253
254}
255Standard_Boolean CDF_Store::IsMainDocument() const {
256 return myIsMainDocument;
257}
258
259CDF_SubComponentStatus CDF_Store::SubComponentStatus(const Standard_ExtString aPresentation) const {
260 Handle(CDM_Document) d = CDM_Document::FindFromPresentation(aPresentation);
261
262 if(!d->IsStored())
263 return d->HasRequestedFolder()? CDF_SCS_Consistent : CDF_SCS_Unconsistent;
264
265 if(d->IsModified()) return CDF_SCS_Modified;
266 return CDF_SCS_Stored;
267}
268
269
270
15e8b082 271PCDM_StoreStatus CDF_Store::StoreStatus() const {
7fd59977 272 return myStatus;
273}
274Standard_ExtString CDF_Store::AssociatedStatusText() const {
275 return myText.ToExtString();
276}
277
278
279void CDF_Store::FindDefault() {
280 if (!myCurrentDocument->IsStored ()) {
281 myCurrentDocument->SetRequestedFolder(CDF_Session::CurrentSession()->CurrentApplication()->DefaultFolder());
282// myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->Presentation()));
283 myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->RequestedName()));
284 }
285}
286void CDF_Store::SetComment(const Standard_ExtString aComment) {
287 myCurrentDocument->SetRequestedComment(aComment);
288}
289
290Standard_ExtString CDF_Store::Comment() const {
291 static TCollection_ExtendedString retv;
292 retv=myCurrentDocument->RequestedComment();
293 return retv.ToExtString();
294}