1 // Copyright (C) 2007-2013 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.
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
23 // File: CurveCreator_Curve.cxx
24 // Created: Thu Jun 20 9:54:07 2013
25 // Author: Sergey KHROMOV
29 #include <CurveCreator_Curve.hxx>
30 #include <CurveCreator_Section.hxx>
33 //=======================================================================
34 // function: Constructor
36 //=======================================================================
37 CurveCreator_Curve::CurveCreator_Curve
38 (const CurveCreator::Dimension theDimension)
40 myDimension (theDimension)
44 //=======================================================================
45 // function: Destructor
47 //=======================================================================
48 CurveCreator_Curve::~CurveCreator_Curve()
50 // Delete all allocated data.
54 //=======================================================================
57 //=======================================================================
58 bool CurveCreator_Curve::isLocked() const
63 //=======================================================================
64 // function: getDimension
66 //=======================================================================
67 CurveCreator::Dimension CurveCreator_Curve::getDimension() const
72 //=======================================================================
73 // function: getNbPoints
75 //=======================================================================
76 int CurveCreator_Curve::getNbPoints(const int theISection) const
80 if (theISection == -1) {
82 const int aNbSections = getNbSections();
84 for (; i < aNbSections; i++) {
85 aNbCoords += mySections[i]->myPoints.size();
88 aNbCoords = mySections.at(theISection)->myPoints.size();
91 return aNbCoords/myDimension;
94 //=======================================================================
95 // function: getNbSections
97 //=======================================================================
98 int CurveCreator_Curve::getNbSections() const
100 return mySections.size();
103 //=======================================================================
104 // function: getCoordinates
106 //=======================================================================
107 CurveCreator::Coordinates CurveCreator_Curve::getCoordinates
108 (const int theISection, const int theIPnt) const
110 CurveCreator_Section *aSection = mySections.at(theISection);
111 CurveCreator::Coordinates::const_iterator
112 anIter = aSection->myPoints.begin() + toICoord(theIPnt);
113 CurveCreator::Coordinates aResult(anIter, anIter + myDimension);
118 //=======================================================================
121 //=======================================================================
122 CurveCreator::Type CurveCreator_Curve::getType(const int theISection) const
124 return mySections.at(theISection)->myType;
127 //=======================================================================
128 // function: getPoints
130 //=======================================================================
131 const CurveCreator::Coordinates &CurveCreator_Curve::getPoints
132 (const int theISection) const
134 return mySections.at(theISection)->myPoints;
137 //=======================================================================
138 // function: isClosed
140 //=======================================================================
141 bool CurveCreator_Curve::isClosed(const int theISection) const
143 return mySections.at(theISection)->myIsClosed;
146 //=======================================================================
149 //=======================================================================
150 void CurveCreator_Curve::setType
151 (const CurveCreator::Type theType, const int theISection)
153 if (theISection == -1) {
155 const int aNbSections = getNbSections();
157 for (; i < aNbSections; i++) {
158 mySections[i]->myType = theType;
161 mySections.at(theISection)->myType = theType;
165 //=======================================================================
166 // function: addPoints
168 //=======================================================================
169 void CurveCreator_Curve::addPoints
170 (const CurveCreator::Coordinates &thePoints, const int theISection)
172 CurveCreator_Section *aSection =
173 (theISection == -1 ? mySections.back() : mySections.at(theISection));
175 aSection->myPoints.insert(aSection->myPoints.end(),
176 thePoints.begin(), thePoints.end());
179 //=======================================================================
180 // function: addSection
182 //=======================================================================
183 void CurveCreator_Curve::addSection
184 (const CurveCreator::Type theType,
185 const bool theIsClosed,
186 const CurveCreator::Coordinates &thePoints)
188 CurveCreator_Section *aSection = new CurveCreator_Section;
190 aSection->myType = theType;
191 aSection->myIsClosed = theIsClosed;
192 aSection->myPoints = thePoints;
193 mySections.push_back(aSection);
196 //=======================================================================
197 // function: removeSection
199 //=======================================================================
200 void CurveCreator_Curve::removeSection(const int theISection)
202 if (theISection == -1) {
203 delete mySections.back();
204 mySections.pop_back();
206 Sections::iterator anIterRm = mySections.begin() + theISection;
209 mySections.erase(anIterRm);
213 //=======================================================================
214 // function: insertPoints
216 //=======================================================================
217 void CurveCreator_Curve::insertPoints
218 (const CurveCreator::Coordinates &thePoints,
219 const int theISection,
223 // Add points to the end of section points.
224 addPoints(thePoints, theISection);
226 CurveCreator_Section *aSection =
227 (theISection == -1 ? mySections.back() : mySections.at(theISection));
229 aSection->myPoints.insert(aSection->myPoints.begin() + toICoord(theIPnt),
230 thePoints.begin(), thePoints.end());
234 //=======================================================================
235 // function: removePoints
237 //=======================================================================
238 void CurveCreator_Curve::removePoints(const int theISection,
240 const int theNbPoints)
242 CurveCreator_Section *aSection = mySections.at(theISection);
243 CurveCreator::Coordinates::iterator anIterBegin =
244 aSection->myPoints.begin() + toICoord(theIPnt);
245 CurveCreator::Coordinates::iterator anIterEnd =
247 aSection->myPoints.end() : anIterBegin + toICoord(theNbPoints));
249 aSection->myPoints.erase(anIterBegin, anIterEnd);
252 //=======================================================================
255 //=======================================================================
256 void CurveCreator_Curve::clear()
258 // Delete all allocated data.
260 const int aNbSections = getNbSections();
262 for (; i < aNbSections; i++) {
263 delete mySections[i];
269 //=======================================================================
270 // function: setCoordinates
272 //=======================================================================
273 void CurveCreator_Curve::setCoordinates
274 (const CurveCreator::Coordinates &theCoords,
275 const int theISection,
278 if (theCoords.size() == myDimension) {
279 CurveCreator_Section *aSection = mySections.at(theISection);
282 for (i = 0; i < myDimension; i++) {
283 aSection->myPoints.at(toICoord(theIPnt) + i) = theCoords[i];
288 //=======================================================================
289 // function: setClosed
291 //=======================================================================
292 void CurveCreator_Curve::setClosed(const bool theIsClosed,
293 const int theISection)
295 if (theISection == -1) {
296 int aSize = mySections.size();
299 for (i = 0; i < aSize; i++) {
300 mySections[i]->myIsClosed = theIsClosed;
303 mySections.at(theISection)->myIsClosed = theIsClosed;
307 //=======================================================================
308 // function: moveSection
310 //=======================================================================
311 void CurveCreator_Curve::moveSection(const int theISection,
312 const int theNewIndex)
314 if (theISection != theNewIndex) {
315 CurveCreator_Section *aSection = mySections.at(theISection);
318 Sections::iterator anIter = mySections.begin() + theISection;
320 mySections.erase(anIter);
323 anIter = mySections.begin() + theNewIndex;
324 mySections.insert(anIter, aSection);
328 //=======================================================================
331 //=======================================================================
332 void CurveCreator_Curve::join(const int theISectionTo,
333 const int theISectionFrom)
335 if (theISectionTo != theISectionFrom) {
336 CurveCreator_Section *aSection1 = mySections.at(theISectionTo);
337 CurveCreator_Section *aSection2 = mySections.at(theISectionFrom);
339 aSection1->myPoints.insert(aSection1->myPoints.end(),
340 aSection2->myPoints.begin(), aSection2->myPoints.end());
342 removeSection(theISectionFrom);
346 //=======================================================================
349 //=======================================================================
350 void CurveCreator_Curve::join()
352 const int aSize = mySections.size();
355 CurveCreator_Section *aSection1 = mySections[0];
358 for (i = 1; i < aSize; i++) {
359 CurveCreator_Section *aSection2 = mySections[i];
361 aSection1->myPoints.insert(aSection1->myPoints.end(),
362 aSection2->myPoints.begin(), aSection2->myPoints.end());
366 // Just erace section pointers as they were deleted before.
367 mySections.erase(mySections.begin() + 1, mySections.end());
371 //=======================================================================
372 // function: toICoord
374 //=======================================================================
375 int CurveCreator_Curve::toICoord(const int theIPnt) const
377 return theIPnt*myDimension;