Python dump implementation

This commit is contained in:
skv 2014-09-29 09:34:02 +04:00
parent 3fe24eae8a
commit bba5e588cd
4 changed files with 408 additions and 0 deletions

View File

@ -149,6 +149,7 @@ SET(GEOMImpl_HEADERS
GEOMImpl_Block6Explorer.hxx
GEOMImpl_MeasureDriver.hxx
GEOMImpl_PolylineDriver.hxx
GEOMImpl_PolylineDumper.hxx
GEOMImpl_CircleDriver.hxx
GEOMImpl_EllipseDriver.hxx
GEOMImpl_ArcDriver.hxx
@ -221,6 +222,7 @@ SET(GEOMImpl_SOURCES
GEOMImpl_Block6Explorer.cxx
GEOMImpl_MeasureDriver.cxx
GEOMImpl_PolylineDriver.cxx
GEOMImpl_PolylineDumper.cxx
GEOMImpl_CircleDriver.cxx
GEOMImpl_EllipseDriver.cxx
GEOMImpl_ArcDriver.cxx

View File

@ -60,6 +60,7 @@
#include "GEOMImpl_I3DSketcher.hxx"
#include "GEOMImpl_ICurveParametric.hxx"
#include "GEOMImpl_IIsoline.hxx"
#include "GEOMImpl_PolylineDumper.hxx"
#include <Basics_OCCTVersion.hxx>
@ -1560,6 +1561,17 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline2D
return NULL;
}
//Make a Python command
GEOMImpl_PolylineDumper aDumper(theCoords, theNames, theTypes,
theCloseds, theWorkingPlane);
aDumper.Dump(aResult);
if (aDumper.IsDone() == Standard_False) {
SetErrorCode("Python dump failed");
return NULL;
}
SetErrorCode(OK);
return aResult;
}
@ -1628,6 +1640,17 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline2DOnPlane
return NULL;
}
//Make a Python command
GEOMImpl_PolylineDumper aDumper(theCoords, theNames, theTypes,
theCloseds, theWorkingPlane);
aDumper.Dump(aResult);
if (aDumper.IsDone() == Standard_False) {
SetErrorCode("Python dump failed");
return NULL;
}
SetErrorCode(OK);
return aResult;
}

View File

@ -0,0 +1,251 @@
// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : GEOMImpl_PolylineDumper.cxx
// Author : Sergey KHROMOV
// Module : GEOM
#include "GEOMImpl_PolylineDumper.hxx"
#include "GEOMImpl_ICurvesOperations.hxx"
#include <GEOM_PythonDump.hxx>
//=======================================================================
// function : Constructor
// purpose :
//=======================================================================
GEOMImpl_PolylineDumper::GEOMImpl_PolylineDumper
(const std::list <std::list <double> > &theCoords,
const Handle(TColStd_HArray1OfExtendedString) &theNames,
const Handle(TColStd_HArray1OfByte) &theTypes,
const Handle(TColStd_HArray1OfByte) &theCloseds,
const Handle(TColStd_HArray1OfReal) &thePlnCoords)
: myCoords (theCoords),
myNames (theNames),
myTypes (theTypes),
myCloseds (theCloseds),
myPlnCoords (thePlnCoords),
myIsDone (Standard_False)
{
init();
}
//=======================================================================
// function : Constructor
// purpose :
//=======================================================================
GEOMImpl_PolylineDumper::GEOMImpl_PolylineDumper
(const std::list <std::list <double> > &theCoords,
const Handle(TColStd_HArray1OfExtendedString) &theNames,
const Handle(TColStd_HArray1OfByte) &theTypes,
const Handle(TColStd_HArray1OfByte) &theCloseds,
const Handle(GEOM_Object) &theWorkingPlane)
: myCoords (theCoords),
myNames (theNames),
myTypes (theTypes),
myCloseds (theCloseds),
myWorkingPlane (theWorkingPlane),
myIsDone (Standard_False)
{
init();
}
//=======================================================================
// function : Dump
// purpose :
//=======================================================================
Standard_Boolean GEOMImpl_PolylineDumper::Dump
(const Handle(GEOM_Object) &theObject)
{
if (theObject.IsNull()) {
return Standard_False;
}
if (myIsDone) {
Handle(GEOM_Function) aFunction = theObject->GetLastFunction();
GEOM::TPythonDump aPD(aFunction);
aPD << myDescr;
aPD << theObject << " = pl.result(";
if (myWorkingPlane.IsNull()) {
// Add coodinates of working plane.
Standard_Integer i;
aPD << "[";
for (i = 0; i < 9; ++i) {
aPD << myPlnCoords->Value(myPlnCoords->Lower() + i);
if (i < 8) {
aPD << ", ";
}
}
aPD << "]";
} else {
aPD << myWorkingPlane;
}
aPD << ")";
}
return myIsDone;
}
//=======================================================================
// function : init
// purpose :
//=======================================================================
void GEOMImpl_PolylineDumper::init()
{
// Check input parameters.
if (myCoords.empty() || myNames.IsNull() ||
myTypes.IsNull() || myCloseds.IsNull()) {
// One or more input parameters are null or empty()
return;
}
const Standard_Integer aNbSec = myCoords.size();
if (aNbSec != myNames->Length() || aNbSec != myTypes->Length() ||
aNbSec != myCloseds->Length()) {
// Inconsistent data.
return;
}
// Check the reference plane
if (myPlnCoords.IsNull()) {
if (myWorkingPlane.IsNull()) {
// Null working plane
return;
}
} else {
if (myWorkingPlane.IsNull() == Standard_False) {
// Ambiguous working plane
return;
}
if (myPlnCoords->Length() != 9) {
// Invalid number of plane coordinates.
return;
}
}
char *aSeparator = "\n\t";
Standard_Integer i;
std::list <std::list <double> >::const_iterator anIt = myCoords.begin();
myDescr += "pl = geompy.Polyline2D()";
// Add sections.
for (i = 0; i < aNbSec && anIt != myCoords.end(); ++i, ++anIt) {
myDescr += aSeparator;
myDescr += "pl.addSection(";
// Add name
myDescr += "\"";
myDescr += myNames->Value(myNames->Lower() + i) + "\", ";
// Add type
const Standard_Integer aType = myTypes->Value(myTypes->Lower() + i);
switch (aType) {
case GEOMImpl_ICurvesOperations::Polyline:
myDescr += "GEOM.Polyline, ";
break;
case GEOMImpl_ICurvesOperations::Interpolation:
myDescr += "GEOM.Interpolation, ";
break;
default:
myDescr.Clear();
return;
break; // NEVERREACHED
}
// Add Closed flag.
if (myCloseds->Value(myCloseds->Lower() + i)) {
myDescr += "True";
} else {
myDescr += "False";
}
// Add points.
const Standard_Integer aNbCoords = anIt->size();
if (aNbCoords > 0) {
if (aNbCoords % 2) {
// Odd number of coordinates.
myDescr.Clear();
return;
}
if (aNbCoords <= 4) {
// Add 2 points to the same command addSection.
myDescr += ", [";
std::list <double>::const_iterator aCIt = anIt->begin();
while (aCIt != anIt->end()) {
myDescr += *aCIt;
if (++aCIt != anIt->end()) {
myDescr += ", ";
}
}
} else {
// Add points to a separate command addPoints.
// Add maximum 4 points in a command.
std::list <double>::const_iterator aCIt = anIt->begin();
Standard_Integer aMaxNbCoord = 8;
Standard_Integer j = 1;
myDescr += ")";
myDescr += aSeparator;
myDescr += "pl.addPoints([";
while (aCIt != anIt->end()) {
myDescr += *aCIt;
if (++aCIt != anIt->end()) {
if (j == aMaxNbCoord) {
// 4 points are added. Add a new command.
myDescr += "])";
myDescr += aSeparator;
myDescr += "pl.addPoints([";
j = 1;
} else {
myDescr += ", ";
j++;
}
}
}
}
myDescr += "]";
}
myDescr += ")";
}
myDescr += aSeparator;
myIsDone = Standard_True;
}

