]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
rnc :
authorgdd <gdd>
Fri, 2 Sep 2011 15:11:47 +0000 (15:11 +0000)
committergdd <gdd>
Fri, 2 Sep 2011 15:11:47 +0000 (15:11 +0000)
- 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

12 files changed:
idl/GEOM_Gen.idl
src/BasicGUI/BasicGUI_CurveDlg.cxx
src/BasicGUI/BasicGUI_CurveDlg.h
src/BasicGUI/BasicGUI_ParamCurveWidget.cxx
src/BasicGUI/BasicGUI_ParamCurveWidget.h
src/GEOMGUI/GEOM_msg_en.ts
src/GEOMGUI/GEOM_msg_fr.ts
src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx
src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx
src/GEOM_I/GEOM_ICurvesOperations_i.cc
src/GEOM_I/GEOM_ICurvesOperations_i.hh
src/GEOM_SWIG/geompyDC.py

index 30314c028f7aafc4d0067a13a50d8431e4c91510..e1ce70642e7531305872da1b3af8c4c727320b85 100644 (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
index 53561d73ca33cadee215bd30729854536d5bb811..9e0ac3bbf901367f67f789c076f276a1a7b0ae6d 100644 (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 );
@@ -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  :
index ff4bae9305875ac4c41e8a560848c7191587927c..c7674db8d15081879ba59858d2c15ad5b5e27197 100644 (file)
@@ -79,6 +79,7 @@ private slots:
   void                               SetEditCurrentArgument();
   void                               CreationModeChanged();
   void                               ValueChangedInSpinBox(double/*theValue*/);
+  void                               ValueChangedInSpinBox(int   /*theValue*/);
   void                               OnEditingFinished();
 };
 
index 96d47d18378c37408e5f6dce2df61506fe4e9a3c..87c5476b7aaf8663140e5a73b445fd10f64f0677 100644 (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);
index ef1aeb1d76b945e81610b1281cabbc40de3bc516..df2adfeafbe47b18a58f3604fb713cf4323fa4b8 100644 (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;
   
 };
 
index 2052270b670aa75f4e92bc74f69e013244a8e026..f3c0edbbb563006c924788a97d01388334a281da 100644 (file)
@@ -4376,6 +4376,10 @@ Otherwise the dimensions will be kept without modifications.</translation>
     <message>
         <source>GEOM_PCURVE_STEP</source>
         <translation>Step</translation>
+    </message>
+    <message>
+        <source>GEOM_PCURVE_NBSTEP</source>
+        <translation>Number of steps</translation>
     </message>        
 </context>
 <context>
index 21c90d14cf84d5da304120682f94d33463d80887..099e90fa3236898aa0d13749a4a5d569dcc38844 100644 (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>
index 1f1075185393671af6d46013bd266b435138bb85..c9c68ab5ccf5d6245ad1f8486f2a28ca3deafff9 100644 (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";
 
-  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;
index be7aedad6cac634c4d9b10051039f4c9366d2ded..4f8f3a8ade7fdc08b08218319d87024f7e56d92c 100644 (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);
index ffcd60b4d037955c26a3760141bb816ee510e0b3..bbd162e112b1afb3ffef5b54473c57cb550c80f7 100644 (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
index 01a948fa949bc774f68d32e90df569a7d061a555..11b1fb5e4268949792ef612999c60bfec524e69c 100644 (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, 
                                            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);
   
index 4712290f14a87755505ee27ba851074ac2603209..be5a1e3154e364c8142c1273f5ab9febafd69afc 100644 (file)
@@ -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