0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / LocOpe / LocOpe_DPrism.cxx
CommitLineData
b311480e 1// Created on: 1996-09-04
2// Created by: Olga PILLOT
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
7fd59977 17
18#include <BRep_Builder.hxx>
19#include <BRep_Tool.hxx>
7fd59977 20#include <BRepClass3d_SolidClassifier.hxx>
7fd59977 21#include <BRepLib.hxx>
42cf5bc1 22#include <BRepLib_MakeEdge.hxx>
23#include <BRepLib_MakeFace.hxx>
24#include <BRepLib_MakeVertex.hxx>
25#include <BRepLib_MakeWire.hxx>
26#include <BRepTools.hxx>
27#include <BSplCLib.hxx>
28#include <Geom_Curve.hxx>
29#include <Geom_Line.hxx>
30#include <Geom_Plane.hxx>
31#include <Geom_RectangularTrimmedSurface.hxx>
32#include <Geom_Surface.hxx>
33#include <Geom_TrimmedCurve.hxx>
34#include <gp.hxx>
7fd59977 35#include <gp_Ax3.hxx>
42cf5bc1 36#include <gp_Lin.hxx>
7fd59977 37#include <gp_Pln.hxx>
38#include <gp_Vec.hxx>
42cf5bc1 39#include <LocOpe.hxx>
40#include <LocOpe_BuildShape.hxx>
41#include <LocOpe_DPrism.hxx>
7fd59977 42#include <Precision.hxx>
7fd59977 43#include <Standard_ConstructionError.hxx>
42cf5bc1 44#include <Standard_DomainError.hxx>
45#include <Standard_NoSuchObject.hxx>
46#include <StdFail_NotDone.hxx>
47#include <TColgp_SequenceOfPnt.hxx>
48#include <TopExp.hxx>
49#include <TopExp_Explorer.hxx>
50#include <TopoDS.hxx>
51#include <TopoDS_Compound.hxx>
52#include <TopoDS_Face.hxx>
53#include <TopoDS_Shape.hxx>
54#include <TopTools.hxx>
55#include <TopTools_DataMapOfShapeListOfShape.hxx>
56#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
57#include <TopTools_ListIteratorOfListOfShape.hxx>
58#include <TopTools_ListOfShape.hxx>
59#include <TopTools_MapOfShape.hxx>
7fd59977 60
0797d9d3 61#ifdef OCCT_DEBUG
1d0a9d4d 62extern Standard_Boolean BRepFeat_GettraceFEAT();
7fd59977 63#endif
64
65#define NECHANT 7 // voir BRepFeat.cxx
66
67//=======================================================================
68//function : LocOpe_DPrism
69//purpose :
70//=======================================================================
71
72LocOpe_DPrism::LocOpe_DPrism(const TopoDS_Face& Spine,
73 const Standard_Real Height1,
74 const Standard_Real Height2,
75 const Standard_Real Angle):
76 mySpine(Spine)
77{
78 Standard_Integer i ;
79
80 myHeight = Height1 + Height2;
81 Standard_Real y = Height1*sin(Angle);
82 Standard_Real z = Height1*cos(Angle);
83
84 TopoDS_Vertex Vert2 = BRepLib_MakeVertex(gp_Pnt(0,y,z));
85
86 Standard_Real y1 = -Height2*sin(Angle);
87 Standard_Real z1 = -Height2*cos(Angle);
88
89 TopoDS_Vertex Vert1 = BRepLib_MakeVertex(gp_Pnt(0,y1,z1));
90
91 myProfile2 = BRepLib_MakeEdge(Vert1, Vert2);
92
93 Standard_Real Umin,Umax,Vmin,Vmax;
94 Umax = 0.;
95 Umin = 0.;
96 Vmin = 0.;
97 Vmax = 0.;
98
99 BRepTools::UVBounds(Spine,Umin,Umax,Vmin,Vmax);
100 Standard_Real Deltay = Max(Umax-Umin,Vmax-Vmin) + Abs(y);
101 Deltay*=2;
102
103 TopoDS_Vertex Vert3 = BRepLib_MakeVertex(gp_Pnt(0, y + Deltay, z));
104 myProfile3 = BRepLib_MakeEdge(Vert2, Vert3);
105
106 Umax = 0.;
107 Umin = 0.;
108 Vmin = 0.;
109 Vmax = 0.;
110
111 BRepTools::UVBounds(Spine,Umin,Umax,Vmin,Vmax);
112 Standard_Real Deltay1 = Max(Umax-Umin,Vmax-Vmin) + Abs(y1);
113 Deltay1*=2;
114
115 TopoDS_Vertex Vert4 = BRepLib_MakeVertex(gp_Pnt(0, y1+Deltay1, z1));
116 myProfile1 = BRepLib_MakeEdge(Vert4, Vert1);
117
118 myProfile = BRepLib_MakeWire(myProfile1,myProfile2,myProfile3);
119
120 myDPrism.Perform(mySpine,myProfile,gp::XOY());
121
122
123 if (myDPrism.IsDone()) {
124 LocOpe_BuildShape BS;
125 BRep_Builder B;
126 TopoDS_Compound C;
127 TopoDS_Compound D;
128 TopTools_ListOfShape lfaces,lcomplete;
129
130
131 B.MakeCompound(C);
132 TopTools_ListIteratorOfListOfShape it;
133 TopExp_Explorer ExpS(mySpine,TopAbs_EDGE);
134 TopTools_MapOfShape View;
135 for (; ExpS.More(); ExpS.Next()) {
136 const TopoDS_Shape& ES = ExpS.Current();
137 const TopTools_ListOfShape& lffs =
138 myDPrism.GeneratedShapes(ES, myProfile1);
139 for (it.Initialize(lffs); it.More(); it.Next()) {
140 if (View.Add(it.Value()))
141 B.Add(C,it.Value());
142 }
143 }
144
145 TopTools_IndexedDataMapOfShapeListOfShape theMapEF;
146 TopExp::MapShapesAndAncestors(C,TopAbs_EDGE,TopAbs_FACE,theMapEF);
147 View.Clear();
148
149 for ( i = 1; i<=theMapEF.Extent(); i++) {
150 if (theMapEF(i).Extent() == 1) {
151 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
152 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
153 if (View.Add(fac)) {
154 TopoDS_Shape aLocalShape = fac.EmptyCopied();
155 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
156// TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
157 TopExp_Explorer exp;
158 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
159 exp.More(); exp.Next()) {
160// for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
161 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
162 for ( ; exp2.More(); exp2.Next()) {
163 if (exp2.Current().IsSame(edg)) {
164 B.Add(newFace,exp.Current());
165 lfaces.Append(newFace);
166 lcomplete.Append(newFace);
167 break;
168 }
169 }
170 if (exp2.More()) {
171 break;
172 }
173 }
174 }
175 }
176 }
177
178 BS.Perform(lfaces);
179 myFirstShape = BS.Shape();
180
181
182 B.MakeCompound(D);
183
184 ExpS.ReInit();
185 View.Clear();
186
187 for (; ExpS.More(); ExpS.Next()) {
188 const TopoDS_Shape& ES = ExpS.Current();
189 const TopTools_ListOfShape& lfls =
190 myDPrism.GeneratedShapes(ES, myProfile3);
191 for (it.Initialize(lfls); it.More(); it.Next()) {
192 if (View.Add(it.Value()))
193 B.Add(D,it.Value());
194 }
195 }
196
197 lfaces.Clear();
198 theMapEF.Clear();
199 TopExp::MapShapesAndAncestors(D,TopAbs_EDGE,TopAbs_FACE,theMapEF);
200 View.Clear();
201
202 for (i = 1; i<=theMapEF.Extent(); i++) {
203 if (theMapEF(i).Extent() == 1) {
204 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
205 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
206 if (View.Add(fac)) {
207 TopoDS_Shape aLocalShape = fac.EmptyCopied();
208 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
209// TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
210 TopExp_Explorer exp;
211 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
212 exp.More(); exp.Next()) {
213// for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
214 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
215 for ( ; exp2.More(); exp2.Next()) {
216 if (exp2.Current().IsSame(edg)) {
217 B.Add(newFace,exp.Current());
218 lfaces.Append(newFace);
219 lcomplete.Append(newFace);
220 break;
221 }
222 }
223 if (exp2.More()) {
224 break;
225 }
226 }
227 }
228 }
229 }
230 BS.Perform(lfaces);
231 myLastShape = BS.Shape();
232
233
234 View.Clear();
235
236 for (ExpS.ReInit(); ExpS.More(); ExpS.Next()) {
237 const TopoDS_Shape& ES = ExpS.Current();
238 const TopTools_ListOfShape& lffs =
239 myDPrism.GeneratedShapes(ES, myProfile2);
240
241 for (it.Initialize(lffs); it.More(); it.Next()) {
242 if (it.Value().ShapeType() == TopAbs_EDGE) {
243 break;
244 }
245 }
246 if (it.More()) {
247 TopoDS_Shape RemovedEdge = it.Value();
248 TopoDS_Face NewFace;
249 TopoDS_Wire NewWire;
250 B.MakeWire(NewWire);
251 TopAbs_Orientation Orref = TopAbs_FORWARD;
252 TopExp_Explorer exp;
253 for (it.Initialize(lffs); it.More(); it.Next()) {
254 if (it.Value().ShapeType() == TopAbs_FACE) {
255 exp.Init(it.Value().Oriented(TopAbs_FORWARD),TopAbs_WIRE);
256 const TopoDS_Shape theWire = exp.Current();
257 if (NewFace.IsNull()) {
258 Handle(Geom_Surface) S =
259 BRep_Tool::Surface(TopoDS::Face(it.Value()));
260 if (S->DynamicType() ==
261 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
262 S = Handle(Geom_RectangularTrimmedSurface)::
263 DownCast(S)->BasisSurface();
264 }
265 if (S->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
266 break;
267 }
268
269 B.MakeFace(NewFace,S,BRep_Tool::
270 Tolerance(TopoDS::Face(it.Value())));
271 NewFace.Orientation(TopAbs_FORWARD);
272 Orref = theWire.Orientation();
273 for (exp.Init(theWire.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
274 exp.More(); exp.Next()) {
275 if (!exp.Current().IsSame(RemovedEdge)) {
276 B.Add(NewWire,exp.Current());
277 }
278 }
279 }
280 else {
281 for (exp.Init(theWire.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
282 exp.More(); exp.Next()) {
283 if (!exp.Current().IsSame(RemovedEdge)) {
284 if (theWire.Orientation() != Orref) { // Les 2 faces planes ont des normales opposees
285 B.Add(NewWire,exp.Current());
286 }
287 else {
288 B.Add(NewWire,exp.Current().Reversed());
289 }
290 }
291 }
292 }
293 }
294 }
295 if (!NewFace.IsNull()) {
296 B.Add(NewFace,NewWire.Oriented(Orref));
297 lcomplete.Append(NewFace);
298 TopTools_ListOfShape thelist;
299 myMap.Bind(ES, thelist);
300 myMap(ES).Append(NewFace);
301 }
302 else {
303 for (it.Initialize(lffs); it.More(); it.Next()) {
304 if (View.Add(it.Value()) &&
305 it.Value().ShapeType() == TopAbs_FACE) {
306 lcomplete.Append(it.Value());
307
308 }
309 }
310 }
311 }
312 else {
313 for (it.Initialize(lffs); it.More(); it.Next()) {
314 if (View.Add(it.Value()) && it.Value().ShapeType()
315 == TopAbs_FACE) {
316 lcomplete.Append(it.Value());
317 }
318 }
319 }
320
321 TopExp_Explorer ExpS2;
322 for (ExpS2.Init(ES,TopAbs_VERTEX);ExpS2.More(); ExpS2.Next()) {
323 const TopTools_ListOfShape& ls2 =
324 myDPrism.GeneratedShapes(ExpS2.Current(), myProfile2);
325 for (it.Initialize(ls2); it.More(); it.Next()) {
326 if (View.Add(it.Value()) && it.Value().ShapeType()
327 == TopAbs_FACE) {
328 lcomplete.Append(it.Value());
329 }
330 }
331 }
332 }
333
334 BS.Perform(lcomplete);
335 myRes = BS.Shape();
336 BRepLib::UpdateTolerances(myRes);
337 }
338}
339
340
341
342//=======================================================================
343//function : LocOpe_DPrism
344//purpose :
345//=======================================================================
346
347LocOpe_DPrism::LocOpe_DPrism(const TopoDS_Face& Spine,
348 const Standard_Real Height,
349 const Standard_Real Angle):
350 mySpine(Spine)
351{
352 Standard_Integer i ;
353 myHeight = Height;
354 Standard_Real y = Height*sin(Angle);
355 Standard_Real z = Height*cos(Angle);
356
357 TopoDS_Vertex Vert1 = BRepLib_MakeVertex(gp_Pnt(0, 0, 0));
358 TopoDS_Vertex Vert2 = BRepLib_MakeVertex(gp_Pnt(0,y,z));
359 myProfile2 = BRepLib_MakeEdge(Vert1, Vert2);
360
361 Standard_Real Umin,Umax,Vmin,Vmax;
362 BRepTools::UVBounds(Spine,Umin,Umax,Vmin,Vmax);
363 Standard_Real Deltay = Max(Umax-Umin,Vmax-Vmin) + Abs(y);
364 Deltay*=2;
365
366 TopoDS_Vertex Vert3 = BRepLib_MakeVertex(gp_Pnt(0, y + Deltay,z));
367 myProfile3 = BRepLib_MakeEdge(Vert2, Vert3);
368
369 TopoDS_Vertex Vert4 = BRepLib_MakeVertex(gp_Pnt(0, Deltay,0));
370 myProfile1 = BRepLib_MakeEdge(Vert4, Vert1);
371
372 myProfile = BRepLib_MakeWire(myProfile1,myProfile2,myProfile3);
373 myDPrism.Perform(mySpine,myProfile,gp::XOY());
374
375
376 if (myDPrism.IsDone()) {
377 LocOpe_BuildShape BS;
378 BRep_Builder B;
379 TopoDS_Compound C;
380 TopoDS_Compound D;
381 TopTools_ListOfShape lfaces,lcomplete;
382
383
384 B.MakeCompound(C);
385 TopTools_ListIteratorOfListOfShape it;
386 TopExp_Explorer ExpS(mySpine,TopAbs_EDGE);
387 TopTools_MapOfShape View;
388 for (; ExpS.More(); ExpS.Next()) {
389 const TopoDS_Shape& ES = ExpS.Current();
390 const TopTools_ListOfShape& lffs =
391 myDPrism.GeneratedShapes(ES, myProfile1);
392 for (it.Initialize(lffs); it.More(); it.Next()) {
393 if (View.Add(it.Value()))
394 B.Add(C,it.Value());
395 }
396 }
397
398 TopTools_IndexedDataMapOfShapeListOfShape theMapEF;
399 TopExp::MapShapesAndAncestors(C,TopAbs_EDGE,TopAbs_FACE,theMapEF);
400 View.Clear();
401
402 for ( i = 1; i<=theMapEF.Extent(); i++) {
403 if (theMapEF(i).Extent() == 1) {
404 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
405 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
406 if (View.Add(fac)) {
407 TopoDS_Shape aLocalShape = fac.EmptyCopied();
408 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
409// TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
410 TopExp_Explorer exp;
411 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
412 exp.More(); exp.Next()) {
413// for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
414 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
415 for ( ; exp2.More(); exp2.Next()) {
416 if (exp2.Current().IsSame(edg)) {
417 B.Add(newFace,exp.Current());
418 lfaces.Append(newFace);
419 lcomplete.Append(newFace);
420 break;
421 }
422 }
423 if (exp2.More()) {
424 break;
425 }
426 }
427 }
428 }
429 }
430
431 BS.Perform(lfaces);
432 myFirstShape = BS.Shape();
433
434
435 B.MakeCompound(D);
436
437 ExpS.ReInit();
438 View.Clear();
439
440 for (; ExpS.More(); ExpS.Next()) {
441 const TopoDS_Shape& ES = ExpS.Current();
442 const TopTools_ListOfShape& lfls =
443 myDPrism.GeneratedShapes(ES, myProfile3);
444 for (it.Initialize(lfls); it.More(); it.Next()) {
445 if (View.Add(it.Value()))
446 B.Add(D,it.Value());
447 }
448 }
449
450 lfaces.Clear();
451 theMapEF.Clear();
452 TopExp::MapShapesAndAncestors(D,TopAbs_EDGE,TopAbs_FACE,theMapEF);
453 View.Clear();
454
455 for (i = 1; i<=theMapEF.Extent(); i++) {
456 if (theMapEF(i).Extent() == 1) {
457 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
458 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
459 if (View.Add(fac)) {
460 TopoDS_Shape aLocalShape = fac.EmptyCopied();
461 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
462// TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
463 TopExp_Explorer exp;
464 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
465 exp.More(); exp.Next()) {
466// for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
467 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
468 for ( ; exp2.More(); exp2.Next()) {
469 if (exp2.Current().IsSame(edg)) {
470 B.Add(newFace,exp.Current());
471 lfaces.Append(newFace);
472 lcomplete.Append(newFace);
473 break;
474 }
475 }
476 if (exp2.More()) {
477 break;
478 }
479 }
480 }
481 }
482 }
483 BS.Perform(lfaces);
484 myLastShape = BS.Shape();
485
486
487 View.Clear();
488 for (ExpS.ReInit(); ExpS.More(); ExpS.Next()) {
489 const TopoDS_Shape& ES = ExpS.Current();
490 const TopTools_ListOfShape& ls =
491 myDPrism.GeneratedShapes(ES, myProfile2);
492 for (it.Initialize(ls); it.More(); it.Next()) {
493 if (View.Add(it.Value())) {
494 lcomplete.Append(it.Value());
495 }
496 }
497 TopExp_Explorer ExpS2;
498 for (ExpS2.Init(ES,TopAbs_VERTEX);ExpS2.More(); ExpS2.Next()) {
499 const TopTools_ListOfShape& ls2 =
500 myDPrism.GeneratedShapes(ExpS2.Current(), myProfile2);
501 for (it.Initialize(ls2); it.More(); it.Next()) {
502 if (View.Add(it.Value()) && it.Value().
503 ShapeType() == TopAbs_FACE) {
504 lcomplete.Append(it.Value());
505 }
506 }
507 }
508 }
509
510 BS.Perform(lcomplete);
511 myRes = BS.Shape();
512 BRepLib::UpdateTolerances(myRes);
513 }
514
515}
516
517
518//=======================================================================
519//function : IsDone
520//purpose :
521//=======================================================================
522
523Standard_Boolean LocOpe_DPrism::IsDone() const
524{
525 return myDPrism.IsDone();
526}
527
528
529//=======================================================================
530//function : Shape
531//purpose :
532//=======================================================================
533
534const TopoDS_Shape& LocOpe_DPrism::Shape () const
535{
536 if (!myDPrism.IsDone()) {
9775fa61 537 throw StdFail_NotDone();
7fd59977 538 }
539 return myRes;
540}
541
542
543//=======================================================================
544//function : Spine
545//purpose :
546//=======================================================================
547
548const TopoDS_Shape& LocOpe_DPrism::Spine () const
549{
550 return mySpine;
551}
552
553//=======================================================================
554//function : Profile
555//purpose :
556//=======================================================================
557
558const TopoDS_Shape& LocOpe_DPrism::Profile () const
559{
560 return myProfile;
561}
562
563
564//=======================================================================
565//function : FirstShape
566//purpose :
567//=======================================================================
568
569const TopoDS_Shape& LocOpe_DPrism::FirstShape () const
570{
571 return myFirstShape;
572}
573
574//=======================================================================
575//function : LastShape
576//purpose :
577//=======================================================================
578
579const TopoDS_Shape& LocOpe_DPrism::LastShape () const
580{
581 return myLastShape;
582}
583
584
585//=======================================================================
586//function : Shapes
587//purpose :
588//=======================================================================
589
590const TopTools_ListOfShape&
591 LocOpe_DPrism::Shapes (const TopoDS_Shape& S)const
592{
593 if (!myDPrism.IsDone()) {
9775fa61 594 throw StdFail_NotDone();
7fd59977 595 }
596 if (myMap.IsBound(S)) {
597 return myMap(S);
598 }
599 else {
600 return myDPrism.GeneratedShapes(S,myProfile2);
601 }
602}
603
604
605//=======================================================================
606//function : Curves
607//purpose :
608//=======================================================================
609
610void LocOpe_DPrism::Curves(TColGeom_SequenceOfCurve& Scurves) const
611{
612 // Retrieves dy and dz with myProfile2
613 TopoDS_Vertex V1,V2;
614 TopExp::Vertices(myProfile2,V1,V2);
615 gp_Pnt P1 = BRep_Tool::Pnt(V1);
616 gp_Pnt P2 = BRep_Tool::Pnt(V2);
617 Standard_Real dy = P2.Y() - P1.Y();
618 Standard_Real dz = P2.Z() - P1.Z();
619 Scurves.Clear();
620 Handle(Geom_Surface) S = BRep_Tool::Surface(mySpine);
621 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
622 S = Handle(Geom_RectangularTrimmedSurface)::
623 DownCast(S)->BasisSurface();
624 }
625
626 Handle(Geom_Plane) PP = Handle(Geom_Plane)::DownCast(S);
627 if (PP.IsNull()) {
9775fa61 628 throw Standard_ConstructionError();
7fd59977 629 }
630
631 gp_Pln P = PP->Pln();
632 gp_Dir Normale(P.Axis().Direction());
633 if (!P.Direct()) {
634 Normale.Reverse();
635 }
636
637 TopTools_MapOfShape theMap;
638 TopExp_Explorer exp(mySpine.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
639 TopLoc_Location Loc;
640 Handle(Geom_Curve) C;
641 Standard_Real f,l,prm;
642 Standard_Integer i;
643
644 for (; exp.More(); exp.Next()) {
645 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
646 if (!theMap.Add(edg)) {
647 continue;
648 }
649 if (!BRep_Tool::Degenerated(edg)) {
650 C = BRep_Tool::Curve(edg,Loc,f,l);
651 C = Handle(Geom_Curve)::
652 DownCast(C->Transformed(Loc.Transformation()));
653 Standard_Real u1 = -2*Abs(myHeight);
654 Standard_Real u2 = 2*Abs(myHeight);
655
656 for (i=0; i<=NECHANT; i++) {
657 prm = ((NECHANT-i)*f+i*l)/NECHANT;
658 gp_Pnt pt;
659 gp_Vec d1;
660 C->D1(prm,pt,d1);
661 if (exp.Current().Orientation() == TopAbs_REVERSED) {
662 d1.Reverse();
663 }
664 d1.Normalize();
665 gp_Dir locy = Normale.Crossed(d1);
666 gp_Vec ldir = dy*locy.XYZ() + dz*Normale.XYZ();
667 gp_Lin lin(pt, ldir);
668 Handle(Geom_Line) Lin = new Geom_Line(lin);
669 Handle(Geom_TrimmedCurve) trlin =
670 new Geom_TrimmedCurve(Lin, u1, u2, Standard_True);
671 Scurves.Append(trlin);
672 }
673 }
674 }
675}
676
677
678//=======================================================================
679//function : BarycCurve
680//purpose :
681//=======================================================================
682
683Handle(Geom_Curve) LocOpe_DPrism::BarycCurve() const
684{
685 TopoDS_Vertex V1,V2;
686 TopExp::Vertices(myProfile2,V1,V2);
687 gp_Pnt P1 = BRep_Tool::Pnt(V1);
688 gp_Pnt P2 = BRep_Tool::Pnt(V2);
689 Standard_Real dz = P2.Z() - P1.Z();
690
691 Handle(Geom_Surface) S = BRep_Tool::Surface(mySpine);
692 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
693 S = Handle(Geom_RectangularTrimmedSurface)::
694 DownCast(S)->BasisSurface();
695 }
696
697 Handle(Geom_Plane) PP = Handle(Geom_Plane)::DownCast(S);
698 if (PP.IsNull()) {
9775fa61 699 throw Standard_ConstructionError();
7fd59977 700 }
701
702 gp_Pln P = PP->Pln();
703 gp_Dir Normale(P.Axis().Direction());
704 if (!P.Direct()) {
705 Normale.Reverse();
706 }
707 if (mySpine.Orientation() == TopAbs_REVERSED) {
0797d9d3 708#ifdef OCCT_DEBUG
7fd59977 709 Standard_Boolean trc = BRepFeat_GettraceFEAT();
710 if (trc) {
711 cout << "LocOpe_DPrism::BarycCurve()" << endl;
712 cout << " Reversed Spine orientation" << endl;
713 }
714#endif
715// Normale.Reverse(); //cts20871
716 }
717 gp_Vec Vec = dz*Normale.XYZ();
718
719 gp_Pnt bar(0., 0., 0.);
720 TColgp_SequenceOfPnt spt;
721 if(!myFirstShape.IsNull()) {
722 LocOpe::SampleEdges(myFirstShape,spt);
723 }
724 else {
725 LocOpe::SampleEdges(mySpine,spt);
726 }
727 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
728 const gp_Pnt& pvt = spt(jj);
729 bar.ChangeCoord() += pvt.XYZ();
730 }
731 bar.ChangeCoord().Divide(spt.Length());
732 gp_Ax1 newAx(bar,Vec);
733 Handle(Geom_Line) theLin = new Geom_Line(newAx);
734 return theLin;
735}