summaryrefslogtreecommitdiff
path: root/src/Interface/Interface_Category.cxx
blob: 1b93246c60b40806be762791381099ac2fcebc35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <Interface_Category.ixx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_SequenceOfAsciiString.hxx>
#include <Interface_GeneralModule.hxx>

static int init = 0;
static Standard_CString unspec = "unspecified";

static TColStd_SequenceOfAsciiString& thecats()
{
  static TColStd_SequenceOfAsciiString thecat;
  return thecat;
}




    Interface_Category::Interface_Category ()
    : thegtool (new Interface_GTool)    {  Init();  }

    Interface_Category::Interface_Category
  (const Handle(Interface_Protocol)& protocol)
    : thegtool (new Interface_GTool(protocol))    {  Init();  }

    Interface_Category::Interface_Category
  (const Handle(Interface_GTool)& gtool)
    : thegtool (gtool)    {  Init();  }

    void  Interface_Category::SetProtocol
  (const Handle(Interface_Protocol)& protocol)
      {  thegtool->SetProtocol(protocol);  }

    Standard_Integer Interface_Category::CatNum
  (const Handle(Standard_Transient)& ent, const Interface_ShareTool& shares)
{
  if (ent.IsNull()) return 0;
  Standard_Integer CN;
  Handle(Interface_GeneralModule) module;
  if (!thegtool->Select (ent,module,CN)) return 0;
  return module->CategoryNumber (CN,ent,shares);
}

    void  Interface_Category::ClearNums ()
      {  thenum.Nullify();  }

    void  Interface_Category::Compute
  (const Handle(Interface_InterfaceModel)& model,
   const Interface_ShareTool& shares)
{
  ClearNums();
  if (model.IsNull()) return;
  Standard_Integer CN, i, nb = model->NbEntities();
  thegtool->Reservate (nb);
  if (nb == 0) return;
  thenum = new TColStd_HArray1OfInteger (1,nb);  thenum->Init(0);
  for (i = 1; i <= nb; i ++) {
    Handle(Standard_Transient) ent = model->Value(i);
    if (ent.IsNull()) continue;
    Handle(Interface_GeneralModule) module;
    if (!thegtool->Select (ent,module,CN)) continue;
    thenum->SetValue (i,module->CategoryNumber (CN,ent,shares));
  }
}

Standard_Integer  Interface_Category::Num (const Standard_Integer nument) const
{
  if (thenum.IsNull()) return 0;
  if (nument < 1 || nument > thenum->Length()) return 0;
  return thenum->Value(nument);
}


//  ##########    LISTE DES CATEGORIES    ##########

    Standard_Integer  Interface_Category::AddCategory (const Standard_CString name)
{
  Standard_Integer num = Interface_Category::Number (name);
  if (num > 0) return num;
  thecats().Append (TCollection_AsciiString(name));
  return thecats().Length()+1;
}

    Standard_Integer  Interface_Category::NbCategories ()
      {  return thecats().Length();  }

    Standard_CString  Interface_Category::Name   (const Standard_Integer num)
{
  if (num < 0) return "";
  if (num < 1 || num > thecats().Length()) return unspec;
  return thecats().Value(num).ToCString();
}


    Standard_Integer  Interface_Category::Number (const Standard_CString name)
{
  Standard_Integer i, nb = thecats().Length();
  for (i = 1; i <= nb; i ++) {
    if (thecats().Value(i).IsEqual(name)) return i;
  }
  return 0;
}


    void Interface_Category::Init ()
{
  if (init) return;  init = 1;
  init = Interface_Category::AddCategory ("Shape");
  init = Interface_Category::AddCategory ("Drawing");
  init = Interface_Category::AddCategory ("Structure");
  init = Interface_Category::AddCategory ("Description");
  init = Interface_Category::AddCategory ("Auxiliary");
  init = Interface_Category::AddCategory ("Professional");
  init = Interface_Category::AddCategory ("FEA");
  init = Interface_Category::AddCategory ("Kinematics");
  init = Interface_Category::AddCategory ("Piping");
}