Salome HOME
Merge branch 'csgroup_IS2'
[modules/shaper.git] / src / PartSet / PartSet_BSplineWidget.cpp
index 9ca97448d277b246ee80c4e46416c6441214cee0..99449702d9d7cccd3fc93c395375655e7b130b41 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2019-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -37,6 +37,8 @@
 #include <QToolButton>
 
 
+static const double THE_MIN_WEIGHT = 1.e-7;
+
 PartSet_BSplineWidget::PartSet_BSplineWidget(
     QWidget* theParent,
     const Config_WidgetAPI* theData)
@@ -46,7 +48,7 @@ PartSet_BSplineWidget::PartSet_BSplineWidget(
   aMainLayout->setContentsMargins(0, 0, 0, 0);
 
   // GroupBox to keep widgets for B-spline poles and weights
-  myPolesGroupBox = new QGroupBox(tr("Poles and weights"), this);
+  myPolesGroupBox = new QGroupBox(translate("Poles and weights"), this);
   aMainLayout->addWidget(myPolesGroupBox);
 
   QVBoxLayout* aLayout = new QVBoxLayout(myPolesGroupBox);
@@ -103,7 +105,10 @@ void PartSet_BSplineWidget::storePolesAndWeights() const
 
   std::list<BSplinePoleWidgets>::const_iterator anIt = myPoles.begin();
   for (int anIndex = 0; anIt != myPoles.end(); ++anIndex, ++anIt) {
-    aWeightsArray->setValue(anIndex, anIt->myWeight->value());
+    double aWeight = anIt->myWeight->value();
+    if (aWeight < THE_MIN_WEIGHT)
+      aWeight = THE_MIN_WEIGHT;
+    aWeightsArray->setValue(anIndex, aWeight);
   }
 }
 
@@ -135,7 +140,7 @@ bool PartSet_BSplineWidget::restoreValueCustom()
       aData->attribute(SketchPlugin_BSpline::POLES_ID()));
   AttributeDoubleArrayPtr aWeights = aData->realArray(SketchPlugin_BSpline::WEIGHTS_ID());
 
-  while (myPoles.size() < aPoles->size())
+  while ((int)myPoles.size() < aPoles->size())
     addPoleWidget();
 
   std::list<BSplinePoleWidgets>::iterator anIt = myPoles.begin();
@@ -155,7 +160,7 @@ void PartSet_BSplineWidget::addPoleWidget()
 {
   QGridLayout* aGroupLay = dynamic_cast<QGridLayout*>(myPolesWgt->layout());
   int aNbPoles = (int)myPoles.size();
-  QString aPoleStr = tr("Pole %1").arg(aNbPoles + 1);
+  QString aPoleStr = translate("Pole %1").arg(aNbPoles + 1);
 
   myPoles.push_back(BSplinePoleWidgets());
   BSplinePoleWidgets& aPole = myPoles.back();
@@ -175,9 +180,9 @@ QGroupBox* PartSet_BSplineWidget::createPoleWidget(BSplinePoleWidgets& thePole,
   thePole.myY = new ModuleBase_LabelValue(aPoleGroupBox, tr("Y"));
   aPoleLay->addWidget(thePole.myY, 1, 0, 1, 3);
   thePole.myWeight = new ModuleBase_ParamSpinBox(aPoleGroupBox);
-  thePole.myWeight->setMinimum(0.0);
+  thePole.myWeight->setMinimum(THE_MIN_WEIGHT);
 
-  aPoleLay->addWidget(new QLabel(tr("Weight :"), aPoleGroupBox), 2, 0);
+  aPoleLay->addWidget(new QLabel(translate("Weight :"), aPoleGroupBox), 2, 0);
   aPoleLay->addWidget(thePole.myWeight, 2, 1);
   // we should listen textChanged signal as valueChanged do not send when text is modified
   connect(thePole.myWeight, SIGNAL(textChanged(const QString&)),
@@ -185,7 +190,7 @@ QGroupBox* PartSet_BSplineWidget::createPoleWidget(BSplinePoleWidgets& thePole,
 
   thePole.myAddBtn = new QToolButton(aPoleGroupBox);
   thePole.myAddBtn->setIcon(QIcon(":pictures/add.png"));
-  thePole.myAddBtn->setToolTip(tr("Add a new pole after the current"));
+  thePole.myAddBtn->setToolTip(translate("Add a new pole after the current"));
   aPoleLay->addWidget(thePole.myAddBtn, 2, 2);
   connect(thePole.myAddBtn, SIGNAL(clicked(bool)), SLOT(onAddPole()));