0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / TFunction / TFunction_DriverTable.cxx
1 // Created on: 1999-06-11
2 // Created by: Vladislav ROMASHKO
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Standard_GUID.hxx>
19 #include <Standard_Type.hxx>
20 #include <TCollection_ExtendedString.hxx>
21 #include <TDF.hxx>
22 #include <TFunction_DataMapIteratorOfDataMapOfGUIDDriver.hxx>
23 #include <TFunction_DataMapOfGUIDDriver.hxx>
24 #include <TFunction_Driver.hxx>
25 #include <TFunction_DriverTable.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(TFunction_DriverTable,Standard_Transient)
28
29 static Handle(TFunction_DriverTable) DT;
30
31 //=======================================================================
32 //function : Get
33 //purpose  : 
34 //=======================================================================
35
36 Handle(TFunction_DriverTable) TFunction_DriverTable::Get()
37 {
38   if (DT.IsNull()) DT = new TFunction_DriverTable;
39   return DT;
40 }
41
42 //=======================================================================
43 //function : TFunction_DriverTable
44 //purpose  : Constructor
45 //=======================================================================
46
47 TFunction_DriverTable::TFunction_DriverTable()
48 {}
49
50 //=======================================================================
51 //function : AddDriver
52 //purpose  : Adds a driver to the DriverTable
53 //=======================================================================
54
55 Standard_Boolean TFunction_DriverTable::AddDriver(const Standard_GUID&            guid,
56                                                   const Handle(TFunction_Driver)& driver,
57                                                   const Standard_Integer          thread)
58 {
59   if (thread == 0)
60     return myDrivers.Bind(guid,driver);
61   else if (thread > 0) 
62   {
63     if (myThreadDrivers.IsNull())
64     {
65       // Create a new table for thread-drivers.
66       myThreadDrivers = new TFunction_HArray1OfDataMapOfGUIDDriver(1, thread);
67     }
68     else if (myThreadDrivers->Upper() < thread)
69     {
70       // Create a bigger table for thread-drivers.
71       Handle(TFunction_HArray1OfDataMapOfGUIDDriver) new_dt = new TFunction_HArray1OfDataMapOfGUIDDriver(1, thread);
72       // Copy old table to the expanded (new) one.
73       Standard_Integer i = 1, old_upper = myThreadDrivers->Upper();
74       for (; i <= old_upper; i++)
75       {
76         const TFunction_DataMapOfGUIDDriver& t = myThreadDrivers->Value(i);
77         TFunction_DataMapIteratorOfDataMapOfGUIDDriver itrt(t);
78         for (; itrt.More(); itrt.Next())
79         {
80           new_dt->ChangeValue(i).Bind(itrt.Key(), itrt.Value());
81         }
82       }//for...
83       myThreadDrivers = new_dt;
84     }//else...
85     return myThreadDrivers->ChangeValue(thread).Bind(guid, driver);
86   }
87   return Standard_False;
88 }
89
90 //=======================================================================
91 //function : HasDriver
92 //purpose  : 
93 //=======================================================================
94
95 Standard_Boolean TFunction_DriverTable::HasDriver(const Standard_GUID&   guid,
96                                                   const Standard_Integer thread) const
97 {
98   if (thread == 0)
99     return myDrivers.IsBound(guid);
100   else if (thread > 0 && !myThreadDrivers.IsNull() && myThreadDrivers->Upper() >= thread)
101     return myThreadDrivers->Value(thread).IsBound(guid);
102   return Standard_False;
103 }
104
105 //=======================================================================
106 //function : FindDriver
107 //purpose  : Returns the driver if find
108 //=======================================================================
109
110 Standard_Boolean TFunction_DriverTable::FindDriver(const Standard_GUID&      guid,
111                                                    Handle(TFunction_Driver)& driver,
112                                                    const Standard_Integer    thread) const
113 {
114   if (thread == 0)
115   {
116     if (myDrivers.IsBound(guid))
117     {
118       driver = myDrivers.Find(guid);
119       return Standard_True;
120     }
121   }
122   else if (thread > 0 && !myThreadDrivers.IsNull() && myThreadDrivers->Upper() >= thread)
123   {
124     if (myThreadDrivers->Value(thread).IsBound(guid))
125     {
126       driver = myThreadDrivers->Value(thread).Find(guid);
127       return Standard_True;
128     }
129   }
130   return Standard_False;
131 }
132
133 //=======================================================================
134 //function : Dump
135 //purpose  : 
136 //=======================================================================
137
138 Standard_OStream& TFunction_DriverTable::Dump(Standard_OStream& anOS) const
139 {
140   TFunction_DataMapIteratorOfDataMapOfGUIDDriver itr(myDrivers);
141   for (; itr.More(); itr.Next())
142   {
143     itr.Key().ShallowDump(anOS); 
144     anOS<<"\t";
145     TCollection_ExtendedString es;
146     TDF::ProgIDFromGUID(itr.Key(), es);
147     anOS<<es<<"\n";
148   }
149   return anOS;
150 }
151
152 //=======================================================================
153 //function : RemoveDriver
154 //purpose  : Removes a driver from the DriverTable
155 //=======================================================================
156
157 Standard_Boolean TFunction_DriverTable::RemoveDriver(const Standard_GUID&   guid,
158                                                      const Standard_Integer thread)
159 {
160   if (thread == 0)
161     return myDrivers.UnBind(guid);
162   else if (thread > 0 && !myThreadDrivers.IsNull() && myThreadDrivers->Upper() >= thread)
163     myThreadDrivers->ChangeValue(thread).UnBind(guid);
164   return Standard_False;
165 }
166
167 //=======================================================================
168 //function : Clear
169 //purpose  : Removes all drivers
170 //=======================================================================
171
172 void TFunction_DriverTable::Clear()
173 {
174   myDrivers.Clear();
175   if (!myThreadDrivers.IsNull())
176     myThreadDrivers.Nullify();
177 }