VTK
dox/Charts/Core/vtkControlPointsItem.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkControlPointsItem.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00030 #ifndef __vtkControlPointsItem_h
00031 #define __vtkControlPointsItem_h
00032 
00033 #include "vtkChartsCoreModule.h" // For export macro
00034 #include "vtkCommand.h" // For vtkCommand enum
00035 #include "vtkPlot.h"
00036 #include "vtkVector.h" // For vtkVector2f
00037 
00038 class vtkCallbackCommand;
00039 class vtkContext2D;
00040 class vtkPoints2D;
00041 class vtkTransform2D;
00042 
00043 class VTKCHARTSCORE_EXPORT vtkControlPointsItem: public vtkPlot
00044 {
00045 public:
00046   vtkTypeMacro(vtkControlPointsItem, vtkPlot);
00047   virtual void PrintSelf(ostream &os, vtkIndent indent);
00048 
00049   enum {
00050     CurrentPointChangedEvent = vtkCommand::UserEvent,
00051     CurrentPointEditEvent
00052   };
00053 
00056   virtual void GetBounds(double bounds[4]);
00057 
00059 
00062   vtkSetVector4Macro(UserBounds, double);
00063   vtkGetVector4Macro(UserBounds, double);
00065 
00067 
00070   vtkSetVector4Macro(ValidBounds, double);
00071   vtkGetVector4Macro(ValidBounds, double);
00073 
00075 
00076   vtkGetMacro(ScreenPointRadius, float);
00077   vtkSetMacro(ScreenPointRadius, float);
00079 
00083   virtual bool Paint(vtkContext2D *painter);
00084 
00086   void SelectPoint(vtkIdType pointId);
00087 
00091   void SelectPoint(double* currentPoint);
00092 
00094   void SelectAllPoints();
00095 
00097   void DeselectPoint(vtkIdType pointId);
00098 
00102   void DeselectPoint(double* currentPoint);
00103 
00105   void DeselectAllPoints();
00106 
00109   void ToggleSelectPoint(vtkIdType pointId);
00110 
00114   void ToggleSelectPoint(double* currentPoint);
00115 
00117   virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
00118 
00120   vtkIdType GetNumberOfSelectedPoints()const;
00121 
00124   vtkIdType FindPoint(double* pos);
00125 
00129   bool IsOverPoint(double* pos, vtkIdType pointId);
00130 
00133   vtkIdType GetControlPointId(double* pos);
00134 
00136 
00139   void GetControlPointsIds(vtkIdTypeArray* ids,
00140                            bool excludeFirstAndLast = false)const;
00142 
00144 
00146   vtkGetMacro(StrokeMode, bool);
00148 
00150 
00154   vtkSetMacro(SwitchPointsMode, bool);
00155   vtkGetMacro(SwitchPointsMode, bool);
00157 
00159 
00161   vtkSetMacro(EndPointsXMovable, bool);
00162   vtkGetMacro(EndPointsXMovable, bool);
00163   vtkSetMacro(EndPointsYMovable, bool);
00164   vtkGetMacro(EndPointsYMovable, bool);
00165   virtual bool GetEndPointsMovable();
00167 
00169 
00171   vtkSetMacro(EndPointsRemovable, bool);
00172   vtkGetMacro(EndPointsRemovable, bool);
00174 
00178   virtual vtkIdType AddPoint(double* newPos) = 0;
00179 
00183   virtual vtkIdType RemovePoint(double* pos) = 0;
00184 
00187   vtkIdType RemovePoint(vtkIdType pointId);
00188 
00190   inline void RemoveCurrentPoint();
00191 
00193   virtual vtkIdType GetNumberOfPoints()const = 0;
00194 
00198   virtual void GetControlPoint(vtkIdType index, double *point)const = 0;
00199 
00202   virtual void SetControlPoint(vtkIdType index, double *point) = 0;
00203 
00210   void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
00211 
00215   void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
00216 
00223   void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
00224 
00228   void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
00229 
00232   vtkIdType GetCurrentPoint()const;
00233 
00235   void SetCurrentPoint(vtkIdType index);
00236 
00238 
00239   vtkGetObjectMacro(SelectedPointPen, vtkPen);
00241 
00243 
00245   vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
00247 
00250   void ResetBounds();
00251 
00253 
00254   virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
00255   virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse);
00257 
00259   virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
00260 
00261   virtual bool KeyPressEvent(const vtkContextKeyEvent &key);
00262   virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key);
00263 
00264 protected:
00265   vtkControlPointsItem();
00266   virtual ~vtkControlPointsItem();
00267 
00268   void StartChanges();
00269   void EndChanges();
00270   void StartInteraction();
00271   void StartInteractionIfNotStarted();
00272   void Interaction();
00273   void EndInteraction();
00274   int GetInteractionsCount()const;
00275   virtual void emitEvent(unsigned long event, void* params = 0) = 0;
00276 
00277   static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params);
00278 
00280 
00282   virtual void ComputePoints();
00283   virtual unsigned long int GetControlPointsMTime() =0;
00285 
00287   virtual bool Hit(const vtkContextMouseEvent &mouse);
00288 
00290 
00292   bool ClampPos(double pos[2], double bounds[4]);
00293   bool ClampValidPos(double pos[2]);
00295 
00297 
00299   void DrawUnselectedPoints(vtkContext2D* painter);
00300   void DrawSelectedPoints(vtkContext2D* painter);
00301   virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
00303 
00304   void SetCurrentPointPos(const vtkVector2f& newPos);
00305   vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
00306   void MoveCurrentPoint(const vtkVector2f& translation);
00307   vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
00308 
00309   inline vtkVector2f GetSelectionCenterOfMass()const;
00310   vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const;
00311 
00312   void Stroke(const vtkVector2f& newPos);
00313   virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
00315   virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
00316 
00317   void AddPointId(vtkIdType addedPointId);
00318 
00321   bool IsEndPointPicked();
00322 
00324   bool IsPointRemovable(vtkIdType pointId);
00325 
00326   vtkCallbackCommand* Callback;
00327   vtkPen*             SelectedPointPen;
00328   vtkBrush*           SelectedPointBrush;
00329   int                 BlockUpdates;
00330   int                 StartedInteractions;
00331   vtkIdType           CurrentPoint;
00332 
00333   double              Bounds[4];
00334   double              UserBounds[4];
00335   double              ValidBounds[4];
00336 
00337   vtkTransform2D*     Transform;
00338   float               ScreenPointRadius;
00339 
00340   bool                StrokeMode;
00341   bool                SwitchPointsMode;
00342   bool                MouseMoved;
00343   bool                EnforceValidFunction;
00344   vtkIdType           PointToDelete;
00345   bool                PointAboutToBeDeleted;
00346   vtkIdType           PointToToggle;
00347   bool                PointAboutToBeToggled;
00348   bool                InvertShadow;
00349   bool                EndPointsXMovable;
00350   bool                EndPointsYMovable;
00351   bool                EndPointsRemovable;
00352 private:
00353   vtkControlPointsItem(const vtkControlPointsItem &); // Not implemented.
00354   void operator=(const vtkControlPointsItem &);   // Not implemented.
00355 
00356   void      ComputeBounds();
00357   void      ComputeBounds(double* bounds);
00358 
00359   vtkIdType RemovePointId(vtkIdType removedPointId);
00360 };
00361 
00362 //-----------------------------------------------------------------------------
00363 void vtkControlPointsItem::RemoveCurrentPoint()
00364 {
00365   this->RemovePoint(this->GetCurrentPoint());
00366 }
00367 
00368 //-----------------------------------------------------------------------------
00369 vtkVector2f vtkControlPointsItem::GetSelectionCenterOfMass()const
00370 {
00371   return this->GetCenterOfMass(this->Selection);
00372 }
00373 
00374 #endif