1 // Created on: 2004-11-22
2 // Created by: Pavel TELKOV
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
18 #include <TObj_Assistant.hxx>
20 #include <TObj_Common.hxx>
21 #include <TObj_Model.hxx>
22 #include <TColStd_SequenceOfTransient.hxx>
23 #include <TColStd_SequenceOfAsciiString.hxx>
24 #include <TColStd_IndexedMapOfTransient.hxx>
25 #include <Standard_Type.hxx>
27 //=======================================================================
28 //function : getModels
30 //=======================================================================
32 TColStd_SequenceOfTransient& TObj_Assistant::getModels()
34 static TColStd_SequenceOfTransient sModels;
38 //=======================================================================
41 //=======================================================================
43 TColStd_IndexedMapOfTransient& TObj_Assistant::getTypes()
45 static TColStd_IndexedMapOfTransient sTypes;
49 //=======================================================================
52 //=======================================================================
54 Handle(TObj_Model)& TObj_Assistant::getCurrentModel()
56 static Handle(TObj_Model) sCurrentModel;
60 //=======================================================================
61 //function : getVersion
63 //=======================================================================
65 Standard_Integer& TObj_Assistant::getVersion()
67 static Standard_Integer sVersion = 0;
71 //=======================================================================
72 //function : FindModel
74 //=======================================================================
76 Handle(TObj_Model) TObj_Assistant::FindModel
77 (const Standard_CString theName)
79 TCollection_ExtendedString aName( theName );
80 Standard_Integer i = getModels().Length();
81 Handle(TObj_Model) aModel;
84 aModel = Handle(TObj_Model)::DownCast(getModels().Value( i ));
85 if ( aName == aModel->GetModelName()->String() )
94 //=======================================================================
95 //function : BindModel
97 //=======================================================================
99 void TObj_Assistant::BindModel (const Handle(TObj_Model) theModel)
101 getModels().Append(theModel);
104 //=======================================================================
107 //=======================================================================
109 void TObj_Assistant::ClearModelMap ()
114 //=======================================================================
115 //function : FindType
117 //=======================================================================
119 Handle(Standard_Type) TObj_Assistant::FindType
120 (const Standard_Integer theTypeIndex)
122 if(theTypeIndex > 0 && theTypeIndex <= getTypes().Extent())
123 return Handle(Standard_Type)::DownCast(getTypes().FindKey(theTypeIndex));
128 //=======================================================================
129 //function : FindTypeIndex
131 //=======================================================================
133 Standard_Integer TObj_Assistant::FindTypeIndex
134 (const Handle(Standard_Type)& theType)
136 if(!getTypes().Contains(theType))
139 return getTypes().FindIndex(theType);
142 //=======================================================================
143 //class : TObj_Assistant_UnknownType
145 //=======================================================================
147 class TObj_Assistant_UnknownType : public Standard_Transient
151 TObj_Assistant_UnknownType() {}
155 DEFINE_STANDARD_RTTI_INLINE(TObj_Assistant_UnknownType,Standard_Transient)
158 // Define handle class for TObj_Assistant_UnknownType
159 DEFINE_STANDARD_HANDLE(TObj_Assistant_UnknownType,Standard_Transient)
162 //=======================================================================
163 //function : BindType
165 //=======================================================================
167 Standard_Integer TObj_Assistant::BindType
168 (const Handle(Standard_Type)& theType)
172 Handle(Standard_Transient) anUnknownType;
173 anUnknownType = new TObj_Assistant_UnknownType;
174 return getTypes().Add(anUnknownType);
177 return getTypes().Add(theType);
180 //=======================================================================
181 //function : ClearTypeMap
183 //=======================================================================
185 void TObj_Assistant::ClearTypeMap ()
190 //=======================================================================
191 //function : SetCurrentModel
193 //=======================================================================
195 void TObj_Assistant::SetCurrentModel (const Handle(TObj_Model)& theModel)
197 getCurrentModel() = theModel;
201 //=======================================================================
202 //function : GetCurrentModel
204 //=======================================================================
206 Handle(TObj_Model) TObj_Assistant::GetCurrentModel ()
208 return getCurrentModel();
211 //=======================================================================
212 //function : UnSetCurrentModel
214 //=======================================================================
216 void TObj_Assistant::UnSetCurrentModel ()
218 getCurrentModel().Nullify();
221 //=======================================================================
222 //function : GetAppVersion
224 //=======================================================================
226 Standard_Integer TObj_Assistant::GetAppVersion()
228 Standard_Integer& aVersion = getVersion();
231 Handle(TObj_Model)& aModel = getCurrentModel();
232 if (!aModel.IsNull())
233 aVersion = aModel->GetFormatVersion();