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 /*******************************************************************************
21  *  Includes
22  ******************************************************************************/
23 #include "cmdcomponentsymbolvariantitemedit.h"
24 
25 #include <QtCore>
26 
27 /*******************************************************************************
28  *  Namespace
29  ******************************************************************************/
30 namespace librepcb {
31 namespace library {
32 
33 /*******************************************************************************
34  *  Constructors / Destructor
35  ******************************************************************************/
36 
CmdComponentSymbolVariantItemEdit(ComponentSymbolVariantItem & item)37 CmdComponentSymbolVariantItemEdit::CmdComponentSymbolVariantItemEdit(
38     ComponentSymbolVariantItem& item) noexcept
39   : UndoCommand(tr("Edit component symbol variant item")),
40     mItem(item),
41     mOldSymbolUuid(item.getSymbolUuid()),
42     mNewSymbolUuid(mOldSymbolUuid),
43     mOldSymbolPos(item.getSymbolPosition()),
44     mNewSymbolPos(mOldSymbolPos),
45     mOldSymbolRot(item.getSymbolRotation()),
46     mNewSymbolRot(mOldSymbolRot),
47     mOldIsRequired(item.isRequired()),
48     mNewIsRequired(mOldIsRequired),
49     mOldSuffix(item.getSuffix()),
50     mNewSuffix(mOldSuffix),
51     mOldPinSignalMap(item.getPinSignalMap()),
52     mNewPinSignalMap(mOldPinSignalMap) {
53 }
54 
55 CmdComponentSymbolVariantItemEdit::
~CmdComponentSymbolVariantItemEdit()56     ~CmdComponentSymbolVariantItemEdit() noexcept {
57 }
58 
59 /*******************************************************************************
60  *  Setters
61  ******************************************************************************/
62 
setSymbolUuid(const Uuid & uuid)63 void CmdComponentSymbolVariantItemEdit::setSymbolUuid(
64     const Uuid& uuid) noexcept {
65   Q_ASSERT(!wasEverExecuted());
66   mNewSymbolUuid = uuid;
67 }
68 
setSymbolPosition(const Point & pos)69 void CmdComponentSymbolVariantItemEdit::setSymbolPosition(
70     const Point& pos) noexcept {
71   Q_ASSERT(!wasEverExecuted());
72   mNewSymbolPos = pos;
73 }
74 
setSymbolRotation(const Angle & rot)75 void CmdComponentSymbolVariantItemEdit::setSymbolRotation(
76     const Angle& rot) noexcept {
77   Q_ASSERT(!wasEverExecuted());
78   mNewSymbolRot = rot;
79 }
80 
setIsRequired(bool required)81 void CmdComponentSymbolVariantItemEdit::setIsRequired(bool required) noexcept {
82   Q_ASSERT(!wasEverExecuted());
83   mNewIsRequired = required;
84 }
85 
setSuffix(const ComponentSymbolVariantItemSuffix & suffix)86 void CmdComponentSymbolVariantItemEdit::setSuffix(
87     const ComponentSymbolVariantItemSuffix& suffix) noexcept {
88   Q_ASSERT(!wasEverExecuted());
89   mNewSuffix = suffix;
90 }
91 
setPinSignalMap(const ComponentPinSignalMap & map)92 void CmdComponentSymbolVariantItemEdit::setPinSignalMap(
93     const ComponentPinSignalMap& map) noexcept {
94   Q_ASSERT(!wasEverExecuted());
95   mNewPinSignalMap = map;
96 }
97 
98 /*******************************************************************************
99  *  Inherited from UndoCommand
100  ******************************************************************************/
101 
performExecute()102 bool CmdComponentSymbolVariantItemEdit::performExecute() {
103   performRedo();  // can throw
104 
105   if (mNewSymbolUuid != mOldSymbolUuid) return true;
106   if (mNewSymbolPos != mOldSymbolPos) return true;
107   if (mNewSymbolRot != mOldSymbolRot) return true;
108   if (mNewIsRequired != mOldIsRequired) return true;
109   if (mNewSuffix != mOldSuffix) return true;
110   if (mNewPinSignalMap != mOldPinSignalMap) return true;
111   return false;
112 }
113 
performUndo()114 void CmdComponentSymbolVariantItemEdit::performUndo() {
115   mItem.setSymbolUuid(mOldSymbolUuid);
116   mItem.setSymbolPosition(mOldSymbolPos);
117   mItem.setSymbolRotation(mOldSymbolRot);
118   mItem.setIsRequired(mOldIsRequired);
119   mItem.setSuffix(mOldSuffix);
120   mItem.getPinSignalMap() = mOldPinSignalMap;
121 }
122 
performRedo()123 void CmdComponentSymbolVariantItemEdit::performRedo() {
124   mItem.setSymbolUuid(mNewSymbolUuid);
125   mItem.setSymbolPosition(mNewSymbolPos);
126   mItem.setSymbolRotation(mNewSymbolRot);
127   mItem.setIsRequired(mNewIsRequired);
128   mItem.setSuffix(mNewSuffix);
129   mItem.getPinSignalMap() = mNewPinSignalMap;
130 }
131 
132 /*******************************************************************************
133  *  End of File
134  ******************************************************************************/
135 
136 }  // namespace library
137 }  // namespace librepcb
138