LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
deviceeditorwidget.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_LIBRARY_EDITOR_DEVICEEDITORWIDGET_H
21 #define LIBREPCB_LIBRARY_EDITOR_DEVICEEDITORWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../common/categorylisteditorwidget.h"
27 #include "../common/editorwidgetbase.h"
28 
30 
31 #include <QtCore>
32 #include <QtWidgets>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 class GraphicsScene;
40 class DefaultGraphicsLayerProvider;
41 
42 namespace library {
43 
44 class Symbol;
45 class Device;
46 class Component;
47 class Package;
48 class SymbolPreviewGraphicsItem;
49 class FootprintPreviewGraphicsItem;
50 
51 namespace editor {
52 
53 namespace Ui {
54 class DeviceEditorWidget;
55 }
56 
57 /*******************************************************************************
58  * Class DeviceEditorWidget
59  ******************************************************************************/
60 
67 class DeviceEditorWidget final : public EditorWidgetBase {
68  Q_OBJECT
69 
70 public:
71  // Constructors / Destructor
72  DeviceEditorWidget() = delete;
73  DeviceEditorWidget(const DeviceEditorWidget& other) = delete;
74  DeviceEditorWidget(const Context& context, const FilePath& fp,
75  QWidget* parent = nullptr);
76  ~DeviceEditorWidget() noexcept;
77 
78  // Operator Overloadings
79  DeviceEditorWidget& operator=(const DeviceEditorWidget& rhs) = delete;
80 
81 public slots:
82  bool save() noexcept override;
83  bool zoomIn() noexcept override;
84  bool zoomOut() noexcept override;
85  bool zoomAll() noexcept override;
86 
87 private: // Methods
88  void updateMetadata() noexcept;
89  QString commitMetadata() noexcept;
90  void btnChooseComponentClicked() noexcept;
91  void btnChoosePackageClicked() noexcept;
92  void updateDeviceComponentUuid(const Uuid& uuid) noexcept;
93  void updateComponentPreview() noexcept;
94  void updateDevicePackageUuid(const Uuid& uuid) noexcept;
95  void updatePackagePreview() noexcept;
96  void memorizeDeviceInterface() noexcept;
97  bool isInterfaceBroken() const noexcept override;
98  bool runChecks(LibraryElementCheckMessageList& msgs) const override;
99  template <typename MessageType>
100  void fixMsg(const MessageType& msg);
101  template <typename MessageType>
102  bool fixMsgHelper(std::shared_ptr<const LibraryElementCheckMessage> msg,
103  bool applyFix);
104  bool processCheckMessage(
105  std::shared_ptr<const LibraryElementCheckMessage> msg,
106  bool applyFix) override;
107 
108 private: // Data
109  QScopedPointer<Ui::DeviceEditorWidget> mUi;
110  QScopedPointer<ComponentCategoryListEditorWidget> mCategoriesEditorWidget;
111  QScopedPointer<Device> mDevice;
112  QScopedPointer<DefaultGraphicsLayerProvider> mGraphicsLayerProvider;
113 
114  // component
115  QScopedPointer<Component> mComponent;
116  QScopedPointer<GraphicsScene> mComponentGraphicsScene;
117  QList<std::shared_ptr<Symbol>> mSymbols;
118  QList<std::shared_ptr<SymbolPreviewGraphicsItem>> mSymbolGraphicsItems;
119 
120  // package
121  QScopedPointer<Package> mPackage;
122  QScopedPointer<GraphicsScene> mPackageGraphicsScene;
123  QScopedPointer<FootprintPreviewGraphicsItem> mFootprintGraphicsItem;
124 
125  // broken interface detection
126  tl::optional<Uuid> mOriginalComponentUuid;
127  tl::optional<Uuid> mOriginalPackageUuid;
129 };
130 
131 /*******************************************************************************
132  * End of File
133  ******************************************************************************/
134 
135 } // namespace editor
136 } // namespace library
137 } // namespace librepcb
138 
139 #endif // LIBREPCB_LIBRARY_EDITOR_DEVICEEDITORWIDGET_H
QScopedPointer< Component > mComponent
Definition: deviceeditorwidget.h:115
bool isInterfaceBroken() const noexceptoverride
Definition: deviceeditorwidget.cpp:408
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
bool save() noexceptoverride
Definition: deviceeditorwidget.cpp:140
DeviceEditorWidget & operator=(const DeviceEditorWidget &rhs)=delete
QList< std::shared_ptr< Symbol > > mSymbols
Definition: deviceeditorwidget.h:117
QScopedPointer< GraphicsScene > mComponentGraphicsScene
Definition: deviceeditorwidget.h:116
bool zoomAll() noexceptoverride
Definition: deviceeditorwidget.cpp:172
void updateComponentPreview() noexcept
Definition: deviceeditorwidget.cpp:337
QScopedPointer< Package > mPackage
Definition: deviceeditorwidget.h:121
QScopedPointer< FootprintPreviewGraphicsItem > mFootprintGraphicsItem
Definition: deviceeditorwidget.h:123
tl::optional< Uuid > mOriginalPackageUuid
Definition: deviceeditorwidget.h:127
void updatePackagePreview() noexcept
Definition: deviceeditorwidget.cpp:391
QScopedPointer< Device > mDevice
Definition: deviceeditorwidget.h:111
void updateDevicePackageUuid(const Uuid &uuid) noexcept
Definition: deviceeditorwidget.cpp:365
tl::optional< Uuid > mOriginalComponentUuid
Definition: deviceeditorwidget.h:126
void updateDeviceComponentUuid(const Uuid &uuid) noexcept
Definition: deviceeditorwidget.cpp:310
bool runChecks(LibraryElementCheckMessageList &msgs) const override
Definition: deviceeditorwidget.cpp:415
QScopedPointer< GraphicsScene > mPackageGraphicsScene
Definition: deviceeditorwidget.h:122
~DeviceEditorWidget() noexcept
Definition: deviceeditorwidget.cpp:132
void memorizeDeviceInterface() noexcept
Definition: deviceeditorwidget.cpp:402
void updateMetadata() noexcept
Definition: deviceeditorwidget.cpp:182
QScopedPointer< Ui::DeviceEditorWidget > mUi
Definition: deviceeditorwidget.h:109
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
bool zoomIn() noexceptoverride
Definition: deviceeditorwidget.cpp:160
QString commitMetadata() noexcept
Definition: deviceeditorwidget.cpp:194
bool zoomOut() noexceptoverride
Definition: deviceeditorwidget.cpp:166
void btnChoosePackageClicked() noexcept
Definition: deviceeditorwidget.cpp:265
QScopedPointer< ComponentCategoryListEditorWidget > mCategoriesEditorWidget
Definition: deviceeditorwidget.h:110
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
DevicePadSignalMap mOriginalPadSignalMap
Definition: deviceeditorwidget.h:128
QList< std::shared_ptr< SymbolPreviewGraphicsItem > > mSymbolGraphicsItems
Definition: deviceeditorwidget.h:118
QScopedPointer< DefaultGraphicsLayerProvider > mGraphicsLayerProvider
Definition: deviceeditorwidget.h:112
void btnChooseComponentClicked() noexcept
Definition: deviceeditorwidget.cpp:225
bool fixMsgHelper(std::shared_ptr< const LibraryElementCheckMessage > msg, bool applyFix)
Definition: deviceeditorwidget.cpp:441
bool processCheckMessage(std::shared_ptr< const LibraryElementCheckMessage > msg, bool applyFix) override
Definition: deviceeditorwidget.cpp:452
The EditorWidgetBase class.
Definition: editorwidgetbase.h:65
The DeviceEditorWidget class.
Definition: deviceeditorwidget.h:67