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.
18 #include <BRep_Tool.hxx>
19 #include <BRepTools_TrsfModification.hxx>
20 #include <Geom2d_Curve.hxx>
21 #include <Geom2d_TrimmedCurve.hxx>
22 #include <Geom_Curve.hxx>
23 #include <Geom_Line.hxx>
24 #include <Geom_Surface.hxx>
25 #include <Geom_TrimmedCurve.hxx>
26 #include <GeomAdaptor_Surface.hxx>
27 #include <GeomLib.hxx>
29 #include <gp_GTrsf2d.hxx>
31 #include <gp_Trsf.hxx>
32 #include <gp_TrsfForm.hxx>
33 #include <Precision.hxx>
34 #include <Standard_Type.hxx>
37 #include <TopLoc_Location.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Vertex.hxx>
43 IMPLEMENT_STANDARD_RTTIEXT(BRepTools_TrsfModification,BRepTools_Modification)
45 //=======================================================================
46 //function : BRepTools_TrsfModification
48 //=======================================================================
49 BRepTools_TrsfModification::BRepTools_TrsfModification(const gp_Trsf& T) :
55 //=======================================================================
58 //=======================================================================
60 gp_Trsf& BRepTools_TrsfModification::Trsf ()
65 //=======================================================================
66 //function : NewSurface
68 //=======================================================================
70 Standard_Boolean BRepTools_TrsfModification::NewSurface
71 (const TopoDS_Face& F,
72 Handle(Geom_Surface)& S,
75 Standard_Boolean& RevWires,
76 Standard_Boolean& RevFace)
78 S = BRep_Tool::Surface(F,L);
79 Tol = BRep_Tool::Tolerance(F);
80 Tol *= Abs(myTrsf.ScaleFactor());
81 RevWires = Standard_False;
82 RevFace = myTrsf.IsNegative();
84 gp_Trsf LT = L.Transformation();
87 LT.Multiply(L.Transformation());
89 S = Handle(Geom_Surface)::DownCast(S->Transformed(LT));
95 //=======================================================================
98 //=======================================================================
100 Standard_Boolean BRepTools_TrsfModification::NewCurve
101 (const TopoDS_Edge& E,
102 Handle(Geom_Curve)& C,
107 C = BRep_Tool::Curve(E,L,f,l);
109 Tol = BRep_Tool::Tolerance(E);
110 Tol *= Abs(myTrsf.ScaleFactor());
112 gp_Trsf LT = L.Transformation();
115 LT.Multiply(L.Transformation());
118 C = Handle(Geom_Curve)::DownCast(C->Transformed(LT));
121 return Standard_True;
124 //=======================================================================
125 //function : NewPoint
127 //=======================================================================
129 Standard_Boolean BRepTools_TrsfModification::NewPoint
130 (const TopoDS_Vertex& V,
134 P = BRep_Tool::Pnt(V);
135 Tol = BRep_Tool::Tolerance(V);
136 Tol *= Abs(myTrsf.ScaleFactor());
139 return Standard_True;
142 //=======================================================================
143 //function : NewCurve2d
145 //=======================================================================
147 Standard_Boolean BRepTools_TrsfModification::NewCurve2d
148 (const TopoDS_Edge& E,
149 const TopoDS_Face& F,
152 Handle(Geom2d_Curve)& C,
156 Tol = BRep_Tool::Tolerance(E);
157 Standard_Real scale = myTrsf.ScaleFactor();
159 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,loc);
160 GeomAdaptor_Surface GAsurf(S);
161 if (GAsurf.GetType() == GeomAbs_Plane)
162 return Standard_False;
165 Handle(Geom2d_Curve) NewC = BRep_Tool::CurveOnSurface(E,F,f,l);
167 return Standard_False;
169 Standard_Real newf,newl;
171 Handle(Standard_Type) TheType = NewC->DynamicType();
173 if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
174 Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(NewC);
175 NewC = TC->BasisCurve();
178 Standard_Real fc = NewC->FirstParameter(), lc = NewC->LastParameter();
180 if(!NewC->IsPeriodic()) {
181 if(fc - f > Precision::PConfusion()) f = fc;
182 if(l - lc > Precision::PConfusion()) l = lc;
183 if(Abs(l - f) < Precision::PConfusion())
185 if(Abs(f - fc) < Precision::PConfusion())
198 if (Abs(scale) != 1.) {
200 NewC = new Geom2d_TrimmedCurve(NewC,f,l);
201 gp_GTrsf2d gtrsf = S->ParametricTransformation(myTrsf);
203 if ( gtrsf.Form() != gp_Identity) {
204 NewC = GeomLib::GTransform(NewC,gtrsf);
206 throw Standard_DomainError("TrsfModification:Error in NewCurve2d");
208 newf = NewC->FirstParameter();
209 newl = NewC->LastParameter();
212 // il faut parfois recadrer les ranges 3d / 2d
213 TopoDS_Vertex V1, V2;
214 TopExp::Vertices(E,V1,V2);
215 TopoDS_Shape initEFOR = E.Oriented(TopAbs_FORWARD); // skl
216 TopoDS_Edge EFOR = TopoDS::Edge(initEFOR/*E.Oriented(TopAbs_FORWARD)*/); //skl
218 NewParameter(V1, EFOR, f, aTolV);
219 NewParameter(V2, EFOR, l, aTolV);
220 GeomLib::SameRange(Precision::PConfusion(), NewC, newf, newl, f, l, C);
222 return Standard_True;
225 //=======================================================================
226 //function : NewParameter
228 //=======================================================================
230 Standard_Boolean BRepTools_TrsfModification::NewParameter
231 (const TopoDS_Vertex& V,
232 const TopoDS_Edge& E,
236 if (V.IsNull()) return Standard_False; // infinite edge may have Null vertex
239 Tol = BRep_Tool::Tolerance(V);
240 Tol *= Abs(myTrsf.ScaleFactor());
241 P = BRep_Tool::Parameter(V,E);
245 Handle(Geom_Curve) C = BRep_Tool::Curve(E,loc,f,l);
247 P = C->TransformedParameter(P,myTrsf);
250 return Standard_True;
253 //=======================================================================
254 //function : Continuity
256 //=======================================================================
258 GeomAbs_Shape BRepTools_TrsfModification::Continuity
259 (const TopoDS_Edge& E,
260 const TopoDS_Face& F1,
261 const TopoDS_Face& F2,
266 return BRep_Tool::Continuity(E,F1,F2);