1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
18 #include <IFSelect_SignCounter.ixx>
19 #include <Interface_EntityIterator.hxx>
22 IFSelect_SignCounter::IFSelect_SignCounter
23 (const Standard_Boolean withmap, const Standard_Boolean withlist)
24 : IFSelect_SignatureList (withlist)
26 themapstat = withmap; thenbcomp1 = thenbcomp2 = theselmode = 0;
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)
34 themapstat = withmap; thenbcomp1 = thenbcomp2 = theselmode = 0;
35 TCollection_AsciiString sign = thematcher->Name();
36 SetName (sign.ToCString());
39 Handle(IFSelect_Signature) IFSelect_SignCounter::Signature () const
40 { return thematcher; }
42 void IFSelect_SignCounter::SetMap (const Standard_Boolean withmap)
43 { themapstat = withmap; }
45 Standard_Boolean IFSelect_SignCounter::AddEntity
46 (const Handle(Standard_Transient)& ent,
47 const Handle(Interface_InterfaceModel)& model)
49 if (themapstat && !ent.IsNull()) {
50 if (themap.Contains(ent)) return Standard_False;
57 void IFSelect_SignCounter::AddSign
58 (const Handle(Standard_Transient)& ent,
59 const Handle(Interface_InterfaceModel)& model)
63 if (ent.IsNull() || thematcher.IsNull())
64 Add (ent, nulsign); // pour compter les Nuls
65 else Add (ent, thematcher->Value(ent,model) );
69 void IFSelect_SignCounter::AddList
70 (const Handle(TColStd_HSequenceOfTransient)& list,
71 const Handle(Interface_InterfaceModel)& model)
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);
78 void IFSelect_SignCounter::AddWithGraph
79 (const Handle(TColStd_HSequenceOfTransient)& list,
80 const Interface_Graph& graph)
81 { AddList (list,graph.Model()); }
84 void IFSelect_SignCounter::AddModel
85 (const Handle(Interface_InterfaceModel)& model)
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);
96 void IFSelect_SignCounter::AddFromSelection
97 (const Handle(IFSelect_Selection)& sel, const Interface_Graph& G)
99 Interface_EntityIterator iter = sel->RootResult(G);
100 AddWithGraph (iter.Content(),G);
103 // ############# SELECTION ##############
105 void IFSelect_SignCounter::SetSelection
106 (const Handle(IFSelect_Selection)& sel)
107 { theselect = sel; SetSelMode(-1); SetSelMode (sel.IsNull() ? 0 : 2); }
109 Handle(IFSelect_Selection) IFSelect_SignCounter::Selection () const
110 { return theselect; }
112 void IFSelect_SignCounter::SetSelMode (const Standard_Integer selmode)
114 if (selmode < 0) thenbcomp1 = thenbcomp2 = 0;
115 else theselmode = selmode;
116 if (selmode == 0) theselect.Nullify();
119 Standard_Integer IFSelect_SignCounter::SelMode () const
120 { return theselmode; }
122 Standard_Boolean IFSelect_SignCounter::ComputeSelected
123 (const Interface_Graph& G, const Standard_Boolean forced)
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;
137 Handle(TCollection_HAsciiString) IFSelect_SignCounter::Sign
138 (const Handle(Standard_Transient)& ent,
139 const Handle(Interface_InterfaceModel)& model) const
141 Handle(TCollection_HAsciiString) res;
142 if (ent.IsNull() || thematcher.IsNull()) return res;
143 res = new TCollection_HAsciiString (thematcher->Value(ent,model));
147 Standard_CString IFSelect_SignCounter::ComputedSign
148 (const Handle(Standard_Transient)& ent,
149 const Interface_Graph& G)
151 Handle(TColStd_HSequenceOfTransient) list = new TColStd_HSequenceOfTransient();
153 ModeSignOnly() = Standard_True;
154 AddWithGraph (list,G);
155 Standard_CString val = LastValue();
156 ModeSignOnly() = Standard_False;