Test for 0022778: Bug in BRepMesh
[occt.git] / src / Interface / Interface_Category.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <Interface_Category.ixx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TColStd_SequenceOfAsciiString.hxx>
21 #include <Interface_GeneralModule.hxx>
22
23 static int init = 0;
24 static Standard_CString unspec = "unspecified";
25
26 static TColStd_SequenceOfAsciiString& thecats()
27 {
28   static TColStd_SequenceOfAsciiString thecat;
29   return thecat;
30 }
31
32
33
34
35     Interface_Category::Interface_Category ()
36     : thegtool (new Interface_GTool)    {  Init();  }
37
38     Interface_Category::Interface_Category
39   (const Handle(Interface_Protocol)& protocol)
40     : thegtool (new Interface_GTool(protocol))    {  Init();  }
41
42     Interface_Category::Interface_Category
43   (const Handle(Interface_GTool)& gtool)
44     : thegtool (gtool)    {  Init();  }
45
46     void  Interface_Category::SetProtocol
47   (const Handle(Interface_Protocol)& protocol)
48       {  thegtool->SetProtocol(protocol);  }
49
50     Standard_Integer Interface_Category::CatNum
51   (const Handle(Standard_Transient)& ent, const Interface_ShareTool& shares)
52 {
53   if (ent.IsNull()) return 0;
54   Standard_Integer CN;
55   Handle(Interface_GeneralModule) module;
56   if (!thegtool->Select (ent,module,CN)) return 0;
57   return module->CategoryNumber (CN,ent,shares);
58 }
59
60     void  Interface_Category::ClearNums ()
61       {  thenum.Nullify();  }
62
63     void  Interface_Category::Compute
64   (const Handle(Interface_InterfaceModel)& model,
65    const Interface_ShareTool& shares)
66 {
67   ClearNums();
68   if (model.IsNull()) return;
69   Standard_Integer CN, i, nb = model->NbEntities();
70   thegtool->Reservate (nb);
71   if (nb == 0) return;
72   thenum = new TColStd_HArray1OfInteger (1,nb);  thenum->Init(0);
73   for (i = 1; i <= nb; i ++) {
74     Handle(Standard_Transient) ent = model->Value(i);
75     if (ent.IsNull()) continue;
76     Handle(Interface_GeneralModule) module;
77     if (!thegtool->Select (ent,module,CN)) continue;
78     thenum->SetValue (i,module->CategoryNumber (CN,ent,shares));
79   }
80 }
81
82 Standard_Integer  Interface_Category::Num (const Standard_Integer nument) const
83 {
84   if (thenum.IsNull()) return 0;
85   if (nument < 1 || nument > thenum->Length()) return 0;
86   return thenum->Value(nument);
87 }
88
89
90 //  ##########    LISTE DES CATEGORIES    ##########
91
92     Standard_Integer  Interface_Category::AddCategory (const Standard_CString name)
93 {
94   Standard_Integer num = Interface_Category::Number (name);
95   if (num > 0) return num;
96   thecats().Append (TCollection_AsciiString(name));
97   return thecats().Length()+1;
98 }
99
100     Standard_Integer  Interface_Category::NbCategories ()
101       {  return thecats().Length();  }
102
103     Standard_CString  Interface_Category::Name   (const Standard_Integer num)
104 {
105   if (num < 0) return "";
106   if (num < 1 || num > thecats().Length()) return unspec;
107   return thecats().Value(num).ToCString();
108 }
109
110
111     Standard_Integer  Interface_Category::Number (const Standard_CString name)
112 {
113   Standard_Integer i, nb = thecats().Length();
114   for (i = 1; i <= nb; i ++) {
115     if (thecats().Value(i).IsEqual(name)) return i;
116   }
117   return 0;
118 }
119
120
121     void Interface_Category::Init ()
122 {
123   if (init) return;  init = 1;
124   init = Interface_Category::AddCategory ("Shape");
125   init = Interface_Category::AddCategory ("Drawing");
126   init = Interface_Category::AddCategory ("Structure");
127   init = Interface_Category::AddCategory ("Description");
128   init = Interface_Category::AddCategory ("Auxiliary");
129   init = Interface_Category::AddCategory ("Professional");
130   init = Interface_Category::AddCategory ("FEA");
131   init = Interface_Category::AddCategory ("Kinematics");
132   init = Interface_Category::AddCategory ("Piping");
133 }