0029902: Data Exchange, XCAF - provide extended Material definition for visualization...
[occt.git] / src / BinMXCAFDoc / BinMXCAFDoc_DimTolDriver.cxx
CommitLineData
b311480e 1// Created on: 2008-12-10
2// Created by: Pavel TELKOV
973c2be1 3// Copyright (c) 2008-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
7fd59977 16
42cf5bc1 17#include <BinMXCAFDoc_DimTolDriver.hxx>
18#include <BinObjMgt_Persistent.hxx>
83ae3591 19#include <Message_Messenger.hxx>
42cf5bc1 20#include <Standard_Type.hxx>
7fd59977 21#include <TCollection_HAsciiString.hxx>
22#include <TColStd_Array1OfReal.hxx>
23#include <TColStd_HArray1OfReal.hxx>
42cf5bc1 24#include <TDF_Attribute.hxx>
25#include <XCAFDoc_DimTol.hxx>
7fd59977 26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_DimTolDriver,BinMDF_ADriver)
28
7fd59977 29//=======================================================================
30//function : Constructor
31//purpose :
32//=======================================================================
33BinMXCAFDoc_DimTolDriver::BinMXCAFDoc_DimTolDriver
83ae3591 34 (const Handle(Message_Messenger)& theMsgDriver)
7fd59977 35: BinMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_DimTol)->Name())
36{
37}
38
39//=======================================================================
40//function : NewEmpty
41//purpose :
42//=======================================================================
43Handle(TDF_Attribute) BinMXCAFDoc_DimTolDriver::NewEmpty() const
44{
45 return new XCAFDoc_DimTol();
46}
47
48//=======================================================================
49//function : Paste
50//purpose :
51//=======================================================================
52Standard_Boolean BinMXCAFDoc_DimTolDriver::Paste(const BinObjMgt_Persistent& theSource,
53 const Handle(TDF_Attribute)& theTarget,
54 BinObjMgt_RRelocationTable& /*theRelocTable*/) const
55{
56 Handle(XCAFDoc_DimTol) anAtt = Handle(XCAFDoc_DimTol)::DownCast(theTarget);
57 Standard_Integer aKind, aFirstInd, aLastInd;
58 TCollection_AsciiString aName, aDescr;
59 if ( !(theSource >> aKind >> aName >> aDescr >> aFirstInd >> aLastInd) )
60 return Standard_False;
61
62 Handle(TColStd_HArray1OfReal) aHArr;
63 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
64 if (aLength > 0 ) {
65 aHArr = new TColStd_HArray1OfReal( aFirstInd, aLastInd );
66
67 TColStd_Array1OfReal& aTargetArray = aHArr->ChangeArray1();
68 if(!theSource.GetRealArray (&aTargetArray(aFirstInd), aLength))
69 return Standard_False;
70 }
71 anAtt->Set(aKind, aHArr,
72 new TCollection_HAsciiString( aName ),
73 new TCollection_HAsciiString( aDescr ));
74 return Standard_True;
75}
76
77//=======================================================================
78//function : Paste
79//purpose :
80//=======================================================================
81void BinMXCAFDoc_DimTolDriver::Paste(const Handle(TDF_Attribute)& theSource,
82 BinObjMgt_Persistent& theTarget,
83 BinObjMgt_SRelocationTable& /*theRelocTable*/) const
84{
85 Handle(XCAFDoc_DimTol) anAtt = Handle(XCAFDoc_DimTol)::DownCast(theSource);
86 theTarget << anAtt->GetKind();
87 if ( !anAtt->GetName().IsNull() )
88 theTarget << anAtt->GetName()->String();
89 else
90 theTarget << TCollection_AsciiString("");
91 if ( !anAtt->GetDescription().IsNull() )
92 theTarget << anAtt->GetDescription()->String();
93 else
94 theTarget << TCollection_AsciiString("");
95
96 Handle(TColStd_HArray1OfReal) aHArr = anAtt->GetVal();
97 Standard_Integer aFirstInd = 1, aLastInd = 0;
98 if ( !aHArr.IsNull() ) {
99 aFirstInd = aHArr->Lower();
100 aLastInd = aHArr->Upper();
101 }
102 theTarget << aFirstInd << aLastInd;
103 if ( !aHArr.IsNull() ) {
104 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
105 const TColStd_Array1OfReal& anArr = aHArr->Array1();
106 Standard_Real *aPtr = (Standard_Real *) &anArr(aFirstInd);
107 theTarget.PutRealArray (aPtr, aLength);
108 }
109}