vtkPiecewisePointHandleItem.h 3.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPiecewisePointHandleItem.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

16 17 18 19 20 21 22 23 24 25
/**
 * @class   vtkPiecewisePointHandleItem
 * @brief   a vtkContextItem that draws handles
 *       around a point of a piecewise function
 *
 *
 * This is a vtkContextItem that can be placed into a vtkContextScene. It draws
 * handles around a given point of a piecewise function so that the curve can
 * be adjusted using these handles.
*/
26

27 28
#ifndef vtkPiecewisePointHandleItem_h
#define vtkPiecewisePointHandleItem_h
29

30
#include "vtkChartsCoreModule.h" // For export macro
31 32 33 34 35 36 37 38
#include "vtkContextItem.h"
#include "vtkWeakPointer.h" // Needed for weak pointer to the PiecewiseFunction.

class vtkContext2D;
class vtkPiecewiseFunction;
class vtkCallbackCommand;
class vtkAbstractContextItem;

39
class VTKCHARTSCORE_EXPORT vtkPiecewisePointHandleItem : public vtkContextItem
40 41 42
{
public:
  vtkTypeMacro(vtkPiecewisePointHandleItem, vtkContextItem);
43
  void PrintSelf(ostream &os, vtkIndent indent) override;
44 45 46 47

  static vtkPiecewisePointHandleItem *New();
  static void CallRedraw(vtkObject* sender, unsigned long event, void* receiver, void* params);

48 49 50
  /**
   * Set the parent item, which should be a vtkControlPointItem
   */
51
  void SetParent(vtkAbstractContextItem *parent) override;
52

53 54 55
  /**
   * Paint event for the item.
   */
56
  bool Paint(vtkContext2D *painter) override;
57

58 59 60 61
  //@{
  /**
   * The current point id in the piecewise function being handled.
   */
62 63
  vtkSetMacro(CurrentPointIndex, vtkIdType);
  vtkGetMacro(CurrentPointIndex, vtkIdType);
64
  //@}
65

66 67 68 69
  //@{
  /**
   * Set the PieceWiseFunction the handles will manipulate
   */
70 71
  virtual void SetPiecewiseFunction(vtkPiecewiseFunction* piecewiseFunc);
  vtkWeakPointer<vtkPiecewiseFunction> GetPiecewiseFunction();
72
  //@}
73

74 75 76 77
  /**
   * Returns the index of the handle if pos is over any of the handles,
   * otherwise return -1;
   */
78 79
  int IsOverHandle(float* pos);

80 81 82
  /**
   * Returns true if the supplied x, y coordinate is inside the item.
   */
83
  bool Hit(const vtkContextMouseEvent &mouse) override;
84

85 86 87
  /**
   * Mouse move event.
   */
88
  bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override;
89

90 91 92
  /**
   * Mouse button down event.
   */
93
  bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override;
94

95 96 97
  /**
   * Mouse button release event.
   */
98
  bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override;
99 100 101

protected:
  vtkPiecewisePointHandleItem();
102
  ~vtkPiecewisePointHandleItem() override;
103

104 105 106
  /**
   * Redraw all the handles
   */
107 108 109 110 111 112 113 114 115 116
  virtual void Redraw();

  int MouseOverHandleIndex;
  vtkIdType CurrentPointIndex;
  float HandleRadius;

  vtkWeakPointer<vtkPiecewiseFunction> PiecewiseFunction;
  vtkCallbackCommand* Callback;

private:
117 118
  vtkPiecewisePointHandleItem(const vtkPiecewisePointHandleItem &) = delete;
  void operator=(const vtkPiecewisePointHandleItem &) = delete;
119 120 121

  class InternalPiecewisePointHandleInfo;
  InternalPiecewisePointHandleInfo* Internal;
122

123 124
};

125
#endif //vtkPiecewisePointHandleItem_h