0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / BinMDataXtd / BinMDataXtd_PositionDriver.cxx
1 // Created on: 2004-05-17
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2004-2014 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 // modified     13.04.2009 Sergey ZARITCHNY
17
18 #include <BinMDataXtd_PositionDriver.hxx>
19
20 #include <gp_Pnt.hxx>
21 #include <Standard_Type.hxx>
22 #include <TDataXtd_Position.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <BinObjMgt_Persistent.hxx>
25
26 IMPLEMENT_STANDARD_RTTIEXT(BinMDataXtd_PositionDriver,BinMDF_ADriver)
27
28 //=======================================================================
29 //function : BinMDataStd_PositionDriver
30 //purpose  : Constructor
31 //=======================================================================
32 BinMDataXtd_PositionDriver::BinMDataXtd_PositionDriver
33                         (const Handle(Message_Messenger)& theMsgDriver)
34 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataXtd_Position)->Name())
35 {
36 }
37
38 //=======================================================================
39 //function : NewEmpty
40 //purpose  : 
41 //=======================================================================
42
43 Handle(TDF_Attribute) BinMDataXtd_PositionDriver::NewEmpty() const
44 {
45   return new TDataXtd_Position();
46 }
47
48 //=======================================================================
49 //function : Paste
50 //purpose  : persistent -> transient (retrieve)
51 //=======================================================================
52
53 Standard_Boolean BinMDataXtd_PositionDriver::Paste
54                                 (const BinObjMgt_Persistent&  theSource,
55                                  const Handle(TDF_Attribute)& theTarget,
56                                  BinObjMgt_RRelocationTable&  ) const
57 {
58   Handle(TDataXtd_Position) anAtt = Handle(TDataXtd_Position)::DownCast(theTarget);
59   Standard_Real aValue;
60   Standard_Boolean ok = theSource >> aValue;
61   if (!ok) return ok;
62   gp_Pnt aPosition(0., 0., 0.);
63   aPosition.SetX(aValue);
64
65   ok = theSource >> aValue;
66   if (!ok) return ok;
67   aPosition.SetY(aValue);
68
69   ok = theSource >> aValue;
70   if (!ok) return ok;
71   aPosition.SetZ(aValue);
72
73   anAtt->SetPosition(aPosition);
74
75   return ok;
76 }
77
78 //=======================================================================
79 //function : Paste
80 //purpose  : transient -> persistent (store)
81 //=======================================================================
82
83 void BinMDataXtd_PositionDriver::Paste (const Handle(TDF_Attribute)& theSource,
84                                        BinObjMgt_Persistent&        theTarget,
85                                        BinObjMgt_SRelocationTable&  ) const
86 {
87   Handle(TDataXtd_Position) anAtt = Handle(TDataXtd_Position)::DownCast(theSource);
88   
89   theTarget << anAtt->GetPosition().X();
90   theTarget << anAtt->GetPosition().Y();
91   theTarget << anAtt->GetPosition().Z();
92 }