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_PROJECT_EDITOR_BOARDEDITORSTATE_ADDVIA_H 21 #define LIBREPCB_PROJECT_EDITOR_BOARDEDITORSTATE_ADDVIA_H 22 23 /******************************************************************************* 24 * Includes 25 ******************************************************************************/ 26 #include "boardeditorstate.h" 27 28 #include <librepcb/project/boards/items/bi_via.h> 29 30 #include <QtCore> 31 32 #include <optional.hpp> 33 34 /******************************************************************************* 35 * Namespace / Forward Declarations 36 ******************************************************************************/ 37 namespace librepcb { 38 39 class PositiveLengthEdit; 40 41 namespace project { 42 43 class BI_Via; 44 class CmdBoardViaEdit; 45 46 namespace editor { 47 48 /******************************************************************************* 49 * Class BoardEditorState_AddVia 50 ******************************************************************************/ 51 52 /** 53 * @brief The "add via" state/tool of the board editor 54 */ 55 class BoardEditorState_AddVia final : public BoardEditorState { 56 Q_OBJECT 57 58 public: 59 // Constructors / Destructor 60 BoardEditorState_AddVia() = delete; 61 BoardEditorState_AddVia(const BoardEditorState_AddVia& other) = delete; 62 explicit BoardEditorState_AddVia(const Context& context) noexcept; 63 virtual ~BoardEditorState_AddVia() noexcept; 64 65 // General Methods 66 virtual bool entry() noexcept override; 67 virtual bool exit() noexcept override; 68 69 // Event Handlers 70 virtual bool processGraphicsSceneMouseMoved( 71 QGraphicsSceneMouseEvent& e) noexcept override; 72 virtual bool processGraphicsSceneLeftMouseButtonPressed( 73 QGraphicsSceneMouseEvent& e) noexcept override; 74 virtual bool processGraphicsSceneLeftMouseButtonDoubleClicked( 75 QGraphicsSceneMouseEvent& e) noexcept override; 76 77 // Operator Overloadings 78 BoardEditorState_AddVia& operator=(const BoardEditorState_AddVia& rhs) = 79 delete; 80 81 private: // Methods 82 bool addVia(Board& board, const Point& pos) noexcept; 83 bool updatePosition(Board& board, const Point& pos) noexcept; 84 void setNetSignal(NetSignal* netsignal) noexcept; 85 bool fixPosition(Board& board, const Point& pos) noexcept; 86 bool abortCommand(bool showErrMsgBox) noexcept; 87 void updateShapeActionsCheckedState() noexcept; 88 void sizeEditValueChanged(const PositiveLength& value) noexcept; 89 void drillDiameterEditValueChanged(const PositiveLength& value) noexcept; 90 void applySelectedNetSignal() noexcept; 91 void updateClosestNetSignal(Board& board, const Point& pos) noexcept; 92 NetSignal* getCurrentNetSignal() const noexcept; 93 BI_Via* findVia(Board& board, const Point pos, 94 const QSet<const NetSignal*>& netsignals = {}, 95 const QSet<BI_Via*>& except = {}) const noexcept; 96 BI_FootprintPad* findPad(Board& board, const Point pos, 97 const QSet<const NetSignal*>& netsignals = {}, 98 const QSet<BI_FootprintPad*>& except = {}) const 99 noexcept; 100 BI_NetLine* findNetLine(Board& board, const Point pos, 101 const QSet<const NetSignal*>& netsignals = {}) const 102 noexcept; 103 104 private: // Data 105 // State 106 bool mIsUndoCmdActive; 107 Via mLastViaProperties; 108 109 /// Whether the net signal is determined automatically or not 110 bool mUseAutoNetSignal; 111 112 /// The current net signal of the via 113 tl::optional<Uuid> mCurrentNetSignal; 114 115 /// Whether #mCurrentNetSignal contains an up-to-date closest net signal 116 bool mClosestNetSignalIsUpToDate; 117 118 // Information about the current via to place. Only valid if 119 // mIsUndoCmdActive == true. 120 BI_Via* mCurrentViaToPlace; 121 QScopedPointer<CmdBoardViaEdit> mCurrentViaEditCmd; 122 123 // Widgets for the command toolbar 124 QHash<int, QAction*> mShapeActions; 125 QList<QAction*> mActionSeparators; 126 QScopedPointer<QLabel> mSizeLabel; 127 QScopedPointer<PositiveLengthEdit> mSizeEdit; 128 QScopedPointer<QLabel> mDrillLabel; 129 QScopedPointer<PositiveLengthEdit> mDrillEdit; 130 QScopedPointer<QLabel> mNetSignalLabel; 131 QScopedPointer<QComboBox> mNetSignalComboBox; 132 }; 133 134 /******************************************************************************* 135 * End of File 136 ******************************************************************************/ 137 138 } // namespace editor 139 } // namespace project 140 } // namespace librepcb 141 142 #endif 143