0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Transfer / Transfer_TransferIterator.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_Check.hxx>
16 #include <Standard_NoSuchObject.hxx>
17 #include <Standard_Transient.hxx>
18 #include <Transfer_Binder.hxx>
19 #include <Transfer_SimpleBinderOfTransient.hxx>
20 #include <Transfer_TransferIterator.hxx>
21
22 static Handle(Standard_Transient)   nultrans;  // pour retour const&(Null)
23
24
25     Transfer_TransferIterator::Transfer_TransferIterator ()
26 {
27   theitems  = new Transfer_HSequenceOfBinder();
28   theselect = new TColStd_HSequenceOfInteger();
29   themaxi = 0;
30   thecurr = 1;
31 }
32
33     void  Transfer_TransferIterator::AddItem
34   (const Handle(Transfer_Binder)& atr)
35 {
36   theitems->Append(atr);
37   theselect->Append(1);
38   themaxi = theselect->Length();
39 }
40
41     void  Transfer_TransferIterator::SelectBinder
42   (const Handle(Standard_Type)& atype, const Standard_Boolean keep)
43 {
44   for (Standard_Integer i = theitems->Length(); i > 0; i --) {
45     if (theitems->Value(i)->IsKind(atype) != keep) {
46       theselect->SetValue(i,0);
47       if (themaxi == i) themaxi = i-1;
48     }
49   }
50 }
51
52     void  Transfer_TransferIterator::SelectResult
53   (const Handle(Standard_Type)& atype, const Standard_Boolean keep)
54 {
55   Standard_Integer casetype = 0;
56   if (atype->SubType(STANDARD_TYPE(Standard_Transient)))  casetype = 2;
57
58   for (Standard_Integer i = theitems->Length(); i > 0; i --) {
59     Handle(Transfer_Binder) atr = theitems->Value(i);
60     Handle(Standard_Type) btype = ResultType();
61     Standard_Boolean matchtype;
62     if      (!atr->HasResult()) matchtype = Standard_False;
63     else if (atr->IsMultiple()) matchtype = Standard_False;
64     else if (casetype == 0) matchtype = (atype == btype);         // Type fixe
65     else                    matchtype = (btype->SubType(atype));  // Dynamique
66     if (matchtype != keep) {
67       theselect->SetValue(i,0);
68       if (themaxi == i) themaxi = i-1;
69     }
70   }
71 }
72
73     void  Transfer_TransferIterator::SelectUnique
74   (const Standard_Boolean keep)
75 {
76   for (Standard_Integer i = theitems->Length(); i > 0; i --) {
77     Handle(Transfer_Binder) atr = theitems->Value(i);
78     if (atr->IsMultiple() == keep) {
79       theselect->SetValue(i,0);
80       if (themaxi == i) themaxi = i-1;
81     }
82   }
83 }
84
85     void  Transfer_TransferIterator::SelectItem
86   (const Standard_Integer num, const Standard_Boolean keep)
87 {
88   if (num < 1 || num > theselect->Length()) return;
89   if (keep) theselect->SetValue (num,1);
90   else theselect->SetValue (num,0);
91 }
92
93 //  ....                Iteration-Interrogations                ....
94
95     Standard_Integer  Transfer_TransferIterator::Number () const
96 {
97   Standard_Integer numb,i;  numb = 0;
98   for (i = 1; i <= themaxi; i ++) {
99     if (theselect->Value(i) != 0) numb ++;
100   }
101   return numb;
102 }
103
104     void  Transfer_TransferIterator::Start ()
105       {  thecurr = 0;  Next();  }
106
107     Standard_Boolean  Transfer_TransferIterator::More ()
108 {
109   if (thecurr > themaxi) return Standard_False;
110   if (theselect->Value(thecurr) == 0) Next();
111   if (thecurr > themaxi) return Standard_False;
112   return (theselect->Value(thecurr) > 0);
113 }
114
115     void  Transfer_TransferIterator::Next ()
116 {
117   thecurr ++;
118   if (thecurr > themaxi) return;
119   if (theselect->Value(thecurr) == 0) Next();
120 }
121
122     const Handle(Transfer_Binder)&  Transfer_TransferIterator::Value () const
123 {
124   if (thecurr == 0 || thecurr > themaxi) throw Standard_NoSuchObject("TransferIterator : Value");
125   if (theselect->Value(thecurr) == 0)    throw Standard_NoSuchObject("TransferIterator : Value");
126   return theitems->Value(thecurr);
127 }
128
129 //  ....                Acces aux Donnees du Binder Courant                ....
130
131     Standard_Boolean  Transfer_TransferIterator::HasResult () const
132 {
133   Handle(Transfer_Binder) atr = Value();
134   return atr->HasResult();
135 }
136
137     Standard_Boolean  Transfer_TransferIterator::HasUniqueResult () const
138 {
139   Handle(Transfer_Binder) atr = Value();
140   if (atr->IsMultiple()) return Standard_False;
141   return atr->HasResult();
142 }
143
144
145     Handle(Standard_Type) Transfer_TransferIterator::ResultType () const
146 {
147   Handle(Standard_Type) btype;
148   Handle(Transfer_Binder) atr = Value();
149   if (!atr->IsMultiple()) btype = atr->ResultType();
150 //  ResultType de Binder prend en compte le Type Dynamique pour les Handle
151   return btype;
152 }
153
154
155     Standard_Boolean  Transfer_TransferIterator::HasTransientResult () const
156 {
157   Handle(Standard_Type) btype = ResultType();
158   if (btype.IsNull()) return Standard_False;
159   return btype->SubType(STANDARD_TYPE(Standard_Transient));
160 }
161
162     const Handle(Standard_Transient)&
163       Transfer_TransferIterator::TransientResult () const
164 {
165   Handle(Transfer_SimpleBinderOfTransient) atr = 
166     Handle(Transfer_SimpleBinderOfTransient)::DownCast(Value());
167   if (!atr.IsNull()) return atr->Result();
168   return nultrans;
169 }
170
171
172     Transfer_StatusExec  Transfer_TransferIterator::Status () const
173 {
174   Handle(Transfer_Binder) atr = Value();
175   return atr->StatusExec();
176 }
177
178
179     Standard_Boolean  Transfer_TransferIterator::HasFails () const
180 {
181   Handle(Transfer_Binder) atr = Value();
182   return atr->Check()->HasFailed();
183 }
184
185     Standard_Boolean  Transfer_TransferIterator::HasWarnings () const
186 {
187   Handle(Transfer_Binder) atr = Value();
188   return atr->Check()->HasWarnings();
189 }
190
191     const Handle(Interface_Check)  Transfer_TransferIterator::Check () const
192 {
193   Handle(Transfer_Binder) atr = Value();
194   return atr->Check();
195 }