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 | |
16 | #include <ShapeUpgrade_FixSmallBezierCurves.ixx> |
17 | #include <TopoDS_Edge.hxx> |
18 | #include <Geom_Curve.hxx> |
19 | #include <Geom2d_Curve.hxx> |
20 | #include <gp_Pnt.hxx> |
21 | #include <ShapeAnalysis_Edge.hxx> |
22 | #include <TopExp.hxx> |
23 | #include <BRep_Tool.hxx> |
24 | #include <gp_Pnt2d.hxx> |
25 | #include <Geom2dConvert_ApproxCurve.hxx> |
26 | #include <TColGeom_HArray1OfCurve.hxx> |
27 | #include <ShapeExtend.hxx> |
28 | #include <TColGeom2d_HArray1OfCurve.hxx> |
29 | #include <GeomAdaptor_Surface.hxx> |
30 | #include <Geom_Surface.hxx> |
31 | #include <BRep_Tool.hxx> |
32 | #include <TopoDS.hxx> |
33 | #include <TopoDS_Shape.hxx> |
34 | #include <Geom2d_TrimmedCurve.hxx> |
35 | #include <GeomAbs_Shape.hxx> |
36 | #include <TopLoc_Location.hxx> |
37 | #include <GeomConvert_ApproxCurve.hxx> |
38 | #include <Geom_TrimmedCurve.hxx> |
39 | #include <GeomConvert_ApproxCurve.hxx> |
40 | #include <ShapeUpgrade_SplitCurve3d.hxx> |
41 | #include <ShapeUpgrade_SplitCurve2d.hxx> |
42 | #include <GeomAdaptor_Surface.hxx> |
43 | #include <Standard_ErrorHandler.hxx> |
44 | #include <Standard_Failure.hxx> |
45 | ShapeUpgrade_FixSmallBezierCurves::ShapeUpgrade_FixSmallBezierCurves() |
46 | { |
47 | } |
48 | |
49 | Standard_Boolean ShapeUpgrade_FixSmallBezierCurves::Approx(Handle(Geom_Curve)& Curve3d,Handle(Geom2d_Curve)& Curve2d,Handle(Geom2d_Curve)& Curve2dR,Standard_Real& First,Standard_Real& Last) |
50 | { |
51 | |
52 | ShapeAnalysis_Edge sae; |
53 | Handle(Geom_Curve) c3d; |
54 | Standard_Real f,l; |
55 | if(sae.Curve3d(myEdge,c3d,f,l,Standard_False)) { |
56 | if(First < f) |
57 | First = f; |
58 | if(Last > l) |
59 | Last =l; |
60 | Handle(Geom_TrimmedCurve) trc = new Geom_TrimmedCurve(c3d,First,Last); |
61 | GeomAbs_Shape aCont = (GeomAbs_Shape)trc->Continuity(); |
62 | if(aCont == GeomAbs_C3 || aCont == GeomAbs_CN) |
63 | aCont = GeomAbs_C2; |
64 | try { |
65 | OCC_CATCH_SIGNALS |
66 | GeomConvert_ApproxCurve AproxCurve(trc,Precision(),aCont,1,9); |
67 | if(AproxCurve.IsDone()) { |
68 | Handle(Geom_Curve) newCurve = AproxCurve.Curve(); |
69 | mySplitCurve3dTool->Init(AproxCurve.Curve(),First,Last); |
70 | mySplitCurve3dTool->Perform(Standard_True); |
71 | if (!mySplitCurve3dTool->Status ( ShapeExtend_FAIL )) { |
72 | Handle(TColGeom_HArray1OfCurve) theSegments3d; |
73 | theSegments3d = mySplitCurve3dTool->GetCurves(); |
74 | if(theSegments3d->Length() >1) return Standard_False; |
75 | Curve3d = theSegments3d->Value(1); |
76 | } |
77 | } |
78 | } |
79 | catch (Standard_Failure) { |
80 | #ifdef DEB |
81 | cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :"; |
82 | Standard_Failure::Caught()->Print(cout); cout << endl; |
83 | #endif |
84 | return Standard_False; |
85 | } |
86 | } |
87 | if ( myFace.IsNull() ) return Standard_True; |
88 | Handle(Geom2d_Curve) c2d; |
89 | TopLoc_Location L; |
90 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(myFace,L); |
91 | GeomAdaptor_Surface ads(aSurf);// = new GeomAdaptor_Surface(aSurf); |
92 | Standard_Real prec = Max(ads.UResolution(Precision()),ads.VResolution(Precision())); |
93 | if(sae.PCurve(myEdge,myFace,c2d,f,l,Standard_False)) { |
94 | if(First < f) |
95 | First = f; |
96 | if(Last > l) |
97 | Last =l; |
98 | Handle(Geom2d_TrimmedCurve) trc2d = new Geom2d_TrimmedCurve(c2d,First,Last); |
99 | GeomAbs_Shape aCont = (GeomAbs_Shape)trc2d->Continuity(); |
100 | try { |
101 | OCC_CATCH_SIGNALS |
102 | Geom2dConvert_ApproxCurve AproxCurve2d(trc2d,prec,aCont,1,9); |
103 | if(AproxCurve2d.IsDone()) { |
104 | Handle(Geom2d_Curve) newCurve = AproxCurve2d.Curve(); |
105 | mySplitCurve2dTool->Init(AproxCurve2d.Curve(),First,Last); |
106 | mySplitCurve2dTool->Perform(Standard_True); |
107 | if ( mySplitCurve2dTool->Status ( ShapeExtend_FAIL )) |
108 | return Standard_False; |
109 | Handle(TColGeom2d_HArray1OfCurve) theSegments2d; |
110 | theSegments2d = mySplitCurve2dTool->GetCurves(); |
111 | if(theSegments2d->Length() >1) return Standard_False; //ShapeAnalysis_Surface |
112 | Curve2d = theSegments2d->Value(1); |
113 | } |
114 | } |
115 | catch (Standard_Failure) { |
116 | #ifdef DEB |
117 | cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :"; |
118 | Standard_Failure::Caught()->Print(cout); cout << endl; |
119 | #endif |
120 | return Standard_False; |
121 | } |
122 | } |
123 | Standard_Boolean isSeam = BRep_Tool::IsClosed ( myEdge, myFace ); |
124 | if ( isSeam ) { |
125 | Handle(Geom2d_Curve) c2; |
126 | Standard_Real f2, l2; |
127 | //smh#8 |
128 | TopoDS_Shape tmpE = myEdge.Reversed(); |
129 | TopoDS_Edge erev = TopoDS::Edge (tmpE ); |
130 | if ( sae.PCurve ( erev, myFace, c2, f2, l2, Standard_False) ) { |
131 | if(First > f) |
132 | First = f; |
133 | if(Last > l) |
134 | Last =l; |
135 | Handle(Geom2d_TrimmedCurve) trc2d = new Geom2d_TrimmedCurve(c2,First,Last); |
136 | GeomAbs_Shape aCont = trc2d->Continuity(); |
137 | Geom2dConvert_ApproxCurve AproxCurve2d(trc2d,prec,aCont,1,9); |
138 | try { |
139 | OCC_CATCH_SIGNALS |
140 | if(AproxCurve2d.IsDone()) { |
141 | Handle(Geom2d_Curve) newCurve = AproxCurve2d.Curve(); |
142 | mySplitCurve2dTool->Init(AproxCurve2d.Curve(),First,Last); |
143 | mySplitCurve2dTool->Perform(Standard_True); |
144 | if ( ! mySplitCurve2dTool->Status ( ShapeExtend_DONE )) |
145 | return Standard_False; |
146 | Handle(TColGeom2d_HArray1OfCurve) theSegments2d; |
147 | theSegments2d = mySplitCurve2dTool->GetCurves(); |
148 | if(theSegments2d->Length() >1) return Standard_False; //ShapeAnalysis_Surface |
149 | Curve2dR = theSegments2d->Value(1); |
150 | } |
151 | } |
152 | catch (Standard_Failure) { |
153 | #ifdef DEB |
154 | cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :"; |
155 | Standard_Failure::Caught()->Print(cout); cout << endl; |
156 | #endif |
157 | return Standard_False; |
158 | } |
159 | } |
160 | } |
161 | return Standard_True; |
162 | } |
163 | |