b311480e |
1 | // Created on: 1994-12-12 |
2 | // Created by: Jacques GOUSSARD |
3 | // Copyright (c) 1994-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
7fd59977 |
18 | #include <BRep_Tool.hxx> |
42cf5bc1 |
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> |
7fd59977 |
24 | #include <gp_Pnt.hxx> |
42cf5bc1 |
25 | #include <TopoDS_Shape.hxx> |
26 | #include <TopoDS_Vertex.hxx> |
55e738d2 |
27 | #include <Poly_Triangulation.hxx> |
7fd59977 |
28 | |
5c8908e0 |
29 | namespace { |
30 | |
7fd59977 |
31 | //! Tool class implementing necessary functionality for copying geometry |
32 | class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification |
33 | { |
34 | public: |
55e738d2 |
35 | BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom, |
5c8908e0 |
36 | const Standard_Boolean copyMesh) |
55e738d2 |
37 | : myCopyGeom(copyGeom), |
38 | myCopyMesh(copyMesh) |
7fd59977 |
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, |
79104795 |
46 | Standard_Boolean& RevWires, Standard_Boolean& RevFace) Standard_OVERRIDE |
7fd59977 |
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 | |
55e738d2 |
58 | //! Returns true to indicate the need to copy triangulation; |
59 | //! copies it if required |
79104795 |
60 | Standard_Boolean NewTriangulation(const TopoDS_Face& F, Handle(Poly_Triangulation)& T) Standard_OVERRIDE |
55e738d2 |
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 | |
8156dddd |
71 | // mesh is copied if and only if the geometry need to be copied too |
5c8908e0 |
72 | if (myCopyGeom) |
73 | T = T->Copy(); |
55e738d2 |
74 | return Standard_True; |
75 | } |
76 | |
7fd59977 |
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, |
79104795 |
80 | TopLoc_Location& L, Standard_Real& Tol) Standard_OVERRIDE |
7fd59977 |
81 | { |
82 | Standard_Real f,l; |
83 | C = BRep_Tool::Curve (E, L, f, l); |
84 | Tol = BRep_Tool::Tolerance(E); |
85 | |
86 | if ( ! C.IsNull() && myCopyGeom ) |
87 | C = Handle(Geom_Curve)::DownCast(C->Copy()); |
88 | |
89 | return Standard_True; |
90 | } |
91 | |
8156dddd |
92 | //! Returns true to indicate the need to copy polygon; |
93 | //! copies it if required |
c7854818 |
94 | Standard_Boolean NewPolygon(const TopoDS_Edge& E, Handle(Poly_Polygon3D)& P) Standard_OVERRIDE |
8156dddd |
95 | { |
96 | if (!myCopyMesh) |
97 | return Standard_False; |
98 | |
99 | TopLoc_Location aLoc; |
100 | P = BRep_Tool::Polygon3D(E, aLoc); |
101 | |
102 | if (P.IsNull()) |
103 | return Standard_False; |
104 | |
105 | // polygon is copied if and only if the geometry need to be copied too |
106 | if (myCopyGeom) |
107 | P = P->Copy(); |
108 | return Standard_True; |
109 | } |
110 | |
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, |
c7854818 |
114 | Handle(Poly_PolygonOnTriangulation)& P) Standard_OVERRIDE |
8156dddd |
115 | { |
116 | if (!myCopyMesh) |
117 | return Standard_False; |
118 | |
119 | TopLoc_Location aLoc; |
120 | Handle(Poly_Triangulation) aTria = BRep_Tool::Triangulation(F, aLoc); |
121 | P = BRep_Tool::PolygonOnTriangulation(E, aTria, aLoc); |
122 | |
123 | if (P.IsNull()) |
124 | return Standard_False; |
125 | |
126 | // polygon is copied if and only if the geometry need to be copied too |
127 | if (myCopyGeom) |
128 | P = P->Copy(); |
129 | return Standard_True; |
130 | } |
131 | |
7fd59977 |
132 | //! Returns true to indicate the need to copy vertex |
133 | Standard_Boolean NewPoint (const TopoDS_Vertex& V, gp_Pnt& P, |
79104795 |
134 | Standard_Real& Tol) Standard_OVERRIDE |
7fd59977 |
135 | { |
136 | P = BRep_Tool::Pnt(V); |
137 | Tol = BRep_Tool::Tolerance(V); |
138 | return Standard_True; |
139 | } |
140 | |
141 | //! Returns true to indicate the need to copy edge; |
142 | //! copies pcurve if requested |
35e08fe8 |
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, |
79104795 |
148 | Standard_Real& Tol) Standard_OVERRIDE |
7fd59977 |
149 | { |
150 | Tol = BRep_Tool::Tolerance(E); |
151 | Standard_Real f, l; |
152 | C = BRep_Tool::CurveOnSurface (E, F, f, l); |
153 | |
154 | if ( ! C.IsNull() && myCopyGeom ) |
155 | C = Handle(Geom2d_Curve)::DownCast (C->Copy()); |
156 | |
157 | return Standard_True; |
158 | } |
159 | |
160 | //! Returns true to indicate the need to copy vertex |
161 | Standard_Boolean NewParameter (const TopoDS_Vertex& V, const TopoDS_Edge& E, |
79104795 |
162 | Standard_Real& P, Standard_Real& Tol) Standard_OVERRIDE |
7fd59977 |
163 | { |
164 | if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex |
165 | |
166 | Tol = BRep_Tool::Tolerance(V); |
167 | P = BRep_Tool::Parameter (V, E); |
168 | |
169 | return Standard_True; |
170 | } |
171 | |
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&, |
79104795 |
175 | const TopoDS_Face&, const TopoDS_Face&) Standard_OVERRIDE |
7fd59977 |
176 | { |
177 | return BRep_Tool::Continuity (E, F1, F2); |
178 | } |
179 | |
180 | public: |
92efcf78 |
181 | DEFINE_STANDARD_RTTI_INLINE(BRepBuilderAPI_Copy_Modification,BRepTools_Modification) |
7fd59977 |
182 | |
183 | private: |
184 | Standard_Boolean myCopyGeom; |
55e738d2 |
185 | Standard_Boolean myCopyMesh; |
7fd59977 |
186 | }; |
187 | |
188 | DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification) |
7fd59977 |
189 | |
5c8908e0 |
190 | } // anonymous namespace |
7fd59977 |
191 | |
192 | //======================================================================= |
193 | //function : BRepBuilderAPI_Copy |
194 | //purpose : |
195 | //======================================================================= |
196 | |
197 | BRepBuilderAPI_Copy::BRepBuilderAPI_Copy () |
198 | { |
5c8908e0 |
199 | myModification = new BRepBuilderAPI_Copy_Modification(Standard_True, Standard_False); |
7fd59977 |
200 | } |
201 | |
202 | |
203 | //======================================================================= |
204 | //function : BRepBuilderAPI_Copy |
205 | //purpose : |
206 | //======================================================================= |
207 | |
55e738d2 |
208 | BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh) |
7fd59977 |
209 | { |
55e738d2 |
210 | myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh); |
7fd59977 |
211 | DoModif(S); |
212 | } |
213 | |
214 | |
215 | //======================================================================= |
216 | //function : Perform |
217 | //purpose : |
218 | //======================================================================= |
219 | |
55e738d2 |
220 | void BRepBuilderAPI_Copy::Perform(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh) |
7fd59977 |
221 | { |
55e738d2 |
222 | myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh); |
7fd59977 |
223 | NotDone(); // on force la copie si on vient deja d`en faire une |
224 | DoModif(S); |
225 | } |
226 | |