0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / BRepOffsetAPI / BRepOffsetAPI_MakeOffsetShape.cxx
1 // Created on: 1996-02-13
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <BRepOffset_MakeOffset.hxx>
18 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
19 #include <Standard_ConstructionError.hxx>
20 #include <TopoDS_Shape.hxx>
21 #include <TopTools_ListIteratorOfListOfShape.hxx>
22
23 //=======================================================================
24 //function : BRepOffsetAPI_MakeOffsetShape
25 //purpose  : 
26 //=======================================================================
27 BRepOffsetAPI_MakeOffsetShape::BRepOffsetAPI_MakeOffsetShape()
28 : myLastUsedAlgo(OffsetAlgo_NONE)
29 {
30 }
31
32 //=======================================================================
33 //function : BRepOffsetAPI_MakeOffsetShape
34 //purpose  : 
35 //=======================================================================
36 BRepOffsetAPI_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 }
48
49 //=======================================================================
50 //function : PerformByJoin
51 //purpose  : 
52 //=======================================================================
53 void BRepOffsetAPI_MakeOffsetShape::PerformByJoin
54 (const TopoDS_Shape&    S,
55  const Standard_Real    Offset,
56  const Standard_Real    Tol,
57  const BRepOffset_Mode  Mode,
58  const Standard_Boolean Intersection,
59  const Standard_Boolean SelfInter,
60  const GeomAbs_JoinType Join,
61  const Standard_Boolean RemoveIntEdges)
62 {
63   NotDone();
64   myLastUsedAlgo = OffsetAlgo_JOIN;
65
66   myOffsetShape.Initialize (S,Offset,Tol,Mode,Intersection,SelfInter,
67                             Join, Standard_False, RemoveIntEdges);
68   myOffsetShape.MakeOffsetShape();
69
70   if (!myOffsetShape.IsDone())
71     return;
72
73   myShape  = myOffsetShape.Shape();
74   Done();
75 }
76
77 //=======================================================================
78 //function : PerformBySimple
79 //purpose  : 
80 //=======================================================================
81 void 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 }
96
97 //=======================================================================
98 //function :MakeOffset
99 //purpose  : 
100 //=======================================================================
101 const BRepOffset_MakeOffset& BRepOffsetAPI_MakeOffsetShape::MakeOffset() const
102 {
103   return myOffsetShape;
104 }
105
106 //=======================================================================
107 //function : Build
108 //purpose  : 
109 //=======================================================================
110 void BRepOffsetAPI_MakeOffsetShape::Build()
111 {
112 }
113
114 //=======================================================================
115 //function : Generated
116 //purpose  : 
117 //=======================================================================
118 const TopTools_ListOfShape& BRepOffsetAPI_MakeOffsetShape::Generated (const TopoDS_Shape& S)
119 {
120   myGenerated.Clear();
121   if (myLastUsedAlgo == OffsetAlgo_JOIN)
122   {
123     myGenerated = myOffsetShape.Generated (S);
124   }
125   else if (myLastUsedAlgo == OffsetAlgo_SIMPLE)
126   {
127     TopoDS_Shape aGenShape = mySimpleOffsetShape.Generated(S);
128     if (!aGenShape.IsNull() && !aGenShape.IsSame (S))
129       myGenerated.Append(aGenShape);
130   }
131
132   return myGenerated;
133 }
134
135 //=======================================================================
136 //function : Modified
137 //purpose  : 
138 //=======================================================================
139 const TopTools_ListOfShape& BRepOffsetAPI_MakeOffsetShape::Modified (const TopoDS_Shape& S)
140 {
141   myGenerated.Clear();
142   if (myLastUsedAlgo == OffsetAlgo_JOIN)
143   {
144     myGenerated = myOffsetShape.Modified (S);
145   }
146   else if (myLastUsedAlgo == OffsetAlgo_SIMPLE)
147   {
148     TopoDS_Shape aGenShape = mySimpleOffsetShape.Modified(S);
149     if (!aGenShape.IsNull() && !aGenShape.IsSame (S))
150       myGenerated.Append(aGenShape);
151   }
152
153   return myGenerated;
154 }
155
156 //=======================================================================
157 //function : IsDeleted
158 //purpose  : 
159 //=======================================================================
160 Standard_Boolean BRepOffsetAPI_MakeOffsetShape::IsDeleted (const TopoDS_Shape& S)
161 {
162   if (myLastUsedAlgo == OffsetAlgo_JOIN)
163   {
164     return myOffsetShape.IsDeleted(S);
165   }
166   return Standard_False;
167 }
168
169 //=======================================================================
170 //function : GetJoinType
171 //purpose  : Query offset join type.
172 //=======================================================================
173 GeomAbs_JoinType BRepOffsetAPI_MakeOffsetShape::GetJoinType() const
174 {
175   return myOffsetShape.GetJoinType();
176 }