0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / BRepMeshData / BRepMeshData_PCurve.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_PCurve.hxx>
17#include <gp_Pnt2d.hxx>
18#include <BRepMesh_OrientedEdge.hxx>
19#include <BRepMesh_Vertex.hxx>
c2a25d52 20#include <Standard_OutOfRange.hxx>
7bd071ed 21
22//=======================================================================
23// Function: Constructor
24// Purpose :
25//=======================================================================
26BRepMeshData_PCurve::BRepMeshData_PCurve (
27 const IMeshData::IFacePtr& theDFace,
28 const TopAbs_Orientation theOrientation,
29 const Handle (NCollection_IncAllocator)& theAllocator)
30 : IMeshData_PCurve (theDFace, theOrientation),
31 myPoints2d (NCollection_StdAllocator<gp_Pnt2d>(theAllocator)),
32 myParameters (NCollection_StdAllocator<Standard_Real>(theAllocator)),
33 myIndices (NCollection_StdAllocator<Standard_Integer>(theAllocator))
34{
35}
36
37//=======================================================================
38// Function: Destructor
39// Purpose :
40//=======================================================================
41BRepMeshData_PCurve::~BRepMeshData_PCurve ()
42{
43}
44
45//=======================================================================
46// Function: InsertPoint
47// Purpose :
48//=======================================================================
49void BRepMeshData_PCurve::InsertPoint(
50 const Standard_Integer thePosition,
51 const gp_Pnt2d& thePoint,
52 const Standard_Real theParamOnPCurve)
53{
54 myPoints2d .insert(myPoints2d .begin() + thePosition, thePoint);
55 myParameters.insert(myParameters.begin() + thePosition, theParamOnPCurve);
56 myIndices .insert(myIndices .begin() + thePosition, 0);
57}
58
59//=======================================================================
60// Function: AddPoint
61// Purpose :
62//=======================================================================
63void BRepMeshData_PCurve::AddPoint (
64 const gp_Pnt2d& thePoint,
65 const Standard_Real theParamOnPCurve)
66{
67 myPoints2d .push_back(thePoint);
68 myParameters.push_back(theParamOnPCurve);
69 myIndices .push_back(0);
70}
71
72//=======================================================================
73// Function: GetPoint
74// Purpose :
75//=======================================================================
76gp_Pnt2d& BRepMeshData_PCurve::GetPoint (const Standard_Integer theIndex)
77{
c2a25d52 78 Standard_OutOfRange_Raise_if (
79 theIndex < 0 || theIndex >= static_cast<Standard_Integer>(myPoints2d.size()),
80 "BRepMeshData_PCurve::GetPoint");
7bd071ed 81 return myPoints2d[theIndex];
82}
83
84//=======================================================================
85// Function: GetIndex
86// Purpose :
87//=======================================================================
88Standard_Integer& BRepMeshData_PCurve::GetIndex(const Standard_Integer theIndex)
89{
c2a25d52 90 Standard_OutOfRange_Raise_if (
91 theIndex < 0 || theIndex >= static_cast<Standard_Integer>(myIndices.size()),
92 "BRepMeshData_PCurve::GetIndex");
7bd071ed 93 return myIndices[theIndex];
94}
95
96//=======================================================================
97// Function: GetParameter
98// Purpose :
99//=======================================================================
100Standard_Real& BRepMeshData_PCurve::GetParameter (const Standard_Integer theIndex)
101{
c2a25d52 102 Standard_OutOfRange_Raise_if (
103 theIndex < 0 || theIndex >= ParametersNb(),
104 "BRepMeshData_PCurve::GetParameter");
7bd071ed 105 return myParameters[theIndex];
106}
107
108//=======================================================================
109// Function: ParameterNb
110// Purpose :
111//=======================================================================
112Standard_Integer BRepMeshData_PCurve::ParametersNb() const
113{
114 return static_cast<Standard_Integer>(myParameters.size());
115}
116
117//=======================================================================
118// Function: RemovePoint
119// Purpose :
120//=======================================================================
121void BRepMeshData_PCurve::RemovePoint (const Standard_Integer theIndex)
122{
123 myPoints2d.erase(myPoints2d.begin() + theIndex);
124 myIndices .erase(myIndices .begin() + theIndex);
125 removeParameter (theIndex);
126}
127
128//=======================================================================
129// Function: removeParameter
130// Purpose :
131//=======================================================================
132void BRepMeshData_PCurve::removeParameter (const Standard_Integer theIndex)
133{
134 myParameters.erase(myParameters.begin() + theIndex);
135}
136
137//=======================================================================
138// Function: Clear
139// Purpose :
140//=======================================================================
141void BRepMeshData_PCurve::Clear(const Standard_Boolean isKeepEndPoints)
142{
143 if (!isKeepEndPoints)
144 {
145 myPoints2d .clear();
146 myParameters.clear();
147 myIndices .clear();
148 }
149 else if (ParametersNb() > 2)
150 {
151 myPoints2d .erase(myPoints2d .begin() + 1, myPoints2d .begin() + (myPoints2d .size() - 1));
152 myParameters.erase(myParameters.begin() + 1, myParameters.begin() + (myParameters.size() - 1));
153 myIndices .erase(myIndices .begin() + 1, myIndices .begin() + (myIndices .size() - 1));
154 }
155}