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 
64 class DeviceEditorWidget final : public EditorWidgetBase {
65  Q_OBJECT
66 
67 public:
68  // Constructors / Destructor
69  DeviceEditorWidget() = delete;
70  DeviceEditorWidget(const DeviceEditorWidget& other) = delete;
71  DeviceEditorWidget(const Context& context, const FilePath& fp,
72  QWidget* parent = nullptr);
73  ~DeviceEditorWidget() noexcept;
74 
75  // Operator Overloadings
76  DeviceEditorWidget& operator=(const DeviceEditorWidget& rhs) = delete;
77 
78 public slots:
79  bool save() noexcept override;
80  bool zoomIn() noexcept override;
81  bool zoomOut() noexcept override;
82  bool zoomAll() noexcept override;
83 
84 private: // Methods
85  void updateMetadata() noexcept;
86  QString commitMetadata() noexcept;
87  void btnChooseComponentClicked() noexcept;
88  void btnChoosePackageClicked() noexcept;
89  void updateDeviceComponentUuid(const Uuid& uuid) noexcept;
90  void updateComponentPreview() noexcept;
91  void updateDevicePackageUuid(const Uuid& uuid) noexcept;
92  void updatePackagePreview() noexcept;
93  void memorizeDeviceInterface() noexcept;
94  bool isInterfaceBroken() const noexcept override;
95  bool runChecks(LibraryElementCheckMessageList& msgs) const override;
96  template <typename MessageType>
97  void fixMsg(const MessageType& msg);
98  template <typename MessageType>
99  bool fixMsgHelper(std::shared_ptr<const LibraryElementCheckMessage> msg,
100  bool applyFix);
101  bool processCheckMessage(
102  std::shared_ptr<const LibraryElementCheckMessage> msg,
103  bool applyFix) override;
104 
105 private: // Data
106  QScopedPointer<Ui::DeviceEditorWidget> mUi;
107  QScopedPointer<ComponentCategoryListEditorWidget> mCategoriesEditorWidget;
108  QScopedPointer<Device> mDevice;
109  QScopedPointer<DefaultGraphicsLayerProvider> mGraphicsLayerProvider;
110 
111  // component
112  QScopedPointer<Component> mComponent;
113  QScopedPointer<GraphicsScene> mComponentGraphicsScene;
114  QList<std::shared_ptr<Symbol>> mSymbols;
115  QList<std::shared_ptr<SymbolPreviewGraphicsItem>> mSymbolGraphicsItems;
116 
117  // package
118  QScopedPointer<Package> mPackage;
119  QScopedPointer<GraphicsScene> mPackageGraphicsScene;
120  QScopedPointer<FootprintPreviewGraphicsItem> mFootprintGraphicsItem;
121 
122  // broken interface detection
123  tl::optional<Uuid> mOriginalComponentUuid;
124  tl::optional<Uuid> mOriginalPackageUuid;
126 };
127 
128 /*******************************************************************************
129  * End of File
130  ******************************************************************************/
131 
132 } // namespace editor
133 } // namespace library
134 } // namespace librepcb
135 
136 #endif // LIBREPCB_LIBRARY_EDITOR_DEVICEEDITORWIDGET_H
QScopedPointer< Component > mComponent
Definition: deviceeditorwidget.h:112
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:114
QScopedPointer< GraphicsScene > mComponentGraphicsScene
Definition: deviceeditorwidget.h:113
bool zoomAll() noexceptoverride
Definition: deviceeditorwidget.cpp:172
void updateComponentPreview() noexcept
Definition: deviceeditorwidget.cpp:337
QScopedPointer< Package > mPackage
Definition: deviceeditorwidget.h:118
QScopedPointer< FootprintPreviewGraphicsItem > mFootprintGraphicsItem
Definition: deviceeditorwidget.h:120
tl::optional< Uuid > mOriginalPackageUuid
Definition: deviceeditorwidget.h:124
void updatePackagePreview() noexcept
Definition: deviceeditorwidget.cpp:391
QScopedPointer< Device > mDevice
Definition: deviceeditorwidget.h:108
void updateDevicePackageUuid(const Uuid &uuid) noexcept
Definition: deviceeditorwidget.cpp:365
tl::optional< Uuid > mOriginalComponentUuid
Definition: deviceeditorwidget.h:123
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:119
~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:106
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
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:107
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
DevicePadSignalMap mOriginalPadSignalMap
Definition: deviceeditorwidget.h:125
QList< std::shared_ptr< SymbolPreviewGraphicsItem > > mSymbolGraphicsItems
Definition: deviceeditorwidget.h:115
QScopedPointer< DefaultGraphicsLayerProvider > mGraphicsLayerProvider
Definition: deviceeditorwidget.h:109
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:62
The DeviceEditorWidget class.
Definition: deviceeditorwidget.h:64