1 // Created on: 1997-10-22
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.
18 #include <CDM_Application.hxx>
19 #include <CDM_Document.hxx>
20 #include <CDM_MetaData.hxx>
21 #include <CDM_Reference.hxx>
22 #include <Standard_Dump.hxx>
23 #include <Standard_Type.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(CDM_Reference,Standard_Transient)
27 CDM_Reference::CDM_Reference(const Handle(CDM_Document)& aFromDocument, const Handle(CDM_Document)& aToDocument, const Standard_Integer aReferenceIdentifier, const Standard_Integer aToDocumentVersion):
28 myToDocument(aToDocument),
29 myFromDocument(aFromDocument.operator->()),
30 myReferenceIdentifier(aReferenceIdentifier),
31 myDocumentVersion(aToDocumentVersion),
32 myUseStorageConfiguration(Standard_False)
35 CDM_Reference::CDM_Reference(const Handle(CDM_Document)& aFromDocument, const Handle(CDM_MetaData)& aToDocument, const Standard_Integer aReferenceIdentifier, const Handle(CDM_Application)& anApplication, const Standard_Integer aToDocumentVersion, const Standard_Boolean UseStorageConfiguration):
36 myFromDocument(aFromDocument.operator->()),
37 myReferenceIdentifier(aReferenceIdentifier),
38 myApplication(anApplication),
39 myMetaData(aToDocument),
40 myDocumentVersion(aToDocumentVersion),
41 myUseStorageConfiguration(UseStorageConfiguration)
44 Handle(CDM_Document) CDM_Reference::FromDocument() {
45 return myFromDocument;
48 Handle(CDM_Document) CDM_Reference::ToDocument() {
49 if(myToDocument.IsNull()) {
50 myToDocument=myApplication->Retrieve(myMetaData,myUseStorageConfiguration);
51 myApplication.Nullify();
55 Standard_Integer CDM_Reference::ReferenceIdentifier() {
56 return myReferenceIdentifier;
60 void CDM_Reference::Update(const Handle(CDM_MetaData)& aMetaData) {
61 if(myToDocument.IsNull()) {
62 if(myMetaData == aMetaData) {
63 myToDocument=myMetaData->Document();
64 myToDocument->AddFromReference(this);
65 myApplication.Nullify();
70 Standard_Boolean CDM_Reference::IsUpToDate() const {
71 Standard_Integer theActualDocumentVersion;
72 if(myToDocument.IsNull())
73 theActualDocumentVersion=myMetaData->DocumentVersion(myApplication);
75 theActualDocumentVersion=myToDocument->Modifications();
77 return myDocumentVersion==theActualDocumentVersion;
79 void CDM_Reference::SetIsUpToDate() {
81 Standard_Integer theActualDocumentVersion;
82 if(myToDocument.IsNull())
83 theActualDocumentVersion=myMetaData->DocumentVersion(myApplication);
85 theActualDocumentVersion=myToDocument->Modifications();
87 if(theActualDocumentVersion != -1) myDocumentVersion=theActualDocumentVersion;
89 void CDM_Reference::UnsetToDocument(const Handle(CDM_MetaData)& aMetaData, const Handle(CDM_Application)& anApplication) {
90 myToDocument.Nullify();
91 myApplication=anApplication;
95 Standard_Integer CDM_Reference::DocumentVersion() const {
96 return myDocumentVersion;
98 Standard_Boolean CDM_Reference::IsOpened() const {
99 if(myToDocument.IsNull()) return Standard_False;
100 return myToDocument->IsOpened();
102 Standard_Boolean CDM_Reference::IsReadOnly() const {
103 if(myToDocument.IsNull()) return myMetaData->IsReadOnly();
104 return myToDocument->IsReadOnly();
106 Handle(CDM_Document) CDM_Reference::Document() const {
109 Handle(CDM_MetaData) CDM_Reference::MetaData() const {
112 Handle(CDM_Application) CDM_Reference::Application() const {
113 return myApplication;
116 Standard_Boolean CDM_Reference::UseStorageConfiguration() const {
117 return myUseStorageConfiguration;
119 Standard_Boolean CDM_Reference::IsInSession() const {
120 return !myToDocument.IsNull();
122 Standard_Boolean CDM_Reference::IsStored() const {
123 return !myMetaData.IsNull();
126 //=======================================================================
127 //function : DumpJson
129 //=======================================================================
130 void CDM_Reference::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
132 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
134 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myToDocument.get())
135 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myFromDocument)
137 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myReferenceIdentifier)
139 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myApplication.get())
140 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myMetaData.get())
142 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDocumentVersion)
143 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUseStorageConfiguration)