b311480e |
1 | // Created on: 2000-06-07 |
2 | // Created by: Galina KULIKOVA |
973c2be1 |
3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
7fd59977 |
17 | #include <BRep_Tool.hxx> |
42cf5bc1 |
18 | #include <Geom2d_BSplineCurve.hxx> |
19 | #include <Geom2d_Curve.hxx> |
20 | #include <Geom2d_TrimmedCurve.hxx> |
7fd59977 |
21 | #include <Geom2dConvert_ApproxCurve.hxx> |
42cf5bc1 |
22 | #include <Geom_BSplineCurve.hxx> |
23 | #include <Geom_Curve.hxx> |
7fd59977 |
24 | #include <Geom_Surface.hxx> |
7fd59977 |
25 | #include <Geom_TrimmedCurve.hxx> |
42cf5bc1 |
26 | #include <GeomAbs_Shape.hxx> |
27 | #include <GeomAdaptor_Surface.hxx> |
7fd59977 |
28 | #include <GeomConvert_ApproxCurve.hxx> |
42cf5bc1 |
29 | #include <gp_Pnt.hxx> |
30 | #include <gp_Pnt2d.hxx> |
31 | #include <ShapeAnalysis_Edge.hxx> |
32 | #include <ShapeExtend.hxx> |
33 | #include <ShapeUpgrade_FixSmallBezierCurves.hxx> |
7fd59977 |
34 | #include <ShapeUpgrade_SplitCurve2d.hxx> |
42cf5bc1 |
35 | #include <ShapeUpgrade_SplitCurve3d.hxx> |
7fd59977 |
36 | #include <Standard_ErrorHandler.hxx> |
37 | #include <Standard_Failure.hxx> |
42cf5bc1 |
38 | #include <Standard_Type.hxx> |
39 | #include <TColGeom2d_HArray1OfCurve.hxx> |
40 | #include <TColGeom_HArray1OfCurve.hxx> |
41 | #include <TopExp.hxx> |
42 | #include <TopLoc_Location.hxx> |
43 | #include <TopoDS.hxx> |
44 | #include <TopoDS_Edge.hxx> |
45 | #include <TopoDS_Shape.hxx> |
46 | |
7fd59977 |
47 | ShapeUpgrade_FixSmallBezierCurves::ShapeUpgrade_FixSmallBezierCurves() |
48 | { |
49 | } |
50 | |
51 | Standard_Boolean ShapeUpgrade_FixSmallBezierCurves::Approx(Handle(Geom_Curve)& Curve3d,Handle(Geom2d_Curve)& Curve2d,Handle(Geom2d_Curve)& Curve2dR,Standard_Real& First,Standard_Real& Last) |
52 | { |
53 | |
54 | ShapeAnalysis_Edge sae; |
55 | Handle(Geom_Curve) c3d; |
56 | Standard_Real f,l; |
57 | if(sae.Curve3d(myEdge,c3d,f,l,Standard_False)) { |
58 | if(First < f) |
59 | First = f; |
60 | if(Last > l) |
61 | Last =l; |
543a9964 |
62 | Handle(Geom_Curve) trc = new Geom_TrimmedCurve(c3d,First,Last); |
7fd59977 |
63 | GeomAbs_Shape aCont = (GeomAbs_Shape)trc->Continuity(); |
64 | if(aCont == GeomAbs_C3 || aCont == GeomAbs_CN) |
65 | aCont = GeomAbs_C2; |
66 | try { |
67 | OCC_CATCH_SIGNALS |
68 | GeomConvert_ApproxCurve AproxCurve(trc,Precision(),aCont,1,9); |
69 | if(AproxCurve.IsDone()) { |
70 | Handle(Geom_Curve) newCurve = AproxCurve.Curve(); |
71 | mySplitCurve3dTool->Init(AproxCurve.Curve(),First,Last); |
72 | mySplitCurve3dTool->Perform(Standard_True); |
73 | if (!mySplitCurve3dTool->Status ( ShapeExtend_FAIL )) { |
74 | Handle(TColGeom_HArray1OfCurve) theSegments3d; |
75 | theSegments3d = mySplitCurve3dTool->GetCurves(); |
76 | if(theSegments3d->Length() >1) return Standard_False; |
77 | Curve3d = theSegments3d->Value(1); |
78 | } |
79 | } |
80 | } |
81 | catch (Standard_Failure) { |
0797d9d3 |
82 | #ifdef OCCT_DEBUG |
7fd59977 |
83 | cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :"; |
84 | Standard_Failure::Caught()->Print(cout); cout << endl; |
85 | #endif |
86 | return Standard_False; |
87 | } |
88 | } |
89 | if ( myFace.IsNull() ) return Standard_True; |
90 | Handle(Geom2d_Curve) c2d; |
91 | TopLoc_Location L; |
92 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(myFace,L); |
93 | GeomAdaptor_Surface ads(aSurf);// = new GeomAdaptor_Surface(aSurf); |
94 | Standard_Real prec = Max(ads.UResolution(Precision()),ads.VResolution(Precision())); |
95 | if(sae.PCurve(myEdge,myFace,c2d,f,l,Standard_False)) { |
96 | if(First < f) |
97 | First = f; |
98 | if(Last > l) |
99 | Last =l; |
543a9964 |
100 | Handle(Geom2d_Curve) trc2d = new Geom2d_TrimmedCurve(c2d,First,Last); |
7fd59977 |
101 | GeomAbs_Shape aCont = (GeomAbs_Shape)trc2d->Continuity(); |
102 | try { |
103 | OCC_CATCH_SIGNALS |
104 | Geom2dConvert_ApproxCurve AproxCurve2d(trc2d,prec,aCont,1,9); |
105 | if(AproxCurve2d.IsDone()) { |
106 | Handle(Geom2d_Curve) newCurve = AproxCurve2d.Curve(); |
107 | mySplitCurve2dTool->Init(AproxCurve2d.Curve(),First,Last); |
108 | mySplitCurve2dTool->Perform(Standard_True); |
109 | if ( mySplitCurve2dTool->Status ( ShapeExtend_FAIL )) |
110 | return Standard_False; |
111 | Handle(TColGeom2d_HArray1OfCurve) theSegments2d; |
112 | theSegments2d = mySplitCurve2dTool->GetCurves(); |
113 | if(theSegments2d->Length() >1) return Standard_False; //ShapeAnalysis_Surface |
114 | Curve2d = theSegments2d->Value(1); |
115 | } |
116 | } |
117 | catch (Standard_Failure) { |
0797d9d3 |
118 | #ifdef OCCT_DEBUG |
7fd59977 |
119 | cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :"; |
120 | Standard_Failure::Caught()->Print(cout); cout << endl; |
121 | #endif |
122 | return Standard_False; |
123 | } |
124 | } |
125 | Standard_Boolean isSeam = BRep_Tool::IsClosed ( myEdge, myFace ); |
126 | if ( isSeam ) { |
127 | Handle(Geom2d_Curve) c2; |
128 | Standard_Real f2, l2; |
129 | //smh#8 |
130 | TopoDS_Shape tmpE = myEdge.Reversed(); |
131 | TopoDS_Edge erev = TopoDS::Edge (tmpE ); |
132 | if ( sae.PCurve ( erev, myFace, c2, f2, l2, Standard_False) ) { |
133 | if(First > f) |
134 | First = f; |
135 | if(Last > l) |
136 | Last =l; |
543a9964 |
137 | Handle(Geom2d_Curve) trc2d = new Geom2d_TrimmedCurve(c2,First,Last); |
7fd59977 |
138 | GeomAbs_Shape aCont = trc2d->Continuity(); |
139 | Geom2dConvert_ApproxCurve AproxCurve2d(trc2d,prec,aCont,1,9); |
140 | try { |
141 | OCC_CATCH_SIGNALS |
142 | if(AproxCurve2d.IsDone()) { |
143 | Handle(Geom2d_Curve) newCurve = AproxCurve2d.Curve(); |
144 | mySplitCurve2dTool->Init(AproxCurve2d.Curve(),First,Last); |
145 | mySplitCurve2dTool->Perform(Standard_True); |
146 | if ( ! mySplitCurve2dTool->Status ( ShapeExtend_DONE )) |
147 | return Standard_False; |
148 | Handle(TColGeom2d_HArray1OfCurve) theSegments2d; |
149 | theSegments2d = mySplitCurve2dTool->GetCurves(); |
150 | if(theSegments2d->Length() >1) return Standard_False; //ShapeAnalysis_Surface |
151 | Curve2dR = theSegments2d->Value(1); |
152 | } |
153 | } |
154 | catch (Standard_Failure) { |
0797d9d3 |
155 | #ifdef OCCT_DEBUG |
7fd59977 |
156 | cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :"; |
157 | Standard_Failure::Caught()->Print(cout); cout << endl; |
158 | #endif |
159 | return Standard_False; |
160 | } |
161 | } |
162 | } |
163 | return Standard_True; |
164 | } |
165 | |