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