1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Interface_EntityCluster.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <Interface_EntityList.hxx>
18 #include <Interface_InterfaceError.hxx>
19 #include <Standard_NullObject.hxx>
20 #include <Standard_OutOfRange.hxx>
21 #include <Standard_Transient.hxx>
23 // Une EntityList, c est au fond un "Handle" bien entoure :
24 // S il est nul, la liste est vide
25 // Si c est une Entite, la liste comprend cette entite et rien d autre
26 // Si c est un EntityCluster, il definit (avec ses Next eventuels) le contenu
28 Interface_EntityList::Interface_EntityList () { }
30 void Interface_EntityList::Clear ()
33 // .... EDITIONS (ajout-suppression) ....
35 void Interface_EntityList::Append
36 (const Handle(Standard_Transient)& ent)
38 if (ent.IsNull()) throw Standard_NullObject("Interface_EntityList Append");
39 if (theval.IsNull()) { theval = ent; return; }
40 Handle(Interface_EntityCluster) aValEC =
41 Handle(Interface_EntityCluster)::DownCast(theval);
42 if (!aValEC.IsNull()) aValEC->Append(ent); // EntityCluster
43 else { // reste InterfaceEntity ...
44 Handle(Interface_EntityCluster) ec = new Interface_EntityCluster(theval);
50 // Difference avec Append : on optimise, en evitant la recursivite
51 // En effet, quand un EntityCluster est plein, Append transmet au Next
52 // Ici, EntityList garde le controle, le temps de traitement reste le meme
53 // Moyennant quoi, l ordre n est pas garanti
55 void Interface_EntityList::Add
56 (const Handle(Standard_Transient)& ent)
58 if (ent.IsNull()) throw Standard_NullObject("Interface_EntityList Add");
59 if (theval.IsNull()) { theval = ent; return; }
60 Handle(Interface_EntityCluster) aValEC =
61 Handle(Interface_EntityCluster)::DownCast(theval);
62 if (!aValEC.IsNull()) { // EntityCluster
63 if (aValEC->IsLocalFull()) theval = new Interface_EntityCluster(ent, aValEC);
64 else aValEC->Append (ent);
65 } else { // reste InterfaceEntity ...
66 Handle(Interface_EntityCluster) ec = new Interface_EntityCluster(theval);
72 // Remove : Par Identification d Item a supprimer, ou par Rang
73 // Identification : Item supprime ou qu il soit
74 // N.B.: La liste peut devenir vide ... cf retour Remove de Cluster
76 void Interface_EntityList::Remove (const Handle(Standard_Transient)& ent)
78 if (ent.IsNull()) throw Standard_NullObject("Interface_EntityList Remove");
79 if (theval.IsNull()) return;
84 Handle(Interface_EntityCluster) ec =
85 Handle(Interface_EntityCluster)::DownCast(theval);
86 if (ec.IsNull()) return; // Une seule Entite et pas la bonne
87 Standard_Boolean res = ec->Remove(ent);
88 if (res) theval.Nullify();
91 // Remove par rang : tester OutOfRange
93 void Interface_EntityList::Remove (const Standard_Integer num)
95 if (theval.IsNull()) throw Standard_OutOfRange("EntityList : Remove");
96 Handle(Interface_EntityCluster) ec =
97 Handle(Interface_EntityCluster)::DownCast(theval);
99 if (num != 1) throw Standard_OutOfRange("EntityList : Remove");
103 Standard_Boolean res = ec->Remove(num);
104 if (res) theval.Nullify();
107 // .... ACCES Unitaire AUX DONNEES ....
109 Standard_Boolean Interface_EntityList::IsEmpty () const
110 { return (theval.IsNull()); }
112 Standard_Integer Interface_EntityList::NbEntities () const
114 if (theval.IsNull()) return 0;
115 Handle(Interface_EntityCluster) ec =
116 Handle(Interface_EntityCluster)::DownCast(theval);
117 if (ec.IsNull()) return 1; // Une seuke Entite
118 return ec->NbEntities();
122 const Handle(Standard_Transient)& Interface_EntityList::Value
123 (const Standard_Integer num) const
125 if (theval.IsNull()) throw Standard_OutOfRange("Interface EntityList : Value");
126 Handle(Interface_EntityCluster) ec =
127 Handle(Interface_EntityCluster)::DownCast(theval);
128 if (!ec.IsNull()) return ec->Value(num); // EntityCluster
129 else if (num != 1) throw Standard_OutOfRange("Interface EntityList : Value");
133 void Interface_EntityList::SetValue
134 (const Standard_Integer num, const Handle(Standard_Transient)& ent)
136 if (ent.IsNull()) throw Standard_NullObject("Interface_EntityList SetValue");
137 if (theval.IsNull()) throw Standard_OutOfRange("Interface EntityList : SetValue");
138 Handle(Interface_EntityCluster) ec =
139 Handle(Interface_EntityCluster)::DownCast(theval);
140 if (!ec.IsNull()) ec->SetValue(num,ent); // EntityCluster
141 else if (num != 1) throw Standard_OutOfRange("Interface EntityList : SetValue");
146 // .... Interrogations Generales ....
148 void Interface_EntityList::FillIterator
149 (Interface_EntityIterator& iter) const
151 if (theval.IsNull()) return;
152 Handle(Interface_EntityCluster) ec =
153 Handle(Interface_EntityCluster)::DownCast(theval);
154 if (!ec.IsNull()) ec->FillIterator(iter); // EntityCluster;
155 else iter.GetOneItem(theval);
159 Standard_Integer Interface_EntityList::NbTypedEntities
160 (const Handle(Standard_Type)& atype) const
162 Standard_Integer res = 0;
163 if (theval.IsNull()) return 0;
164 Handle(Interface_EntityCluster) ec =
165 Handle(Interface_EntityCluster)::DownCast(theval);
166 if (!ec.IsNull()) { // EntityCluster
167 while (!ec.IsNull()) {
168 for (Standard_Integer i = ec->NbLocal(); i > 0; i --) {
169 if (ec->Value(i)->IsKind(atype)) res ++;
171 if (!ec->HasNext()) break;
174 } else { // Une seule Entite
175 if (theval->IsKind(atype)) res = 1;
180 Handle(Standard_Transient) Interface_EntityList::TypedEntity
181 (const Handle(Standard_Type)& atype, const Standard_Integer num) const
183 Standard_Integer res = 0;
184 Handle(Standard_Transient) entres;
185 if (theval.IsNull()) throw Interface_InterfaceError("Interface EntityList : TypedEntity , none found");
186 Handle(Interface_EntityCluster) ec =
187 Handle(Interface_EntityCluster)::DownCast(theval);
188 if (!ec.IsNull()) { // EntityCluster
189 while (!ec.IsNull()) {
190 for (Standard_Integer i = ec->NbLocal(); i > 0; i --) {
191 if (ec->Value(i)->IsKind(atype)) {
193 if (num == 0 && res > 1) throw Interface_InterfaceError("Interface EntityList : TypedEntity , several found");
194 entres = ec->Value(i);
195 if (res == num) return entres;
198 if (!ec->HasNext()) break;
201 } else if (num > 1) {
202 throw Interface_InterfaceError("Interface EntityList : TypedEntity ,out of range");
203 } else { // InterfaceEntity
204 if (!theval->IsKind(atype)) throw Interface_InterfaceError("Interface EntityList : TypedEntity , none found");