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 GraphicsScene* fsmGetGraphicsScene() noexcept override;
123 SymbolGraphicsItem* fsmGetGraphicsItem() noexcept override;
124 PositiveLength fsmGetGridInterval() const noexcept override;
125 void fsmSetViewCursor(
126 const std::optional<Qt::CursorShape>& shape) noexcept override;
127 void fsmSetViewGrayOut(bool grayOut) noexcept override;
128 void fsmSetViewInfoBoxText(const QString& text) noexcept override;
129 void fsmSetViewRuler(
130 const std::optional<std::pair<Point, Point>>& pos) noexcept override;
131 void fsmSetSceneCursor(const Point& pos, bool cross,
132 bool circle) noexcept override;
133 QPainterPath fsmCalcPosWithTolerance(
134 const Point& pos, qreal multiplier) const noexcept override;
135 Point fsmMapGlobalPosToScenePos(const QPoint& pos) const noexcept override;
136 void fsmSetStatusBarMessage(const QString& message,
137 int timeoutMs = -1) noexcept override;
138 void fsmSetFeatures(Features features) noexcept override;
139 void fsmToolLeave() noexcept override;
140 void fsmToolEnter(SymbolEditorState_Select& state) noexcept override;
141 void fsmToolEnter(SymbolEditorState_DrawLine& state) noexcept override;
142 void fsmToolEnter(SymbolEditorState_DrawRect& state) noexcept override;
143 void fsmToolEnter(SymbolEditorState_DrawPolygon& state) noexcept override;
144 void fsmToolEnter(SymbolEditorState_DrawCircle& state) noexcept override;
145 void fsmToolEnter(SymbolEditorState_DrawArc& state) noexcept override;
146 void fsmToolEnter(SymbolEditorState_AddNames& state) noexcept override;
147 void fsmToolEnter(SymbolEditorState_AddValues& state) noexcept override;
148 void fsmToolEnter(SymbolEditorState_DrawText& state) noexcept override;
149 void fsmToolEnter(SymbolEditorState_AddPins& state) noexcept override;
150 void fsmToolEnter(SymbolEditorState_Measure& state) noexcept override;
151
152 // Operator Overloadings
153 SymbolTab& operator=(const SymbolTab& rhs) = delete;
154
155signals:
156 void layerRequested(const Layer& layer);
157 void angleRequested(const Angle& angle);
158 void filledRequested(bool filled);
159 void grabAreaRequested(bool grabArea);
160 void valueRequested(const QString& value);
161 void hAlignRequested(const HAlign& align);
162 void vAlignRequested(const VAlign& align);
163
164protected:
165 std::optional<std::pair<RuleCheckMessageList, QSet<SExpression>>>
166 runChecksImpl() override;
167 bool autoFixImpl(const std::shared_ptr<const RuleCheckMessage>& msg,
168 bool checkOnly) override;
169 template <typename MessageType>
170 bool autoFixHelper(const std::shared_ptr<const RuleCheckMessage>& msg,
171 bool checkOnly);
172 template <typename MessageType>
173 void autoFix(const MessageType& msg);
174 void messageApprovalChanged(const SExpression& approval,
175 bool approved) noexcept override;
176 void notifyDerivedUiDataChanged() noexcept override;
177
178private:
179 bool isWritable() const noexcept;
180 void refreshUiData() noexcept;
181 void commitUiData() noexcept;
182 bool save() noexcept;
183 void setGridInterval(const PositiveLength& interval) noexcept;
185 const QString& settingsKey) noexcept;
186 void requestRepaint() noexcept;
187 void applyTheme() noexcept;
188
189private:
190 // References
191 std::unique_ptr<Symbol> mSymbol;
194 const bool mIsNewElement;
195
196 // Message handles
198
199 // State
202 Theme::GridStyle mGridStyle;
209
210 // Library metadata to be applied
211 slint::SharedString mName;
212 slint::SharedString mNameError;
214 slint::SharedString mDescription;
215 slint::SharedString mKeywords;
216 slint::SharedString mAuthor;
217 slint::SharedString mVersion;
218 slint::SharedString mVersionError;
223
224 // Current tool
226 ui::EditorTool mTool;
227 Qt::CursorShape mToolCursorShape;
229 QVector<const Layer*> mToolLayersQt;
230 std::shared_ptr<slint::VectorModel<slint::SharedString>> mToolLayers;
237 QString mToolValue;
238 std::shared_ptr<slint::VectorModel<slint::SharedString>>
241
243 QVector<QMetaObject::Connection> mFsmStateConnections;
245
246 // Objects in active state
249
253};
254
255/*******************************************************************************
256 * End of File
257 ******************************************************************************/
258
259} // namespace editor
260} // namespace librepcb
261
262#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 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:55
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:57
Specialized base class for all library editor tabs.
Definition libraryeditortab.h:54
The LibraryElementCategoriesModel class.
Definition libraryelementcategoriesmodel.h:50
The SlintGraphicsView class.
Definition slintgraphicsview.h:51
Interface for the integration of the Symbol editor FSM.
Definition symboleditorfsmadapter.h:61
The SymbolEditorFsm class is the finit state machine (FSM) of the symbol editor.
Definition symboleditorfsm.h:55
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:56
The SymbolGraphicsItem class.
Definition symbolgraphicsitem.h:56
The SymbolTab class.
Definition symboltab.h:69
slint::Image renderScene(float width, float height, int scene) noexcept override
Definition symboltab.cpp:603
Angle mToolAngle
Definition symboltab.h:234
void autoFix(const MessageType &msg)
PositiveLength fsmGetGridInterval() const noexcept override
Definition symboltab.cpp:702
bool graphicsSceneMouseMoved(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:664
slint::SharedString mVersionError
Definition symboltab.h:218
std::shared_ptr< LibraryElementCategoriesModel > mCategories
Definition symboltab.h:221
Features mToolFeatures
Definition symboltab.h:225
bool requestClose() noexcept override
Request to close the tab.
Definition symboltab.cpp:627
bool execGraphicsExportDialog(GraphicsExportDialog::Output output, const QString &settingsKey) noexcept
Definition symboltab.cpp:1493
std::optional< std::pair< RuleCheckMessageList, QSet< SExpression > > > runChecksImpl() override
Definition symboltab.cpp:1255
QPointF mSceneImagePos
Definition symboltab.h:207
std::unique_ptr< SlintGraphicsView > mView
Definition symboltab.h:193
PositiveLength mGridInterval
Definition symboltab.h:203
bool save() noexcept
Definition symboltab.cpp:1442
void fsmSetSceneCursor(const Point &pos, bool cross, bool circle) noexcept override
Definition symboltab.cpp:742
void applyTheme() noexcept
Definition symboltab.cpp:1530
bool mToolGrabArea
Definition symboltab.h:236
Alignment mToolAlign
Definition symboltab.h:240
LengthUnit mUnit
Definition symboltab.h:204
bool graphicsSceneRightMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:685
slint::SharedString mName
Definition symboltab.h:211
void layerRequested(const Layer &layer)
QString mToolValue
Definition symboltab.h:237
int mFrameIndex
Definition symboltab.h:208
bool graphicsSceneLeftMouseButtonDoubleClicked(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:680
std::unique_ptr< GraphicsLayerList > mLayers
Definition symboltab.h:192
Signal< SymbolTab > onDerivedUiDataChanged
Definition symboltab.h:74
slint::SharedString mDescription
Definition symboltab.h:214
QSet< Uuid > mOriginalSymbolPinUuids
Definition symboltab.h:252
Mode
Definition symboltab.h:77
bool graphicsSceneLeftMouseButtonPressed(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:670
slint::SharedString mVersion
Definition symboltab.h:217
Theme::GridStyle mGridStyle
Definition symboltab.h:202
std::shared_ptr< slint::VectorModel< slint::SharedString > > mToolValueSuggestions
Definition symboltab.h:239
std::shared_ptr< slint::VectorModel< slint::SharedString > > mToolLayers
Definition symboltab.h:230
GraphicsScene * fsmGetGraphicsScene() noexcept override
Definition symboltab.cpp:694
SymbolGraphicsItem * fsmGetGraphicsItem() noexcept override
Definition symboltab.cpp:698
LengthEditContext mToolSize
Definition symboltab.h:233
bool mWizardMode
Definition symboltab.h:200
bool mDeprecated
Definition symboltab.h:220
ui::SymbolTabData getDerivedUiData() const noexcept
Definition symboltab.cpp:229
void fsmSetViewCursor(const std::optional< Qt::CursorShape > &shape) noexcept override
Definition symboltab.cpp:706
std::unique_ptr< SymbolGraphicsItem > mGraphicsItem
Definition symboltab.h:248
bool processSceneScrolled(const QPointF &pos, slint::private_api::PointerScrollEvent e) noexcept override
Definition symboltab.cpp:617
const bool mIsNewElement
Definition symboltab.h:194
void fsmToolLeave() noexcept override
Definition symboltab.cpp:775
void valueRequested(const QString &value)
void angleRequested(const Angle &angle)
std::unique_ptr< Symbol > mSymbol
Definition symboltab.h:191
void messageApprovalChanged(const SExpression &approval, bool approved) noexcept override
Definition symboltab.cpp:1299
void fsmToolEnter(SymbolEditorState_Select &state) noexcept override
Definition symboltab.cpp:784
bool autoFixImpl(const std::shared_ptr< const RuleCheckMessage > &msg, bool checkOnly) override
Definition symboltab.cpp:1272
bool mCompactLayout
Definition symboltab.h:206
void requestRepaint() noexcept
Definition symboltab.cpp:1525
bool processScenePointerEvent(const QPointF &pos, slint::private_api::PointerEvent e) noexcept override
Definition symboltab.cpp:612
void vAlignRequested(const VAlign &align)
bool graphicsSceneKeyPressed(const GraphicsSceneKeyEvent &e) noexcept override
Definition symboltab.cpp:654
QPainterPath fsmCalcPosWithTolerance(const Point &pos, qreal multiplier) const noexcept override
Definition symboltab.cpp:749
FilePath getDirectoryPath() const noexcept override
Definition symboltab.cpp:186
void hAlignRequested(const HAlign &align)
bool autoFixHelper(const std::shared_ptr< const RuleCheckMessage > &msg, bool checkOnly)
Definition symboltab.cpp:1288
QVector< QMetaObject::Connection > mFsmStateConnections
Editor state machine.
Definition symboltab.h:243
bool processSceneKeyEvent(const slint::private_api::KeyEvent &e) noexcept override
Definition symboltab.cpp:622
Version mVersionParsed
Definition symboltab.h:219
void grabAreaRequested(bool grabArea)
void fsmSetViewGrayOut(bool grayOut) noexcept override
Definition symboltab.cpp:716
std::unique_ptr< SymbolEditorFsm > mFsm
Definition symboltab.h:244
void fsmSetViewRuler(const std::optional< std::pair< Point, Point > > &pos) noexcept override
Definition symboltab.cpp:735
void commitUiData() noexcept
Definition symboltab.cpp:1417
void fsmSetViewInfoBoxText(const QString &text) noexcept override
Definition symboltab.cpp:722
const Layer * mToolLayer
Definition symboltab.h:231
std::unique_ptr< GraphicsScene > mScene
Definition symboltab.h:247
SymbolTab(const SymbolTab &other)=delete
DismissableMessageContext mMsgImportPins
Definition symboltab.h:197
slint::SharedString mNameError
Definition symboltab.h:212
slint::SharedString mKeywords
Definition symboltab.h:215
Qt::CursorShape mToolCursorShape
Definition symboltab.h:227
void fsmSetStatusBarMessage(const QString &message, int timeoutMs=-1) noexcept override
Definition symboltab.cpp:763
Point fsmMapGlobalPosToScenePos(const QPoint &pos) const noexcept override
Definition symboltab.cpp:754
void trigger(ui::TabAction a) noexcept override
Definition symboltab.cpp:392
std::shared_ptr< CategoryTreeModel > mCategoriesTree
Definition symboltab.h:222
void deactivate() noexcept override
Definition symboltab.cpp:387
bool mAddCategoryRequested
Definition symboltab.h:205
void notifyDerivedUiDataChanged() noexcept override
Definition symboltab.cpp:1309
ElementName mNameParsed
Definition symboltab.h:213
slint::SharedString mAuthor
Definition symboltab.h:216
bool isWritable() const noexcept
Definition symboltab.cpp:1387
QString mToolOverlayText
Definition symboltab.h:228
ui::TabData getUiData() const noexcept override
Definition symboltab.cpp:190
bool graphicsSceneKeyReleased(const GraphicsSceneKeyEvent &e) noexcept override
Definition symboltab.cpp:659
bool mToolFilled
Definition symboltab.h:235
int mCurrentPageIndex
Definition symboltab.h:201
void setDerivedUiData(const ui::SymbolTabData &data) noexcept
Definition symboltab.cpp:305
void filledRequested(bool filled)
ui::EditorTool mTool
Definition symboltab.h:226
void fsmSetFeatures(Features features) noexcept override
Definition symboltab.cpp:768
LengthEditContext mToolLineWidth
Definition symboltab.h:232
void setGridInterval(const PositiveLength &interval) noexcept
Definition symboltab.cpp:1482
void refreshUiData() noexcept
Definition symboltab.cpp:1391
bool graphicsSceneLeftMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept override
Definition symboltab.cpp:675
QVector< const Layer * > mToolLayersQt
Definition symboltab.h:229
void activate() noexcept override
Definition symboltab.cpp:374
bool mIsInterfaceBroken
Broken interface detection.
Definition symboltab.h:251
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