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, |
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 | |
55e738d2 |
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 | |
5c8908e0 |
71 | if (myCopyGeom) |
72 | T = T->Copy(); |
55e738d2 |
73 | return Standard_True; |
74 | } |
75 | |
7fd59977 |
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 |
35e08fe8 |
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) |
7fd59977 |
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: |
ec357c5c |
140 | DEFINE_STANDARD_RTTI(BRepBuilderAPI_Copy_Modification, BRepTools_Modification) |
7fd59977 |
141 | |
142 | private: |
143 | Standard_Boolean myCopyGeom; |
55e738d2 |
144 | Standard_Boolean myCopyMesh; |
7fd59977 |
145 | }; |
146 | |
147 | DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification) |
7fd59977 |
148 | |
5c8908e0 |
149 | } // anonymous namespace |
7fd59977 |
150 | |
151 | //======================================================================= |
152 | //function : BRepBuilderAPI_Copy |
153 | //purpose : |
154 | //======================================================================= |
155 | |
156 | BRepBuilderAPI_Copy::BRepBuilderAPI_Copy () |
157 | { |
5c8908e0 |
158 | myModification = new BRepBuilderAPI_Copy_Modification(Standard_True, Standard_False); |
7fd59977 |
159 | } |
160 | |
161 | |
162 | //======================================================================= |
163 | //function : BRepBuilderAPI_Copy |
164 | //purpose : |
165 | //======================================================================= |
166 | |
55e738d2 |
167 | BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh) |
7fd59977 |
168 | { |
55e738d2 |
169 | myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh); |
7fd59977 |
170 | DoModif(S); |
171 | } |
172 | |
173 | |
174 | //======================================================================= |
175 | //function : Perform |
176 | //purpose : |
177 | //======================================================================= |
178 | |
55e738d2 |
179 | void BRepBuilderAPI_Copy::Perform(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh) |
7fd59977 |
180 | { |
55e738d2 |
181 | myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh); |
7fd59977 |
182 | NotDone(); // on force la copie si on vient deja d`en faire une |
183 | DoModif(S); |
184 | } |
185 | |