- 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 double theParamStep,
in curve_type theCurveType); 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, * Create a sketcher (wire or face), following the textual description,
* passed through \a theCommand argument. \n * 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 */ /* min, max, step and decimals for spin boxes & initial values */
initSpinBox( myParams->myPMin, COORD_MIN, COORD_MAX, step, "length_precision" ); initSpinBox( myParams->myPMin, COORD_MIN, COORD_MAX, step, "length_precision" );
initSpinBox( myParams->myPMax, 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->myPMin->setValue( aMin );
myParams->myPMax->setValue( aMax ); myParams->myPMax->setValue( aMax );
myParams->myPStep->setValue( step ); myParams->myPStep->setValue( step );
@ -165,32 +167,32 @@ void BasicGUI_CurveDlg::Init()
myParams->hide(); myParams->hide();
/* signals and slots connections */ /* signals and slots connections */
connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) ); connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) );
connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ); connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) ); connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( GroupPoints->CheckButton1, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) ); connect( GroupPoints->CheckButton1, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) );
connect( GroupPoints->CheckButton2, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) ); connect( GroupPoints->CheckButton2, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) );
connect( myGeomGUI->getApp()->selectionMgr(), connect( myGeomGUI->getApp()->selectionMgr(),
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
connect( myBySelectionBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) ); connect( myBySelectionBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) );
connect( myAnaliticalBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) ); connect( myAnaliticalBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) );
connect(myParams->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double))); connect(myParams->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(myParams->myPMax, 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->myXExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
connect(myParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished())); connect(myParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
connect(myParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished())); connect(myParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
initName( tr( "GEOM_CURVE" ) ); initName( tr( "GEOM_CURVE" ) );
resize(100,100); resize(100,100);
@ -407,7 +409,7 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects )
if( myBySelectionBtn->isChecked() ) if( myBySelectionBtn->isChecked() )
anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() ); anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() );
else else
anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()), anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
qPrintable(myParams->myYExpr->text()), qPrintable(myParams->myYExpr->text()),
qPrintable(myParams->myZExpr->text()), qPrintable(myParams->myZExpr->text()),
myParams->myPMin->value(), myParams->myPMin->value(),
@ -420,7 +422,7 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects )
if( myBySelectionBtn->isChecked() ) if( myBySelectionBtn->isChecked() )
anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() ); anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() );
else else
anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()), anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
qPrintable(myParams->myYExpr->text()), qPrintable(myParams->myYExpr->text()),
qPrintable(myParams->myZExpr->text()), qPrintable(myParams->myZExpr->text()),
myParams->myPMin->value(), myParams->myPMin->value(),
@ -435,7 +437,7 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects )
anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(), anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(),
GroupPoints->CheckButton2->isChecked() ); GroupPoints->CheckButton2->isChecked() );
else else
anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()), anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
qPrintable(myParams->myYExpr->text()), qPrintable(myParams->myYExpr->text()),
qPrintable(myParams->myZExpr->text()), qPrintable(myParams->myZExpr->text()),
myParams->myPMin->value(), myParams->myPMin->value(),
@ -491,6 +493,15 @@ void BasicGUI_CurveDlg::ValueChangedInSpinBox(double/*theValue*/)
processPreview(); processPreview();
} }
//=================================================================================
// function : ValueChangedInSpinBox()
// purpose :
//=================================================================================
void BasicGUI_CurveDlg::ValueChangedInSpinBox(int/*theValue*/)
{
processPreview();
}
//================================================================================= //=================================================================================
// function : ValueChangedInSpinBox() // function : ValueChangedInSpinBox()
// purpose : // purpose :

View File

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

View File

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

View File

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

View File

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

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> <source>GEOM_PCURVE_STEP</source>
<translation>Pas</translation> <translation>Pas</translation>
</message> </message>
<message>
<source>GEOM_PCURVE_NBSTEP</source>
<translation>Nombre de pas</translation>
</message>
</context> </context>
<context> <context>
<name>BasicGUI_EllipseDlg</name> <name>BasicGUI_EllipseDlg</name>

View File

