Sfoglia il codice sorgente

Avoid assert when vtkControlPoints current point is changed

In setCurrentPoint(), calling updateCurrentPoint() before updating the point
lead to an assert in updateCurrentPoint().
Julien Finet 13 anni fa
parent
commit
b4ece51651

+ 11 - 3
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsWidget.cpp

@@ -281,7 +281,7 @@ void ctkVTKScalarsToColorsWidget::setCurrentPoint(vtkObject* caller, void* callD
     // When a new point is added, the modified event is fired later.
     // however we need to update the max of the current spin box before
     // setting the new value.
-    this->updateCurrentPoint();
+    this->updateNumberOfPoints();
     }
   this->setCurrentPoint(newPoint);
 }
@@ -363,13 +363,21 @@ void ctkVTKScalarsToColorsWidget::onCurrentPointChanged(int currentPoint)
 }
 
 // ----------------------------------------------------------------------------
+void ctkVTKScalarsToColorsWidget::updateNumberOfPoints()
+{
+  Q_D(ctkVTKScalarsToColorsWidget);
+  const int numberOfPoints = d->CurrentControlPointsItem ?
+    d->CurrentControlPointsItem->GetNumberOfPoints() : 0;
+  d->PointIdSpinBox->setMaximum( numberOfPoints - 1 );
+}
+
+// ----------------------------------------------------------------------------
 void ctkVTKScalarsToColorsWidget::updateCurrentPoint()
 {
   Q_D(ctkVTKScalarsToColorsWidget);
   Q_ASSERT(d->CurrentControlPointsItem);
   Q_ASSERT(d->PointIdSpinBox->value() == d->CurrentControlPointsItem->GetCurrentPoint());
-  d->PointIdSpinBox->setMaximum((d->CurrentControlPointsItem ?
-                                 d->CurrentControlPointsItem->GetNumberOfPoints() : 0) - 1);
+  this->updateNumberOfPoints();
 
   int pointId = d->PointIdSpinBox->value();
   if (pointId == -1)

+ 1 - 0
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsWidget.h

@@ -85,6 +85,7 @@ protected Q_SLOTS:
   void onPlotAdded(vtkPlot*);
   void onBoundsChanged();
   void setCurrentPoint(vtkObject* controlPointsItem, void* pointId);
+  void updateNumberOfPoints();
   void updateCurrentPoint();
   void onCurrentPointChanged(int pointId);
   void onColorChanged(const QColor& color);