Commit | Line | Data |
---|---|---|
973c2be1 | 1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 2 | // |
973c2be1 | 3 | // This file is part of Open CASCADE Technology software library. |
b311480e | 4 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 10 | // |
973c2be1 | 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. | |
b311480e | 13 | |
7fd59977 | 14 | |
7fd59977 | 15 | #include <Geom2d_CartesianPoint.hxx> |
42cf5bc1 | 16 | #include <Interface_Check.hxx> |
17 | #include <Interface_IntVal.hxx> | |
18 | #include <Standard_Type.hxx> | |
19 | #include <TCollection_HAsciiString.hxx> | |
20 | #include <Transfer_Binder.hxx> | |
21 | #include <Transfer_TransferFailure.hxx> | |
22 | #include <Transfer_VoidBinder.hxx> | |
7fd59977 | 23 | |
25e59720 | 24 | IMPLEMENT_STANDARD_RTTIEXT(Transfer_Binder,Standard_Transient) |
92efcf78 | 25 | |
7fd59977 | 26 | //======================================================================= |
27 | //function : Transfer_Binder | |
28 | //purpose : | |
29 | //======================================================================= | |
7fd59977 | 30 | Transfer_Binder::Transfer_Binder () |
31 | { | |
32 | thestatus = Transfer_StatusVoid; | |
33 | theexecst = Transfer_StatusInitial; | |
34 | thecheck = new Interface_Check; | |
35 | } | |
36 | ||
37 | //======================================================================= | |
38 | //function : Merge | |
39 | //purpose : | |
40 | //======================================================================= | |
41 | ||
42 | void Transfer_Binder::Merge (const Handle(Transfer_Binder)& other) | |
43 | { | |
44 | if (other.IsNull()) return; | |
45 | if ((int) theexecst < (int) other->StatusExec()) theexecst = other->StatusExec(); | |
46 | thecheck->GetMessages (other->Check()); | |
47 | } | |
48 | ||
49 | //======================================================================= | |
50 | //function : IsMultiple | |
51 | //purpose : | |
52 | //======================================================================= | |
53 | ||
54 | Standard_Boolean Transfer_Binder::IsMultiple () const | |
55 | { | |
56 | if (thenextr.IsNull()) return Standard_False; | |
57 | if (!HasResult()) return thenextr->IsMultiple(); | |
58 | ||
59 | Handle(Transfer_Binder) next = thenextr; | |
60 | while (!next.IsNull()) { | |
61 | if (next->HasResult()) return Standard_True; | |
62 | next = next->NextResult(); | |
63 | } | |
64 | return Standard_False; | |
65 | } | |
66 | ||
67 | //======================================================================= | |
68 | //function : AddResult | |
69 | //purpose : | |
70 | //======================================================================= | |
71 | ||
72 | void Transfer_Binder::AddResult (const Handle(Transfer_Binder)& next) | |
73 | { | |
74 | if (next == this || next.IsNull()) return; | |
75 | next->CutResult(this); | |
76 | if (thenextr.IsNull()) | |
77 | thenextr = next; | |
78 | else { | |
97e23d55 | 79 | //Modification of recursive to cycle |
63cdf48e | 80 | Handle(Transfer_Binder) theBinder = theendr.IsNull() ? thenextr : theendr; |
7fd59977 | 81 | while( theBinder != next ) { |
82 | if( theBinder->NextResult().IsNull() ) { | |
83 | theBinder->AddResult(next); | |
63cdf48e | 84 | theendr = next; |
7fd59977 | 85 | return; |
86 | } | |
87 | else | |
88 | theBinder = theBinder->NextResult(); | |
89 | } | |
90 | } | |
7fd59977 | 91 | } |
92 | ||
93 | //======================================================================= | |
94 | //function : CutResult | |
95 | //purpose : | |
96 | //======================================================================= | |
97 | ||
98 | void Transfer_Binder::CutResult (const Handle(Transfer_Binder)& next) | |
99 | { | |
100 | if (thenextr.IsNull()) return; | |
63cdf48e | 101 | if (thenextr == next) |
102 | { | |
103 | thenextr.Nullify(); | |
104 | theendr.Nullify(); | |
105 | } | |
97e23d55 M |
106 | //else thenextr->CutResult (next); |
107 | else { | |
108 | Handle(Transfer_Binder) currBinder = thenextr, currNext; | |
109 | while( !( (currNext = currBinder->NextResult()) == next ) ) { | |
110 | if( currNext.IsNull() ) | |
111 | return; | |
112 | currBinder = currNext; | |
113 | } | |
114 | currBinder->CutResult(next); | |
115 | } | |
7fd59977 | 116 | } |
117 | ||
118 | //======================================================================= | |
119 | //function : NextResult | |
120 | //purpose : | |
121 | //======================================================================= | |
122 | ||
123 | Handle(Transfer_Binder) Transfer_Binder::NextResult () const | |
124 | { return thenextr; } | |
125 | ||
126 | ||
127 | //======================================================================= | |
128 | //function : SetResultPresent | |
129 | //purpose : | |
130 | //======================================================================= | |
131 | ||
132 | void Transfer_Binder::SetResultPresent () | |
133 | { | |
9775fa61 | 134 | if (thestatus == Transfer_StatusUsed) throw Transfer_TransferFailure("Binder : SetResult, Result is Already Set and Used"); |
7fd59977 | 135 | theexecst = Transfer_StatusDone; |
136 | thestatus = Transfer_StatusDefined; | |
137 | } | |
138 | ||
139 | //======================================================================= | |
140 | //function : HasResult | |
141 | //purpose : | |
142 | //======================================================================= | |
143 | ||
144 | Standard_Boolean Transfer_Binder::HasResult () const | |
145 | { return (thestatus != Transfer_StatusVoid); } | |
146 | ||
147 | //======================================================================= | |
148 | //function : SetAlreadyUsed | |
149 | //purpose : | |
150 | //======================================================================= | |
151 | ||
152 | void Transfer_Binder::SetAlreadyUsed () | |
153 | { if (thestatus != Transfer_StatusVoid) thestatus = Transfer_StatusUsed; } | |
154 | ||
155 | ||
156 | //======================================================================= | |
157 | //function : Status | |
158 | //purpose : | |
159 | //======================================================================= | |
160 | ||
161 | Transfer_StatusResult Transfer_Binder::Status () const | |
162 | { return thestatus; } | |
163 | ||
164 | ||
165 | // ############ Checks ############ | |
166 | ||
167 | //======================================================================= | |
168 | //function : StatusExec | |
169 | //purpose : | |
170 | //======================================================================= | |
171 | ||
172 | Transfer_StatusExec Transfer_Binder::StatusExec () const | |
173 | { return theexecst; } | |
174 | ||
175 | //======================================================================= | |
176 | //function : SetStatusExec | |
177 | //purpose : | |
178 | //======================================================================= | |
179 | ||
180 | void Transfer_Binder::SetStatusExec (const Transfer_StatusExec stat) | |
181 | { theexecst = stat; } | |
182 | ||
183 | //======================================================================= | |
184 | //function : AddFail | |
185 | //purpose : | |
186 | //======================================================================= | |
187 | ||
188 | void Transfer_Binder::AddFail | |
189 | (const Standard_CString mess, const Standard_CString orig) | |
190 | { | |
191 | theexecst = Transfer_StatusError; | |
192 | thecheck->AddFail(mess,orig); | |
193 | } | |
194 | ||
195 | //======================================================================= | |
196 | //function : AddWarning | |
197 | //purpose : | |
198 | //======================================================================= | |
199 | ||
200 | void Transfer_Binder::AddWarning | |
201 | (const Standard_CString mess, const Standard_CString orig) | |
202 | { | |
203 | // theexecst = Transfer_StatusError; | |
204 | thecheck->AddWarning(mess,orig); | |
205 | } | |
206 | ||
207 | //======================================================================= | |
208 | //function : Check | |
209 | //purpose : | |
210 | //======================================================================= | |
211 | ||
212 | const Handle(Interface_Check) Transfer_Binder::Check () const | |
213 | { | |
214 | return thecheck; | |
215 | } | |
216 | ||
217 | //======================================================================= | |
218 | //function : CCheck | |
219 | //purpose : | |
220 | //======================================================================= | |
221 | ||
222 | Handle(Interface_Check) Transfer_Binder::CCheck () | |
223 | { | |
224 | return thecheck; | |
225 | } | |
226 | ||
63cdf48e | 227 | //======================================================================= |
228 | //function : Destructor | |
229 | //purpose : | |
230 | //======================================================================= | |
231 | ||
232 | Transfer_Binder::~Transfer_Binder() | |
233 | { | |
234 | // To prevent stack overflow on long chains it is needed | |
235 | // to avoid recursive destruction of the field thenextr | |
236 | if (!thenextr.IsNull()) | |
237 | { | |
238 | Handle(Transfer_Binder) aCurr = thenextr; | |
239 | theendr.Nullify(); | |
240 | thenextr.Nullify(); | |
241 | // we check GetRefCount in order to not destroy a chain if it belongs also | |
242 | // to another upper level chain (two chains continue at the same binder) | |
243 | while (!aCurr->thenextr.IsNull() && aCurr->thenextr->GetRefCount() == 1) | |
244 | { | |
245 | Handle(Transfer_Binder) aPrev = aCurr; | |
246 | aCurr = aCurr->thenextr; | |
247 | aPrev->thenextr.Nullify(); | |
248 | } | |
249 | } | |
250 | } |