ACF $AcfVersion:0$
CLineShape.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5#include <i2d/CVector2d.h>
6#include <i2d/CLine2d.h>
7
9
10
11namespace iview
12{
13
14
16{
17public:
19
21
27
31 int GetLineDisplayMode() const;
35 void SetLineDisplayMode(int mode);
36
46 void SetArrowLinesProportion(double value);
47
52 double GetMaxArrowLineLength() const;
57 void SetMaxArrowLineLength(double value);
58
59 // reimplemented (iview::CInteractiveShapeBase)
60 virtual void InvalidateBoundingBox() override;
61
62 // reimplemented (iview::ITouchable)
63 virtual TouchState IsTouched(istd::CIndex2d position) const override;
64
65 // reimplemented (iview::IVisualizable)
66 virtual void Draw(QPainter& drawContext) const override;
67
68 // reimplemented (imod::IObserver)
69 virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask) override;
70
71 // reimplemented (iview::IMouseActionObserver)
72 virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag) override;
73 virtual bool OnMouseMove(istd::CIndex2d position) override;
74
75protected:
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 override;
83
84 // reimplemented (iview::CInteractiveShapeBase)
85 virtual void BeginLogDrag(const i2d::CVector2d& reference) override;
86 virtual void SetLogDragPosition(const i2d::CVector2d& position) override;
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
123inline 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
136
Definition of a line in 2D-space.
Definition CLine2d.h:25
Simple rectangle with integer bounds.
Definition CRect.h:22
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
imod::IModel * GetObservedModel() const
Get access to observed model.
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:21
Set of change flags (its IDs).
Definition IChangeable.h:36
virtual void BeginLogDrag(const i2d::CVector2d &reference) override
CInteractiveShapeBase BaseClass
Definition CLineShape.h:18
virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag) override
It is called, when mouse button is pushed down or up on this object.
void SetLineDisplayMode(int mode)
Set display mode of this line.
virtual bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
Callback invoked when an observable model is about to be attached to this observer.
virtual void InvalidateBoundingBox() override
Invalidate bounding box.
virtual TouchState IsTouched(istd::CIndex2d position) const override
Check, if any shape is touched.
int GetLineDisplayMode() const
Get displayed of line.
double GetMaxArrowLineLength() const
Get maximal length of arrow lines.
void SetArrowLinesProportion(double value)
Set proportion of arrow side lines to line length.
void SetMaxArrowLineLength(double value)
Set maximal length of arrow lines.
virtual bool OnMouseMove(istd::CIndex2d position) override
It is called, when mouse is moved.
void CalcPoints(const i2d::CLine2d &line) const
void EnsurePointsAreValid() const
Definition CLineShape.h:108
double GetArrowLinesProportion() const
Get proportion of arrow side lines to line length.
istd::CIndex2d m_points[4]
Definition CLineShape.h:101
static bool CheckLine(const istd::CIndex2d &firstPoint, const istd::CIndex2d &secondPoint, const istd::CIndex2d &point, double maxDistance)
double m_arrowLinesProportion
Definition CLineShape.h:96
virtual void Draw(QPainter &drawContext) const override
Draw this shape using draw context.
i2d::CVector2d m_referencePosition
Definition CLineShape.h:99
virtual void SetLogDragPosition(const i2d::CVector2d &position) override
void ResetPoints() const
double m_maxArrowLineLength
Definition CLineShape.h:97
virtual i2d::CRect CalcBoundingBox() const override
Calculate bounding box.
TouchState
Enumeration for possible shape touch states.
Definition ITouchable.h:25
#define NULL
Definition istd.h:74
In this library is defined 2D view concept and standard visualisation objects.