0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / Interface / Interface_GTool.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_GeneralLib.hxx>
16 #include <Interface_GeneralModule.hxx>
17 #include <Interface_GTool.hxx>
18 #include <Interface_InterfaceModel.hxx>
19 #include <Interface_Protocol.hxx>
20 #include <Interface_SignType.hxx>
21 #include <Standard_Transient.hxx>
22 #include <Standard_Type.hxx>
23
24 IMPLEMENT_STANDARD_RTTIEXT(Interface_GTool,Standard_Transient)
25
26 Interface_GTool::Interface_GTool  ()    {  }
27
28     Interface_GTool::Interface_GTool
29   (const Handle(Interface_Protocol)& proto, const Standard_Integer nb)
30     : theproto (proto) , thelib (proto)
31       {  if (nb > 0)  {  thentnum.ReSize(nb);  thentmod.ReSize(nb);  }  }
32
33
34     void  Interface_GTool::SetSignType (const Handle(Interface_SignType)& sign)
35       {  thesign = sign;  }
36
37     Handle(Interface_SignType)  Interface_GTool::SignType () const
38       {  return thesign;  }
39
40     Standard_CString  Interface_GTool::SignValue
41   (const Handle(Standard_Transient)& ent,
42    const Handle(Interface_InterfaceModel)& model) const
43 {
44   if (ent.IsNull()) return "";
45   if (thesign.IsNull()) return Interface_SignType::ClassName(ent->DynamicType()->Name());
46   return thesign->Value (ent,model);
47 }
48
49     Standard_CString  Interface_GTool::SignName () const
50 {
51   if (thesign.IsNull()) return "Class Name";
52   return thesign->Name();
53 }
54
55
56     void  Interface_GTool::SetProtocol
57   (const Handle(Interface_Protocol)& proto, const Standard_Boolean enforce)
58 {
59   if (proto == theproto && !enforce) return;
60   theproto = proto;
61   thelib.Clear();
62   thelib.AddProtocol (proto);
63 }
64
65     Handle(Interface_Protocol)  Interface_GTool::Protocol () const
66       {  return theproto;  }
67
68     Interface_GeneralLib&  Interface_GTool::Lib ()
69       {  return thelib;  }
70
71     void  Interface_GTool::Reservate
72   (const Standard_Integer nb, const Standard_Boolean enforce)
73 {
74   Standard_Integer n = thentnum.NbBuckets();
75   if (n < nb && !enforce) return;
76   thentnum.ReSize (nb);  thentmod.ReSize (nb);
77 }
78
79     void  Interface_GTool::ClearEntities ()
80       {  thentnum.Clear();  thentmod.Clear();  }
81
82
83 //=======================================================================
84 //function : Select
85 //purpose  : 
86 //=======================================================================
87
88 Standard_Boolean  Interface_GTool::Select (const Handle(Standard_Transient)& ent,
89                                            Handle(Interface_GeneralModule)& gmod,
90                                            Standard_Integer& CN,
91                                            const Standard_Boolean enforce)
92 {
93   const Handle(Standard_Type)& aType = ent->DynamicType();
94   Standard_Integer num = thentmod.FindIndex(aType);// (ent);
95   if (num == 0 || enforce) {
96     if (thelib.Select (ent,gmod,CN)) {
97       num = thentmod.Add (aType,gmod);
98       thentnum.Bind (aType,CN);
99       return Standard_True;
100     }
101     return Standard_False;
102   }
103   gmod = Handle(Interface_GeneralModule)::DownCast (thentmod.FindFromKey(aType));
104   CN   = thentnum.Find (aType);
105   return Standard_True;
106 }