1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Interface_Category.hxx>
16 #include <Interface_GeneralModule.hxx>
17 #include <Interface_InterfaceModel.hxx>
18 #include <Interface_Protocol.hxx>
19 #include <Interface_ShareTool.hxx>
20 #include <Standard_Transient.hxx>
21 #include <Standard_Mutex.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TColStd_SequenceOfAsciiString.hxx>
24 #include <NCollection_Vector.hxx>
27 static Standard_CString unspec = "unspecified";
29 static Standard_Mutex gMapTypesMutex;
30 static volatile Standard_Boolean gMapTypesInit = Standard_False;
32 static NCollection_Vector<TCollection_AsciiString>& theCats()
34 static NCollection_Vector<TCollection_AsciiString> aCat;
38 Standard_Integer Interface_Category::CatNum
39 (const Handle(Standard_Transient)& theEnt,
40 const Interface_ShareTool& theShares)
42 if (theEnt.IsNull()) return 0;
44 Handle(Interface_GeneralModule) aModule;
45 if (!myGTool->Select (theEnt,aModule,CN)) return 0;
46 return aModule->CategoryNumber (CN,theEnt,theShares);
49 void Interface_Category::Compute
50 (const Handle(Interface_InterfaceModel)& theModel,
51 const Interface_ShareTool& theShares)
54 if (theModel.IsNull()) return;
55 Standard_Integer CN, i, nb = theModel->NbEntities();
56 myGTool->Reservate (nb);
58 myNum = new TColStd_HArray1OfInteger (1,nb); myNum->Init(0);
59 for (i = 1; i <= nb; i ++) {
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));
68 Standard_Integer Interface_Category::Num (const Standard_Integer theNumEnt) const
70 if (myNum.IsNull()) return 0;
71 if (theNumEnt < 1 || theNumEnt > myNum->Length()) return 0;
72 return myNum->Value(theNumEnt);
77 Standard_Integer Interface_Category::AddCategory (const Standard_CString theName)
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;
85 Standard_Integer Interface_Category::NbCategories()
87 return theCats().Length();
90 Standard_CString Interface_Category::Name (const Standard_Integer theNum)
92 if (theNum < 0) return "";
93 if (theNum < theCats().Lower() || theNum > theCats().Upper()) return unspec;
94 return theCats().ChangeValue(theNum).ToCString();
97 Standard_Integer Interface_Category::Number (const Standard_CString theName)
100 for (i = theCats().Lower(); i <= theCats().Upper(); i ++) {
101 if (theCats().ChangeValue(i).IsEqual(theName)) return i;
106 void Interface_Category::Init ()
108 // On first call, initialize static map
109 if ( !gMapTypesInit )
111 gMapTypesMutex.Lock();
112 if ( !gMapTypesInit )
114 if (init) return; init = 1;
115 init = Interface_Category::AddCategory ("Shape");
116 init = Interface_Category::AddCategory ("Drawing");
117 init = Interface_Category::AddCategory ("Structure");
118 init = Interface_Category::AddCategory ("Description");
119 init = Interface_Category::AddCategory ("Auxiliary");
120 init = Interface_Category::AddCategory ("Professional");
121 init = Interface_Category::AddCategory ("FEA");
122 init = Interface_Category::AddCategory ("Kinematics");
123 init = Interface_Category::AddCategory ("Piping");
125 gMapTypesInit = Standard_True;
127 gMapTypesMutex.Unlock();