0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / Law / Law_Composite.cxx
CommitLineData
b311480e 1// Created on: 1996-03-29
2// Created by: Laurent BOURESCHE
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17// pmn -> 17/01/1996 added : Continuity, (Nb)Intervals, D2, Trim
18
7fd59977 19#include <ElCLib.hxx>
42cf5bc1 20#include <Law_Composite.hxx>
21#include <Law_Function.hxx>
7fd59977 22#include <Law_Laws.hxx>
42cf5bc1 23#include <Law_ListIteratorOfLaws.hxx>
7fd59977 24#include <Standard_NotImplemented.hxx>
42cf5bc1 25#include <Standard_OutOfRange.hxx>
26#include <Standard_Type.hxx>
27#include <TColStd_HArray1OfReal.hxx>
7fd59977 28
92efcf78 29IMPLEMENT_STANDARD_RTTIEXT(Law_Composite,Law_Function)
30
7fd59977 31//=======================================================================
32//function : Law_Composite
33//purpose :
34//=======================================================================
7fd59977 35Law_Composite::Law_Composite()
36 : first(-1.e100),last(1.e100),
37 periodic(Standard_False),
38 TFirst(-1.e100), TLast(1.e100), PTol(0.)
39
40{
41}
42//=======================================================================
43//function : Law_Composite
44//purpose :
45//=======================================================================
46
47Law_Composite::Law_Composite(const Standard_Real First,
48 const Standard_Real Last,
49 const Standard_Real Tol) :
50 first(-1.e100),last(1.e100),
51 periodic(Standard_False),
52 TFirst(First), TLast(Last),PTol(Tol)
53
54{
55}
56
57//=======================================================================
58//function : Continuity
59//purpose :
60//=======================================================================
61GeomAbs_Shape Law_Composite::Continuity() const
62{
9775fa61 63 throw Standard_NotImplemented("Law_Composite::Continuity()");
7fd59977 64}
65
66//=======================================================================
67//function : NbIntervals
68//purpose : On ne se casse pas la tete, on decoupe pour chaque composant
69//=======================================================================
70Standard_Integer Law_Composite::NbIntervals(const GeomAbs_Shape S) const
71{
72 Law_ListIteratorOfLaws It(funclist);
73 Handle(Law_Function) func;
74 Standard_Integer nbr_interval =0;
75
76 for(; It.More(); It.Next()){
77 func = It.Value();
78 nbr_interval += func->NbIntervals(S);
79 }
80 return nbr_interval;
81}
82
83//=======================================================================
84//function : Intervals
85//purpose : Meme simplifications....
86//=======================================================================
87void Law_Composite::Intervals(TColStd_Array1OfReal& T, const GeomAbs_Shape S) const
88{
89 Law_ListIteratorOfLaws It(funclist);
90 Handle(Law_Function) func;
91 Handle(TColStd_HArray1OfReal) LocT;
92 Standard_Integer nb_index, Iloc, IGlob=2;
93
94 func = funclist.First();
95 func->Bounds(T(1),T(2));
96
97 for(; It.More(); It.Next()){
98 func = It.Value();
99 nb_index = func->NbIntervals(S)+1;
100 LocT = new (TColStd_HArray1OfReal)(1, nb_index);
101 func->Intervals(LocT->ChangeArray1(), S);
102 for (Iloc=2; Iloc<=nb_index; Iloc++, IGlob++) {
103 T(IGlob) = LocT->Value(Iloc);
104 }
105 }
106}
107
108//=======================================================================
109//function : Value
110//purpose :
111//=======================================================================
112
113Standard_Real Law_Composite::Value(const Standard_Real X)
114{
115 Standard_Real W = X;
116 Prepare(W);
117 return curfunc->Value(W);
118}
119
120
121//=======================================================================
122//function : D1
123//purpose :
124//=======================================================================
125
126void Law_Composite::D1(const Standard_Real X, Standard_Real& F, Standard_Real& D)
127{
128 Standard_Real W = X;
129 Prepare(W);
130 curfunc->D1(W,F,D);
131}
132
133//=======================================================================
134//function : D2
135//purpose :
136//=======================================================================
137
138void Law_Composite::D2(const Standard_Real X,
139 Standard_Real& F,
140 Standard_Real& D,
141 Standard_Real& D2)
142{
143 Standard_Real W = X;
144 Prepare(W);
145 curfunc->D2(W,F,D,D2);
146}
147
148//=======================================================================
149//function : Trim
150//purpose : ne garde que la partie utile dans le champs.
151//=======================================================================
152
153Handle(Law_Function) Law_Composite::Trim(const Standard_Real PFirst,
154 const Standard_Real PLast,
155 const Standard_Real Tol) const
156{
157 Handle(Law_Composite) l = new (Law_Composite)(PFirst, PLast, Tol );
158 l->ChangeLaws() = funclist;
159 return l;
160}
161
162//=======================================================================
163//function : Bounds
164//purpose :
165//=======================================================================
166
167void Law_Composite::Bounds(Standard_Real& PFirst, Standard_Real& PLast)
168{
169 PFirst = first;
170 PLast = last;
171}
172
173//=======================================================================
174//function : Prepare
175//purpose :
176// Lorsque le parametre est pres d'un "noeud" on determine la loi en
177// fonction du signe de tol:
178// - negatif -> Loi precedente au noeud.
179// - positif -> Loi consecutive au noeud.
180//=======================================================================
181
182void Law_Composite::Prepare(Standard_Real& W)
183{
184 Standard_Real f,l, Wtest, Eps;
185 if (W-TFirst < TLast-W) { Eps = PTol; }
186 else { Eps = -PTol;}
187
188 if(curfunc.IsNull()){
189 curfunc = funclist.Last();
190 curfunc->Bounds(f,last);
191 curfunc = funclist.First();
192 curfunc->Bounds(first,l);
193 }
194
195 Wtest = W+Eps; //Decalage pour discriminer les noeuds
196 if(periodic){
197 Wtest = ElCLib::InPeriod(Wtest,first,last);
198 W = Wtest-Eps;
199 }
200
201 curfunc->Bounds(f,l);
202 if(f <= Wtest && Wtest <= l) return;
203 if(W <= first) {
204 curfunc = funclist.First();
205 }
206 else if(W >= last) {
207 curfunc = funclist.Last();
208 }
209 else{
210 Law_ListIteratorOfLaws It(funclist);
211 for(; It.More(); It.Next()){
212 curfunc = It.Value();
213 curfunc->Bounds(f,l);
214 if (f <= Wtest && Wtest <= l) return;
215 }
216 }
217}
218
219
220//=======================================================================
221//function : ChangeElementaryLaw
222//purpose :
223//=======================================================================
224
225Handle(Law_Function)& Law_Composite::ChangeElementaryLaw(const Standard_Real W)
226{
227 Standard_Real WW = W;
228 Prepare(WW);
229 return curfunc;
230}
231
232//=======================================================================
233//function : ChangeLaws
234//purpose :
235//=======================================================================
236
237Law_Laws& Law_Composite::ChangeLaws()
238{
239 return funclist;
240}
241
242//=======================================================================
243//function : IsPeriodic
244//purpose :
245//=======================================================================
246
247Standard_Boolean Law_Composite::IsPeriodic() const
248{
249 return periodic;
250}
251
252//=======================================================================
253//function : SetPeriodic
254//purpose :
255//=======================================================================
256
257void Law_Composite::SetPeriodic()
258{
259 periodic = Standard_True;
260}