CLineShape.h
Go to the documentation of this file.
1 #ifndef iview_CLineShape_included
2 #define iview_CLineShape_included
3 
4 
5 #include <i2d/CVector2d.h>
6 #include <i2d/CLine2d.h>
7 
9 
10 
11 namespace iview
12 {
13 
14 
16 {
17 public:
19 
20  CLineShape();
21 
23  {
26  };
27 
31  int GetLineDisplayMode() const;
35  void SetLineDisplayMode(int mode);
36 
41  double GetArrowLinesProportion() const;
46  void SetArrowLinesProportion(double value);
47 
52  double GetMaxArrowLineLength() const;
57  void SetMaxArrowLineLength(double value);
58 
59  // reimplemented (iview::CInteractiveShapeBase)
60  virtual void InvalidateBoundingBox();
61 
62  // reimplemented (iview::ITouchable)
63  virtual TouchState IsTouched(istd::CIndex2d position) const;
64 
65  // reimplemented (iview::IVisualizable)
66  virtual void Draw(QPainter& drawContext) const;
67 
68  // reimplemented (imod::IObserver)
69  virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask);
70 
71  // reimplemented (iview::IMouseActionObserver)
72  virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag);
73  virtual bool OnMouseMove(istd::CIndex2d position);
74 
75 protected:
76  void EnsurePointsAreValid() const;
77  void EnsurePointsAreValid(const i2d::CLine2d& line) const;
78  void CalcPoints(const i2d::CLine2d& line) const;
79  void ResetPoints() const;
80 
81  // reimplemented (iview::CShapeBase)
82  virtual i2d::CRect CalcBoundingBox() const;
83 
84  // reimplemented (iview::CInteractiveShapeBase)
85  virtual void BeginLogDrag(const i2d::CVector2d& reference);
86  virtual void SetLogDragPosition(const i2d::CVector2d& position);
87 
88  // static methods
89  static bool CheckLine(
90  const istd::CIndex2d& firstPoint,
91  const istd::CIndex2d& secondPoint,
92  const istd::CIndex2d& point,
93  double maxDistance);
94 
98 
102  mutable bool m_arePointsValid;
103 };
104 
105 
106 // inline methods
107 
109 {
110  if (!m_arePointsValid){
111  const i2d::CLine2d* linePtr = dynamic_cast<const i2d::CLine2d*>(GetObservedModel());
112  if (linePtr != NULL){
113  CalcPoints(*linePtr);
114  }
115  else{
116  ResetPoints();
117  }
118  m_arePointsValid = true;
119  }
120 }
121 
122 
123 inline void CLineShape::EnsurePointsAreValid(const i2d::CLine2d& line) const
124 {
125  if (!m_arePointsValid){
126  CalcPoints(line);
127  m_arePointsValid = true;
128  }
129 }
130 
131 
132 } // namespace iview
133 
134 
135 #endif // !iview_CLineShape_included
136 
137 
virtual bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask)
This call back function will be called, if an observable object is about to be attached.
void ResetPoints() const
virtual void BeginLogDrag(const i2d::CVector2d &reference)
i2d::CVector2d m_referencePosition
Definition: CLineShape.h:99
double GetMaxArrowLineLength() const
Get maximal length of arrow lines.
virtual TouchState IsTouched(istd::CIndex2d position) const
Check, if any shape is touched.
void SetMaxArrowLineLength(double value)
Set maximal length of arrow lines.
double m_maxArrowLineLength
Definition: CLineShape.h:97
Definition of a line in 2D-space.
Definition: CLine2d.h:24
virtual void Draw(QPainter &drawContext) const
Draw this shape using draw context.
Simple rectangle with integer bounds.
Definition: CRect.h:21
Index implementation for addressing elements in 2D-space.
Definition: CIndex2d.h:20
virtual bool OnMouseMove(istd::CIndex2d position)
It is called, when mouse is moved.
double m_arrowLinesProportion
Definition: CLineShape.h:96
imod::IModel * GetObservedModel() const
Get access to observed model.
static bool CheckLine(const istd::CIndex2d &firstPoint, const istd::CIndex2d &secondPoint, const istd::CIndex2d &point, double maxDistance)
void SetLineDisplayMode(int mode)
Set display mode of this line.
Definition of position or mathematical vector on 2D plane.
Definition: CVector2d.h:28
void SetArrowLinesProportion(double value)
Set proportion of arrow side lines to line length.
void EnsurePointsAreValid() const
Definition: CLineShape.h:108
#define NULL
Definition: istd.h:64
virtual void InvalidateBoundingBox()
Invalidate bounding box.
TouchState
Enumeration for possible shape touch states.
Definition: ITouchable.h:24
int GetLineDisplayMode() const
Get displayed of line.
CInteractiveShapeBase BaseClass
Definition: CLineShape.h:18
double GetArrowLinesProportion() const
Get proportion of arrow side lines to line length.
virtual i2d::CRect CalcBoundingBox() const
Calculate bounding box.
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
Set of change flags (its IDs).
Definition: IChangeable.h:30
void CalcPoints(const i2d::CLine2d &line) const
istd::CIndex2d m_points[4]
Definition: CLineShape.h:101
virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag)
It is called, when mouse button is pushed down or up on this object.
virtual void SetLogDragPosition(const i2d::CVector2d &position)

© 2007-2017 Witold Gantzke and Kirill Lepskiy