1 // Modified by rmi, Thu Dec 4 14:24:24 1997
2 #include <CDF_Store.ixx>
3 #include <CDF_Session.hxx>
4 #include <CDF_Application.hxx>
5 #include <CDF_StoreStatus.hxx>
6 #include <CDF_StoreSetNameStatus.hxx>
7 #include <Standard_ProgramError.hxx>
8 #include <CDF_MetaDataDriver.hxx>
9 #include <PCDM_StorageDriver.hxx>
11 #include <TCollection_ExtendedString.hxx>
12 #include <CDM_MetaData.hxx>
14 #define theMetaDataDriver CDF_Session::CurrentSession()->MetaDataDriver()
17 static TCollection_ExtendedString blank("");
21 CDF_Store::CDF_Store() {}
22 CDF_Store::CDF_Store(const Handle(CDM_Document)& aDocument):myHasSubComponents(Standard_False) {
24 myMainDocument = aDocument;
28 void CDF_Store::Init() {
30 myCurrentDocument = myMainDocument;
31 myList = new CDF_StoreList(myCurrentDocument);
33 myIsMainDocument = Standard_True;
36 // getting the subcomponents.
38 myIsMainDocument = Standard_False;
40 for ( myList->Init(); myList->More(); myList->Next()) {
41 myCurrentDocument = myList->Value();
42 if(myCurrentDocument != myMainDocument) {
43 myHasSubComponents = Standard_True;
48 myIsMainDocument = Standard_True;
49 myCurrentDocument = myMainDocument;
52 CDF_TryStoreStatus CDF_Store::Check() {
53 if(!PCDM::FindStorageDriver(myMainDocument)) return CDF_TS_NoDriver;
56 // Checking the subcomponent.
57 Handle(CDM_Document) theCurrentDocument;
59 for ( myList->Init(); myList->More(); myList->Next()) {
60 theCurrentDocument = myList->Value();
62 if(theCurrentDocument != myMainDocument) {
63 if( theCurrentDocument->IsModified()) {
65 myLastName = theCurrentDocument->Presentation();
67 if(!PCDM::FindStorageDriver(theCurrentDocument)) return CDF_TS_NoDriver;
76 Standard_ExtString CDF_Store::LastName() const {
77 return myLastName.ToExtString();
80 Standard_ExtString CDF_Store::Folder() const {
81 static TCollection_ExtendedString retv;
82 if(myCurrentDocument->HasRequestedFolder())
83 retv = myCurrentDocument->RequestedFolder();
86 return retv.ToExtString();
89 Standard_ExtString CDF_Store::Name() const {
90 static TCollection_ExtendedString retv;
91 retv = myCurrentDocument->RequestedName();
92 return retv.ToExtString();
96 Standard_Boolean CDF_Store::SetFolder(const Standard_ExtString aFolder) {
97 TCollection_ExtendedString f(aFolder);
100 Standard_Boolean CDF_Store::SetFolder(const TCollection_ExtendedString& aFolder) {
102 TCollection_ExtendedString theFolder(aFolder);
103 Standard_Integer l = theFolder.Length();
105 // if the last character is the folder separator (which is always the first character)
107 // This is correct for Unix systems but not for Windows! VMS and MAC? Thomas Haller, 23.11.01
110 if(theFolder.Value(l) == theFolder.Value(1)) theFolder.Trunc(l-1);
112 if (theFolder.Value(l) == '/' || theFolder.Value(l) == '\\')
113 theFolder.Trunc(l-1);
117 if(theMetaDataDriver->FindFolder(theFolder)) {
118 myCurrentDocument->SetRequestedFolder(theFolder);
119 return Standard_True;
121 return Standard_False;
125 CDF_StoreSetNameStatus CDF_Store::RecheckName () {
126 return SetName(myCurrentDocument->RequestedName());
129 CDF_StoreSetNameStatus CDF_Store::SetName(const TCollection_ExtendedString& aName)
131 TCollection_ExtendedString theName=theMetaDataDriver->SetName(myCurrentDocument,aName);
133 if(myCurrentDocument->IsStored ()) {
134 Handle(CDM_MetaData) E = myCurrentDocument->MetaData();
135 if( E->Folder() == myCurrentDocument->RequestedFolder()
136 && E->Name() == theName) return CDF_SSNS_OK;
139 if(myCurrentDocument->HasRequestedFolder()) {
140 if (theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),theName)) {
141 if(theMetaDataDriver->MetaData(myCurrentDocument->RequestedFolder(),theName)->IsRetrieved())
142 return CDF_SSNS_OpenDocument;
144 myCurrentDocument->SetRequestedName(theName);
145 return CDF_SSNS_ReplacingAnExistentDocument;
149 myCurrentDocument->SetRequestedName(theName);
152 CDF_StoreSetNameStatus CDF_Store::SetName(const Standard_ExtString aName)
154 TCollection_ExtendedString theName(aName);
155 return SetName(theName);
158 void CDF_Store::Realize() {
159 Standard_ProgramError_Raise_if(!myList->IsConsistent(),"information are missing");
160 Handle(CDM_MetaData) m;
162 myStatus = myList->Store(m,myText);
163 if(myStatus==CDF_SS_OK) myPath = m->Path();
165 Standard_ExtString CDF_Store::Path() const {
166 return myPath.ToExtString();
168 Standard_ExtString CDF_Store::MetaDataPath() const {
169 static TCollection_ExtendedString retv;
171 if(myCurrentDocument->IsStored()) retv=myCurrentDocument->MetaData()->Path();
172 return retv.ToExtString();
174 Standard_ExtString CDF_Store::Description() const {
175 static TCollection_ExtendedString retv;
177 if(myMainDocument->FindDescription())
178 retv = myMainDocument->Description();
182 return retv.ToExtString();
185 Standard_Boolean CDF_Store::IsStored() const {
186 return myCurrentDocument->IsStored();
188 Standard_Boolean CDF_Store::IsModified() const {
189 return myCurrentDocument->IsModified();
191 Standard_Boolean CDF_Store::CurrentIsConsistent() const {
192 if(!myCurrentDocument->IsStored())
193 return myCurrentDocument->HasRequestedFolder();
194 return Standard_True;
197 Standard_Boolean CDF_Store::IsConsistent() const {
198 return myList->IsConsistent();
200 Standard_Boolean CDF_Store::HasAPreviousVersion() const {
201 return myCurrentDocument->HasRequestedPreviousVersion();
204 Standard_ExtString CDF_Store::PreviousVersion() const {
205 static TCollection_ExtendedString retv;
206 if(myCurrentDocument->HasRequestedPreviousVersion())
207 retv= myCurrentDocument->RequestedPreviousVersion();
210 return retv.ToExtString();
213 Standard_Boolean CDF_Store::SetPreviousVersion (const Standard_ExtString aPreviousVersion) {
214 if(theMetaDataDriver->HasVersionCapability()) {
215 if(myCurrentDocument->HasRequestedFolder()) {
216 if(theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),myCurrentDocument->RequestedName(),aPreviousVersion)){
218 myCurrentDocument->SetRequestedPreviousVersion(aPreviousVersion);
219 return Standard_True;
222 return Standard_False;
225 return Standard_False;
227 return Standard_True;
230 void CDF_Store::InitComponent() {
234 Standard_Boolean CDF_Store::MoreComponent() const {
235 return myList->More();
238 void CDF_Store::NextComponent() {
241 void CDF_Store::SetCurrent() {
242 myCurrentDocument = myList->Value();
243 myIsMainDocument = myCurrentDocument == myMainDocument;
248 Standard_ExtString CDF_Store::Component() const {
250 static TCollection_ExtendedString retv;
251 retv=myList->Value()->Presentation();
252 return retv.ToExtString();
254 Standard_Boolean CDF_Store::HasSubComponents () const {
255 return myHasSubComponents;
258 void CDF_Store::SetCurrent(const Standard_ExtString aPresentation) {
259 myCurrentDocument = CDM_Document::FindFromPresentation(aPresentation);
260 myIsMainDocument = myCurrentDocument == myMainDocument;
262 void CDF_Store::SetMain() {
263 myCurrentDocument = myMainDocument;
264 myIsMainDocument = Standard_True;
267 Standard_Boolean CDF_Store::IsMainDocument() const {
268 return myIsMainDocument;
271 CDF_SubComponentStatus CDF_Store::SubComponentStatus(const Standard_ExtString aPresentation) const {
272 Handle(CDM_Document) d = CDM_Document::FindFromPresentation(aPresentation);
275 return d->HasRequestedFolder()? CDF_SCS_Consistent : CDF_SCS_Unconsistent;
277 if(d->IsModified()) return CDF_SCS_Modified;
278 return CDF_SCS_Stored;
283 CDF_StoreStatus CDF_Store::StoreStatus() const {
286 Standard_ExtString CDF_Store::AssociatedStatusText() const {
287 return myText.ToExtString();
291 void CDF_Store::FindDefault() {
292 if (!myCurrentDocument->IsStored ()) {
293 myCurrentDocument->SetRequestedFolder(CDF_Session::CurrentSession()->CurrentApplication()->DefaultFolder());
294 // myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->Presentation()));
295 myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->RequestedName()));
298 void CDF_Store::SetComment(const Standard_ExtString aComment) {
299 myCurrentDocument->SetRequestedComment(aComment);
302 Standard_ExtString CDF_Store::Comment() const {
303 static TCollection_ExtendedString retv;
304 retv=myCurrentDocument->RequestedComment();
305 return retv.ToExtString();