LibrePCB Developers Documentation
Loading...
Searching...
No Matches
symboltab.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_SYMBOLTAB_H
21#define LIBREPCB_EDITOR_SYMBOLTAB_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../dialogs/graphicsexportdialog.h"
27#include "../../utils/dismissablemessagecontext.h"
28#include "../../utils/lengtheditcontext.h"
29#include "../../widgets/if_graphicsvieweventhandler.h"
30#include "../libraryeditortab.h"
32
39
40#include <QtCore>
41
42/*******************************************************************************
43 * Namespace / Forward Declarations
44 ******************************************************************************/
45namespace librepcb {
46
47class Layer;
48class Symbol;
49
50namespace editor {
51
52class CategoryTreeModel;
53class GraphicsLayerList;
54class GraphicsScene;
55class LibraryElementCategoriesModel;
56class SlintGraphicsView;
57class SymbolEditorFsm;
58class SymbolGraphicsItem;
59
60/*******************************************************************************
61 * Class SymbolTab
62 ******************************************************************************/
63
67class SymbolTab final : public LibraryEditorTab,
70 Q_OBJECT
71
72public:
73 // Signals
75
76 // Types
77 enum class Mode { Open, New, Duplicate };
78
79 // Constructors / Destructor
80 SymbolTab() = delete;
81 SymbolTab(const SymbolTab& other) = delete;
82 explicit SymbolTab(LibraryEditor& editor, std::unique_ptr<Symbol> sym,
83 Mode mode, QObject* parent = nullptr) noexcept;
84 ~SymbolTab() noexcept;
85
86 // General Methods
87 FilePath getDirectoryPath() const noexcept override;
88 ui::TabData getUiData() const noexcept override;
89 ui::SymbolTabData getDerivedUiData() const noexcept;
90 void setDerivedUiData(const ui::SymbolTabData& data) noexcept;
91 void activate() noexcept override;
92 void deactivate() noexcept override;
93 void trigger(ui::TabAction a) noexcept override;
94 slint::Image renderScene(float width, float height,
95 int scene) noexcept override;
97 const QPointF& pos, slint::private_api::PointerEvent e) noexcept override;
99 const QPointF& pos,
100 slint::private_api::PointerScrollEvent e) noexcept override;
102 const slint::private_api::KeyEvent& e) noexcept override;
103 bool requestClose() noexcept override;
104
105 // IF_GraphicsViewEventHandler
107 const GraphicsSceneKeyEvent& e) noexcept override;
109 const GraphicsSceneKeyEvent& e) noexcept override;
111 const GraphicsSceneMouseEvent& e) noexcept override;
113 const GraphicsSceneMouseEvent& e) noexcept override;
115 const GraphicsSceneMouseEvent& e) noexcept override;
117 const GraphicsSceneMouseEvent& e) noexcept override;
119 const GraphicsSceneMouseEvent& e) noexcept override;
120
121 // SymbolEditorFsmAdapter
122 QWidget* fsmGetParentWidget() noexcept override;
123 GraphicsScene* fsmGetGraphicsScene() noexcept override;
124 SymbolGraphicsItem* fsmGetGraphicsItem() noexcept override;
125 PositiveLength fsmGetGridInterval() const noexcept override;
126 void fsmSetViewCursor(
127 const std::optional<Qt::CursorShape>& shape) noexcept override;
128 void fsmSetViewGrayOut(bool grayOut) noexcept override;
129 void fsmSetViewInfoBoxText(const QString& text) noexcept override;
130 void fsmSetViewRuler(
131 const std::optional<std::pair<Point, Point>>& pos) noexcept override;
132 void fsmSetSceneCursor(const Point& pos, bool cross,
133 bool circle) noexcept override;
134 QPainterPath fsmCalcPosWithTolerance(
135 const Point& pos, qreal multiplier) const noexcept override;
136 Point fsmMapGlobalPosToScenePos(const QPoint& pos) const noexcept override;
137 void fsmSetStatusBarMessage(const QString& message,
138 int timeoutMs = -1) noexcept override;
139 void fsmSetFeatures(Features features) noexcept override;
140 void fsmToolLeave() noexcept override;
141 void fsmToolEnter(SymbolEditorState_Select& state) noexcept override;
142 void fsmToolEnter(SymbolEditorState_DrawLine& state) noexcept override;
143 void fsmToolEnter(SymbolEditorState_DrawRect& state) noexcept override;
144 void fsmToolEnter(SymbolEditorState_DrawPolygon& state) noexcept override;
145 void fsmToolEnter(SymbolEditorState_DrawCircle& state) noexcept override;
146 void fsmToolEnter(SymbolEditorState_DrawArc& state) noexcept override;
147 void fsmToolEnter(SymbolEditorState_AddNames& state) noexcept override;
148 void fsmToolEnter(SymbolEditorState_AddValues& state) noexcept override;
149 void fsmToolEnter(SymbolEditorState_DrawText& state) noexcept override;
150 void fsmToolEnter(SymbolEditorState_AddImage& state) noexcept override;
151 void fsmToolEnter(SymbolEditorState_AddPins& state) noexcept override;
152 void fsmToolEnter(SymbolEditorState_Measure& state) noexcept override;
153
154 // Operator Overloadings
155 SymbolTab& operator=(const SymbolTab& rhs) = delete;
156
157signals:
158 void layerRequested(const Layer& layer);
159 void angleRequested(const Angle& angle);
160 void filledRequested(bool filled);
161 void grabAreaRequested(bool grabArea);
162 void valueRequested(const QString& value);
163 void hAlignRequested(const HAlign& align);
164 void vAlignRequested(const VAlign& align);
165
166protected:
167 void watchedFilesModifiedChanged() noexcept override;
168 void reloadFromDisk() override;
169 std::optional<std::pair<RuleCheckMessageList, QSet<SExpression>>>
170 runChecksImpl() override;
171 bool autoFixImpl(const std::shared_ptr<const RuleCheckMessage>& msg,
172 bool checkOnly) override;
173 template <typename MessageType>
174 bool autoFixHelper(const std::shared_ptr<const RuleCheckMessage>& msg,
175 bool checkOnly);
176 template <typename MessageType>
177 bool autoFix(const MessageType& msg);
178 void messageApprovalChanged(const SExpression& approval,
179 bool approved) noexcept override;
180 void notifyDerivedUiDataChanged() noexcept override;
181
182private:
183 bool isWritable() const noexcept;
184 void refreshUiData() noexcept;
185 void commitUiData() noexcept;
186 bool save() noexcept;
187 void memorizeInterface() noexcept;
188 void updateWatchedFiles() noexcept;
189 void setGridInterval(const PositiveLength& interval) noexcept;
191 const QString& settingsKey) noexcept;
192 void requestRepaint() noexcept;
193 void applyTheme() noexcept;
194
195private:
196 // References
197 std::unique_ptr<Symbol> mSymbol;
200 const bool mIsNewElement;
201
202 // Message handles
204
205 // State
208 Theme::GridStyle mGridStyle;
214
215 // Library metadata to be applied
216 slint::SharedString mName;
217 slint::SharedString mNameError;
219 slint::SharedString mDescription;
220 slint::SharedString mKeywords;
221 slint::SharedString mAuthor;
222 slint::SharedString mVersion;
223 slint::SharedString mVersionError;
228
229 // Current tool
231 ui::EditorTool mTool;
232 Qt::CursorShape mToolCursorShape;
234 QVector<const Layer*> mToolLayersQt;
235 std::shared_ptr<slint::VectorModel<slint::SharedString>> mToolLayers;
242 QString mToolValue;
243 std::shared_ptr<slint::VectorModel<slint::SharedString>>
246
248 QVector<QMetaObject::Connection> mFsmStateConnections;
250
251 // Objects in active state
254
258};
259
260/*******************************************************************************
261 * End of File
262 ******************************************************************************/
263
264} // namespace editor
265} // namespace librepcb
266
267#endif
The Alignment class.
Definition alignment.h:115
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 HAlign class.
Definition alignment.h:43
The Image class.
Definition image.h:49
The Layer class provides all supported geometry layers.
Definition layer.h:42
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition lengthunit.h:62
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
The RuleCheckMessage class.
Definition rulecheckmessage.h:45
The SExpression class.
Definition sexpression.h:69
The Signal class is used to emit signals on non-QObject derived classes.
Definition signalslot.h:65
The Symbol class represents the part of a component which is added to schematics.
Definition symbol.h:56
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 VAlign class.
Definition alignment.h:79
The Version class represents a version number in the format "1.42.7".
Definition version.h:58
The CategoryTreeModel class.
Definition categorytreemodel.h:50
A handle to a optionally dismissable message in the UI.
Definition dismissablemessagecontext.h:53
This class provides a Dialog (GUI) to choose DXF import settings.
Definition graphicsexportdialog.h:61
The GraphicsLayerList class.
Definition graphicslayerlist.h:48
The GraphicsScene class.
Definition graphicsscene.h:64
The IF_GraphicsViewEventHandler class.
Definition if_graphicsvieweventhandler.h:45
Backend configuration for the LengthEdit UI element.
Definition lengtheditcontext.h:49
The LibraryEditor class.
Definition libraryeditor.h:56
Specialized base class for all library editor tabs.
Definition libraryeditortab.h:55
The LibraryElementCategoriesModel class.
Definition libraryelementcategoriesmodel.h:50
The SlintGraphicsView class.
Definition slintgraphicsview.h:52
Interface for the integration of the Symbol editor FSM.
Definition symboleditorfsmadapter.h:62
The SymbolEditorFsm class is the finit state machine (FSM) of the symbol editor.
Definition symboleditorfsm.h:58
The SymbolEditorState_AddImage class.
Definition symboleditorstate_addimage.h:50
The SymbolEditorState_AddNames class.
Definition symboleditorstate_addnames.h:43
The SymbolEditorState_AddPins class.
Definition symboleditorstate_addpins.h:50
The SymbolEditorState_AddValues class.
Definition symboleditorstate_addvalues.h:44
The SymbolEditorState_DrawArc class.
Definition symboleditorstate_drawarc.h:44
The SymbolEditorState_DrawCircle class.
Definition symboleditorstate_drawcircle.h:50
The SymbolEditorState_DrawLine class.
Definition symboleditorstate_drawline.h:44
The SymbolEditorState_DrawPolygon class.
Definition symboleditorstate_drawpolygon.h:44
The SymbolEditorState_DrawRect class.
Definition symboleditorstate_drawrect.h:44
The SymbolEditorState_DrawText class.
Definition symboleditorstate_drawtext.h:43
The SymbolEditorState_Measure class.
Definition symboleditorstate_measure.h:45
The SymbolEditorState_Select class.
Definition symboleditorstate_select.h:58
The SymbolGraphicsItem class.
Definition symbolgraphicsitem.h:55
The SymbolTab class.
Definition symboltab.h:69
slint::Image renderScene(float width, float height, int scene) noexcept override
Definition symboltab.cpp:639
Angle mToolAngle
Definition symboltab.h:239
PositiveLength fsmGetGridInterval() const noexcept override
Definition symboltab.cpp:742
bool graphicsSceneMouseMoved(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:700
slint::SharedString mVersionError
Definition symboltab.h:223
std::shared_ptr< LibraryElementCategoriesModel > mCategories
Definition symboltab.h:226
Features mToolFeatures
Definition symboltab.h:230
bool requestClose() noexcept override
Request to close the tab.
Definition symboltab.cpp:663
bool execGraphicsExportDialog(GraphicsExportDialog::Output output, const QString &settingsKey) noexcept
Definition symboltab.cpp:1595
std::optional< std::pair< RuleCheckMessageList, QSet< SExpression > > > runChecksImpl() override
Definition symboltab.cpp:1323
QPointF mSceneImagePos
Definition symboltab.h:212
std::unique_ptr< SlintGraphicsView > mView
Definition symboltab.h:199
bool save() noexcept
Definition symboltab.cpp:1529
void fsmSetSceneCursor(const Point &pos, bool cross, bool circle) noexcept override
Definition symboltab.cpp:782
void applyTheme() noexcept
Definition symboltab.cpp:1632
bool mToolGrabArea
Definition symboltab.h:241
Alignment mToolAlign
Definition symboltab.h:245
LengthUnit mUnit
Definition symboltab.h:209
bool graphicsSceneRightMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:721
slint::SharedString mName
Definition symboltab.h:216
void layerRequested(const Layer &layer)
void memorizeInterface() noexcept
Definition symboltab.cpp:1570
QString mToolValue
Definition symboltab.h:242
int mFrameIndex
Definition symboltab.h:213
bool graphicsSceneLeftMouseButtonDoubleClicked(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:716
std::unique_ptr< GraphicsLayerList > mLayers
Definition symboltab.h:198
Signal< SymbolTab > onDerivedUiDataChanged
Definition symboltab.h:74
slint::SharedString mDescription
Definition symboltab.h:219
QSet< Uuid > mOriginalSymbolPinUuids
Definition symboltab.h:257
Mode
Definition symboltab.h:77
bool graphicsSceneLeftMouseButtonPressed(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:706
QWidget * fsmGetParentWidget() noexcept override
Definition symboltab.cpp:730
slint::SharedString mVersion
Definition symboltab.h:222
Theme::GridStyle mGridStyle
Definition symboltab.h:208
std::shared_ptr< slint::VectorModel< slint::SharedString > > mToolValueSuggestions
Definition symboltab.h:244
void watchedFilesModifiedChanged() noexcept override
Definition symboltab.cpp:1302
std::shared_ptr< slint::VectorModel< slint::SharedString > > mToolLayers
Definition symboltab.h:235
GraphicsScene * fsmGetGraphicsScene() noexcept override
Definition symboltab.cpp:734
SymbolGraphicsItem * fsmGetGraphicsItem() noexcept override
Definition symboltab.cpp:738
LengthEditContext mToolSize
Definition symboltab.h:238
bool mWizardMode
Definition symboltab.h:206
bool mDeprecated
Definition symboltab.h:225
ui::SymbolTabData getDerivedUiData() const noexcept
Definition symboltab.cpp:243
void fsmSetViewCursor(const std::optional< Qt::CursorShape > &shape) noexcept override
Definition symboltab.cpp:746
std::unique_ptr< SymbolGraphicsItem > mGraphicsItem
Definition symboltab.h:253
bool processSceneScrolled(const QPointF &pos, slint::private_api::PointerScrollEvent e) noexcept override
Definition symboltab.cpp:653
const bool mIsNewElement
Definition symboltab.h:200
void fsmToolLeave() noexcept override
Definition symboltab.cpp:816
void valueRequested(const QString &value)
void angleRequested(const Angle &angle)
std::unique_ptr< Symbol > mSymbol
Definition symboltab.h:197
void messageApprovalChanged(const SExpression &approval, bool approved) noexcept override
Definition symboltab.cpp:1370
void fsmToolEnter(SymbolEditorState_Select &state) noexcept override
Definition symboltab.cpp:825
void reloadFromDisk() override
Definition symboltab.cpp:1306
bool autoFixImpl(const std::shared_ptr< const RuleCheckMessage > &msg, bool checkOnly) override
Definition symboltab.cpp:1340
bool mCompactLayout
Definition symboltab.h:211
void requestRepaint() noexcept
Definition symboltab.cpp:1627
bool processScenePointerEvent(const QPointF &pos, slint::private_api::PointerEvent e) noexcept override
Definition symboltab.cpp:648
void vAlignRequested(const VAlign &align)
bool graphicsSceneKeyPressed(const GraphicsSceneKeyEvent &e) noexcept override
Definition symboltab.cpp:690
QPainterPath fsmCalcPosWithTolerance(const Point &pos, qreal multiplier) const noexcept override
Definition symboltab.cpp:789
FilePath getDirectoryPath() const noexcept override
Definition symboltab.cpp:200
void hAlignRequested(const HAlign &align)
bool autoFixHelper(const std::shared_ptr< const RuleCheckMessage > &msg, bool checkOnly)
Definition symboltab.cpp:1356
QVector< QMetaObject::Connection > mFsmStateConnections
Editor state machine.
Definition symboltab.h:248
bool processSceneKeyEvent(const slint::private_api::KeyEvent &e) noexcept override
Definition symboltab.cpp:658
Version mVersionParsed
Definition symboltab.h:224
void grabAreaRequested(bool grabArea)
void fsmSetViewGrayOut(bool grayOut) noexcept override
Definition symboltab.cpp:756
std::unique_ptr< SymbolEditorFsm > mFsm
Definition symboltab.h:249
void fsmSetViewRuler(const std::optional< std::pair< Point, Point > > &pos) noexcept override
Definition symboltab.cpp:775
void commitUiData() noexcept
Definition symboltab.cpp:1498
bool autoFix(const MessageType &msg)
void fsmSetViewInfoBoxText(const QString &text) noexcept override
Definition symboltab.cpp:762
const Layer * mToolLayer
Definition symboltab.h:236
std::unique_ptr< GraphicsScene > mScene
Definition symboltab.h:252
SymbolTab(const SymbolTab &other)=delete
DismissableMessageContext mMsgImportPins
Definition symboltab.h:203
slint::SharedString mNameError
Definition symboltab.h:217
slint::SharedString mKeywords
Definition symboltab.h:220
Qt::CursorShape mToolCursorShape
Definition symboltab.h:232
void fsmSetStatusBarMessage(const QString &message, int timeoutMs=-1) noexcept override
Definition symboltab.cpp:804
Point fsmMapGlobalPosToScenePos(const QPoint &pos) const noexcept override
Definition symboltab.cpp:794
void trigger(ui::TabAction a) noexcept override
Definition symboltab.cpp:409
std::shared_ptr< CategoryTreeModel > mCategoriesTree
Definition symboltab.h:227
void deactivate() noexcept override
Definition symboltab.cpp:404
void notifyDerivedUiDataChanged() noexcept override
Definition symboltab.cpp:1380
bool mChooseCategory
Definition symboltab.h:210
ElementName mNameParsed
Definition symboltab.h:218
slint::SharedString mAuthor
Definition symboltab.h:221
bool isWritable() const noexcept
Definition symboltab.cpp:1468
QString mToolOverlayText
Definition symboltab.h:233
ui::TabData getUiData() const noexcept override
Definition symboltab.cpp:204
bool graphicsSceneKeyReleased(const GraphicsSceneKeyEvent &e) noexcept override
Definition symboltab.cpp:695
void updateWatchedFiles() noexcept
Definition symboltab.cpp:1574
bool mToolFilled
Definition symboltab.h:240
int mCurrentPageIndex
Definition symboltab.h:207
void setDerivedUiData(const ui::SymbolTabData &data) noexcept
Definition symboltab.cpp:321
void filledRequested(bool filled)
ui::EditorTool mTool
Definition symboltab.h:231
void fsmSetFeatures(Features features) noexcept override
Definition symboltab.cpp:809
LengthEditContext mToolLineWidth
Definition symboltab.h:237
void setGridInterval(const PositiveLength &interval) noexcept
Definition symboltab.cpp:1582
void refreshUiData() noexcept
Definition symboltab.cpp:1472
bool graphicsSceneLeftMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:711
QVector< const Layer * > mToolLayersQt
Definition symboltab.h:234
void activate() noexcept override
Definition symboltab.cpp:390
bool mIsInterfaceBroken
Broken interface detection.
Definition symboltab.h:256
Definition occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition rulecheckmessage.h:104
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84
Definition uuid.h:186
Definition graphicsscene.h:52
Definition graphicsscene.h:45