LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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;
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:76
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
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:56
The CategoryListEditorWidget class.
Definition categorylisteditorwidget.h:54
The EditorWidgetBase class.
Definition editorwidgetbase.h:61
Tool
Definition editorwidgetbase.h:75
Feature
Definition editorwidgetbase.h:95
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:49
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:888
bool graphicsViewEventHandler(QEvent *event) noexcept override
Definition packageeditorwidget.cpp:701
bool processGenerateCourtyard() noexcept override
Definition packageeditorwidget.cpp:585
bool copy() noexcept override
Definition packageeditorwidget.cpp:481
bool mirror(Qt::Orientation orientation) noexcept override
Definition packageeditorwidget.cpp:521
bool save() noexcept override
Definition packageeditorwidget.cpp:449
bool execGraphicsExportDialog(GraphicsExportDialog::Output output, const QString &settingsKey) noexcept override
Definition packageeditorwidget.cpp:1260
bool toggle3D() noexcept override
Definition packageeditorwidget.cpp:572
void setGridProperties(const PositiveLength &interval, const LengthUnit &unit, Theme::GridStyle style) noexcept
Definition packageeditorwidget.cpp:1301
void updateMetadata() noexcept
Definition packageeditorwidget.cpp:652
bool processGenerateOutline() noexcept override
Definition packageeditorwidget.cpp:581
bool increaseGridInterval() noexcept override
Definition packageeditorwidget.cpp:602
FilePath getBackgroundImageCacheDir() const noexcept
Definition packageeditorwidget.cpp:1354
QScopedPointer< GraphicsScene > mGraphicsScene
Definition packageeditorwidget.h:170
bool isBackgroundImageSet() const noexcept override
Definition packageeditorwidget.cpp:378
bool flip(Qt::Orientation orientation) noexcept override
Definition packageeditorwidget.cpp:525
std::shared_ptr< QGraphicsPixmapItem > mBackgroundImageGraphicsItem
Definition packageeditorwidget.h:180
bool abortCommand() noexcept override
Definition packageeditorwidget.cpp:577
bool editGridProperties() noexcept override
Definition packageeditorwidget.cpp:593
LengthUnit mLengthUnit
Definition packageeditorwidget.h:173
bool toggleBackgroundImage() noexcept override
Definition packageeditorwidget.cpp:618
QScopedPointer< OpenGlSceneBuilder > mOpenGlSceneBuilder
Definition packageeditorwidget.h:171
void currentFootprintChanged(int index) noexcept
Definition packageeditorwidget.cpp:800
void ruleCheckApproveRequested(std::shared_ptr< const RuleCheckMessage > msg, bool approve) noexcept override
Definition packageeditorwidget.cpp:1254
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:533
bool is3DModeEnabled() const noexcept
Definition packageeditorwidget.cpp:1388
void updateOpenGlScene() noexcept
Definition packageeditorwidget.cpp:816
QScopedPointer< CategoryListEditorWidget > mCategoriesEditorWidget
Definition packageeditorwidget.h:169
void applyBackgroundImageSettings() noexcept
Definition packageeditorwidget.cpp:1315
BackgroundImageSettings mBackgroundImageSettings
Definition packageeditorwidget.h:179
bool paste() noexcept override
Definition packageeditorwidget.cpp:485
void connectEditor(UndoStackActionGroup &undoStackActionGroup, ExclusiveActionGroup &toolsActionGroup, QToolBar &commandToolBar, StatusBar &statusBar) noexcept override
Definition packageeditorwidget.cpp:401
bool cut() noexcept override
Definition packageeditorwidget.cpp:477
bool importDxf() noexcept override
Definition packageeditorwidget.cpp:589
FootprintList mOriginalFootprints
Definition packageeditorwidget.h:184
void scheduleOpenGlSceneUpdate() noexcept
Definition packageeditorwidget.cpp:812
bool decreaseGridInterval() noexcept override
Definition packageeditorwidget.cpp:609
bool rotate(const librepcb::Angle &rotation) noexcept override
Definition packageeditorwidget.cpp:517
bool selectAll() noexcept override
Definition packageeditorwidget.cpp:473
bool zoomAll() noexcept override
Definition packageeditorwidget.cpp:563
QSet< Uuid > mOriginalPadUuids
Definition packageeditorwidget.h:183
~PackageEditorWidget() noexcept
Definition packageeditorwidget.cpp:358
bool move(Qt::ArrowType direction) noexcept override
Definition packageeditorwidget.cpp:489
void fixMsg(const MessageType &msg)
bool editProperties() noexcept override
Definition packageeditorwidget.cpp:541
bool mOpenGlSceneBuildScheduled
Definition packageeditorwidget.h:172
QString commitMetadata() noexcept
Definition packageeditorwidget.cpp:667
void toggle3DMode(bool enable) noexcept
Definition packageeditorwidget.cpp:1360
bool fixMsgHelper(std::shared_ptr< const RuleCheckMessage > msg, bool applyFix)
Definition packageeditorwidget.cpp:1213
bool moveAlign() noexcept override
Definition packageeditorwidget.cpp:529
std::unique_ptr< Package > mPackage
Definition packageeditorwidget.h:174
bool toolChangeRequested(Tool newTool, const QVariant &mode) noexcept override
Definition packageeditorwidget.cpp:757
QScopedPointer< Ui::PackageEditorWidget > mUi
Definition packageeditorwidget.h:167
void disconnectEditor() noexcept override
Definition packageeditorwidget.cpp:434
bool isInterfaceBroken() const noexcept override
Definition packageeditorwidget.cpp:893
QSet< Feature > getAvailableFeatures() const noexcept override
Definition packageeditorwidget.cpp:382
bool zoomIn() noexcept override
Definition packageeditorwidget.cpp:545
bool zoomOut() noexcept override
Definition packageeditorwidget.cpp:554
std::shared_ptr< Footprint > mCurrentFootprint
Definition packageeditorwidget.h:175
bool runChecks(RuleCheckMessageList &msgs) const override
Definition packageeditorwidget.cpp:905
void currentModelChanged(int index) noexcept
Definition packageeditorwidget.cpp:807
void fixPadFunction(const MessageType &msg)
Definition packageeditorwidget.cpp:1163
bool remove() noexcept override
Definition packageeditorwidget.cpp:537
bool processRuleCheckMessage(std::shared_ptr< const RuleCheckMessage > msg, bool applyFix) override
Definition packageeditorwidget.cpp:1224
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:76
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition rulecheckmessage.h:104
Definition uuid.h:186
Definition packageeditorwidget.h:62
QPixmap buildPixmap(const QColor &bgColor) const noexcept
Definition packageeditorwidget.cpp:146
bool tryLoadFromDir(const FilePath &dir) noexcept
Definition packageeditorwidget.cpp:92
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:117
Definition editorwidgetbase.h:67