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