1 // Created on: 2008-12-10
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2008-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.
21 #include <BinMXCAFDoc_DimTolDriver.ixx>
22 #include <XCAFDoc_DimTol.hxx>
24 #include <TCollection_HAsciiString.hxx>
25 #include <TColStd_Array1OfReal.hxx>
26 #include <TColStd_HArray1OfReal.hxx>
28 //=======================================================================
29 //function : Constructor
31 //=======================================================================
32 BinMXCAFDoc_DimTolDriver::BinMXCAFDoc_DimTolDriver
33 (const Handle(CDM_MessageDriver)& theMsgDriver)
34 : BinMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_DimTol)->Name())
38 //=======================================================================
41 //=======================================================================
42 Handle(TDF_Attribute) BinMXCAFDoc_DimTolDriver::NewEmpty() const
44 return new XCAFDoc_DimTol();
47 //=======================================================================
50 //=======================================================================
51 Standard_Boolean BinMXCAFDoc_DimTolDriver::Paste(const BinObjMgt_Persistent& theSource,
52 const Handle(TDF_Attribute)& theTarget,
53 BinObjMgt_RRelocationTable& /*theRelocTable*/) const
55 Handle(XCAFDoc_DimTol) anAtt = Handle(XCAFDoc_DimTol)::DownCast(theTarget);
56 Standard_Integer aKind, aFirstInd, aLastInd;
57 TCollection_AsciiString aName, aDescr;
58 if ( !(theSource >> aKind >> aName >> aDescr >> aFirstInd >> aLastInd) )
59 return Standard_False;
61 Handle(TColStd_HArray1OfReal) aHArr;
62 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
64 aHArr = new TColStd_HArray1OfReal( aFirstInd, aLastInd );
66 TColStd_Array1OfReal& aTargetArray = aHArr->ChangeArray1();
67 if(!theSource.GetRealArray (&aTargetArray(aFirstInd), aLength))
68 return Standard_False;
70 anAtt->Set(aKind, aHArr,
71 new TCollection_HAsciiString( aName ),
72 new TCollection_HAsciiString( aDescr ));
76 //=======================================================================
79 //=======================================================================
80 void BinMXCAFDoc_DimTolDriver::Paste(const Handle(TDF_Attribute)& theSource,
81 BinObjMgt_Persistent& theTarget,
82 BinObjMgt_SRelocationTable& /*theRelocTable*/) const
84 Handle(XCAFDoc_DimTol) anAtt = Handle(XCAFDoc_DimTol)::DownCast(theSource);
85 theTarget << anAtt->GetKind();
86 if ( !anAtt->GetName().IsNull() )
87 theTarget << anAtt->GetName()->String();
89 theTarget << TCollection_AsciiString("");
90 if ( !anAtt->GetDescription().IsNull() )
91 theTarget << anAtt->GetDescription()->String();
93 theTarget << TCollection_AsciiString("");
95 Handle(TColStd_HArray1OfReal) aHArr = anAtt->GetVal();
96 Standard_Integer aFirstInd = 1, aLastInd = 0;
97 if ( !aHArr.IsNull() ) {
98 aFirstInd = aHArr->Lower();
99 aLastInd = aHArr->Upper();
101 theTarget << aFirstInd << aLastInd;
102 if ( !aHArr.IsNull() ) {
103 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
104 const TColStd_Array1OfReal& anArr = aHArr->Array1();
105 Standard_Real *aPtr = (Standard_Real *) &anArr(aFirstInd);
106 theTarget.PutRealArray (aPtr, aLength);