1 // Copyright (c) 2021 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13 
14 #include <Graphic3d_GraphicDriverFactory.hxx>
15 
16 #include <Graphic3d_GraphicDriver.hxx>
17 
18 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_GraphicDriverFactory, Standard_Transient)
19 
20 namespace
21 {
getDriverFactories()22   static Graphic3d_GraphicDriverFactoryList& getDriverFactories()
23   {
24     static Graphic3d_GraphicDriverFactoryList TheFactories;
25     return TheFactories;
26   }
27 }
28 
29 // =======================================================================
30 // function : DriverFactories
31 // purpose  :
32 // =======================================================================
DriverFactories()33 const Graphic3d_GraphicDriverFactoryList& Graphic3d_GraphicDriverFactory::DriverFactories()
34 {
35   return getDriverFactories();
36 }
37 
38 // =======================================================================
39 // function : RegisterFactory
40 // purpose  :
41 // =======================================================================
RegisterFactory(const Handle (Graphic3d_GraphicDriverFactory)& theFactory,bool theIsPreferred)42 void Graphic3d_GraphicDriverFactory::RegisterFactory (const Handle(Graphic3d_GraphicDriverFactory)& theFactory,
43                                                       bool theIsPreferred)
44 {
45   const TCollection_AsciiString aName = theFactory->Name();
46   Graphic3d_GraphicDriverFactoryList& aFactories = getDriverFactories();
47   if (theIsPreferred)
48   {
49     UnregisterFactory (aName);
50     aFactories.Prepend (theFactory);
51     return;
52   }
53 
54   for (Graphic3d_GraphicDriverFactoryList::Iterator anIter (aFactories); anIter.More(); anIter.Next())
55   {
56     if (TCollection_AsciiString::IsSameString (anIter.Value()->Name(), aName, false))
57     {
58       return;
59     }
60   }
61   aFactories.Append (theFactory);
62 }
63 
64 // =======================================================================
65 // function : UnregisterFactory
66 // purpose  :
67 // =======================================================================
UnregisterFactory(const TCollection_AsciiString & theName)68 void Graphic3d_GraphicDriverFactory::UnregisterFactory (const TCollection_AsciiString& theName)
69 {
70   Graphic3d_GraphicDriverFactoryList& aFactories = getDriverFactories();
71   for (Graphic3d_GraphicDriverFactoryList::Iterator anIter (aFactories); anIter.More();)
72   {
73     if (TCollection_AsciiString::IsSameString (anIter.Value()->Name(), theName, false))
74     {
75       aFactories.Remove (anIter);
76     }
77     else
78     {
79       anIter.Next();
80     }
81   }
82 }
83 
84 // =======================================================================
85 // function : DefaultDriverFactory
86 // purpose  :
87 // =======================================================================
Handle(Graphic3d_GraphicDriverFactory)88 Handle(Graphic3d_GraphicDriverFactory) Graphic3d_GraphicDriverFactory::DefaultDriverFactory()
89 {
90   const Graphic3d_GraphicDriverFactoryList& aMap = getDriverFactories();
91   return !aMap.IsEmpty()
92         ? aMap.First()
93         : Handle(Graphic3d_GraphicDriverFactory)();
94 }
95 
96 // =======================================================================
97 // function : Graphic3d_GraphicDriverFactory
98 // purpose  :
99 // =======================================================================
Graphic3d_GraphicDriverFactory(const TCollection_AsciiString & theName)100 Graphic3d_GraphicDriverFactory::Graphic3d_GraphicDriverFactory (const TCollection_AsciiString& theName)
101 : myName (theName)
102 {
103   //
104 }
105