0023367: New functionality restoring the middle path of pipe-like shape
[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-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 //  Modified by skv - Tue Mar 15 16:20:43 2005
24 // Add methods for supporting history.
25
26 #include <BRepOffsetAPI_MakeOffsetShape.ixx>
27 #include <BRepOffset_MakeOffset.hxx>
28 #include <TopTools_ListIteratorOfListOfShape.hxx>
29 #include <Standard_ConstructionError.hxx>
30
31 //=======================================================================
32 //function : BRepOffsetAPI_MakeOffsetShape
33 //purpose  : 
34 //=======================================================================
35
36 BRepOffsetAPI_MakeOffsetShape::BRepOffsetAPI_MakeOffsetShape()
37 {
38 }
39
40 //=======================================================================
41 //function : BRepOffsetAPI_MakeOffsetShape
42 //purpose  : 
43 //=======================================================================
44
45 BRepOffsetAPI_MakeOffsetShape::BRepOffsetAPI_MakeOffsetShape
46 (const TopoDS_Shape&    S, 
47  const Standard_Real    Offset, 
48  const Standard_Real    Tol, 
49  const BRepOffset_Mode  Mode, 
50  const Standard_Boolean Intersection,
51  const Standard_Boolean SelfInter,
52  const GeomAbs_JoinType Join)
53 {
54   myOffsetShape.Initialize (S,Offset,Tol,Mode,Intersection,SelfInter,Join);
55   Build();
56 }
57
58
59 //=======================================================================
60 //function :MakeOffset
61 //purpose  : 
62 //=======================================================================
63
64 const BRepOffset_MakeOffset& BRepOffsetAPI_MakeOffsetShape::MakeOffset() const 
65 {
66   return myOffsetShape;
67 }
68
69 //=======================================================================
70 //function : Build
71 //purpose  : 
72 //=======================================================================
73
74 void BRepOffsetAPI_MakeOffsetShape::Build()
75 {
76   if (!IsDone()) {
77     myOffsetShape.MakeOffsetShape();
78     if (!myOffsetShape.IsDone()) return;
79     myShape  = myOffsetShape.Shape();
80     Done();
81   }
82 }
83
84
85 //=======================================================================
86 //function : Generated
87 //purpose  : 
88 //=======================================================================
89
90 const TopTools_ListOfShape& BRepOffsetAPI_MakeOffsetShape::Generated (const TopoDS_Shape& S) 
91
92 {  
93   myGenerated.Clear();
94   if (!myOffsetShape.ClosingFaces().Contains(S)) {
95     myOffsetShape.OffsetFacesFromShapes ().LastImage (S, myGenerated);
96    
97     if (!myOffsetShape.ClosingFaces().IsEmpty()) {
98       // Reverse generated shapes in case of small solids.
99       // Useful only for faces without influence on others.
100       TopTools_ListIteratorOfListOfShape it(myGenerated);
101       for (; it.More(); it.Next())
102         it.Value().Reverse();
103     }
104   }
105   return myGenerated;
106 }
107
108
109 //  Modified by skv - Tue Mar 15 16:20:43 2005 Begin
110
111 //=======================================================================
112 //function : GeneratedEdge
113 //purpose  : 
114 //=======================================================================
115
116 const TopTools_ListOfShape& BRepOffsetAPI_MakeOffsetShape::GeneratedEdge (const TopoDS_Shape& S) 
117
118 {  
119   myGenerated.Clear();
120   myOffsetShape.OffsetEdgesFromShapes ().LastImage (S, myGenerated);
121
122   if (!myGenerated.IsEmpty()) {
123     if (S.IsSame(myGenerated.First()))
124       myGenerated.RemoveFirst();
125   }
126
127   return myGenerated;
128 }
129
130
131 //=======================================================================
132 //function : GetJoinType
133 //purpose  : Query offset join type.
134 //=======================================================================
135
136 GeomAbs_JoinType BRepOffsetAPI_MakeOffsetShape::GetJoinType() const
137 {
138   return myOffsetShape.GetJoinType();
139 }
140
141 //  Modified by skv - Tue Mar 15 16:20:43 2005 End