1 // Created on: 2002-10-31
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2002-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 under
8 // the terms of the GNU Lesser General Public License 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.
17 #include <BinMDataStd.hxx>
18 #include <BinMDataStd_RealArrayDriver.hxx>
19 #include <BinObjMgt_Persistent.hxx>
20 #include <Message_Messenger.hxx>
21 #include <Standard_Type.hxx>
22 #include <TColStd_HArray1OfReal.hxx>
23 #include <TDataStd_RealArray.hxx>
24 #include <TDF_Attribute.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_RealArrayDriver,BinMDF_ADriver)
28 //=======================================================================
29 //function : BinMDataStd_RealArrayDriver
30 //purpose : Constructor
31 //=======================================================================
32 BinMDataStd_RealArrayDriver::BinMDataStd_RealArrayDriver
33 (const Handle(Message_Messenger)& theMsgDriver)
34 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_RealArray)->Name())
38 //=======================================================================
41 //=======================================================================
43 Handle(TDF_Attribute) BinMDataStd_RealArrayDriver::NewEmpty() const
45 return new TDataStd_RealArray();
48 //=======================================================================
50 //purpose : persistent -> transient (retrieve)
51 //=======================================================================
53 Standard_Boolean BinMDataStd_RealArrayDriver::Paste
54 (const BinObjMgt_Persistent& theSource,
55 const Handle(TDF_Attribute)& theTarget,
56 BinObjMgt_RRelocationTable& ) const
58 Standard_Integer aFirstInd, aLastInd;
59 if (! (theSource >> aFirstInd >> aLastInd))
60 return Standard_False;
61 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
63 return Standard_False;
65 const Handle(TDataStd_RealArray) anAtt =
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;
72 Standard_Boolean aDelta(Standard_False);
73 if(BinMDataStd::DocumentVersion() > 2) {
74 Standard_Byte aDeltaValue;
75 if (! (theSource >> aDeltaValue))
76 return Standard_False;
78 aDelta = (aDeltaValue != 0);
80 anAtt->SetDelta(aDelta);
82 BinMDataStd::SetAttributeID(theSource, anAtt);
86 //=======================================================================
88 //purpose : transient -> persistent (store)
89 //=======================================================================
91 void BinMDataStd_RealArrayDriver::Paste
92 (const Handle(TDF_Attribute)& theSource,
93 BinObjMgt_Persistent& theTarget,
94 BinObjMgt_SRelocationTable& ) const
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);
105 theTarget << (Standard_Byte)(anAtt->GetDelta() ? 1 : 0);
106 // process user defined guid
107 if(anAtt->ID() != TDataStd_RealArray::GetID())
108 theTarget << anAtt->ID();