1 // Created on: 1994-08-25
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1994-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_TrsfModification.ixx>
19 #include <Geom_Line.hxx>
20 #include <Geom_TrimmedCurve.hxx>
21 #include <Geom2d_TrimmedCurve.hxx>
22 #include <BRep_Tool.hxx>
23 #include <gp_GTrsf2d.hxx>
24 #include <gp_TrsfForm.hxx>
27 #include <GeomLib.hxx>
32 #include <Precision.hxx>
33 #include <GeomAdaptor_Surface.hxx>
35 //=======================================================================
36 //function : BRepTools_TrsfModification
38 //=======================================================================
40 BRepTools_TrsfModification::BRepTools_TrsfModification(const gp_Trsf& T) :
46 //=======================================================================
49 //=======================================================================
51 gp_Trsf& BRepTools_TrsfModification::Trsf ()
56 //=======================================================================
57 //function : NewSurface
59 //=======================================================================
61 Standard_Boolean BRepTools_TrsfModification::NewSurface
62 (const TopoDS_Face& F,
63 Handle(Geom_Surface)& S,
66 Standard_Boolean& RevWires,
67 Standard_Boolean& RevFace)
69 S = BRep_Tool::Surface(F,L);
70 Tol = BRep_Tool::Tolerance(F);
71 Tol *= Abs(myTrsf.ScaleFactor());
72 RevWires = Standard_False;
73 RevFace = myTrsf.IsNegative();
75 gp_Trsf LT = L.Transformation();
78 LT.Multiply(L.Transformation());
80 S = Handle(Geom_Surface)::DownCast(S->Transformed(LT));
86 //=======================================================================
89 //=======================================================================
91 Standard_Boolean BRepTools_TrsfModification::NewCurve
92 (const TopoDS_Edge& E,
93 Handle(Geom_Curve)& C,
98 C = BRep_Tool::Curve(E,L,f,l);
100 Tol = BRep_Tool::Tolerance(E);
101 Tol *= Abs(myTrsf.ScaleFactor());
103 gp_Trsf LT = L.Transformation();
106 LT.Multiply(L.Transformation());
109 C = Handle(Geom_Curve)::DownCast(C->Transformed(LT));
112 return Standard_True;
115 //=======================================================================
116 //function : NewPoint
118 //=======================================================================
120 Standard_Boolean BRepTools_TrsfModification::NewPoint
121 (const TopoDS_Vertex& V,
125 P = BRep_Tool::Pnt(V);
126 Tol = BRep_Tool::Tolerance(V);
127 Tol *= Abs(myTrsf.ScaleFactor());
130 return Standard_True;
133 //=======================================================================
134 //function : NewCurve2d
136 //=======================================================================
138 Standard_Boolean BRepTools_TrsfModification::NewCurve2d
139 (const TopoDS_Edge& E,
140 const TopoDS_Face& F,
143 Handle(Geom2d_Curve)& C,
147 Tol = BRep_Tool::Tolerance(E);
148 Standard_Real scale = myTrsf.ScaleFactor();
150 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,loc);
151 GeomAdaptor_Surface GAsurf(S);
152 if (GAsurf.GetType() == GeomAbs_Plane)
153 return Standard_False;
156 Handle(Geom2d_Curve) NewC = BRep_Tool::CurveOnSurface(E,F,f,l);
158 return Standard_False;
160 Standard_Real newf,newl;
162 Handle(Standard_Type) TheType = NewC->DynamicType();
164 if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
165 Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(NewC);
166 NewC = TC->BasisCurve();
169 Standard_Real fc = NewC->FirstParameter(), lc = NewC->LastParameter();
171 if(!NewC->IsPeriodic()) {
172 if(fc - f > Precision::PConfusion()) f = fc;
173 if(l - lc > Precision::PConfusion()) l = lc;
178 if (Abs(scale) != 1.) {
180 NewC = new Geom2d_TrimmedCurve(NewC,f,l);
181 gp_GTrsf2d gtrsf = S->ParametricTransformation(myTrsf);
183 if ( gtrsf.Form() != gp_Identity) {
184 NewC = GeomLib::GTransform(NewC,gtrsf);
186 Standard_DomainError::Raise("TrsfModification:Error in NewCurve2d");
187 return Standard_False;
189 newf = NewC->FirstParameter();
190 newl = NewC->LastParameter();
193 // il faut parfois recadrer les ranges 3d / 2d
194 TopoDS_Vertex V1, V2;
195 TopExp::Vertices(E,V1,V2);
196 TopoDS_Shape initEFOR = E.Oriented(TopAbs_FORWARD); // skl
197 TopoDS_Edge EFOR = TopoDS::Edge(initEFOR/*E.Oriented(TopAbs_FORWARD)*/); //skl
198 NewParameter(V1,EFOR,f,Tol);
199 NewParameter(V2,EFOR,l,Tol);
200 GeomLib::SameRange(Tol,NewC,newf,newl,f,l,C);
202 return Standard_True;
205 //=======================================================================
206 //function : NewParameter
208 //=======================================================================
210 Standard_Boolean BRepTools_TrsfModification::NewParameter
211 (const TopoDS_Vertex& V,
212 const TopoDS_Edge& E,
216 if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex
219 Tol = BRep_Tool::Tolerance(V);
220 Tol *= Abs(myTrsf.ScaleFactor());
221 P = BRep_Tool::Parameter(V,E);
225 Handle(Geom_Curve) C = BRep_Tool::Curve(E,loc,f,l);
227 P = C->TransformedParameter(P,myTrsf);
230 return Standard_True;
233 //=======================================================================
234 //function : Continuity
236 //=======================================================================
238 GeomAbs_Shape BRepTools_TrsfModification::Continuity
239 (const TopoDS_Edge& E,
240 const TopoDS_Face& F1,
241 const TopoDS_Face& F2,
246 return BRep_Tool::Continuity(E,F1,F2);