- Fixed a bug in MakeCurveParametric that the curve does not always reach the specified max parameter.
- Added a new idl method MakeCurvePrametricNew that takes a number of steps as input instead of a step value (to achieve the fix and a more usual interface)
- Wrapped the new idl method in python MakeCurveParametric with a flag theNewMethod = true
- Modified the associated dialog in order to use the new method and dump it
This commit is contained in:
gdd 2011-09-02 15:11:47 +00:00
parent d7e9366c5f
commit 55423f9957
12 changed files with 156 additions and 38 deletions

View File

@ -2635,6 +2635,25 @@ module GEOM
in double theParamStep,
in curve_type theCurveType);
/*!
* Creates a curve using the parametric definition of the basic points.
* \param thexExpr parametric equation of the coordinates X.
* \param theyExpr parametric equation of the coordinates Y.
* \param thezExpr parametric equation of the coordinates Z.
* \param theParamMin the minimal value of the parameter.
* \param theParamMax the maximum value of the parameter.
* \param theParamStep the number of steps of the parameter discretization.
* \param theCurveType the type of the curve.
* \return New GEOM_Object, containing the created curve.
*/
GEOM_Object MakeCurveParametricNew(in string thexExpr,
in string theyExpr,
in string thezExpr,
in double theParamMin,
in double theParamMax,
in long theParamNbStep,
in curve_type theCurveType);
/*!
* Create a sketcher (wire or face), following the textual description,
* passed through \a theCommand argument. \n

View File

@ -154,7 +154,9 @@ void BasicGUI_CurveDlg::Init()
/* min, max, step and decimals for spin boxes & initial values */
initSpinBox( myParams->myPMin, COORD_MIN, COORD_MAX, step, "length_precision" );
initSpinBox( myParams->myPMax, COORD_MIN, COORD_MAX, step, "length_precision" );
initSpinBox( myParams->myPStep, COORD_MIN, COORD_MAX, step, "length_precision" );
myParams->myPStep->setValue( 10 );
myParams->myPStep->setMaximum( 999 );
myParams->myPStep->setSingleStep( 10 );
myParams->myPMin->setValue( aMin );
myParams->myPMax->setValue( aMax );
myParams->myPStep->setValue( step );
@ -186,7 +188,7 @@ void BasicGUI_CurveDlg::Init()
connect(myParams->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(myParams->myPMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(myParams->myPStep, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(myParams->myPStep, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
connect(myParams->myXExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
connect(myParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
@ -407,7 +409,7 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects )
if( myBySelectionBtn->isChecked() )
anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() );
else
anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()),
anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
qPrintable(myParams->myYExpr->text()),
qPrintable(myParams->myZExpr->text()),
myParams->myPMin->value(),
@ -420,7 +422,7 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects )
if( myBySelectionBtn->isChecked() )
anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() );
else
anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()),
anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
qPrintable(myParams->myYExpr->text()),
qPrintable(myParams->myZExpr->text()),
myParams->myPMin->value(),
@ -435,7 +437,7 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects )
anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(),
GroupPoints->CheckButton2->isChecked() );
else
anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()),
anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
qPrintable(myParams->myYExpr->text()),
qPrintable(myParams->myZExpr->text()),
myParams->myPMin->value(),
@ -491,6 +493,15 @@ void BasicGUI_CurveDlg::ValueChangedInSpinBox(double/*theValue*/)
processPreview();
}
//=================================================================================
// function : ValueChangedInSpinBox()
// purpose :
//=================================================================================
void BasicGUI_CurveDlg::ValueChangedInSpinBox(int/*theValue*/)
{
processPreview();
}
//=================================================================================
// function : ValueChangedInSpinBox()
// purpose :

View File

@ -79,6 +79,7 @@ private slots:
void SetEditCurrentArgument();
void CreationModeChanged();
void ValueChangedInSpinBox(double/*theValue*/);
void ValueChangedInSpinBox(int /*theValue*/);
void OnEditingFinished();
};

View File

@ -32,6 +32,7 @@
#include <QGroupBox>
#include <SalomeApp_DoubleSpinBox.h>
#include <SalomeApp_IntSpinBox.h>
BasicGUI_ParamCurveWidget::BasicGUI_ParamCurveWidget(QWidget* parent):
@ -68,8 +69,8 @@ BasicGUI_ParamCurveWidget::BasicGUI_ParamCurveWidget(QWidget* parent):
myPMax = new SalomeApp_DoubleSpinBox( groupBox );
// Step
QLabel* textLabel6 = new QLabel( tr("GEOM_PCURVE_STEP"), groupBox );
myPStep = new SalomeApp_DoubleSpinBox( groupBox );
QLabel* textLabel6 = new QLabel( tr("GEOM_PCURVE_NBSTEP"), groupBox );
myPStep = new SalomeApp_IntSpinBox( groupBox );
//Layout
gridLayout->addWidget(textLabel1, 0, 0, 1, 1);

View File

