1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 #include "GEOMImpl_IPolyline2D.hxx"
26 #include <TColStd_HArray1OfInteger.hxx>
29 //=============================================================================
33 //=============================================================================
34 void GEOMImpl_IPolyline2D::SetCoords
35 (const std::list <std::list <double> > &theValue)
37 const Standard_Integer aNbSec = theValue.size();
40 // Compute the total number of points and fill the array of start indices.
42 Standard_Integer aNbCoords = 0;
43 Handle(TColStd_HArray1OfInteger) anIndices =
44 new TColStd_HArray1OfInteger(1, aNbSec);
45 Handle(TColStd_HArray1OfReal) aCoords;
46 std::list <std::list <double> >::const_iterator aSecIter = theValue.begin();
48 for (i = 1; aSecIter != theValue.end(); ++aSecIter, ++i) {
49 anIndices->SetValue(i, aNbCoords + 1);
50 aNbCoords += aSecIter->size();
54 // Fill the array of coordinates.
55 std::list<double>::const_iterator aCIter;
57 aCoords = new TColStd_HArray1OfReal(1, aNbCoords);
58 aSecIter = theValue.begin();
60 for (i = 1; aSecIter != theValue.end(); ++aSecIter) {
61 for (aCIter = aSecIter->begin(); aCIter != aSecIter->end(); ++aCIter) {
62 aCoords->SetValue(i++, *aCIter);
67 // Store the coordinates.
68 if (aCoords.IsNull() == Standard_False) {
69 _func->SetRealArray(POLY_ARG_COORDS, aCoords);
72 _func->SetIntegerArray(POLY_ARG_START_INDICES, anIndices);
76 //=============================================================================
80 //=============================================================================
81 void GEOMImpl_IPolyline2D::GetCoords(std::list <std::list <double> > &theValue)
85 Handle(TColStd_HArray1OfReal) aCoords =
86 _func->GetRealArray(POLY_ARG_COORDS);
87 Handle(TColStd_HArray1OfInteger) anIndices =
88 _func->GetIntegerArray(POLY_ARG_START_INDICES);
90 if (anIndices.IsNull() == Standard_False) {
91 const Standard_Integer aNbSec = anIndices->Length();
93 // Create an empty sections.
94 theValue.resize(aNbSec);
96 if (aCoords.IsNull() == Standard_False) {
99 std::list <std::list <double> >::iterator anIt = theValue.begin();
101 for (i = anIndices->Lower(); i <= anIndices->Upper(); ++i, ++anIt) {
102 const Standard_Integer iCoord1 = anIndices->Value(i);
103 const Standard_Integer iCoord2 = i + 1 > anIndices->Upper() ?
104 aCoords->Upper() + 1 : anIndices->Value(i + 1);
106 for (j = iCoord1; j < iCoord2; ++j) {
107 anIt->push_back(aCoords->Value(j));