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;
76 //! Returns true to indicate the need to copy edge;
77 //! copies curves if requested
78 Standard_Boolean NewCurve (const TopoDS_Edge& E, Handle(Geom_Curve)& C,
79 TopLoc_Location& L, Standard_Real& Tol) Standard_OVERRIDE
82 C = BRep_Tool::Curve (E, L, f, l);
83 Tol = BRep_Tool::Tolerance(E);
85 if ( ! C.IsNull() && myCopyGeom )
86 C = Handle(Geom_Curve)::DownCast(C->Copy());
91 //! Returns true to indicate the need to copy vertex
92 Standard_Boolean NewPoint (const TopoDS_Vertex& V, gp_Pnt& P,
93 Standard_Real& Tol) Standard_OVERRIDE
95 P = BRep_Tool::Pnt(V);
96 Tol = BRep_Tool::Tolerance(V);
100 //! Returns true to indicate the need to copy edge;
101 //! copies pcurve if requested
102 Standard_Boolean NewCurve2d (const TopoDS_Edge& E,
103 const TopoDS_Face& F,
104 const TopoDS_Edge& /*NewE*/,
105 const TopoDS_Face& /*NewF*/,
106 Handle(Geom2d_Curve)& C,
107 Standard_Real& Tol) Standard_OVERRIDE
109 Tol = BRep_Tool::Tolerance(E);
111 C = BRep_Tool::CurveOnSurface (E, F, f, l);
113 if ( ! C.IsNull() && myCopyGeom )
114 C = Handle(Geom2d_Curve)::DownCast (C->Copy());
116 return Standard_True;
119 //! Returns true to indicate the need to copy vertex
120 Standard_Boolean NewParameter (const TopoDS_Vertex& V, const TopoDS_Edge& E,
121 Standard_Real& P, Standard_Real& Tol) Standard_OVERRIDE
123 if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex
125 Tol = BRep_Tool::Tolerance(V);
126 P = BRep_Tool::Parameter (V, E);
128 return Standard_True;
131 //! Returns the continuity of E between F1 and F2
132 GeomAbs_Shape Continuity (const TopoDS_Edge& E, const TopoDS_Face& F1,
133 const TopoDS_Face& F2, const TopoDS_Edge&,
134 const TopoDS_Face&, const TopoDS_Face&) Standard_OVERRIDE
136 return BRep_Tool::Continuity (E, F1, F2);
140 DEFINE_STANDARD_RTTI(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
143 Standard_Boolean myCopyGeom;
144 Standard_Boolean myCopyMesh;
147 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
149 } // anonymous namespace
151 //=======================================================================
152 //function : BRepBuilderAPI_Copy
154 //=======================================================================
156 BRepBuilderAPI_Copy::BRepBuilderAPI_Copy ()
158 myModification = new BRepBuilderAPI_Copy_Modification(Standard_True, Standard_False);
162 //=======================================================================
163 //function : BRepBuilderAPI_Copy
165 //=======================================================================
167 BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh)
169 myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh);
174 //=======================================================================
177 //=======================================================================
179 void BRepBuilderAPI_Copy::Perform(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh)
181 myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh);
182 NotDone(); // on force la copie si on vient deja d`en faire une