b311480e |
1 | // Created on: 2002-10-31 |
2 | // Created by: Michael SAZONOV |
973c2be1 |
3 | // Copyright (c) 2002-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
7fd59977 |
17 | #include <BinMDataStd.hxx> |
42cf5bc1 |
18 | #include <BinMDataStd_RealArrayDriver.hxx> |
19 | #include <BinObjMgt_Persistent.hxx> |
83ae3591 |
20 | #include <Message_Messenger.hxx> |
42cf5bc1 |
21 | #include <Standard_Type.hxx> |
22 | #include <TColStd_HArray1OfReal.hxx> |
23 | #include <TDataStd_RealArray.hxx> |
24 | #include <TDF_Attribute.hxx> |
7fd59977 |
25 | |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_RealArrayDriver,BinMDF_ADriver) |
27 | |
7fd59977 |
28 | //======================================================================= |
29 | //function : BinMDataStd_RealArrayDriver |
30 | //purpose : Constructor |
31 | //======================================================================= |
7fd59977 |
32 | BinMDataStd_RealArrayDriver::BinMDataStd_RealArrayDriver |
83ae3591 |
33 | (const Handle(Message_Messenger)& theMsgDriver) |
7fd59977 |
34 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_RealArray)->Name()) |
35 | { |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : NewEmpty |
40 | //purpose : |
41 | //======================================================================= |
42 | |
43 | Handle(TDF_Attribute) BinMDataStd_RealArrayDriver::NewEmpty() const |
44 | { |
45 | return new TDataStd_RealArray(); |
46 | } |
47 | |
48 | //======================================================================= |
49 | //function : Paste |
50 | //purpose : persistent -> transient (retrieve) |
51 | //======================================================================= |
52 | |
53 | Standard_Boolean BinMDataStd_RealArrayDriver::Paste |
54 | (const BinObjMgt_Persistent& theSource, |
55 | const Handle(TDF_Attribute)& theTarget, |
b34d86cb |
56 | BinObjMgt_RRelocationTable& theRelocTable) const |
7fd59977 |
57 | { |
58 | Standard_Integer aFirstInd, aLastInd; |
59 | if (! (theSource >> aFirstInd >> aLastInd)) |
60 | return Standard_False; |
61 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
62 | if (aLength <= 0) |
63 | return Standard_False; |
64 | |
5a1271c8 |
65 | const Handle(TDataStd_RealArray) anAtt = |
7fd59977 |
66 | Handle(TDataStd_RealArray)::DownCast(theTarget); |
67 | anAtt->Init(aFirstInd, aLastInd); |
68 | TColStd_Array1OfReal& aTargetArray = anAtt->Array()->ChangeArray1(); |
69 | if(!theSource.GetRealArray (&aTargetArray(aFirstInd), aLength)) |
70 | return Standard_False; |
63c629aa |
71 | |
7fd59977 |
72 | Standard_Boolean aDelta(Standard_False); |
b34d86cb |
73 | if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) { |
7fd59977 |
74 | Standard_Byte aDeltaValue; |
75 | if (! (theSource >> aDeltaValue)) |
76 | return Standard_False; |
77 | else |
dde68833 |
78 | aDelta = (aDeltaValue != 0); |
7fd59977 |
79 | } |
80 | anAtt->SetDelta(aDelta); |
5a1271c8 |
81 | |
b34d86cb |
82 | BinMDataStd::SetAttributeID(theSource, anAtt, theRelocTable.GetHeaderData()->StorageVersion().IntegerValue()); |
7fd59977 |
83 | return Standard_True; |
84 | } |
85 | |
86 | //======================================================================= |
87 | //function : Paste |
88 | //purpose : transient -> persistent (store) |
89 | //======================================================================= |
90 | |
91 | void BinMDataStd_RealArrayDriver::Paste |
92 | (const Handle(TDF_Attribute)& theSource, |
93 | BinObjMgt_Persistent& theTarget, |
94 | BinObjMgt_SRelocationTable& ) const |
95 | { |
96 | Handle(TDataStd_RealArray) anAtt = |
97 | Handle(TDataStd_RealArray)::DownCast(theSource); |
98 | const TColStd_Array1OfReal& aSourceArray = anAtt->Array()->Array1(); |
99 | const Standard_Integer aFirstInd = aSourceArray.Lower(); |
100 | const Standard_Integer aLastInd = aSourceArray.Upper(); |
101 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
102 | theTarget << aFirstInd << aLastInd; |
103 | Standard_Real *aPtr = (Standard_Real *) &aSourceArray(aFirstInd); |
104 | theTarget.PutRealArray (aPtr, aLength); |
dde68833 |
105 | theTarget << (Standard_Byte)(anAtt->GetDelta() ? 1 : 0); |
5a1271c8 |
106 | // process user defined guid |
107 | if(anAtt->ID() != TDataStd_RealArray::GetID()) |
108 | theTarget << anAtt->ID(); |
7fd59977 |
109 | } |