VTK
|
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 // Events fires by this class (and subclasses). 00050 // \li CurrentPointChangedEvent is fired when the current point index is changed. 00051 // \li CurrentPointEditEvent is fired to request the application to show UI to 00052 // edit the current point. 00053 // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired 00054 // to mark groups of changes to control points. 00055 enum { 00056 CurrentPointChangedEvent = vtkCommand::UserEvent, 00057 CurrentPointEditEvent, 00058 }; 00059 00062 virtual void GetBounds(double bounds[4]); 00063 00065 00068 vtkSetVector4Macro(UserBounds, double); 00069 vtkGetVector4Macro(UserBounds, double); 00071 00073 00076 vtkSetVector4Macro(ValidBounds, double); 00077 vtkGetVector4Macro(ValidBounds, double); 00079 00081 00082 vtkGetMacro(ScreenPointRadius, float); 00083 vtkSetMacro(ScreenPointRadius, float); 00085 00089 virtual bool Paint(vtkContext2D *painter); 00090 00092 void SelectPoint(vtkIdType pointId); 00093 00097 void SelectPoint(double* currentPoint); 00098 00100 void SelectAllPoints(); 00101 00103 void DeselectPoint(vtkIdType pointId); 00104 00108 void DeselectPoint(double* currentPoint); 00109 00111 void DeselectAllPoints(); 00112 00115 void ToggleSelectPoint(vtkIdType pointId); 00116 00120 void ToggleSelectPoint(double* currentPoint); 00121 00123 virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max); 00124 00126 vtkIdType GetNumberOfSelectedPoints()const; 00127 00130 vtkIdType FindPoint(double* pos); 00131 00135 bool IsOverPoint(double* pos, vtkIdType pointId); 00136 00139 vtkIdType GetControlPointId(double* pos); 00140 00142 00145 void GetControlPointsIds(vtkIdTypeArray* ids, 00146 bool excludeFirstAndLast = false)const; 00148 00150 00152 vtkGetMacro(StrokeMode, bool); 00154 00156 00160 vtkSetMacro(SwitchPointsMode, bool); 00161 vtkGetMacro(SwitchPointsMode, bool); 00163 00165 00167 vtkSetMacro(EndPointsXMovable, bool); 00168 vtkGetMacro(EndPointsXMovable, bool); 00169 vtkSetMacro(EndPointsYMovable, bool); 00170 vtkGetMacro(EndPointsYMovable, bool); 00171 virtual bool GetEndPointsMovable(); 00173 00175 00177 vtkSetMacro(EndPointsRemovable, bool); 00178 vtkGetMacro(EndPointsRemovable, bool); 00180 00182 00184 vtkSetMacro(ShowLabels, bool); 00185 vtkGetMacro(ShowLabels, bool); 00187 00189 00190 vtkSetStringMacro(LabelFormat); 00191 vtkGetStringMacro(LabelFormat); 00193 00197 virtual vtkIdType AddPoint(double* newPos) = 0; 00198 00202 virtual vtkIdType RemovePoint(double* pos) = 0; 00203 00206 vtkIdType RemovePoint(vtkIdType pointId); 00207 00209 inline void RemoveCurrentPoint(); 00210 00212 virtual vtkIdType GetNumberOfPoints()const = 0; 00213 00217 virtual void GetControlPoint(vtkIdType index, double *point)const = 0; 00218 00221 virtual void SetControlPoint(vtkIdType index, double *point) = 0; 00222 00229 void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds); 00230 00234 void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false); 00235 00242 void SpreadPoints(float factor, vtkIdTypeArray* pointIds); 00243 00247 void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false); 00248 00251 vtkIdType GetCurrentPoint()const; 00252 00254 void SetCurrentPoint(vtkIdType index); 00255 00257 00258 vtkGetObjectMacro(SelectedPointPen, vtkPen); 00260 00262 00264 vtkGetObjectMacro(SelectedPointBrush, vtkBrush); 00266 00269 void ResetBounds(); 00270 00272 00273 virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse); 00274 virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse); 00276 00278 virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse); 00279 00280 virtual bool KeyPressEvent(const vtkContextKeyEvent &key); 00281 virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key); 00282 00283 protected: 00284 vtkControlPointsItem(); 00285 virtual ~vtkControlPointsItem(); 00286 00287 void StartChanges(); 00288 void EndChanges(); 00289 void StartInteraction(); 00290 void StartInteractionIfNotStarted(); 00291 void Interaction(); 00292 void EndInteraction(); 00293 int GetInteractionsCount()const; 00294 virtual void emitEvent(unsigned long event, void* params = 0) = 0; 00295 00296 static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params); 00297 00299 00301 virtual void ComputePoints(); 00302 virtual unsigned long int GetControlPointsMTime() =0; 00304 00306 virtual bool Hit(const vtkContextMouseEvent &mouse); 00307 00309 00311 virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out); 00312 virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out); 00314 00316 00318 bool ClampPos(double pos[2], double bounds[4]); 00319 bool ClampValidPos(double pos[2]); 00321 00323 00325 void DrawUnselectedPoints(vtkContext2D* painter); 00326 void DrawSelectedPoints(vtkContext2D* painter); 00327 virtual void DrawPoint(vtkContext2D* painter, vtkIdType index); 00329 00330 void SetCurrentPointPos(const vtkVector2f& newPos); 00331 vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos); 00332 void MoveCurrentPoint(const vtkVector2f& translation); 00333 vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation); 00334 00335 inline vtkVector2f GetSelectionCenterOfMass()const; 00336 vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const; 00337 00338 void Stroke(const vtkVector2f& newPos); 00339 virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY)); 00341 virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse); 00342 00344 virtual vtkStdString GetControlPointLabel(vtkIdType index); 00345 00346 void AddPointId(vtkIdType addedPointId); 00347 00350 bool IsEndPointPicked(); 00351 00353 bool IsPointRemovable(vtkIdType pointId); 00354 00360 virtual void ComputeBounds(double* bounds); 00361 00365 virtual bool UsingLogScale() { return false; } 00366 00367 vtkCallbackCommand* Callback; 00368 vtkPen* SelectedPointPen; 00369 vtkBrush* SelectedPointBrush; 00370 int BlockUpdates; 00371 int StartedInteractions; 00372 int StartedChanges; 00373 vtkIdType CurrentPoint; 00374 00375 double Bounds[4]; 00376 double UserBounds[4]; 00377 double ValidBounds[4]; 00378 00379 vtkTransform2D* Transform; 00380 float ScreenPointRadius; 00381 00382 bool StrokeMode; 00383 bool SwitchPointsMode; 00384 bool MouseMoved; 00385 bool EnforceValidFunction; 00386 vtkIdType PointToDelete; 00387 bool PointAboutToBeDeleted; 00388 vtkIdType PointToToggle; 00389 bool PointAboutToBeToggled; 00390 bool InvertShadow; 00391 bool EndPointsXMovable; 00392 bool EndPointsYMovable; 00393 bool EndPointsRemovable; 00394 bool ShowLabels; 00395 char* LabelFormat; 00396 private: 00397 vtkControlPointsItem(const vtkControlPointsItem &); // Not implemented. 00398 void operator=(const vtkControlPointsItem &); // Not implemented. 00399 00400 void ComputeBounds(); 00401 00402 vtkIdType RemovePointId(vtkIdType removedPointId); 00403 }; 00404 00405 //----------------------------------------------------------------------------- 00406 void vtkControlPointsItem::RemoveCurrentPoint() 00407 { 00408 this->RemovePoint(this->GetCurrentPoint()); 00409 } 00410 00411 //----------------------------------------------------------------------------- 00412 vtkVector2f vtkControlPointsItem::GetSelectionCenterOfMass()const 00413 { 00414 return this->GetCenterOfMass(this->Selection); 00415 } 00416 00417 #endif