1 // Created on: 1994-12-12
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1994-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_Tool.hxx>
19 #include <BRepBuilderAPI_Copy.hxx>
20 #include <BRepTools_Modification.hxx>
21 #include <Geom2d_Curve.hxx>
22 #include <Geom_Curve.hxx>
23 #include <Geom_Surface.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <Poly_Triangulation.hxx>
31 //! Tool class implementing necessary functionality for copying geometry
32 class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification
35 BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom,
36 const Standard_Boolean copyMesh)
37 : myCopyGeom(copyGeom),
42 //! Returns true to indicate the need to copy face;
43 //! copies surface if requested
44 Standard_Boolean NewSurface (const TopoDS_Face& F, Handle(Geom_Surface)& S,
45 TopLoc_Location& L, Standard_Real& Tol,
46 Standard_Boolean& RevWires, Standard_Boolean& RevFace) Standard_OVERRIDE
48 S = BRep_Tool::Surface(F,L);
49 Tol = BRep_Tool::Tolerance(F);
50 RevWires = RevFace = Standard_False;
52 if ( ! S.IsNull() && myCopyGeom )
53 S = Handle(Geom_Surface)::DownCast(S->Copy());
58 //! Returns true to indicate the need to copy triangulation;
59 //! copies it if required
60 Standard_Boolean NewTriangulation(const TopoDS_Face& F, Handle(Poly_Triangulation)& T) Standard_OVERRIDE
63 return Standard_False;
66 T = BRep_Tool::Triangulation(F, L);
69 return Standard_False;
71 // mesh is copied if and only if the geometry need to be copied too
77 //! Returns true to indicate the need to copy edge;
78 //! copies curves if requested
79 Standard_Boolean NewCurve (const TopoDS_Edge& E, Handle(Geom_Curve)& C,
80 TopLoc_Location& L, Standard_Real& Tol) Standard_OVERRIDE
83 C = BRep_Tool::Curve (E, L, f, l);
84 Tol = BRep_Tool::Tolerance(E);
86 if ( ! C.IsNull() && myCopyGeom )
87 C = Handle(Geom_Curve)::DownCast(C->Copy());
92 //! Returns true to indicate the need to copy polygon;
93 //! copies it if required
94 Standard_Boolean NewPolygon(const TopoDS_Edge& E, Handle(Poly_Polygon3D)& P)
97 return Standard_False;
100 P = BRep_Tool::Polygon3D(E, aLoc);
103 return Standard_False;
105 // polygon is copied if and only if the geometry need to be copied too
108 return Standard_True;
111 //! Returns true to indicate the need to copy polygon;
112 //! copies it if required
113 Standard_Boolean NewPolygonOnTriangulation(const TopoDS_Edge& E, const TopoDS_Face& F,
114 Handle(Poly_PolygonOnTriangulation)& P)
117 return Standard_False;
119 TopLoc_Location aLoc;
120 Handle(Poly_Triangulation) aTria = BRep_Tool::Triangulation(F, aLoc);
121 P = BRep_Tool::PolygonOnTriangulation(E, aTria, aLoc);
124 return Standard_False;
126 // polygon is copied if and only if the geometry need to be copied too
129 return Standard_True;
132 //! Returns true to indicate the need to copy vertex
133 Standard_Boolean NewPoint (const TopoDS_Vertex& V, gp_Pnt& P,
134 Standard_Real& Tol) Standard_OVERRIDE
136 P = BRep_Tool::Pnt(V);
137 Tol = BRep_Tool::Tolerance(V);
138 return Standard_True;
141 //! Returns true to indicate the need to copy edge;
142 //! copies pcurve if requested
143 Standard_Boolean NewCurve2d (const TopoDS_Edge& E,
144 const TopoDS_Face& F,
145 const TopoDS_Edge& /*NewE*/,
146 const TopoDS_Face& /*NewF*/,
147 Handle(Geom2d_Curve)& C,
148 Standard_Real& Tol) Standard_OVERRIDE
150 Tol = BRep_Tool::Tolerance(E);
152 C = BRep_Tool::CurveOnSurface (E, F, f, l);
154 if ( ! C.IsNull() && myCopyGeom )
155 C = Handle(Geom2d_Curve)::DownCast (C->Copy());
157 return Standard_True;
160 //! Returns true to indicate the need to copy vertex
161 Standard_Boolean NewParameter (const TopoDS_Vertex& V, const TopoDS_Edge& E,
162 Standard_Real& P, Standard_Real& Tol) Standard_OVERRIDE
164 if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex
166 Tol = BRep_Tool::Tolerance(V);
167 P = BRep_Tool::Parameter (V, E);
169 return Standard_True;
172 //! Returns the continuity of E between F1 and F2
173 GeomAbs_Shape Continuity (const TopoDS_Edge& E, const TopoDS_Face& F1,
174 const TopoDS_Face& F2, const TopoDS_Edge&,
175 const TopoDS_Face&, const TopoDS_Face&) Standard_OVERRIDE
177 return BRep_Tool::Continuity (E, F1, F2);
181 DEFINE_STANDARD_RTTI(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
184 Standard_Boolean myCopyGeom;
185 Standard_Boolean myCopyMesh;
188 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
190 } // anonymous namespace
192 //=======================================================================
193 //function : BRepBuilderAPI_Copy
195 //=======================================================================
197 BRepBuilderAPI_Copy::BRepBuilderAPI_Copy ()
199 myModification = new BRepBuilderAPI_Copy_Modification(Standard_True, Standard_False);
203 //=======================================================================
204 //function : BRepBuilderAPI_Copy
206 //=======================================================================
208 BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh)
210 myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh);
215 //=======================================================================
218 //=======================================================================
220 void BRepBuilderAPI_Copy::Perform(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh)
222 myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh);
223 NotDone(); // on force la copie si on vient deja d`en faire une