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.
17 #include <BRepTools_GTrsfModification.ixx>
19 #include <Geom_Plane.hxx>
20 #include <Geom_Line.hxx>
21 #include <Geom_TrimmedCurve.hxx>
22 #include <Geom2d_TrimmedCurve.hxx>
23 #include <Geom_BSplineSurface.hxx>
24 #include <Geom_BezierSurface.hxx>
25 #include <Geom_BSplineCurve.hxx>
26 #include <Geom_BezierCurve.hxx>
27 #include <Standard_Type.hxx>
28 #include <BRep_Tool.hxx>
29 #include <gp_GTrsf2d.hxx>
31 #include <gp_TrsfForm.hxx>
32 #include <Standard_NoSuchObject.hxx>
35 #include <GeomLib.hxx>
38 //=======================================================================
39 //function : BRepTools_GTrsfModification
41 //=======================================================================
43 BRepTools_GTrsfModification::BRepTools_GTrsfModification(const gp_GTrsf& T) :
46 // on prend comme dilatation maximale pour la tolerance la norme sup
47 Standard_Real loc1, loc2, loc3, loc4;
49 loc1 = Max(Abs(T.Value(1,1)), Abs(T.Value(1,2)));
50 loc2 = Max(Abs(T.Value(2,1)), Abs(T.Value(2,2)));
51 loc3 = Max(Abs(T.Value(3,1)), Abs(T.Value(3,2)));
52 loc4 = Max(Abs(T.Value(1,3)), Abs(T.Value(2,3)));
54 loc1 = Max(loc1, loc2);
55 loc2 = Max(loc3, loc4);
57 loc1 = Max(loc1, loc2);
59 myGScale = Max(loc1, Abs(T.Value(3,3)));
63 //=======================================================================
66 //=======================================================================
68 gp_GTrsf& BRepTools_GTrsfModification::GTrsf ()
73 //=======================================================================
74 //function : NewSurface
76 //=======================================================================
78 Standard_Boolean BRepTools_GTrsfModification::NewSurface
79 (const TopoDS_Face& F,
80 Handle(Geom_Surface)& S,
83 Standard_Boolean& RevWires,
84 Standard_Boolean& RevFace)
87 gtrsf.SetVectorialPart(myGTrsf.VectorialPart());
88 gtrsf.SetTranslationPart(myGTrsf.TranslationPart());
89 S = Handle(Geom_Surface)::DownCast(BRep_Tool::Surface(F,L)->Copy());
91 Tol = BRep_Tool::Tolerance(F);
93 RevWires = Standard_False;
94 RevFace = myGTrsf.IsNegative();
95 S = Handle(Geom_Surface)::DownCast(S->Transformed(L.Transformation()));
97 Handle(Standard_Type) TheTypeS = S->DynamicType();
98 if (TheTypeS == STANDARD_TYPE(Geom_BSplineSurface)) {
99 Handle(Geom_BSplineSurface) S2 = Handle(Geom_BSplineSurface)::DownCast(S);
100 for(Standard_Integer i = 1; i <= S2->NbUPoles(); i++)
101 for(Standard_Integer j = 1; j <= S2->NbVPoles(); j++) {
102 gp_XYZ coor(S2->Pole(i, j).Coord());
103 gtrsf.Transforms(coor);
105 S2->SetPole(i, j, P);
109 if (TheTypeS == STANDARD_TYPE(Geom_BezierSurface)) {
110 Handle(Geom_BezierSurface) S2 = Handle(Geom_BezierSurface)::DownCast(S);
111 for(Standard_Integer i = 1; i <= S2->NbUPoles(); i++)
112 for(Standard_Integer j = 1; j <= S2->NbVPoles(); j++) {
113 gp_XYZ coor(S2->Pole(i, j).Coord());
114 gtrsf.Transforms(coor);
116 S2->SetPole(i, j, P);
120 Standard_NoSuchObject::Raise("BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Surface");
124 return Standard_True;
128 //=======================================================================
129 //function : NewCurve
131 //=======================================================================
133 Standard_Boolean BRepTools_GTrsfModification::NewCurve
134 (const TopoDS_Edge& E,
135 Handle(Geom_Curve)& C,
141 gtrsf.SetVectorialPart(myGTrsf.VectorialPart());
142 gtrsf.SetTranslationPart(myGTrsf.TranslationPart());
143 Tol = BRep_Tool::Tolerance(E)*myGScale;
144 C = BRep_Tool::Curve(E, L, f, l);
147 C = Handle(Geom_Curve)::DownCast(C->Copy()->Transformed(L.Transformation()));
148 Handle(Standard_Type) TheTypeC = C->DynamicType();
149 if (TheTypeC == STANDARD_TYPE(Geom_BSplineCurve)) {
150 Handle(Geom_BSplineCurve) C2 = Handle(Geom_BSplineCurve)::DownCast(C);
151 for(Standard_Integer i = 1; i <= C2->NbPoles(); i++) {
152 gp_XYZ coor(C2->Pole(i).Coord());
153 gtrsf.Transforms(coor);
159 if(TheTypeC == STANDARD_TYPE(Geom_BezierCurve)) {
160 Handle(Geom_BezierCurve) C2 = Handle(Geom_BezierCurve)::DownCast(C);
161 for(Standard_Integer i = 1; i <= C2->NbPoles(); i++) {
162 gp_XYZ coor(C2->Pole(i).Coord());
163 gtrsf.Transforms(coor);
169 Standard_NoSuchObject::Raise("BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Curve");
171 C = new Geom_TrimmedCurve(C, f, l);
174 return Standard_True;
177 //=======================================================================
178 //function : NewPoint
180 //=======================================================================
182 Standard_Boolean BRepTools_GTrsfModification::NewPoint
183 (const TopoDS_Vertex& V,
187 gp_Pnt Pnt = BRep_Tool::Pnt(V);
188 Tol = BRep_Tool::Tolerance(V);
190 gp_XYZ coor(Pnt.Coord());
191 myGTrsf.Transforms(coor);
194 return Standard_True;
197 //=======================================================================
198 //function : NewCurve2d
200 //=======================================================================
202 Standard_Boolean BRepTools_GTrsfModification::NewCurve2d
203 (const TopoDS_Edge& E,
204 const TopoDS_Face& F,
207 Handle(Geom2d_Curve)& C,
211 Tol = BRep_Tool::Tolerance(E);
214 C = BRep_Tool::CurveOnSurface(E,F,f,l);
215 C = new Geom2d_TrimmedCurve(C, f, l);
216 return Standard_True;
219 //=======================================================================
220 //function : NewParameter
222 //=======================================================================
224 Standard_Boolean BRepTools_GTrsfModification::NewParameter
225 (const TopoDS_Vertex& V,
226 const TopoDS_Edge& E,
230 Tol = BRep_Tool::Tolerance(V);
232 P = BRep_Tool::Parameter(V,E);
233 return Standard_True;
236 //=======================================================================
237 //function : Continuity
239 //=======================================================================
241 GeomAbs_Shape BRepTools_GTrsfModification::Continuity
242 (const TopoDS_Edge& E,
243 const TopoDS_Face& F1,
244 const TopoDS_Face& F2,
249 return BRep_Tool::Continuity(E,F1,F2);