LibrePCB Developers Documentation
unplacedcomponentsdock.h
Go to the documentation of this file.
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_EDITOR_UNPLACEDCOMPONENTSDOCK_H
21 #define LIBREPCB_EDITOR_UNPLACEDCOMPONENTSDOCK_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
28 
29 #include <QtCore>
30 #include <QtWidgets>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 class Board;
38 class ComponentInstance;
39 class Device;
40 class Footprint;
41 class Package;
42 class Project;
43 
44 namespace editor {
45 
46 class DefaultGraphicsLayerProvider;
47 class FootprintGraphicsItem;
48 class GraphicsScene;
49 class ProjectEditor;
50 
51 namespace Ui {
52 class UnplacedComponentsDock;
53 }
54 
55 /*******************************************************************************
56  * Class SchematicPagesDock
57  ******************************************************************************/
58 
62 class UnplacedComponentsDock final : public QDockWidget {
63  Q_OBJECT
64 
65  struct DeviceMetadata {
68 
70  QString deviceName;
71 
74 
76  QString packageName;
77 
81  };
82 
83 public:
84  // Constructors / Destructor
85  UnplacedComponentsDock() = delete;
86  explicit UnplacedComponentsDock(ProjectEditor& editor,
87  QWidget* parent = nullptr) noexcept;
88  UnplacedComponentsDock(const UnplacedComponentsDock& other) = delete;
89  ~UnplacedComponentsDock() noexcept;
90 
91  // Getters
92  int getUnplacedComponentsCount() const noexcept;
93 
94  // Setters
95  void setBoard(Board* board);
96 
97  // Operator Overloadings
98  UnplacedComponentsDock& operator=(const UnplacedComponentsDock& rhs) = delete;
99 
100 signals:
101  void unplacedComponentsCountChanged(int count);
102  void addDeviceTriggered(ComponentInstance& cmp, const Uuid& deviceUuid,
103  Uuid footprintUuid);
104 
105 private: // Methods
106  void updateComponentsList() noexcept;
107  void currentComponentListItemChanged(QListWidgetItem* current,
108  QListWidgetItem* previous) noexcept;
109  void currentDeviceIndexChanged(int index) noexcept;
110  void currentFootprintIndexChanged(int index) noexcept;
111  void setSelectedComponentInstance(ComponentInstance* cmp) noexcept;
112  void setSelectedDeviceAndPackage(const tl::optional<Uuid>& deviceUuid,
113  Package* package,
114  bool packageOwned) noexcept;
115  void setSelectedFootprintUuid(const tl::optional<Uuid>& uuid) noexcept;
116  void addSelectedDeviceToBoard() noexcept;
117  void addSimilarDevicesToBoard() noexcept;
118  void addAllDevicesToBoard() noexcept;
119  void autoAddDevicesToBoard(
120  const tl::optional<Uuid>& libCmpUuidFilter) noexcept;
121 
130  std::pair<QList<DeviceMetadata>, int> getAvailableDevices(
131  ComponentInstance& cmp) const noexcept;
132  tl::optional<Uuid> getSuggestedFootprint(
133  const Uuid& libPkgUuid) const noexcept;
134 
135 private: // Data
136  ProjectEditor& mProjectEditor;
137  Project& mProject;
138  Board* mBoard;
139  QScopedPointer<Ui::UnplacedComponentsDock> mUi;
140 
141  // State
142  bool mDisableListUpdate;
143  Point mNextPosition;
144  QHash<Uuid, Uuid> mLastDeviceOfComponent;
145  QHash<Uuid, Uuid> mLastFootprintOfPackage;
146  QList<DeviceMetadata> mCurrentDevices;
147 
148  // Current selection
149  ComponentInstance* mSelectedComponent;
150  tl::optional<Uuid> mSelectedDeviceUuid;
151  Package* mSelectedPackage;
152  bool mSelectedPackageOwned;
153  tl::optional<Uuid> mSelectedFootprintUuid;
154 
155  // Preview graphics scene
156  QScopedPointer<DefaultGraphicsLayerProvider> mGraphicsLayerProvider;
157  QScopedPointer<GraphicsScene> mPreviewGraphicsScene;
158  QScopedPointer<FootprintGraphicsItem> mPreviewGraphicsItem;
159 };
160 
161 /*******************************************************************************
162  * End of File
163  ******************************************************************************/
164 
165 } // namespace editor
166 } // namespace librepcb
167 
168 #endif
The ProjectEditor class.
Definition: projecteditor.h:62
QString deviceName
Device library element name.
Definition: unplacedcomponentsdock.h:70
bool isListedInComponentInstance
Definition: unplacedcomponentsdock.h:80
Definition: occmodel.cpp:77
Uuid packageUuid
Package library element UUID.
Definition: unplacedcomponentsdock.h:73
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:59
Definition: unplacedcomponentsdock.h:65
The UnplacedComponentsDock class.
Definition: unplacedcomponentsdock.h:62
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:79
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
The FootprintGraphicsItem class.
Definition: footprintgraphicsitem.h:66
Uuid deviceUuid
Device library element UUID.
Definition: unplacedcomponentsdock.h:67
The GraphicsScene class.
Definition: graphicsscene.h:45
The Project class represents a whole (opened) project with all its content.
Definition: project.h:71
Definition: uuid.h:183
QString packageName
Package library element name.
Definition: unplacedcomponentsdock.h:76
The ComponentInstance class.
Definition: componentinstance.h:54
The DefaultGraphicsLayerProvider class.
Definition: defaultgraphicslayerprovider.h:46
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58