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