1 // Created on: 2001-08-24
2 // Created by: Alexnder GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
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.
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.
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.
20 // modified 13.04.2009 Sergey Zaritchny
22 #include <BinMDataXtd_PatternStdDriver.ixx>
24 #include <TDataStd_Real.hxx>
25 #include <TDataStd_Integer.hxx>
26 #include <TDataXtd_PatternStd.hxx>
27 #include <TNaming_NamedShape.hxx>
29 //=======================================================================
30 //function : BinMDataXtd_PatternStdDriver
31 //purpose : Constructor
32 //=======================================================================
33 BinMDataXtd_PatternStdDriver::BinMDataXtd_PatternStdDriver
34 (const Handle(CDM_MessageDriver)& theMsgDriver)
35 : BinMDF_ADriver (theMsgDriver, NULL)
38 //=======================================================================
41 //=======================================================================
42 Handle(TDF_Attribute) BinMDataXtd_PatternStdDriver::NewEmpty() const
44 return (new TDataXtd_PatternStd());
47 //=======================================================================
50 //=======================================================================
51 Standard_Boolean BinMDataXtd_PatternStdDriver::Paste
52 (const BinObjMgt_Persistent& theSource,
53 const Handle(TDF_Attribute)& theTarget,
54 BinObjMgt_RRelocationTable& theRelocTable) const
56 Handle(TDataXtd_PatternStd) aP =
57 Handle(TDataXtd_PatternStd)::DownCast(theTarget);
60 Standard_Integer signature;
61 if (! (theSource >> signature))
62 return Standard_False;
65 aP->Signature(signature);
68 Standard_Integer revFlags;
69 if (! (theSource >> revFlags))
70 return Standard_False;
71 aP->Axis1Reversed( revFlags & 1 );
72 aP->Axis2Reversed( revFlags & 2 );
74 Handle(TNaming_NamedShape) TNS;
77 if (signature == 5) // mirror
79 if (! (theSource >> aNb))
80 return Standard_False;
81 if (theRelocTable.IsBound(aNb))
82 TNS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
85 TNS = new TNaming_NamedShape;
86 theRelocTable.Bind(aNb, TNS);
92 Handle(TDataStd_Real) TReal;
93 Handle(TDataStd_Integer) TInt;
96 if (! (theSource >> aNb))
97 return Standard_False;
98 if (theRelocTable.IsBound(aNb))
99 TNS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
102 TNS = new TNaming_NamedShape;
103 theRelocTable.Bind(aNb, TNS);
108 if (! (theSource >> aNb))
109 return Standard_False;
110 if (theRelocTable.IsBound(aNb))
111 TReal = Handle(TDataStd_Real)::DownCast(theRelocTable.Find(aNb));
114 TReal = new TDataStd_Real;
115 theRelocTable.Bind(aNb, TReal);
119 // number of instances 1
120 if (! (theSource >> aNb))
121 return Standard_False;
122 if (theRelocTable.IsBound(aNb))
123 TInt = Handle(TDataStd_Integer)::DownCast(theRelocTable.Find(aNb));
126 TInt = new TDataStd_Integer;
127 theRelocTable.Bind(aNb, TInt);
129 aP->NbInstances1(TInt);
134 if (! (theSource >> aNb))
135 return Standard_False;
136 if (theRelocTable.IsBound(aNb))
137 TNS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
140 TNS = new TNaming_NamedShape;
141 theRelocTable.Bind(aNb, TNS);
146 if (! (theSource >> aNb))
147 return Standard_False;
148 if (theRelocTable.IsBound(aNb))
149 TReal = Handle(TDataStd_Real)::DownCast(theRelocTable.Find(aNb));
152 TReal = new TDataStd_Real;
153 theRelocTable.Bind(aNb, TReal);
157 // number of instances 2
158 if (! (theSource >> aNb))
159 return Standard_False;
160 if (theRelocTable.IsBound(aNb))
161 TInt = Handle(TDataStd_Integer)::DownCast(theRelocTable.Find(aNb));
164 TInt = new TDataStd_Integer;
165 theRelocTable.Bind(aNb, TInt);
167 aP->NbInstances2(TInt);
171 return Standard_True;
174 //=======================================================================
177 //=======================================================================
178 void BinMDataXtd_PatternStdDriver::Paste
179 (const Handle(TDF_Attribute)& theSource,
180 BinObjMgt_Persistent& theTarget,
181 BinObjMgt_SRelocationTable& theRelocTable) const
183 Handle(TDataXtd_PatternStd) aP =
184 Handle(TDataXtd_PatternStd)::DownCast(theSource);
187 Standard_Integer signature = aP->Signature();
188 if (signature < 1 || signature > 5)
190 theTarget << signature;
195 Standard_Integer revFlags = 0;
196 if (aP->Axis1Reversed()) revFlags |= 1;
197 if (aP->Axis2Reversed()) revFlags |= 2;
198 theTarget << revFlags;
200 Standard_Integer aNb;
201 if (signature == 5) // mirror
203 Handle(TNaming_NamedShape) Plane = aP->Mirror();
204 aNb = theRelocTable.Add(Plane);
210 Handle(TNaming_NamedShape) Axis = aP->Axis1();
211 aNb = theRelocTable.Add(Axis);
215 Handle(TDataStd_Real) Value = aP->Value1();
216 aNb = theRelocTable.Add(Value);
219 // number of instances 1
220 Handle(TDataStd_Integer) NbInstances = aP->NbInstances1();
221 aNb = theRelocTable.Add(NbInstances);
228 aNb = theRelocTable.Add(Axis);
232 Value = aP->Value2();
233 aNb = theRelocTable.Add(Value);
236 // number of instances 2
237 NbInstances = aP->NbInstances2();
238 aNb = theRelocTable.Add(NbInstances);