973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
15 | #include <Interface_Category.hxx> |
16 | #include <Interface_GeneralModule.hxx> |
42cf5bc1 |
17 | #include <Interface_InterfaceModel.hxx> |
18 | #include <Interface_Protocol.hxx> |
19 | #include <Interface_ShareTool.hxx> |
20 | #include <Standard_Transient.hxx> |
7f56eba8 |
21 | #include <Standard_Mutex.hxx> |
7fd59977 |
22 | #include <TCollection_AsciiString.hxx> |
23 | #include <TColStd_SequenceOfAsciiString.hxx> |
7f56eba8 |
24 | #include <NCollection_Vector.hxx> |
7fd59977 |
25 | |
c48e2889 |
26 | static int THE_Interface_Category_init = 0; |
7fd59977 |
27 | static Standard_CString unspec = "unspecified"; |
28 | |
7f56eba8 |
29 | static Standard_Mutex gMapTypesMutex; |
30 | static volatile Standard_Boolean gMapTypesInit = Standard_False; |
31 | |
32 | static NCollection_Vector<TCollection_AsciiString>& theCats() |
7fd59977 |
33 | { |
7f56eba8 |
34 | static NCollection_Vector<TCollection_AsciiString> aCat; |
35 | return aCat; |
7fd59977 |
36 | } |
37 | |
7f56eba8 |
38 | Standard_Integer Interface_Category::CatNum |
39 | (const Handle(Standard_Transient)& theEnt, |
40 | const Interface_ShareTool& theShares) |
7fd59977 |
41 | { |
7f56eba8 |
42 | if (theEnt.IsNull()) return 0; |
7fd59977 |
43 | Standard_Integer CN; |
7f56eba8 |
44 | Handle(Interface_GeneralModule) aModule; |
45 | if (!myGTool->Select (theEnt,aModule,CN)) return 0; |
46 | return aModule->CategoryNumber (CN,theEnt,theShares); |
7fd59977 |
47 | } |
48 | |
7f56eba8 |
49 | void Interface_Category::Compute |
50 | (const Handle(Interface_InterfaceModel)& theModel, |
51 | const Interface_ShareTool& theShares) |
7fd59977 |
52 | { |
53 | ClearNums(); |
7f56eba8 |
54 | if (theModel.IsNull()) return; |
55 | Standard_Integer CN, i, nb = theModel->NbEntities(); |
56 | myGTool->Reservate (nb); |
7fd59977 |
57 | if (nb == 0) return; |
7f56eba8 |
58 | myNum = new TColStd_HArray1OfInteger (1,nb); myNum->Init(0); |
7fd59977 |
59 | for (i = 1; i <= nb; i ++) { |
7f56eba8 |
60 | Handle(Standard_Transient) anEnt = theModel->Value(i); |
61 | if (anEnt.IsNull()) continue; |
62 | Handle(Interface_GeneralModule) aModule; |
63 | if (!myGTool->Select (anEnt,aModule,CN)) continue; |
64 | myNum->SetValue (i,aModule->CategoryNumber (CN,anEnt,theShares)); |
7fd59977 |
65 | } |
66 | } |
67 | |
7f56eba8 |
68 | Standard_Integer Interface_Category::Num (const Standard_Integer theNumEnt) const |
7fd59977 |
69 | { |
7f56eba8 |
70 | if (myNum.IsNull()) return 0; |
71 | if (theNumEnt < 1 || theNumEnt > myNum->Length()) return 0; |
72 | return myNum->Value(theNumEnt); |
7fd59977 |
73 | } |
74 | |
7f56eba8 |
75 | // List of Categories |
7fd59977 |
76 | |
7f56eba8 |
77 | Standard_Integer Interface_Category::AddCategory (const Standard_CString theName) |
7fd59977 |
78 | { |
7f56eba8 |
79 | Standard_Integer aNum = Interface_Category::Number (theName); |
80 | if (aNum > 0) return aNum; |
81 | theCats().Append (TCollection_AsciiString(theName)); |
82 | return theCats().Length()+1; |
7fd59977 |
83 | } |
84 | |
7f56eba8 |
85 | Standard_Integer Interface_Category::NbCategories() |
7fd59977 |
86 | { |
7f56eba8 |
87 | return theCats().Length(); |
7fd59977 |
88 | } |
89 | |
7f56eba8 |
90 | Standard_CString Interface_Category::Name (const Standard_Integer theNum) |
91 | { |
92 | if (theNum < 0) return ""; |
3e64931d |
93 | if (theNum < theCats().Lower() || theNum > theCats().Upper()) return unspec; |
7f56eba8 |
94 | return theCats().ChangeValue(theNum).ToCString(); |
95 | } |
7fd59977 |
96 | |
7f56eba8 |
97 | Standard_Integer Interface_Category::Number (const Standard_CString theName) |
7fd59977 |
98 | { |
3e64931d |
99 | Standard_Integer i; |
100 | for (i = theCats().Lower(); i <= theCats().Upper(); i ++) { |
7f56eba8 |
101 | if (theCats().ChangeValue(i).IsEqual(theName)) return i; |
7fd59977 |
102 | } |
103 | return 0; |
104 | } |
105 | |
7f56eba8 |
106 | void Interface_Category::Init () |
7fd59977 |
107 | { |
7f56eba8 |
108 | // On first call, initialize static map |
109 | if ( !gMapTypesInit ) |
110 | { |
111 | gMapTypesMutex.Lock(); |
112 | if ( !gMapTypesInit ) |
113 | { |
c48e2889 |
114 | if (THE_Interface_Category_init) |
115 | { |
116 | return; |
117 | } |
118 | |
119 | THE_Interface_Category_init = 1; |
120 | Interface_Category::AddCategory ("Shape"); |
121 | Interface_Category::AddCategory ("Drawing"); |
122 | Interface_Category::AddCategory ("Structure"); |
123 | Interface_Category::AddCategory ("Description"); |
124 | Interface_Category::AddCategory ("Auxiliary"); |
125 | Interface_Category::AddCategory ("Professional"); |
126 | Interface_Category::AddCategory ("FEA"); |
127 | Interface_Category::AddCategory ("Kinematics"); |
128 | Interface_Category::AddCategory ("Piping"); |
7f56eba8 |
129 | |
130 | gMapTypesInit = Standard_True; |
131 | } |
132 | gMapTypesMutex.Unlock(); |
133 | } |
7fd59977 |
134 | } |