1 // Created on: 2000-05-25
2 // Created by: data exchange team
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Tool.hxx>
18 #include <Geom2d_Curve.hxx>
19 #include <Geom_Curve.hxx>
20 #include <Geom_Surface.hxx>
22 #include <gp_Pnt2d.hxx>
23 #include <ShapeAnalysis_Edge.hxx>
24 #include <ShapeUpgrade_ClosedEdgeDivide.hxx>
25 #include <ShapeUpgrade_SplitCurve2d.hxx>
26 #include <ShapeUpgrade_SplitCurve3d.hxx>
27 #include <Standard_Type.hxx>
28 #include <TColStd_HSequenceOfReal.hxx>
29 #include <TopoDS_Edge.hxx>
30 #include <TopoDS_Vertex.hxx>
32 //=======================================================================
33 //function : ShapeUpgrade_ClosedEdgeDivide
35 //=======================================================================
36 ShapeUpgrade_ClosedEdgeDivide::ShapeUpgrade_ClosedEdgeDivide():
37 ShapeUpgrade_EdgeDivide()
41 //=======================================================================
44 //=======================================================================
46 Standard_Boolean ShapeUpgrade_ClosedEdgeDivide::Compute(const TopoDS_Edge& anEdge)
49 ShapeAnalysis_Edge sae;
50 TopoDS_Vertex V1 = sae.FirstVertex(anEdge);
51 TopoDS_Vertex V2 = sae.LastVertex(anEdge);
52 if( V1.IsSame(V2) && !BRep_Tool::Degenerated ( anEdge ) ) {
53 const Standard_Integer nbPoints = 23;
54 gp_Pnt pntV = BRep_Tool::Pnt(V1);
55 Standard_Real TolV1 = LimitTolerance( BRep_Tool::Tolerance(V1) );
58 Handle(Geom_Curve) curve3d = BRep_Tool::Curve (anEdge, f, l);
59 myHasCurve3d = !curve3d.IsNull();
60 Standard_Real f2d = 0., l2d = 0.;
61 Handle(Geom2d_Curve) pcurve1;
62 if ( ! myFace.IsNull() ) { // process free edges
63 sae.PCurve (anEdge, myFace, pcurve1, f2d, l2d, Standard_False);
65 myHasCurve2d = !pcurve1.IsNull();
68 Standard_Real maxPar = f, dMax = 0;
69 Standard_Real step = (l-f)/(nbPoints-1);
70 Standard_Real param = f+step;
71 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
72 gp_Pnt curPnt = curve3d->Value(param);
73 Standard_Real dist = pntV.SquareDistance(curPnt);
80 Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = GetSplitCurve3dTool();
81 theSplit3dTool->Init(curve3d,f,l);
83 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
84 values->Append(maxPar);
85 theSplit3dTool->SetSplitValues(values);
86 myKnots3d = theSplit3dTool->SplitValues();
89 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
90 theSplit2dTool->Init(pcurve1,f2d,l2d);
91 myKnots2d = theSplit2dTool->SplitValues();
96 return Standard_False;
100 Handle(Geom_Surface) surf = BRep_Tool::Surface(myFace);
101 Standard_Real maxPar = f2d, dMax = 0;
102 Standard_Real step = (l2d-f2d)/(nbPoints-1);
103 Standard_Real param = f2d+step;
104 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
105 gp_Pnt2d p2d = pcurve1->Value(param);
106 gp_Pnt curPnt = surf->Value(p2d.X(),p2d.Y());
107 Standard_Real dist = pntV.SquareDistance(curPnt);
115 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
116 theSplit2dTool->Init(pcurve1,f2d,l2d);
118 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
119 values->Append(maxPar);
120 theSplit2dTool->SetSplitValues(values);
121 myKnots2d = theSplit2dTool->SplitValues();
122 return Standard_True;
125 return Standard_False;
128 return Standard_False;
132 return Standard_False;