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