1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_PROJECT_BGI_PLANE_H
21 #define LIBREPCB_PROJECT_BGI_PLANE_H
22 
23 /*******************************************************************************
24  *  Includes
25  ******************************************************************************/
26 #include "bgi_base.h"
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 /*******************************************************************************
32  *  Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 class Path;
37 class Polygon;
38 class GraphicsLayer;
39 
40 namespace project {
41 
42 class BI_Plane;
43 
44 /*******************************************************************************
45  *  Class BGI_Plane
46  ******************************************************************************/
47 
48 /**
49  * @brief The BGI_Plane class
50  */
51 class BGI_Plane final : public BGI_Base {
52 public:
53   // Constructors / Destructor
54   BGI_Plane() = delete;
55   BGI_Plane(const BGI_Plane& other) = delete;
56   explicit BGI_Plane(BI_Plane& plane) noexcept;
57   ~BGI_Plane() noexcept;
58 
59   // Getters
60   bool isSelectable() const noexcept;
61 
62   /// Get the line segment at a specific position
63   ///
64   /// @param pos    The position to check for lines.
65   /// @return       The index of the vertex *after* the line under the cursor.
66   ///               So for the first line segment, index 1 is returned. If no
67   ///               line is located under the specified position, -1 is
68   ///               returned.
69   int getLineIndexAtPosition(const Point& pos) const noexcept;
70 
71   /// Get the vertices at a specific position
72   ///
73   /// @param pos    The position to check for vertices.
74   /// @return       All indices of the vertices at the specified position.
75   QVector<int> getVertexIndicesAtPosition(const Point& pos) const noexcept;
76 
77   // General Methods
78   void updateCacheAndRepaint() noexcept;
79 
80   // Inherited from QGraphicsItem
boundingRect()81   QRectF boundingRect() const noexcept { return mBoundingRect; }
shape()82   QPainterPath shape() const noexcept { return mShape; }
83   void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
84              QWidget* widget = 0);
85 
86   // Operator Overloadings
87   BGI_Plane& operator=(const BGI_Plane& rhs) = delete;
88 
89 private:
90   // Private Methods
91   GraphicsLayer* getLayer(QString name) const noexcept;
92 
93   // General Attributes
94   BI_Plane& mPlane;
95 
96   // Cached Attributes
97   GraphicsLayer* mLayer;
98   QRectF mBoundingRect;
99   QPainterPath mShape;
100   QPainterPath mOutline;
101   QVector<QPainterPath> mAreas;
102   qreal mLineWidthPx;
103   qreal mVertexRadiusPx;
104 };
105 
106 /*******************************************************************************
107  *  End of File
108  ******************************************************************************/
109 
110 }  // namespace project
111 }  // namespace librepcb
112 
113 #endif  // LIBREPCB_PROJECT_BGI_PLANE_H
114