0024428: Implementation of LGPL license
[occt.git] / src / BinMDataXtd / BinMDataXtd_PatternStdDriver.cxx
1 // Created on: 2001-08-24
2 // Created by: Alexnder GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 // modified     13.04.2009 Sergey Zaritchny
17
18 #include <BinMDataXtd_PatternStdDriver.ixx>
19
20 #include <TDataStd_Real.hxx>
21 #include <TDataStd_Integer.hxx>
22 #include <TDataXtd_PatternStd.hxx>
23 #include <TNaming_NamedShape.hxx>
24
25 //=======================================================================
26 //function : BinMDataXtd_PatternStdDriver
27 //purpose  : Constructor
28 //=======================================================================
29 BinMDataXtd_PatternStdDriver::BinMDataXtd_PatternStdDriver
30                         (const Handle(CDM_MessageDriver)& theMsgDriver)
31       : BinMDF_ADriver (theMsgDriver, NULL)
32 {}
33
34 //=======================================================================
35 //function : NewEmpty
36 //purpose  : 
37 //=======================================================================
38 Handle(TDF_Attribute) BinMDataXtd_PatternStdDriver::NewEmpty() const
39 {
40   return (new TDataXtd_PatternStd());
41 }
42
43 //=======================================================================
44 //function : Paste
45 //purpose  : 
46 //=======================================================================
47 Standard_Boolean BinMDataXtd_PatternStdDriver::Paste
48                         (const BinObjMgt_Persistent&  theSource,
49                          const Handle(TDF_Attribute)& theTarget,
50                          BinObjMgt_RRelocationTable&  theRelocTable) const
51 {
52   Handle(TDataXtd_PatternStd) aP =
53     Handle(TDataXtd_PatternStd)::DownCast(theTarget);
54
55   // signature
56   Standard_Integer signature;
57   if (! (theSource >> signature))
58     return Standard_False;
59   if (signature == 0)
60     return Standard_True;
61   aP->Signature(signature);
62
63   // reversed flags
64   Standard_Integer revFlags;
65   if (! (theSource >> revFlags))
66     return Standard_False;
67   aP->Axis1Reversed( revFlags & 1 );
68   aP->Axis2Reversed( revFlags & 2 );
69
70   Handle(TNaming_NamedShape) TNS;
71   Standard_Integer aNb;
72
73   if (signature == 5) // mirror
74   {
75     if (! (theSource >> aNb))
76       return Standard_False;
77     if (theRelocTable.IsBound(aNb))
78       TNS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
79     else
80     {
81       TNS = new TNaming_NamedShape;
82       theRelocTable.Bind(aNb, TNS);
83     }
84     aP->Mirror(TNS);
85   }
86   else
87   {
88     Handle(TDataStd_Real) TReal;
89     Handle(TDataStd_Integer) TInt;
90
91     // axis 1
92     if (! (theSource >> aNb))
93       return Standard_False;
94     if (theRelocTable.IsBound(aNb))
95       TNS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
96     else
97     {
98       TNS = new TNaming_NamedShape;
99       theRelocTable.Bind(aNb, TNS);
100     }
101     aP->Axis1(TNS);
102
103     // value 1
104     if (! (theSource >> aNb))
105       return Standard_False;
106     if (theRelocTable.IsBound(aNb))
107       TReal = Handle(TDataStd_Real)::DownCast(theRelocTable.Find(aNb));
108     else
109     {
110       TReal = new TDataStd_Real;
111       theRelocTable.Bind(aNb, TReal);
112     }
113     aP->Value1(TReal);
114
115     // number of instances 1
116     if (! (theSource >> aNb))
117       return Standard_False;
118     if (theRelocTable.IsBound(aNb))
119       TInt = Handle(TDataStd_Integer)::DownCast(theRelocTable.Find(aNb));
120     else
121     {
122       TInt = new TDataStd_Integer;
123       theRelocTable.Bind(aNb, TInt);
124     }
125     aP->NbInstances1(TInt);
126
127     if (signature > 2)
128     {
129       // axis 2
130       if (! (theSource >> aNb))
131         return Standard_False;
132       if (theRelocTable.IsBound(aNb))
133         TNS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
134       else
135       {
136         TNS = new TNaming_NamedShape;
137         theRelocTable.Bind(aNb, TNS);
138       }
139       aP->Axis2(TNS);
140
141       // real value 2
142       if (! (theSource >> aNb))
143         return Standard_False;
144       if (theRelocTable.IsBound(aNb))
145         TReal = Handle(TDataStd_Real)::DownCast(theRelocTable.Find(aNb));
146       else
147       {
148         TReal = new TDataStd_Real;
149         theRelocTable.Bind(aNb, TReal);
150       }
151       aP->Value2(TReal);
152
153       // number of instances 2
154       if (! (theSource >> aNb))
155         return Standard_False;
156       if (theRelocTable.IsBound(aNb))
157         TInt = Handle(TDataStd_Integer)::DownCast(theRelocTable.Find(aNb));
158       else
159       {
160         TInt = new TDataStd_Integer;
161         theRelocTable.Bind(aNb, TInt);
162       }
163       aP->NbInstances2(TInt);
164     }
165   }
166
167   return Standard_True;
168 }
169
170 //=======================================================================
171 //function : Paste
172 //purpose  : 
173 //=======================================================================
174 void BinMDataXtd_PatternStdDriver::Paste
175                         (const Handle(TDF_Attribute)& theSource,
176                          BinObjMgt_Persistent&        theTarget,
177                          BinObjMgt_SRelocationTable&  theRelocTable) const
178 {
179   Handle(TDataXtd_PatternStd) aP =
180     Handle(TDataXtd_PatternStd)::DownCast(theSource);
181
182   // signature
183   Standard_Integer signature = aP->Signature();
184   if (signature < 1 || signature > 5)
185     signature = 0;
186   theTarget << signature;
187   if (signature == 0)
188     return;
189
190   // reversed flags
191   Standard_Integer revFlags = 0;
192   if (aP->Axis1Reversed()) revFlags |= 1;
193   if (aP->Axis2Reversed()) revFlags |= 2;
194   theTarget << revFlags;
195
196   Standard_Integer aNb;
197   if (signature == 5) // mirror
198   {
199     Handle(TNaming_NamedShape) Plane = aP->Mirror();
200     aNb = theRelocTable.Add(Plane);
201     theTarget << aNb;
202   }
203   else
204   {
205     // axis 1
206     Handle(TNaming_NamedShape) Axis = aP->Axis1();
207     aNb = theRelocTable.Add(Axis);
208     theTarget << aNb;
209
210     // real value 1
211     Handle(TDataStd_Real) Value = aP->Value1();
212     aNb = theRelocTable.Add(Value);
213     theTarget << aNb;
214
215     // number of instances 1
216     Handle(TDataStd_Integer) NbInstances = aP->NbInstances1();
217     aNb = theRelocTable.Add(NbInstances);
218     theTarget << aNb;
219
220     if (signature > 2)
221     {
222       // axis 2
223       Axis = aP->Axis2();
224       aNb = theRelocTable.Add(Axis);
225       theTarget << aNb;
226
227       // real value 2
228       Value = aP->Value2();
229       aNb = theRelocTable.Add(Value);
230       theTarget << aNb;
231
232       // number of instances 2
233       NbInstances = aP->NbInstances2();
234       aNb = theRelocTable.Add(NbInstances);
235       theTarget << aNb;
236     }
237   }
238 }