0030773: Application Framework - To allow to inherit existing attributes to reuse...
[occt.git] / src / XmlMDF / XmlMDF_ADriverTable.cxx
CommitLineData
b311480e 1// Created on: 2001-09-26
2// Created by: Julia DOROVSKIKH
973c2be1 3// Copyright (c) 2001-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.
7fd59977 15
c99ad5d7 16#include <XmlMDF_ADriverTable.hxx>
42cf5bc1 17
c99ad5d7 18#include <Message_Messenger.hxx>
19#include <TDF_DerivedAttribute.hxx>
20#include <TDF_AttributeList.hxx>
42cf5bc1 21#include <XmlMDF_ADriver.hxx>
c99ad5d7 22#include <XmlMDF_DerivedDriver.hxx>
7fd59977 23
25e59720 24IMPLEMENT_STANDARD_RTTIEXT(XmlMDF_ADriverTable,Standard_Transient)
92efcf78 25
7fd59977 26//=======================================================================
27//function : MDF_ADriverTable
28//purpose :
29//=======================================================================
30XmlMDF_ADriverTable::XmlMDF_ADriverTable()
31{}
32
33//=======================================================================
34//function : AddDriver
35//purpose :
36//=======================================================================
37void XmlMDF_ADriverTable::AddDriver (const Handle(XmlMDF_ADriver)& anHDriver)
38{
39 const Handle(Standard_Type)& type = anHDriver->SourceType();
40
41 // to make possible for applications to redefine standard attribute drivers
42 myMap.UnBind(type);
43
44 myMap.Bind(type,anHDriver);
45}
46
47//=======================================================================
c99ad5d7 48//function : AddDerivedDriver
49//purpose :
50//=======================================================================
51void XmlMDF_ADriverTable::AddDerivedDriver (const Handle(TDF_Attribute)& theInstance)
52{
53 const Handle(Standard_Type)& anInstanceType = theInstance->DynamicType();
54 if (!myMap.IsBound (anInstanceType)) // no direct driver, use a derived one
55 {
56 for (Handle(Standard_Type) aType = anInstanceType->Parent(); !aType.IsNull(); aType = aType->Parent())
57 {
58 if (myMap.IsBound (aType))
59 {
60 Handle(XmlMDF_ADriver) aDriver = new XmlMDF_DerivedDriver (theInstance, myMap (aType));
61 myMap.Bind (anInstanceType, aDriver);
62 return;
63 }
64 }
65 }
66}
67
7fd59977 68//=======================================================================
c99ad5d7 69//function : AddDerivedDriver
70//purpose :
71//=======================================================================
72const Handle(Standard_Type)& XmlMDF_ADriverTable::AddDerivedDriver (Standard_CString theDerivedType)
7fd59977 73{
c99ad5d7 74 if (Handle(TDF_Attribute) anInstance = TDF_DerivedAttribute::Attribute (theDerivedType))
75 {
76 AddDerivedDriver (anInstance);
77 return anInstance->DynamicType();
78 }
79 static const Handle(Standard_Type) aNullType;
80 return aNullType;
7fd59977 81}
82
83//=======================================================================
84//function : GetDriver
85//purpose :
86//=======================================================================
87Standard_Boolean XmlMDF_ADriverTable::GetDriver
88 (const Handle(Standard_Type)& aType,
c99ad5d7 89 Handle(XmlMDF_ADriver)& anHDriver)
7fd59977 90{
c99ad5d7 91 if (!myMap.IsBound (aType)) // try to assign driver for derived type
92 {
93 AddDerivedDriver (aType->Name());
94 }
7fd59977 95 if (myMap.IsBound(aType))
96 {
97 anHDriver = myMap.Find(aType);
98 return Standard_True;
99 }
100 return Standard_False;
101}
c99ad5d7 102
103//=======================================================================
104//function : CreateDrvMap
105//purpose :
106//=======================================================================
107void XmlMDF_ADriverTable::CreateDrvMap (XmlMDF_MapOfDriver& theDriverMap)
108{
109 // add derived drivers not yet registered in the map
110 TDF_AttributeList aDerived;
111 TDF_DerivedAttribute::Attributes (aDerived);
112 for (TDF_AttributeList::Iterator aDerIter (aDerived); aDerIter.More(); aDerIter.Next())
113 {
114 if (!myMap.IsBound (aDerIter.Value()->DynamicType()))
115 {
116 AddDerivedDriver (aDerIter.Value());
117 }
118 }
119
120 // put everything to the map
121 for (XmlMDF_DataMapIteratorOfTypeADriverMap anIter (myMap); anIter.More(); anIter.Next())
122 {
123 const Handle(XmlMDF_ADriver)& aDriver = anIter.Value();
124 const TCollection_AsciiString aTypeName = aDriver->TypeName();
125 if (!theDriverMap.IsBound (aTypeName))
126 {
127 theDriverMap.Bind (aTypeName, aDriver);
128 }
129 else
130 {
131 aDriver->MessageDriver()->Send (TCollection_AsciiString ("Warning: skipped driver name: \"")
132 + aTypeName + "\"", Message_Warning);
133 }
134 }
135}