b311480e |
1 | // Created on: 1994-10-04 |
2 | // Created by: Yves FRICAUD |
3 | // Copyright (c) 1994-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 | |
42cf5bc1 |
17 | |
18 | #include <BRep_Builder.hxx> |
19 | #include <BRep_Tool.hxx> |
20 | #include <BRepBuilderAPI_MakeFace.hxx> |
21 | #include <BRepLib.hxx> |
22 | #include <BRepMAT2d_Explorer.hxx> |
7fd59977 |
23 | #include <BRepTools_WireExplorer.hxx> |
42cf5bc1 |
24 | #include <GCE2d_MakeArcOfCircle.hxx> |
25 | #include <GCE2d_MakeSegment.hxx> |
26 | #include <Geom2d_BezierCurve.hxx> |
27 | #include <Geom2d_BoundedCurve.hxx> |
28 | #include <Geom2d_BSplineCurve.hxx> |
29 | #include <Geom2d_Circle.hxx> |
30 | #include <Geom2d_Curve.hxx> |
31 | #include <Geom2d_Ellipse.hxx> |
32 | #include <Geom2d_Hyperbola.hxx> |
33 | #include <Geom2d_Line.hxx> |
1aec3320 |
34 | #include <Geom2d_OffsetCurve.hxx> |
42cf5bc1 |
35 | #include <Geom2d_Parabola.hxx> |
7fd59977 |
36 | #include <Geom2d_TrimmedCurve.hxx> |
42cf5bc1 |
37 | #include <Geom2dConvert.hxx> |
38 | #include <Geom_Curve.hxx> |
39 | #include <Geom_TrimmedCurve.hxx> |
40 | #include <GeomAbs_CurveType.hxx> |
7fd59977 |
41 | #include <GeomAPI.hxx> |
7fd59977 |
42 | #include <gp.hxx> |
43 | #include <gp_Pln.hxx> |
42cf5bc1 |
44 | #include <MAT2d_SequenceOfSequenceOfCurve.hxx> |
7fd59977 |
45 | #include <Precision.hxx> |
42cf5bc1 |
46 | #include <TColGeom2d_SequenceOfCurve.hxx> |
47 | #include <TopAbs.hxx> |
7fd59977 |
48 | #include <TopExp.hxx> |
42cf5bc1 |
49 | #include <TopExp_Explorer.hxx> |
50 | #include <TopLoc_Location.hxx> |
51 | #include <TopoDS.hxx> |
52 | #include <TopoDS_Face.hxx> |
53 | #include <TopoDS_Shape.hxx> |
54 | #include <TopoDS_Wire.hxx> |
7fd59977 |
55 | #include <TopTools_IndexedDataMapOfShapeShape.hxx> |
42cf5bc1 |
56 | |
873c119f |
57 | // |
7fd59977 |
58 | // Modified by Sergey KHROMOV - Thu Dec 5 10:38:14 2002 Begin |
59 | static TopoDS_Edge MakeEdge(const Handle(Geom2d_Curve) &theCurve, |
873c119f |
60 | const TopoDS_Face &theFace, |
61 | const TopoDS_Vertex &theVFirst, |
62 | const TopoDS_Vertex &theVLast); |
7fd59977 |
63 | // Modified by Sergey KHROMOV - Thu Dec 5 10:38:16 2002 End |
873c119f |
64 | // |
65 | static GeomAbs_CurveType GetCurveType(const Handle(Geom2d_Curve)& theC2d); |
7f22979e |
66 | static Handle(Geom2d_TrimmedCurve) AdjustCurveEnd (const Handle(Geom2d_BoundedCurve)& theC2d, |
67 | const gp_Pnt2d theP, const Standard_Boolean isFirst); |
873c119f |
68 | // |
7fd59977 |
69 | //======================================================================= |
70 | //function : BRepMAT2d_Explorer |
71 | //purpose : |
72 | //======================================================================= |
73 | |
74 | BRepMAT2d_Explorer::BRepMAT2d_Explorer() |
75 | { |
76 | Clear(); |
77 | } |
78 | |
79 | //======================================================================= |
80 | //function : BRepMAT2d_Explorer |
81 | //purpose : |
82 | //======================================================================= |
83 | |
84 | BRepMAT2d_Explorer::BRepMAT2d_Explorer(const TopoDS_Face& aFace) |
85 | { |
86 | Perform (aFace); |
87 | } |
88 | |
89 | //======================================================================= |
90 | //function : Perform |
91 | //purpose : |
92 | //======================================================================= |
93 | |
94 | void BRepMAT2d_Explorer::Perform(const TopoDS_Face& aFace) |
95 | { |
96 | Clear(); |
97 | myShape = aFace; |
98 | TopoDS_Face F = TopoDS::Face(aFace); |
99 | F.Orientation(TopAbs_FORWARD); |
100 | TopExp_Explorer Exp (F,TopAbs_WIRE); |
873c119f |
101 | // Modified by Sergey KHROMOV - Tue Nov 26 16:10:37 2002 Begin |
7fd59977 |
102 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F); |
1c72dff6 |
103 | TopoDS_Face aNewF = BRepBuilderAPI_MakeFace(aSurf, Precision::Confusion()); |
7fd59977 |
104 | |
105 | while (Exp.More()) { |
106 | Add (TopoDS::Wire (Exp.Current()),F, aNewF); |
107 | Exp.Next(); |
108 | } |
109 | |
110 | BRepLib::BuildCurves3d(aNewF); |
111 | |
112 | myModifShapes.Add(aFace, aNewF); |
873c119f |
113 | // CheckConnection(); |
114 | // Modified by Sergey KHROMOV - Tue Nov 26 16:10:38 2002 End |
7fd59977 |
115 | } |
116 | |
117 | //======================================================================= |
118 | //function : Add |
119 | //purpose : |
120 | //======================================================================= |
121 | |
122 | void BRepMAT2d_Explorer::Add(const TopoDS_Wire& Spine, |
873c119f |
123 | const TopoDS_Face& aFace, |
124 | TopoDS_Face& aNewFace) |
7fd59977 |
125 | { |
873c119f |
126 | // Modified by Sergey KHROMOV - Tue Nov 26 14:25:46 2002 Begin |
127 | // This method is totally rewroted to include check |
128 | // of connection and creation of a new spine. |
7fd59977 |
129 | NewContour(); |
130 | myIsClosed(currentContour) = (Spine.Closed()) ? Standard_True : Standard_False; |
131 | |
873c119f |
132 | // Modified by skv - Wed Jun 23 12:23:01 2004 Integration Begin |
133 | // Taking into account side of bisecting loci construction. |
134 | // TopoDS_Wire aWFwd = TopoDS::Wire(Spine.Oriented(TopAbs_FORWARD)); |
135 | // BRepTools_WireExplorer anExp(aWFwd, aFace); |
7fd59977 |
136 | BRepTools_WireExplorer anExp(Spine, aFace); |
873c119f |
137 | // Modified by skv - Wed Jun 23 12:23:02 2004 Integration End |
7fd59977 |
138 | TopTools_IndexedDataMapOfShapeShape anOldNewE; |
139 | |
140 | if (!anExp.More()) |
141 | return; |
142 | |
143 | TopoDS_Edge aFirstEdge = anExp.Current(); |
873c119f |
144 | TopoDS_Edge aPrevEdge = aFirstEdge; |
7fd59977 |
145 | Standard_Real UFirst,ULast, aD; |
7fd59977 |
146 | Handle(Geom2d_Curve) C2d; |
147 | Handle(Geom2d_TrimmedCurve) CT2d; |
148 | Handle(Geom2d_TrimmedCurve) aFirstCurve; |
149 | gp_Pnt2d aPFirst; |
150 | gp_Pnt2d aPLast; |
151 | gp_Pnt2d aPCurFirst; |
873c119f |
152 | // Modified by skv - Mon Jul 11 19:00:25 2005 Integration Begin |
153 | // Set the confusion tolerance in accordance with the further algo |
154 | // Standard_Real aTolConf = Precision::Confusion(); |
7fd59977 |
155 | Standard_Real aTolConf = 1.e-8; |
873c119f |
156 | // Modified by skv - Mon Jul 11 19:00:25 2005 Integration End |
7fd59977 |
157 | Standard_Boolean isModif = Standard_False; |
158 | |
873c119f |
159 | // Treatment of the first edge of a wire. |
7fd59977 |
160 | anOldNewE.Add(aFirstEdge, aFirstEdge); |
161 | C2d = BRep_Tool::CurveOnSurface (aFirstEdge, aFace, UFirst, ULast); |
162 | CT2d = new Geom2d_TrimmedCurve(C2d,UFirst,ULast); |
163 | |
164 | if (aFirstEdge.Orientation() == TopAbs_REVERSED) |
165 | CT2d->Reverse(); |
166 | |
167 | aPFirst = CT2d->Value(CT2d->FirstParameter()); |
168 | aPLast = CT2d->Value(CT2d->LastParameter()); |
169 | |
170 | Add(CT2d); |
171 | aFirstCurve = CT2d; |
172 | anExp.Next(); |
173 | |
873c119f |
174 | // Treatment of the next edges: |
7fd59977 |
175 | for (; anExp.More(); anExp.Next()) { |
176 | TopoDS_Edge anEdge = anExp.Current(); |
177 | |
178 | anOldNewE.Add(anEdge, anEdge); |
179 | C2d = BRep_Tool::CurveOnSurface (anEdge, aFace, UFirst, ULast); |
180 | CT2d = new Geom2d_TrimmedCurve(C2d,UFirst,ULast); |
181 | |
182 | if (anEdge.Orientation() == TopAbs_REVERSED) |
183 | CT2d->Reverse(); |
184 | |
185 | aPCurFirst = CT2d->Value(CT2d->FirstParameter()); |
186 | // |
187 | aD=aPLast.Distance(aPCurFirst); |
188 | if (aD > aTolConf) { |
189 | // There are two ways how to fill holes: |
190 | // First, to create a line between these two points. |
191 | // Second, create a BSpline curve and to add the last point of the previous |
192 | // curve as the first pole of the current one. Second method which |
193 | // is worse was performed before and leaved here. Otherwise too much |
194 | // code should be rewritten. |
195 | isModif = Standard_True; |
196 | // |
873c119f |
197 | Standard_Integer aNbC = theCurves.Value(currentContour).Length(); |
198 | Handle(Geom2d_BoundedCurve) CPrev = |
199 | Handle(Geom2d_BoundedCurve)::DownCast(theCurves.ChangeValue(currentContour).ChangeValue(aNbC)); |
200 | // |
201 | GeomAbs_CurveType TCPrev = GetCurveType(CPrev); |
202 | GeomAbs_CurveType TCCurr = GetCurveType(CT2d); |
203 | // |
204 | if(TCCurr <= TCPrev) |
205 | { |
7f22979e |
206 | CT2d = AdjustCurveEnd (CT2d, aPLast, Standard_True); |
873c119f |
207 | // Creation of new edge. |
208 | TopoDS_Edge aNewEdge; |
209 | TopoDS_Vertex aVf = TopExp::FirstVertex(anEdge); |
210 | TopoDS_Vertex aVl = TopExp::LastVertex(anEdge); |
211 | |
212 | if (anEdge.Orientation() == TopAbs_FORWARD) |
213 | aNewEdge = MakeEdge(CT2d, aNewFace, aVf, aVl); |
214 | else |
215 | aNewEdge = MakeEdge(CT2d->Reversed(), aNewFace, aVf, aVl); |
216 | |
217 | aNewEdge.Orientation(anEdge.Orientation()); |
218 | |
219 | anOldNewE.ChangeFromKey(anEdge) = aNewEdge; |
220 | } |
221 | else |
222 | { |
223 | gp_Pnt2d aP = CT2d->Value(CT2d->FirstParameter()); |
7f22979e |
224 | CPrev = AdjustCurveEnd(CPrev, aP, Standard_False); |
873c119f |
225 | theCurves.ChangeValue(currentContour).ChangeValue(aNbC) = CPrev; |
226 | //Change previous edge |
227 | TopoDS_Edge aNewEdge; |
228 | TopoDS_Vertex aVf = TopExp::FirstVertex(aPrevEdge); |
229 | TopoDS_Vertex aVl = TopExp::LastVertex(aPrevEdge); |
230 | |
231 | if (aPrevEdge.Orientation() == TopAbs_FORWARD) |
232 | aNewEdge = MakeEdge(CPrev, aNewFace, aVf, aVl); |
233 | else |
234 | aNewEdge = MakeEdge(CPrev->Reversed(), aNewFace, aVf, aVl); |
235 | |
236 | aNewEdge.Orientation(aPrevEdge.Orientation()); |
237 | |
238 | anOldNewE.ChangeFromKey(aPrevEdge) = aNewEdge; |
239 | |
240 | } |
7fd59977 |
241 | |
7fd59977 |
242 | } |
243 | |
244 | aPLast = CT2d->Value(CT2d->LastParameter()); |
245 | Add(CT2d); |
873c119f |
246 | aPrevEdge = anEdge; |
7fd59977 |
247 | } |
248 | |
249 | // Check of the distance between the first and the last point of wire |
250 | // if the wire is closed. |
873c119f |
251 | if (myIsClosed(currentContour) && aPLast.Distance(aPFirst) > aTolConf) { |
252 | isModif = Standard_True; |
7fd59977 |
253 | |
873c119f |
254 | // |
255 | Standard_Integer aNbC = theCurves.Value(currentContour).Length(); |
256 | Handle(Geom2d_BoundedCurve) CPrev = |
257 | Handle(Geom2d_BoundedCurve)::DownCast(theCurves.ChangeValue(currentContour).ChangeValue(aNbC)); |
258 | // |
259 | GeomAbs_CurveType TCPrev = GetCurveType(CPrev); |
260 | GeomAbs_CurveType TCCurr = GetCurveType(aFirstCurve); |
261 | // |
262 | if(TCCurr <= TCPrev) |
263 | { |
7f22979e |
264 | aFirstCurve = AdjustCurveEnd(aFirstCurve, aPLast, Standard_True); |
7fd59977 |
265 | theCurves.ChangeValue(currentContour).ChangeValue(1) = aFirstCurve; |
873c119f |
266 | // Creation of new edge. |
7fd59977 |
267 | TopoDS_Edge aNewEdge; |
268 | TopoDS_Vertex aVf = TopExp::FirstVertex(aFirstEdge); |
269 | TopoDS_Vertex aVl = TopExp::LastVertex(aFirstEdge); |
270 | |
271 | if (aFirstEdge.Orientation() == TopAbs_FORWARD) |
873c119f |
272 | aNewEdge = MakeEdge(aFirstCurve, aNewFace, aVf, aVl); |
7fd59977 |
273 | else |
873c119f |
274 | aNewEdge = MakeEdge(aFirstCurve->Reversed(), aNewFace, aVf, aVl); |
7fd59977 |
275 | |
276 | aNewEdge.Orientation(aFirstEdge.Orientation()); |
873c119f |
277 | |
7fd59977 |
278 | anOldNewE.ChangeFromKey(aFirstEdge) = aNewEdge; |
279 | } |
873c119f |
280 | else |
281 | { |
282 | gp_Pnt2d aP = aFirstCurve->Value(aFirstCurve->FirstParameter()); |
7f22979e |
283 | CPrev = AdjustCurveEnd(CPrev, aP, Standard_False); |
873c119f |
284 | theCurves.ChangeValue(currentContour).ChangeValue(aNbC) = CPrev; |
285 | //Change previous edge |
286 | TopoDS_Edge aNewEdge; |
287 | TopoDS_Vertex aVf = TopExp::FirstVertex(aPrevEdge); |
288 | TopoDS_Vertex aVl = TopExp::LastVertex(aPrevEdge); |
289 | |
290 | if (aPrevEdge.Orientation() == TopAbs_FORWARD) |
291 | aNewEdge = MakeEdge(CPrev, aNewFace, aVf, aVl); |
292 | else |
293 | aNewEdge = MakeEdge(CPrev->Reversed(), aNewFace, aVf, aVl); |
294 | |
295 | aNewEdge.Orientation(aPrevEdge.Orientation()); |
296 | |
297 | anOldNewE.ChangeFromKey(aPrevEdge) = aNewEdge; |
298 | |
299 | } |
300 | |
301 | } |
7fd59977 |
302 | |
303 | TopoDS_Wire aNewWire; |
304 | BRep_Builder aBuilder; |
305 | |
306 | if (isModif) { |
307 | Standard_Integer i; |
308 | Standard_Integer aNbEdges = anOldNewE.Extent(); |
309 | |
310 | aBuilder.MakeWire(aNewWire); |
311 | |
312 | for (i = 1; i <= aNbEdges; i++) { |
313 | const TopoDS_Shape &aKey = anOldNewE.FindKey(i); |
314 | const TopoDS_Shape &aNewEdge = anOldNewE.FindFromIndex(i); |
315 | |
316 | aBuilder.Add(aNewWire, aNewEdge); |
317 | myModifShapes.Add(aKey, aNewEdge); |
318 | } |
319 | |
320 | if (myIsClosed(currentContour)) |
321 | aNewWire.Closed(Standard_True); |
322 | |
323 | // Modified by skv - Fri Nov 12 17:22:12 2004 Integration Begin |
324 | // The orientation of wire is already taken into account. |
325 | // aNewWire.Orientation(Spine.Orientation()); |
326 | // Modified by skv - Fri Nov 12 17:22:12 2004 Integration End |
327 | myModifShapes.Add(Spine, aNewWire); |
328 | } else |
329 | aNewWire = Spine; |
330 | |
331 | aBuilder.Add(aNewFace, aNewWire); |
873c119f |
332 | // Modified by Sergey KHROMOV - Tue Nov 26 14:25:53 2002 End |
7fd59977 |
333 | } |
334 | |
335 | //======================================================================= |
336 | //function : CheckConnection |
337 | //purpose : |
338 | //======================================================================= |
339 | |
340 | // Modified by Sergey KHROMOV - Tue Nov 26 17:21:44 2002 Begin |
341 | // void BRepMAT2d_Explorer::CheckConnection() |
342 | // { |
343 | // for (Standard_Integer i = 1; i <= theCurves.Length(); i++) |
344 | // for (Standard_Integer j = 2; j <= theCurves(i).Length(); j++) |
345 | // { |
346 | // gp_Pnt2d P1 = theCurves(i)(j-1)->Value( theCurves(i)(j-1)->LastParameter() ); |
347 | // gp_Pnt2d P2 = theCurves(i)(j)->Value( theCurves(i)(j)->FirstParameter() ); |
348 | // if (P1.Distance( P2 ) > Precision::Confusion()) |
349 | // { |
350 | // Handle( Geom2d_BSplineCurve ) BCurve; |
351 | // if (theCurves(i)(j)->DynamicType() != STANDARD_TYPE(Geom2d_BSplineCurve)) |
352 | // BCurve = Geom2dConvert::CurveToBSplineCurve( theCurves(i)(j) ); |
353 | // else |
354 | // BCurve = Handle( Geom2d_BSplineCurve )::DownCast( theCurves(i)(j) ); |
355 | // BCurve->SetPole( 1, P1 ); |
356 | // theCurves(i)(j) = new Geom2d_TrimmedCurve( BCurve, BCurve->FirstParameter(), BCurve->LastParameter() ); |
357 | // } |
358 | // } |
359 | // } |
360 | // Modified by Sergey KHROMOV - Tue Nov 26 17:21:29 2002 End |
361 | |
362 | //======================================================================= |
363 | //function : Clear |
364 | //purpose : |
365 | //======================================================================= |
366 | |
367 | void BRepMAT2d_Explorer::Clear() |
368 | { |
369 | theCurves.Clear() ; |
370 | currentContour = 0; |
873c119f |
371 | // Modified by Sergey KHROMOV - Wed Mar 6 16:07:55 2002 Begin |
7fd59977 |
372 | myIsClosed.Clear(); |
373 | myModifShapes.Clear(); |
873c119f |
374 | // Modified by Sergey KHROMOV - Wed Mar 6 16:07:55 2002 End |
7fd59977 |
375 | } |
376 | |
377 | |
378 | //======================================================================= |
379 | //function : NewContour |
380 | //purpose : |
381 | //======================================================================= |
382 | |
383 | void BRepMAT2d_Explorer::NewContour() |
384 | { |
385 | TColGeom2d_SequenceOfCurve Contour; |
386 | theCurves.Append(Contour); |
873c119f |
387 | // Modified by Sergey KHROMOV - Wed Mar 6 16:12:05 2002 Begin |
7fd59977 |
388 | myIsClosed.Append(Standard_False); |
873c119f |
389 | // Modified by Sergey KHROMOV - Wed Mar 6 16:12:05 2002 End |
7fd59977 |
390 | currentContour ++ ; |
391 | } |
392 | |
393 | |
394 | //======================================================================= |
395 | //function : Add |
396 | //purpose : |
397 | //======================================================================= |
398 | |
399 | void BRepMAT2d_Explorer::Add(const Handle(Geom2d_Curve)& aCurve) |
400 | { |
401 | theCurves.ChangeValue(currentContour).Append(aCurve); |
402 | } |
403 | |
404 | //======================================================================= |
405 | //function : NumberOfContours |
406 | //purpose : |
407 | //======================================================================= |
408 | |
409 | Standard_Integer BRepMAT2d_Explorer::NumberOfContours() const |
410 | { |
411 | return theCurves.Length() ; |
412 | } |
413 | |
414 | |
415 | //======================================================================= |
416 | //function : NumberOfCurves |
417 | //purpose : |
418 | //======================================================================= |
419 | |
420 | Standard_Integer BRepMAT2d_Explorer::NumberOfCurves |
421 | (const Standard_Integer IndexContour) |
873c119f |
422 | const |
7fd59977 |
423 | { |
424 | return theCurves.Value(IndexContour).Length(); |
425 | } |
426 | |
427 | |
428 | //======================================================================= |
429 | //function : Init |
430 | //purpose : |
431 | //======================================================================= |
432 | |
433 | void BRepMAT2d_Explorer::Init(const Standard_Integer IndexContour) |
434 | { |
435 | currentContour = IndexContour; |
436 | current = 1; |
437 | } |
438 | |
439 | |
440 | //======================================================================= |
441 | //function : More |
442 | //purpose : |
443 | //======================================================================= |
444 | |
445 | Standard_Boolean BRepMAT2d_Explorer::More() const |
446 | { |
447 | return (current <= NumberOfCurves(currentContour)); |
448 | } |
449 | |
450 | |
451 | //======================================================================= |
452 | //function : Next |
453 | //purpose : |
454 | //======================================================================= |
455 | |
456 | void BRepMAT2d_Explorer::Next() |
457 | { |
458 | current++; |
459 | } |
460 | |
461 | |
462 | //======================================================================= |
463 | //function : Value |
464 | //purpose : |
465 | //======================================================================= |
466 | |
467 | Handle(Geom2d_Curve) BRepMAT2d_Explorer::Value() const |
468 | { |
469 | return theCurves.Value(currentContour).Value(current); |
470 | } |
471 | |
472 | //======================================================================= |
473 | //function : Shape |
474 | //purpose : |
475 | //======================================================================= |
476 | |
477 | TopoDS_Shape BRepMAT2d_Explorer::Shape() const |
478 | { |
479 | return myShape; |
480 | } |
481 | |
482 | |
483 | //======================================================================= |
484 | //function : Contour |
485 | //purpose : |
486 | //======================================================================= |
487 | |
488 | const TColGeom2d_SequenceOfCurve& BRepMAT2d_Explorer::Contour |
489 | (const Standard_Integer IC) |
873c119f |
490 | const |
7fd59977 |
491 | { |
492 | return theCurves.Value(IC); |
493 | } |
494 | |
495 | |
496 | // Modified by Sergey KHROMOV - Wed Mar 6 17:40:07 2002 Begin |
497 | //======================================================================= |
498 | //function : IsModified |
499 | //purpose : |
500 | //======================================================================= |
501 | |
502 | Standard_Boolean BRepMAT2d_Explorer::IsModified |
873c119f |
503 | (const TopoDS_Shape &aShape) const |
7fd59977 |
504 | { |
505 | if (myModifShapes.Contains(aShape)) { |
506 | const TopoDS_Shape &aNewShape = myModifShapes.FindFromKey(aShape); |
507 | const Standard_Boolean isSame = aNewShape.IsSame(aShape); |
508 | |
509 | return !isSame; |
510 | } |
511 | |
512 | return Standard_False; |
513 | } |
514 | |
515 | //======================================================================= |
516 | //function : ModifiedShape |
517 | //purpose : |
518 | //======================================================================= |
519 | |
520 | TopoDS_Shape BRepMAT2d_Explorer::ModifiedShape |
873c119f |
521 | (const TopoDS_Shape &aShape) const |
7fd59977 |
522 | { |
523 | if (myModifShapes.Contains(aShape)) { |
524 | const TopoDS_Shape &aNewShape = myModifShapes.FindFromKey(aShape); |
525 | |
526 | return aNewShape; |
527 | } |
528 | |
529 | return aShape; |
530 | } |
531 | |
532 | //======================================================================= |
533 | //function : GetIsClosed |
534 | //purpose : |
535 | //======================================================================= |
536 | |
537 | const TColStd_SequenceOfBoolean &BRepMAT2d_Explorer::GetIsClosed() const |
538 | { |
539 | return myIsClosed; |
540 | } |
541 | |
542 | //======================================================================= |
543 | //function : MakeEdge |
544 | //purpose : Creation of an edge by 2d curve, face and two vertices. |
545 | //======================================================================= |
546 | |
547 | TopoDS_Edge MakeEdge(const Handle(Geom2d_Curve) &theCurve, |
873c119f |
548 | const TopoDS_Face &theFace, |
549 | const TopoDS_Vertex &theVFirst, |
550 | const TopoDS_Vertex &theVLast) |
7fd59977 |
551 | { |
552 | TopoDS_Edge aNewEdge; |
553 | BRep_Builder aBuilder; |
554 | Standard_Real aTol = Precision::Confusion(); |
555 | Standard_Real aFPar = theCurve->FirstParameter(); |
556 | Standard_Real aLPar = theCurve->LastParameter(); |
557 | |
558 | aBuilder.MakeEdge(aNewEdge); |
559 | aBuilder.UpdateEdge(aNewEdge, theCurve, theFace, aTol); |
560 | aBuilder.Add(aNewEdge, theVFirst.Oriented(TopAbs_FORWARD)); |
561 | aBuilder.Add(aNewEdge, theVLast.Oriented(TopAbs_REVERSED)); |
562 | aBuilder.Range(aNewEdge, aFPar, aLPar); |
563 | |
564 | return aNewEdge; |
565 | } |
566 | // Modified by Sergey KHROMOV - Wed Mar 6 17:40:14 2002 End |
873c119f |
567 | // |
568 | //======================================================================= |
569 | //function : GetCurveType |
570 | //purpose : Get curve type. |
571 | //======================================================================= |
572 | |
573 | GeomAbs_CurveType GetCurveType(const Handle(Geom2d_Curve)& theC2d) |
574 | { |
575 | GeomAbs_CurveType aTypeCurve = GeomAbs_OtherCurve; |
576 | Handle(Standard_Type) TheType = theC2d->DynamicType(); |
577 | if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
c5f3a425 |
578 | TheType = Handle(Geom2d_TrimmedCurve)::DownCast (theC2d)->BasisCurve()->DynamicType(); |
873c119f |
579 | } |
580 | |
581 | if ( TheType == STANDARD_TYPE(Geom2d_Circle)) { |
582 | aTypeCurve = GeomAbs_Circle; |
583 | } |
584 | else if ( TheType ==STANDARD_TYPE(Geom2d_Line)) { |
585 | aTypeCurve = GeomAbs_Line; |
586 | } |
587 | else if ( TheType == STANDARD_TYPE(Geom2d_Ellipse)) { |
588 | aTypeCurve = GeomAbs_Ellipse; |
589 | } |
590 | else if ( TheType == STANDARD_TYPE(Geom2d_Parabola)) { |
591 | aTypeCurve = GeomAbs_Parabola; |
592 | } |
593 | else if ( TheType == STANDARD_TYPE(Geom2d_Hyperbola)) { |
594 | aTypeCurve = GeomAbs_Hyperbola; |
595 | } |
596 | else if ( TheType == STANDARD_TYPE(Geom2d_BezierCurve)) { |
597 | aTypeCurve = GeomAbs_BezierCurve; |
598 | } |
599 | else if ( TheType == STANDARD_TYPE(Geom2d_BSplineCurve)) { |
600 | aTypeCurve = GeomAbs_BSplineCurve; |
601 | } |
1aec3320 |
602 | else if ( TheType == STANDARD_TYPE(Geom2d_OffsetCurve)) { |
603 | aTypeCurve = GeomAbs_OffsetCurve; |
604 | } |
873c119f |
605 | else { |
606 | aTypeCurve = GeomAbs_OtherCurve; |
607 | } |
608 | return aTypeCurve; |
609 | } |
610 | //======================================================================= |
611 | //function : AdjustCurveEnd |
612 | //purpose : |
613 | //======================================================================= |
7f22979e |
614 | Handle(Geom2d_TrimmedCurve) AdjustCurveEnd (const Handle(Geom2d_BoundedCurve)& theC2d, |
615 | const gp_Pnt2d theP, const Standard_Boolean isFirst) |
873c119f |
616 | { |
617 | GeomAbs_CurveType aType = GetCurveType(theC2d); |
618 | if(aType == GeomAbs_Line) |
619 | { |
620 | //create new line |
621 | if(isFirst) |
622 | { |
623 | gp_Pnt2d aP = theC2d->Value(theC2d->LastParameter()); |
7f22979e |
624 | return GCE2d_MakeSegment(theP, aP); |
873c119f |
625 | } |
626 | else |
627 | { |
628 | gp_Pnt2d aP = theC2d->Value(theC2d->FirstParameter()); |
7f22979e |
629 | return GCE2d_MakeSegment(aP, theP); |
873c119f |
630 | } |
631 | } |
632 | else |
633 | { |
634 | //Convert to BSpline and adjust first pole |
635 | Handle(Geom2d_BSplineCurve) BCurve = |
636 | Geom2dConvert::CurveToBSplineCurve(theC2d, Convert_QuasiAngular); |
637 | if(isFirst) |
638 | { |
639 | BCurve->SetPole(1, theP); |
7f22979e |
640 | return new Geom2d_TrimmedCurve(BCurve, BCurve->FirstParameter(), |
873c119f |
641 | BCurve->LastParameter()); |
642 | } |
643 | else |
644 | { |
645 | BCurve->SetPole(BCurve->NbPoles(), theP); |
7f22979e |
646 | return new Geom2d_TrimmedCurve(BCurve, BCurve->FirstParameter(), |
873c119f |
647 | BCurve->LastParameter()); |
648 | } |
649 | } |
650 | |
651 | } |