Skip to content

Commit 119936c

Browse files
committed
Show VTKButtons on interaction
* msvVTKButtons::Update() must be called to refresh their visibility and positions. * Don't trigger a rendering each time 1 button is modified, refreshes should be triggered by the application. * Factorize the ShowButtons()/HideButtons()
1 parent b83d513 commit 119936c

10 files changed

Lines changed: 77 additions & 90 deletions

Applications/ButtonClusters/msvQButtonClustersMainWindow.cxx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,7 @@ void msvQButtonClustersMainWindowPrivate::showData(int idx, bool value)
260260
void msvQButtonClustersMainWindowPrivate::enableClustering(bool value)
261261
{
262262
this->ButtonsManager->SetClustering(value);
263-
if(value)
264-
{
265-
266-
this->ButtonsManager->HideButtons();
267-
}
268-
else
269-
{
270-
this->ButtonsManager->ShowButtons();
271-
}
263+
this->ButtonsManager->SetCustersButtonsVisibility(value);
272264
this->ButtonsManager->UpdateWidgets();
273265
this->updateView();
274266
}

Libs/VTK/Widgets/msvVTKButtons.cxx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,14 @@ vtkImageData* msvVTKButtons::GetPreview(int width, int height)
202202
}
203203

204204
//------------------------------------------------------------------------------
205-
void msvVTKButtons::Update()
205+
void msvVTKButtons::Update(bool render)
206206
{
207-
Superclass::Update();
208207
this->CalculatePosition();
209-
if (ButtonCallback)
208+
if (this->ButtonCallback)
210209
{
211-
vtkButtonCallback::SafeDownCast(ButtonCallback)->FlyTo = FlyTo;
212-
if (vtkButtonCallback::SafeDownCast(ButtonCallback)->Renderer)
213-
{
214-
Renderer->GetRenderWindow()->Render();
215-
}
210+
vtkButtonCallback::SafeDownCast(this->ButtonCallback)->FlyTo = FlyTo;
216211
}
212+
this->Superclass::Update(render);
217213
}
218214

219215
//------------------------------------------------------------------------------

Libs/VTK/Widgets/msvVTKButtons.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class MSV_VTK_WIDGETS_EXPORT msvVTKButtons : public msvVTKButtonsInterface
9393
void SetCurrentRenderer(vtkRenderer *renderer);
9494

9595
// Description:
96-
// Perform update
97-
void Update();
96+
// Recalculate its position and request a rendering if \a render is true.
97+
void Update(bool render = true);
9898

9999
// Description:
100100
// Calculate position (center or corner)

Libs/VTK/Widgets/msvVTKButtonsGroup.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,10 @@ void msvVTKButtonsGroup::SetCurrentRenderer(vtkRenderer *renderer)
483483
}
484484

485485
//----------------------------------------------------------------------
486-
void msvVTKButtonsGroup::Update()
486+
void msvVTKButtonsGroup::Update(bool render)
487487
{
488-
Superclass::Update();
489488
this->CalculatePosition();
489+
this->Superclass::Update(render);
490490
}
491491

492492
//----------------------------------------------------------------------

Libs/VTK/Widgets/msvVTKButtonsGroup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class MSV_VTK_WIDGETS_EXPORT msvVTKButtonsGroup : public msvVTKButtonsInterface
117117

118118
// Description:
119119
// Perform update
120-
void Update();
120+
virtual void Update(bool render = true);
121121

122122
// Description:
123123
// Calculate position (center or corner)

Libs/VTK/Widgets/msvVTKButtonsInterface.cxx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void msvVTKButtonsInterface::SetCurrentRenderer(vtkRenderer* renderer)
100100
}
101101

102102
//----------------------------------------------------------------------
103-
void msvVTKButtonsInterface::Update()
103+
void msvVTKButtonsInterface::Update(bool render)
104104
{
105105
vtkTexturedButtonRepresentation2D *rep =
106106
vtkTexturedButtonRepresentation2D::SafeDownCast(
@@ -143,6 +143,10 @@ void msvVTKButtonsInterface::Update()
143143
this->GetButton()->GetRepresentation()->SetVisibility(false);
144144
this->GetButton()->EnabledOff();
145145
}
146+
if (this->Renderer && render)
147+
{
148+
this->Renderer->GetRenderWindow()->Render();
149+
}
146150
}
147151

148152
//----------------------------------------------------------------------
@@ -155,7 +159,6 @@ void msvVTKButtonsInterface::SetImage(vtkImageData* image)
155159
rep->SetButtonTexture(0,Image);
156160
int size[2]; size[0] = 16; size[1] = 16;
157161
rep->GetBalloon()->SetImageSize(size);
158-
//this->Update();
159162
}
160163

161164
//----------------------------------------------------------------------
@@ -164,20 +167,22 @@ void msvVTKButtonsInterface::SetOpacity(double opacity)
164167
if (opacity > 1) opacity=1;
165168
if (opacity < 0) opacity=0;
166169

167-
Opacity = opacity;
168-
169-
this->Update();
170+
this->Opacity = opacity;
170171
}
171172

172173
//----------------------------------------------------------------------
173174
void msvVTKButtonsInterface::RestorePreviousOpacity()
174175
{
175-
this->SetOpacity(PreviousOpacity);
176+
this->SetOpacity(this->PreviousOpacity);
176177
}
177178

178179
//----------------------------------------------------------------------
179180
void msvVTKButtonsInterface::SetShowButton(bool show)
180181
{
182+
if (this->ShowButton == show)
183+
{
184+
return;
185+
}
181186
this->ShowButton = show;
182187
if (this->Renderer)
183188
{

Libs/VTK/Widgets/msvVTKButtonsInterface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ class MSV_VTK_WIDGETS_EXPORT msvVTKButtonsInterface : public vtkObject
107107

108108
// Description:
109109
// Add vtk button to Renderer
110-
void SetCurrentRenderer(vtkRenderer *renderer);
110+
virtual void SetCurrentRenderer(vtkRenderer *renderer);
111111

112112
// Description:
113-
// update graphic objects
114-
void Update();
113+
// Update graphic objects and render the view if requested.
114+
virtual void Update(bool render = true);
115115

116116
// Description:
117117
// Get the current renderer

Libs/VTK/Widgets/msvVTKButtonsManager.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class vtkCameraCallback : public vtkCommand
114114
this->MoveOverlappingButtons();
115115
}
116116
toolButton->SetOpacity(1-opacity);
117+
toolButton->Update(false);
117118
}
118119
}
119120
}

0 commit comments

Comments
 (0)