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 <Geom2d_CartesianPoint.hxx>
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>
24 IMPLEMENT_STANDARD_RTTIEXT(Transfer_Binder,Standard_Transient)
26 //=======================================================================
27 //function : Transfer_Binder
29 //=======================================================================
30 Transfer_Binder::Transfer_Binder ()
32 thestatus = Transfer_StatusVoid;
33 theexecst = Transfer_StatusInitial;
34 thecheck = new Interface_Check;
37 //=======================================================================
40 //=======================================================================
42 void Transfer_Binder::Merge (const Handle(Transfer_Binder)& other)
44 if (other.IsNull()) return;
45 if ((int) theexecst < (int) other->StatusExec()) theexecst = other->StatusExec();
46 thecheck->GetMessages (other->Check());
49 //=======================================================================
50 //function : IsMultiple
52 //=======================================================================
54 Standard_Boolean Transfer_Binder::IsMultiple () const
56 if (thenextr.IsNull()) return Standard_False;
57 if (!HasResult()) return thenextr->IsMultiple();
59 Handle(Transfer_Binder) next = thenextr;
60 while (!next.IsNull()) {
61 if (next->HasResult()) return Standard_True;
62 next = next->NextResult();
64 return Standard_False;
67 //=======================================================================
68 //function : AddResult
70 //=======================================================================
72 void Transfer_Binder::AddResult (const Handle(Transfer_Binder)& next)
74 if (next == this || next.IsNull()) return;
75 next->CutResult(this);
76 if (thenextr.IsNull())
79 //Modification of recursive to cycle
80 Handle(Transfer_Binder) theBinder = theendr.IsNull() ? thenextr : theendr;
81 while( theBinder != next ) {
82 if( theBinder->NextResult().IsNull() ) {
83 theBinder->AddResult(next);
88 theBinder = theBinder->NextResult();
93 //=======================================================================
94 //function : CutResult
96 //=======================================================================
98 void Transfer_Binder::CutResult (const Handle(Transfer_Binder)& next)
100 if (thenextr.IsNull()) return;
101 if (thenextr == next)
106 //else thenextr->CutResult (next);
108 Handle(Transfer_Binder) currBinder = thenextr, currNext;
109 while( !( (currNext = currBinder->NextResult()) == next ) ) {
110 if( currNext.IsNull() )
112 currBinder = currNext;
114 currBinder->CutResult(next);
118 //=======================================================================
119 //function : NextResult
121 //=======================================================================
123 Handle(Transfer_Binder) Transfer_Binder::NextResult () const
127 //=======================================================================
128 //function : SetResultPresent
130 //=======================================================================
132 void Transfer_Binder::SetResultPresent ()
134 if (thestatus == Transfer_StatusUsed) throw Transfer_TransferFailure("Binder : SetResult, Result is Already Set and Used");
135 theexecst = Transfer_StatusDone;
136 thestatus = Transfer_StatusDefined;
139 //=======================================================================
140 //function : HasResult
142 //=======================================================================
144 Standard_Boolean Transfer_Binder::HasResult () const
145 { return (thestatus != Transfer_StatusVoid); }
147 //=======================================================================
148 //function : SetAlreadyUsed
150 //=======================================================================
152 void Transfer_Binder::SetAlreadyUsed ()
153 { if (thestatus != Transfer_StatusVoid) thestatus = Transfer_StatusUsed; }
156 //=======================================================================
159 //=======================================================================
161 Transfer_StatusResult Transfer_Binder::Status () const
162 { return thestatus; }
165 // ############ Checks ############
167 //=======================================================================
168 //function : StatusExec
170 //=======================================================================
172 Transfer_StatusExec Transfer_Binder::StatusExec () const
173 { return theexecst; }
175 //=======================================================================
176 //function : SetStatusExec
178 //=======================================================================
180 void Transfer_Binder::SetStatusExec (const Transfer_StatusExec stat)
181 { theexecst = stat; }
183 //=======================================================================
186 //=======================================================================
188 void Transfer_Binder::AddFail
189 (const Standard_CString mess, const Standard_CString orig)
191 theexecst = Transfer_StatusError;
192 thecheck->AddFail(mess,orig);
195 //=======================================================================
196 //function : AddWarning
198 //=======================================================================
200 void Transfer_Binder::AddWarning
201 (const Standard_CString mess, const Standard_CString orig)
203 // theexecst = Transfer_StatusError;
204 thecheck->AddWarning(mess,orig);
207 //=======================================================================
210 //=======================================================================
212 const Handle(Interface_Check) Transfer_Binder::Check () const
217 //=======================================================================
220 //=======================================================================
222 Handle(Interface_Check) Transfer_Binder::CCheck ()
227 //=======================================================================
228 //function : Destructor
230 //=======================================================================
232 Transfer_Binder::~Transfer_Binder()
234 // To prevent stack overflow on long chains it is needed
235 // to avoid recursive destruction of the field thenextr
236 if (!thenextr.IsNull())
238 Handle(Transfer_Binder) aCurr = thenextr;
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)
245 Handle(Transfer_Binder) aPrev = aCurr;
246 aCurr = aCurr->thenextr;
247 aPrev->thenextr.Nullify();