0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / BRepLib / BRepLib_CheckCurveOnSurface.cxx
1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <BRep_Tool.hxx>
16 #include <BRepLib_CheckCurveOnSurface.hxx>
17 #include <Geom_Surface.hxx>
18 #include <Standard_ErrorHandler.hxx>
19 #include <TopoDS.hxx>
20 #include <TopoDS_Edge.hxx>
21 #include <TopoDS_Face.hxx>
22 #include <Geom_Curve.hxx>
23
24 //=======================================================================
25 //function : BRepLib_CheckCurveOnSurface
26 //purpose  : 
27 //=======================================================================
28 BRepLib_CheckCurveOnSurface::BRepLib_CheckCurveOnSurface
29                                             ( const TopoDS_Edge& theEdge,
30                                               const TopoDS_Face& theFace)
31 {
32   Init(theEdge, theFace);
33 }
34
35 //=======================================================================
36 //function : Init
37 //purpose  : 
38 //=======================================================================
39 void BRepLib_CheckCurveOnSurface::Init
40   (const TopoDS_Edge& theEdge,
41    const TopoDS_Face& theFace)
42 {
43   myCOnSurfGeom.Init();
44
45   if (theEdge.IsNull() || theFace.IsNull())
46   {
47     return;
48   }
49   //
50   if (BRep_Tool::Degenerated(theEdge) ||
51       !BRep_Tool::IsGeometric(theEdge))
52   {
53     return;
54   }
55   
56   //
57   TopLoc_Location aLocE, aLocF, aLocC2D;
58   Standard_Real aFirst = 0.0, aLast = 0.0;
59   //
60   // 3D curve initialization
61   const Handle(Geom_Curve)& aC3dTmp = BRep_Tool::Curve(theEdge, aLocE, aFirst, aLast);
62   const Handle(Geom_Curve) aC3d(Handle(Geom_Curve)::DownCast(aC3dTmp->Transformed(aLocE.Transformation())));
63
64   // Surface initialization
65   const Handle(Geom_Surface)& aSTmp = BRep_Tool::Surface(theFace, aLocF);
66   const Handle(Geom_Surface) aS(Handle(Geom_Surface)::DownCast(aSTmp->Transformed(aLocF.Transformation())));
67   //
68   // 2D curves initialization 
69   myPCurve = BRep_Tool::CurveOnSurface(theEdge, theFace, aFirst, aLast);
70
71   if(BRep_Tool::IsClosed(theEdge, theFace))
72     myPCurve2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(theEdge.Reversed()),
73                                           theFace, aFirst, aLast);
74
75   myCOnSurfGeom.Init(aC3d, aS, aFirst, aLast);
76 }
77
78 //=======================================================================
79 //function : Perform
80 //purpose  : if isTheMTDisabled == TRUE parallelization is not used
81 //=======================================================================
82 void BRepLib_CheckCurveOnSurface::Perform(const Standard_Boolean isTheMTDisabled)
83 {
84   // Compute the max distance
85   Compute(myPCurve, isTheMTDisabled);
86   if (ErrorStatus())
87   {
88     return;
89   }
90   //
91   if (!myPCurve2.IsNull())
92   {
93     // compute max distance for myPCurve2
94     // (for the second curve on closed surface)
95     Compute(myPCurve2, isTheMTDisabled);
96   }
97 }
98
99 //=======================================================================
100 //function : Compute
101 //purpose  : if isTheMTDisabled == TRUE parallelization is not used
102 //=======================================================================
103 void BRepLib_CheckCurveOnSurface::Compute(const Handle(Geom2d_Curve)& thePCurve,
104                                           const Standard_Boolean isTheMTDisabled)
105 {
106   myCOnSurfGeom.Perform(thePCurve, isTheMTDisabled);
107 }