b311480e |
1 | // Created on: 1994-12-12 |
2 | // Created by: Jacques GOUSSARD |
3 | // Copyright (c) 1994-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | |
23 | #include <BRepBuilderAPI_Copy.ixx> |
24 | |
25 | #include <Geom_Surface.hxx> |
26 | #include <Geom_Curve.hxx> |
27 | #include <Geom2d_Curve.hxx> |
28 | #include <BRepTools_Modification.hxx> |
29 | #include <BRep_Tool.hxx> |
30 | #include <TopoDS_Vertex.hxx> |
31 | #include <gp_Pnt.hxx> |
32 | |
33 | //! Tool class implementing necessary functionality for copying geometry |
34 | class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification |
35 | { |
36 | public: |
37 | BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom) |
38 | : myCopyGeom(copyGeom) |
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 edge; |
59 | //! copies curves if requested |
60 | Standard_Boolean NewCurve (const TopoDS_Edge& E, Handle(Geom_Curve)& C, |
61 | TopLoc_Location& L, Standard_Real& Tol) |
62 | { |
63 | Standard_Real f,l; |
64 | C = BRep_Tool::Curve (E, L, f, l); |
65 | Tol = BRep_Tool::Tolerance(E); |
66 | |
67 | if ( ! C.IsNull() && myCopyGeom ) |
68 | C = Handle(Geom_Curve)::DownCast(C->Copy()); |
69 | |
70 | return Standard_True; |
71 | } |
72 | |
73 | //! Returns true to indicate the need to copy vertex |
74 | Standard_Boolean NewPoint (const TopoDS_Vertex& V, gp_Pnt& P, |
75 | Standard_Real& Tol) |
76 | { |
77 | P = BRep_Tool::Pnt(V); |
78 | Tol = BRep_Tool::Tolerance(V); |
79 | return Standard_True; |
80 | } |
81 | |
82 | //! Returns true to indicate the need to copy edge; |
83 | //! copies pcurve if requested |
84 | Standard_Boolean NewCurve2d (const TopoDS_Edge& E, const TopoDS_Face& F, |
85 | const TopoDS_Edge& NewE, const TopoDS_Face& NewF, |
86 | Handle(Geom2d_Curve)& C, Standard_Real& Tol) |
87 | { |
88 | Tol = BRep_Tool::Tolerance(E); |
89 | Standard_Real f, l; |
90 | C = BRep_Tool::CurveOnSurface (E, F, f, l); |
91 | |
92 | if ( ! C.IsNull() && myCopyGeom ) |
93 | C = Handle(Geom2d_Curve)::DownCast (C->Copy()); |
94 | |
95 | return Standard_True; |
96 | } |
97 | |
98 | //! Returns true to indicate the need to copy vertex |
99 | Standard_Boolean NewParameter (const TopoDS_Vertex& V, const TopoDS_Edge& E, |
100 | Standard_Real& P, Standard_Real& Tol) |
101 | { |
102 | if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex |
103 | |
104 | Tol = BRep_Tool::Tolerance(V); |
105 | P = BRep_Tool::Parameter (V, E); |
106 | |
107 | return Standard_True; |
108 | } |
109 | |
110 | //! Returns the continuity of E between F1 and F2 |
111 | GeomAbs_Shape Continuity (const TopoDS_Edge& E, const TopoDS_Face& F1, |
112 | const TopoDS_Face& F2, const TopoDS_Edge&, |
113 | const TopoDS_Face&, const TopoDS_Face&) |
114 | { |
115 | return BRep_Tool::Continuity (E, F1, F2); |
116 | } |
117 | |
118 | public: |
119 | DEFINE_STANDARD_RTTI(BRepBuilderAPI_Copy_Modification) |
120 | |
121 | private: |
122 | Standard_Boolean myCopyGeom; |
123 | }; |
124 | |
125 | DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification) |
126 | IMPLEMENT_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification) |
127 | |
128 | IMPLEMENT_STANDARD_RTTIEXT(BRepBuilderAPI_Copy_Modification, BRepTools_Modification) |
129 | |
130 | //======================================================================= |
131 | //function : BRepBuilderAPI_Copy |
132 | //purpose : |
133 | //======================================================================= |
134 | |
135 | BRepBuilderAPI_Copy::BRepBuilderAPI_Copy () |
136 | { |
137 | myModification = new BRepBuilderAPI_Copy_Modification(Standard_True); |
138 | } |
139 | |
140 | |
141 | //======================================================================= |
142 | //function : BRepBuilderAPI_Copy |
143 | //purpose : |
144 | //======================================================================= |
145 | |
146 | BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom) |
147 | { |
148 | myModification = new BRepBuilderAPI_Copy_Modification(copyGeom); |
149 | DoModif(S); |
150 | } |
151 | |
152 | |
153 | //======================================================================= |
154 | //function : Perform |
155 | //purpose : |
156 | //======================================================================= |
157 | |
158 | void BRepBuilderAPI_Copy::Perform(const TopoDS_Shape& S, const Standard_Boolean copyGeom) |
159 | { |
160 | myModification = new BRepBuilderAPI_Copy_Modification(copyGeom); |
161 | NotDone(); // on force la copie si on vient deja d`en faire une |
162 | DoModif(S); |
163 | } |
164 | |