LibrePCB Developers Documentation
packageeditorwidget.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_PACKAGEEDITORWIDGET_H
21#define LIBREPCB_EDITOR_PACKAGEEDITORWIDGET_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../widgets/if_graphicsvieweventhandler.h"
27#include "../cat/categorylisteditorwidget.h"
28#include "../editorwidgetbase.h"
29
33
34#include <QtCore>
35#include <QtWidgets>
36
37#include <memory>
38
39/*******************************************************************************
40 * Namespace / Forward Declarations
41 ******************************************************************************/
42namespace librepcb {
43
44class Package;
45class PackageModel;
46
47namespace editor {
48
49class GraphicsScene;
50class OpenGlSceneBuilder;
51class OpenGlView;
52class PackageEditorFsm;
53
54namespace Ui {
55class PackageEditorWidget;
56}
57
58/*******************************************************************************
59 * Class BackgroundImageSettings
60 ******************************************************************************/
61
63 bool enabled = true;
64 QImage image;
66 QList<std::pair<QPointF, Point>> references;
67
68 bool tryLoadFromDir(const FilePath& dir) noexcept;
69 void saveToDir(const FilePath& dir) noexcept;
70 QPixmap buildPixmap(const QColor& bgColor) const noexcept;
71};
72
73/*******************************************************************************
74 * Class PackageEditorWidget
75 ******************************************************************************/
76
82 Q_OBJECT
83
84public:
85 // Constructors / Destructor
88 PackageEditorWidget(const Context& context, const FilePath& fp,
89 QWidget* parent = nullptr);
90 ~PackageEditorWidget() noexcept;
91
92 // Getters
93 bool isBackgroundImageSet() const noexcept override;
94 QSet<Feature> getAvailableFeatures() const noexcept override;
95
96 // Setters
97 void connectEditor(UndoStackActionGroup& undoStackActionGroup,
98 ExclusiveActionGroup& toolsActionGroup,
99 QToolBar& commandToolBar,
100 StatusBar& statusBar) noexcept override;
101 void disconnectEditor() noexcept override;
102
103 // Operator Overloadings
104 PackageEditorWidget& operator=(const PackageEditorWidget& rhs) = delete;
105
106public slots:
107 bool save() noexcept override;
108 bool selectAll() noexcept override;
109 bool cut() noexcept override;
110 bool copy() noexcept override;
111 bool paste() noexcept override;
112 bool move(Qt::ArrowType direction) noexcept override;
113 bool rotate(const librepcb::Angle& rotation) noexcept override;
114 bool mirror(Qt::Orientation orientation) noexcept override;
115 bool flip(Qt::Orientation orientation) noexcept override;
116 bool moveAlign() noexcept override;
117 bool snapToGrid() noexcept override;
118 bool remove() noexcept override;
119 bool editProperties() noexcept override;
120 bool zoomIn() noexcept override;
121 bool zoomOut() noexcept override;
122 bool zoomAll() noexcept override;
123 bool toggle3D() noexcept override;
124 bool abortCommand() noexcept override;
125 bool processGenerateOutline() noexcept override;
126 bool processGenerateCourtyard() noexcept override;
127 bool importDxf() noexcept override;
128 bool editGridProperties() noexcept override;
129 bool increaseGridInterval() noexcept override;
130 bool decreaseGridInterval() noexcept override;
131 bool toggleBackgroundImage() noexcept override;
132
133private: // Methods
134 void updateMetadata() noexcept;
135 QString commitMetadata() noexcept;
137 bool graphicsViewEventHandler(QEvent* event) noexcept override;
138 bool toolChangeRequested(Tool newTool,
139 const QVariant& mode) noexcept override;
140 void currentFootprintChanged(int index) noexcept;
141 void currentModelChanged(int index) noexcept;
142 void scheduleOpenGlSceneUpdate() noexcept;
143 void updateOpenGlScene() noexcept;
144 void memorizePackageInterface() noexcept;
145 bool isInterfaceBroken() const noexcept override;
146 bool runChecks(RuleCheckMessageList& msgs) const override;
147 template <typename MessageType>
148 void fixMsg(const MessageType& msg);
149 template <typename MessageType>
150 void fixPadFunction(const MessageType& msg);
151 template <typename MessageType>
152 bool fixMsgHelper(std::shared_ptr<const RuleCheckMessage> msg, bool applyFix);
153 bool processRuleCheckMessage(std::shared_ptr<const RuleCheckMessage> msg,
154 bool applyFix) override;
155 void ruleCheckApproveRequested(std::shared_ptr<const RuleCheckMessage> msg,
156 bool approve) noexcept override;
158 const QString& settingsKey) noexcept override;
159 void setGridProperties(const PositiveLength& interval, const LengthUnit& unit,
160 Theme::GridStyle style) noexcept;
161 void applyBackgroundImageSettings() noexcept;
162 FilePath getBackgroundImageCacheDir() const noexcept;
163 void toggle3DMode(bool enable) noexcept;
164 bool is3DModeEnabled() const noexcept;
165
166private: // Data
167 QScopedPointer<Ui::PackageEditorWidget> mUi;
168 QScopedPointer<OpenGlView> mOpenGlView;
174 std::unique_ptr<Package> mPackage;
175 std::shared_ptr<Footprint> mCurrentFootprint;
176 std::shared_ptr<PackageModel> mCurrentModel;
177
178 // Background image
180 std::shared_ptr<QGraphicsPixmapItem> mBackgroundImageGraphicsItem;
181
182 // broken interface detection
185
187 QScopedPointer<PackageEditorFsm> mFsm;
188};
189
190/*******************************************************************************
191 * End of File
192 ******************************************************************************/
193
194} // namespace editor
195} // namespace librepcb
196
197#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:55
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
The Package class represents a package of a component (including footprint and 3D model)
Definition: package.h:59
Represents a 3D model of a librepcb::Package.
Definition: packagemodel.h:43
The RuleCheckMessage class.
Definition: rulecheckmessage.h:45
Theme class as used by librepcb::WorkspaceSettingsItem_Themes.
Definition: theme.h:44
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The CategoryListEditorWidget class.
Definition: categorylisteditorwidget.h:54
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
Tool
Definition: editorwidgetbase.h:76
Feature
Definition: editorwidgetbase.h:96
The ExclusiveActionGroup class groups multiple QAction's together.
Definition: exclusiveactiongroup.h:54
This class provides a Dialog (GUI) to choose DXF import settings.
Definition: graphicsexportdialog.h:61
The GraphicsScene class.
Definition: graphicsscene.h:45
The IF_GraphicsViewEventHandler class.
Definition: if_graphicsvieweventhandler.h:41
Asynchronously generates a 3D board scene for OpenGL rendering.
Definition: openglscenebuilder.h:49
OpenGL 3D viewer widget.
Definition: openglview.h:52
The PackageEditorFsm class is the finit state machine (FSM) of the package editor.
Definition: packageeditorfsm.h:60
The PackageEditorWidget class.
Definition: packageeditorwidget.h:81
void memorizePackageInterface() noexcept
Definition: packageeditorwidget.cpp:898
bool graphicsViewEventHandler(QEvent *event) noexcept override
Definition: packageeditorwidget.cpp:711
bool processGenerateCourtyard() noexcept override
Definition: packageeditorwidget.cpp:595
bool copy() noexcept override
Definition: packageeditorwidget.cpp:491
bool mirror(Qt::Orientation orientation) noexcept override
Definition: packageeditorwidget.cpp:531
bool save() noexcept override
Definition: packageeditorwidget.cpp:459
bool execGraphicsExportDialog(GraphicsExportDialog::Output output, const QString &settingsKey) noexcept override
Definition: packageeditorwidget.cpp:1270
bool toggle3D() noexcept override
Definition: packageeditorwidget.cpp:582
void setGridProperties(const PositiveLength &interval, const LengthUnit &unit, Theme::GridStyle style) noexcept
Definition: packageeditorwidget.cpp:1311
void updateMetadata() noexcept
Definition: packageeditorwidget.cpp:662
bool processGenerateOutline() noexcept override
Definition: packageeditorwidget.cpp:591
bool increaseGridInterval() noexcept override
Definition: packageeditorwidget.cpp:612
FilePath getBackgroundImageCacheDir() const noexcept
Definition: packageeditorwidget.cpp:1364
QScopedPointer< GraphicsScene > mGraphicsScene
Definition: packageeditorwidget.h:170
bool isBackgroundImageSet() const noexcept override
Definition: packageeditorwidget.cpp:388
bool flip(Qt::Orientation orientation) noexcept override
Definition: packageeditorwidget.cpp:535
std::shared_ptr< QGraphicsPixmapItem > mBackgroundImageGraphicsItem
Definition: packageeditorwidget.h:180
bool abortCommand() noexcept override
Definition: packageeditorwidget.cpp:587
bool editGridProperties() noexcept override
Definition: packageeditorwidget.cpp:603
LengthUnit mLengthUnit
Definition: packageeditorwidget.h:173
bool toggleBackgroundImage() noexcept override
Definition: packageeditorwidget.cpp:628
QScopedPointer< OpenGlSceneBuilder > mOpenGlSceneBuilder
Definition: packageeditorwidget.h:171
void currentFootprintChanged(int index) noexcept
Definition: packageeditorwidget.cpp:810
void ruleCheckApproveRequested(std::shared_ptr< const RuleCheckMessage > msg, bool approve) noexcept override
Definition: packageeditorwidget.cpp:1264
PackageEditorWidget(const PackageEditorWidget &other)=delete
QScopedPointer< PackageEditorFsm > mFsm
Editor state machine.
Definition: packageeditorwidget.h:187
std::shared_ptr< PackageModel > mCurrentModel
Definition: packageeditorwidget.h:176
bool snapToGrid() noexcept override
Definition: packageeditorwidget.cpp:543
bool is3DModeEnabled() const noexcept
Definition: packageeditorwidget.cpp:1398
void updateOpenGlScene() noexcept
Definition: packageeditorwidget.cpp:826
QScopedPointer< CategoryListEditorWidget > mCategoriesEditorWidget
Definition: packageeditorwidget.h:169
void applyBackgroundImageSettings() noexcept
Definition: packageeditorwidget.cpp:1325
BackgroundImageSettings mBackgroundImageSettings
Definition: packageeditorwidget.h:179
bool paste() noexcept override
Definition: packageeditorwidget.cpp:495
void connectEditor(UndoStackActionGroup &undoStackActionGroup, ExclusiveActionGroup &toolsActionGroup, QToolBar &commandToolBar, StatusBar &statusBar) noexcept override
Definition: packageeditorwidget.cpp:411
bool cut() noexcept override
Definition: packageeditorwidget.cpp:487
bool importDxf() noexcept override
Definition: packageeditorwidget.cpp:599
FootprintList mOriginalFootprints
Definition: packageeditorwidget.h:184
void scheduleOpenGlSceneUpdate() noexcept
Definition: packageeditorwidget.cpp:822
bool decreaseGridInterval() noexcept override
Definition: packageeditorwidget.cpp:619
bool rotate(const librepcb::Angle &rotation) noexcept override
Definition: packageeditorwidget.cpp:527
bool selectAll() noexcept override
Definition: packageeditorwidget.cpp:483
bool zoomAll() noexcept override
Definition: packageeditorwidget.cpp:573
QSet< Uuid > mOriginalPadUuids
Definition: packageeditorwidget.h:183
~PackageEditorWidget() noexcept
Definition: packageeditorwidget.cpp:368
bool move(Qt::ArrowType direction) noexcept override
Definition: packageeditorwidget.cpp:499
void fixMsg(const MessageType &msg)
bool editProperties() noexcept override
Definition: packageeditorwidget.cpp:551
bool mOpenGlSceneBuildScheduled
Definition: packageeditorwidget.h:172
QString commitMetadata() noexcept
Definition: packageeditorwidget.cpp:677
void toggle3DMode(bool enable) noexcept
Definition: packageeditorwidget.cpp:1370
bool fixMsgHelper(std::shared_ptr< const RuleCheckMessage > msg, bool applyFix)
Definition: packageeditorwidget.cpp:1223
bool moveAlign() noexcept override
Definition: packageeditorwidget.cpp:539
std::unique_ptr< Package > mPackage
Definition: packageeditorwidget.h:174
bool toolChangeRequested(Tool newTool, const QVariant &mode) noexcept override
Definition: packageeditorwidget.cpp:767
QScopedPointer< Ui::PackageEditorWidget > mUi
Definition: packageeditorwidget.h:167
void disconnectEditor() noexcept override
Definition: packageeditorwidget.cpp:444
bool isInterfaceBroken() const noexcept override
Definition: packageeditorwidget.cpp:903
QSet< Feature > getAvailableFeatures() const noexcept override
Definition: packageeditorwidget.cpp:392
bool zoomIn() noexcept override
Definition: packageeditorwidget.cpp:555
bool zoomOut() noexcept override
Definition: packageeditorwidget.cpp:564
std::shared_ptr< Footprint > mCurrentFootprint
Definition: packageeditorwidget.h:175
bool runChecks(RuleCheckMessageList &msgs) const override
Definition: packageeditorwidget.cpp:915
void currentModelChanged(int index) noexcept
Definition: packageeditorwidget.cpp:817
void fixPadFunction(const MessageType &msg)
Definition: packageeditorwidget.cpp:1173
bool remove() noexcept override
Definition: packageeditorwidget.cpp:547
bool processRuleCheckMessage(std::shared_ptr< const RuleCheckMessage > msg, bool applyFix) override
Definition: packageeditorwidget.cpp:1234
QScopedPointer< OpenGlView > mOpenGlView
Definition: packageeditorwidget.h:168
The StatusBar class extends QStatusBar for some commonly used fields.
Definition: statusbar.h:45
The UndoStackActionGroup class groups an undo-QAction and redo-QAction together and optionally connec...
Definition: undostackactiongroup.h:45
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition: rulecheckmessage.h:104
Definition: packageeditorwidget.h:62
QPixmap buildPixmap(const QColor &bgColor) const noexcept
Definition: packageeditorwidget.cpp:156
bool tryLoadFromDir(const FilePath &dir) noexcept
Definition: packageeditorwidget.cpp:102
Angle rotation
Rotation in scene.
Definition: packageeditorwidget.h:65
QList< std::pair< QPointF, Point > > references
References in image.
Definition: packageeditorwidget.h:66
QImage image
The original loaded image.
Definition: packageeditorwidget.h:64
bool enabled
Whether the background is enabled or not.
Definition: packageeditorwidget.h:63
void saveToDir(const FilePath &dir) noexcept
Definition: packageeditorwidget.cpp:127
Definition: editorwidgetbase.h:68