Skip to content

Commit 8df3d75

Browse files
Tom O'ReillyTom O'Reilly
authored andcommitted
Disable and remove observers from widgets before clearing widget vector, removed unneeded code
1 parent 61e604c commit 8df3d75

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

src/qt-guilib/DrawInteractorStyle.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ void DrawInteractorStyle::OnLeftButtonUp() {
7272
return;
7373
}
7474

75+
// Left-mouse button clicked without moving;
7576
// Get world coordinates of this point
7677
vtkNew<vtkPointPicker> picker;
7778
if (picker->Pick(eventPos[0], eventPos[1], 0, GetDefaultRenderer())) {
79+
// Successfully picked world coordinates
7880
double worldCoords[3];
7981
picker->GetPickPosition(worldCoords);
8082

@@ -85,40 +87,48 @@ void DrawInteractorStyle::OnLeftButtonUp() {
8587
userPath_.push_back(point);
8688
}
8789
else {
88-
qWarning() << "Unable to pick point";
90+
qWarning() << "ERROR: Unable to pick point";
8991
return;
9092
}
9193

94+
// Which point in user-defined path?
9295
int pointIndex = userPath_.size() - 1;
9396

9497
qDebug() << "userPath_.size() = " << userPath_.size();
9598
if (userPath_.size() == 1) {
99+
// Defining first point in path
96100
qDebug() << "Clear existing widgets and profile line";
97101

98102
// First point of profile defined; clear existing widgets
99103
topoDataItem_->clearAddedActors();
104+
105+
// Detach each widget from the Interactor before releasing memory
106+
for (auto &w : pinWidgets_) {
107+
w->EnabledOff();
108+
w->removeKeyObservers(Interactor);
109+
w->SetInteractor(nullptr);
110+
}
111+
100112
pinWidgets_.clear();
101113
pinRepresentations_.clear();
102114
}
103-
115+
116+
// Note: vtkHandleRepresentation takes world position as 'c-style' double
117+
// array, so must copy vector of std::array<double, 3> to this double array
104118
double point[3];
119+
// Copy coordinates of this point to double array
105120
std::copy(userPath_[pointIndex].begin(), userPath_[pointIndex].end(), point);
106121

107122
// Put a pin marker at selected point
108123
auto pinWidget = vtkSmartPointer<MyHandleWidget>::New();
109124
auto pin = vtkSmartPointer<vtkFixedSizeHandleRepresentation3D>::New();
110125

111-
pin->SetWorldPosition(point);
126+
pin->SetWorldPosition(point); // C-style double array input
112127
pin->SetHandleSizeInPixels(30);
113128
pin->GetProperty()->SetColor(1., 0., 0.);
114129
pinWidget->SetInteractor(Interactor);
115130
pinWidget->SetRepresentation(pin);
116-
117-
pinWidget->RemoveObservers(vtkCommand::CharEvent);
118-
119131
pinWidget->EnabledOn();
120-
pinWidget->ProcessEventsOff();
121-
pinWidget->removeKeyObservers(Interactor);
122132

123133
pinWidgets_.push_back(pinWidget); // pinWidget should persist
124134
pinRepresentations_.push_back(pin); // pin representation should persist

0 commit comments

Comments
 (0)