1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2014 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15Blend_CSWalking::Blend_CSWalking(const TheCurve& Curv,
16				 const TheSurface& Surf,
17				 const Handle(TheTopolTool)& Domain):
18       done(Standard_False),surf(Surf),
19       curv(Curv)
20{
21  domain = Domain;
22}
23
24
25
26void Blend_CSWalking::Perform(Blend_CSFunction& Func,
27//			      Blend_CSFuncInv& FuncInv,
28			      const Standard_Real Pdep,
29			      const Standard_Real Pmax,
30			      const Standard_Real MaxStep,
31			      const Standard_Real TolGuide,
32			      const math_Vector& ParDep,
33			      const Standard_Real Tolesp,
34			      const Standard_Real Fleche,
35			      const Standard_Boolean Appro)
36{
37
38  done = Standard_False;
39  iscomplete = Standard_False;
40  comptra = Standard_False;
41  line = new TheLine ();
42  Standard_Integer Nbvar = Func.NbVariables();
43  tolesp = Abs(Tolesp);
44  tolgui = Abs(TolGuide);
45  fleche = Abs(Fleche);
46  rebrou = Standard_False;
47  pasmax = Abs(MaxStep);
48  math_Vector sol(1,Nbvar);
49
50  firstsol = new TColStd_HArray1OfReal(1,Nbvar);
51
52  if (Pmax-Pdep >= 0.) {
53    sens = 1.;
54  }
55  else {
56    sens = -1.;
57  }
58
59  Blend_Status State;
60  TheExtremity ptf1,ptf2;
61
62  param = Pdep;
63  firstparam = Pdep;
64  Func.Set(param);
65
66  if (Appro) {
67
68    TopAbs_State situ;
69//    math_Vector tolerance(1,3),infbound(1,3),supbound(1,3);
70    math_Vector tolerance(1,Nbvar),infbound(1,Nbvar),supbound(1,Nbvar);
71    Func.GetTolerance(tolerance,tolesp);
72    Func.GetBounds(infbound,supbound);
73    math_FunctionSetRoot rsnld(Func,tolerance,30);
74
75    rsnld.Perform(Func,ParDep,infbound,supbound);
76
77    if (!rsnld.IsDone()) {
78      return;
79    }
80    rsnld.Root(sol);
81
82//    situ1 = TheTopolTool::Classify(surf1,gp_Pnt2d(sol(1),sol(2)),
83//				   Max(tolerance(1),tolerance(2)));
84//    situ2 = TheTopolTool::Classify(surf2,gp_Pnt2d(sol(3),sol(4)),
85//				   Max(tolerance(3),tolerance(4)));
86/*
87    situ = domain->Classify(gp_Pnt2d(sol(1),sol(2)),
88			      Min(tolerance(1),tolerance(2)));
89*/
90    situ = domain->Classify(Func.Pnt2d(),
91			    Min(tolerance(1),tolerance(2)));
92
93    if (situ != TopAbs_IN ) {
94      return;
95    }
96  }
97  else {
98    sol = ParDep;
99  }
100
101  for (Standard_Integer i=1; i<= Nbvar; i++) {
102    firstsol->ChangeValue(i) = sol(i);
103  }
104  State = TestArret(Func,sol,Standard_False,Blend_OK);
105  if (State!=Blend_OK) {
106    return;
107  }
108#ifdef OCCT_DEBUG
109  if (Blend_GettraceDRAWSECT()){
110    Drawsect(surf,curv,param,Func);
111  }
112#endif
113  // Mettre a jour la ligne.
114  line->Append(previousP);
115  Standard_Real U,V,W;
116  previousP.ParametersOnS(U,V);
117  W = previousP.ParameterOnC();
118  TheExtremity P1(previousP.PointOnS(),U,V,previousP.Parameter(),tolesp);
119  TheExtremity P2(previousP.PointOnC(),W,previousP.Parameter(),tolesp);
120  if (sens>0.) {
121    line->SetStartPoints(P1,P2);
122  }
123  else {
124    line->SetEndPoints(P1,P2);
125  }
126
127//  InternalPerform(Func,FuncInv,Pmax);
128  InternalPerform(Func,sol,Pmax);
129
130  done = Standard_True;
131}
132
133
134
135Standard_Boolean Blend_CSWalking::Complete(Blend_CSFunction& Func,
136//					   Blend_CSFuncInv& FuncInv,
137					   const Standard_Real Pmin)
138{
139  if (!done) {throw StdFail_NotDone();}
140  if (iscomplete) {return Standard_True;}
141
142/*
143  if (sens >0.) {
144    previousP = line->Point(1);
145  }
146  else {
147    previousP = line->Point(line->NbPoints());
148  }
149*/
150
151  sens = -sens;
152/*
153  param = previousP.Parameter();
154  previousP.ParametersOnS(sol(1),sol(2));
155  sol(3) = previousP.ParameterOnC();
156*/
157  Standard_Integer Nbvar = Func.NbVariables();
158  math_Vector sol(1,Nbvar);
159  for (Standard_Integer i =1; i<= Nbvar; i++) {
160    sol(i) = firstsol->Value(i);
161  }
162
163  param = firstparam;
164
165//  InternalPerform(Func,FuncInv,Pmin);
166  InternalPerform(Func,sol,Pmin);
167
168  sens = -sens;
169  iscomplete = Standard_True;
170  return Standard_True;
171}
172
173