0024157: Parallelization of assembly part of BO
[occt.git] / src / CDM / CDM_Reference.cxx
1 // Created on: 1997-10-22
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
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.
10 //
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.
13 //
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.
20
21
22
23 #include <CDM_Reference.ixx>
24
25
26 CDM_Reference::CDM_Reference(const Handle(CDM_Document)& aFromDocument, const Handle(CDM_Document)& aToDocument, const Standard_Integer aReferenceIdentifier, const Standard_Integer aToDocumentVersion):
27 myToDocument(aToDocument),
28 myFromDocument(aFromDocument.operator->()),
29 myReferenceIdentifier(aReferenceIdentifier),
30 myDocumentVersion(aToDocumentVersion) 
31 {}
32
33 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):
34 myFromDocument(aFromDocument.operator->()),
35 myReferenceIdentifier(aReferenceIdentifier),
36 myApplication(anApplication),
37 myMetaData(aToDocument),
38 myDocumentVersion(aToDocumentVersion),
39 myUseStorageConfiguration(UseStorageConfiguration)
40 {}
41
42 Handle(CDM_Document) CDM_Reference::FromDocument() {
43   return myFromDocument;
44 }
45
46 Handle(CDM_Document) CDM_Reference::ToDocument() {
47   if(myToDocument.IsNull()) { 
48     myToDocument=myApplication->Retrieve(myMetaData,myUseStorageConfiguration);
49     myApplication.Nullify();
50   }
51   return myToDocument;
52 }
53 Standard_Integer CDM_Reference::ReferenceIdentifier() {
54   return myReferenceIdentifier;
55 }
56  
57
58 void CDM_Reference::Update(const Handle(CDM_MetaData)& aMetaData) {
59   if(myToDocument.IsNull()) {
60     if(myMetaData == aMetaData) {
61       myToDocument=myMetaData->Document();
62       myToDocument->AddFromReference(this);
63       myApplication.Nullify();
64     }
65   }
66 }
67
68 Standard_Boolean CDM_Reference::IsUpToDate() const {
69   Standard_Integer theActualDocumentVersion;
70   if(myToDocument.IsNull())
71     theActualDocumentVersion=myMetaData->DocumentVersion(myApplication);
72   else
73     theActualDocumentVersion=myToDocument->Modifications();
74   
75   return myDocumentVersion==theActualDocumentVersion;
76 }
77 void CDM_Reference::SetIsUpToDate() {
78   
79   Standard_Integer theActualDocumentVersion;
80   if(myToDocument.IsNull())
81     theActualDocumentVersion=myMetaData->DocumentVersion(myApplication);
82   else
83     theActualDocumentVersion=myToDocument->Modifications();
84
85   if(theActualDocumentVersion != -1) myDocumentVersion=theActualDocumentVersion;
86 }
87 void CDM_Reference::UnsetToDocument(const Handle(CDM_MetaData)& aMetaData, const Handle(CDM_Application)& anApplication) {
88   myToDocument.Nullify();
89   myApplication=anApplication;
90   myMetaData=aMetaData;
91 }
92
93 Standard_Integer CDM_Reference::DocumentVersion() const {
94   return myDocumentVersion;
95 }
96 Standard_Boolean CDM_Reference::IsOpened() const {
97   if(myToDocument.IsNull()) return Standard_False;
98   return myToDocument->IsOpened();
99 }
100 Standard_Boolean CDM_Reference::IsReadOnly() const {
101   if(myToDocument.IsNull()) return myMetaData->IsReadOnly();
102   return myToDocument->IsReadOnly();
103 }
104 Handle(CDM_Document) CDM_Reference::Document() const {
105   return myToDocument;
106 }
107 Handle(CDM_MetaData) CDM_Reference::MetaData() const {
108   return myMetaData;
109 }
110 Handle(CDM_Application) CDM_Reference::Application() const {
111   return myApplication;
112 }
113
114 Standard_Boolean CDM_Reference::UseStorageConfiguration() const {
115   return myUseStorageConfiguration;
116 }
117 Standard_Boolean CDM_Reference::IsInSession() const {
118   return !myToDocument.IsNull();
119 }
120 Standard_Boolean CDM_Reference::IsStored() const {
121   return !myMetaData.IsNull();
122 }