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.
17 #include <BRepBuilderAPI_Copy.ixx>
19 #include <Geom_Surface.hxx>
20 #include <Geom_Curve.hxx>
21 #include <Geom2d_Curve.hxx>
22 #include <BRepTools_Modification.hxx>
23 #include <BRep_Tool.hxx>
24 #include <TopoDS_Vertex.hxx>
27 //! Tool class implementing necessary functionality for copying geometry
28 class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification
31 BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom)
32 : myCopyGeom(copyGeom)
36 //! Returns true to indicate the need to copy face;
37 //! copies surface if requested
38 Standard_Boolean NewSurface (const TopoDS_Face& F, Handle(Geom_Surface)& S,
39 TopLoc_Location& L, Standard_Real& Tol,
40 Standard_Boolean& RevWires, Standard_Boolean& RevFace)
42 S = BRep_Tool::Surface(F,L);
43 Tol = BRep_Tool::Tolerance(F);
44 RevWires = RevFace = Standard_False;
46 if ( ! S.IsNull() && myCopyGeom )
47 S = Handle(Geom_Surface)::DownCast(S->Copy());
52 //! Returns true to indicate the need to copy edge;
53 //! copies curves if requested
54 Standard_Boolean NewCurve (const TopoDS_Edge& E, Handle(Geom_Curve)& C,
55 TopLoc_Location& L, Standard_Real& Tol)
58 C = BRep_Tool::Curve (E, L, f, l);
59 Tol = BRep_Tool::Tolerance(E);
61 if ( ! C.IsNull() && myCopyGeom )
62 C = Handle(Geom_Curve)::DownCast(C->Copy());
67 //! Returns true to indicate the need to copy vertex
68 Standard_Boolean NewPoint (const TopoDS_Vertex& V, gp_Pnt& P,
71 P = BRep_Tool::Pnt(V);
72 Tol = BRep_Tool::Tolerance(V);
76 //! Returns true to indicate the need to copy edge;
77 //! copies pcurve if requested
78 Standard_Boolean NewCurve2d (const TopoDS_Edge& E,
80 const TopoDS_Edge& /*NewE*/,
81 const TopoDS_Face& /*NewF*/,
82 Handle(Geom2d_Curve)& C,
85 Tol = BRep_Tool::Tolerance(E);
87 C = BRep_Tool::CurveOnSurface (E, F, f, l);
89 if ( ! C.IsNull() && myCopyGeom )
90 C = Handle(Geom2d_Curve)::DownCast (C->Copy());
95 //! Returns true to indicate the need to copy vertex
96 Standard_Boolean NewParameter (const TopoDS_Vertex& V, const TopoDS_Edge& E,
97 Standard_Real& P, Standard_Real& Tol)
99 if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex
101 Tol = BRep_Tool::Tolerance(V);
102 P = BRep_Tool::Parameter (V, E);
104 return Standard_True;
107 //! Returns the continuity of E between F1 and F2
108 GeomAbs_Shape Continuity (const TopoDS_Edge& E, const TopoDS_Face& F1,
109 const TopoDS_Face& F2, const TopoDS_Edge&,
110 const TopoDS_Face&, const TopoDS_Face&)
112 return BRep_Tool::Continuity (E, F1, F2);
116 DEFINE_STANDARD_RTTI(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
119 Standard_Boolean myCopyGeom;
122 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
125 //=======================================================================
126 //function : BRepBuilderAPI_Copy
128 //=======================================================================
130 BRepBuilderAPI_Copy::BRepBuilderAPI_Copy ()
132 myModification = new BRepBuilderAPI_Copy_Modification(Standard_True);
136 //=======================================================================
137 //function : BRepBuilderAPI_Copy
139 //=======================================================================
141 BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom)
143 myModification = new BRepBuilderAPI_Copy_Modification(copyGeom);
148 //=======================================================================
151 //=======================================================================
153 void BRepBuilderAPI_Copy::Perform(const TopoDS_Shape& S, const Standard_Boolean copyGeom)
155 myModification = new BRepBuilderAPI_Copy_Modification(copyGeom);
156 NotDone(); // on force la copie si on vient deja d`en faire une