1 // Created on: 1997-07-30
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Modified by rmi, Tue Nov 18 08:17:41 1997
24 #include <CDM_Document.ixx>
26 #include <Standard_NullObject.hxx>
28 #include <TCollection_ExtendedString.hxx>
29 #include <Standard_ProgramError.hxx>
31 #include <CDM_PresentationDirectory.hxx>
32 #include <CDM_NamesDirectory.hxx>
34 #include <CDM_ListOfDocument.hxx>
35 #include <CDM_ListIteratorOfListOfDocument.hxx>
38 #include <CDM_DataMapIteratorOfMetaDataLookUpTable.hxx>
40 static CDM_PresentationDirectory& getPresentations() {
41 static CDM_PresentationDirectory thePresentations;
42 return thePresentations;
45 //=======================================================================
46 //function : CDM_Document
48 //=======================================================================
50 CDM_Document::CDM_Document():
51 myResourcesAreLoaded (Standard_False),
52 myValidPresentation (Standard_False),
54 myActualReferenceIdentifier (0),
56 myRequestedComment (""),
57 myRequestedFolderIsDefined (Standard_False),
58 myRequestedNameIsDefined (Standard_False),
59 myRequestedPreviousVersionIsDefined(Standard_False),
60 myFileExtensionWasFound (Standard_False),
61 myDataTypeWasFound (Standard_False),
62 myVersionDataTypeWasFound (Standard_False),
63 myDescriptionWasFound (Standard_False),
64 myDomainWasFound (Standard_False),
65 myStoragePluginWasFound (Standard_False),
66 myDefaultPresentationWasFound (Standard_False)
70 //=======================================================================
73 //=======================================================================
75 void CDM_Document::Destroy() {
76 if(!myMetaData.IsNull()) myMetaData->UnsetDocument();
79 //=======================================================================
82 //=======================================================================
84 void CDM_Document::Update (const Handle(CDM_Document)& /*aToDocument*/,
85 const Standard_Integer /*aReferenceIdentifier*/,
86 const Standard_Address /*aModifContext*/)
90 //=======================================================================
93 //=======================================================================
95 void CDM_Document::Update()
99 //=======================================================================
102 //=======================================================================
104 Standard_Boolean CDM_Document::Update(TCollection_ExtendedString& ErrorString)
108 return Standard_True;
111 //=======================================================================
112 //function : GetAlternativeDocument
114 //=======================================================================
116 Standard_Boolean CDM_Document::GetAlternativeDocument
117 (const TCollection_ExtendedString& aFormat,
118 Handle(CDM_Document)& anAlternativeDocument)
120 anAlternativeDocument = this;
121 return aFormat == StorageFormat();
124 //=======================================================================
125 //function : Extensions
127 //=======================================================================
129 void CDM_Document::Extensions (TColStd_SequenceOfExtendedString& Extensions) const
134 //=======================================================================
135 //function : CreateReference
137 //=======================================================================
139 Standard_Integer CDM_Document::CreateReference
140 (const Handle(CDM_Document)& anOtherDocument)
142 CDM_ListIteratorOfListOfReferences it(myToReferences);
144 for(; it.More(); it.Next()) {
145 if(anOtherDocument == it.Value()->Document())
146 return it.Value()->ReferenceIdentifier();
149 Handle(CDM_Reference) r = new CDM_Reference (this,
151 ++myActualReferenceIdentifier,
152 anOtherDocument->Modifications());
154 anOtherDocument->AddFromReference(r);
155 return r->ReferenceIdentifier();
158 //=======================================================================
159 //function : RemoveAllReferences
161 //=======================================================================
163 void CDM_Document::RemoveAllReferences()
165 CDM_ListIteratorOfListOfReferences it(myToReferences);
167 for(; it.More(); it.Next()) {
168 it.Value()->ToDocument()->RemoveFromReference(it.Value()->ReferenceIdentifier());
170 myToReferences.Clear();
173 //=======================================================================
174 //function : RemoveReference
176 //=======================================================================
178 void CDM_Document::RemoveReference(const Standard_Integer aReferenceIdentifier)
180 CDM_ListIteratorOfListOfReferences it(myToReferences);
182 for(; it.More(); it.Next()) {
183 if(aReferenceIdentifier == it.Value()->ReferenceIdentifier()) {
184 it.Value()->ToDocument()->RemoveFromReference(aReferenceIdentifier);
185 myToReferences.Remove(it);
191 //=======================================================================
192 //function : Document
194 //=======================================================================
196 Handle(CDM_Document) CDM_Document::Document
197 (const Standard_Integer aReferenceIdentifier) const
199 Handle(CDM_Document) theDocument;
201 if(aReferenceIdentifier == 0)
205 Handle(CDM_Reference) theReference = Reference(aReferenceIdentifier);
206 if(!theReference.IsNull()) theDocument = theReference->ToDocument();
211 //=======================================================================
212 //function : Reference
214 //=======================================================================
216 Handle(CDM_Reference) CDM_Document::Reference
217 (const Standard_Integer aReferenceIdentifier) const
219 Handle(CDM_Reference) theReference;
221 CDM_ListIteratorOfListOfReferences it(myToReferences);
223 Standard_Boolean found = Standard_False;
225 for(; it.More() && !found; it.Next()) {
226 found = aReferenceIdentifier == it.Value()->ReferenceIdentifier();
227 if(found) theReference = it.Value();
232 static CDM_ListOfDocument& getListOfDocumentToUpdate() {
233 static CDM_ListOfDocument theListOfDocumentToUpdate;
234 return theListOfDocumentToUpdate;
237 //=======================================================================
238 //function : IsInSession
240 //=======================================================================
242 Standard_Boolean CDM_Document::IsInSession
243 (const Standard_Integer aReferenceIdentifier) const
245 if(aReferenceIdentifier == 0) return Standard_True;
246 Handle(CDM_Reference) theReference=Reference(aReferenceIdentifier);
247 if(theReference.IsNull())
248 Standard_NoSuchObject::Raise("CDM_Document::IsInSession: "
249 "invalid reference identifier");
250 return theReference->IsInSession();
253 //=======================================================================
254 //function : IsStored
256 //=======================================================================
258 Standard_Boolean CDM_Document::IsStored
259 (const Standard_Integer aReferenceIdentifier) const
261 if(aReferenceIdentifier == 0) return IsStored();
262 Handle(CDM_Reference) theReference=Reference(aReferenceIdentifier);
263 if(theReference.IsNull())
264 Standard_NoSuchObject::Raise("CDM_Document::IsInSession: "
265 "invalid reference identifier");
266 return theReference->IsStored();
269 //=======================================================================
272 //=======================================================================
274 TCollection_ExtendedString CDM_Document::Name
275 (const Standard_Integer aReferenceIdentifier) const
277 if(!IsStored(aReferenceIdentifier))
278 Standard_DomainError::Raise("CDM_Document::Name: document is not stored");
280 if(aReferenceIdentifier == 0) return myMetaData->Name();
282 return Reference(aReferenceIdentifier)->MetaData()->Name();
285 //=======================================================================
286 //function : UpdateFromDocuments
288 //=======================================================================
290 void CDM_Document::UpdateFromDocuments(const Standard_Address aModifContext) const
292 Standard_Boolean StartUpdateCycle=getListOfDocumentToUpdate().IsEmpty();
294 CDM_ListIteratorOfListOfReferences it(myFromReferences);
295 for(; it.More() ; it.Next()) {
296 Handle(CDM_Document) theFromDocument=it.Value()->FromDocument();
297 CDM_ListIteratorOfListOfDocument itUpdate;
299 for(; itUpdate.More(); itUpdate.Next()) {
300 if(itUpdate.Value() == theFromDocument) break;
302 if(itUpdate.Value()->ShallowReferences(theFromDocument)) {
303 getListOfDocumentToUpdate().InsertBefore(theFromDocument,itUpdate);
307 if(!itUpdate.More()) getListOfDocumentToUpdate().Append(theFromDocument);
308 theFromDocument->Update(this,it.Value()->ReferenceIdentifier(),aModifContext);
311 if(StartUpdateCycle) {
313 Handle(CDM_Document) theDocumentToUpdate;
314 Handle(CDM_Application) theApplication;
315 TCollection_ExtendedString ErrorString;
317 while(!getListOfDocumentToUpdate().IsEmpty()) {
318 theDocumentToUpdate=getListOfDocumentToUpdate().First();
319 theApplication=theDocumentToUpdate->Application();
321 theApplication->BeginOfUpdate(theDocumentToUpdate);
322 theApplication->EndOfUpdate (theDocumentToUpdate,
323 theDocumentToUpdate->Update(ErrorString),
325 getListOfDocumentToUpdate().RemoveFirst();
330 //=======================================================================
331 //function : ToReferencesNumber
333 //=======================================================================
335 Standard_Integer CDM_Document::ToReferencesNumber() const
337 return myToReferences.Extent();
340 //=======================================================================
341 //function : FromReferencesNumber
343 //=======================================================================
345 Standard_Integer CDM_Document::FromReferencesNumber() const
347 return myFromReferences.Extent();
350 //=======================================================================
351 //function : ShallowReferences
353 //=======================================================================
355 Standard_Boolean CDM_Document::ShallowReferences
356 (const Handle(CDM_Document)& aDocument) const
358 CDM_ListIteratorOfListOfReferences it(myFromReferences);
359 for(; it.More() ; it.Next()) {
360 if(it.Value()->Document() == aDocument) return Standard_True;
362 return Standard_False;
365 //=======================================================================
366 //function : DeepReferences
368 //=======================================================================
370 Standard_Boolean CDM_Document::DeepReferences
371 (const Handle(CDM_Document)& aDocument) const
373 CDM_ListIteratorOfListOfReferences it(myFromReferences);
374 for(; it.More() ; it.Next()) {
375 Handle(CDM_Document) theToDocument=it.Value()->Document();
376 if(!theToDocument.IsNull()) {
377 if(theToDocument == aDocument) return Standard_True;
378 if(theToDocument->DeepReferences(aDocument)) return Standard_True;
381 return Standard_False;
384 //=======================================================================
385 //function : CopyReference
387 //=======================================================================
389 Standard_Integer CDM_Document::CopyReference
390 (const Handle(CDM_Document)& /*aFromDocument*/,
391 const Standard_Integer aReferenceIdentifier)
393 Handle(CDM_Reference) theReference = Reference(aReferenceIdentifier);
394 if(!theReference.IsNull()) {
395 Handle(CDM_Document) theDocument = theReference->Document();
396 if(!theDocument.IsNull()) {
397 return CreateReference(theDocument);
400 return CreateReference(theReference->MetaData(),
401 theReference->Application(),
402 theReference->DocumentVersion(),
403 theReference->UseStorageConfiguration());
405 return 0; //for NT ...
408 //=======================================================================
411 //=======================================================================
413 void CDM_Document::Modify()
418 //=======================================================================
419 //function : UnModify
421 //=======================================================================
423 void CDM_Document::UnModify()
425 myVersion = myStorageVersion;
428 //=======================================================================
429 //function : Modifications
431 //=======================================================================
433 Standard_Integer CDM_Document::Modifications() const
438 //=======================================================================
439 //function : SetModifications
441 //=======================================================================
443 void CDM_Document::SetModifications(const Standard_Integer Modifications)
445 myVersion = Modifications;
448 //=======================================================================
449 //function : IsUpToDate
451 //=======================================================================
453 Standard_Boolean CDM_Document::IsUpToDate
454 (const Standard_Integer aReferenceIdentifier) const
456 return Reference(aReferenceIdentifier)->IsUpToDate();
459 //=======================================================================
460 //function : SetIsUpToDate
462 //=======================================================================
464 void CDM_Document::SetIsUpToDate (const Standard_Integer aReferenceIdentifier)
466 Reference(aReferenceIdentifier)->SetIsUpToDate();
469 //=======================================================================
470 //function : SetComment
472 //=======================================================================
474 void CDM_Document::SetComment(const TCollection_ExtendedString& aComment)
477 myComments.Append(aComment);
480 //=======================================================================
481 //function : AddComment
483 //=======================================================================
485 void CDM_Document::AddComment(const TCollection_ExtendedString& aComment)
487 myComments.Append(aComment);
490 //=======================================================================
491 //function : SetComments
493 //=======================================================================
495 void CDM_Document::SetComments(const TColStd_SequenceOfExtendedString& aComments)
497 myComments = aComments;
500 //=======================================================================
501 //function : Comments
503 //=======================================================================
505 void CDM_Document::Comments(TColStd_SequenceOfExtendedString& aComments) const
507 aComments = myComments;
510 //=======================================================================
513 //=======================================================================
515 Standard_ExtString CDM_Document::Comment() const
517 if (myComments.Length() < 1)
518 return TCollection_ExtendedString().ToExtString();
519 return myComments(1).ToExtString();
522 //=======================================================================
523 //function : Presentation
525 //=======================================================================
527 Standard_ExtString CDM_Document::Presentation()
529 if(!myValidPresentation) ComputePresentation();
530 return myPresentation.ToExtString();
533 //=======================================================================
534 //function : UnvalidPresentation
536 //=======================================================================
538 void CDM_Document::UnvalidPresentation()
540 if(myValidPresentation) {
541 getPresentations().UnBind(myPresentation);
542 myValidPresentation=Standard_False;
546 //=======================================================================
547 //function : ComputePresentation
549 //=======================================================================
551 void CDM_Document::ComputePresentation()
553 TCollection_ExtendedString presentation("");
554 static Standard_Integer theUnnamedDocuments(0);
555 static CDM_NamesDirectory theNames;
556 static CDM_NamesDirectory theTypes;
558 if(!myMetaData.IsNull()) {
559 presentation += myMetaData->Name();
560 if(!theNames.IsBound(presentation)) theNames.Bind(presentation,0);
561 Standard_Integer range = theNames(presentation);
563 theNames(presentation) = range;
566 presentation += range;
572 if(myDefaultPresentationWasFound) {
573 // presentation += "$";
574 presentation += myDefaultPresentation;
575 if(!theTypes.IsBound(presentation)) theTypes.Bind(presentation,0);
576 Standard_Integer range = theTypes(presentation);
578 theTypes(presentation) = range;
580 presentation += range;
583 presentation += TCollection_ExtendedString("Document_");
584 presentation += ++theUnnamedDocuments;
588 if(getPresentations().IsBound(presentation)) {
589 TCollection_ExtendedString Test = presentation;
591 Standard_Integer Count=0;
592 while (getPresentations().IsBound(Test)) {
594 Test = presentation; Test+= "!"; Test+= Count;
600 myPresentation = TCollection_ExtendedString(presentation);
601 myValidPresentation = Standard_True;
602 getPresentations().Bind(presentation,this);
605 //=======================================================================
606 //function : FindFromPresentation
608 //=======================================================================
610 Handle(CDM_Document) CDM_Document::FindFromPresentation
611 (const TCollection_ExtendedString& aPresentation)
613 TCollection_ExtendedString x(aPresentation);
614 if(!getPresentations().IsBound(x)) {
615 Standard_SStream aMsg;
616 aMsg <<"No document having this presentation: " << x << " does exist."
618 Standard_NoSuchObject::Raise(aMsg);
620 return getPresentations()(x);
623 //=======================================================================
624 //function : FindPresentation
626 //=======================================================================
628 Standard_Boolean CDM_Document::FindPresentation
629 (const TCollection_ExtendedString& aPresentation)
631 return getPresentations().IsBound(aPresentation);
634 //=======================================================================
635 //function : IsStored
637 //=======================================================================
639 Standard_Boolean CDM_Document::IsStored() const
641 return !myMetaData.IsNull();
644 //=======================================================================
645 //function : StorageVersion
647 //=======================================================================
649 Standard_Integer CDM_Document::StorageVersion() const
651 return myStorageVersion;
654 //=======================================================================
655 //function : SetMetaData
657 //=======================================================================
659 void CDM_Document::SetMetaData(const Handle(CDM_MetaData)& aMetaData)
661 if(!aMetaData->IsRetrieved() || aMetaData->Document() != This()) {
663 aMetaData->SetDocument(this);
665 // Update the document refencing this MetaData:
666 CDM_DataMapIteratorOfMetaDataLookUpTable it(CDM_MetaData::LookUpTable());
667 for(;it.More();it.Next()) {
668 const Handle(CDM_MetaData)& theMetaData=it.Value();
669 if(theMetaData != aMetaData && theMetaData->IsRetrieved()) {
670 CDM_ListIteratorOfListOfReferences rit(theMetaData->Document()->myToReferences);
671 for(;rit.More();rit.Next()) {
672 rit.Value()->Update(aMetaData);
676 if(!myMetaData.IsNull()) {
677 if(myMetaData->Name() != aMetaData->Name()) UnvalidPresentation();
678 myMetaData->UnsetDocument();
681 UnvalidPresentation();
684 myStorageVersion = Modifications();
686 myMetaData = aMetaData;
688 SetRequestedFolder(aMetaData->Folder());
689 if(aMetaData->HasVersion()) SetRequestedPreviousVersion(aMetaData->Version());
692 //=======================================================================
693 //function : UnsetIsStored
695 //=======================================================================
697 void CDM_Document::UnsetIsStored()
699 if(!myMetaData.IsNull()) {
700 myMetaData->UnsetDocument();
701 // myMetaData.Nullify();
705 //=======================================================================
706 //function : MetaData
708 //=======================================================================
710 Handle(CDM_MetaData) CDM_Document::MetaData() const
712 if(myMetaData.IsNull())
713 Standard_NoSuchObject::Raise("cannot furnish the MetaData of an object "
714 "which is not stored");
718 //=======================================================================
719 //function : SetRequestedComment
721 //=======================================================================
723 void CDM_Document::SetRequestedComment(const TCollection_ExtendedString& aComment)
725 myRequestedComment=aComment;
728 //=======================================================================
729 //function : RequestedComment
731 //=======================================================================
733 TCollection_ExtendedString CDM_Document::RequestedComment() const
735 return myRequestedComment.ToExtString();
738 //=======================================================================
741 //=======================================================================
743 TCollection_ExtendedString CDM_Document::Folder() const {
744 if(myMetaData.IsNull())
745 Standard_NoSuchObject::Raise("cannot furnish the folder of an object "
746 "which is not stored");
747 return myMetaData->Folder();
750 //=======================================================================
751 //function : SetRequestedFolder
753 //=======================================================================
755 void CDM_Document::SetRequestedFolder(const TCollection_ExtendedString& aFolder)
757 TCollection_ExtendedString f(aFolder);
758 if(f.Length() != 0) {
759 myRequestedFolderIsDefined=Standard_True;
760 myRequestedFolder=aFolder;
764 //=======================================================================
765 //function : RequestedFolder
767 //=======================================================================
769 TCollection_ExtendedString CDM_Document::RequestedFolder() const
771 Standard_NoSuchObject_Raise_if (!myRequestedFolderIsDefined,
772 "storage folder is undefined for this document");
773 return myRequestedFolder;
776 //=======================================================================
777 //function : HasRequestedFolder
779 //=======================================================================
781 Standard_Boolean CDM_Document::HasRequestedFolder() const
783 return myRequestedFolderIsDefined;
786 //=======================================================================
787 //function : SetRequestedName
789 //=======================================================================
791 void CDM_Document::SetRequestedName(const TCollection_ExtendedString& aName)
793 myRequestedName=aName;
794 myRequestedNameIsDefined=Standard_True;
797 //=======================================================================
798 //function : RequestedName
800 //=======================================================================
802 TCollection_ExtendedString CDM_Document::RequestedName()
804 if(!myRequestedNameIsDefined) {
805 if(!myMetaData.IsNull())
806 myRequestedName=myMetaData->Name();
808 myRequestedName=Presentation();
810 myRequestedNameIsDefined=Standard_True;
811 return myRequestedName;
814 //=======================================================================
815 //function : SetRequestedPreviousVersion
817 //=======================================================================
819 void CDM_Document::SetRequestedPreviousVersion
820 (const TCollection_ExtendedString& aPreviousVersion)
822 myRequestedPreviousVersionIsDefined=Standard_True;
823 myRequestedPreviousVersion=aPreviousVersion;
826 //=======================================================================
827 //function : RequestedPreviousVersion
829 //=======================================================================
831 TCollection_ExtendedString CDM_Document::RequestedPreviousVersion() const
833 Standard_NoSuchObject_Raise_if (!myRequestedPreviousVersionIsDefined,
834 "PreviousVersion is undefined fro this document");
835 return myRequestedPreviousVersion;
838 //=======================================================================
839 //function : HasRequestedPreviousVersion
841 //=======================================================================
843 Standard_Boolean CDM_Document::HasRequestedPreviousVersion() const
845 return myRequestedPreviousVersionIsDefined;
848 //=======================================================================
849 //function : UnsetRequestedPreviousVersion
851 //=======================================================================
853 void CDM_Document::UnsetRequestedPreviousVersion()
855 myRequestedPreviousVersionIsDefined=Standard_False;
858 //=======================================================================
859 //function : IsOpened
861 //=======================================================================
863 Standard_Boolean CDM_Document::IsOpened() const
865 return !myApplication.IsNull();
868 //=======================================================================
869 //function : IsOpened
871 //=======================================================================
873 Standard_Boolean CDM_Document::IsOpened
874 (const Standard_Integer aReferenceIdentifier) const
876 CDM_ListIteratorOfListOfReferences it(myToReferences);
878 for (; it.More(); it.Next()) {
879 if (aReferenceIdentifier == it.Value()->ReferenceIdentifier())
880 return it.Value()->IsOpened();
882 return Standard_False;
885 //=======================================================================
888 //=======================================================================
890 void CDM_Document::Open(const Handle(CDM_Application)& anApplication)
892 myApplication=anApplication;
895 //=======================================================================
898 //=======================================================================
900 void CDM_Document::Close()
902 switch (CanClose()) {
903 case CDM_CCS_NotOpen:
904 Standard_Failure::Raise("cannot close a document that has not been opened");
906 case CDM_CCS_UnstoredReferenced:
907 Standard_Failure::Raise("cannot close an unstored document which is referenced");
909 case CDM_CCS_ModifiedReferenced:
910 Standard_Failure::Raise("cannot close a document which is referenced when "
911 "the document has been modified since it was stored.");
913 case CDM_CCS_ReferenceRejection:
914 Standard_Failure::Raise("cannot close this document because a document "
915 "referencing it refuses");
920 if(FromReferencesNumber() != 0) {
921 CDM_ListIteratorOfListOfReferences it(myFromReferences);
922 for(; it.More(); it.Next()) {
923 it.Value()->UnsetToDocument(MetaData(),myApplication);
926 RemoveAllReferences();
928 myApplication.Nullify();
929 UnvalidPresentation();
933 //=======================================================================
934 //function : CanClose
936 //=======================================================================
938 CDM_CanCloseStatus CDM_Document::CanClose() const
940 if(!IsOpened()) return CDM_CCS_NotOpen;
942 if(FromReferencesNumber() != 0) {
943 if(!IsStored()) return CDM_CCS_UnstoredReferenced;
944 if(IsModified()) return CDM_CCS_ModifiedReferenced;
947 CDM_ListIteratorOfListOfReferences it(myFromReferences);
948 for(; it.More(); it.Next()) {
949 if(!it.Value()->FromDocument()->CanCloseReference(this, it.Value()->ReferenceIdentifier()))
950 return CDM_CCS_ReferenceRejection;
956 //=======================================================================
957 //function : CanCloseReference
959 //=======================================================================
961 Standard_Boolean CDM_Document::CanCloseReference
962 (const Handle(CDM_Document)& /*aDocument*/,
963 const Standard_Integer /*(aReferenceIdent*/) const
965 return Standard_True;
968 //=======================================================================
969 //function : CloseReference
971 //=======================================================================
973 void CDM_Document::CloseReference (const Handle(CDM_Document)& /*aDocument*/,
974 const Standard_Integer /*aReferenceIdentifier*/)
978 //=======================================================================
979 //function : Application
981 //=======================================================================
983 const Handle(CDM_Application)& CDM_Document::Application() const
986 Standard_Failure::Raise("this document has not yet been opened "
987 "by any application");
988 return myApplication;
991 //=======================================================================
992 //function : IsModified
994 //=======================================================================
996 Standard_Boolean CDM_Document::IsModified() const
998 return Modifications() > StorageVersion();
1001 //=======================================================================
1004 //=======================================================================
1006 Standard_OStream& CDM_Document::Print(Standard_OStream& anOStream) const
1011 //=======================================================================
1012 //function : CreateReference
1014 //=======================================================================
1016 void CDM_Document::CreateReference(const Handle(CDM_MetaData)& aMetaData,
1017 const Standard_Integer aReferenceIdentifier,
1018 const Handle(CDM_Application)& anApplication,
1019 const Standard_Integer aToDocumentVersion,
1020 const Standard_Boolean UseStorageConfiguration)
1022 myActualReferenceIdentifier=Max(myActualReferenceIdentifier,aReferenceIdentifier);
1024 if(aMetaData->IsRetrieved()) {
1025 Handle(CDM_Reference) r = new CDM_Reference (this,
1026 aMetaData->Document(),
1027 aReferenceIdentifier,
1028 aToDocumentVersion);
1030 aMetaData->Document()->AddFromReference(r);
1034 Handle(CDM_Reference) r = new CDM_Reference (this,
1036 aReferenceIdentifier,
1039 UseStorageConfiguration);
1044 //=======================================================================
1045 //function : CreateReference
1047 //=======================================================================
1049 Standard_Integer CDM_Document::CreateReference
1050 (const Handle(CDM_MetaData)& aMetaData,
1051 const Handle(CDM_Application)& anApplication,
1052 const Standard_Integer aDocumentVersion,
1053 const Standard_Boolean UseStorageConfiguration)
1055 CDM_ListIteratorOfListOfReferences it(myToReferences);
1057 for(; it.More(); it.Next()) {
1058 if(aMetaData == it.Value()->MetaData())
1059 return it.Value()->ReferenceIdentifier();
1061 Handle(CDM_Reference) r = new CDM_Reference (this,
1063 ++myActualReferenceIdentifier,
1066 UseStorageConfiguration);
1068 return r->ReferenceIdentifier();
1071 //=======================================================================
1072 //function : AddToReference
1074 //=======================================================================
1076 void CDM_Document::AddToReference(const Handle(CDM_Reference)& aReference)
1078 myToReferences.Append(aReference);
1081 //=======================================================================
1082 //function : AddFromReference
1084 //=======================================================================
1086 void CDM_Document::AddFromReference(const Handle(CDM_Reference)& aReference)
1088 myFromReferences.Append(aReference);
1091 //=======================================================================
1092 //function : RemoveFromReference
1094 //=======================================================================
1096 void CDM_Document::RemoveFromReference(const Standard_Integer aReferenceIdentifier)
1098 CDM_ListIteratorOfListOfReferences it(myFromReferences);
1100 for(; it.More(); it.Next()) {
1101 if(aReferenceIdentifier == it.Value()->ReferenceIdentifier()) {
1102 myFromReferences.Remove(it);
1108 //=======================================================================
1109 //function : GetResource
1111 //=======================================================================
1113 TCollection_ExtendedString GetResource (const TCollection_ExtendedString aFormat,
1114 const TCollection_ExtendedString anItem)
1116 TCollection_ExtendedString theResource;
1117 theResource+= aFormat;
1119 theResource+= anItem;
1123 static void FIND (const Handle(Resource_Manager)& theDocumentResource,
1124 const TCollection_ExtendedString& theResourceName,
1125 Standard_Boolean& IsDef,
1126 TCollection_ExtendedString& theValue)
1128 IsDef=UTL::Find(theDocumentResource,theResourceName);
1129 if(IsDef) theValue=UTL::Value(theDocumentResource,theResourceName);
1133 //=======================================================================
1134 //function : StorageResource
1136 //=======================================================================
1138 Handle(Resource_Manager) CDM_Document::StorageResource()
1140 if(myApplication.IsNull()) {
1141 Standard_SStream aMsg;
1142 aMsg << "this document of format "<< StorageFormat()
1143 << " has not yet been opened by any application. "<< endl;
1144 Standard_Failure::Raise(aMsg);
1146 return myApplication->Resources();
1149 //=======================================================================
1150 //function : LoadResources
1152 //=======================================================================
1154 void CDM_Document::LoadResources()
1156 if(!myResourcesAreLoaded) {
1157 Handle(Resource_Manager) theDocumentResource = StorageResource();
1159 TCollection_ExtendedString theFormat=StorageFormat(); theFormat+=".";
1160 TCollection_ExtendedString theResourceName;
1162 theResourceName=theFormat;
1163 theResourceName+="FileExtension";
1164 FIND(theDocumentResource,
1165 theResourceName,myFileExtensionWasFound,myFileExtension);
1167 theResourceName=theFormat;
1168 theResourceName+="DataType";
1169 FIND(theDocumentResource,theResourceName,myDataTypeWasFound,myDataType);
1172 theResourceName=theFormat;
1173 theResourceName+="VersionDataType";
1174 FIND(theDocumentResource,
1175 theResourceName,myVersionDataTypeWasFound,myVersionDataType);
1177 theResourceName=theFormat;
1178 theResourceName+="Description";
1179 FIND(theDocumentResource,theResourceName,myDescriptionWasFound,myDescription);
1181 theResourceName=theFormat;
1182 theResourceName+="Domain";
1183 FIND(theDocumentResource,theResourceName,myDomainWasFound,myDomain);
1185 theResourceName=theFormat;
1186 theResourceName+="Presentation";
1187 FIND(theDocumentResource,
1188 theResourceName,myDefaultPresentationWasFound,myDefaultPresentation);
1190 theResourceName=theFormat;
1191 theResourceName+="StoragePlugin";
1192 TCollection_ExtendedString thePluginId;
1193 FIND(theDocumentResource,theResourceName,myStoragePluginWasFound,thePluginId);
1194 if(myStoragePluginWasFound) myStoragePlugin=UTL::GUID(thePluginId);
1195 myResourcesAreLoaded=Standard_True;
1197 // cout << "resource Loaded: " << "Format: " << theFormat << ", FileExtension:" << myFileExtension << ", DataType:" << myDataType << ", VersionDataType:" << myVersionDataType << ", Description:" << myDescription << ", Domain:" << myDomain << endl;
1202 //=======================================================================
1203 //function : FindFileExtension
1205 //=======================================================================
1207 Standard_Boolean CDM_Document::FindFileExtension ()
1210 return myFileExtensionWasFound;
1213 //=======================================================================
1214 //function : FileExtension
1216 //=======================================================================
1218 TCollection_ExtendedString CDM_Document::FileExtension()
1221 return myFileExtension;
1224 //=======================================================================
1225 //function : FindDataType
1227 //=======================================================================
1229 Standard_Boolean CDM_Document::FindDataType ()
1232 return myDataTypeWasFound;
1235 //=======================================================================
1236 //function : DataType
1238 //=======================================================================
1240 TCollection_ExtendedString CDM_Document::DataType()
1246 //=======================================================================
1247 //function : FindVersionDataType
1249 //=======================================================================
1251 Standard_Boolean CDM_Document::FindVersionDataType ()
1254 return myVersionDataTypeWasFound;
1257 //=======================================================================
1258 //function : VersionDataType
1260 //=======================================================================
1262 TCollection_ExtendedString CDM_Document::VersionDataType()
1265 return myVersionDataType;
1268 //=======================================================================
1269 //function : FindDescription
1271 //=======================================================================
1273 Standard_Boolean CDM_Document::FindDescription ()
1276 return myDescriptionWasFound;
1279 //=======================================================================
1280 //function : Description
1282 //=======================================================================
1284 TCollection_ExtendedString CDM_Document::Description()
1287 return myDescription;
1290 //=======================================================================
1291 //function : FindDomain
1293 //=======================================================================
1295 Standard_Boolean CDM_Document::FindDomain ()
1298 return myDomainWasFound;
1301 //=======================================================================
1304 //=======================================================================
1306 TCollection_ExtendedString CDM_Document::Domain()
1312 //=======================================================================
1313 //function : FindStoragePlugin
1315 //=======================================================================
1317 Standard_Boolean CDM_Document::FindStoragePlugin()
1320 return myStoragePluginWasFound;
1323 //=======================================================================
1324 //function : StoragePlugin
1326 //=======================================================================
1328 Standard_GUID CDM_Document::StoragePlugin()
1331 return myStoragePlugin;
1334 //=======================================================================
1335 //function : IsReadOnly
1337 //=======================================================================
1339 Standard_Boolean CDM_Document::IsReadOnly() const
1341 if(IsStored()) return myMetaData->IsReadOnly();
1342 return Standard_False;
1345 //=======================================================================
1346 //function : IsReadOnly
1348 //=======================================================================
1350 Standard_Boolean CDM_Document::IsReadOnly
1351 (const Standard_Integer aReferenceIdentifier) const
1353 return Reference(aReferenceIdentifier)->IsReadOnly();
1356 //=======================================================================
1357 //function : SetIsReadOnly
1359 //=======================================================================
1361 void CDM_Document::SetIsReadOnly()
1363 if(IsStored()) myMetaData->SetIsReadOnly();
1366 //=======================================================================
1367 //function : UnsetIsReadOnly
1369 //=======================================================================
1371 void CDM_Document::UnsetIsReadOnly()
1373 if(IsStored()) myMetaData->UnsetIsReadOnly();
1376 //=======================================================================
1377 //function : ReferenceCounter
1379 //=======================================================================
1381 Standard_Integer CDM_Document::ReferenceCounter() const
1383 return myActualReferenceIdentifier;
1386 //=======================================================================
1387 //function : SetReferenceCounter
1389 //=======================================================================
1391 void CDM_Document::SetReferenceCounter (const Standard_Integer aReferenceCounter)
1393 myActualReferenceIdentifier=aReferenceCounter;