1 // Copyright (C) 2007-2016 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
23 // File : GEOMImpl_PolylineDumper.cxx
24 // Author : Sergey KHROMOV
28 #include "GEOMImpl_PolylineDumper.hxx"
29 #include "GEOMImpl_ICurvesOperations.hxx"
31 #include <GEOM_PythonDump.hxx>
34 //=======================================================================
35 // function : Constructor
37 //=======================================================================
38 GEOMImpl_PolylineDumper::GEOMImpl_PolylineDumper
39 (const std::list <std::list <double> > &theCoords,
40 const Handle(TColStd_HArray1OfExtendedString) &theNames,
41 const Handle(TColStd_HArray1OfByte) &theTypes,
42 const Handle(TColStd_HArray1OfByte) &theCloseds,
43 const Handle(TColStd_HArray1OfReal) &thePlnCoords)
44 : myCoords (theCoords),
47 myCloseds (theCloseds),
48 myPlnCoords (thePlnCoords),
49 myIsDone (Standard_False)
55 //=======================================================================
56 // function : Constructor
58 //=======================================================================
59 GEOMImpl_PolylineDumper::GEOMImpl_PolylineDumper
60 (const std::list <std::list <double> > &theCoords,
61 const Handle(TColStd_HArray1OfExtendedString) &theNames,
62 const Handle(TColStd_HArray1OfByte) &theTypes,
63 const Handle(TColStd_HArray1OfByte) &theCloseds,
64 const Handle(GEOM_Object) &theWorkingPlane)
65 : myCoords (theCoords),
68 myCloseds (theCloseds),
69 myWorkingPlane (theWorkingPlane),
70 myIsDone (Standard_False)
75 //=======================================================================
78 //=======================================================================
79 Standard_Boolean GEOMImpl_PolylineDumper::Dump
80 (const Handle(GEOM_Object) &theObject)
82 if (theObject.IsNull()) {
83 return Standard_False;
87 Handle(GEOM_Function) aFunction = theObject->GetLastFunction();
88 GEOM::TPythonDump aPD(aFunction);
91 aPD << theObject << " = pl.result(";
93 if (myWorkingPlane.IsNull()) {
94 // Add coodinates of working plane.
98 for (i = 0; i < 9; ++i) {
99 aPD << myPlnCoords->Value(myPlnCoords->Lower() + i);
107 aPD << myWorkingPlane;
116 //=======================================================================
119 //=======================================================================
120 void GEOMImpl_PolylineDumper::init()
122 // Check input parameters.
123 if (myCoords.empty() || myNames.IsNull() ||
124 myTypes.IsNull() || myCloseds.IsNull()) {
125 // One or more input parameters are null or empty()
129 const Standard_Integer aNbSec = myCoords.size();
131 if (aNbSec != myNames->Length() || aNbSec != myTypes->Length() ||
132 aNbSec != myCloseds->Length()) {
133 // Inconsistent data.
137 // Check the reference plane
138 if (myPlnCoords.IsNull()) {
139 if (myWorkingPlane.IsNull()) {
140 // Null working plane
144 if (myWorkingPlane.IsNull() == Standard_False) {
145 // Ambiguous working plane
149 if (myPlnCoords->Length() != 9) {
150 // Invalid number of plane coordinates.
155 const char *aSeparator = "\n\t";
157 std::list <std::list <double> >::const_iterator anIt = myCoords.begin();
159 myDescr += "pl = geompy.Polyline2D()";
162 for (i = 0; i < aNbSec && anIt != myCoords.end(); ++i, ++anIt) {
163 myDescr += aSeparator;
164 myDescr += "pl.addSection(";
167 myDescr += myNames->Value(myNames->Lower() + i) + "\", ";
169 const Standard_Integer aType = myTypes->Value(myTypes->Lower() + i);
172 case GEOMImpl_ICurvesOperations::Polyline:
173 myDescr += "GEOM.Polyline, ";
175 case GEOMImpl_ICurvesOperations::Interpolation:
176 myDescr += "GEOM.Interpolation, ";
181 break; // NEVERREACHED
185 if (myCloseds->Value(myCloseds->Lower() + i)) {
192 const Standard_Integer aNbCoords = anIt->size();
196 // Odd number of coordinates.
201 if (aNbCoords <= 4) {
202 // Add 2 points to the same command addSection.
205 std::list <double>::const_iterator aCIt = anIt->begin();
207 while (aCIt != anIt->end()) {
210 if (++aCIt != anIt->end()) {
215 // Add points to a separate command addPoints.
216 // Add maximum 4 points in a command.
217 std::list <double>::const_iterator aCIt = anIt->begin();
218 Standard_Integer aMaxNbCoord = 8;
219 Standard_Integer j = 1;
222 myDescr += aSeparator;
223 myDescr += "pl.addPoints([";
225 while (aCIt != anIt->end()) {
228 if (++aCIt != anIt->end()) {
229 if (j == aMaxNbCoord) {
230 // 4 points are added. Add a new command.
232 myDescr += aSeparator;
233 myDescr += "pl.addPoints([";
249 myDescr += aSeparator;
250 myIsDone = Standard_True;