0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / BRepSweep / BRepSweep_Translation.cxx
CommitLineData
b311480e 1// Created on: 1993-02-04
2// Created by: Laurent BOURESCHE
3// Copyright (c) 1993-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 <BRepSweep_Translation.ixx>
18#include <BRep_Tool.hxx>
19#include <BRepTools.hxx>
20#include <BRepAdaptor_Surface.hxx>
21#include <TopoDS.hxx>
22#include <TopoDS_Vertex.hxx>
23#include <ElSLib.hxx>
24#include <GeomAbs_SurfaceType.hxx>
25#include <GeomAdaptor_Surface.hxx>
26#include <GeomAdaptor_Curve.hxx>
27#include <Geom_SurfaceOfLinearExtrusion.hxx>
28#include <Geom_Plane.hxx>
29#include <Geom_CylindricalSurface.hxx>
30#include <Geom_Line.hxx>
31#include <Geom2d_Line.hxx>
32#include <gp.hxx>
33#include <gp_Trsf.hxx>
34#include <gp_Pnt.hxx>
35#include <gp_Pnt2d.hxx>
36#include <gp_Lin.hxx>
37#include <gp_Lin2d.hxx>
38#include <gp_Dir.hxx>
39#include <gp_Dir2d.hxx>
40#include <Precision.hxx>
41#include <Standard_ConstructionError.hxx>
42
43#include <GeomAdaptor_HCurve.hxx>
44#include <Adaptor3d_SurfaceOfLinearExtrusion.hxx>
45
46#include <BRepAdaptor_Curve.hxx>
47#include <BRep_TEdge.hxx>
48#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
49#include <BRep_CurveRepresentation.hxx>
50#include <TopExp_Explorer.hxx>
51
52static void SetThePCurve(const BRep_Builder& B,
53 TopoDS_Edge& E,
54 const TopoDS_Face& F,
55 const TopAbs_Orientation O,
56 const Handle(Geom2d_Curve)& C)
57{
58 // check if there is already a pcurve on non planar faces
59 Standard_Real f,l;
60 Handle(Geom2d_Curve) OC;
61 TopLoc_Location SL;
62 Handle(Geom_Plane) GP = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(F,SL));
63 if (GP.IsNull())
64 OC = BRep_Tool::CurveOnSurface(E,F,f,l);
65 if (OC.IsNull())
66 B.UpdateEdge(E,C,F,Precision::Confusion());
67 else {
68 if (O == TopAbs_REVERSED)
69 B.UpdateEdge(E,OC,C,F,Precision::Confusion());
70 else
71 B.UpdateEdge(E,C,OC,F,Precision::Confusion());
72 }
73}
74
75//=======================================================================
76//function : BRepSweep_Translation
77//purpose :
78//=======================================================================
79
80BRepSweep_Translation::BRepSweep_Translation(const TopoDS_Shape& S,
81 const Sweep_NumShape& N,
82 const TopLoc_Location& L,
83 const gp_Vec& V,
84 const Standard_Boolean C,
85 const Standard_Boolean Canonize) :
86 BRepSweep_Trsf(BRep_Builder(),S,N,L,C),
87 myVec(V),
88 myCanonize(Canonize)
89{
90
91 Standard_ConstructionError_Raise_if
92 (V.Magnitude()<Precision::Confusion(),
93 "BRepSweep_Translation::Constructor");
94 Init();
95}
96
97void BRepSweep_Translation::Delete()
98{}
99
100
101//=======================================================================
102//function : MakeEmptyVertex
103//purpose :
104//=======================================================================
105
106TopoDS_Shape BRepSweep_Translation::MakeEmptyVertex
107 (const TopoDS_Shape& aGenV,
108 const Sweep_NumShape& aDirV)
109{
110 //Only called when the option of construction is with copy.
111 Standard_ConstructionError_Raise_if
112 (!myCopy,"BRepSweep_Translation::MakeEmptyVertex");
113 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aGenV));
114 if (aDirV.Index()==2) P.Transform(myLocation.Transformation());
115 TopoDS_Vertex V;
116 ////// modified by jgv, 5.10.01, for buc61008 //////
117 //myBuilder.Builder().MakeVertex(V,P,Precision::Confusion());
118 myBuilder.Builder().MakeVertex( V, P, BRep_Tool::Tolerance(TopoDS::Vertex(aGenV)) );
119 ////////////////////////////////////////////////////
120 return V;
121}
122
123
124//=======================================================================
125//function : MakeEmptyDirectingEdge
126//purpose :
127//=======================================================================
128
129TopoDS_Shape BRepSweep_Translation::MakeEmptyDirectingEdge
130 (const TopoDS_Shape& aGenV,
131 const Sweep_NumShape&)
132{
133 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aGenV));
134 gp_Lin L(P,myVec);
135 Handle(Geom_Line) GL = new Geom_Line(L);
136 TopoDS_Edge E;
137 myBuilder.Builder().MakeEdge
138 (E,GL,BRep_Tool::Tolerance(TopoDS::Vertex(aGenV)));
139 return E;
140}
141
142
143//=======================================================================
144//function : MakeEmptyGeneratingEdge
145//purpose :
146//=======================================================================
147
148TopoDS_Shape BRepSweep_Translation::MakeEmptyGeneratingEdge
149 (const TopoDS_Shape& aGenE,
150 const Sweep_NumShape& aDirV)
151{
0d969553 152 //Call only in case of construction with copy.
7fd59977 153 Standard_ConstructionError_Raise_if
154 (!myCopy,"BRepSweep_Translation::MakeEmptyVertex");
155 TopLoc_Location L;
156 Standard_Real First,Last;
157 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(aGenE),L,First,Last);
158 C = Handle(Geom_Curve)::DownCast(C->Copy());
159 C->Transform(L.Transformation());
160 if (aDirV.Index() == 2) C->Transform(myLocation.Transformation());
161 TopoDS_Edge newE;
162 myBuilder.Builder().MakeEdge
163 (newE,C,BRep_Tool::Tolerance(TopoDS::Edge(aGenE)));
164 return newE;
165}
166
167
168//=======================================================================
169//function : SetParameters
170//purpose :
171//=======================================================================
172
173void BRepSweep_Translation::SetParameters
174 (const TopoDS_Shape& aNewFace,
175 TopoDS_Shape& aNewVertex,
176 const TopoDS_Shape& aGenF,
177 const TopoDS_Shape& aGenV,
178 const Sweep_NumShape&)
179{
0d969553 180 //Glue the parameter of vertices directly included in cap faces.
7fd59977 181 gp_Pnt2d pnt2d = BRep_Tool::Parameters(TopoDS::Vertex(aGenV),
182 TopoDS::Face(aGenF));
183 myBuilder.Builder().UpdateVertex
184 (TopoDS::Vertex(aNewVertex),pnt2d.X(),pnt2d.Y(),
185 TopoDS::Face(aNewFace),Precision::PConfusion());
186}
187
188
189//=======================================================================
190//function : SetDirectingParameter
191//purpose :
192//=======================================================================
193
194void BRepSweep_Translation::SetDirectingParameter
195 (const TopoDS_Shape& aNewEdge,
196 TopoDS_Shape& aNewVertex,
197 const TopoDS_Shape&,
198 const Sweep_NumShape&,
199 const Sweep_NumShape& aDirV)
200{
201 Standard_Real param = 0;
202 if (aDirV.Index() == 2) param = myVec.Magnitude();
203 myBuilder.Builder().UpdateVertex(TopoDS::Vertex(aNewVertex),
204 param,TopoDS::Edge(aNewEdge),
205 Precision::PConfusion());
206}
207
208
209//=======================================================================
210//function : SetGeneratingParameter
211//purpose :
212//=======================================================================
213
214void BRepSweep_Translation::SetGeneratingParameter
215 (const TopoDS_Shape& aNewEdge,
216 TopoDS_Shape& aNewVertex,
217 const TopoDS_Shape& aGenE,
218 const TopoDS_Shape& aGenV,
219 const Sweep_NumShape&)
220{
221 TopoDS_Vertex vbid = TopoDS::Vertex(aNewVertex);
222 vbid.Orientation(aGenV.Orientation());
223 myBuilder.Builder().UpdateVertex
224 (vbid,
225 BRep_Tool::Parameter(TopoDS::Vertex(aGenV),TopoDS::Edge(aGenE)),
226 TopoDS::Edge(aNewEdge),Precision::PConfusion());
227}
228
229
230//=======================================================================
231//function : MakeEmptyFace
232//purpose :
233//=======================================================================
234
235TopoDS_Shape BRepSweep_Translation::MakeEmptyFace
236 (const TopoDS_Shape& aGenS,
237 const Sweep_NumShape& aDirS)
238{
239 Standard_Real toler;
240 TopoDS_Face F;
241 Handle(Geom_Surface) S;
242 if (myDirShapeTool.Type(aDirS)==TopAbs_EDGE){
243 TopLoc_Location L;
244 Standard_Real First,Last;
245 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(aGenS),L,First,Last);
246 toler = BRep_Tool::Tolerance(TopoDS::Edge(aGenS));
247 gp_Trsf Tr = L.Transformation();
248 C = Handle(Geom_Curve)::DownCast(C->Copy());
0d969553 249 //extruded surfaces are inverted correspondingly to the topology, so reverse.
7fd59977 250 C->Transform(Tr);
251 gp_Dir D(myVec);
252 D.Reverse();
253
254 if (myCanonize) {
255 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(C,First,Last);
256 Adaptor3d_SurfaceOfLinearExtrusion AS(HC,D);
257 switch(AS.GetType()){
258
259 case GeomAbs_Plane :
260 S = new Geom_Plane(AS.Plane());
261 break;
262 case GeomAbs_Cylinder :
263 S = new Geom_CylindricalSurface(AS.Cylinder());
264 break;
265 default:
266 S = new Geom_SurfaceOfLinearExtrusion(C,D);
267 break;
268 }
269 }
270 else {
271 S = new Geom_SurfaceOfLinearExtrusion(C,D);
272 }
273 }
274 else {
275 TopLoc_Location L;
276 S = BRep_Tool::Surface(TopoDS::Face(aGenS),L);
277 toler = BRep_Tool::Tolerance(TopoDS::Face(aGenS));
278 gp_Trsf Tr = L.Transformation();
279 S = Handle(Geom_Surface)::DownCast(S->Copy());
280 S->Transform(Tr);
281 if (aDirS.Index()==2) S->Translate(myVec);
282 }
283 myBuilder.Builder().MakeFace(F,S,toler);
284 return F;
285}
286
287
288//=======================================================================
289//function : SetPCurve
290//purpose :
291//=======================================================================
292
293void BRepSweep_Translation::SetPCurve
294 (const TopoDS_Shape& aNewFace,
295 TopoDS_Shape& aNewEdge,
296 const TopoDS_Shape& aGenF,
297 const TopoDS_Shape& aGenE,
298 const Sweep_NumShape&,
299 const TopAbs_Orientation)
300{
0d969553
Y
301 //Set on edges of cap faces the same pcurves as
302 //edges of the generating face.
7fd59977 303 Standard_Real First,Last;
304 myBuilder.Builder().UpdateEdge
305 (TopoDS::Edge(aNewEdge),
306 BRep_Tool::CurveOnSurface
307 (TopoDS::Edge(aGenE),TopoDS::Face(aGenF),First,Last),
308 TopoDS::Face(aNewFace),Precision::PConfusion());
309}
310
311
312//=======================================================================
313//function : SetGeneratingPCurve
314//purpose :
315//=======================================================================
316
317void BRepSweep_Translation::SetGeneratingPCurve
318 (const TopoDS_Shape& aNewFace,
319 TopoDS_Shape& aNewEdge,
320 const TopoDS_Shape& ,
321 const Sweep_NumShape&,
322 const Sweep_NumShape& aDirV,
323 const TopAbs_Orientation orien)
324{
325 TopLoc_Location Loc;
326 GeomAdaptor_Surface AS(BRep_Tool::Surface(TopoDS::Face(aNewFace),Loc));
327// Standard_Real First,Last;
328 gp_Lin2d L;
329 TopoDS_Edge aNewOrientedEdge = TopoDS::Edge(aNewEdge);
330 aNewOrientedEdge.Orientation(orien);
331
332 if (AS.GetType()==GeomAbs_Plane){
0d969553 333/* nothing is done JAG
7fd59977 334 gp_Pln pln = AS.Plane();
335 gp_Ax3 ax3 = pln.Position();
336
0d969553 337// JYL : the following produces bugs on an edge constructed from a trimmed 3D curve :
7fd59977 338//
339// Handle(Geom_Line)
340// GL = Handle(Geom_Line)::DownCast(BRep_Tool::Curve(TopoDS::Edge(aGenE),
341// Loc,First,Last));
342// gp_Lin gl = GL->Lin();
343// gl.Transform(Loc.Transformation());
344//
345// correction :
346 const TopoDS_Edge& EE = TopoDS::Edge(aGenE);
347 BRepAdaptor_Curve BRAC(EE);
348 gp_Lin gl = BRAC.Line();
349
350 if(aDirV.Index()==2) gl.Translate(myVec);
351 gp_Pnt pnt = gl.Location();
352 gp_Dir dir = gl.Direction();
353 Standard_Real u,v;
354 ElSLib::PlaneParameters(ax3,pnt,u,v);
355 gp_Pnt2d pnt2d(u,v);
356 gp_Dir2d dir2d(dir.Dot(ax3.XDirection()),dir.Dot(ax3.YDirection()));
357 L.SetLocation(pnt2d);
358 L.SetDirection(dir2d);
359*/
360 }
361 else{
362 Standard_Real v = 0;
363 if (aDirV.Index() == 2) v = -myVec.Magnitude();
364 L.SetLocation(gp_Pnt2d(0,v));
365 L.SetDirection(gp_Dir2d(1,0));
366// }
367 Handle(Geom2d_Line) GL = new Geom2d_Line(L);
368 SetThePCurve(myBuilder.Builder(),
369 TopoDS::Edge(aNewEdge),
370 TopoDS::Face(aNewFace),
371 orien,
372 GL);
373 }
374}
375
376
377//=======================================================================
378//function : SetDirectingPCurve
379//purpose :
380//=======================================================================
381
382void BRepSweep_Translation::SetDirectingPCurve
383 (const TopoDS_Shape& aNewFace,
384 TopoDS_Shape& aNewEdge,
385 const TopoDS_Shape& aGenE,
386 const TopoDS_Shape& aGenV,
387 const Sweep_NumShape&,
388 const TopAbs_Orientation orien)
389{
390 TopLoc_Location Loc;
391 GeomAdaptor_Surface AS(BRep_Tool::Surface(TopoDS::Face(aNewFace),Loc));
392 gp_Lin2d L;
393 if(AS.GetType()!=GeomAbs_Plane){
394 L.SetLocation(gp_Pnt2d(BRep_Tool::Parameter(TopoDS::Vertex(aGenV),
395 TopoDS::Edge(aGenE)),0));
396 L.SetDirection(gp_Dir2d(0,-1));
397/* JAG
398 }
399 else{
400
401 gp_Pln pln = AS.Plane();
402 gp_Ax3 ax3 = pln.Position();
403 gp_Pnt pv = BRep_Tool::Pnt(TopoDS::Vertex(aGenV));
404 gp_Dir dir(myVec);
405 Standard_Real u,v;
406 ElSLib::PlaneParameters(ax3,pv,u,v);
407 gp_Pnt2d pnt2d(u,v);
408 gp_Dir2d dir2d(dir.Dot(ax3.XDirection()),dir.Dot(ax3.YDirection()));
409 L.SetLocation(pnt2d);
410 L.SetDirection(dir2d);
411
412 }
413*/
414 Handle(Geom2d_Line) GL = new Geom2d_Line(L);
415 SetThePCurve(myBuilder.Builder(),
416 TopoDS::Edge(aNewEdge),
417 TopoDS::Face(aNewFace),
418 orien,GL);
419 }
420}
421
422//=======================================================================
423//function : DirectSolid
424//purpose :
425//=======================================================================
426
427TopAbs_Orientation BRepSweep_Translation::DirectSolid
428 (const TopoDS_Shape& aGenS,
429 const Sweep_NumShape&)
430{
431 // compare the face normal and the direction
432 BRepAdaptor_Surface surf(TopoDS::Face(aGenS));
433 gp_Pnt P;
434 gp_Vec du,dv;
435 surf.D1((surf.FirstUParameter() + surf.LastUParameter()) / 2.,
436 (surf.FirstVParameter() + surf.LastVParameter()) / 2.,
437 P,du,dv);
438
439 Standard_Real x = myVec.DotCross(du,dv);
440 TopAbs_Orientation orient = (x > 0) ? TopAbs_REVERSED : TopAbs_FORWARD;
441 return orient;
442}
443
444
445//=======================================================================
446//function : GGDShapeIsToAdd
447//purpose :
448//=======================================================================
449
450Standard_Boolean BRepSweep_Translation::GGDShapeIsToAdd
451 (const TopoDS_Shape& ,
452 const TopoDS_Shape& ,
453 const TopoDS_Shape& ,
454 const TopoDS_Shape& ,
455 const Sweep_NumShape& )const
456{
457 return Standard_True;
458}
459
460
461//=======================================================================
462//function : GDDShapeIsToAdd
463//purpose :
464//=======================================================================
465
466Standard_Boolean BRepSweep_Translation::GDDShapeIsToAdd
467 (const TopoDS_Shape& ,
468 const TopoDS_Shape& ,
469 const TopoDS_Shape& ,
470 const Sweep_NumShape& ,
471 const Sweep_NumShape& )const
472{
473 return Standard_True;
474}
475
476
477//=======================================================================
478//function : SeparatedWires
479//purpose :
480//=======================================================================
481
482Standard_Boolean BRepSweep_Translation::SeparatedWires
483 (const TopoDS_Shape& ,
484 const TopoDS_Shape& ,
485 const TopoDS_Shape& ,
486 const TopoDS_Shape& ,
487 const Sweep_NumShape& )const
488{
489 return Standard_False;
490}
491
492
493//=======================================================================
494//function : HasShape
495//purpose :
496//=======================================================================
497
498Standard_Boolean BRepSweep_Translation::HasShape
499 (const TopoDS_Shape& aGenS,
500 const Sweep_NumShape& aDirS)const
501{
502 if(myDirShapeTool.Type(aDirS) == TopAbs_EDGE) {
503
504 if(myGenShapeTool.Type(aGenS) == TopAbs_EDGE) {
505 TopoDS_Edge E = TopoDS::Edge(aGenS);
506
507 // check if the edge is degenerated
508 if(BRep_Tool::Degenerated(E)) {
509 return Standard_False;
510 }
511 // check if the edge is a sewing edge
512
513// modified by NIZHNY-EAP Fri Dec 24 11:13:09 1999 ___BEGIN___
514// const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
515
516// BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
517// BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
518
519// while (itcr.More()) {
520// const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
521// if (cr->IsCurveOnSurface() &&
522// cr->IsCurveOnClosedSurface() ) {
523// cout<<"sewing edge"<<endl;
524// return Standard_False;
525// }
526// itcr.Next();
527// }
528 TopExp_Explorer FaceExp(myGenShape, TopAbs_FACE);
529 for (;FaceExp.More(); FaceExp.Next()) {
530 TopoDS_Face F = TopoDS::Face(FaceExp.Current());
531 if (BRepTools::IsReallyClosed(E, F))
532 return Standard_False;
533 }
534// modified by NIZHNY-EAP Fri Dec 24 11:13:21 1999 ___END___
535 }
536 }
537
538 return Standard_True;
539}
540
541//=======================================================================
542//function : IsInvariant
543//purpose :
544//=======================================================================
545
546Standard_Boolean BRepSweep_Translation::IsInvariant
547 (const TopoDS_Shape& )const
548{
549 return Standard_False;
550}
551
552
553//=======================================================================
554//function : Vec
555//purpose :
556//=======================================================================
557
558gp_Vec BRepSweep_Translation::Vec()const
559{
560 return myVec;
561}
562
563