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 IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_ObjectDriver,BinMDF_ADriver)
33 //=======================================================================
34 //function : BinTObjDrivers_ObjectDriver
35 //purpose : constructor
36 //=======================================================================
38 BinTObjDrivers_ObjectDriver::BinTObjDrivers_ObjectDriver
39 (const Handle(CDM_MessageDriver)& theMessageDriver)
40 : BinMDF_ADriver( theMessageDriver, NULL)
44 //=======================================================================
46 //purpose : Creates a new attribute
47 //=======================================================================
49 Handle(TDF_Attribute) BinTObjDrivers_ObjectDriver::NewEmpty() const
51 return new TObj_TObject;
54 //=======================================================================
56 //purpose : Translate the contents of <theSource> and put it
58 //=======================================================================
60 Standard_Boolean BinTObjDrivers_ObjectDriver::Paste
61 (const BinObjMgt_Persistent& theSource,
62 const Handle(TDF_Attribute)& theTarget,
63 BinObjMgt_RRelocationTable&) const
65 Standard_Integer aSavedPos = theSource.Position();
67 // first try to get the type as an integer ID
68 Standard_Integer anID;
69 if (! (theSource >> anID)) return Standard_False;
70 Handle(TObj_Object) anObject;
71 if ( (unsigned)anID > 0xffff)
73 // if we are here it means that the type was stored as an ascii string,
74 // so rewind theSource and reget
75 theSource.SetPosition(aSavedPos);
76 TCollection_AsciiString aName;
77 if (! (theSource >> aName)) return Standard_False;
79 TObj_Persistence::CreateNewObject(aName.ToCString(),theTarget->Label());
80 if (anObject.IsNull())
82 TCollection_AsciiString anEntry;
83 TDF_Tool::Entry (theTarget->Label(), anEntry);
84 WriteMessage (TCollection_ExtendedString
85 ("TObj_TObject retrieval: wrong object type name ") +
86 aName + ", entry " + anEntry);
87 TObj_Assistant::BindType(0);
88 return Standard_False;
91 TObj_Assistant::BindType(anObject->DynamicType());
95 // use anID to get the type from earlier registered ones
96 Handle(Standard_Type) aType = TObj_Assistant::FindType(anID);
99 TObj_Persistence::CreateNewObject(aType->Name(), theTarget->Label());
102 return Standard_False;
105 Handle(TObj_TObject)::DownCast (theTarget) ->Set( anObject );
106 return Standard_True;
109 //=======================================================================
111 //purpose : Translate the contents of <theSource> and put it
113 // anObject is stored as a Name of class derived from TObj_Object
114 //=======================================================================
116 void BinTObjDrivers_ObjectDriver::Paste
117 (const Handle(TDF_Attribute)& theSource,
118 BinObjMgt_Persistent& theTarget,
119 BinObjMgt_SRelocationTable&) const
121 Handle(TObj_TObject) aTObj =
122 Handle(TObj_TObject)::DownCast( theSource );
123 Handle(TObj_Object) anIObject = aTObj->Get();
124 if (anIObject.IsNull()) return;
126 Handle(Standard_Type) aType = anIObject->DynamicType();
128 Standard_Integer anID = TObj_Assistant::FindTypeIndex(anIObject->DynamicType());
132 // we first meet this type;
133 // register a type and store a type name as a string
134 TObj_Assistant::BindType(aType);
135 TCollection_AsciiString aName = aType->Name();
140 // store the integer type ID