0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / BRepFill / BRepFill_Section.cxx
CommitLineData
b311480e 1// Created on: 1998-07-22
2// Created by: Philippe MANGIN
3// Copyright (c) 1998-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
7fd59977 18#include <BRep_Builder.hxx>
42cf5bc1 19#include <BRepFill_Section.hxx>
20#include <TopoDS.hxx>
7fd59977 21#include <TopoDS_Edge.hxx>
42cf5bc1 22#include <TopoDS_Shape.hxx>
23#include <TopoDS_Vertex.hxx>
24#include <TopoDS_Wire.hxx>
833e7561 25#include <TopoDS_Iterator.hxx>
26#include <TopExp_Explorer.hxx>
27#include <ShapeUpgrade_RemoveLocations.hxx>
7fd59977 28
953d87f3 29BRepFill_Section::BRepFill_Section() :islaw(0),
30 ispunctual(0),
31 contact(0),
32 correction(0)
7fd59977 33{
34}
35
36
37BRepFill_Section::BRepFill_Section(const TopoDS_Shape& Profile,
38 const TopoDS_Vertex& V,
39 const Standard_Boolean WithContact,
40 const Standard_Boolean WithCorrection)
41 : vertex(V),
953d87f3 42 islaw(0),
43 ispunctual(0),
44 contact(WithContact),
7fd59977 45 correction(WithCorrection)
46{
833e7561 47 myOriginalShape = Profile;
48
49 ShapeUpgrade_RemoveLocations RemLoc;
50 RemLoc.SetRemoveLevel(TopAbs_COMPOUND);
51 RemLoc.Remove(Profile);
52 TopoDS_Shape aProfile = RemLoc.GetResult();
53
54 if (aProfile.ShapeType() == TopAbs_WIRE)
55 wire = TopoDS::Wire(aProfile);
56 else if (aProfile.ShapeType() == TopAbs_VERTEX)
7fd59977 57 {
953d87f3 58 ispunctual = Standard_True;
833e7561 59 TopoDS_Vertex aVertex = TopoDS::Vertex(aProfile);
7fd59977 60 BRep_Builder BB;
61
62 TopoDS_Edge DegEdge;
63 BB.MakeEdge( DegEdge );
64 BB.Add( DegEdge, aVertex.Oriented(TopAbs_FORWARD) );
65 BB.Add( DegEdge, aVertex.Oriented(TopAbs_REVERSED) );
66 BB.Degenerated( DegEdge, Standard_True );
7fd59977 67
68 BB.MakeWire( wire );
69 BB.Add( wire, DegEdge );
70 wire.Closed( Standard_True );
71 }
72 else
9775fa61 73 throw Standard_Failure("BRepFill_Section: bad shape type of section");
7fd59977 74}
75
76void BRepFill_Section::Set(const Standard_Boolean IsLaw)
77{
78 islaw = IsLaw;
79}
833e7561 80
81TopoDS_Shape BRepFill_Section::ModifiedShape(const TopoDS_Shape& theShape) const
82{
83 TopoDS_Shape aModifiedShape;
84
85 switch (theShape.ShapeType())
86 {
87 case TopAbs_WIRE:
88 if (theShape.IsSame(myOriginalShape))
89 aModifiedShape = wire;
90 break;
91 case TopAbs_EDGE:
92 {
93 TopoDS_Iterator itor(myOriginalShape);
94 TopoDS_Iterator itw(wire);
95 for (; itor.More(); itor.Next(),itw.Next())
96 {
97 const TopoDS_Shape& anOriginalEdge = itor.Value();
98 const TopoDS_Shape& anEdge = itw.Value();
99 if (anOriginalEdge.IsSame(theShape))
100 {
101 aModifiedShape = anEdge;
102 break;
103 }
104 }
105 }
106 break;
107 case TopAbs_VERTEX:
108 if (theShape.IsSame(myOriginalShape))
109 {
110 TopExp_Explorer Explo(wire, TopAbs_VERTEX);
111 aModifiedShape = Explo.Current();
112 }
113 else
114 {
115 TopExp_Explorer ExpOrig(myOriginalShape, TopAbs_VERTEX);
116 TopExp_Explorer ExpWire(wire, TopAbs_VERTEX);
117 for (; ExpOrig.More(); ExpOrig.Next(),ExpWire.Next())
118 {
119 const TopoDS_Shape& anOriginalVertex = ExpOrig.Current();
120 const TopoDS_Shape& aVertex = ExpWire.Current();
121 if (anOriginalVertex.IsSame(theShape))
122 {
123 aModifiedShape = aVertex;
124 break;
125 }
126 }
127 }
128 break;
129 default:
130 break;
131 }
132
133 return aModifiedShape;
134}