Warnings on vc14 were eliminated
[occt.git] / src / BRepTools / BRepTools_GTrsfModification.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
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>
32 #include <gp.hxx>
33 #include <gp_GTrsf.hxx>
34 #include <gp_GTrsf2d.hxx>
35 #include <gp_Pnt.hxx>
36 #include <gp_TrsfForm.hxx>
37 #include <gp_XYZ.hxx>
38 #include <Standard_NoSuchObject.hxx>
39 #include <Standard_Type.hxx>
40 #include <TopAbs.hxx>
41 #include <TopLoc_Location.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TopoDS_Vertex.hxx>
45
46 IMPLEMENT_STANDARD_RTTIEXT(BRepTools_GTrsfModification,BRepTools_Modification)
47
48 //=======================================================================
49 //function : BRepTools_GTrsfModification
50 //purpose  : 
51 //=======================================================================
52 BRepTools_GTrsfModification::BRepTools_GTrsfModification(const gp_GTrsf& T) :
53 myGTrsf(T)
54 {
55   // on prend comme dilatation maximale pour la tolerance la norme sup
56   Standard_Real loc1, loc2, loc3, loc4;
57
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)));
62
63   loc1 = Max(loc1, loc2);
64   loc2 = Max(loc3, loc4);
65
66   loc1 = Max(loc1, loc2);
67
68   myGScale = Max(loc1, Abs(T.Value(3,3)));
69 }
70
71
72 //=======================================================================
73 //function : GTrsf
74 //purpose  : 
75 //=======================================================================
76
77 gp_GTrsf& BRepTools_GTrsfModification::GTrsf ()
78 {
79   return myGTrsf;
80 }
81
82 //=======================================================================
83 //function : NewSurface
84 //purpose  : 
85 //=======================================================================
86
87 Standard_Boolean BRepTools_GTrsfModification::NewSurface
88       (const TopoDS_Face& F,
89        Handle(Geom_Surface)& S,
90        TopLoc_Location& L,
91        Standard_Real& Tol,
92        Standard_Boolean& RevWires,
93        Standard_Boolean& RevFace)
94 {
95   gp_GTrsf gtrsf;
96   gtrsf.SetVectorialPart(myGTrsf.VectorialPart());
97   gtrsf.SetTranslationPart(myGTrsf.TranslationPart());
98   S = Handle(Geom_Surface)::DownCast(BRep_Tool::Surface(F,L)->Copy());
99
100   Tol = BRep_Tool::Tolerance(F);
101   Tol *= myGScale;
102   RevWires = Standard_False;
103   RevFace = myGTrsf.IsNegative();
104   S = Handle(Geom_Surface)::DownCast(S->Transformed(L.Transformation()));
105   
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);
113         gp_Pnt P(coor);
114         S2->SetPole(i, j, P);
115       }
116   }
117   else
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);
124           gp_Pnt P(coor);
125           S2->SetPole(i, j, P);
126         }
127     }
128     else{
129       throw Standard_NoSuchObject("BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Surface");
130     }
131
132   L.Identity();
133   return Standard_True;
134 }
135
136
137 //=======================================================================
138 //function : NewCurve
139 //purpose  : 
140 //=======================================================================
141
142 Standard_Boolean BRepTools_GTrsfModification::NewCurve
143 (const TopoDS_Edge& E, 
144  Handle(Geom_Curve)& C,
145  TopLoc_Location& L, 
146  Standard_Real& Tol)
147 {
148   Standard_Real f,l;
149   gp_GTrsf gtrsf;
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);
154   
155   if (!C.IsNull()) {
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);
163         gp_Pnt P(coor);
164         C2->SetPole(i, P);
165       }
166     }
167     else
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);
173           gp_Pnt P(coor);
174           C2->SetPole(i, P);
175         }
176       }
177       else {
178         throw Standard_NoSuchObject("BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Curve");
179       }
180     C = new Geom_TrimmedCurve(C, f, l);
181   }
182   L.Identity() ;  
183   return Standard_True;
184 }
185
186 //=======================================================================
187 //function : NewPoint
188 //purpose  : 
189 //=======================================================================
190
191 Standard_Boolean BRepTools_GTrsfModification::NewPoint
192 (const TopoDS_Vertex& V, 
193  gp_Pnt& P, 
194  Standard_Real& Tol)
195 {
196   gp_Pnt Pnt = BRep_Tool::Pnt(V);
197   Tol = BRep_Tool::Tolerance(V);
198   Tol *= myGScale;
199   gp_XYZ coor(Pnt.Coord());
200   myGTrsf.Transforms(coor);
201   P.SetXYZ(coor);
202
203   return Standard_True;
204 }
205
206 //=======================================================================
207 //function : NewCurve2d
208 //purpose  : 
209 //=======================================================================
210
211 Standard_Boolean BRepTools_GTrsfModification::NewCurve2d
212     (const TopoDS_Edge& E, 
213      const TopoDS_Face& F, 
214      const TopoDS_Edge&, 
215      const TopoDS_Face&, 
216      Handle(Geom2d_Curve)& C,
217      Standard_Real& Tol)
218 {
219   TopLoc_Location loc;
220   Tol = BRep_Tool::Tolerance(E);
221   Tol *= myGScale;
222   Standard_Real f,l;
223   C = BRep_Tool::CurveOnSurface(E,F,f,l);
224   C = new Geom2d_TrimmedCurve(C, f, l);
225   return Standard_True;
226 }
227
228 //=======================================================================
229 //function : NewParameter
230 //purpose  : 
231 //=======================================================================
232
233 Standard_Boolean BRepTools_GTrsfModification::NewParameter
234    (const TopoDS_Vertex& V, 
235     const TopoDS_Edge& E, 
236     Standard_Real& P, 
237     Standard_Real& Tol)
238 {
239   Tol = BRep_Tool::Tolerance(V);
240   Tol *= myGScale;
241   P = BRep_Tool::Parameter(V,E);
242   return Standard_True;
243 }
244
245 //=======================================================================
246 //function : Continuity
247 //purpose  : 
248 //=======================================================================
249
250 GeomAbs_Shape BRepTools_GTrsfModification::Continuity
251   (const TopoDS_Edge& E,
252    const TopoDS_Face& F1,
253    const TopoDS_Face& F2,
254    const TopoDS_Edge&,
255    const TopoDS_Face&,
256    const TopoDS_Face&)
257 {
258   return BRep_Tool::Continuity(E,F1,F2);
259 }
260
261