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_ADDDEVICE_H
21 #define LIBREPCB_PROJECT_EDITOR_BOARDEDITORSTATE_ADDDEVICE_H
22 
23 /*******************************************************************************
24  *  Includes
25  ******************************************************************************/
26 #include "boardeditorstate.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  *  Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 namespace project {
35 
36 class Board;
37 class ComponentInstance;
38 class BI_Device;
39 class CmdDeviceInstanceEditAll;
40 
41 namespace editor {
42 
43 /*******************************************************************************
44  *  Class BoardEditorState_AddDevice
45  ******************************************************************************/
46 
47 /**
48  * @brief The "add device" state/tool of the board editor
49  */
50 class BoardEditorState_AddDevice final : public BoardEditorState {
51   Q_OBJECT
52 
53 public:
54   // Constructors / Destructor
55   BoardEditorState_AddDevice() = delete;
56   BoardEditorState_AddDevice(const BoardEditorState_AddDevice& other) = delete;
57   BoardEditorState_AddDevice(const Context& context) noexcept;
58   virtual ~BoardEditorState_AddDevice() noexcept;
59 
60   // General Methods
61   virtual bool entry() noexcept override;
62   virtual bool exit() noexcept override;
63 
64   // Event Handlers
65   virtual bool processAddDevice(ComponentInstance& component,
66                                 const Uuid& device,
67                                 const Uuid& footprint) noexcept override;
68   virtual bool processRotateCw() noexcept override;
69   virtual bool processRotateCcw() noexcept override;
70   virtual bool processFlipHorizontal() noexcept override;
71   virtual bool processFlipVertical() noexcept override;
72   virtual bool processGraphicsSceneMouseMoved(
73       QGraphicsSceneMouseEvent& e) noexcept override;
74   virtual bool processGraphicsSceneLeftMouseButtonPressed(
75       QGraphicsSceneMouseEvent& e) noexcept override;
76   virtual bool processGraphicsSceneLeftMouseButtonDoubleClicked(
77       QGraphicsSceneMouseEvent& e) noexcept override;
78   virtual bool processGraphicsSceneRightMouseButtonReleased(
79       QGraphicsSceneMouseEvent& e) noexcept override;
80 
81   // Operator Overloadings
82   BoardEditorState_AddDevice& operator=(const BoardEditorState_AddDevice& rhs) =
83       delete;
84 
85 private:
86   // Private Methods
87   bool addDevice(ComponentInstance& cmp, const Uuid& dev,
88                  const Uuid& fpt) noexcept;
89   bool rotateDevice(const Angle& angle) noexcept;
90   bool mirrorDevice(Qt::Orientation orientation) noexcept;
91   bool abortCommand(bool showErrMsgBox) noexcept;
92 
93   // State
94   bool mIsUndoCmdActive;
95 
96   // Information about the current device to place. Only valid if
97   // mIsUndoCmdActive == true.
98   BI_Device* mCurrentDeviceToPlace;
99   QScopedPointer<CmdDeviceInstanceEditAll> mCurrentDeviceEditCmd;
100 };
101 
102 /*******************************************************************************
103  *  End of File
104  ******************************************************************************/
105 
106 }  // namespace editor
107 }  // namespace project
108 }  // namespace librepcb
109 
110 #endif
111