From: gdd Date: Fri, 2 Sep 2011 15:11:47 +0000 (+0000) Subject: rnc : X-Git-Tag: Before_opencv_branch_20110913~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=55423f9957d470bc998afbf81e64b5a1e30409e9;p=modules%2Fgeom.git rnc : - 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 --- diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 30314c028..e1ce70642 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -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 diff --git a/src/BasicGUI/BasicGUI_CurveDlg.cxx b/src/BasicGUI/BasicGUI_CurveDlg.cxx index 53561d73c..9e0ac3bbf 100644 --- a/src/BasicGUI/BasicGUI_CurveDlg.cxx +++ b/src/BasicGUI/BasicGUI_CurveDlg.cxx @@ -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 ); @@ -165,32 +167,32 @@ void BasicGUI_CurveDlg::Init() myParams->hide(); /* signals and slots connections */ - connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) ); - connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ); + connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) ); + connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ); - connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); - connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); + connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + 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->CheckButton2, 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( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); - connect( myBySelectionBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) ); - connect( myAnaliticalBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) ); + connect( myBySelectionBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) ); + connect( myAnaliticalBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) ); - 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->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double))); + connect(myParams->myPMax, 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())); - connect(myParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished())); + connect(myParams->myXExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished())); + connect(myParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished())); + connect(myParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished())); initName( tr( "GEOM_CURVE" ) ); resize(100,100); @@ -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 : diff --git a/src/BasicGUI/BasicGUI_CurveDlg.h b/src/BasicGUI/BasicGUI_CurveDlg.h index ff4bae930..c7674db8d 100644 --- a/src/BasicGUI/BasicGUI_CurveDlg.h +++ b/src/BasicGUI/BasicGUI_CurveDlg.h @@ -79,6 +79,7 @@ private slots: void SetEditCurrentArgument(); void CreationModeChanged(); void ValueChangedInSpinBox(double/*theValue*/); + void ValueChangedInSpinBox(int /*theValue*/); void OnEditingFinished(); }; diff --git a/src/BasicGUI/BasicGUI_ParamCurveWidget.cxx b/src/BasicGUI/BasicGUI_ParamCurveWidget.cxx index 96d47d183..87c5476b7 100644 --- a/src/BasicGUI/BasicGUI_ParamCurveWidget.cxx +++ b/src/BasicGUI/BasicGUI_ParamCurveWidget.cxx @@ -32,6 +32,7 @@ #include #include +#include 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); diff --git a/src/BasicGUI/BasicGUI_ParamCurveWidget.h b/src/BasicGUI/BasicGUI_ParamCurveWidget.h index ef1aeb1d7..df2adfeaf 100644 --- a/src/BasicGUI/BasicGUI_ParamCurveWidget.h +++ b/src/BasicGUI/BasicGUI_ParamCurveWidget.h @@ -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; }; diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 2052270b6..f3c0edbbb 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -4376,6 +4376,10 @@ Otherwise the dimensions will be kept without modifications. GEOM_PCURVE_STEP Step + + + GEOM_PCURVE_NBSTEP + Number of steps diff --git a/src/GEOMGUI/GEOM_msg_fr.ts b/src/GEOMGUI/GEOM_msg_fr.ts index 21c90d14c..099e90fa3 100644 --- a/src/GEOMGUI/GEOM_msg_fr.ts +++ b/src/GEOMGUI/GEOM_msg_fr.ts @@ -4377,6 +4377,10 @@ le paramètre '%1' aux préférences du module Géométrie.GEOM_PCURVE_STEP Pas + + GEOM_PCURVE_NBSTEP + Nombre de pas + BasicGUI_EllipseDlg diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx index 1f1075185..c9c68ab5c 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx @@ -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"; - 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); @@ -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 <<", "; - pd << theParamStep <<", "; - pd << aCurveType.ToCString() <<")"; + if (theNewMethod) + pd << theParamNbStep <<", "; + else + pd << theParamStep <<", "; + pd << aCurveType.ToCString() <<", "; + pd << theNewMethod <<")"; SetErrorCode(OK); return aCurve; diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx index be7aedad6..4f8f3a8ad 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx @@ -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 theWorkingPlane); diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.cc b/src/GEOM_I/GEOM_ICurvesOperations_i.cc index ffcd60b4d..bbd162e11 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.cc +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.cc @@ -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 diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.hh b/src/GEOM_I/GEOM_ICurvesOperations_i.hh index 01a948fa9..11b1fb5e4 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.hh +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.hh @@ -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, 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); diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 4712290f1..be5a1e315 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -966,9 +966,12 @@ 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) - 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) anObj.SetParameters(Parameters) return anObj