Commit 805ad16d authored by Julien Finet's avatar Julien Finet
Browse files

Delete current point when "del" is typed in vtkControlPoints

When the "Delete" or "Backspace" keys are typed, it deletes the current
point.

Change-Id: I03765ce084a6850ad9c377208dfece7ef6d9f64d
parent ccbc3c55
......@@ -59,7 +59,7 @@ int TestColorTransferFunction(int , char * [])
// Finally render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(1);
if (view->GetContext()->GetDevice()->IsA("vtkOpenGL2ContextDevice2D"))
if (view->GetContext()->GetDevice()->IsA("vtkOpenGLContextDevice2D"))
{
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
......
......@@ -16,6 +16,7 @@
#include "vtkBrush.h"
#include "vtkCallbackCommand.h"
#include "vtkContext2D.h"
#include "vtkContextKeyEvent.h"
#include "vtkContextMouseEvent.h"
#include "vtkContextScene.h"
#include "vtkControlPointsItem.h"
......@@ -23,6 +24,7 @@
#include "vtkObjectFactory.h"
#include "vtkPen.h"
#include "vtkPoints2D.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkTransform2D.h"
......@@ -626,6 +628,14 @@ vtkIdType vtkControlPointsItem::RemovePoint(double* point)
return this->RemovePointId(this->GetControlPointId(point));
}
//-----------------------------------------------------------------------------
vtkIdType vtkControlPointsItem::RemovePoint(vtkIdType pointId)
{
double point[4];
this->GetControlPoint(pointId, point);
return this->RemovePoint(point);
}
//-----------------------------------------------------------------------------
vtkIdType vtkControlPointsItem::RemovePointId(vtkIdType pointId)
{
......@@ -1056,3 +1066,25 @@ bool vtkControlPointsItem::MouseButtonReleaseEvent(const vtkContextMouseEvent &m
}
return false;
}
//-----------------------------------------------------------------------------
bool vtkControlPointsItem::KeyPressEvent(const vtkContextKeyEvent &key)
{
return this->Superclass::KeyPressEvent(key);
}
//-----------------------------------------------------------------------------
bool vtkControlPointsItem::KeyReleaseEvent(const vtkContextKeyEvent &key)
{
if (key.GetInteractor()->GetKeySym() == std::string("Delete") ||
key.GetInteractor()->GetKeySym() == std::string("BackSpace"))
{
vtkIdType removedPoint = this->RemovePoint(this->GetCurrentPoint());
if (key.GetInteractor()->GetKeySym() == std::string("BackSpace"))
{
this->SetCurrentPoint(removedPoint > 0 ? removedPoint - 1 : 0);
}
return true;
}
return this->Superclass::KeyPressEvent(key);
}
......@@ -146,6 +146,15 @@ public:
// Subclasses should reimplement this function to do the actual work.
virtual vtkIdType RemovePoint(double* pos) = 0;
// Description:
// Remove a point give its id. It is a utility function that internally call
// the virtual method RemovePoint(double*) and return its result.
vtkIdType RemovePoint(vtkIdType pointId);
// Description:
// Remove the current point.
inline void RemoveCurrentPoint();
// Description:
// Returns the total number of points
virtual int GetNumberOfPoints()const = 0;
......@@ -172,6 +181,9 @@ public:
// You shouldn't have to call it but it is provided for rare cases.
void ResetBounds();
virtual bool KeyPressEvent(const vtkContextKeyEvent &key);
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key);
protected:
vtkControlPointsItem();
virtual ~vtkControlPointsItem();
......@@ -248,4 +260,10 @@ private:
vtkIdType RemovePointId(vtkIdType removedPointId);
};
//-----------------------------------------------------------------------------
void vtkControlPointsItem::RemoveCurrentPoint()
{
this->RemovePoint(this->GetCurrentPoint());
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment