summaryrefslogtreecommitdiff
path: root/src/Interface/Interface_GTool.cxx
blob: d3016ca7c4e059867ffdadede4dd197565a1f6e2 (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
#include <Interface_GTool.ixx>

    Interface_GTool::Interface_GTool  ()    {  }

    Interface_GTool::Interface_GTool
  (const Handle(Interface_Protocol)& proto, const Standard_Integer nb)
    : theproto (proto) , thelib (proto)
      {  if (nb > 0)  {  thentnum.ReSize(nb);  thentmod.ReSize(nb);  }  }


    void  Interface_GTool::SetSignType (const Handle(Interface_SignType)& sign)
      {  thesign = sign;  }

    Handle(Interface_SignType)  Interface_GTool::SignType () const
      {  return thesign;  }

    Standard_CString  Interface_GTool::SignValue
  (const Handle(Standard_Transient)& ent,
   const Handle(Interface_InterfaceModel)& model) const
{
  if (ent.IsNull()) return "";
  if (thesign.IsNull()) return Interface_SignType::ClassName(ent->DynamicType()->Name());
  return thesign->Value (ent,model);
}

    Standard_CString  Interface_GTool::SignName () const
{
  if (thesign.IsNull()) return "Class Name";
  return thesign->Name();
}


    void  Interface_GTool::SetProtocol
  (const Handle(Interface_Protocol)& proto, const Standard_Boolean enforce)
{
  if (proto == theproto && !enforce) return;
  theproto = proto;
  thelib.Clear();
  thelib.AddProtocol (proto);
}

    Handle(Interface_Protocol)  Interface_GTool::Protocol () const
      {  return theproto;  }

    Interface_GeneralLib&  Interface_GTool::Lib ()
      {  return thelib;  }

    void  Interface_GTool::Reservate
  (const Standard_Integer nb, const Standard_Boolean enforce)
{
  Standard_Integer n = thentnum.NbBuckets();
  if (n < nb && !enforce) return;
  thentnum.ReSize (nb);  thentmod.ReSize (nb);
}

    void  Interface_GTool::ClearEntities ()
      {  thentnum.Clear();  thentmod.Clear();  }


//=======================================================================
//function : Select
//purpose  : 
//=======================================================================

Standard_Boolean  Interface_GTool::Select (const Handle(Standard_Transient)& ent,
                                           Handle(Interface_GeneralModule)& gmod,
                                           Standard_Integer& CN,
                                           const Standard_Boolean enforce)
{
//  const Handle(Standard_Type)& aType = ent->DynamicType();
  Standard_Integer num = thentmod.FindIndex (ent);
  if (num == 0 || enforce) {
    if (thelib.Select (ent,gmod,CN)) {
      num = thentmod.Add (ent,gmod);
      thentnum.Bind (ent,CN);
      return Standard_True;
    }
    return Standard_False;
  }
  gmod = Handle(Interface_GeneralModule)::DownCast (thentmod.FindFromIndex(num));
  CN   = thentnum.Find (ent);
  return Standard_True;
}