1 // Created on: 1996-02-15
2 // Created by: Jacques GOUSSARD
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 <LocOpe_FindEdgesInFace.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAdaptor_Surface.hxx>
21 #include <BRepTopAdaptor_TopolTool.hxx>
24 #include <Geom_Circle.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_CylindricalSurface.hxx>
27 #include <Geom_Line.hxx>
28 #include <Geom_Plane.hxx>
29 #include <Geom_RectangularTrimmedSurface.hxx>
30 #include <Geom_Surface.hxx>
31 #include <Geom_TrimmedCurve.hxx>
32 #include <Precision.hxx>
33 #include <Standard_ConstructionError.hxx>
34 #include <Standard_NoMoreObject.hxx>
35 #include <Standard_NoSuchObject.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopTools_MapOfShape.hxx>
42 //=======================================================================
45 //=======================================================================
46 void LocOpe_FindEdgesInFace::Set(const TopoDS_Shape& Sh,
53 TopTools_MapOfShape M;
54 TopExp_Explorer exp,expf;
56 Handle(Geom_Surface) S;
59 Handle(Standard_Type) Tc,Ts;
60 Standard_Boolean ToAdd;
65 Standard_Real Tol = Precision::Confusion();
66 Standard_Real TolAng = Precision::Angular();
68 S = BRep_Tool::Surface(F);
69 Ts = S->DynamicType();
70 if (Ts == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
71 S = Handle(Geom_RectangularTrimmedSurface)::DownCast(S)->BasisSurface();
72 Ts = S->DynamicType();
75 if (Ts != STANDARD_TYPE(Geom_Plane) && Ts != STANDARD_TYPE(Geom_CylindricalSurface)) {
76 return; // pour le moment
79 Handle(BRepAdaptor_Surface) HS = new BRepAdaptor_Surface(myFace);
80 BRepTopAdaptor_TopolTool TPT(HS);
82 for (exp.Init(myShape,TopAbs_EDGE); exp.More(); exp.Next()) {
83 ToAdd = Standard_False;
84 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
85 if (M.Contains(edg)) {
89 for (expf.Init(myFace,TopAbs_EDGE); expf.More();expf.Next()) {
90 if (expf.Current().IsSame(edg)) {
94 if (expf.More()) { // partage d`edge
100 C = BRep_Tool::Curve(edg,Loc,f,l);
101 C = Handle(Geom_Curve)::DownCast(C->Transformed(Loc.Transformation()));
102 Tc = C->DynamicType();
103 if (Tc == STANDARD_TYPE(Geom_TrimmedCurve)) {
104 C = Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve();
105 Tc = C->DynamicType();
107 if (Tc != STANDARD_TYPE(Geom_Line) && Tc != STANDARD_TYPE(Geom_Circle)) {
108 continue; // pour le moment
110 if (Ts == STANDARD_TYPE(Geom_Plane)) {
111 pl = Handle(Geom_Plane)::DownCast(S)->Pln();
114 cy = Handle(Geom_CylindricalSurface)::DownCast(S)->Cylinder();
117 if (Tc == STANDARD_TYPE(Geom_Line)) {
118 gp_Lin li = Handle(Geom_Line)::DownCast(C)->Lin();
119 if (Ts == STANDARD_TYPE(Geom_Plane)) {
120 if (pl.Contains(li,Tol,TolAng)) {
121 ToAdd = Standard_True;
124 else { //Ts == STANDARD_TYPE(Geom_CylindricalSurface)
125 if (cy.Axis().IsParallel(li.Position(),TolAng) &&
126 Abs(li.Distance(cy.Location())-cy.Radius()) < Tol) {
127 ToAdd = Standard_True;
131 else { // Tt == STANDARD_TYPE(Geom_Circle)
132 gp_Circ ci = Handle(Geom_Circle)::DownCast(C)->Circ();
133 if (Ts == STANDARD_TYPE(Geom_Plane)) {
134 if (pl.Position().IsCoplanar(ci.Position(),Tol,TolAng)) {
135 ToAdd = Standard_True;
139 if (Abs(cy.Radius()-ci.Radius()) < Tol &&
140 cy.Axis().IsCoaxial(ci.Axis(),TolAng,Tol)) {
141 ToAdd = Standard_True;
147 // On classifie 3 points.
152 p[2] = C->Value((f+l)/2.);
153 // for (Standard_Integer i=0; i<3; i++) {
155 for ( i=0; i<3; i++) {
156 if (Ts == STANDARD_TYPE(Geom_Plane)) {
157 ElSLib::Parameters(pl,p[i],U,V);
160 ElSLib::Parameters(cy,p[i],U,V);
162 if (TPT.Classify(gp_Pnt2d(U,V),Precision::Confusion())== TopAbs_OUT) {