Corrections made for OCCT 6.9.1.beta
[occt.git] / src / BRepBuilderAPI / BRepBuilderAPI_Copy.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
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>
24 #include <gp_Pnt.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <Poly_Triangulation.hxx>
28
29 namespace {
30
31 //! Tool class implementing necessary functionality for copying geometry
32 class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification 
33 {
34 public:
35   BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom,
36                                     const Standard_Boolean copyMesh)
37     : myCopyGeom(copyGeom),
38       myCopyMesh(copyMesh)
39   {
40   }
41
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)
47   {
48     S = BRep_Tool::Surface(F,L);
49     Tol = BRep_Tool::Tolerance(F);
50     RevWires = RevFace = Standard_False;
51
52     if ( ! S.IsNull() && myCopyGeom )
53       S = Handle(Geom_Surface)::DownCast(S->Copy());
54
55     return Standard_True;
56   }
57
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)
61   {
62     if (!myCopyMesh)
63       return Standard_False;
64
65     TopLoc_Location L;
66     T = BRep_Tool::Triangulation(F, L);
67
68     if (T.IsNull())
69       return Standard_False;
70
71     if (myCopyGeom)
72       T = T->Copy();
73     return Standard_True;
74   }
75
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)
80   {
81     Standard_Real f,l;
82     C = BRep_Tool::Curve (E, L, f, l);
83     Tol = BRep_Tool::Tolerance(E);
84
85     if ( ! C.IsNull() && myCopyGeom )
86       C = Handle(Geom_Curve)::DownCast(C->Copy());
87
88     return Standard_True;
89   }
90
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)
94   {
95     P = BRep_Tool::Pnt(V);
96     Tol = BRep_Tool::Tolerance(V);
97     return Standard_True;
98   }
99
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)
108   {
109     Tol = BRep_Tool::Tolerance(E);
110     Standard_Real f, l;
111     C = BRep_Tool::CurveOnSurface (E, F, f, l);
112
113     if ( ! C.IsNull() && myCopyGeom )
114       C = Handle(Geom2d_Curve)::DownCast (C->Copy());
115
116     return Standard_True;
117   }
118
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)
122   {
123     if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex
124
125     Tol = BRep_Tool::Tolerance(V);
126     P = BRep_Tool::Parameter (V, E);
127
128     return Standard_True;
129   }
130
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&)
135   {
136     return BRep_Tool::Continuity (E, F1, F2);
137   }
138
139 public:
140   DEFINE_STANDARD_RTTI(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
141
142 private: 
143   Standard_Boolean myCopyGeom;
144   Standard_Boolean myCopyMesh;
145 };
146
147 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
148
149 } // anonymous namespace
150
151 //=======================================================================
152 //function : BRepBuilderAPI_Copy
153 //purpose  : 
154 //=======================================================================
155
156 BRepBuilderAPI_Copy::BRepBuilderAPI_Copy ()
157 {
158   myModification = new BRepBuilderAPI_Copy_Modification(Standard_True, Standard_False);
159 }
160
161
162 //=======================================================================
163 //function : BRepBuilderAPI_Copy
164 //purpose  : 
165 //=======================================================================
166
167 BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh)
168 {
169   myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh);
170   DoModif(S);
171 }
172
173
174 //=======================================================================
175 //function : Perform
176 //purpose  : 
177 //=======================================================================
178
179 void BRepBuilderAPI_Copy::Perform(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh)
180 {
181   myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh);
182   NotDone(); // on force la copie si on vient deja d`en faire une
183   DoModif(S);
184 }
185