Warnings on vc14 were eliminated
[occt.git] / src / BRepOffsetAPI / BRepOffsetAPI_MakeOffsetShape.cxx
CommitLineData
b311480e 1// Created on: 1996-02-13
2// Created by: Yves FRICAUD
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#include <BRepOffset_MakeOffset.hxx>
42cf5bc1 18#include <BRepOffsetAPI_MakeOffsetShape.hxx>
7fd59977 19#include <Standard_ConstructionError.hxx>
42cf5bc1 20#include <TopoDS_Shape.hxx>
21#include <TopTools_ListIteratorOfListOfShape.hxx>
b311480e 22
7fd59977 23//=======================================================================
24//function : BRepOffsetAPI_MakeOffsetShape
25//purpose :
26//=======================================================================
7fd59977 27BRepOffsetAPI_MakeOffsetShape::BRepOffsetAPI_MakeOffsetShape()
8013367c 28: myLastUsedAlgo(OffsetAlgo_NONE)
7fd59977 29{
30}
31
32//=======================================================================
33//function : BRepOffsetAPI_MakeOffsetShape
34//purpose :
35//=======================================================================
8013367c 36BRepOffsetAPI_MakeOffsetShape::BRepOffsetAPI_MakeOffsetShape(const TopoDS_Shape& S,
37 const Standard_Real Offset,
38 const Standard_Real Tol,
39 const BRepOffset_Mode Mode,
40 const Standard_Boolean Intersection,
41 const Standard_Boolean SelfInter,
42 const GeomAbs_JoinType Join,
43 const Standard_Boolean RemoveIntEdges)
44: myLastUsedAlgo(OffsetAlgo_NONE)
45{
46 PerformByJoin(S, Offset, Tol, Mode, Intersection, SelfInter, Join, RemoveIntEdges);
47}
7fd59977 48
8013367c 49//=======================================================================
50//function : PerformByJoin
51//purpose :
52//=======================================================================
53void BRepOffsetAPI_MakeOffsetShape::PerformByJoin
54(const TopoDS_Shape& S,
55 const Standard_Real Offset,
56 const Standard_Real Tol,
57 const BRepOffset_Mode Mode,
7fd59977 58 const Standard_Boolean Intersection,
59 const Standard_Boolean SelfInter,
9b7f3f83 60 const GeomAbs_JoinType Join,
61 const Standard_Boolean RemoveIntEdges)
7fd59977 62{
8013367c 63 NotDone();
64 myLastUsedAlgo = OffsetAlgo_JOIN;
65
9b7f3f83 66 myOffsetShape.Initialize (S,Offset,Tol,Mode,Intersection,SelfInter,
67 Join, Standard_False, RemoveIntEdges);
8013367c 68 myOffsetShape.MakeOffsetShape();
69
70 if (!myOffsetShape.IsDone())
71 return;
72
73 myShape = myOffsetShape.Shape();
74 Done();
7fd59977 75}
76
8013367c 77//=======================================================================
78//function : PerformBySimple
79//purpose :
80//=======================================================================
81void BRepOffsetAPI_MakeOffsetShape::PerformBySimple(const TopoDS_Shape& theS,
82 const Standard_Real theOffsetValue)
83{
84 NotDone();
85 myLastUsedAlgo = OffsetAlgo_SIMPLE;
86
87 mySimpleOffsetShape.Initialize(theS, theOffsetValue);
88 mySimpleOffsetShape.Perform();
89
90 if (!mySimpleOffsetShape.IsDone())
91 return;
92
93 myShape = mySimpleOffsetShape.GetResultShape();
94 Done();
95}
7fd59977 96
97//=======================================================================
98//function :MakeOffset
99//purpose :
100//=======================================================================
8013367c 101const BRepOffset_MakeOffset& BRepOffsetAPI_MakeOffsetShape::MakeOffset() const
7fd59977 102{
103 return myOffsetShape;
104}
105
106//=======================================================================
107//function : Build
108//purpose :
109//=======================================================================
7fd59977 110void BRepOffsetAPI_MakeOffsetShape::Build()
111{
7fd59977 112}
113
7fd59977 114//=======================================================================
115//function : Generated
116//purpose :
117//=======================================================================
8013367c 118const TopTools_ListOfShape& BRepOffsetAPI_MakeOffsetShape::Generated (const TopoDS_Shape& S)
119{
7fd59977 120 myGenerated.Clear();
8013367c 121
122 if (myLastUsedAlgo == OffsetAlgo_JOIN && !myOffsetShape.ClosingFaces().Contains(S))
123 {
7fd59977 124 myOffsetShape.OffsetFacesFromShapes ().LastImage (S, myGenerated);
8013367c 125
126 if (!myOffsetShape.ClosingFaces().IsEmpty())
127 {
0d969553
Y
128 // Reverse generated shapes in case of small solids.
129 // Useful only for faces without influence on others.
7fd59977 130 TopTools_ListIteratorOfListOfShape it(myGenerated);
131 for (; it.More(); it.Next())
8013367c 132 it.Value().Reverse();
7fd59977 133 }
134 }
8013367c 135 else if (myLastUsedAlgo == OffsetAlgo_SIMPLE)
136 {
137 TopoDS_Shape aGenShape = mySimpleOffsetShape.Generated(S);
138 if (!aGenShape.IsNull())
139 myGenerated.Append(aGenShape);
140 }
141
7fd59977 142 return myGenerated;
143}
144
7fd59977 145//=======================================================================
146//function : GeneratedEdge
147//purpose :
148//=======================================================================
8013367c 149const TopTools_ListOfShape& BRepOffsetAPI_MakeOffsetShape::GeneratedEdge (const TopoDS_Shape& S)
150{
7fd59977 151 myGenerated.Clear();
7fd59977 152
8013367c 153 if (myLastUsedAlgo == OffsetAlgo_JOIN)
154 {
155 myOffsetShape.OffsetEdgesFromShapes().LastImage (S, myGenerated);
156
157 if (!myGenerated.IsEmpty())
158 {
159 if (S.IsSame(myGenerated.First()))
160 myGenerated.RemoveFirst();
161 }
162 }
163 else if (myLastUsedAlgo == OffsetAlgo_SIMPLE)
164 {
165 TopoDS_Shape aGenShape = mySimpleOffsetShape.Generated(S);
166 if (!aGenShape.IsNull())
167 myGenerated.Append(aGenShape);
7fd59977 168 }
169
170 return myGenerated;
171}
172
7fd59977 173//=======================================================================
174//function : GetJoinType
175//purpose : Query offset join type.
176//=======================================================================
7fd59977 177GeomAbs_JoinType BRepOffsetAPI_MakeOffsetShape::GetJoinType() const
178{
179 return myOffsetShape.GetJoinType();
180}