View File

@ -0,0 +1,132 @@
// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : GEOMImpl_PolylineDumper.h
// Author : Sergey KHROMOV
#ifndef _GEOMImpl_PolylineDumper_HXX_
#define _GEOMImpl_PolylineDumper_HXX_
#include "GEOM_GEOMImpl.hxx"
#include <GEOM_Object.hxx>
#include <TColStd_HArray1OfExtendedString.hxx>
#include <TColStd_HArray1OfByte.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <list>
/**
* This is a helper class to form a dump of a polyline 2d curves creation
* algorithm.
*/
class GEOMIMPL_EXPORT GEOMImpl_PolylineDumper
{
public:
/**
* This construcor initializes the object with 2D polyline creation
* parameters.
*
* \param theCoords the list of coordinates list. theCoordsList[0]
* is the coordinates list of the first section. theCoordsList[1]
* is for the second section etc.
* \param theNames the list of names. The order corresponds to theCoords.
* \param theTypes the list of curve types. The order corresponds to
* theCoords.
* \param theCloseds the list of Closed flags. The order corresponds to
* theCoords.
* \param thePlnCoords 9 double values, defining origin,
* OZ and OX directions of the working plane.
*/
GEOMImpl_PolylineDumper
(const std::list <std::list <double> > &theCoords,
const Handle_TColStd_HArray1OfExtendedString &theNames,
const Handle_TColStd_HArray1OfByte &theTypes,
const Handle_TColStd_HArray1OfByte &theCloseds,
const Handle_TColStd_HArray1OfReal &thePlnCoords);
/**
* This construcor initializes the object with 2D polyline creation
* parameters.
*
* \param theCoords the list of coordinates list. theCoordsList[0]
* is the coordinates list of the first section. theCoordsList[1]
* is for the second section etc.
* \param theNames the list of names. The order corresponds to theCoords.
* \param theTypes the list of curve types. The order corresponds to
* theCoords.
* \param theCloseds the list of Closed flags. The order corresponds to
* theCoords.
* \param theWorkingPlane planar Face or LCS(Marker) of the working plane.
*/
GEOMImpl_PolylineDumper
(const std::list <std::list <double> > &theCoords,
const Handle_TColStd_HArray1OfExtendedString &theNames,
const Handle_TColStd_HArray1OfByte &theTypes,
const Handle_TColStd_HArray1OfByte &theCloseds,
const Handle_GEOM_Object &theWorkingPlane);
/**
* This method returns Standard_True if the dump description is created
* successfully.
*
* \return Standard_True in case of success; Standard_False otherwise.
*/
Standard_Boolean IsDone() const
{ return myIsDone; }
/**
* This method performs dump of the polyline.
*
* \param theObject the newly created object.
* \return Standard_True in case of success; Standard_False otherwise.
*/
Standard_Boolean Dump(const Handle_GEOM_Object &theObject);
protected:
/**
* This method generates the description required for python dump.
* It is called from constructor.
*/
void init();
private:
const std::list <std::list <double> > &myCoords;
Handle_TColStd_HArray1OfExtendedString myNames;
Handle_TColStd_HArray1OfByte myTypes;
Handle_TColStd_HArray1OfByte myCloseds;
Handle_TColStd_HArray1OfReal myPlnCoords;
Handle_GEOM_Object myWorkingPlane;
Standard_Boolean myIsDone;
TCollection_ExtendedString myDescr;
};
#endif