LibrePCB Developers Documentation
Loading...
Searching...
No Matches
boardeditorstate_drawtrace.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_BOARDEDITORSTATE_DRAWTRACE_H
21#define LIBREPCB_EDITOR_BOARDEDITORSTATE_DRAWTRACE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "boardeditorstate.h"
27
30
31#include <QtCore>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38class BI_NetLine;
39class BI_NetLineAnchor;
40class BI_NetPoint;
41class BI_NetSegment;
42class BI_Pad;
43class BI_Via;
44class Layer;
45class NetSignal;
46
47namespace editor {
48
49/*******************************************************************************
50 * Class BoardEditorState_DrawTrace
51 ******************************************************************************/
52
57 Q_OBJECT
58
59public:
63 enum class WireMode {
64 HV,
65 VH,
66 Deg9045,
67 Deg4590,
68 Straight,
69 _COUNT,
70 };
71
72 // Constructors / Destructor
75 explicit BoardEditorState_DrawTrace(const Context& context) noexcept;
76 virtual ~BoardEditorState_DrawTrace() noexcept;
77
78 // General Methods
79 virtual bool entry() noexcept override;
80 virtual bool exit() noexcept override;
81
82 // Event Handlers
83 virtual bool processAbortCommand() noexcept override;
84 virtual bool processKeyPressed(
85 const GraphicsSceneKeyEvent& e) noexcept override;
86 virtual bool processKeyReleased(
87 const GraphicsSceneKeyEvent& e) noexcept override;
89 const GraphicsSceneMouseEvent& e) noexcept override;
91 const GraphicsSceneMouseEvent& e) noexcept override;
93 const GraphicsSceneMouseEvent& e) noexcept override;
95 const GraphicsSceneMouseEvent& e) noexcept override;
96
97 // Connection to UI
98 NetClass* getNetClass() const noexcept { return mCurrentNetClass; }
99 WireMode getWireMode() const noexcept { return mCurrentWireMode; }
100 void setWireMode(WireMode mode) noexcept;
101 QSet<const Layer*> getAvailableLayers() noexcept;
102 const Layer& getLayer() const noexcept { return *mCurrentLayer; }
103 void setLayer(const Layer& layer) noexcept;
104 bool getAutoWidth() const noexcept { return mCurrentAutoWidth; }
105 void setAutoWidth(bool autoWidth) noexcept;
106 const PositiveLength& getWidth() const noexcept { return mCurrentWidth; }
107 void setWidth(const PositiveLength& width) noexcept;
108 void saveWidthInBoard() noexcept;
109 void saveWidthInNetClass() noexcept;
110 bool getViaAutoDrillDiameter() const noexcept {
111 return !mCurrentViaProperties.getDrillDiameter().has_value();
112 }
113 PositiveLength getViaDrillDiameter() const noexcept;
115 const std::optional<PositiveLength>& diameter) noexcept;
116 void saveViaDrillDiameterInBoard() noexcept;
117 void saveViaDrillDiameterInNetClass() noexcept;
118 bool getAutoViaSize() const noexcept {
119 return !mCurrentViaProperties.getSize().has_value();
120 }
121 PositiveLength getViaSize() const noexcept;
122 void setViaSize(const std::optional<PositiveLength>& size) noexcept;
123
124 // Operator Overloadings
126 delete;
127
128signals:
131 void layerChanged(const Layer& layer);
132 void autoWidthChanged(bool autoWidth);
133 void widthChanged(const PositiveLength& width);
134 void viaDrillDiameterChanged(bool autoSize, const PositiveLength& diameter);
135 void viaSizeChanged(bool autoSize, const PositiveLength& size);
136
137private:
144
164 bool startPositioning(Board& board, const Point& pos,
165 bool autoWidthFromExistingTraces = true,
166 BI_NetPoint* fixedPoint = nullptr,
167 BI_Via* fixedVia = nullptr,
168 BI_Pad* fixedPad = nullptr) noexcept;
169
178 bool addNextNetPoint(BoardGraphicsScene& scene) noexcept;
179
186 bool abortPositioning(bool showErrMsgBox, bool simplifySegment) noexcept;
187
197 void updateNetpointPositions() noexcept;
198
212 void showVia(bool isVisible) noexcept;
213
215
224 Point calcMiddlePointPos(const Point& p1, const Point p2,
225 WireMode mode) const noexcept;
226
230 void updateNetClass() noexcept;
231
232 // State
237 bool mAddVia;
244
257};
258
259/*******************************************************************************
260 * End of File
261 ******************************************************************************/
262
263} // namespace editor
264} // namespace librepcb
265
266#endif
Definition bi_netline.h:46
The BI_NetLine class.
Definition bi_netline.h:71
The BI_NetPoint class.
Definition bi_netpoint.h:46
The BI_NetSegment class.
Definition bi_netsegment.h:53
A pad in a board (either standalone or from a footprint)
Definition bi_pad.h:49
The BI_Via class.
Definition bi_via.h:44
The Board class represents a PCB of a project and is always part of a circuit.
Definition board.h:74
The Layer class provides all supported geometry layers.
Definition layer.h:42
The NetClass class.
Definition netclass.h:47
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
The Via class represents a via of a board.
Definition via.h:55
const std::optional< PositiveLength > & getDrillDiameter() const noexcept
Definition via.h:86
const std::optional< PositiveLength > & getSize() const noexcept
Definition via.h:89
The "draw trace" state/tool of the board editor.
Definition boardeditorstate_drawtrace.h:56
WireMode
All available wire modes.
Definition boardeditorstate_drawtrace.h:63
bool addNextNetPoint(BoardGraphicsScene &scene) noexcept
Finalize the BI_NetLines and connect them to other existing traces if necessary.
Definition boardeditorstate_drawtrace.cpp:663
NetClass * getNetClass() const noexcept
Definition boardeditorstate_drawtrace.h:98
BI_NetLine * mPositioningNetLine2
line between p1 and p2
Definition boardeditorstate_drawtrace.h:255
virtual bool processGraphicsSceneMouseMoved(const GraphicsSceneMouseEvent &e) noexcept override
Definition boardeditorstate_drawtrace.cpp:174
const PositiveLength & getWidth() const noexcept
Definition boardeditorstate_drawtrace.h:106
const Layer * mCurrentLayer
the current board layer name
Definition boardeditorstate_drawtrace.h:236
const Layer * mViaLayer
Layer where the via was started.
Definition boardeditorstate_drawtrace.h:241
bool mAddVia
whether a via add is requested
Definition boardeditorstate_drawtrace.h:237
void saveWidthInNetClass() noexcept
Definition boardeditorstate_drawtrace.cpp:327
BI_NetLine * mPositioningNetLine1
line between fixed point and p1
Definition boardeditorstate_drawtrace.h:253
bool getAutoViaSize() const noexcept
Definition boardeditorstate_drawtrace.h:118
bool mCurrentAutoWidth
automatically adjust wire width
Definition boardeditorstate_drawtrace.h:247
WireMode mCurrentWireMode
the current wire mode
Definition boardeditorstate_drawtrace.h:235
virtual ~BoardEditorState_DrawTrace() noexcept
Definition boardeditorstate_drawtrace.cpp:101
virtual bool processGraphicsSceneRightMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept override
Definition boardeditorstate_drawtrace.cpp:218
PositiveLength mCurrentWidth
the current wire width
Definition boardeditorstate_drawtrace.h:246
PositiveLength getViaSize() const noexcept
Definition boardeditorstate_drawtrace.cpp:431
void updateNetpointPositions() noexcept
Update the currently active traces according to the set parameters.
Definition boardeditorstate_drawtrace.cpp:898
void updateNetClass() noexcept
Update mCurrentNetClass and emit netClassChanged.
Definition boardeditorstate_drawtrace.cpp:1064
void setLayer(const Layer &layer) noexcept
Definition boardeditorstate_drawtrace.cpp:253
BI_NetPoint * mPositioningNetPoint2
the second netpoint to place
Definition boardeditorstate_drawtrace.h:256
QSet< const Layer * > getAvailableLayers() noexcept
Definition boardeditorstate_drawtrace.cpp:249
Point mTargetPos
Definition boardeditorstate_drawtrace.h:242
virtual bool processGraphicsSceneLeftMouseButtonPressed(const GraphicsSceneMouseEvent &e) noexcept override
Definition boardeditorstate_drawtrace.cpp:188
BI_NetLineAnchor * mFixedStartAnchor
Definition boardeditorstate_drawtrace.h:249
void saveViaDrillDiameterInBoard() noexcept
Definition boardeditorstate_drawtrace.cpp:390
void setWireMode(WireMode mode) noexcept
Definition boardeditorstate_drawtrace.cpp:238
BI_Via * mTempVia
Definition boardeditorstate_drawtrace.h:238
void viaDrillDiameterChanged(bool autoSize, const PositiveLength &diameter)
void setWidth(const PositiveLength &width) noexcept
Definition boardeditorstate_drawtrace.cpp:297
virtual bool processAbortCommand() noexcept override
Definition boardeditorstate_drawtrace.cpp:129
const Layer & getLayer() const noexcept
Definition boardeditorstate_drawtrace.h:102
PositiveLength getViaDrillDiameter() const noexcept
Definition boardeditorstate_drawtrace.cpp:347
BoardEditorState_DrawTrace(const BoardEditorState_DrawTrace &other)=delete
Via mCurrentViaProperties
Definition boardeditorstate_drawtrace.h:239
virtual bool processGraphicsSceneLeftMouseButtonDoubleClicked(const GraphicsSceneMouseEvent &e) noexcept override
Definition boardeditorstate_drawtrace.cpp:213
WireMode getWireMode() const noexcept
Definition boardeditorstate_drawtrace.h:99
BI_NetPoint * mPositioningNetPoint1
the first netpoint to place
Definition boardeditorstate_drawtrace.h:254
virtual bool processKeyPressed(const GraphicsSceneKeyEvent &e) noexcept override
Definition boardeditorstate_drawtrace.cpp:140
void saveViaDrillDiameterInNetClass() noexcept
Definition boardeditorstate_drawtrace.cpp:409
void setViaDrillDiameter(const std::optional< PositiveLength > &diameter) noexcept
Definition boardeditorstate_drawtrace.cpp:361
bool getAutoWidth() const noexcept
Definition boardeditorstate_drawtrace.h:104
bool mCurrentSnapActive
the current active snap to target
Definition boardeditorstate_drawtrace.h:248
Point calcMiddlePointPos(const Point &p1, const Point p2, WireMode mode) const noexcept
Calculate the 'middle point' of two point, according to the chosen WireMode.
Definition boardeditorstate_drawtrace.cpp:1036
QPointer< NetClass > mCurrentNetClass
nullptr in idle state
Definition boardeditorstate_drawtrace.h:234
virtual bool exit() noexcept override
Definition boardeditorstate_drawtrace.cpp:116
bool startPositioning(Board &board, const Point &pos, bool autoWidthFromExistingTraces=true, BI_NetPoint *fixedPoint=nullptr, BI_Via *fixedVia=nullptr, BI_Pad *fixedPad=nullptr) noexcept
Begin drawing the next BI_NetLine.
Definition boardeditorstate_drawtrace.cpp:466
BI_NetSegment * mCurrentNetSegment
Definition boardeditorstate_drawtrace.h:251
void widthChanged(const PositiveLength &width)
void saveWidthInBoard() noexcept
Definition boardeditorstate_drawtrace.cpp:308
void setAutoWidth(bool autoWidth) noexcept
Definition boardeditorstate_drawtrace.cpp:286
virtual bool processKeyReleased(const GraphicsSceneKeyEvent &e) noexcept override
Definition boardeditorstate_drawtrace.cpp:157
void viaSizeChanged(bool autoSize, const PositiveLength &size)
void showVia(bool isVisible) noexcept
Sets the BI_Via of the currently active trace.
Definition boardeditorstate_drawtrace.cpp:958
void setViaSize(const std::optional< PositiveLength > &size) noexcept
Definition boardeditorstate_drawtrace.cpp:441
BI_NetLineAnchor * combineAnchors(BI_NetLineAnchor &a, BI_NetLineAnchor &b)
Definition boardeditorstate_drawtrace.cpp:1001
bool abortPositioning(bool showErrMsgBox, bool simplifySegment) noexcept
Abort or cancel the current drawing of the trace.
Definition boardeditorstate_drawtrace.cpp:856
SubState
Internal FSM States (substates)
Definition boardeditorstate_drawtrace.h:139
@ SubState_Idle
idle state [initial state]
Definition boardeditorstate_drawtrace.h:140
@ SubState_PositioningNetPoint
in this state, an undo command is active!
Definition boardeditorstate_drawtrace.h:142
@ SubState_Initializing
beginning to start
Definition boardeditorstate_drawtrace.h:141
SubState mSubState
the current substate
Definition boardeditorstate_drawtrace.h:233
Point mCursorPos
the current cursor position
Definition boardeditorstate_drawtrace.h:245
virtual bool entry() noexcept override
Definition boardeditorstate_drawtrace.cpp:108
bool getViaAutoDrillDiameter() const noexcept
Definition boardeditorstate_drawtrace.h:110
The board editor state base class.
Definition boardeditorstate.h:60
The BoardGraphicsScene class.
Definition boardgraphicsscene.h:77
Definition occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
Definition uuid.h:186
FSM Context.
Definition boardeditorfsm.h:99
Definition graphicsscene.h:52
Definition graphicsscene.h:45