1 // Created on: 1996-12-30
2 // Created by: Stagiaire Mary FABIEN
3 // Copyright (c) 1996-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.
18 #include <BRep_Tool.hxx>
19 #include <BRepTools_GTrsfModification.hxx>
20 #include <Geom2d_Curve.hxx>
21 #include <Geom2d_TrimmedCurve.hxx>
22 #include <Geom_BezierCurve.hxx>
23 #include <Geom_BezierSurface.hxx>
24 #include <Geom_BSplineCurve.hxx>
25 #include <Geom_BSplineSurface.hxx>
26 #include <Geom_Curve.hxx>
27 #include <Geom_Line.hxx>
28 #include <Geom_Plane.hxx>
29 #include <Geom_Surface.hxx>
30 #include <Geom_TrimmedCurve.hxx>
31 #include <GeomLib.hxx>
33 #include <gp_GTrsf.hxx>
34 #include <gp_GTrsf2d.hxx>
36 #include <gp_TrsfForm.hxx>
38 #include <Standard_NoSuchObject.hxx>
39 #include <Standard_Type.hxx>
41 #include <TopLoc_Location.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TopoDS_Vertex.hxx>
46 IMPLEMENT_STANDARD_RTTIEXT(BRepTools_GTrsfModification,BRepTools_Modification)
48 //=======================================================================
49 //function : BRepTools_GTrsfModification
51 //=======================================================================
52 BRepTools_GTrsfModification::BRepTools_GTrsfModification(const gp_GTrsf& T) :
55 // on prend comme dilatation maximale pour la tolerance la norme sup
56 Standard_Real loc1, loc2, loc3, loc4;
58 loc1 = Max(Abs(T.Value(1,1)), Abs(T.Value(1,2)));
59 loc2 = Max(Abs(T.Value(2,1)), Abs(T.Value(2,2)));
60 loc3 = Max(Abs(T.Value(3,1)), Abs(T.Value(3,2)));
61 loc4 = Max(Abs(T.Value(1,3)), Abs(T.Value(2,3)));
63 loc1 = Max(loc1, loc2);
64 loc2 = Max(loc3, loc4);
66 loc1 = Max(loc1, loc2);
68 myGScale = Max(loc1, Abs(T.Value(3,3)));
72 //=======================================================================
75 //=======================================================================
77 gp_GTrsf& BRepTools_GTrsfModification::GTrsf ()
82 //=======================================================================
83 //function : NewSurface
85 //=======================================================================
87 Standard_Boolean BRepTools_GTrsfModification::NewSurface
88 (const TopoDS_Face& F,
89 Handle(Geom_Surface)& S,
92 Standard_Boolean& RevWires,
93 Standard_Boolean& RevFace)
96 gtrsf.SetVectorialPart(myGTrsf.VectorialPart());
97 gtrsf.SetTranslationPart(myGTrsf.TranslationPart());
98 S = Handle(Geom_Surface)::DownCast(BRep_Tool::Surface(F,L)->Copy());
100 Tol = BRep_Tool::Tolerance(F);
102 RevWires = Standard_False;
103 RevFace = myGTrsf.IsNegative();
104 S = Handle(Geom_Surface)::DownCast(S->Transformed(L.Transformation()));
106 Handle(Standard_Type) TheTypeS = S->DynamicType();
107 if (TheTypeS == STANDARD_TYPE(Geom_BSplineSurface)) {
108 Handle(Geom_BSplineSurface) S2 = Handle(Geom_BSplineSurface)::DownCast(S);
109 for(Standard_Integer i = 1; i <= S2->NbUPoles(); i++)
110 for(Standard_Integer j = 1; j <= S2->NbVPoles(); j++) {
111 gp_XYZ coor(S2->Pole(i, j).Coord());
112 gtrsf.Transforms(coor);
114 S2->SetPole(i, j, P);
118 if (TheTypeS == STANDARD_TYPE(Geom_BezierSurface)) {
119 Handle(Geom_BezierSurface) S2 = Handle(Geom_BezierSurface)::DownCast(S);
120 for(Standard_Integer i = 1; i <= S2->NbUPoles(); i++)
121 for(Standard_Integer j = 1; j <= S2->NbVPoles(); j++) {
122 gp_XYZ coor(S2->Pole(i, j).Coord());
123 gtrsf.Transforms(coor);
125 S2->SetPole(i, j, P);
129 throw Standard_NoSuchObject("BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Surface");
133 return Standard_True;
137 //=======================================================================
138 //function : NewCurve
140 //=======================================================================
142 Standard_Boolean BRepTools_GTrsfModification::NewCurve
143 (const TopoDS_Edge& E,
144 Handle(Geom_Curve)& C,
150 gtrsf.SetVectorialPart(myGTrsf.VectorialPart());
151 gtrsf.SetTranslationPart(myGTrsf.TranslationPart());
152 Tol = BRep_Tool::Tolerance(E)*myGScale;
153 C = BRep_Tool::Curve(E, L, f, l);
156 C = Handle(Geom_Curve)::DownCast(C->Copy()->Transformed(L.Transformation()));
157 Handle(Standard_Type) TheTypeC = C->DynamicType();
158 if (TheTypeC == STANDARD_TYPE(Geom_BSplineCurve)) {
159 Handle(Geom_BSplineCurve) C2 = Handle(Geom_BSplineCurve)::DownCast(C);
160 for(Standard_Integer i = 1; i <= C2->NbPoles(); i++) {
161 gp_XYZ coor(C2->Pole(i).Coord());
162 gtrsf.Transforms(coor);
168 if(TheTypeC == STANDARD_TYPE(Geom_BezierCurve)) {
169 Handle(Geom_BezierCurve) C2 = Handle(Geom_BezierCurve)::DownCast(C);
170 for(Standard_Integer i = 1; i <= C2->NbPoles(); i++) {
171 gp_XYZ coor(C2->Pole(i).Coord());
172 gtrsf.Transforms(coor);
178 throw Standard_NoSuchObject("BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Curve");
180 C = new Geom_TrimmedCurve(C, f, l);
183 return Standard_True;
186 //=======================================================================
187 //function : NewPoint
189 //=======================================================================
191 Standard_Boolean BRepTools_GTrsfModification::NewPoint
192 (const TopoDS_Vertex& V,
196 gp_Pnt Pnt = BRep_Tool::Pnt(V);
197 Tol = BRep_Tool::Tolerance(V);
199 gp_XYZ coor(Pnt.Coord());
200 myGTrsf.Transforms(coor);
203 return Standard_True;
206 //=======================================================================
207 //function : NewCurve2d
209 //=======================================================================
211 Standard_Boolean BRepTools_GTrsfModification::NewCurve2d
212 (const TopoDS_Edge& E,
213 const TopoDS_Face& F,
216 Handle(Geom2d_Curve)& C,
220 Tol = BRep_Tool::Tolerance(E);
223 C = BRep_Tool::CurveOnSurface(E,F,f,l);
224 C = new Geom2d_TrimmedCurve(C, f, l);
225 return Standard_True;
228 //=======================================================================
229 //function : NewParameter
231 //=======================================================================
233 Standard_Boolean BRepTools_GTrsfModification::NewParameter
234 (const TopoDS_Vertex& V,
235 const TopoDS_Edge& E,
239 Tol = BRep_Tool::Tolerance(V);
241 P = BRep_Tool::Parameter(V,E);
242 return Standard_True;
245 //=======================================================================
246 //function : Continuity
248 //=======================================================================
250 GeomAbs_Shape BRepTools_GTrsfModification::Continuity
251 (const TopoDS_Edge& E,
252 const TopoDS_Face& F1,
253 const TopoDS_Face& F2,
258 return BRep_Tool::Continuity(E,F1,F2);