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_FOOTPRINTGRAPHICSITEM_H 21 #define LIBREPCB_LIBRARY_FOOTPRINTGRAPHICSITEM_H 22 23 /******************************************************************************* 24 * Includes 25 ******************************************************************************/ 26 #include "../pkg/packagepad.h" 27 28 #include <librepcb/common/units/all_length_units.h> 29 #include <librepcb/common/uuid.h> 30 31 #include <QtCore> 32 #include <QtWidgets> 33 34 /******************************************************************************* 35 * Namespace / Forward Declarations 36 ******************************************************************************/ 37 namespace librepcb { 38 39 class Circle; 40 class Polygon; 41 class StrokeText; 42 class Hole; 43 class IF_GraphicsLayerProvider; 44 class PolygonGraphicsItem; 45 class CircleGraphicsItem; 46 class StrokeTextGraphicsItem; 47 class HoleGraphicsItem; 48 49 namespace library { 50 51 class Footprint; 52 class FootprintPad; 53 class FootprintPadGraphicsItem; 54 55 /******************************************************************************* 56 * Class FootprintGraphicsItem 57 ******************************************************************************/ 58 59 /** 60 * @brief The FootprintGraphicsItem class 61 */ 62 class FootprintGraphicsItem final : public QGraphicsItem { 63 public: 64 // Constructors / Destructor 65 FootprintGraphicsItem() = delete; 66 FootprintGraphicsItem(const FootprintGraphicsItem& other) = delete; 67 FootprintGraphicsItem(Footprint& fpt, const IF_GraphicsLayerProvider& lp, 68 const PackagePadList* packagePadList) noexcept; 69 ~FootprintGraphicsItem() noexcept; 70 71 // Getters getFootprint()72 Footprint& getFootprint() noexcept { return mFootprint; } 73 FootprintPadGraphicsItem* getPadGraphicsItem( 74 const FootprintPad& pin) noexcept; 75 CircleGraphicsItem* getCircleGraphicsItem(const Circle& circle) noexcept; 76 PolygonGraphicsItem* getPolygonGraphicsItem(const Polygon& polygon) noexcept; 77 StrokeTextGraphicsItem* getTextGraphicsItem(const StrokeText& text) noexcept; 78 HoleGraphicsItem* getHoleGraphicsItem(const Hole& hole) noexcept; 79 int getItemsAtPosition( 80 const Point& pos, QList<QSharedPointer<FootprintPadGraphicsItem>>* pads, 81 QList<QSharedPointer<CircleGraphicsItem>>* circles, 82 QList<QSharedPointer<PolygonGraphicsItem>>* polygons, 83 QList<QSharedPointer<StrokeTextGraphicsItem>>* texts, 84 QList<QSharedPointer<HoleGraphicsItem>>* holes) noexcept; 85 QList<QSharedPointer<FootprintPadGraphicsItem>> getSelectedPads() noexcept; 86 QList<QSharedPointer<CircleGraphicsItem>> getSelectedCircles() noexcept; 87 QList<QSharedPointer<PolygonGraphicsItem>> getSelectedPolygons() noexcept; 88 QList<QSharedPointer<StrokeTextGraphicsItem>> 89 getSelectedStrokeTexts() noexcept; 90 QList<QSharedPointer<HoleGraphicsItem>> getSelectedHoles() noexcept; 91 92 // Setters 93 void setPosition(const Point& pos) noexcept; 94 void setRotation(const Angle& rot) noexcept; 95 96 // General Methods 97 void addPad(FootprintPad& pad) noexcept; 98 void removePad(FootprintPad& pad) noexcept; 99 void addCircle(Circle& circle) noexcept; 100 void removeCircle(Circle& circle) noexcept; 101 void addPolygon(Polygon& polygon) noexcept; 102 void removePolygon(Polygon& polygon) noexcept; 103 void addStrokeText(StrokeText& text) noexcept; 104 void removeStrokeText(StrokeText& text) noexcept; 105 void addHole(Hole& hole) noexcept; 106 void removeHole(Hole& hole) noexcept; 107 void setSelectionRect(const QRectF rect) noexcept; 108 109 // Inherited from QGraphicsItem boundingRect()110 QRectF boundingRect() const noexcept override { return QRectF(); } shape()111 QPainterPath shape() const noexcept override { return QPainterPath(); } 112 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, 113 QWidget* widget = 0) noexcept override; 114 115 // Operator Overloadings 116 FootprintGraphicsItem& operator=(const FootprintGraphicsItem& rhs) = delete; 117 118 private: // Data 119 Footprint& mFootprint; 120 const IF_GraphicsLayerProvider& mLayerProvider; 121 const PackagePadList* mPackagePadList; 122 QHash<const FootprintPad*, QSharedPointer<FootprintPadGraphicsItem>> 123 mPadGraphicsItems; 124 QHash<const Circle*, QSharedPointer<CircleGraphicsItem>> mCircleGraphicsItems; 125 QHash<const Polygon*, QSharedPointer<PolygonGraphicsItem>> 126 mPolygonGraphicsItems; 127 QHash<const StrokeText*, QSharedPointer<StrokeTextGraphicsItem>> 128 mStrokeTextGraphicsItems; 129 QHash<const Hole*, QSharedPointer<HoleGraphicsItem>> mHoleGraphicsItems; 130 }; 131 132 /******************************************************************************* 133 * End of File 134 ******************************************************************************/ 135 136 } // namespace library 137 } // namespace librepcb 138 139 #endif // LIBREPCB_LIBRARY_FOOTPRINTGRAPHICSITEM_H 140