1 // Created on: 2001-08-24
2 // Created by: Alexnder GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // modified 13.04.2009 Sergey Zaritchny
18 #include <BinMDataXtd_PatternStdDriver.ixx>
20 #include <TDataStd_Real.hxx>
21 #include <TDataStd_Integer.hxx>
22 #include <TDataXtd_PatternStd.hxx>
23 #include <TNaming_NamedShape.hxx>
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)
34 //=======================================================================
37 //=======================================================================
38 Handle(TDF_Attribute) BinMDataXtd_PatternStdDriver::NewEmpty() const
40 return (new TDataXtd_PatternStd());
43 //=======================================================================
46 //=======================================================================
47 Standard_Boolean BinMDataXtd_PatternStdDriver::Paste
48 (const BinObjMgt_Persistent& theSource,
49 const Handle(TDF_Attribute)& theTarget,
50 BinObjMgt_RRelocationTable& theRelocTable) const
52 Handle(TDataXtd_PatternStd) aP =
53 Handle(TDataXtd_PatternStd)::DownCast(theTarget);
56 Standard_Integer signature;
57 if (! (theSource >> signature))
58 return Standard_False;
61 aP->Signature(signature);
64 Standard_Integer revFlags;
65 if (! (theSource >> revFlags))
66 return Standard_False;
67 aP->Axis1Reversed( revFlags & 1 );
68 aP->Axis2Reversed( revFlags & 2 );
70 Handle(TNaming_NamedShape) TNS;
73 if (signature == 5) // mirror
75 if (! (theSource >> aNb))
76 return Standard_False;
77 if (theRelocTable.IsBound(aNb))
78 TNS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
81 TNS = new TNaming_NamedShape;
82 theRelocTable.Bind(aNb, TNS);
88 Handle(TDataStd_Real) TReal;
89 Handle(TDataStd_Integer) TInt;
92 if (! (theSource >> aNb))
93 return Standard_False;
94 if (theRelocTable.IsBound(aNb))
95 TNS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
98 TNS = new TNaming_NamedShape;
99 theRelocTable.Bind(aNb, TNS);
104 if (! (theSource >> aNb))
105 return Standard_False;
106 if (theRelocTable.IsBound(aNb))
107 TReal = Handle(TDataStd_Real)::DownCast(theRelocTable.Find(aNb));
110 TReal = new TDataStd_Real;
111 theRelocTable.Bind(aNb, TReal);
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));
122 TInt = new TDataStd_Integer;
123 theRelocTable.Bind(aNb, TInt);
125 aP->NbInstances1(TInt);
130 if (! (theSource >> aNb))
131 return Standard_False;
132 if (theRelocTable.IsBound(aNb))
133 TNS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
136 TNS = new TNaming_NamedShape;
137 theRelocTable.Bind(aNb, TNS);
142 if (! (theSource >> aNb))
143 return Standard_False;
144 if (theRelocTable.IsBound(aNb))
145 TReal = Handle(TDataStd_Real)::DownCast(theRelocTable.Find(aNb));
148 TReal = new TDataStd_Real;
149 theRelocTable.Bind(aNb, TReal);
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));
160 TInt = new TDataStd_Integer;
161 theRelocTable.Bind(aNb, TInt);
163 aP->NbInstances2(TInt);
167 return Standard_True;
170 //=======================================================================
173 //=======================================================================
174 void BinMDataXtd_PatternStdDriver::Paste
175 (const Handle(TDF_Attribute)& theSource,
176 BinObjMgt_Persistent& theTarget,
177 BinObjMgt_SRelocationTable& theRelocTable) const
179 Handle(TDataXtd_PatternStd) aP =
180 Handle(TDataXtd_PatternStd)::DownCast(theSource);
183 Standard_Integer signature = aP->Signature();
184 if (signature < 1 || signature > 5)
186 theTarget << signature;
191 Standard_Integer revFlags = 0;
192 if (aP->Axis1Reversed()) revFlags |= 1;
193 if (aP->Axis2Reversed()) revFlags |= 2;
194 theTarget << revFlags;
196 Standard_Integer aNb;
197 if (signature == 5) // mirror
199 Handle(TNaming_NamedShape) Plane = aP->Mirror();
200 aNb = theRelocTable.Add(Plane);
206 Handle(TNaming_NamedShape) Axis = aP->Axis1();
207 aNb = theRelocTable.Add(Axis);
211 Handle(TDataStd_Real) Value = aP->Value1();
212 aNb = theRelocTable.Add(Value);
215 // number of instances 1
216 Handle(TDataStd_Integer) NbInstances = aP->NbInstances1();
217 aNb = theRelocTable.Add(NbInstances);
224 aNb = theRelocTable.Add(Axis);
228 Value = aP->Value2();
229 aNb = theRelocTable.Add(Value);
232 // number of instances 2
233 NbInstances = aP->NbInstances2();
234 aNb = theRelocTable.Add(NbInstances);