@ -30,6 +30,7 @@
class QLineEdit;
class SalomeApp_DoubleSpinBox;
class SalomeApp_IntSpinBox;
class BasicGUI_ParamCurveWidget: public QWidget {
Q_OBJECT
@ -45,7 +46,7 @@ class BasicGUI_ParamCurveWidget: public QWidget {
SalomeApp_DoubleSpinBox* myPMin;
SalomeApp_DoubleSpinBox* myPMax;
SalomeApp_DoubleSpinBox* myPStep;
SalomeApp_IntSpinBox* myPStep;
};

View File

@ -4377,6 +4377,10 @@ Otherwise the dimensions will be kept without modifications.</translation>
<source>GEOM_PCURVE_STEP</source>
<translation>Step</translation>
</message>
<message>
<source>GEOM_PCURVE_NBSTEP</source>
<translation>Number of steps</translation>
</message>
</context>
<context>
<name>BasicGUI_EllipseDlg</name>

View File

@ -4377,6 +4377,10 @@ le paramètre &apos;%1&apos; aux préférences du module Géométrie.</translati
<source>GEOM_PCURVE_STEP</source>
<translation>Pas</translation>
</message>
<message>
<source>GEOM_PCURVE_NBSTEP</source>
<translation>Nombre de pas</translation>
</message>
</context>
<context>
<name>BasicGUI_EllipseDlg</name>

View File

@ -864,7 +864,8 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
(const char* thexExpr, const char* theyExpr, const char* thezExpr,
double theParamMin, double theParamMax, double theParamStep,
CurveType theCurveType)
CurveType theCurveType,
int theParamNbStep, bool theNewMethod)
{
TCollection_AsciiString aPyScript;
aPyScript +="from math import * \n";
@ -882,12 +883,27 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
aPyScript += thezExpr;
aPyScript += "\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);
@ -896,10 +912,14 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
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()) {
@ -933,7 +953,12 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
return NULL;
}
PyObject* coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
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* new_stderr = NULL;
if (coords == NULL){
@ -1065,8 +1090,12 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
pd << theParamMin <<", ";
pd << theParamMax <<", ";
if (theNewMethod)
pd << theParamNbStep <<", ";
else
pd << theParamStep <<", ";
pd << aCurveType.ToCString() <<")";
pd << aCurveType.ToCString() <<", ";
pd << theNewMethod <<")";
SetErrorCode(OK);
return aCurve;

View File

@ -80,7 +80,8 @@ class GEOMImpl_ICurvesOperations : public GEOM_IOperations {
Standard_EXPORT Handle(GEOM_Object) MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr,
double theParamMin, double theParamMax, double theParamStep,
CurveType theCurveType);
CurveType theCurveType,
int theParamNbStep=0, bool theNewMethod=false);
Standard_EXPORT Handle(GEOM_Object) MakeSketcher (const char* theCommand,
std::list<double> theWorkingPlane);

View File

@ -468,6 +468,46 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCurveParametric(const char*
return GetObject(anObject);
}
//=============================================================================
/*!
* MakeCurveParametricNew
*/
//=============================================================================
GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCurveParametricNew(const char* thexExpr, const char* theyExpr, const char* thezExpr,
double theParamMin, double theParamMax, int theParamNbStep,
GEOM::curve_type theCurveType) {
GEOM::GEOM_Object_var aGEOMObject;
//Set a not done flag
GetOperations()->SetNotDone();
GEOMImpl_ICurvesOperations::CurveType aType;
switch(theCurveType) {
case GEOM::Polyline:
aType = GEOMImpl_ICurvesOperations::Polyline;
break;
case GEOM::Bezier:
aType = GEOMImpl_ICurvesOperations::Bezier;
break;
case GEOM::Interpolation:
aType = GEOMImpl_ICurvesOperations::Interpolation;
break;
default:
break;
}
// Make Polyline
Handle(GEOM_Object) anObject =
GetOperations()->MakeCurveParametric(thexExpr, theyExpr, thezExpr,
theParamMin, theParamMax,
0.0, aType, theParamNbStep, true);
if (!GetOperations()->IsDone() || anObject.IsNull())
return aGEOMObject._retn();
return GetObject(anObject);
}
//=============================================================================
/*!
* MakeSketcher

View File

@ -90,6 +90,10 @@ class GEOM_I_EXPORT GEOM_ICurvesOperations_i :
double theParamMin, double theParamMax, double theParamStep,
GEOM::curve_type theCurveType);
GEOM::GEOM_Object_ptr MakeCurveParametricNew(const char* thexExpr, const char* theyExpr, const char* thezExpr,
double theParamMin, double theParamMax, int theParamNbStep,
GEOM::curve_type theCurveType);
GEOM::GEOM_Object_ptr MakeSketcher (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane);
GEOM::GEOM_Object_ptr Make3DSketcher (const GEOM::ListOfDouble& theCoordinates);

View File

@ -966,8 +966,11 @@ class geompyDC(GEOM._objref_GEOM_Gen):
#
# @ref tui_creation_curve "Example"
def MakeCurveParametric(self, thexExpr, theyExpr, thezExpr,
theParamMin, theParamMax, theParamStep, theCurveType):
theParamMin, theParamMax, theParamStep, theCurveType, theNewMethod=False ):
theParamMin,theParamMax,theParamStep,Parameters = ParseParameters(theParamMin,theParamMax,theParamStep)
if theNewMethod:
anObj = self.CurvesOp.MakeCurveParametricNew(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType)
else:
anObj = self.CurvesOp.MakeCurveParametric(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType)
RaiseIfFailed("MakeSplineInterpolation", self.CurvesOp)
anObj.SetParameters(Parameters)