0029220: Application Framework - replace CDM_MessageDriver interface by Message_Messe...
[occt.git] / src / BinMXCAFDoc / BinMXCAFDoc_AssemblyItemRefDriver.cxx
1 // Created on: 2017-02-16
2 // Created by: Eugeny NIKONOV
3 // Copyright (c) 2005-2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BinObjMgt_Persistent.hxx>
17 #include <Message_Messenger.hxx>
18 #include <Standard_Type.hxx>
19 #include <TDF_Attribute.hxx>
20 #include <BinMXCAFDoc_AssemblyItemRefDriver.hxx>
21 #include <XCAFDoc_AssemblyItemRef.hxx>
22
23 IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_AssemblyItemRefDriver, BinMDF_ADriver)
24
25 //=======================================================================
26 //function :
27 //purpose  : 
28 //=======================================================================
29 BinMXCAFDoc_AssemblyItemRefDriver::BinMXCAFDoc_AssemblyItemRefDriver(const Handle(Message_Messenger)& theMsgDriver)
30   : BinMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_AssemblyItemRef)->Name())
31 {
32
33 }
34
35 //=======================================================================
36 //function :
37 //purpose  : 
38 //=======================================================================
39 Handle(TDF_Attribute) BinMXCAFDoc_AssemblyItemRefDriver::NewEmpty() const
40 {
41   return new XCAFDoc_AssemblyItemRef();
42 }
43
44 //=======================================================================
45 //function :
46 //purpose  : 
47 //=======================================================================
48 Standard_Boolean BinMXCAFDoc_AssemblyItemRefDriver::Paste(const BinObjMgt_Persistent&  theSource,
49                                                           const Handle(TDF_Attribute)& theTarget,
50                                                           BinObjMgt_RRelocationTable&  /*theRelocTable*/) const
51 {
52   Handle(XCAFDoc_AssemblyItemRef) aThis = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theTarget);
53   if (aThis.IsNull())
54     return Standard_False;
55   
56   TCollection_AsciiString aPathStr;
57   if (!(theSource >> aPathStr))
58     return Standard_False;
59
60   aThis->SetItem(aPathStr);
61
62   Standard_Integer anExtraRef = 0;
63   if (!(theSource >> anExtraRef))
64     return Standard_False;
65
66   if (anExtraRef == 1)
67   {
68     Standard_GUID aGUID;
69     if (!(theSource >> aGUID))
70       return Standard_False;
71
72     aThis->SetGUID(aGUID);
73   }
74   else if (anExtraRef == 2)
75   {
76     Standard_Integer aSubshapeIndex;
77     if (!(theSource >> aSubshapeIndex))
78       return Standard_False;
79
80     aThis->SetSubshapeIndex(aSubshapeIndex);
81   }
82
83   return Standard_True;
84 }
85
86 //=======================================================================
87 //function :
88 //purpose  : 
89 //=======================================================================
90 void BinMXCAFDoc_AssemblyItemRefDriver::Paste(const Handle(TDF_Attribute)& theSource,
91                                                                             BinObjMgt_Persistent&        theTarget,
92                                                                             BinObjMgt_SRelocationTable&  /*theRelocTable*/) const
93 {
94   Handle(XCAFDoc_AssemblyItemRef) aThis = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theSource);
95   if (!aThis.IsNull())
96   {
97     theTarget << aThis->GetItem().ToString();
98     if (aThis->IsGUID())
99     {
100       theTarget << Standard_Integer(1);
101       theTarget << aThis->GetGUID();
102     }
103     else if (aThis->IsSubshapeIndex())
104     {
105       theTarget << Standard_Integer(2);
106       theTarget << aThis->GetSubshapeIndex();
107     }
108     else
109       theTarget << Standard_Integer(0);
110   }
111 }