1 // Created on: 1999-06-17
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_GCurve.hxx>
19 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
20 #include <BRep_TEdge.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRepTools.hxx>
23 #include <Geom2d_Curve.hxx>
24 #include <Geom_BSplineSurface.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_OffsetSurface.hxx>
27 #include <Geom_Plane.hxx>
28 #include <Geom_RectangularTrimmedSurface.hxx>
29 #include <Geom_Surface.hxx>
30 #include <Geom_SurfaceOfLinearExtrusion.hxx>
31 #include <Geom_SurfaceOfRevolution.hxx>
33 #include <Message_Msg.hxx>
34 #include <Precision.hxx>
35 #include <ShapeConstruct.hxx>
36 #include <ShapeCustom_ConvertToBSpline.hxx>
37 #include <Standard_Type.hxx>
38 #include <TopLoc_Location.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Vertex.hxx>
43 IMPLEMENT_STANDARD_RTTIEXT(ShapeCustom_ConvertToBSpline,ShapeCustom_Modification)
45 //=======================================================================
46 //function : ShapeCustom_ConvertToBSpline
48 //=======================================================================
49 ShapeCustom_ConvertToBSpline::ShapeCustom_ConvertToBSpline():
50 myExtrMode(Standard_True), myRevolMode(Standard_True),
51 myOffsetMode(Standard_True), myPlaneMode(Standard_False)
55 //=======================================================================
56 //function : IsToConvert
58 //=======================================================================
60 Standard_Boolean ShapeCustom_ConvertToBSpline::IsToConvert(const Handle(Geom_Surface) &S,
61 Handle(Geom_Surface) &SS) const
64 if(S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
65 Handle(Geom_RectangularTrimmedSurface) RTS =
66 Handle(Geom_RectangularTrimmedSurface)::DownCast ( S );
67 SS = RTS->BasisSurface();
69 if(SS->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
73 Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast ( SS );
74 Handle(Geom_Surface) basis = OS->BasisSurface();
75 Handle(Geom_Surface) tmp;
76 return IsToConvert(basis,tmp);
79 if ( SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) )
81 if ( SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution)) )
83 if ( SS->IsKind(STANDARD_TYPE(Geom_Plane)) )
85 return Standard_False;
88 //=======================================================================
89 //function : NewSurface
91 //=======================================================================
93 Standard_Boolean ShapeCustom_ConvertToBSpline::NewSurface (const TopoDS_Face& F,
94 Handle(Geom_Surface)& S,
97 Standard_Boolean& RevWires,
98 Standard_Boolean& RevFace)
100 S = BRep_Tool::Surface(F,L);
101 Standard_Real U1,U2,V1,V2;
102 S->Bounds(U1,U2,V1,V2);
103 Standard_Real Umin, Umax,Vmin,Vmax;
104 BRepTools::UVBounds(F,Umin, Umax, Vmin, Vmax);
105 if(Precision::IsInfinite(U1) || Precision::IsInfinite(U2)) {
109 if(Precision::IsInfinite(V1) || Precision::IsInfinite(V2)) {
114 Handle(Geom_Surface) surf;
115 if ( ! IsToConvert ( S, surf) ) return Standard_False;
117 Handle(Geom_Surface) res;
118 if(surf->IsKind(STANDARD_TYPE(Geom_OffsetSurface))&&!myOffsetMode) {
119 Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast ( surf );
120 Handle(Geom_Surface) basis = OS->BasisSurface();
121 Standard_Real offset = OS->Offset();
122 Handle(Geom_BSplineSurface) bspl = ShapeConstruct::
123 ConvertSurfaceToBSpline(basis,U1,U2,V1,V2,Precision::Approximation(),
124 surf->Continuity(),10000,15);
125 Handle(Geom_OffsetSurface) nOff = new Geom_OffsetSurface(bspl,offset);
129 GeomAbs_Shape cnt = surf->Continuity();
130 if(surf->IsKind(STANDARD_TYPE(Geom_OffsetSurface)))
131 cnt = GeomAbs_C0; //pdn 30.06.99 because of hang-up in GeomConvert_ApproxSurface
132 res = ShapeConstruct::ConvertSurfaceToBSpline(surf,U1,U2,V1,V2,Precision::Approximation(),
135 if(S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ) {
136 Handle(Geom_RectangularTrimmedSurface) RTS =
137 Handle(Geom_RectangularTrimmedSurface)::DownCast ( S );
138 Standard_Real UF, UL, VF, VL;
139 RTS->Bounds ( UF, UL, VF, VL );
140 S = new Geom_RectangularTrimmedSurface ( res, UF, UL, VF, VL );
145 SendMsg( F, Message_Msg("ConvertToBSpline.NewSurface.MSG0"));
147 Tol = BRep_Tool::Tolerance(F);
148 RevWires = Standard_False;
149 RevFace = Standard_False;
150 return Standard_True;
153 //=======================================================================
154 //function : NewCurve
156 //=======================================================================
158 Standard_Boolean ShapeCustom_ConvertToBSpline::NewCurve (const TopoDS_Edge& E,
159 Handle(Geom_Curve)& C,
163 //:p5 abv 26 Feb 99: force copying of edge if any its pcurve will be replaced
164 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
166 // iterate on pcurves
167 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
168 for ( ; itcr.More(); itcr.Next() ) {
169 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
170 if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue;
171 Handle(Geom_Surface) S = GC->Surface();
172 Handle(Geom_Surface) ES;
173 if ( ! IsToConvert ( S, ES ) ) continue;
175 C = BRep_Tool::Curve ( E, L, f, l );
176 if ( ! C.IsNull() ) C = Handle(Geom_Curve)::DownCast ( C->Copy() );
177 Tol = BRep_Tool::Tolerance ( E );
178 SendMsg( E, Message_Msg("ConvertToBSpline.NewCurve.MSG0"));
179 return Standard_True;
181 return Standard_False;
184 //=======================================================================
185 //function : NewPoint
187 //=======================================================================
189 Standard_Boolean ShapeCustom_ConvertToBSpline::NewPoint (const TopoDS_Vertex& /*V*/,
190 gp_Pnt& /*P*/, Standard_Real& /*Tol*/)
192 return Standard_False;
195 //=======================================================================
196 //function : NewCurve2d
198 //=======================================================================
200 Standard_Boolean ShapeCustom_ConvertToBSpline::NewCurve2d (const TopoDS_Edge& E,
201 const TopoDS_Face& F,
202 const TopoDS_Edge& NewE,
203 const TopoDS_Face& /*NewF*/,
204 Handle(Geom2d_Curve)& C,
208 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
209 Handle(Geom_Surface) ES;
211 // just copy pcurve if either its surface is changing or edge was copied
212 if ( ! IsToConvert ( S, ES ) && E.IsSame ( NewE ) ) return Standard_False;
215 C = BRep_Tool::CurveOnSurface(E,F,f,l);
217 C = Handle(Geom2d_Curve)::DownCast ( C->Copy() );
219 Tol = BRep_Tool::Tolerance ( E );
220 return Standard_True;
223 //=======================================================================
224 //function : NewParameter
226 //=======================================================================
228 Standard_Boolean ShapeCustom_ConvertToBSpline::NewParameter (const TopoDS_Vertex& /*V*/,
229 const TopoDS_Edge& /*E*/,
230 Standard_Real& /*P*/,
231 Standard_Real& /*Tol*/)
233 return Standard_False;
236 //=======================================================================
237 //function : Continuity
239 //=======================================================================
241 GeomAbs_Shape ShapeCustom_ConvertToBSpline::Continuity (const TopoDS_Edge& E,
242 const TopoDS_Face& F1,
243 const TopoDS_Face& F2,
244 const TopoDS_Edge& /*NewE*/,
245 const TopoDS_Face& /*NewF1*/,
246 const TopoDS_Face& /*NewF2*/)
248 return BRep_Tool::Continuity(E,F1,F2);
251 void ShapeCustom_ConvertToBSpline::SetExtrusionMode(const Standard_Boolean extrMode)
253 myExtrMode = extrMode;
256 void ShapeCustom_ConvertToBSpline::SetRevolutionMode(const Standard_Boolean revolMode)
258 myRevolMode = revolMode;
261 void ShapeCustom_ConvertToBSpline::SetOffsetMode(const Standard_Boolean offsetMode)
263 myOffsetMode = offsetMode;
266 void ShapeCustom_ConvertToBSpline::SetPlaneMode(const Standard_Boolean planeMode)
268 myPlaneMode = planeMode;