0023072: Eliminate compiler warnings (level 3) on Windows / MSVC++
[occt.git] / src / IFSelect / IFSelect_SignCounter.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 <IFSelect_SignCounter.ixx>
19 #include <Interface_EntityIterator.hxx>
20
21
22 IFSelect_SignCounter::IFSelect_SignCounter
23   (const Standard_Boolean withmap, const Standard_Boolean withlist)
24     : IFSelect_SignatureList (withlist)
25 {
26   themapstat = withmap;  thenbcomp1 = thenbcomp2 = theselmode = 0;
27 }
28
29     IFSelect_SignCounter::IFSelect_SignCounter
30   (const Handle(IFSelect_Signature)& matcher,
31    const Standard_Boolean withmap, const Standard_Boolean withlist)
32     : IFSelect_SignatureList (withlist) , thematcher (matcher)
33 {
34   themapstat = withmap;  thenbcomp1 = thenbcomp2 = theselmode = 0;
35   TCollection_AsciiString sign = thematcher->Name();
36   SetName (sign.ToCString());
37 }
38
39     Handle(IFSelect_Signature)  IFSelect_SignCounter::Signature () const
40       {  return thematcher;  }
41
42     void  IFSelect_SignCounter::SetMap  (const Standard_Boolean withmap)
43       {  themapstat = withmap;  }
44
45     Standard_Boolean  IFSelect_SignCounter::AddEntity
46   (const Handle(Standard_Transient)& ent,
47    const Handle(Interface_InterfaceModel)& model)
48 {
49   if (themapstat && !ent.IsNull()) {
50     if (themap.Contains(ent)) return Standard_False;
51     themap.Add(ent);
52   }
53   AddSign (ent,model);
54   return Standard_True;
55 }
56
57     void  IFSelect_SignCounter::AddSign
58   (const Handle(Standard_Transient)& ent,
59    const Handle(Interface_InterfaceModel)& model)
60 {
61   char nulsign[2];
62   nulsign[0] = '\0';
63   if (ent.IsNull() || thematcher.IsNull())
64     Add (ent, nulsign);  // pour compter les Nuls
65   else              Add (ent, thematcher->Value(ent,model) );
66 }
67
68
69     void  IFSelect_SignCounter::AddList
70   (const Handle(TColStd_HSequenceOfTransient)& list,
71    const Handle(Interface_InterfaceModel)& model)
72 {
73   if (list.IsNull()) return;
74   Standard_Integer nb = list->Length();
75   for (Standard_Integer i = 1; i <= nb; i ++) AddEntity(list->Value(i),model);
76 }
77
78     void  IFSelect_SignCounter::AddWithGraph
79   (const Handle(TColStd_HSequenceOfTransient)& list,
80    const Interface_Graph& graph)
81       {  AddList (list,graph.Model());  }
82
83
84     void  IFSelect_SignCounter::AddModel
85   (const Handle(Interface_InterfaceModel)& model)
86 {
87   if (model.IsNull()) return;
88   Standard_Integer nb = model->NbEntities();
89 //  Si on part de vide, on sait que chque entite est unique dans le modele
90   Standard_Boolean mapstat = themapstat;
91   if (themap.Extent() == 0) themapstat = Standard_False;
92   for (Standard_Integer i = 1; i <= nb; i ++) AddEntity(model->Value(i),model);
93   themapstat = mapstat;
94 }
95
96     void  IFSelect_SignCounter::AddFromSelection
97   (const Handle(IFSelect_Selection)& sel, const Interface_Graph& G)
98 {
99   Interface_EntityIterator iter = sel->RootResult(G);
100   AddWithGraph (iter.Content(),G);
101 }
102
103 //  #############    SELECTION    ##############
104
105     void  IFSelect_SignCounter::SetSelection
106   (const Handle(IFSelect_Selection)& sel)
107 {  theselect = sel;  SetSelMode(-1);  SetSelMode (sel.IsNull() ? 0 : 2);  }
108
109     Handle(IFSelect_Selection)  IFSelect_SignCounter::Selection () const
110       {  return theselect;  }
111
112     void  IFSelect_SignCounter::SetSelMode (const Standard_Integer selmode)
113 {
114   if (selmode < 0) thenbcomp1 = thenbcomp2 = 0;
115   else theselmode = selmode;
116   if (selmode == 0) theselect.Nullify();
117 }
118
119     Standard_Integer  IFSelect_SignCounter::SelMode () const
120       {  return theselmode;  }
121
122     Standard_Boolean  IFSelect_SignCounter::ComputeSelected
123   (const Interface_Graph& G, const Standard_Boolean forced)
124 {
125   if (theselmode < 2 || theselect.IsNull()) return Standard_False;
126   Standard_Boolean afaire = forced;
127   Interface_EntityIterator iter = theselect->RootResult(G);
128   Standard_Integer nb1 = G.Size();
129   Standard_Integer nb2 = iter.NbEntities();
130   if (!afaire) afaire = (nb1 != thenbcomp1 || nb2 != thenbcomp2);
131   thenbcomp1 = nb1;  thenbcomp2 = nb2;
132   if (afaire) AddWithGraph (iter.Content(),G);
133   return Standard_True;
134 }
135
136
137     Handle(TCollection_HAsciiString)  IFSelect_SignCounter::Sign
138   (const Handle(Standard_Transient)& ent,
139    const Handle(Interface_InterfaceModel)& model) const
140 {
141   Handle(TCollection_HAsciiString) res;
142   if (ent.IsNull() || thematcher.IsNull()) return res;
143   res = new TCollection_HAsciiString (thematcher->Value(ent,model));
144   return res;
145 }
146
147     Standard_CString  IFSelect_SignCounter::ComputedSign
148   (const Handle(Standard_Transient)& ent,
149    const Interface_Graph& G)
150 {
151   Handle(TColStd_HSequenceOfTransient) list = new TColStd_HSequenceOfTransient();
152   list->Append (ent);
153   ModeSignOnly() = Standard_True;
154   AddWithGraph (list,G);
155   Standard_CString val = LastValue();
156   ModeSignOnly() = Standard_False;
157   return val;
158 }