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_LIBRARY_SYMBOLGRAPHICSITEM_H
21 #define LIBREPCB_LIBRARY_SYMBOLGRAPHICSITEM_H
22 
23 /*******************************************************************************
24  *  Includes
25  ******************************************************************************/
26 #include <librepcb/common/units/all_length_units.h>
27 #include <librepcb/common/uuid.h>
28 
29 #include <QtCore>
30 #include <QtWidgets>
31 
32 /*******************************************************************************
33  *  Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 class Circle;
38 class Polygon;
39 class Text;
40 class IF_GraphicsLayerProvider;
41 class PolygonGraphicsItem;
42 class CircleGraphicsItem;
43 class TextGraphicsItem;
44 
45 namespace library {
46 
47 class Symbol;
48 class SymbolPin;
49 class SymbolPinGraphicsItem;
50 
51 /*******************************************************************************
52  *  Class SymbolGraphicsItem
53  ******************************************************************************/
54 
55 /**
56  * @brief The SymbolGraphicsItem class
57  */
58 class SymbolGraphicsItem final : public QGraphicsItem {
59 public:
60   // Constructors / Destructor
61   SymbolGraphicsItem() = delete;
62   SymbolGraphicsItem(const SymbolGraphicsItem& other) = delete;
63   SymbolGraphicsItem(Symbol& symbol,
64                      const IF_GraphicsLayerProvider& lp) noexcept;
65   ~SymbolGraphicsItem() noexcept;
66 
67   // Getters
68   SymbolPinGraphicsItem* getPinGraphicsItem(const Uuid& pin) noexcept;
69   CircleGraphicsItem* getCircleGraphicsItem(const Circle& circle) noexcept;
70   PolygonGraphicsItem* getPolygonGraphicsItem(const Polygon& polygon) noexcept;
71   TextGraphicsItem* getTextGraphicsItem(const Text& text) noexcept;
72   int getItemsAtPosition(
73       const Point& pos, QList<QSharedPointer<SymbolPinGraphicsItem>>* pins,
74       QList<QSharedPointer<CircleGraphicsItem>>* circles,
75       QList<QSharedPointer<PolygonGraphicsItem>>* polygons,
76       QList<QSharedPointer<TextGraphicsItem>>* texts) noexcept;
77   QList<QSharedPointer<SymbolPinGraphicsItem>> getSelectedPins() noexcept;
78   QList<QSharedPointer<CircleGraphicsItem>> getSelectedCircles() noexcept;
79   QList<QSharedPointer<PolygonGraphicsItem>> getSelectedPolygons() noexcept;
80   QList<QSharedPointer<TextGraphicsItem>> getSelectedTexts() noexcept;
81 
82   // Setters
83   void setPosition(const Point& pos) noexcept;
84   void setRotation(const Angle& rot) noexcept;
85 
86   // General Methods
87   void addPin(SymbolPin& pin) noexcept;
88   void removePin(SymbolPin& pin) noexcept;
89   void addCircle(Circle& circle) noexcept;
90   void removeCircle(Circle& circle) noexcept;
91   void addPolygon(Polygon& polygon) noexcept;
92   void removePolygon(Polygon& polygon) noexcept;
93   void addText(Text& text) noexcept;
94   void removeText(Text& text) noexcept;
95   void setSelectionRect(const QRectF rect) noexcept;
96 
97   // Inherited from QGraphicsItem
boundingRect()98   QRectF boundingRect() const noexcept override { return QRectF(); }
shape()99   QPainterPath shape() const noexcept override { return QPainterPath(); }
100   void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
101              QWidget* widget = 0) noexcept override;
102 
103   // Operator Overloadings
104   SymbolGraphicsItem& operator=(const SymbolGraphicsItem& rhs) = delete;
105 
106 private:  // Data
107   Symbol& mSymbol;
108   const IF_GraphicsLayerProvider& mLayerProvider;
109   QHash<Uuid, QSharedPointer<SymbolPinGraphicsItem>> mPinGraphicsItems;
110   QHash<const Circle*, QSharedPointer<CircleGraphicsItem>> mCircleGraphicsItems;
111   QHash<const Polygon*, QSharedPointer<PolygonGraphicsItem>>
112       mPolygonGraphicsItems;
113   QHash<const Text*, QSharedPointer<TextGraphicsItem>> mTextGraphicsItems;
114 };
115 
116 /*******************************************************************************
117  *  End of File
118  ******************************************************************************/
119 
120 }  // namespace library
121 }  // namespace librepcb
122 
123 #endif  // LIBREPCB_LIBRARY_SYMBOLGRAPHICSITEM_H
124