1 // Created on: 2004-11-24
2 // Created by: Edward AGAPOV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // The original implementation Copyright: (C) RINA S.p.A
19 #include <CDM_MessageDriver.hxx>
20 #include <BinObjMgt_Persistent.hxx>
21 #include <TDF_Tool.hxx>
23 #include <BinTObjDrivers_ObjectDriver.hxx>
24 #include <TObj_Assistant.hxx>
25 #include <TObj_TObject.hxx>
26 #include <TObj_Persistence.hxx>
31 //=======================================================================
32 //function : BinTObjDrivers_ObjectDriver
33 //purpose : constructor
34 //=======================================================================
36 BinTObjDrivers_ObjectDriver::BinTObjDrivers_ObjectDriver
37 (const Handle(CDM_MessageDriver)& theMessageDriver)
38 : BinMDF_ADriver( theMessageDriver, NULL)
42 //=======================================================================
44 //purpose : Creates a new attribute
45 //=======================================================================
47 Handle(TDF_Attribute) BinTObjDrivers_ObjectDriver::NewEmpty() const
49 return new TObj_TObject;
52 //=======================================================================
54 //purpose : Translate the contents of <theSource> and put it
56 //=======================================================================
58 Standard_Boolean BinTObjDrivers_ObjectDriver::Paste
59 (const BinObjMgt_Persistent& theSource,
60 const Handle(TDF_Attribute)& theTarget,
61 BinObjMgt_RRelocationTable&) const
63 Standard_Integer aSavedPos = theSource.Position();
65 // first try to get the type as an integer ID
66 Standard_Integer anID;
67 if (! (theSource >> anID)) return Standard_False;
68 Handle(TObj_Object) anObject;
69 if ( (unsigned)anID > 0xffff)
71 // if we are here it means that the type was stored as an ascii string,
72 // so rewind theSource and reget
73 theSource.SetPosition(aSavedPos);
74 TCollection_AsciiString aName;
75 if (! (theSource >> aName)) return Standard_False;
77 TObj_Persistence::CreateNewObject(aName.ToCString(),theTarget->Label());
78 if (anObject.IsNull())
80 TCollection_AsciiString anEntry;
81 TDF_Tool::Entry (theTarget->Label(), anEntry);
82 WriteMessage (TCollection_ExtendedString
83 ("TObj_TObject retrieval: wrong object type name ") +
84 aName + ", entry " + anEntry);
85 TObj_Assistant::BindType(0);
86 return Standard_False;
89 TObj_Assistant::BindType(anObject->DynamicType());
93 // use anID to get the type from earlier registered ones
94 Handle(Standard_Type) aType = TObj_Assistant::FindType(anID);
97 TObj_Persistence::CreateNewObject(aType->Name(), theTarget->Label());
100 return Standard_False;
103 Handle(TObj_TObject)::DownCast (theTarget) ->Set( anObject );
104 return Standard_True;
107 //=======================================================================
109 //purpose : Translate the contents of <theSource> and put it
111 // anObject is stored as a Name of class derived from TObj_Object
112 //=======================================================================
114 void BinTObjDrivers_ObjectDriver::Paste
115 (const Handle(TDF_Attribute)& theSource,
116 BinObjMgt_Persistent& theTarget,
117 BinObjMgt_SRelocationTable&) const
119 Handle(TObj_TObject) aTObj =
120 Handle(TObj_TObject)::DownCast( theSource );
121 Handle(TObj_Object) anIObject = aTObj->Get();
122 if (anIObject.IsNull()) return;
124 Handle(Standard_Type) aType = anIObject->DynamicType();
126 Standard_Integer anID = TObj_Assistant::FindTypeIndex(anIObject->DynamicType());
130 // we first meet this type;
131 // register a type and store a type name as a string
132 TObj_Assistant::BindType(aType);
133 TCollection_AsciiString aName = aType->Name();
138 // store the integer type ID