0031587: Modeling Data - add BRepTools::RemoveInternals() removing internal sub-shape...
[occt.git] / src / BRepTools / BRepTools_GTrsfModification.cxx
CommitLineData
b311480e 1// Created on: 1996-12-30
2// Created by: Stagiaire Mary FABIEN
3// Copyright (c) 1996-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
42cf5bc1 18#include <BRep_Tool.hxx>
19#include <BRepTools_GTrsfModification.hxx>
20#include <Geom2d_Curve.hxx>
7fd59977 21#include <Geom2d_TrimmedCurve.hxx>
42cf5bc1 22#include <Geom_BezierCurve.hxx>
7fd59977 23#include <Geom_BezierSurface.hxx>
24#include <Geom_BSplineCurve.hxx>
42cf5bc1 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>
7fd59977 34#include <gp_GTrsf2d.hxx>
42cf5bc1 35#include <gp_Pnt.hxx>
7fd59977 36#include <gp_TrsfForm.hxx>
42cf5bc1 37#include <gp_XYZ.hxx>
7fd59977 38#include <Standard_NoSuchObject.hxx>
42cf5bc1 39#include <Standard_Type.hxx>
7fd59977 40#include <TopAbs.hxx>
42cf5bc1 41#include <TopLoc_Location.hxx>
42#include <TopoDS_Edge.hxx>
43#include <TopoDS_Face.hxx>
44#include <TopoDS_Vertex.hxx>
7fd59977 45
92efcf78 46IMPLEMENT_STANDARD_RTTIEXT(BRepTools_GTrsfModification,BRepTools_Modification)
47
7fd59977 48//=======================================================================
49//function : BRepTools_GTrsfModification
50//purpose :
51//=======================================================================
7fd59977 52BRepTools_GTrsfModification::BRepTools_GTrsfModification(const gp_GTrsf& T) :
53myGTrsf(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
77gp_GTrsf& BRepTools_GTrsfModification::GTrsf ()
78{
79 return myGTrsf;
80}
81
82//=======================================================================
83//function : NewSurface
84//purpose :
85//=======================================================================
86
87Standard_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 }
3ed30348 128 else{
9775fa61 129 throw Standard_NoSuchObject("BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Surface");
3ed30348 130 }
7fd59977 131
132 L.Identity();
133 return Standard_True;
134}
135
136
137//=======================================================================
138//function : NewCurve
139//purpose :
140//=======================================================================
141
142Standard_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 }
3ed30348 177 else {
9775fa61 178 throw Standard_NoSuchObject("BRepTools_GTrsfModification : Pb no BSpline/Bezier Type Curve");
3ed30348 179 }
7fd59977 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
191Standard_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
211Standard_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
233Standard_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
250GeomAbs_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