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
19 #include <CDM_Application.hxx>
20 #include <CDM_DataMapIteratorOfMetaDataLookUpTable.hxx>
21 #include <CDM_Document.hxx>
22 #include <CDM_ListIteratorOfListOfDocument.hxx>
23 #include <CDM_ListOfDocument.hxx>
24 #include <CDM_MetaData.hxx>
25 #include <CDM_NamesDirectory.hxx>
26 #include <CDM_PresentationDirectory.hxx>
27 #include <CDM_Reference.hxx>
28 #include <CDM_ReferenceIterator.hxx>
29 #include <Resource_Manager.hxx>
30 #include <Standard_DomainError.hxx>
31 #include <Standard_Failure.hxx>
32 #include <Standard_GUID.hxx>
33 #include <Standard_NoSuchObject.hxx>
34 #include <Standard_NullObject.hxx>
35 #include <Standard_ProgramError.hxx>
36 #include <Standard_Type.hxx>
37 #include <TCollection_ExtendedString.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(CDM_Document,Standard_Transient)
42 static CDM_PresentationDirectory& getPresentations() {
43 static CDM_PresentationDirectory thePresentations;
44 return thePresentations;
47 //=======================================================================
48 //function : CDM_Document
50 //=======================================================================
52 CDM_Document::CDM_Document():
53 myResourcesAreLoaded (Standard_False),
54 myValidPresentation (Standard_False),
56 myActualReferenceIdentifier (0),
58 myRequestedComment (""),
59 myRequestedFolderIsDefined (Standard_False),
60 myRequestedNameIsDefined (Standard_False),
61 myRequestedPreviousVersionIsDefined(Standard_False),
62 myFileExtensionWasFound (Standard_False),
63 myDescriptionWasFound (Standard_False)
67 //=======================================================================
68 //function : ~CDM_Document
70 //=======================================================================
72 CDM_Document::~CDM_Document()
74 if(!myMetaData.IsNull()) myMetaData->UnsetDocument();
77 //=======================================================================
80 //=======================================================================
82 void CDM_Document::Update (const Handle(CDM_Document)& /*aToDocument*/,
83 const Standard_Integer /*aReferenceIdentifier*/,
84 const Standard_Address /*aModifContext*/)
88 //=======================================================================
91 //=======================================================================
93 void CDM_Document::Update()
97 //=======================================================================
100 //=======================================================================
102 Standard_Boolean CDM_Document::Update(TCollection_ExtendedString& ErrorString)
106 return Standard_True;
109 //=======================================================================
110 //function : GetAlternativeDocument
112 //=======================================================================
114 Standard_Boolean CDM_Document::GetAlternativeDocument
115 (const TCollection_ExtendedString& aFormat,
116 Handle(CDM_Document)& anAlternativeDocument)
118 anAlternativeDocument = this;
119 return aFormat == StorageFormat();
122 //=======================================================================
123 //function : Extensions
125 //=======================================================================
127 void CDM_Document::Extensions (TColStd_SequenceOfExtendedString& Extensions) const
132 //=======================================================================
133 //function : CreateReference
135 //=======================================================================
137 Standard_Integer CDM_Document::CreateReference
138 (const Handle(CDM_Document)& anOtherDocument)
140 CDM_ListIteratorOfListOfReferences it(myToReferences);
142 for(; it.More(); it.Next()) {
143 if(anOtherDocument == it.Value()->Document())
144 return it.Value()->ReferenceIdentifier();
147 Handle(CDM_Reference) r = new CDM_Reference (this,
149 ++myActualReferenceIdentifier,
150 anOtherDocument->Modifications());
152 anOtherDocument->AddFromReference(r);
153 return r->ReferenceIdentifier();
156 //=======================================================================
157 //function : RemoveAllReferences
159 //=======================================================================
161 void CDM_Document::RemoveAllReferences()
163 CDM_ListIteratorOfListOfReferences it(myToReferences);
165 for(; it.More(); it.Next()) {
166 it.Value()->ToDocument()->RemoveFromReference(it.Value()->ReferenceIdentifier());
168 myToReferences.Clear();
171 //=======================================================================
172 //function : RemoveReference
174 //=======================================================================
176 void CDM_Document::RemoveReference(const Standard_Integer aReferenceIdentifier)
178 CDM_ListIteratorOfListOfReferences it(myToReferences);
180 for(; it.More(); it.Next()) {
181 if(aReferenceIdentifier == it.Value()->ReferenceIdentifier()) {
182 it.Value()->ToDocument()->RemoveFromReference(aReferenceIdentifier);
183 myToReferences.Remove(it);
189 //=======================================================================
190 //function : Document
192 //=======================================================================
194 Handle(CDM_Document) CDM_Document::Document
195 (const Standard_Integer aReferenceIdentifier) const
197 Handle(CDM_Document) theDocument;
199 if(aReferenceIdentifier == 0)
203 Handle(CDM_Reference) theReference = Reference(aReferenceIdentifier);
204 if(!theReference.IsNull()) theDocument = theReference->ToDocument();
209 //=======================================================================
210 //function : Reference
212 //=======================================================================
214 Handle(CDM_Reference) CDM_Document::Reference
215 (const Standard_Integer aReferenceIdentifier) const
217 Handle(CDM_Reference) theReference;
219 CDM_ListIteratorOfListOfReferences it(myToReferences);
221 Standard_Boolean found = Standard_False;
223 for(; it.More() && !found; it.Next()) {
224 found = aReferenceIdentifier == it.Value()->ReferenceIdentifier();
225 if(found) theReference = it.Value();
230 static CDM_ListOfDocument& getListOfDocumentToUpdate() {
231 static CDM_ListOfDocument theListOfDocumentToUpdate;
232 return theListOfDocumentToUpdate;
235 //=======================================================================
236 //function : IsInSession
238 //=======================================================================
240 Standard_Boolean CDM_Document::IsInSession
241 (const Standard_Integer aReferenceIdentifier) const
243 if(aReferenceIdentifier == 0) return Standard_True;
244 Handle(CDM_Reference) theReference=Reference(aReferenceIdentifier);
245 if(theReference.IsNull())
246 throw Standard_NoSuchObject("CDM_Document::IsInSession: "
247 "invalid reference identifier");
248 return theReference->IsInSession();
251 //=======================================================================
252 //function : IsStored
254 //=======================================================================
256 Standard_Boolean CDM_Document::IsStored
257 (const Standard_Integer aReferenceIdentifier) const
259 if(aReferenceIdentifier == 0) return IsStored();
260 Handle(CDM_Reference) theReference=Reference(aReferenceIdentifier);
261 if(theReference.IsNull())
262 throw Standard_NoSuchObject("CDM_Document::IsInSession: "
263 "invalid reference identifier");
264 return theReference->IsStored();
267 //=======================================================================
270 //=======================================================================
272 TCollection_ExtendedString CDM_Document::Name
273 (const Standard_Integer aReferenceIdentifier) const
275 if(!IsStored(aReferenceIdentifier))
276 throw Standard_DomainError("CDM_Document::Name: document is not stored");
278 if(aReferenceIdentifier == 0) return myMetaData->Name();
280 return Reference(aReferenceIdentifier)->MetaData()->Name();
283 //=======================================================================
284 //function : UpdateFromDocuments
286 //=======================================================================
288 void CDM_Document::UpdateFromDocuments(const Standard_Address aModifContext) const
290 Standard_Boolean StartUpdateCycle=getListOfDocumentToUpdate().IsEmpty();
292 CDM_ListIteratorOfListOfReferences it(myFromReferences);
293 for(; it.More() ; it.Next()) {
294 Handle(CDM_Document) theFromDocument=it.Value()->FromDocument();
295 CDM_ListIteratorOfListOfDocument itUpdate;
297 for(; itUpdate.More(); itUpdate.Next()) {
298 if(itUpdate.Value() == theFromDocument) break;
300 if(itUpdate.Value()->ShallowReferences(theFromDocument)) {
301 getListOfDocumentToUpdate().InsertBefore(theFromDocument,itUpdate);
305 if(!itUpdate.More()) getListOfDocumentToUpdate().Append(theFromDocument);
306 theFromDocument->Update(this,it.Value()->ReferenceIdentifier(),aModifContext);
309 if(StartUpdateCycle) {
311 Handle(CDM_Document) theDocumentToUpdate;
312 Handle(CDM_Application) theApplication;
313 TCollection_ExtendedString ErrorString;
315 while(!getListOfDocumentToUpdate().IsEmpty()) {
316 theDocumentToUpdate=getListOfDocumentToUpdate().First();
317 theApplication=theDocumentToUpdate->Application();
319 theApplication->BeginOfUpdate(theDocumentToUpdate);
320 theApplication->EndOfUpdate (theDocumentToUpdate,
321 theDocumentToUpdate->Update(ErrorString),
323 getListOfDocumentToUpdate().RemoveFirst();
328 //=======================================================================
329 //function : ToReferencesNumber
331 //=======================================================================
333 Standard_Integer CDM_Document::ToReferencesNumber() const
335 return myToReferences.Extent();
338 //=======================================================================
339 //function : FromReferencesNumber
341 //=======================================================================
343 Standard_Integer CDM_Document::FromReferencesNumber() const
345 return myFromReferences.Extent();
348 //=======================================================================
349 //function : ShallowReferences
351 //=======================================================================
353 Standard_Boolean CDM_Document::ShallowReferences
354 (const Handle(CDM_Document)& aDocument) const
356 CDM_ListIteratorOfListOfReferences it(myFromReferences);
357 for(; it.More() ; it.Next()) {
358 if(it.Value()->Document() == aDocument) return Standard_True;
360 return Standard_False;
363 //=======================================================================
364 //function : DeepReferences
366 //=======================================================================
368 Standard_Boolean CDM_Document::DeepReferences
369 (const Handle(CDM_Document)& aDocument) const
371 CDM_ListIteratorOfListOfReferences it(myFromReferences);
372 for(; it.More() ; it.Next()) {
373 Handle(CDM_Document) theToDocument=it.Value()->Document();
374 if(!theToDocument.IsNull()) {
375 if(theToDocument == aDocument) return Standard_True;
376 if(theToDocument->DeepReferences(aDocument)) return Standard_True;
379 return Standard_False;
382 //=======================================================================
383 //function : CopyReference
385 //=======================================================================
387 Standard_Integer CDM_Document::CopyReference
388 (const Handle(CDM_Document)& /*aFromDocument*/,
389 const Standard_Integer aReferenceIdentifier)
391 Handle(CDM_Reference) theReference = Reference(aReferenceIdentifier);
392 if(!theReference.IsNull()) {
393 Handle(CDM_Document) theDocument = theReference->Document();
394 if(!theDocument.IsNull()) {
395 return CreateReference(theDocument);
398 return CreateReference(theReference->MetaData(),
399 theReference->Application(),
400 theReference->DocumentVersion(),
401 theReference->UseStorageConfiguration());
403 return 0; //for NT ...
406 //=======================================================================
409 //=======================================================================
411 void CDM_Document::Modify()
416 //=======================================================================
417 //function : UnModify
419 //=======================================================================
421 void CDM_Document::UnModify()
423 myVersion = myStorageVersion;
426 //=======================================================================
427 //function : Modifications
429 //=======================================================================
431 Standard_Integer CDM_Document::Modifications() const
436 //=======================================================================
437 //function : SetModifications
439 //=======================================================================
441 void CDM_Document::SetModifications(const Standard_Integer Modifications)
443 myVersion = Modifications;
446 //=======================================================================
447 //function : IsUpToDate
449 //=======================================================================
451 Standard_Boolean CDM_Document::IsUpToDate
452 (const Standard_Integer aReferenceIdentifier) const
454 return Reference(aReferenceIdentifier)->IsUpToDate();
457 //=======================================================================
458 //function : SetIsUpToDate
460 //=======================================================================
462 void CDM_Document::SetIsUpToDate (const Standard_Integer aReferenceIdentifier)
464 Reference(aReferenceIdentifier)->SetIsUpToDate();
467 //=======================================================================
468 //function : SetComment
470 //=======================================================================
472 void CDM_Document::SetComment(const TCollection_ExtendedString& aComment)
475 myComments.Append(aComment);
478 //=======================================================================
479 //function : AddComment
481 //=======================================================================
483 void CDM_Document::AddComment(const TCollection_ExtendedString& aComment)
485 myComments.Append(aComment);
488 //=======================================================================
489 //function : SetComments
491 //=======================================================================
493 void CDM_Document::SetComments(const TColStd_SequenceOfExtendedString& aComments)
495 myComments = aComments;
498 //=======================================================================
499 //function : Comments
501 //=======================================================================
503 void CDM_Document::Comments(TColStd_SequenceOfExtendedString& aComments) const
505 aComments = myComments;
508 //=======================================================================
511 //=======================================================================
513 Standard_ExtString CDM_Document::Comment() const
515 if (myComments.Length() < 1)
517 return myComments(1).ToExtString();
520 //=======================================================================
521 //function : Presentation
523 //=======================================================================
525 Standard_ExtString CDM_Document::Presentation()
527 if(!myValidPresentation) ComputePresentation();
528 return myPresentation.ToExtString();
531 //=======================================================================
532 //function : UnvalidPresentation
534 //=======================================================================
536 void CDM_Document::UnvalidPresentation()
538 if(myValidPresentation) {
539 getPresentations().UnBind(myPresentation);
540 myValidPresentation=Standard_False;
544 //=======================================================================
545 //function : ComputePresentation
547 //=======================================================================
549 void CDM_Document::ComputePresentation()
551 TCollection_ExtendedString presentation("");
552 static Standard_Integer theUnnamedDocuments(0);
553 static CDM_NamesDirectory theNames;
555 if(!myMetaData.IsNull()) {
556 presentation += myMetaData->Name();
557 if(!theNames.IsBound(presentation)) theNames.Bind(presentation,0);
558 Standard_Integer range = theNames(presentation);
560 theNames(presentation) = range;
563 presentation += range;
568 presentation = "Document_";
569 presentation += ++theUnnamedDocuments;
572 if(getPresentations().IsBound(presentation)) {
573 TCollection_ExtendedString Test = presentation;
575 Standard_Integer Count=0;
576 while (getPresentations().IsBound(Test)) {
578 Test = presentation; Test+= "!"; Test+= Count;
584 myPresentation = TCollection_ExtendedString(presentation);
585 myValidPresentation = Standard_True;
586 getPresentations().Bind(presentation,this);
589 //=======================================================================
590 //function : FindFromPresentation
592 //=======================================================================
594 Handle(CDM_Document) CDM_Document::FindFromPresentation
595 (const TCollection_ExtendedString& aPresentation)
597 TCollection_ExtendedString x(aPresentation);
598 if(!getPresentations().IsBound(x)) {
599 Standard_SStream aMsg;
600 aMsg <<"No document having this presentation: " << x << " does exist."
602 throw Standard_NoSuchObject(aMsg.str().c_str());
604 return getPresentations()(x);
607 //=======================================================================
608 //function : FindPresentation
610 //=======================================================================
612 Standard_Boolean CDM_Document::FindPresentation
613 (const TCollection_ExtendedString& aPresentation)
615 return getPresentations().IsBound(aPresentation);
618 //=======================================================================
619 //function : IsStored
621 //=======================================================================
623 Standard_Boolean CDM_Document::IsStored() const
625 return !myMetaData.IsNull();
628 //=======================================================================
629 //function : StorageVersion
631 //=======================================================================
633 Standard_Integer CDM_Document::StorageVersion() const
635 return myStorageVersion;
638 //=======================================================================
639 //function : SetMetaData
641 //=======================================================================
643 void CDM_Document::SetMetaData(const Handle(CDM_MetaData)& aMetaData)
645 if(!aMetaData->IsRetrieved() || aMetaData->Document() != This()) {
647 aMetaData->SetDocument(this);
649 // Update the document refencing this MetaData:
650 CDM_DataMapIteratorOfMetaDataLookUpTable it(CDM_MetaData::LookUpTable());
651 for(;it.More();it.Next()) {
652 const Handle(CDM_MetaData)& theMetaData=it.Value();
653 if(theMetaData != aMetaData && theMetaData->IsRetrieved()) {
654 CDM_ListIteratorOfListOfReferences rit(theMetaData->Document()->myToReferences);
655 for(;rit.More();rit.Next()) {
656 rit.Value()->Update(aMetaData);
660 if(!myMetaData.IsNull()) {
661 if(myMetaData->Name() != aMetaData->Name()) UnvalidPresentation();
662 myMetaData->UnsetDocument();
665 UnvalidPresentation();
668 myStorageVersion = Modifications();
670 myMetaData = aMetaData;
672 SetRequestedFolder(aMetaData->Folder());
673 if(aMetaData->HasVersion()) SetRequestedPreviousVersion(aMetaData->Version());
676 //=======================================================================
677 //function : UnsetIsStored
679 //=======================================================================
681 void CDM_Document::UnsetIsStored()
683 if(!myMetaData.IsNull()) {
684 myMetaData->UnsetDocument();
685 // myMetaData.Nullify();
689 //=======================================================================
690 //function : MetaData
692 //=======================================================================
694 Handle(CDM_MetaData) CDM_Document::MetaData() const
696 if(myMetaData.IsNull())
697 throw Standard_NoSuchObject("cannot furnish the MetaData of an object "
698 "which is not stored");
702 //=======================================================================
703 //function : SetRequestedComment
705 //=======================================================================
707 void CDM_Document::SetRequestedComment(const TCollection_ExtendedString& aComment)
709 myRequestedComment=aComment;
712 //=======================================================================
713 //function : RequestedComment
715 //=======================================================================
717 TCollection_ExtendedString CDM_Document::RequestedComment() const
719 return myRequestedComment.ToExtString();
722 //=======================================================================
725 //=======================================================================
727 TCollection_ExtendedString CDM_Document::Folder() const {
728 if(myMetaData.IsNull())
729 throw Standard_NoSuchObject("cannot furnish the folder of an object "
730 "which is not stored");
731 return myMetaData->Folder();
734 //=======================================================================
735 //function : SetRequestedFolder
737 //=======================================================================
739 void CDM_Document::SetRequestedFolder(const TCollection_ExtendedString& aFolder)
741 TCollection_ExtendedString f(aFolder);
742 if(f.Length() != 0) {
743 myRequestedFolderIsDefined=Standard_True;
744 myRequestedFolder=aFolder;
748 //=======================================================================
749 //function : RequestedFolder
751 //=======================================================================
753 TCollection_ExtendedString CDM_Document::RequestedFolder() const
755 Standard_NoSuchObject_Raise_if (!myRequestedFolderIsDefined,
756 "storage folder is undefined for this document");
757 return myRequestedFolder;
760 //=======================================================================
761 //function : HasRequestedFolder
763 //=======================================================================
765 Standard_Boolean CDM_Document::HasRequestedFolder() const
767 return myRequestedFolderIsDefined;
770 //=======================================================================
771 //function : SetRequestedName
773 //=======================================================================
775 void CDM_Document::SetRequestedName(const TCollection_ExtendedString& aName)
777 myRequestedName=aName;
778 myRequestedNameIsDefined=Standard_True;
781 //=======================================================================
782 //function : RequestedName
784 //=======================================================================
786 TCollection_ExtendedString CDM_Document::RequestedName()
788 if(!myRequestedNameIsDefined) {
789 if(!myMetaData.IsNull())
790 myRequestedName=myMetaData->Name();
792 myRequestedName=Presentation();
794 myRequestedNameIsDefined=Standard_True;
795 return myRequestedName;
798 //=======================================================================
799 //function : SetRequestedPreviousVersion
801 //=======================================================================
803 void CDM_Document::SetRequestedPreviousVersion
804 (const TCollection_ExtendedString& aPreviousVersion)
806 myRequestedPreviousVersionIsDefined=Standard_True;
807 myRequestedPreviousVersion=aPreviousVersion;
810 //=======================================================================
811 //function : RequestedPreviousVersion
813 //=======================================================================
815 TCollection_ExtendedString CDM_Document::RequestedPreviousVersion() const
817 Standard_NoSuchObject_Raise_if (!myRequestedPreviousVersionIsDefined,
818 "PreviousVersion is undefined fro this document");
819 return myRequestedPreviousVersion;
822 //=======================================================================
823 //function : HasRequestedPreviousVersion
825 //=======================================================================
827 Standard_Boolean CDM_Document::HasRequestedPreviousVersion() const
829 return myRequestedPreviousVersionIsDefined;
832 //=======================================================================
833 //function : UnsetRequestedPreviousVersion
835 //=======================================================================
837 void CDM_Document::UnsetRequestedPreviousVersion()
839 myRequestedPreviousVersionIsDefined=Standard_False;
842 //=======================================================================
843 //function : IsOpened
845 //=======================================================================
847 Standard_Boolean CDM_Document::IsOpened() const
849 return !myApplication.IsNull();
852 //=======================================================================
853 //function : IsOpened
855 //=======================================================================
857 Standard_Boolean CDM_Document::IsOpened
858 (const Standard_Integer aReferenceIdentifier) const
860 CDM_ListIteratorOfListOfReferences it(myToReferences);
862 for (; it.More(); it.Next()) {
863 if (aReferenceIdentifier == it.Value()->ReferenceIdentifier())
864 return it.Value()->IsOpened();
866 return Standard_False;
869 //=======================================================================
872 //=======================================================================
874 void CDM_Document::Open(const Handle(CDM_Application)& anApplication)
876 myApplication=anApplication;
879 //=======================================================================
882 //=======================================================================
884 void CDM_Document::Close()
886 switch (CanClose()) {
887 case CDM_CCS_NotOpen:
888 throw Standard_Failure("cannot close a document that has not been opened");
890 case CDM_CCS_UnstoredReferenced:
891 throw Standard_Failure("cannot close an unstored document which is referenced");
893 case CDM_CCS_ModifiedReferenced:
894 throw Standard_Failure("cannot close a document which is referenced when "
895 "the document has been modified since it was stored.");
897 case CDM_CCS_ReferenceRejection:
898 throw Standard_Failure("cannot close this document because a document "
899 "referencing it refuses");
904 if(FromReferencesNumber() != 0) {
905 CDM_ListIteratorOfListOfReferences it(myFromReferences);
906 for(; it.More(); it.Next()) {
907 it.Value()->UnsetToDocument(MetaData(),myApplication);
910 RemoveAllReferences();
912 myApplication.Nullify();
913 UnvalidPresentation();
917 //=======================================================================
918 //function : CanClose
920 //=======================================================================
922 CDM_CanCloseStatus CDM_Document::CanClose() const
924 if(!IsOpened()) return CDM_CCS_NotOpen;
926 if(FromReferencesNumber() != 0) {
927 if(!IsStored()) return CDM_CCS_UnstoredReferenced;
928 if(IsModified()) return CDM_CCS_ModifiedReferenced;
931 CDM_ListIteratorOfListOfReferences it(myFromReferences);
932 for(; it.More(); it.Next()) {
933 if(!it.Value()->FromDocument()->CanCloseReference(this, it.Value()->ReferenceIdentifier()))
934 return CDM_CCS_ReferenceRejection;
940 //=======================================================================
941 //function : CanCloseReference
943 //=======================================================================
945 Standard_Boolean CDM_Document::CanCloseReference
946 (const Handle(CDM_Document)& /*aDocument*/,
947 const Standard_Integer /*(aReferenceIdent*/) const
949 return Standard_True;
952 //=======================================================================
953 //function : CloseReference
955 //=======================================================================
957 void CDM_Document::CloseReference (const Handle(CDM_Document)& /*aDocument*/,
958 const Standard_Integer /*aReferenceIdentifier*/)
962 //=======================================================================
963 //function : Application
965 //=======================================================================
967 const Handle(CDM_Application)& CDM_Document::Application() const
970 throw Standard_Failure("this document has not yet been opened "
971 "by any application");
972 return myApplication;
975 //=======================================================================
976 //function : IsModified
978 //=======================================================================
980 Standard_Boolean CDM_Document::IsModified() const
982 return Modifications() > StorageVersion();
985 //=======================================================================
988 //=======================================================================
990 Standard_OStream& CDM_Document::Print(Standard_OStream& anOStream) const
995 //=======================================================================
996 //function : CreateReference
998 //=======================================================================
1000 void CDM_Document::CreateReference(const Handle(CDM_MetaData)& aMetaData,
1001 const Standard_Integer aReferenceIdentifier,
1002 const Handle(CDM_Application)& anApplication,
1003 const Standard_Integer aToDocumentVersion,
1004 const Standard_Boolean UseStorageConfiguration)
1006 myActualReferenceIdentifier=Max(myActualReferenceIdentifier,aReferenceIdentifier);
1008 if(aMetaData->IsRetrieved()) {
1009 Handle(CDM_Reference) r = new CDM_Reference (this,
1010 aMetaData->Document(),
1011 aReferenceIdentifier,
1012 aToDocumentVersion);
1014 aMetaData->Document()->AddFromReference(r);
1018 Handle(CDM_Reference) r = new CDM_Reference (this,
1020 aReferenceIdentifier,
1023 UseStorageConfiguration);
1028 //=======================================================================
1029 //function : CreateReference
1031 //=======================================================================
1033 Standard_Integer CDM_Document::CreateReference
1034 (const Handle(CDM_MetaData)& aMetaData,
1035 const Handle(CDM_Application)& anApplication,
1036 const Standard_Integer aDocumentVersion,
1037 const Standard_Boolean UseStorageConfiguration)
1039 CDM_ListIteratorOfListOfReferences it(myToReferences);
1041 for(; it.More(); it.Next()) {
1042 if(aMetaData == it.Value()->MetaData())
1043 return it.Value()->ReferenceIdentifier();
1045 Handle(CDM_Reference) r = new CDM_Reference (this,
1047 ++myActualReferenceIdentifier,
1050 UseStorageConfiguration);
1052 return r->ReferenceIdentifier();
1055 //=======================================================================
1056 //function : AddToReference
1058 //=======================================================================
1060 void CDM_Document::AddToReference(const Handle(CDM_Reference)& aReference)
1062 myToReferences.Append(aReference);
1065 //=======================================================================
1066 //function : AddFromReference
1068 //=======================================================================
1070 void CDM_Document::AddFromReference(const Handle(CDM_Reference)& aReference)
1072 myFromReferences.Append(aReference);
1075 //=======================================================================
1076 //function : RemoveFromReference
1078 //=======================================================================
1080 void CDM_Document::RemoveFromReference(const Standard_Integer aReferenceIdentifier)
1082 CDM_ListIteratorOfListOfReferences it(myFromReferences);
1084 for(; it.More(); it.Next()) {
1085 if(aReferenceIdentifier == it.Value()->ReferenceIdentifier()) {
1086 myFromReferences.Remove(it);
1092 //=======================================================================
1093 //function : GetResource
1095 //=======================================================================
1097 TCollection_ExtendedString GetResource (const TCollection_ExtendedString aFormat,
1098 const TCollection_ExtendedString anItem)
1100 TCollection_ExtendedString theResource;
1101 theResource+= aFormat;
1103 theResource+= anItem;
1107 static void FIND (const Handle(Resource_Manager)& theDocumentResource,
1108 const TCollection_ExtendedString& theResourceName,
1109 Standard_Boolean& IsDef,
1110 TCollection_ExtendedString& theValue)
1112 IsDef=UTL::Find(theDocumentResource,theResourceName);
1113 if(IsDef) theValue=UTL::Value(theDocumentResource,theResourceName);
1117 //=======================================================================
1118 //function : StorageResource
1120 //=======================================================================
1122 Handle(Resource_Manager) CDM_Document::StorageResource()
1124 if(myApplication.IsNull()) {
1125 Standard_SStream aMsg;
1126 aMsg << "this document of format "<< StorageFormat()
1127 << " has not yet been opened by any application. "<< endl;
1128 throw Standard_Failure(aMsg.str().c_str());
1130 return myApplication->Resources();
1133 //=======================================================================
1134 //function : LoadResources
1136 //=======================================================================
1138 void CDM_Document::LoadResources()
1140 if(!myResourcesAreLoaded) {
1141 Handle(Resource_Manager) theDocumentResource = StorageResource();
1143 TCollection_ExtendedString theFormat=StorageFormat(); theFormat+=".";
1144 TCollection_ExtendedString theResourceName;
1146 theResourceName=theFormat;
1147 theResourceName+="FileExtension";
1148 FIND(theDocumentResource,
1149 theResourceName,myFileExtensionWasFound,myFileExtension);
1151 theResourceName=theFormat;
1152 theResourceName+="Description";
1153 FIND(theDocumentResource,theResourceName,myDescriptionWasFound,myDescription);
1155 myResourcesAreLoaded=Standard_True;
1157 // cout << "resource Loaded: Format: " << theFormat << ", FileExtension:" << myFileExtension << ", Description:" << myDescription << endl;
1162 //=======================================================================
1163 //function : FindFileExtension
1165 //=======================================================================
1167 Standard_Boolean CDM_Document::FindFileExtension ()
1170 return myFileExtensionWasFound;
1173 //=======================================================================
1174 //function : FileExtension
1176 //=======================================================================
1178 TCollection_ExtendedString CDM_Document::FileExtension()
1181 return myFileExtension;
1184 //=======================================================================
1185 //function : FindDescription
1187 //=======================================================================
1189 Standard_Boolean CDM_Document::FindDescription ()
1192 return myDescriptionWasFound;
1195 //=======================================================================
1196 //function : Description
1198 //=======================================================================
1200 TCollection_ExtendedString CDM_Document::Description()
1203 return myDescription;
1206 //=======================================================================
1207 //function : IsReadOnly
1209 //=======================================================================
1211 Standard_Boolean CDM_Document::IsReadOnly() const
1213 if(IsStored()) return myMetaData->IsReadOnly();
1214 return Standard_False;
1217 //=======================================================================
1218 //function : IsReadOnly
1220 //=======================================================================
1222 Standard_Boolean CDM_Document::IsReadOnly
1223 (const Standard_Integer aReferenceIdentifier) const
1225 return Reference(aReferenceIdentifier)->IsReadOnly();
1228 //=======================================================================
1229 //function : SetIsReadOnly
1231 //=======================================================================
1233 void CDM_Document::SetIsReadOnly()
1235 if(IsStored()) myMetaData->SetIsReadOnly();
1238 //=======================================================================
1239 //function : UnsetIsReadOnly
1241 //=======================================================================
1243 void CDM_Document::UnsetIsReadOnly()
1245 if(IsStored()) myMetaData->UnsetIsReadOnly();
1248 //=======================================================================
1249 //function : ReferenceCounter
1251 //=======================================================================
1253 Standard_Integer CDM_Document::ReferenceCounter() const
1255 return myActualReferenceIdentifier;
1258 //=======================================================================
1259 //function : SetReferenceCounter
1261 //=======================================================================
1263 void CDM_Document::SetReferenceCounter (const Standard_Integer aReferenceCounter)
1265 myActualReferenceIdentifier=aReferenceCounter;