b311480e |
1 | // Created on: 1997-10-20 |
2 | // Created by: Olga KOULECHOVA |
3 | // Copyright (c) 1997-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 | |
7fd59977 |
21 | |
22 | |
23 | #include <LocOpe_RevolutionForm.ixx> |
24 | |
25 | #include <BRepSweep_Revol.hxx> |
26 | |
27 | #include <TopExp_Explorer.hxx> |
28 | #include <LocOpe_BuildShape.hxx> |
29 | #include <gp_Ax1.hxx> |
30 | #include <gp_Trsf.hxx> |
31 | #include <gp_Circ.hxx> |
32 | #include <gp_Vec.hxx> |
33 | |
34 | #include <BRepTools_TrsfModification.hxx> |
35 | #include <BRepTools_Modifier.hxx> |
36 | #include <Geom_Curve.hxx> |
37 | #include <Geom_Circle.hxx> |
38 | |
39 | |
40 | #include <BRepLib_MakeVertex.hxx> |
41 | #include <TopoDS_Edge.hxx> |
42 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
43 | #include <TColgp_SequenceOfPnt.hxx> |
44 | |
45 | #include <LocOpe.hxx> |
46 | #include <TopoDS.hxx> |
47 | #include <TopExp.hxx> |
48 | #include <Precision.hxx> |
49 | |
7fd59977 |
50 | //======================================================================= |
51 | //function : LocOpe_Revol |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | LocOpe_RevolutionForm::LocOpe_RevolutionForm() : myDone(Standard_False) |
56 | |
57 | {} |
58 | |
59 | |
60 | //======================================================================= |
61 | //function : Perform |
62 | //purpose : |
63 | //======================================================================= |
64 | |
65 | void LocOpe_RevolutionForm::Perform(const TopoDS_Shape& Base, |
66 | const gp_Ax1& Axis, |
67 | const Standard_Real Angle) |
68 | { |
69 | myMap.Clear(); |
70 | myFirstShape.Nullify(); |
71 | myLastShape.Nullify(); |
72 | myBase.Nullify(); |
73 | myRes.Nullify(); |
74 | myBase = Base; |
75 | myAngle = Angle; |
76 | myAxis = Axis; |
77 | myAngTra = 0.; |
78 | myIsTrans = Standard_False; |
79 | IntPerf(); |
80 | } |
81 | |
82 | |
83 | //======================================================================= |
84 | //function : IntPerf |
85 | //purpose : |
86 | //======================================================================= |
87 | |
88 | void LocOpe_RevolutionForm::IntPerf() |
89 | { |
90 | TopoDS_Shape theBase = myBase; |
91 | BRepTools_Modifier Modif; |
92 | if (myIsTrans) { |
93 | gp_Trsf T; |
94 | T.SetRotation(myAxis,myAngTra); |
95 | Handle(BRepTools_TrsfModification) modbase = |
96 | new BRepTools_TrsfModification(T); |
97 | Modif.Init(theBase); |
98 | Modif.Perform(modbase); |
99 | theBase = Modif.ModifiedShape(theBase); |
100 | } |
101 | |
102 | BRepSweep_Revol theRevol(theBase,myAxis,myAngle); |
103 | |
104 | myFirstShape = theRevol.FirstShape(); |
105 | myLastShape = theRevol.LastShape(); |
106 | |
107 | TopExp_Explorer exp; |
108 | if (theBase.ShapeType() == TopAbs_FACE) { |
109 | for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) { |
110 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
111 | if (!myMap.IsBound(edg)) { |
112 | TopTools_ListOfShape thelist; |
113 | myMap.Bind(edg, thelist); |
114 | TopoDS_Shape desc = theRevol.Shape(edg); |
115 | if (!desc.IsNull()) { |
116 | myMap(edg).Append(desc); |
117 | } |
118 | } |
119 | } |
120 | myRes = theRevol.Shape(); |
121 | } |
122 | |
123 | else { |
124 | // Cas base != FACE |
125 | TopTools_IndexedDataMapOfShapeListOfShape theEFMap; |
126 | TopExp::MapShapesAndAncestors(theBase,TopAbs_EDGE,TopAbs_FACE,theEFMap); |
127 | TopTools_ListOfShape lfaces; |
128 | Standard_Boolean toremove = Standard_False; |
129 | for (Standard_Integer i=1; i<=theEFMap.Extent(); i++) { |
130 | const TopoDS_Shape& edg = theEFMap.FindKey(i); |
131 | TopTools_ListOfShape thelist1; |
132 | myMap.Bind(edg, thelist1); |
133 | TopoDS_Shape desc = theRevol.Shape(edg); |
134 | if (!desc.IsNull()) { |
135 | if (theEFMap(i).Extent() >= 2) { |
136 | toremove = Standard_True; |
137 | } |
138 | else { |
139 | myMap(edg).Append(desc); |
140 | lfaces.Append(desc); |
141 | } |
142 | } |
143 | } |
144 | if(toremove) { |
145 | // Rajouter les faces de FirstShape et LastShape |
146 | for (exp.Init(myFirstShape,TopAbs_FACE);exp.More();exp.Next()) { |
147 | lfaces.Append(exp.Current()); |
148 | } |
149 | for (exp.Init(myLastShape,TopAbs_FACE);exp.More();exp.Next()) { |
150 | lfaces.Append(exp.Current()); |
151 | } |
152 | |
153 | LocOpe_BuildShape BS(lfaces); |
154 | myRes = BS.Shape(); |
155 | } |
156 | else { |
157 | for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) { |
158 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
159 | if (!myMap.IsBound(edg)) { |
160 | TopTools_ListOfShape thelist2; |
161 | myMap.Bind(edg, thelist2); |
162 | TopoDS_Shape desc = theRevol.Shape(edg); |
163 | if (!desc.IsNull()) { |
164 | myMap(edg).Append(desc); |
165 | } |
166 | } |
167 | } |
168 | myRes = theRevol.Shape(); |
169 | } |
170 | } |
171 | |
172 | if (myIsTrans) { |
173 | // m-a-j des descendants |
174 | TopExp_Explorer exp; |
175 | for (exp.Init(myBase,TopAbs_EDGE);exp.More();exp.Next()) { |
176 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
177 | const TopoDS_Edge& edgbis = TopoDS::Edge(Modif.ModifiedShape(edg)); |
178 | if (!edgbis.IsSame(edg) && myMap.IsBound(edgbis)) { |
179 | myMap.Bind(edg,myMap(edgbis)); |
180 | myMap.UnBind(edgbis); |
181 | } |
182 | } |
183 | } |
184 | myDone = Standard_True; |
185 | } |
186 | |
187 | //======================================================================= |
188 | //function : Shape |
189 | //purpose : |
190 | //======================================================================= |
191 | |
192 | const TopoDS_Shape& LocOpe_RevolutionForm::Shape () const |
193 | { |
194 | if (!myDone) { |
195 | StdFail_NotDone::Raise(); |
196 | } |
197 | return myRes; |
198 | } |
199 | |
200 | |
201 | //======================================================================= |
202 | //function : FirstShape |
203 | //purpose : |
204 | //======================================================================= |
205 | |
206 | const TopoDS_Shape& LocOpe_RevolutionForm::FirstShape () const |
207 | { |
208 | return myFirstShape; |
209 | } |
210 | |
211 | //======================================================================= |
212 | //function : LastShape |
213 | //purpose : |
214 | //======================================================================= |
215 | |
216 | const TopoDS_Shape& LocOpe_RevolutionForm::LastShape () const |
217 | { |
218 | return myLastShape; |
219 | } |
220 | |
221 | |
222 | //======================================================================= |
223 | //function : Shapes |
224 | //purpose : |
225 | //======================================================================= |
226 | |
227 | const TopTools_ListOfShape& LocOpe_RevolutionForm::Shapes (const TopoDS_Shape& S) const |
228 | { |
229 | return myMap(S); |
230 | } |