1
/*******************************************************************
3
Part of the Fritzing project - http://fritzing.org
4
Copyright (c) 2007-2012 Fachhochschule Potsdam - http://fh-potsdam.de
6
Fritzing 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.
11
Fritzing 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.
16
You should have received a copy of the GNU General Public License
17
along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************
22
$Author: irascibl@gmail.com $:
23
$Date: 2012-10-16 06:25:29 +0200 (Tue, 16 Oct 2012) $
25
********************************************************************/
28
#include "pecommands.h"
29
#include "pemainwindow.h"
30
#include "../debugdialog.h"
33
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
35
PEBaseCommand::PEBaseCommand(PEMainWindow * peMainWindow, QUndoCommand *parent)
36
: BaseCommand(BaseCommand::CrossView, NULL, parent)
38
m_peMainWindow = peMainWindow;
41
PEBaseCommand::~PEBaseCommand()
45
QString PEBaseCommand::getParamString() const {
49
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51
ChangeMetadataCommand::ChangeMetadataCommand(PEMainWindow * peMainWindow, const QString & name, const QString & oldValue, const QString & newValue, QUndoCommand *parent)
52
: PEBaseCommand(peMainWindow, parent)
55
m_oldValue = oldValue;
56
m_newValue = newValue;
59
void ChangeMetadataCommand::undo()
61
m_peMainWindow->changeMetadata(m_name, m_oldValue, true);
64
void ChangeMetadataCommand::redo()
66
if (m_skipFirstRedo) {
67
m_skipFirstRedo = false;
70
m_peMainWindow->changeMetadata(m_name, m_newValue, true);
74
QString ChangeMetadataCommand::getParamString() const {
75
return "ChangeMetadataCommand " +
76
QString(" name:%1, old:%2, new:%3")
83
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85
ChangeTagsCommand::ChangeTagsCommand(PEMainWindow * peMainWindow, const QStringList & oldTags, const QStringList & newTags, QUndoCommand *parent)
86
: PEBaseCommand(peMainWindow, parent)
92
void ChangeTagsCommand::undo()
94
m_peMainWindow->changeTags(m_old, true);
97
void ChangeTagsCommand::redo()
99
if (m_skipFirstRedo) {
100
m_skipFirstRedo = false;
103
m_peMainWindow->changeTags(m_new, true);
107
QString ChangeTagsCommand::getParamString() const {
108
return "ChangeTagsCommand " +
109
QString(" old:%1, new:%2")
115
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117
ChangePropertiesCommand::ChangePropertiesCommand(PEMainWindow * peMainWindow, const QHash<QString, QString> & oldProps, const QHash<QString, QString> & newProps, QUndoCommand *parent)
118
: PEBaseCommand(peMainWindow, parent)
124
void ChangePropertiesCommand::undo()
126
m_peMainWindow->changeProperties(m_old, true);
129
void ChangePropertiesCommand::redo()
131
if (m_skipFirstRedo) {
132
m_skipFirstRedo = false;
135
m_peMainWindow->changeProperties(m_new, true);
139
QString ChangePropertiesCommand::getParamString() const {
140
return "ChangePropertiesCommand " +
141
QString(" old:%1, new:%2")
147
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
149
ChangeConnectorMetadataCommand::ChangeConnectorMetadataCommand(PEMainWindow * peMainWindow, ConnectorMetadata * oldValue, ConnectorMetadata * newValue, QUndoCommand *parent)
150
: PEBaseCommand(peMainWindow, parent)
156
void ChangeConnectorMetadataCommand::undo()
158
m_peMainWindow->changeConnectorMetadata(&m_oldcm, true);
161
void ChangeConnectorMetadataCommand::redo()
163
if (m_skipFirstRedo) {
164
m_skipFirstRedo = false;
167
m_peMainWindow->changeConnectorMetadata(&m_newcm, true);
171
QString ChangeConnectorMetadataCommand::getParamString() const {
172
return "ChangeConnectorMetadataCommand " +
173
QString(" name:%1, old:%2, new:%3")
174
.arg(m_oldcm.connectorName)
175
.arg(m_newcm.connectorName)
178
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
180
ChangeFzpCommand::ChangeFzpCommand(PEMainWindow * peMainWindow, const QString & oldFzpFile, const QString & newFzpFile, QUndoCommand *parent)
181
: PEBaseCommand(peMainWindow, parent)
183
m_oldFzpFile = oldFzpFile;
184
m_newFzpFile = newFzpFile;
187
void ChangeFzpCommand::undo()
190
m_peMainWindow->restoreFzp(m_oldFzpFile);
194
void ChangeFzpCommand::redo()
197
m_peMainWindow->restoreFzp(m_newFzpFile);
201
QString ChangeFzpCommand::getParamString() const {
202
return "ChangeFzpCommand " +
203
QString(" old:%1 new:%2")
209
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
211
ChangeSvgCommand::ChangeSvgCommand(PEMainWindow * peMainWindow, SketchWidget * sketchWidget, const QString & oldFilename, const QString & newFilename, QUndoCommand *parent)
212
: PEBaseCommand(peMainWindow, parent)
214
m_sketchWidget = sketchWidget;
215
m_oldFilename = oldFilename;
216
m_newFilename = newFilename;
220
void ChangeSvgCommand::undo()
222
m_peMainWindow->changeSvg(m_sketchWidget, m_oldFilename, -1);
225
void ChangeSvgCommand::redo()
227
m_peMainWindow->changeSvg(m_sketchWidget, m_newFilename, 1);
230
QString ChangeSvgCommand::getParamString() const {
231
return "ChangeSvgCommand " +
232
QString(" id:%1, old:%2, new:%3")
233
.arg(m_sketchWidget->viewIdentifier())
239
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
241
RelocateConnectorSvgCommand::RelocateConnectorSvgCommand(PEMainWindow * peMainWindow, SketchWidget * sketchWidget, const QString & id, const QString & terminalID,
242
const QString & oldGorn, const QString & oldGornTerminal, const QString & newGorn, const QString & newGornTerminal,
243
QUndoCommand *parent)
244
: PEBaseCommand(peMainWindow, parent)
246
m_sketchWidget = sketchWidget;
248
m_terminalID = terminalID;
250
m_oldGornTerminal = oldGornTerminal;
252
m_newGornTerminal = newGornTerminal;
255
void RelocateConnectorSvgCommand::undo()
257
m_peMainWindow->relocateConnectorSvg(m_sketchWidget, m_id, m_terminalID, m_newGorn, m_newGornTerminal, m_oldGorn, m_oldGornTerminal, -1);
260
void RelocateConnectorSvgCommand::redo()
262
m_peMainWindow->relocateConnectorSvg(m_sketchWidget, m_id, m_terminalID, m_oldGorn, m_oldGornTerminal, m_newGorn, m_newGornTerminal, 1);
265
QString RelocateConnectorSvgCommand::getParamString() const {
266
return "RelocateConnectorSvgCommand " +
267
QString(" vid:%1 id:%2, terminalid:%3, oldgorn:%4, oldgornterminal:%5, newgorn:%6, newgornterminal:%7")
268
.arg(m_sketchWidget->viewIdentifier())
272
.arg(m_oldGornTerminal)
274
.arg(m_newGornTerminal)
278
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
280
MoveTerminalPointCommand::MoveTerminalPointCommand(PEMainWindow * peMainWindow, SketchWidget * sketchWidget, const QString & id,
281
QSizeF size, QPointF oldLocation, QPointF newLocation, QUndoCommand *parent)
282
: PEBaseCommand(peMainWindow, parent)
284
m_sketchWidget = sketchWidget;
287
m_oldLocation = oldLocation;
288
m_newLocation = newLocation;
291
void MoveTerminalPointCommand::undo()
293
m_peMainWindow->moveTerminalPoint(m_sketchWidget, m_id, m_size, m_oldLocation, -1);
296
void MoveTerminalPointCommand::redo()
298
m_peMainWindow->moveTerminalPoint(m_sketchWidget, m_id, m_size, m_newLocation, 1);
301
QString MoveTerminalPointCommand::getParamString() const {
302
return "RelocateConnectorSvgCommand " +
303
QString(" vid:%1, id:%2, old:%3,%4, new:%5,%6")
304
.arg(m_sketchWidget->viewIdentifier())
306
.arg(m_oldLocation.x())
307
.arg(m_oldLocation.y())
308
.arg(m_newLocation.x())
309
.arg(m_newLocation.y())
313
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
315
RemoveBusConnectorCommand::RemoveBusConnectorCommand(PEMainWindow * peMainWindow, const QString & busID, const QString & connectorID, bool inverted, QUndoCommand *parent)
316
: PEBaseCommand(peMainWindow, parent)
319
m_connectorID = connectorID;
320
m_inverted = inverted;
323
void RemoveBusConnectorCommand::undo()
325
if (m_inverted) m_peMainWindow->removeBusConnector(m_busID, m_connectorID, true);
326
else m_peMainWindow->addBusConnector(m_busID, m_connectorID);
329
void RemoveBusConnectorCommand::redo()
331
if (m_inverted) m_peMainWindow->addBusConnector(m_busID, m_connectorID);
332
else m_peMainWindow->removeBusConnector(m_busID, m_connectorID, true);
335
QString RemoveBusConnectorCommand::getParamString() const {
336
return "RemoveBusConnectorCommand " +
337
QString(" busID:%1, connectorID:%2 inv:%3")
343
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
345
ChangeSMDCommand::ChangeSMDCommand(PEMainWindow * peMainWindow, const QString & before, const QString & after,
346
const QString & oldFilename, const QString & newFilename,
347
QUndoCommand *parent)
348
: PEBaseCommand(peMainWindow, parent)
352
m_oldFilename = oldFilename;
353
m_newFilename = newFilename;
356
void ChangeSMDCommand::undo()
358
m_peMainWindow->changeSMD(m_before, m_oldFilename, -1);
361
void ChangeSMDCommand::redo()
363
m_peMainWindow->changeSMD(m_after, m_newFilename, 1);
366
QString ChangeSMDCommand::getParamString() const {
367
return "ChangeSMDCommand " +
368
QString(" before:%1, after:%2 oldpath:%3, newPath:%4, oldorig:%5, neworig:%6")
376
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////