0024624: Lost word in license statement in source files
[occt.git] / src / Interface / Interface_Category.cxx
1 // Copyright (c) 1999-2014 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 <Interface_Category.ixx>
15 #include <TCollection_AsciiString.hxx>
16 #include <TColStd_SequenceOfAsciiString.hxx>
17 #include <Interface_GeneralModule.hxx>
18
19 static int init = 0;
20 static Standard_CString unspec = "unspecified";
21
22 static TColStd_SequenceOfAsciiString& thecats()
23 {
24   static TColStd_SequenceOfAsciiString thecat;
25   return thecat;
26 }
27
28
29
30
31     Interface_Category::Interface_Category ()
32     : thegtool (new Interface_GTool)    {  Init();  }
33
34     Interface_Category::Interface_Category
35   (const Handle(Interface_Protocol)& protocol)
36     : thegtool (new Interface_GTool(protocol))    {  Init();  }
37
38     Interface_Category::Interface_Category
39   (const Handle(Interface_GTool)& gtool)
40     : thegtool (gtool)    {  Init();  }
41
42     void  Interface_Category::SetProtocol
43   (const Handle(Interface_Protocol)& protocol)
44       {  thegtool->SetProtocol(protocol);  }
45
46     Standard_Integer Interface_Category::CatNum
47   (const Handle(Standard_Transient)& ent, const Interface_ShareTool& shares)
48 {
49   if (ent.IsNull()) return 0;
50   Standard_Integer CN;
51   Handle(Interface_GeneralModule) module;
52   if (!thegtool->Select (ent,module,CN)) return 0;
53   return module->CategoryNumber (CN,ent,shares);
54 }
55
56     void  Interface_Category::ClearNums ()
57       {  thenum.Nullify();  }
58
59     void  Interface_Category::Compute
60   (const Handle(Interface_InterfaceModel)& model,
61    const Interface_ShareTool& shares)
62 {
63   ClearNums();
64   if (model.IsNull()) return;
65   Standard_Integer CN, i, nb = model->NbEntities();
66   thegtool->Reservate (nb);
67   if (nb == 0) return;
68   thenum = new TColStd_HArray1OfInteger (1,nb);  thenum->Init(0);
69   for (i = 1; i <= nb; i ++) {
70     Handle(Standard_Transient) ent = model->Value(i);
71     if (ent.IsNull()) continue;
72     Handle(Interface_GeneralModule) module;
73     if (!thegtool->Select (ent,module,CN)) continue;
74     thenum->SetValue (i,module->CategoryNumber (CN,ent,shares));
75   }
76 }
77
78 Standard_Integer  Interface_Category::Num (const Standard_Integer nument) const
79 {
80   if (thenum.IsNull()) return 0;
81   if (nument < 1 || nument > thenum->Length()) return 0;
82   return thenum->Value(nument);
83 }
84
85
86 //  ##########    LISTE DES CATEGORIES    ##########
87
88     Standard_Integer  Interface_Category::AddCategory (const Standard_CString name)
89 {
90   Standard_Integer num = Interface_Category::Number (name);
91   if (num > 0) return num;
92   thecats().Append (TCollection_AsciiString(name));
93   return thecats().Length()+1;
94 }
95
96     Standard_Integer  Interface_Category::NbCategories ()
97       {  return thecats().Length();  }
98
99     Standard_CString  Interface_Category::Name   (const Standard_Integer num)
100 {
101   if (num < 0) return "";
102   if (num < 1 || num > thecats().Length()) return unspec;
103   return thecats().Value(num).ToCString();
104 }
105
106
107     Standard_Integer  Interface_Category::Number (const Standard_CString name)
108 {
109   Standard_Integer i, nb = thecats().Length();
110   for (i = 1; i <= nb; i ++) {
111     if (thecats().Value(i).IsEqual(name)) return i;
112   }
113   return 0;
114 }
115
116
117     void Interface_Category::Init ()
118 {
119   if (init) return;  init = 1;
120   init = Interface_Category::AddCategory ("Shape");
121   init = Interface_Category::AddCategory ("Drawing");
122   init = Interface_Category::AddCategory ("Structure");
123   init = Interface_Category::AddCategory ("Description");
124   init = Interface_Category::AddCategory ("Auxiliary");
125   init = Interface_Category::AddCategory ("Professional");
126   init = Interface_Category::AddCategory ("FEA");
127   init = Interface_Category::AddCategory ("Kinematics");
128   init = Interface_Category::AddCategory ("Piping");
129 }