0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / BRepMeshData / BRepMeshData_Edge.cxx
CommitLineData
7bd071ed 1// Created on: 2016-04-07
2// Copyright (c) 2016 OPEN CASCADE SAS
3// Created by: Oleg AGASHIN
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <BRepMeshData_Edge.hxx>
17#include <BRepMeshData_PCurve.hxx>
18#include <BRepMeshData_Curve.hxx>
19#include <BRepMesh_OrientedEdge.hxx>
20#include <BRepMesh_Vertex.hxx>
21
22//=======================================================================
23// Function: Constructor
24// Purpose :
25//=======================================================================
26BRepMeshData_Edge::BRepMeshData_Edge (
27 const TopoDS_Edge& theEdge,
28 const Handle (NCollection_IncAllocator)& theAllocator)
29 : IMeshData_Edge (theEdge),
30 myAllocator (theAllocator),
31 myPCurves (256, myAllocator),
32 myPCurvesMap(1, myAllocator)
33{
34 SetCurve (IMeshData::ICurveHandle (new (myAllocator) BRepMeshData_Curve (myAllocator)));
35}
36
37//=======================================================================
38// Function: Destructor
39// Purpose :
40//=======================================================================
41BRepMeshData_Edge::~BRepMeshData_Edge ()
42{
43}
44
45//=======================================================================
46// Function: AddPCurve
47// Purpose :
48//=======================================================================
49Standard_Integer BRepMeshData_Edge::PCurvesNb () const
50{
51 return myPCurves.Size ();
52}
53
54//=======================================================================
55// Function: AddPCurve
56// Purpose :
57//=======================================================================
58const IMeshData::IPCurveHandle& BRepMeshData_Edge::AddPCurve (
59 const IMeshData::IFacePtr& theDFace,
60 const TopAbs_Orientation theOrientation)
61{
62 const Standard_Integer aPCurveIndex = PCurvesNb ();
63 // Add pcurve to list of pcurves
64 IMeshData::IPCurveHandle aPCurve (new (myAllocator) BRepMeshData_PCurve (theDFace, theOrientation, myAllocator));
65 myPCurves.Append (aPCurve);
66
67 // Map pcurve to faces.
68 if (!myPCurvesMap.IsBound(theDFace))
69 {
70 myPCurvesMap.Bind(theDFace, IMeshData::ListOfInteger(myAllocator));
71 }
72
73 IMeshData::ListOfInteger& aListOfPCurves = myPCurvesMap.ChangeFind(theDFace);
74 aListOfPCurves.Append (aPCurveIndex);
75
76 return GetPCurve (aPCurveIndex);
77}
78
79//=======================================================================
80// Function: GetPCurve
81// Purpose :
82//=======================================================================
83const IMeshData::IPCurveHandle& BRepMeshData_Edge::GetPCurve (
84 const IMeshData::IFacePtr& theDFace,
85 const TopAbs_Orientation theOrientation) const
86{
87 const IMeshData::ListOfInteger& aListOfPCurves = myPCurvesMap.Find (theDFace);
88 const IMeshData::IPCurveHandle& aPCurve1 = myPCurves (aListOfPCurves.First ());
89 return (aPCurve1->GetOrientation () == theOrientation) ?
90 aPCurve1 :
91 myPCurves (aListOfPCurves.Last ());
92}
93
94//=======================================================================
95// Function: GetPCurve
96// Purpose :
97//=======================================================================
98const IMeshData::IPCurveHandle& BRepMeshData_Edge::GetPCurve (
99 const Standard_Integer theIndex) const
100{
101 return myPCurves (theIndex);
102}