// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
#ifdef WNT
// E.A. : On windows with python 2.6, there is a conflict
#include <Standard_Stream.hxx>
#include <GEOMImpl_ICurvesOperations.hxx>
-
-#include <TColStd_HArray1OfReal.hxx>
+#include <GEOMImpl_Types.hxx>
#include <GEOM_Function.hxx>
#include <GEOM_PythonDump.hxx>
-#include <GEOMImpl_Types.hxx>
-
#include <GEOMImpl_PolylineDriver.hxx>
#include <GEOMImpl_CircleDriver.hxx>
#include <GEOMImpl_SplineDriver.hxx>
#include <GEOMImpl_ISketcher.hxx>
#include <GEOMImpl_I3DSketcher.hxx>
+#include <Basics_OCCTVersion.hxx>
+
#include "utilities.h"
#include <TDF_Tool.hxx>
+#include <TColStd_HArray1OfReal.hxx>
#include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
//Compute the Circle value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
//Compute the Circle value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
//Compute the Circle value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
//Compute the Ellipse value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
//Add a new Circle Arc function
Handle(GEOM_Function) aFunction =
- anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
+ anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
if (aFunction.IsNull()) return NULL;
-
+
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
GEOMImpl_IArc aCI (aFunction);
Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
-
if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
aCI.SetPoint1(aRefPnt1);
aCI.SetPoint2(aRefPnt2);
aCI.SetPoint3(aRefPnt3);
-
+
//Compute the Arc value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
//Compute the Arc value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
if (aFunction.IsNull()) return NULL;
-
+
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
GEOMImpl_IArc aCI (aFunction);
Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
-
if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
aCI.SetPoint1(aRefPnt1);
aCI.SetPoint2(aRefPnt2);
aCI.SetPoint3(aRefPnt3);
-
+
//Compute the Arc value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
//Compute the Polyline value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
//Compute the Spline value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
//Compute the Spline value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
* MakeCurveParametric
*/
//=============================================================================
-Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr,
- double theParamMin, double theParamMax, double theParamStep,
- CurveType theCurveType) {
+Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
+ (const char* thexExpr, const char* theyExpr, const char* thezExpr,
+ double theParamMin, double theParamMax, double theParamStep,
+ CurveType theCurveType,
+ int theParamNbStep, bool theNewMethod)
+{
TCollection_AsciiString aPyScript;
aPyScript +="from math import * \n";
aPyScript +="def X(t): \n";
- aPyScript +=" return ";
+ aPyScript +=" return ";
aPyScript += thexExpr;
- aPyScript += "\n";
+ aPyScript += "\n";
aPyScript +="def Y(t): \n";
aPyScript +=" return ";
aPyScript += theyExpr;
aPyScript += "\n";
-
+
aPyScript +="def Z(t): \n";
aPyScript +=" return ";
aPyScript += thezExpr;
aPyScript += "\n";
-
- aPyScript +="def coordCalculator(tmin, tmax, tstep): \n";
- aPyScript +=" coords = [] \n";
- aPyScript +=" while tmin <= tmax : \n";
- aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
- aPyScript +=" tmin = tmin + tstep \n";
- aPyScript +=" return coords \n";
-
+
+ if (theNewMethod)
+ {
+ aPyScript +="def coordCalculator(tmin, tmax, nstep): \n";
+ aPyScript +=" coords = [] \n";
+ aPyScript +=" tstep = (tmax - tmin) / nstep \n";
+ aPyScript +=" n = 0 \n";
+ aPyScript +=" while n <= nstep : \n";
+ aPyScript +=" t = tmin + n*tstep \n";
+ aPyScript +=" coords.append([X(t), Y(t), Z(t)]) \n";
+ aPyScript +=" n = n+1 \n";
+ aPyScript +=" return coords \n";
+ }
+ else
+ {
+ aPyScript +="def coordCalculator(tmin, tmax, tstep): \n";
+ aPyScript +=" coords = [] \n";
+ aPyScript +=" while tmin <= tmax : \n";
+ aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
+ aPyScript +=" tmin = tmin + tstep \n";
+ aPyScript +=" return coords \n";
+ }
+
SetErrorCode(KO);
if(theParamMin >= theParamMax) {
return NULL;
}
- if(theParamStep <= 0.0 ) {
+ if(!theNewMethod && theParamStep <= 0.0) {
SetErrorCode("Value of the step must be positive !!!");
return NULL;
}
-
+ else if(theNewMethod && theParamNbStep < 0) {
+ SetErrorCode("The number of steps must be positive !!!");
+ return NULL;
+ }
+
/* Initialize the Python interpreter */
if (! Py_IsInitialized()) {
SetErrorCode("Python interpreter is not initialized !!! ");
return NULL;
- }
+ }
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
-
+
PyObject* main_mod = PyImport_AddModule("__main__");
PyObject* main_dict = PyModule_GetDict(main_mod);
PyObject * func = NULL;
func = PyObject_GetAttrString(main_mod, "coordCalculator");
-
+
if (func == NULL){
SetErrorCode("Can't get function from python module !!!");
PyGILState_Release(gstate);
return NULL;
}
+
+ PyObject* coords;
+ if (theNewMethod)
+ coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep );
+ else
+ coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
- PyObject* coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
PyObject* new_stderr = NULL;
if (coords == NULL){
if(PyList_Size( coords ) <= 0) {
SetErrorCode("Empty list of the points, please check input parameters !!!");
return NULL;
- }
+ }
int k=1;
for ( Py_ssize_t i = 0; i< PyList_Size( coords ); ++i ) {
PyObject* coord = PyList_GetItem( coords, i );
if (coord != NULL) {
for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
- PyObject* item = PyList_GetItem(coord, j);
- aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
- k++;
+ PyObject* item = PyList_GetItem(coord, j);
+ aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
+ k++;
}
}
}
Py_DECREF(coords);
-
-
PyGILState_Release(gstate);
- Handle(GEOM_Object) aCurve;
+ Handle(GEOM_Object) aCurve;
Handle(GEOM_Function) aFunction;
TCollection_AsciiString aCurveType;
-
+
switch(theCurveType) {
case Polyline: {
//Add a new Polyline object
aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
-
+
//Add a new Polyline function for creation a polyline relatively to points set
aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
if (aFunction.IsNull()) return NULL;
-
+
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
aFunction =
aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
if (aFunction.IsNull()) return NULL;
-
+
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
-
+
GEOMImpl_ISpline aCI (aFunction);
aCI.SetLength(PyList_Size( coords ));
//Add a new Spline function for creation a bezier curve relatively to points set
aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
if (aFunction.IsNull()) return NULL;
-
+
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
//Compute the Curve value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode(aFail->GetMessageString());
return NULL;
}
-
+
//Make a Python command
GEOM::TPythonDump pd (aFunction);
pd << aCurve << " = geompy.MakeCurveParametric(";
pd << "\"" << thexExpr << "\", ";
pd << "\"" << theyExpr << "\", ";
pd << "\"" << thezExpr << "\", ";
-
+
pd << theParamMin <<", ";
pd << theParamMax <<", ";
- pd << theParamStep <<", ";
- pd << aCurveType.ToCString() <<")";
-
+ if (theNewMethod)
+ pd << theParamNbStep <<", ";
+ else
+ pd << theParamStep <<", ";
+ pd << aCurveType.ToCString() <<", ";
+ pd << theNewMethod <<")";
+
SetErrorCode(OK);
return aCurve;
}
//Compute the Sketcher value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
aCoordsArray->SetValue(ind, *it);
aCI.SetCoordinates(aCoordsArray);
-
+
//Compute the Sketcher value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
//Compute the Sketcher value
try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode(OK);
return aSketcher;
}
-