1 // Created on: 2004-11-24
2 // Created by: Edward AGAPOV
3 // Copyright (c) 2004-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 // The original implementation Copyright: (C) RINA S.p.A
23 #include <CDM_MessageDriver.hxx>
24 #include <BinObjMgt_Persistent.hxx>
25 #include <TDF_Tool.hxx>
27 #include <BinTObjDrivers_ObjectDriver.hxx>
28 #include <TObj_Assistant.hxx>
29 #include <TObj_TObject.hxx>
30 #include <TObj_Persistence.hxx>
32 IMPLEMENT_STANDARD_HANDLE(BinTObjDrivers_ObjectDriver,BinMDF_ADriver)
33 IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_ObjectDriver,BinMDF_ADriver);
35 //=======================================================================
36 //function : BinTObjDrivers_ObjectDriver
37 //purpose : constructor
38 //=======================================================================
40 BinTObjDrivers_ObjectDriver::BinTObjDrivers_ObjectDriver
41 (const Handle(CDM_MessageDriver)& theMessageDriver)
42 : BinMDF_ADriver( theMessageDriver, NULL)
46 //=======================================================================
48 //purpose : Creates a new attribute
49 //=======================================================================
51 Handle(TDF_Attribute) BinTObjDrivers_ObjectDriver::NewEmpty() const
53 return new TObj_TObject;
56 //=======================================================================
58 //purpose : Translate the contents of <theSource> and put it
60 //=======================================================================
62 Standard_Boolean BinTObjDrivers_ObjectDriver::Paste
63 (const BinObjMgt_Persistent& theSource,
64 const Handle(TDF_Attribute)& theTarget,
65 BinObjMgt_RRelocationTable&) const
67 Standard_Integer aSavedPos = theSource.Position();
69 // first try to get the type as an integer ID
70 Standard_Integer anID;
71 if (! (theSource >> anID)) return Standard_False;
72 Handle(TObj_Object) anObject;
73 if ( (unsigned)anID > 0xffff)
75 // if we are here it means that the type was stored as an ascii string,
76 // so rewind theSource and reget
77 theSource.SetPosition(aSavedPos);
78 TCollection_AsciiString aName;
79 if (! (theSource >> aName)) return Standard_False;
81 TObj_Persistence::CreateNewObject(aName.ToCString(),theTarget->Label());
82 if (anObject.IsNull())
84 TCollection_AsciiString anEntry;
85 TDF_Tool::Entry (theTarget->Label(), anEntry);
86 WriteMessage (TCollection_ExtendedString
87 ("TObj_TObject retrieval: wrong object type name ") +
88 aName + ", entry " + anEntry);
89 TObj_Assistant::BindType(0);
90 return Standard_False;
93 TObj_Assistant::BindType(anObject->DynamicType());
97 // use anID to get the type from earlier registered ones
98 Handle(Standard_Type) aType = TObj_Assistant::FindType(anID);
101 TObj_Persistence::CreateNewObject(aType->Name(), theTarget->Label());
104 return Standard_False;
107 Handle(TObj_TObject)::DownCast (theTarget) ->Set( anObject );
108 return Standard_True;
111 //=======================================================================
113 //purpose : Translate the contents of <theSource> and put it
115 // anObject is stored as a Name of class derived from TObj_Object
116 //=======================================================================
118 void BinTObjDrivers_ObjectDriver::Paste
119 (const Handle(TDF_Attribute)& theSource,
120 BinObjMgt_Persistent& theTarget,
121 BinObjMgt_SRelocationTable&) const
123 Handle(TObj_TObject) aTObj =
124 Handle(TObj_TObject)::DownCast( theSource );
125 Handle(TObj_Object) anIObject = aTObj->Get();
126 if (anIObject.IsNull()) return;
128 Handle(Standard_Type) aType = anIObject->DynamicType();
130 Standard_Integer anID = TObj_Assistant::FindTypeIndex(anIObject->DynamicType());
134 // we first meet this type;
135 // register a type and store a type name as a string
136 TObj_Assistant::BindType(aType);
137 TCollection_AsciiString aName = aType->Name();
142 // store the integer type ID