1 // Created on: 1997-07-30
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by rmi, Tue Nov 18 08:17:41 1997
20 #include <CDM_Document.ixx>
22 #include <Standard_NullObject.hxx>
24 #include <TCollection_ExtendedString.hxx>
25 #include <Standard_ProgramError.hxx>
27 #include <CDM_PresentationDirectory.hxx>
28 #include <CDM_NamesDirectory.hxx>
30 #include <CDM_ListOfDocument.hxx>
31 #include <CDM_ListIteratorOfListOfDocument.hxx>
34 #include <CDM_DataMapIteratorOfMetaDataLookUpTable.hxx>
36 static CDM_PresentationDirectory& getPresentations() {
37 static CDM_PresentationDirectory thePresentations;
38 return thePresentations;
41 //=======================================================================
42 //function : CDM_Document
44 //=======================================================================
46 CDM_Document::CDM_Document():
47 myResourcesAreLoaded (Standard_False),
48 myValidPresentation (Standard_False),
50 myActualReferenceIdentifier (0),
52 myRequestedComment (""),
53 myRequestedFolderIsDefined (Standard_False),
54 myRequestedNameIsDefined (Standard_False),
55 myRequestedPreviousVersionIsDefined(Standard_False),
56 myFileExtensionWasFound (Standard_False),
57 myDataTypeWasFound (Standard_False),
58 myVersionDataTypeWasFound (Standard_False),
59 myDescriptionWasFound (Standard_False),
60 myDomainWasFound (Standard_False),
61 myStoragePluginWasFound (Standard_False),
62 myDefaultPresentationWasFound (Standard_False)
66 //=======================================================================
69 //=======================================================================
71 void CDM_Document::Destroy() {
72 if(!myMetaData.IsNull()) myMetaData->UnsetDocument();
75 //=======================================================================
78 //=======================================================================
80 void CDM_Document::Update (const Handle(CDM_Document)& /*aToDocument*/,
81 const Standard_Integer /*aReferenceIdentifier*/,
82 const Standard_Address /*aModifContext*/)
86 //=======================================================================
89 //=======================================================================
91 void CDM_Document::Update()
95 //=======================================================================
98 //=======================================================================
100 Standard_Boolean CDM_Document::Update(TCollection_ExtendedString& ErrorString)
104 return Standard_True;
107 //=======================================================================
108 //function : GetAlternativeDocument
110 //=======================================================================
112 Standard_Boolean CDM_Document::GetAlternativeDocument
113 (const TCollection_ExtendedString& aFormat,
114 Handle(CDM_Document)& anAlternativeDocument)
116 anAlternativeDocument = this;
117 return aFormat == StorageFormat();
120 //=======================================================================
121 //function : Extensions
123 //=======================================================================
125 void CDM_Document::Extensions (TColStd_SequenceOfExtendedString& Extensions) const
130 //=======================================================================
131 //function : CreateReference
133 //=======================================================================
135 Standard_Integer CDM_Document::CreateReference
136 (const Handle(CDM_Document)& anOtherDocument)
138 CDM_ListIteratorOfListOfReferences it(myToReferences);
140 for(; it.More(); it.Next()) {
141 if(anOtherDocument == it.Value()->Document())
142 return it.Value()->ReferenceIdentifier();
145 Handle(CDM_Reference) r = new CDM_Reference (this,
147 ++myActualReferenceIdentifier,
148 anOtherDocument->Modifications());
150 anOtherDocument->AddFromReference(r);
151 return r->ReferenceIdentifier();
154 //=======================================================================
155 //function : RemoveAllReferences
157 //=======================================================================
159 void CDM_Document::RemoveAllReferences()
161 CDM_ListIteratorOfListOfReferences it(myToReferences);
163 for(; it.More(); it.Next()) {
164 it.Value()->ToDocument()->RemoveFromReference(it.Value()->ReferenceIdentifier());
166 myToReferences.Clear();
169 //=======================================================================
170 //function : RemoveReference
172 //=======================================================================
174 void CDM_Document::RemoveReference(const Standard_Integer aReferenceIdentifier)
176 CDM_ListIteratorOfListOfReferences it(myToReferences);
178 for(; it.More(); it.Next()) {
179 if(aReferenceIdentifier == it.Value()->ReferenceIdentifier()) {
180 it.Value()->ToDocument()->RemoveFromReference(aReferenceIdentifier);
181 myToReferences.Remove(it);
187 //=======================================================================
188 //function : Document
190 //=======================================================================
192 Handle(CDM_Document) CDM_Document::Document
193 (const Standard_Integer aReferenceIdentifier) const
195 Handle(CDM_Document) theDocument;
197 if(aReferenceIdentifier == 0)
201 Handle(CDM_Reference) theReference = Reference(aReferenceIdentifier);
202 if(!theReference.IsNull()) theDocument = theReference->ToDocument();
207 //=======================================================================
208 //function : Reference
210 //=======================================================================
212 Handle(CDM_Reference) CDM_Document::Reference
213 (const Standard_Integer aReferenceIdentifier) const
215 Handle(CDM_Reference) theReference;
217 CDM_ListIteratorOfListOfReferences it(myToReferences);
219 Standard_Boolean found = Standard_False;
221 for(; it.More() && !found; it.Next()) {
222 found = aReferenceIdentifier == it.Value()->ReferenceIdentifier();
223 if(found) theReference = it.Value();
228 static CDM_ListOfDocument& getListOfDocumentToUpdate() {
229 static CDM_ListOfDocument theListOfDocumentToUpdate;
230 return theListOfDocumentToUpdate;
233 //=======================================================================
234 //function : IsInSession
236 //=======================================================================
238 Standard_Boolean CDM_Document::IsInSession
239 (const Standard_Integer aReferenceIdentifier) const
241 if(aReferenceIdentifier == 0) return Standard_True;
242 Handle(CDM_Reference) theReference=Reference(aReferenceIdentifier);
243 if(theReference.IsNull())
244 Standard_NoSuchObject::Raise("CDM_Document::IsInSession: "
245 "invalid reference identifier");
246 return theReference->IsInSession();
249 //=======================================================================
250 //function : IsStored
252 //=======================================================================
254 Standard_Boolean CDM_Document::IsStored
255 (const Standard_Integer aReferenceIdentifier) const
257 if(aReferenceIdentifier == 0) return IsStored();
258 Handle(CDM_Reference) theReference=Reference(aReferenceIdentifier);
259 if(theReference.IsNull())
260 Standard_NoSuchObject::Raise("CDM_Document::IsInSession: "
261 "invalid reference identifier");
262 return theReference->IsStored();
265 //=======================================================================
268 //=======================================================================
270 TCollection_ExtendedString CDM_Document::Name
271 (const Standard_Integer aReferenceIdentifier) const
273 if(!IsStored(aReferenceIdentifier))
274 Standard_DomainError::Raise("CDM_Document::Name: document is not stored");
276 if(aReferenceIdentifier == 0) return myMetaData->Name();
278 return Reference(aReferenceIdentifier)->MetaData()->Name();
281 //=======================================================================
282 //function : UpdateFromDocuments
284 //=======================================================================
286 void CDM_Document::UpdateFromDocuments(const Standard_Address aModifContext) const
288 Standard_Boolean StartUpdateCycle=getListOfDocumentToUpdate().IsEmpty();
290 CDM_ListIteratorOfListOfReferences it(myFromReferences);
291 for(; it.More() ; it.Next()) {
292 Handle(CDM_Document) theFromDocument=it.Value()->FromDocument();
293 CDM_ListIteratorOfListOfDocument itUpdate;
295 for(; itUpdate.More(); itUpdate.Next()) {
296 if(itUpdate.Value() == theFromDocument) break;
298 if(itUpdate.Value()->ShallowReferences(theFromDocument)) {
299 getListOfDocumentToUpdate().InsertBefore(theFromDocument,itUpdate);
303 if(!itUpdate.More()) getListOfDocumentToUpdate().Append(theFromDocument);
304 theFromDocument->Update(this,it.Value()->ReferenceIdentifier(),aModifContext);
307 if(StartUpdateCycle) {
309 Handle(CDM_Document) theDocumentToUpdate;
310 Handle(CDM_Application) theApplication;
311 TCollection_ExtendedString ErrorString;
313 while(!getListOfDocumentToUpdate().IsEmpty()) {
314 theDocumentToUpdate=getListOfDocumentToUpdate().First();
315 theApplication=theDocumentToUpdate->Application();
317 theApplication->BeginOfUpdate(theDocumentToUpdate);
318 theApplication->EndOfUpdate (theDocumentToUpdate,
319 theDocumentToUpdate->Update(ErrorString),
321 getListOfDocumentToUpdate().RemoveFirst();
326 //=======================================================================
327 //function : ToReferencesNumber
329 //=======================================================================
331 Standard_Integer CDM_Document::ToReferencesNumber() const
333 return myToReferences.Extent();
336 //=======================================================================
337 //function : FromReferencesNumber
339 //=======================================================================
341 Standard_Integer CDM_Document::FromReferencesNumber() const
343 return myFromReferences.Extent();
346 //=======================================================================
347 //function : ShallowReferences
349 //=======================================================================
351 Standard_Boolean CDM_Document::ShallowReferences
352 (const Handle(CDM_Document)& aDocument) const
354 CDM_ListIteratorOfListOfReferences it(myFromReferences);
355 for(; it.More() ; it.Next()) {
356 if(it.Value()->Document() == aDocument) return Standard_True;
358 return Standard_False;
361 //=======================================================================
362 //function : DeepReferences
364 //=======================================================================
366 Standard_Boolean CDM_Document::DeepReferences
367 (const Handle(CDM_Document)& aDocument) const
369 CDM_ListIteratorOfListOfReferences it(myFromReferences);
370 for(; it.More() ; it.Next()) {
371 Handle(CDM_Document) theToDocument=it.Value()->Document();
372 if(!theToDocument.IsNull()) {
373 if(theToDocument == aDocument) return Standard_True;
374 if(theToDocument->DeepReferences(aDocument)) return Standard_True;
377 return Standard_False;
380 //=======================================================================
381 //function : CopyReference
383 //=======================================================================
385 Standard_Integer CDM_Document::CopyReference
386 (const Handle(CDM_Document)& /*aFromDocument*/,
387 const Standard_Integer aReferenceIdentifier)
389 Handle(CDM_Reference) theReference = Reference(aReferenceIdentifier);
390 if(!theReference.IsNull()) {
391 Handle(CDM_Document) theDocument = theReference->Document();
392 if(!theDocument.IsNull()) {
393 return CreateReference(theDocument);
396 return CreateReference(theReference->MetaData(),
397 theReference->Application(),
398 theReference->DocumentVersion(),
399 theReference->UseStorageConfiguration());
401 return 0; //for NT ...
404 //=======================================================================
407 //=======================================================================
409 void CDM_Document::Modify()
414 //=======================================================================
415 //function : UnModify
417 //=======================================================================
419 void CDM_Document::UnModify()
421 myVersion = myStorageVersion;
424 //=======================================================================
425 //function : Modifications
427 //=======================================================================
429 Standard_Integer CDM_Document::Modifications() const
434 //=======================================================================
435 //function : SetModifications
437 //=======================================================================
439 void CDM_Document::SetModifications(const Standard_Integer Modifications)
441 myVersion = Modifications;
444 //=======================================================================
445 //function : IsUpToDate
447 //=======================================================================
449 Standard_Boolean CDM_Document::IsUpToDate
450 (const Standard_Integer aReferenceIdentifier) const
452 return Reference(aReferenceIdentifier)->IsUpToDate();
455 //=======================================================================
456 //function : SetIsUpToDate
458 //=======================================================================
460 void CDM_Document::SetIsUpToDate (const Standard_Integer aReferenceIdentifier)
462 Reference(aReferenceIdentifier)->SetIsUpToDate();
465 //=======================================================================
466 //function : SetComment
468 //=======================================================================
470 void CDM_Document::SetComment(const TCollection_ExtendedString& aComment)
473 myComments.Append(aComment);
476 //=======================================================================
477 //function : AddComment
479 //=======================================================================
481 void CDM_Document::AddComment(const TCollection_ExtendedString& aComment)
483 myComments.Append(aComment);
486 //=======================================================================
487 //function : SetComments
489 //=======================================================================
491 void CDM_Document::SetComments(const TColStd_SequenceOfExtendedString& aComments)
493 myComments = aComments;
496 //=======================================================================
497 //function : Comments
499 //=======================================================================
501 void CDM_Document::Comments(TColStd_SequenceOfExtendedString& aComments) const
503 aComments = myComments;
506 //=======================================================================
509 //=======================================================================
511 Standard_ExtString CDM_Document::Comment() const
513 if (myComments.Length() < 1)
514 return TCollection_ExtendedString().ToExtString();
515 return myComments(1).ToExtString();
518 //=======================================================================
519 //function : Presentation
521 //=======================================================================
523 Standard_ExtString CDM_Document::Presentation()
525 if(!myValidPresentation) ComputePresentation();
526 return myPresentation.ToExtString();
529 //=======================================================================
530 //function : UnvalidPresentation
532 //=======================================================================
534 void CDM_Document::UnvalidPresentation()
536 if(myValidPresentation) {
537 getPresentations().UnBind(myPresentation);
538 myValidPresentation=Standard_False;
542 //=======================================================================
543 //function : ComputePresentation
545 //=======================================================================
547 void CDM_Document::ComputePresentation()
549 TCollection_ExtendedString presentation("");
550 static Standard_Integer theUnnamedDocuments(0);
551 static CDM_NamesDirectory theNames;
552 static CDM_NamesDirectory theTypes;
554 if(!myMetaData.IsNull()) {
555 presentation += myMetaData->Name();
556 if(!theNames.IsBound(presentation)) theNames.Bind(presentation,0);
557 Standard_Integer range = theNames(presentation);
559 theNames(presentation) = range;
562 presentation += range;
568 if(myDefaultPresentationWasFound) {
569 // presentation += "$";
570 presentation += myDefaultPresentation;
571 if(!theTypes.IsBound(presentation)) theTypes.Bind(presentation,0);
572 Standard_Integer range = theTypes(presentation);
574 theTypes(presentation) = range;
576 presentation += range;
579 presentation += TCollection_ExtendedString("Document_");
580 presentation += ++theUnnamedDocuments;
584 if(getPresentations().IsBound(presentation)) {
585 TCollection_ExtendedString Test = presentation;
587 Standard_Integer Count=0;
588 while (getPresentations().IsBound(Test)) {
590 Test = presentation; Test+= "!"; Test+= Count;
596 myPresentation = TCollection_ExtendedString(presentation);
597 myValidPresentation = Standard_True;
598 getPresentations().Bind(presentation,this);
601 //=======================================================================
602 //function : FindFromPresentation
604 //=======================================================================
606 Handle(CDM_Document) CDM_Document::FindFromPresentation
607 (const TCollection_ExtendedString& aPresentation)
609 TCollection_ExtendedString x(aPresentation);
610 if(!getPresentations().IsBound(x)) {
611 Standard_SStream aMsg;
612 aMsg <<"No document having this presentation: " << x << " does exist."
614 Standard_NoSuchObject::Raise(aMsg);
616 return getPresentations()(x);
619 //=======================================================================
620 //function : FindPresentation
622 //=======================================================================
624 Standard_Boolean CDM_Document::FindPresentation
625 (const TCollection_ExtendedString& aPresentation)
627 return getPresentations().IsBound(aPresentation);
630 //=======================================================================
631 //function : IsStored
633 //=======================================================================
635 Standard_Boolean CDM_Document::IsStored() const
637 return !myMetaData.IsNull();
640 //=======================================================================
641 //function : StorageVersion
643 //=======================================================================
645 Standard_Integer CDM_Document::StorageVersion() const
647 return myStorageVersion;
650 //=======================================================================
651 //function : SetMetaData
653 //=======================================================================
655 void CDM_Document::SetMetaData(const Handle(CDM_MetaData)& aMetaData)
657 if(!aMetaData->IsRetrieved() || aMetaData->Document() != This()) {
659 aMetaData->SetDocument(this);
661 // Update the document refencing this MetaData:
662 CDM_DataMapIteratorOfMetaDataLookUpTable it(CDM_MetaData::LookUpTable());
663 for(;it.More();it.Next()) {
664 const Handle(CDM_MetaData)& theMetaData=it.Value();
665 if(theMetaData != aMetaData && theMetaData->IsRetrieved()) {
666 CDM_ListIteratorOfListOfReferences rit(theMetaData->Document()->myToReferences);
667 for(;rit.More();rit.Next()) {
668 rit.Value()->Update(aMetaData);
672 if(!myMetaData.IsNull()) {
673 if(myMetaData->Name() != aMetaData->Name()) UnvalidPresentation();
674 myMetaData->UnsetDocument();
677 UnvalidPresentation();
680 myStorageVersion = Modifications();
682 myMetaData = aMetaData;
684 SetRequestedFolder(aMetaData->Folder());
685 if(aMetaData->HasVersion()) SetRequestedPreviousVersion(aMetaData->Version());
688 //=======================================================================
689 //function : UnsetIsStored
691 //=======================================================================
693 void CDM_Document::UnsetIsStored()
695 if(!myMetaData.IsNull()) {
696 myMetaData->UnsetDocument();
697 // myMetaData.Nullify();
701 //=======================================================================
702 //function : MetaData
704 //=======================================================================
706 Handle(CDM_MetaData) CDM_Document::MetaData() const
708 if(myMetaData.IsNull())
709 Standard_NoSuchObject::Raise("cannot furnish the MetaData of an object "
710 "which is not stored");
714 //=======================================================================
715 //function : SetRequestedComment
717 //=======================================================================
719 void CDM_Document::SetRequestedComment(const TCollection_ExtendedString& aComment)
721 myRequestedComment=aComment;
724 //=======================================================================
725 //function : RequestedComment
727 //=======================================================================
729 TCollection_ExtendedString CDM_Document::RequestedComment() const
731 return myRequestedComment.ToExtString();
734 //=======================================================================
737 //=======================================================================
739 TCollection_ExtendedString CDM_Document::Folder() const {
740 if(myMetaData.IsNull())
741 Standard_NoSuchObject::Raise("cannot furnish the folder of an object "
742 "which is not stored");
743 return myMetaData->Folder();
746 //=======================================================================
747 //function : SetRequestedFolder
749 //=======================================================================
751 void CDM_Document::SetRequestedFolder(const TCollection_ExtendedString& aFolder)
753 TCollection_ExtendedString f(aFolder);
754 if(f.Length() != 0) {
755 myRequestedFolderIsDefined=Standard_True;
756 myRequestedFolder=aFolder;
760 //=======================================================================
761 //function : RequestedFolder
763 //=======================================================================
765 TCollection_ExtendedString CDM_Document::RequestedFolder() const
767 Standard_NoSuchObject_Raise_if (!myRequestedFolderIsDefined,
768 "storage folder is undefined for this document");
769 return myRequestedFolder;
772 //=======================================================================
773 //function : HasRequestedFolder
775 //=======================================================================
777 Standard_Boolean CDM_Document::HasRequestedFolder() const
779 return myRequestedFolderIsDefined;
782 //=======================================================================
783 //function : SetRequestedName
785 //=======================================================================
787 void CDM_Document::SetRequestedName(const TCollection_ExtendedString& aName)
789 myRequestedName=aName;
790 myRequestedNameIsDefined=Standard_True;
793 //=======================================================================
794 //function : RequestedName
796 //=======================================================================
798 TCollection_ExtendedString CDM_Document::RequestedName()
800 if(!myRequestedNameIsDefined) {
801 if(!myMetaData.IsNull())
802 myRequestedName=myMetaData->Name();
804 myRequestedName=Presentation();
806 myRequestedNameIsDefined=Standard_True;
807 return myRequestedName;
810 //=======================================================================
811 //function : SetRequestedPreviousVersion
813 //=======================================================================
815 void CDM_Document::SetRequestedPreviousVersion
816 (const TCollection_ExtendedString& aPreviousVersion)
818 myRequestedPreviousVersionIsDefined=Standard_True;
819 myRequestedPreviousVersion=aPreviousVersion;
822 //=======================================================================
823 //function : RequestedPreviousVersion
825 //=======================================================================
827 TCollection_ExtendedString CDM_Document::RequestedPreviousVersion() const
829 Standard_NoSuchObject_Raise_if (!myRequestedPreviousVersionIsDefined,
830 "PreviousVersion is undefined fro this document");
831 return myRequestedPreviousVersion;
834 //=======================================================================
835 //function : HasRequestedPreviousVersion
837 //=======================================================================
839 Standard_Boolean CDM_Document::HasRequestedPreviousVersion() const
841 return myRequestedPreviousVersionIsDefined;
844 //=======================================================================
845 //function : UnsetRequestedPreviousVersion
847 //=======================================================================
849 void CDM_Document::UnsetRequestedPreviousVersion()
851 myRequestedPreviousVersionIsDefined=Standard_False;
854 //=======================================================================
855 //function : IsOpened
857 //=======================================================================
859 Standard_Boolean CDM_Document::IsOpened() const
861 return !myApplication.IsNull();
864 //=======================================================================
865 //function : IsOpened
867 //=======================================================================
869 Standard_Boolean CDM_Document::IsOpened
870 (const Standard_Integer aReferenceIdentifier) const
872 CDM_ListIteratorOfListOfReferences it(myToReferences);
874 for (; it.More(); it.Next()) {
875 if (aReferenceIdentifier == it.Value()->ReferenceIdentifier())
876 return it.Value()->IsOpened();
878 return Standard_False;
881 //=======================================================================
884 //=======================================================================
886 void CDM_Document::Open(const Handle(CDM_Application)& anApplication)
888 myApplication=anApplication;
891 //=======================================================================
894 //=======================================================================
896 void CDM_Document::Close()
898 switch (CanClose()) {
899 case CDM_CCS_NotOpen:
900 Standard_Failure::Raise("cannot close a document that has not been opened");
902 case CDM_CCS_UnstoredReferenced:
903 Standard_Failure::Raise("cannot close an unstored document which is referenced");
905 case CDM_CCS_ModifiedReferenced:
906 Standard_Failure::Raise("cannot close a document which is referenced when "
907 "the document has been modified since it was stored.");
909 case CDM_CCS_ReferenceRejection:
910 Standard_Failure::Raise("cannot close this document because a document "
911 "referencing it refuses");
916 if(FromReferencesNumber() != 0) {
917 CDM_ListIteratorOfListOfReferences it(myFromReferences);
918 for(; it.More(); it.Next()) {
919 it.Value()->UnsetToDocument(MetaData(),myApplication);
922 RemoveAllReferences();
924 myApplication.Nullify();
925 UnvalidPresentation();
929 //=======================================================================
930 //function : CanClose
932 //=======================================================================
934 CDM_CanCloseStatus CDM_Document::CanClose() const
936 if(!IsOpened()) return CDM_CCS_NotOpen;
938 if(FromReferencesNumber() != 0) {
939 if(!IsStored()) return CDM_CCS_UnstoredReferenced;
940 if(IsModified()) return CDM_CCS_ModifiedReferenced;
943 CDM_ListIteratorOfListOfReferences it(myFromReferences);
944 for(; it.More(); it.Next()) {
945 if(!it.Value()->FromDocument()->CanCloseReference(this, it.Value()->ReferenceIdentifier()))
946 return CDM_CCS_ReferenceRejection;
952 //=======================================================================
953 //function : CanCloseReference
955 //=======================================================================
957 Standard_Boolean CDM_Document::CanCloseReference
958 (const Handle(CDM_Document)& /*aDocument*/,
959 const Standard_Integer /*(aReferenceIdent*/) const
961 return Standard_True;
964 //=======================================================================
965 //function : CloseReference
967 //=======================================================================
969 void CDM_Document::CloseReference (const Handle(CDM_Document)& /*aDocument*/,
970 const Standard_Integer /*aReferenceIdentifier*/)
974 //=======================================================================
975 //function : Application
977 //=======================================================================
979 const Handle(CDM_Application)& CDM_Document::Application() const
982 Standard_Failure::Raise("this document has not yet been opened "
983 "by any application");
984 return myApplication;
987 //=======================================================================
988 //function : IsModified
990 //=======================================================================
992 Standard_Boolean CDM_Document::IsModified() const
994 return Modifications() > StorageVersion();
997 //=======================================================================
1000 //=======================================================================
1002 Standard_OStream& CDM_Document::Print(Standard_OStream& anOStream) const
1007 //=======================================================================
1008 //function : CreateReference
1010 //=======================================================================
1012 void CDM_Document::CreateReference(const Handle(CDM_MetaData)& aMetaData,
1013 const Standard_Integer aReferenceIdentifier,
1014 const Handle(CDM_Application)& anApplication,
1015 const Standard_Integer aToDocumentVersion,
1016 const Standard_Boolean UseStorageConfiguration)
1018 myActualReferenceIdentifier=Max(myActualReferenceIdentifier,aReferenceIdentifier);
1020 if(aMetaData->IsRetrieved()) {
1021 Handle(CDM_Reference) r = new CDM_Reference (this,
1022 aMetaData->Document(),
1023 aReferenceIdentifier,
1024 aToDocumentVersion);
1026 aMetaData->Document()->AddFromReference(r);
1030 Handle(CDM_Reference) r = new CDM_Reference (this,
1032 aReferenceIdentifier,
1035 UseStorageConfiguration);
1040 //=======================================================================
1041 //function : CreateReference
1043 //=======================================================================
1045 Standard_Integer CDM_Document::CreateReference
1046 (const Handle(CDM_MetaData)& aMetaData,
1047 const Handle(CDM_Application)& anApplication,
1048 const Standard_Integer aDocumentVersion,
1049 const Standard_Boolean UseStorageConfiguration)
1051 CDM_ListIteratorOfListOfReferences it(myToReferences);
1053 for(; it.More(); it.Next()) {
1054 if(aMetaData == it.Value()->MetaData())
1055 return it.Value()->ReferenceIdentifier();
1057 Handle(CDM_Reference) r = new CDM_Reference (this,
1059 ++myActualReferenceIdentifier,
1062 UseStorageConfiguration);
1064 return r->ReferenceIdentifier();
1067 //=======================================================================
1068 //function : AddToReference
1070 //=======================================================================
1072 void CDM_Document::AddToReference(const Handle(CDM_Reference)& aReference)
1074 myToReferences.Append(aReference);
1077 //=======================================================================
1078 //function : AddFromReference
1080 //=======================================================================
1082 void CDM_Document::AddFromReference(const Handle(CDM_Reference)& aReference)
1084 myFromReferences.Append(aReference);
1087 //=======================================================================
1088 //function : RemoveFromReference
1090 //=======================================================================
1092 void CDM_Document::RemoveFromReference(const Standard_Integer aReferenceIdentifier)
1094 CDM_ListIteratorOfListOfReferences it(myFromReferences);
1096 for(; it.More(); it.Next()) {
1097 if(aReferenceIdentifier == it.Value()->ReferenceIdentifier()) {
1098 myFromReferences.Remove(it);
1104 //=======================================================================
1105 //function : GetResource
1107 //=======================================================================
1109 TCollection_ExtendedString GetResource (const TCollection_ExtendedString aFormat,
1110 const TCollection_ExtendedString anItem)
1112 TCollection_ExtendedString theResource;
1113 theResource+= aFormat;
1115 theResource+= anItem;
1119 static void FIND (const Handle(Resource_Manager)& theDocumentResource,
1120 const TCollection_ExtendedString& theResourceName,
1121 Standard_Boolean& IsDef,
1122 TCollection_ExtendedString& theValue)
1124 IsDef=UTL::Find(theDocumentResource,theResourceName);
1125 if(IsDef) theValue=UTL::Value(theDocumentResource,theResourceName);
1129 //=======================================================================
1130 //function : StorageResource
1132 //=======================================================================
1134 Handle(Resource_Manager) CDM_Document::StorageResource()
1136 if(myApplication.IsNull()) {
1137 Standard_SStream aMsg;
1138 aMsg << "this document of format "<< StorageFormat()
1139 << " has not yet been opened by any application. "<< endl;
1140 Standard_Failure::Raise(aMsg);
1142 return myApplication->Resources();
1145 //=======================================================================
1146 //function : LoadResources
1148 //=======================================================================
1150 void CDM_Document::LoadResources()
1152 if(!myResourcesAreLoaded) {
1153 Handle(Resource_Manager) theDocumentResource = StorageResource();
1155 TCollection_ExtendedString theFormat=StorageFormat(); theFormat+=".";
1156 TCollection_ExtendedString theResourceName;
1158 theResourceName=theFormat;
1159 theResourceName+="FileExtension";
1160 FIND(theDocumentResource,
1161 theResourceName,myFileExtensionWasFound,myFileExtension);
1163 theResourceName=theFormat;
1164 theResourceName+="DataType";
1165 FIND(theDocumentResource,theResourceName,myDataTypeWasFound,myDataType);
1168 theResourceName=theFormat;
1169 theResourceName+="VersionDataType";
1170 FIND(theDocumentResource,
1171 theResourceName,myVersionDataTypeWasFound,myVersionDataType);
1173 theResourceName=theFormat;
1174 theResourceName+="Description";
1175 FIND(theDocumentResource,theResourceName,myDescriptionWasFound,myDescription);
1177 theResourceName=theFormat;
1178 theResourceName+="Domain";
1179 FIND(theDocumentResource,theResourceName,myDomainWasFound,myDomain);
1181 theResourceName=theFormat;
1182 theResourceName+="Presentation";
1183 FIND(theDocumentResource,
1184 theResourceName,myDefaultPresentationWasFound,myDefaultPresentation);
1186 theResourceName=theFormat;
1187 theResourceName+="StoragePlugin";
1188 TCollection_ExtendedString thePluginId;
1189 FIND(theDocumentResource,theResourceName,myStoragePluginWasFound,thePluginId);
1190 if(myStoragePluginWasFound) myStoragePlugin=UTL::GUID(thePluginId);
1191 myResourcesAreLoaded=Standard_True;
1193 // cout << "resource Loaded: " << "Format: " << theFormat << ", FileExtension:" << myFileExtension << ", DataType:" << myDataType << ", VersionDataType:" << myVersionDataType << ", Description:" << myDescription << ", Domain:" << myDomain << endl;
1198 //=======================================================================
1199 //function : FindFileExtension
1201 //=======================================================================
1203 Standard_Boolean CDM_Document::FindFileExtension ()
1206 return myFileExtensionWasFound;
1209 //=======================================================================
1210 //function : FileExtension
1212 //=======================================================================
1214 TCollection_ExtendedString CDM_Document::FileExtension()
1217 return myFileExtension;
1220 //=======================================================================
1221 //function : FindDataType
1223 //=======================================================================
1225 Standard_Boolean CDM_Document::FindDataType ()
1228 return myDataTypeWasFound;
1231 //=======================================================================
1232 //function : DataType
1234 //=======================================================================
1236 TCollection_ExtendedString CDM_Document::DataType()
1242 //=======================================================================
1243 //function : FindVersionDataType
1245 //=======================================================================
1247 Standard_Boolean CDM_Document::FindVersionDataType ()
1250 return myVersionDataTypeWasFound;
1253 //=======================================================================
1254 //function : VersionDataType
1256 //=======================================================================
1258 TCollection_ExtendedString CDM_Document::VersionDataType()
1261 return myVersionDataType;
1264 //=======================================================================
1265 //function : FindDescription
1267 //=======================================================================
1269 Standard_Boolean CDM_Document::FindDescription ()
1272 return myDescriptionWasFound;
1275 //=======================================================================
1276 //function : Description
1278 //=======================================================================
1280 TCollection_ExtendedString CDM_Document::Description()
1283 return myDescription;
1286 //=======================================================================
1287 //function : FindDomain
1289 //=======================================================================
1291 Standard_Boolean CDM_Document::FindDomain ()
1294 return myDomainWasFound;
1297 //=======================================================================
1300 //=======================================================================
1302 TCollection_ExtendedString CDM_Document::Domain()
1308 //=======================================================================
1309 //function : FindStoragePlugin
1311 //=======================================================================
1313 Standard_Boolean CDM_Document::FindStoragePlugin()
1316 return myStoragePluginWasFound;
1319 //=======================================================================
1320 //function : StoragePlugin
1322 //=======================================================================
1324 Standard_GUID CDM_Document::StoragePlugin()
1327 return myStoragePlugin;
1330 //=======================================================================
1331 //function : IsReadOnly
1333 //=======================================================================
1335 Standard_Boolean CDM_Document::IsReadOnly() const
1337 if(IsStored()) return myMetaData->IsReadOnly();
1338 return Standard_False;
1341 //=======================================================================
1342 //function : IsReadOnly
1344 //=======================================================================
1346 Standard_Boolean CDM_Document::IsReadOnly
1347 (const Standard_Integer aReferenceIdentifier) const
1349 return Reference(aReferenceIdentifier)->IsReadOnly();
1352 //=======================================================================
1353 //function : SetIsReadOnly
1355 //=======================================================================
1357 void CDM_Document::SetIsReadOnly()
1359 if(IsStored()) myMetaData->SetIsReadOnly();
1362 //=======================================================================
1363 //function : UnsetIsReadOnly
1365 //=======================================================================
1367 void CDM_Document::UnsetIsReadOnly()
1369 if(IsStored()) myMetaData->UnsetIsReadOnly();
1372 //=======================================================================
1373 //function : ReferenceCounter
1375 //=======================================================================
1377 Standard_Integer CDM_Document::ReferenceCounter() const
1379 return myActualReferenceIdentifier;
1382 //=======================================================================
1383 //function : SetReferenceCounter
1385 //=======================================================================
1387 void CDM_Document::SetReferenceCounter (const Standard_Integer aReferenceCounter)
1389 myActualReferenceIdentifier=aReferenceCounter;