0024157: Parallelization of assembly part of BO
[occt.git] / src / BinMXCAFDoc / BinMXCAFDoc_LocationDriver.cxx
CommitLineData
b311480e 1// Created on: 2005-05-17
2// Created by: Eugeny NAPALKOV
3// Copyright (c) 2005-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#include <BinMXCAFDoc_LocationDriver.ixx>
22#include <XCAFDoc_Location.hxx>
23
24#include <TopLoc_Datum3D.hxx>
25#include <TopLoc_Location.hxx>
26#include <gp_Trsf.hxx>
27#include <gp_Mat.hxx>
28#include <gp_XYZ.hxx>
29//#include <Precision.hxx>
30#include <BinMDataStd.hxx>
31#include <BinTools_LocationSet.hxx>
32
33
34//=======================================================================
35//function :
36//purpose :
37//=======================================================================
38BinMXCAFDoc_LocationDriver::BinMXCAFDoc_LocationDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
39 : BinMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_Location)->Name())
40 , myLocations(0) {
41}
42
43//=======================================================================
44//function :
45//purpose :
46//=======================================================================
47Handle(TDF_Attribute) BinMXCAFDoc_LocationDriver::NewEmpty() const {
48 return new XCAFDoc_Location();
49}
50
51//=======================================================================
52//function :
53//purpose :
54//=======================================================================
55Standard_Boolean BinMXCAFDoc_LocationDriver::Paste(const BinObjMgt_Persistent& theSource,
56 const Handle(TDF_Attribute)& theTarget,
57 BinObjMgt_RRelocationTable& theRelocTable) const
58{
59 Handle(XCAFDoc_Location) anAtt = Handle(XCAFDoc_Location)::DownCast(theTarget);
60 TopLoc_Location aLoc;
61 Standard_Boolean aRes = Translate(theSource, aLoc, theRelocTable);
62 anAtt->Set(aLoc);
63 return aRes;
64}
65
66//=======================================================================
67//function :
68//purpose :
69//=======================================================================
70void BinMXCAFDoc_LocationDriver::Paste(const Handle(TDF_Attribute)& theSource,
71 BinObjMgt_Persistent& theTarget,
72 BinObjMgt_SRelocationTable& theRelocTable) const
73{
74 Handle(XCAFDoc_Location) anAtt = Handle(XCAFDoc_Location)::DownCast(theSource);
75 TopLoc_Location aLoc = anAtt->Get();
76 Translate(aLoc, theTarget, theRelocTable);
77}
78
79//=======================================================================
80//function :
81//purpose :
82//=======================================================================
83Standard_Boolean BinMXCAFDoc_LocationDriver::Translate(const BinObjMgt_Persistent& theSource,
84 TopLoc_Location& theLoc,
85 BinObjMgt_RRelocationTable& theMap) const
86{
87 Standard_Integer anId = 0;
88 theSource >> anId;
89
90 if(anId == 0)
91 {
92 return Standard_True;
93 }
94
95 Standard_Integer aFileVer = BinMDataStd::DocumentVersion();
96 if( aFileVer > 5 && myLocations == 0 )
97 {
98 return Standard_False;
99 }
100
101 Standard_Integer aPower;
102 Handle(TopLoc_Datum3D) aDatum;
103
104 if( aFileVer > 5 )
105 {
106 const TopLoc_Location& aLoc = myLocations->Location(anId);
107 aPower = aLoc.FirstPower();
108 aDatum = aLoc.FirstDatum();
109 } else {
110 theSource >> aPower;
111
112 Standard_Integer aDatumID = -1;
113 Standard_Integer aReadDatum = -1;
114 theSource >> aReadDatum;
115 theSource >> aDatumID;
116 if(aReadDatum != -1) {
117 if(theMap.IsBound(aDatumID)) {
118 aDatum = Handle(TopLoc_Datum3D)::DownCast(theMap.Find(aDatumID));
119 } else
120 return Standard_False;
121 } else {
122 // read the datum's trasformation
123 gp_Trsf aTrsf;
124
125 Standard_Real aScaleFactor;
126 theSource >> aScaleFactor;
127 aTrsf._CSFDB_Setgp_Trsfscale(aScaleFactor);
128
129 Standard_Integer aForm;
130 theSource >> aForm;
131 aTrsf._CSFDB_Setgp_Trsfshape((gp_TrsfForm)aForm);
132
133 Standard_Integer R, C;
134 gp_Mat& aMat = (gp_Mat&)aTrsf._CSFDB_Getgp_Trsfmatrix();
135 for(R = 1; R <= 3; R++)
136 for(C = 1; C <= 3; C++) {
137 Standard_Real aVal;
138 theSource >> aVal;
139 aMat.SetValue(R, C, aVal);
140 }
141
142 Standard_Real x, y, z;
143 theSource >> x >> y >> z;
144 gp_XYZ& aLoc = (gp_XYZ&)aTrsf._CSFDB_Getgp_Trsfloc();
145 aLoc.SetX(x);
146 aLoc.SetY(y);
147 aLoc.SetZ(z);
148
149 aDatum = new TopLoc_Datum3D(aTrsf);
150 theMap.Bind(aDatumID, aDatum);
151 }
152 }
153
154 // Get Next Location
155 TopLoc_Location aNextLoc;
156 Translate(theSource, aNextLoc, theMap);
157
158 // Calculate the result
159 theLoc = aNextLoc * TopLoc_Location(aDatum).Powered(aPower);
160 return Standard_True;
161}
162
163//=======================================================================
164//function :
165//purpose :
166//=======================================================================
167void BinMXCAFDoc_LocationDriver::Translate(const TopLoc_Location& theLoc,
168 BinObjMgt_Persistent& theTarget,
169 BinObjMgt_SRelocationTable& theMap) const
170{
171 if(theLoc.IsIdentity())
172 {
173 theTarget.PutInteger(0);
174 return;
175 }
176
177 // The location is not identity
178 if( myLocations == 0 )
179 {
180#ifdef DEB
181 cout<<"Pointer to LocationSet is NULL\n";
182#endif
183 return;
184 }
185
186 Standard_Integer anId = myLocations->Add(theLoc);
187 theTarget << anId;
188
189 // In earlier version of this driver a datums from location stored in
190 // the relocation table, but now it's not necessary
191 // (try to uncomment it if some problems appear)
192 /*
193 Handle(TopLoc_Datum3D) aDatum = theLoc.FirstDatum();
194
195 if(!theMap.Contains(aDatum)) {
196 theMap.Add(aDatum);
197 }
198 */
199
200 Translate(theLoc.NextLocation(), theTarget, theMap);
201}
202