b311480e |
1 | // Created on: 1996-09-04 |
2 | // Created by: Olga PILLOT |
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 | |
42cf5bc1 |
18 | #include <BRepLib_MakeVertex.hxx> |
7fd59977 |
19 | #include <BRepSweep_Prism.hxx> |
7fd59977 |
20 | #include <BRepTools_Modifier.hxx> |
42cf5bc1 |
21 | #include <BRepTools_TrsfModification.hxx> |
22 | #include <Geom_Curve.hxx> |
7fd59977 |
23 | #include <Geom_Line.hxx> |
24 | #include <Geom_TrimmedCurve.hxx> |
42cf5bc1 |
25 | #include <gp_Ax1.hxx> |
26 | #include <gp_Trsf.hxx> |
27 | #include <gp_Vec.hxx> |
7fd59977 |
28 | #include <LocOpe.hxx> |
42cf5bc1 |
29 | #include <LocOpe_BuildShape.hxx> |
30 | #include <LocOpe_Prism.hxx> |
31 | #include <Standard_NoSuchObject.hxx> |
32 | #include <StdFail_NotDone.hxx> |
33 | #include <TColgp_SequenceOfPnt.hxx> |
7fd59977 |
34 | #include <TopExp.hxx> |
42cf5bc1 |
35 | #include <TopExp_Explorer.hxx> |
36 | #include <TopoDS.hxx> |
37 | #include <TopoDS_Edge.hxx> |
38 | #include <TopoDS_Shape.hxx> |
39 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
7fd59977 |
40 | |
41 | //======================================================================= |
42 | //function : LocOpe_Prism |
43 | //purpose : |
44 | //======================================================================= |
d533dafb |
45 | LocOpe_Prism::LocOpe_Prism() |
46 | : myIsTrans(Standard_False), |
47 | myDone(Standard_False) |
48 | { |
49 | } |
7fd59977 |
50 | |
51 | //======================================================================= |
52 | //function : LocOpe_Prism |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | LocOpe_Prism::LocOpe_Prism(const TopoDS_Shape& Base, |
57 | const gp_Vec& V): |
58 | myBase(Base), myVec(V), myIsTrans(Standard_False) |
59 | |
60 | { |
61 | IntPerf(); |
62 | } |
63 | |
64 | //======================================================================= |
65 | //function : LocOpe_Prism |
66 | //purpose : |
67 | //======================================================================= |
68 | |
69 | LocOpe_Prism::LocOpe_Prism(const TopoDS_Shape& Base, |
70 | const gp_Vec& V, |
71 | const gp_Vec& Vtra): |
72 | myBase(Base), myVec(V), myTra(Vtra), myIsTrans(Standard_True) |
73 | |
74 | { |
75 | IntPerf(); |
76 | |
77 | } |
78 | |
79 | //======================================================================= |
80 | //function : Perform |
81 | //purpose : |
82 | //======================================================================= |
83 | |
84 | void LocOpe_Prism::Perform(const TopoDS_Shape& Base, |
85 | const gp_Vec& V) |
86 | { |
87 | myMap.Clear(); |
88 | myFirstShape.Nullify(); |
89 | myLastShape.Nullify(); |
90 | myBase.Nullify(); |
91 | myRes.Nullify(); |
92 | |
93 | myBase = Base; |
94 | myVec = V; |
95 | myIsTrans = Standard_False; |
96 | IntPerf(); |
97 | } |
98 | |
99 | //======================================================================= |
100 | //function : Perform |
101 | //purpose : |
102 | //======================================================================= |
103 | |
104 | void LocOpe_Prism::Perform(const TopoDS_Shape& Base, |
105 | const gp_Vec& V, |
106 | const gp_Vec& Vtra) |
107 | { |
108 | myMap.Clear(); |
109 | myFirstShape.Nullify(); |
110 | myLastShape.Nullify(); |
111 | myBase.Nullify(); |
112 | myRes.Nullify(); |
113 | |
114 | myBase = Base; |
115 | myVec = V; |
116 | myTra = Vtra; |
117 | myIsTrans = Standard_True; |
118 | IntPerf(); |
119 | } |
120 | |
121 | |
122 | //======================================================================= |
123 | //function : IntPerf |
124 | //purpose : |
125 | //======================================================================= |
126 | |
127 | void LocOpe_Prism::IntPerf() |
128 | { |
129 | TopoDS_Shape theBase = myBase; |
130 | BRepTools_Modifier Modif; |
131 | if (myIsTrans) { |
132 | gp_Trsf T; |
133 | T.SetTranslation(myTra); |
134 | Handle(BRepTools_TrsfModification) modbase = |
135 | new BRepTools_TrsfModification(T); |
136 | Modif.Init(theBase); |
137 | Modif.Perform(modbase); |
138 | theBase = Modif.ModifiedShape(theBase); |
139 | } |
140 | |
141 | BRepSweep_Prism thePrism(theBase,myVec); |
142 | |
143 | myFirstShape = thePrism.FirstShape(); |
144 | myLastShape = thePrism.LastShape(); |
145 | |
146 | TopExp_Explorer exp; |
147 | if (theBase.ShapeType() == TopAbs_FACE) { |
148 | for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) { |
149 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
150 | if (!myMap.IsBound(edg)) { |
151 | TopTools_ListOfShape thelist; |
152 | myMap.Bind(edg, thelist); |
153 | TopoDS_Shape desc = thePrism.Shape(edg); |
154 | if (!desc.IsNull()) { |
155 | myMap(edg).Append(desc); |
156 | } |
157 | } |
158 | } |
159 | myRes = thePrism.Shape(); |
160 | } |
161 | |
162 | else { |
163 | // Cas base != FACE |
164 | TopTools_IndexedDataMapOfShapeListOfShape theEFMap; |
165 | TopExp::MapShapesAndAncestors(theBase,TopAbs_EDGE,TopAbs_FACE,theEFMap); |
166 | TopTools_ListOfShape lfaces; |
167 | Standard_Boolean toremove = Standard_False; |
168 | for (Standard_Integer i=1; i<=theEFMap.Extent(); i++) { |
169 | const TopoDS_Shape& edg = theEFMap.FindKey(i); |
170 | TopTools_ListOfShape thelist1; |
171 | myMap.Bind(edg, thelist1); |
172 | TopoDS_Shape desc = thePrism.Shape(edg); |
173 | if (!desc.IsNull()) { |
174 | if (theEFMap(i).Extent() >= 2) { |
175 | toremove = Standard_True; |
176 | } |
177 | else { |
178 | myMap(edg).Append(desc); |
179 | lfaces.Append(desc); |
180 | } |
181 | } |
182 | } |
183 | if(toremove) { |
184 | // Rajouter les faces de FirstShape et LastShape |
185 | for (exp.Init(myFirstShape,TopAbs_FACE);exp.More();exp.Next()) { |
186 | lfaces.Append(exp.Current()); |
187 | } |
188 | for (exp.Init(myLastShape,TopAbs_FACE);exp.More();exp.Next()) { |
189 | lfaces.Append(exp.Current()); |
190 | } |
191 | |
192 | LocOpe_BuildShape BS(lfaces); |
193 | myRes = BS.Shape(); |
194 | } |
195 | else { |
196 | for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) { |
197 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
198 | if (!myMap.IsBound(edg)) { |
199 | TopTools_ListOfShape thelist2; |
200 | myMap.Bind(edg, thelist2); |
201 | TopoDS_Shape desc = thePrism.Shape(edg); |
202 | if (!desc.IsNull()) { |
203 | myMap(edg).Append(desc); |
204 | } |
205 | } |
206 | } |
207 | myRes = thePrism.Shape(); |
208 | } |
209 | } |
210 | |
211 | if (myIsTrans) { |
212 | // m-a-j des descendants |
51740958 |
213 | TopExp_Explorer anExp; |
214 | for (anExp.Init(myBase,TopAbs_EDGE); anExp.More(); anExp.Next()) { |
215 | const TopoDS_Edge& edg = TopoDS::Edge(anExp.Current()); |
7fd59977 |
216 | const TopoDS_Edge& edgbis = TopoDS::Edge(Modif.ModifiedShape(edg)); |
217 | if (!edgbis.IsSame(edg) && myMap.IsBound(edgbis)) { |
218 | myMap.Bind(edg,myMap(edgbis)); |
219 | myMap.UnBind(edgbis); |
220 | } |
221 | } |
222 | } |
223 | myDone = Standard_True; |
224 | } |
225 | |
226 | //======================================================================= |
227 | //function : Shape |
228 | //purpose : |
229 | //======================================================================= |
230 | |
231 | const TopoDS_Shape& LocOpe_Prism::Shape () const |
232 | { |
233 | if (!myDone) { |
9775fa61 |
234 | throw StdFail_NotDone(); |
7fd59977 |
235 | } |
236 | return myRes; |
237 | } |
238 | |
239 | |
240 | //======================================================================= |
241 | //function : FirstShape |
242 | //purpose : |
243 | //======================================================================= |
244 | |
245 | const TopoDS_Shape& LocOpe_Prism::FirstShape () const |
246 | { |
247 | return myFirstShape; |
248 | } |
249 | |
250 | //======================================================================= |
251 | //function : LastShape |
252 | //purpose : |
253 | //======================================================================= |
254 | |
255 | const TopoDS_Shape& LocOpe_Prism::LastShape () const |
256 | { |
257 | return myLastShape; |
258 | } |
259 | |
260 | |
261 | //======================================================================= |
262 | //function : Shapes |
263 | //purpose : |
264 | //======================================================================= |
265 | |
266 | const TopTools_ListOfShape& LocOpe_Prism::Shapes (const TopoDS_Shape& S) const |
267 | { |
268 | return myMap(S); |
269 | } |
270 | |
271 | |
272 | //======================================================================= |
273 | //function : Curves |
274 | //purpose : |
275 | //======================================================================= |
276 | |
277 | void LocOpe_Prism::Curves(TColGeom_SequenceOfCurve& Scurves) const |
278 | { |
279 | Scurves.Clear(); |
280 | TColgp_SequenceOfPnt spt; |
281 | LocOpe::SampleEdges(myFirstShape,spt); |
282 | Standard_Real height = |
283 | Sqrt(myVec.X()*myVec.X()+myVec.Y()*myVec.Y()+myVec.Z()*myVec.Z()); |
284 | Standard_Real u1 = -2*height; |
285 | Standard_Real u2 = 2*height; |
286 | |
287 | for (Standard_Integer jj=1;jj<=spt.Length(); jj++) { |
288 | gp_Ax1 theAx(spt(jj),myVec); |
289 | Handle(Geom_Line) theLin = new Geom_Line(theAx); |
290 | Handle(Geom_TrimmedCurve) trlin = |
291 | new Geom_TrimmedCurve(theLin, u1, u2, Standard_True); |
292 | Scurves.Append(trlin); |
293 | } |
294 | } |
295 | |
296 | //======================================================================= |
297 | //function : BarycCurve |
298 | //purpose : |
299 | //======================================================================= |
300 | |
301 | Handle(Geom_Curve) LocOpe_Prism::BarycCurve() const |
302 | { |
303 | gp_Pnt bar(0., 0., 0.); |
304 | TColgp_SequenceOfPnt spt; |
305 | LocOpe::SampleEdges(myFirstShape,spt); |
306 | for (Standard_Integer jj=1;jj<=spt.Length(); jj++) { |
307 | const gp_Pnt& pvt = spt(jj); |
308 | bar.ChangeCoord() += pvt.XYZ(); |
309 | } |
310 | bar.ChangeCoord().Divide(spt.Length()); |
311 | gp_Ax1 newAx(bar,myVec); |
312 | Handle(Geom_Line) theLin = new Geom_Line(newAx); |
313 | return theLin; |
314 | } |
315 | |