@ -864,7 +864,8 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
(const char* thexExpr, const char* theyExpr, const char* thezExpr, (const char* thexExpr, const char* theyExpr, const char* thezExpr,
double theParamMin, double theParamMax, double theParamStep, double theParamMin, double theParamMax, double theParamStep,
CurveType theCurveType) CurveType theCurveType,
int theParamNbStep, bool theNewMethod)
{ {
TCollection_AsciiString aPyScript; TCollection_AsciiString aPyScript;
aPyScript +="from math import * \n"; aPyScript +="from math import * \n";
@ -882,12 +883,27 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
aPyScript += thezExpr; aPyScript += thezExpr;
aPyScript += "\n"; aPyScript += "\n";
aPyScript +="def coordCalculator(tmin, tmax, tstep): \n"; if (theNewMethod)
aPyScript +=" coords = [] \n"; {
aPyScript +=" while tmin <= tmax : \n"; aPyScript +="def coordCalculator(tmin, tmax, nstep): \n";
aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n"; aPyScript +=" coords = [] \n";
aPyScript +=" tmin = tmin + tstep \n"; aPyScript +=" tstep = (tmax - tmin) / nstep \n";
aPyScript +=" return coords \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); SetErrorCode(KO);
@ -896,10 +912,14 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
return NULL; return NULL;
} }
if(theParamStep <= 0.0 ) { if(!theNewMethod && theParamStep <= 0.0) {
SetErrorCode("Value of the step must be positive !!!"); SetErrorCode("Value of the step must be positive !!!");
return NULL; return NULL;
} }
else if(theNewMethod && theParamNbStep < 0) {
SetErrorCode("The number of steps must be positive !!!");
return NULL;
}
/* Initialize the Python interpreter */ /* Initialize the Python interpreter */
if (! Py_IsInitialized()) { if (! Py_IsInitialized()) {
@ -933,7 +953,12 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
return NULL; 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; PyObject* new_stderr = NULL;
if (coords == NULL){ if (coords == NULL){
@ -1065,8 +1090,12 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
pd << theParamMin <<", "; pd << theParamMin <<", ";
pd << theParamMax <<", "; pd << theParamMax <<", ";
pd << theParamStep <<", "; if (theNewMethod)
pd << aCurveType.ToCString() <<")"; pd << theParamNbStep <<", ";
else
pd << theParamStep <<", ";
pd << aCurveType.ToCString() <<", ";
pd << theNewMethod <<")";
SetErrorCode(OK); SetErrorCode(OK);
return aCurve; 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, Standard_EXPORT Handle(GEOM_Object) MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr,
double theParamMin, double theParamMax, double theParamStep, 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, Standard_EXPORT Handle(GEOM_Object) MakeSketcher (const char* theCommand,
std::list<double> theWorkingPlane); std::list<double> theWorkingPlane);

View File

@ -468,6 +468,46 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCurveParametric(const char*
return GetObject(anObject); 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 * MakeSketcher

View File

@ -89,6 +89,10 @@ class GEOM_I_EXPORT GEOM_ICurvesOperations_i :
GEOM::GEOM_Object_ptr MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr, GEOM::GEOM_Object_ptr MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr,
double theParamMin, double theParamMax, double theParamStep, double theParamMin, double theParamMax, double theParamStep,
GEOM::curve_type theCurveType); 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 MakeSketcher (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane);

View File

@ -966,9 +966,12 @@ class geompyDC(GEOM._objref_GEOM_Gen):
# #
# @ref tui_creation_curve "Example" # @ref tui_creation_curve "Example"
def MakeCurveParametric(self, thexExpr, theyExpr, thezExpr, def MakeCurveParametric(self, thexExpr, theyExpr, thezExpr,
theParamMin, theParamMax, theParamStep, theCurveType): theParamMin, theParamMax, theParamStep, theCurveType, theNewMethod=False ):
theParamMin,theParamMax,theParamStep,Parameters = ParseParameters(theParamMin,theParamMax,theParamStep) theParamMin,theParamMax,theParamStep,Parameters = ParseParameters(theParamMin,theParamMax,theParamStep)
anObj = self.CurvesOp.MakeCurveParametric(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType) 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) RaiseIfFailed("MakeSplineInterpolation", self.CurvesOp)
anObj.SetParameters(Parameters) anObj.SetParameters(Parameters)
return anObj return anObj