summaryrefslogtreecommitdiff
path: root/src/BinTObjDrivers/BinTObjDrivers_ModelDriver.cxx
blob: b57304cd66944981983ad1c780fda158b95e7c01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// File      : BinTObjDrivers_ModelDriver.cxx
// Created   : Wed Nov 24 11:27:45 2004
// Author    : Edward AGAPOV
// Copyright:   Open CASCADE  2007
// The original implementation Copyright: (C) RINA S.p.A

#include <BinTObjDrivers_ModelDriver.hxx>

#include <BinObjMgt_Persistent.hxx>
#include <CDM_MessageDriver.hxx>
#include <Standard_GUID.hxx>
#include <TDF_Attribute.hxx>

#include <TObj_TModel.hxx>
#include <TObj_Model.hxx>
#include <TObj_Assistant.hxx>

IMPLEMENT_STANDARD_HANDLE(BinTObjDrivers_ModelDriver,BinMDF_ADriver)
IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_ModelDriver,BinMDF_ADriver);

//=======================================================================
//function : BinTObjDrivers_ModelDriver
//purpose  : constructor
//=======================================================================

BinTObjDrivers_ModelDriver::BinTObjDrivers_ModelDriver
                         (const Handle(CDM_MessageDriver)& theMessageDriver)
: BinMDF_ADriver( theMessageDriver, NULL)
{
}

//=======================================================================
//function : NewEmpty
//purpose  : Creates a new attribute
//=======================================================================

Handle(TDF_Attribute) BinTObjDrivers_ModelDriver::NewEmpty() const
{
  return new TObj_TModel;
}

//=======================================================================
//function : Paste
//purpose  : Translate the contents of <theSource> and put it
//           into <theTarget>.
//           Set CurrentModel of TObj_Assistant into theTarget TObj_TModel
//           if its GUID and GUID stored in theSource are same
//=======================================================================

Standard_Boolean BinTObjDrivers_ModelDriver::Paste
                         (const BinObjMgt_Persistent&  theSource,
                          const Handle(TDF_Attribute)& theTarget,
                          BinObjMgt_RRelocationTable&) const
{
  Standard_GUID aGUID;
  if (! (theSource >> aGUID)) return Standard_False;

  Handle(TObj_Model) aCurrentModel = TObj_Assistant::GetCurrentModel();
  if (aCurrentModel.IsNull()) return Standard_False;

  if (aGUID != aCurrentModel->GetGUID())
  {
    WriteMessage("TObj_TModel retrieval: wrong model GUID");
    return Standard_False;
  }

  Handle(TObj_TModel) aTModel = Handle(TObj_TModel)::DownCast( theTarget );
  aCurrentModel->SetLabel ( aTModel->Label() );
  aTModel->Set( aCurrentModel );
  return Standard_True;
}

//=======================================================================
//function : Paste
//purpose  : Translate the contents of <theSource> and put it
//           into <theTarget>.
//           a Model is stored as its GUID
//=======================================================================

void BinTObjDrivers_ModelDriver::Paste
                         (const Handle(TDF_Attribute)& theSource,
                          BinObjMgt_Persistent&        theTarget,
                          BinObjMgt_SRelocationTable&) const
{
  Handle(TObj_TModel) aTModel =
    Handle(TObj_TModel)::DownCast( theSource );
  Handle(TObj_Model) aModel = aTModel->Model();
  if (!aModel.IsNull())
  {
    // Store model GUID.
    Standard_GUID aGUID = aModel->GetGUID();
    theTarget << aGUID;
  }
}