0024428: Implementation of LGPL license
[occt.git] / src / BRepIntCurveSurface / BRepIntCurveSurface_Inter.cxx
CommitLineData
b311480e 1// Created on: 1994-02-07
2// Created by: Modelistation
3// Copyright (c) 1994-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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
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#include <BRepIntCurveSurface_Inter.ixx>
18#include <Geom_Line.hxx>
19#include <TopAbs_ShapeEnum.hxx>
20#include <TopoDS.hxx>
21#include <TopoDS_Face.hxx>
22#include <BRepAdaptor_Surface.hxx>
23#include <BRepAdaptor_HSurface.hxx>
24#include <GeomAdaptor_HCurve.hxx>
25#include <BRepTopAdaptor_TopolTool.hxx>
26#include <BRepAdaptor_HSurface.hxx>
27
28//modified by NIZNHY-PKV Sun Dec 15 16:57:10 2002 f
29/*
30static Standard_Real currentU,currentV;
31TopAbs_State currentstate;
32static Handle(BRepTopAdaptor_TopolTool) FastClass
33 = new BRepTopAdaptor_TopolTool();
34
35static Handle(BRepAdaptor_HSurface) SurfForFastClass
36 = new BRepAdaptor_HSurface();
37*/
38//modified by NIZNHY-PKV Sun Dec 15 16:57:14 2002 t
39
40//===========================================================================
41//function :BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inte
42//purpose :
43//===========================================================================
44BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inter()
45 : empty(Standard_True)
46{
47//modified by NIZNHY-PKV Sun Dec 15 16:58:10 2002 f
48 FastClass = new BRepTopAdaptor_TopolTool();
49 SurfForFastClass = new BRepAdaptor_HSurface();
50//modified by NIZNHY-PKV Sun Dec 15 16:58:13 2002 t
51}
52
53void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& ashape,
54 const GeomAdaptor_Curve& acurve,
55 const Standard_Real tol) {
56 empty = Standard_False;
57 curveisaline = Standard_False;
58 curve = acurve;
59 explorer.Init(ashape,TopAbs_FACE);
60 currentnbpoints = 0;
61 tolerance = tol;
62 Find();
63}
64
65void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& ashape,
66 const gp_Lin& aline,
67 const Standard_Real tol) {
68 empty = Standard_False;
69 curveisaline = Standard_True;
70 line = aline;
71 Handle(Geom_Line) geomline = new Geom_Line(aline);
72 curve.Load(geomline);
73 explorer.Init(ashape,TopAbs_FACE);
74 currentnbpoints = 0;
75 tolerance = tol;
76 Find();
77}
78
79Standard_Boolean BRepIntCurveSurface_Inter::More() const {
80 return(explorer.More());
81}
82
83void BRepIntCurveSurface_Inter::Next() {
84 Find();
85}
86
87void BRepIntCurveSurface_Inter::Find() {
88
89 static Standard_Real UMin = 0.0;
90 static Standard_Real UMax = 0.0;
91 static Standard_Real VMin = 0.0;
92 static Standard_Real VMax = 0.0;
93 static Standard_Real PeriodU = 0.0;
94 static Standard_Real PeriodV = 0.0;
95
96 if(currentnbpoints) {
97 while(currentindex < currentnbpoints) {
98 currentindex++;
99 Standard_Real U = intcs.Point(currentindex).U();
100 Standard_Real V = intcs.Point(currentindex).V();
101 //-------------------------------------------------------
0d969553 102 //-- Try to reframe point U,V in the face UV
7fd59977 103 //--
104 if(PeriodU) {
105 while(U>UMin)
106 U-=PeriodU;
107 }
108 if(PeriodV) {
109 while(V>VMin)
110 V-=PeriodV;
111 }
112// Standard_Real UInit = U;
113 Standard_Real VInit = V;
0d969553 114 do { //-- Loop on U
7fd59977 115 V = VInit;
0d969553 116 do { //-- Loop on V
7fd59977 117 gp_Pnt2d Puv(U,V);
118 //---
119 //-- classifier.Perform(TopoDS::Face(explorer.Current()),Puv,tolerance);
120 currentstate = FastClass->Classify(Puv,tolerance); //-- MODIF
121 //-- TopAbs_State currentstate = classifier.State();
122
123 if(currentstate == TopAbs_ON || currentstate == TopAbs_IN) {
124 currentU = U;
125 currentV = V;
126 return;
127 }
128 V+=PeriodV;
129 }
130 while(PeriodV && V< VMax);
131 U+=PeriodU;
132 }
133 while(PeriodU && U<UMax);
134 }
135 explorer.Next();
136 }
137
138 if(explorer.More()) {
139 //---------------------------------------------
140 BRepAdaptor_Surface brepadaptsurf;
141
142 TopoDS_Face face=TopoDS::Face(explorer.Current());
143 face.Orientation(TopAbs_FORWARD);
144
145 brepadaptsurf.Initialize(face,Standard_True);
146 //----------------------------------------------
0d969553 147 //-- Update variables PeriodU,PeriodV
7fd59977 148 //--
149
150 SurfForFastClass->ChangeSurface().Initialize(face); //-- MODIF
151// SurfForFastClass->ChangeSurface().Initialize(TopoDS::Face(face)); //-- MODIF
152 FastClass->Initialize(SurfForFastClass); //-- MODIF
153
154 if( brepadaptsurf.Surface().IsUPeriodic()) {
155 PeriodU = brepadaptsurf.Surface().UPeriod();
156 UMin = brepadaptsurf.Surface().FirstUParameter();
157 UMax = brepadaptsurf.Surface().LastUParameter();
158 }
159 else {
160 PeriodU = 0.0;
161 }
162 if( brepadaptsurf.Surface().IsVPeriodic()) {
163 PeriodV = brepadaptsurf.Surface().VPeriod();
164 VMin = brepadaptsurf.Surface().FirstVParameter();
165 VMax = brepadaptsurf.Surface().LastVParameter();
166 }
167 else {
168 PeriodV = 0.0;
169 }
170
171 //----------------------------------------------
172 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(curve);
173 Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(brepadaptsurf);
174 //----------------------------------------------
175 //-- intcs.Perform(curve,brepadaptsurf);
176 intcs.Perform(HC,HS);
177
178 currentindex = 0;
179 currentnbpoints = intcs.NbPoints();
180 if(currentnbpoints) {
181 Find();
182 }
183 else {
184 explorer.Next();
185 Find();
186 }
187 }
188 else {
189 currentnbpoints=0;
190 }
191}
192
193
194IntCurveSurface_IntersectionPoint BRepIntCurveSurface_Inter::Point() const {
195 if(currentindex==0)
196 StdFail_NotDone::Raise();
197 const IntCurveSurface_IntersectionPoint& ICPS = intcs.Point(currentindex);
198 return(IntCurveSurface_IntersectionPoint(ICPS.Pnt(),
199 currentU, // ICPS.U(),
200 currentV, // ICPS.V(),
201 ICPS.W(),
202 ICPS.Transition()));
203 //-- return(intcs.Point(currentindex));
204}
205
206Standard_Real BRepIntCurveSurface_Inter::U() const {
207 if(currentindex==0)
208 StdFail_NotDone::Raise();
209 //-- return(intcs.Point(currentindex).U());
210 return(currentU);
211}
212
213Standard_Real BRepIntCurveSurface_Inter::V() const {
214 if(currentindex==0)
215 StdFail_NotDone::Raise();
216 //-- return(intcs.Point(currentindex).V());
217 return(currentV);
218}
219
220Standard_Real BRepIntCurveSurface_Inter::W() const {
221 if(currentindex==0)
222 StdFail_NotDone::Raise();
223 return(intcs.Point(currentindex).W());
224}
225
226TopAbs_State BRepIntCurveSurface_Inter::State() const {
227 if(currentindex==0)
228 StdFail_NotDone::Raise();
229 //-- return(classifier.State());
230 return(currentstate);
231}
232
233IntCurveSurface_TransitionOnCurve BRepIntCurveSurface_Inter::Transition() const {
234 if(currentindex==0)
235 StdFail_NotDone::Raise();
236 return(intcs.Point(currentindex).Transition());
237}
238
239const TopoDS_Face& BRepIntCurveSurface_Inter::Face() const {
240 return(TopoDS::Face(explorer.Current()));
241}
242
243const gp_Pnt& BRepIntCurveSurface_Inter::Pnt() const {
244 if(currentindex==0)
245 StdFail_NotDone::Raise();
246 return(intcs.Point(currentindex).Pnt());
247}