0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / BinTObjDrivers / BinTObjDrivers_ModelDriver.cxx
CommitLineData
b311480e 1// Created on: 2004-11-24
2// Created by: Edward AGAPOV
973c2be1 3// Copyright (c) 2004-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.
b311480e 15
7fd59977 16// The original implementation Copyright: (C) RINA S.p.A
17
18#include <BinTObjDrivers_ModelDriver.hxx>
19
20#include <BinObjMgt_Persistent.hxx>
21#include <CDM_MessageDriver.hxx>
22#include <Standard_GUID.hxx>
23#include <TDF_Attribute.hxx>
24
25#include <TObj_TModel.hxx>
26#include <TObj_Model.hxx>
27#include <TObj_Assistant.hxx>
28
ec357c5c 29
30
7fd59977 31
92efcf78 32IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_ModelDriver,BinMDF_ADriver)
33
7fd59977 34//=======================================================================
35//function : BinTObjDrivers_ModelDriver
36//purpose : constructor
37//=======================================================================
38
39BinTObjDrivers_ModelDriver::BinTObjDrivers_ModelDriver
40 (const Handle(CDM_MessageDriver)& theMessageDriver)
41: BinMDF_ADriver( theMessageDriver, NULL)
42{
43}
44
45//=======================================================================
46//function : NewEmpty
47//purpose : Creates a new attribute
48//=======================================================================
49
50Handle(TDF_Attribute) BinTObjDrivers_ModelDriver::NewEmpty() const
51{
52 return new TObj_TModel;
53}
54
55//=======================================================================
56//function : Paste
57//purpose : Translate the contents of <theSource> and put it
58// into <theTarget>.
59// Set CurrentModel of TObj_Assistant into theTarget TObj_TModel
60// if its GUID and GUID stored in theSource are same
61//=======================================================================
62
63Standard_Boolean BinTObjDrivers_ModelDriver::Paste
64 (const BinObjMgt_Persistent& theSource,
65 const Handle(TDF_Attribute)& theTarget,
66 BinObjMgt_RRelocationTable&) const
67{
68 Standard_GUID aGUID;
69 if (! (theSource >> aGUID)) return Standard_False;
70
71 Handle(TObj_Model) aCurrentModel = TObj_Assistant::GetCurrentModel();
72 if (aCurrentModel.IsNull()) return Standard_False;
73
74 if (aGUID != aCurrentModel->GetGUID())
75 {
76 WriteMessage("TObj_TModel retrieval: wrong model GUID");
77 return Standard_False;
78 }
79
80 Handle(TObj_TModel) aTModel = Handle(TObj_TModel)::DownCast( theTarget );
81 aCurrentModel->SetLabel ( aTModel->Label() );
82 aTModel->Set( aCurrentModel );
83 return Standard_True;
84}
85
86//=======================================================================
87//function : Paste
88//purpose : Translate the contents of <theSource> and put it
89// into <theTarget>.
90// a Model is stored as its GUID
91//=======================================================================
92
93void BinTObjDrivers_ModelDriver::Paste
94 (const Handle(TDF_Attribute)& theSource,
95 BinObjMgt_Persistent& theTarget,
96 BinObjMgt_SRelocationTable&) const
97{
98 Handle(TObj_TModel) aTModel =
99 Handle(TObj_TModel)::DownCast( theSource );
100 Handle(TObj_Model) aModel = aTModel->Model();
101 if (!aModel.IsNull())
102 {
103 // Store model GUID.
104 Standard_GUID aGUID = aModel->GetGUID();
105 theTarget << aGUID;
106 }
107}