1 /*******************************************************************
2 
3 Part of the Fritzing project - http://fritzing.org
4 Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de
5 
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.
10 
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.
15 
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/>.
18 
19 ********************************************************************
20 
21 $Revision: 6912 $:
22 $Author: irascibl@gmail.com $:
23 $Date: 2013-03-09 08:18:59 +0100 (Sa, 09. Mrz 2013) $
24 
25 ********************************************************************/
26 
27 
28 #include "pecommands.h"
29 #include "pemainwindow.h"
30 #include "../debugdialog.h"
31 
32 
33 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34 
PEBaseCommand(PEMainWindow * peMainWindow,QUndoCommand * parent)35 PEBaseCommand::PEBaseCommand(PEMainWindow * peMainWindow, QUndoCommand *parent)
36 	: BaseCommand(BaseCommand::CrossView, NULL, parent)
37 {
38 	m_peMainWindow = peMainWindow;
39 }
40 
~PEBaseCommand()41 PEBaseCommand::~PEBaseCommand()
42 {
43 }
44 
getParamString() const45 QString PEBaseCommand::getParamString() const {
46     return "";
47 }
48 
49 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50 
ChangeMetadataCommand(PEMainWindow * peMainWindow,const QString & name,const QString & oldValue,const QString & newValue,QUndoCommand * parent)51 ChangeMetadataCommand::ChangeMetadataCommand(PEMainWindow * peMainWindow, const QString & name, const QString  & oldValue, const QString & newValue, QUndoCommand *parent)
52     : PEBaseCommand(peMainWindow, parent)
53 {
54  	m_name = name;
55 	m_oldValue = oldValue;
56 	m_newValue = newValue;
57 }
58 
undo()59 void ChangeMetadataCommand::undo()
60 {
61     m_peMainWindow->changeMetadata(m_name, m_oldValue, true);
62 }
63 
redo()64 void ChangeMetadataCommand::redo()
65 {
66     if (m_skipFirstRedo) {
67         m_skipFirstRedo = false;
68     }
69     else {
70         m_peMainWindow->changeMetadata(m_name, m_newValue, true);
71     }
72 }
73 
getParamString() const74 QString ChangeMetadataCommand::getParamString() const {
75 	return "ChangeMetadataCommand " +
76         QString(" name:%1, old:%2, new:%3")
77             .arg(m_name)
78             .arg(m_oldValue)
79             .arg(m_newValue)
80         ;
81 }
82 
83 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 
ChangeTagsCommand(PEMainWindow * peMainWindow,const QStringList & oldTags,const QStringList & newTags,QUndoCommand * parent)85 ChangeTagsCommand::ChangeTagsCommand(PEMainWindow * peMainWindow, const QStringList  & oldTags, const QStringList & newTags, QUndoCommand *parent)
86     : PEBaseCommand(peMainWindow, parent)
87 {
88 	m_old = oldTags;
89 	m_new = newTags;
90 }
91 
undo()92 void ChangeTagsCommand::undo()
93 {
94     m_peMainWindow->changeTags(m_old, true);
95 }
96 
redo()97 void ChangeTagsCommand::redo()
98 {
99     if (m_skipFirstRedo) {
100         m_skipFirstRedo = false;
101     }
102     else {
103         m_peMainWindow->changeTags(m_new, true);
104     }
105 }
106 
getParamString() const107 QString ChangeTagsCommand::getParamString() const {
108 	return "ChangeTagsCommand " +
109         QString(" old:%1, new:%2")
110             .arg(m_old.count())
111             .arg(m_new.count())
112         ;
113 }
114 
115 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
116 
ChangePropertiesCommand(PEMainWindow * peMainWindow,const QHash<QString,QString> & oldProps,const QHash<QString,QString> & newProps,QUndoCommand * parent)117 ChangePropertiesCommand::ChangePropertiesCommand(PEMainWindow * peMainWindow, const QHash<QString, QString> & oldProps, const QHash<QString, QString> & newProps, QUndoCommand *parent)
118     : PEBaseCommand(peMainWindow, parent)
119 {
120 	m_old = oldProps;
121 	m_new = newProps;
122 }
123 
undo()124 void ChangePropertiesCommand::undo()
125 {
126     m_peMainWindow->changeProperties(m_old, true);
127 }
128 
redo()129 void ChangePropertiesCommand::redo()
130 {
131     if (m_skipFirstRedo) {
132         m_skipFirstRedo = false;
133     }
134     else {
135         m_peMainWindow->changeProperties(m_new, true);
136     }
137 }
138 
getParamString() const139 QString ChangePropertiesCommand::getParamString() const {
140 	return "ChangePropertiesCommand " +
141         QString(" old:%1, new:%2")
142             .arg(m_old.count())
143             .arg(m_new.count())
144         ;
145 }
146 
147 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
148 
ChangeConnectorMetadataCommand(PEMainWindow * peMainWindow,ConnectorMetadata * oldValue,ConnectorMetadata * newValue,QUndoCommand * parent)149 ChangeConnectorMetadataCommand::ChangeConnectorMetadataCommand(PEMainWindow * peMainWindow, ConnectorMetadata  * oldValue, ConnectorMetadata * newValue, QUndoCommand *parent)
150     : PEBaseCommand(peMainWindow, parent)
151 {
152 	m_oldcm = *oldValue;
153 	m_newcm = *newValue;
154 }
155 
undo()156 void ChangeConnectorMetadataCommand::undo()
157 {
158     m_peMainWindow->changeConnectorMetadata(&m_oldcm, true);
159 }
160 
redo()161 void ChangeConnectorMetadataCommand::redo()
162 {
163     if (m_skipFirstRedo) {
164         m_skipFirstRedo = false;
165     }
166     else {
167         m_peMainWindow->changeConnectorMetadata(&m_newcm, true);
168     }
169 }
170 
getParamString() const171 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)
176         ;
177 }
178 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
179 
ChangeFzpCommand(PEMainWindow * peMainWindow,const QString & oldFzpFile,const QString & newFzpFile,QUndoCommand * parent)180 ChangeFzpCommand::ChangeFzpCommand(PEMainWindow * peMainWindow, const QString & oldFzpFile, const QString & newFzpFile, QUndoCommand *parent)
181     : PEBaseCommand(peMainWindow, parent)
182 {
183 	m_oldFzpFile = oldFzpFile;
184     m_newFzpFile = newFzpFile;
185 }
186 
undo()187 void ChangeFzpCommand::undo()
188 {
189 	if (!m_redoOnly) {
190 		m_peMainWindow->restoreFzp(m_oldFzpFile);
191 	}
192 }
193 
redo()194 void ChangeFzpCommand::redo()
195 {
196 	if (!m_undoOnly) {
197 		m_peMainWindow->restoreFzp(m_newFzpFile);
198 	}
199 }
200 
getParamString() const201 QString ChangeFzpCommand::getParamString() const {
202 	return "ChangeFzpCommand " +
203         QString(" old:%1 new:%2")
204             .arg(m_oldFzpFile)
205             .arg(m_newFzpFile)
206         ;
207 }
208 
209 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
210 
ChangeSvgCommand(PEMainWindow * peMainWindow,SketchWidget * sketchWidget,const QString & oldFilename,const QString & newFilename,QUndoCommand * parent)211 ChangeSvgCommand::ChangeSvgCommand(PEMainWindow * peMainWindow, SketchWidget * sketchWidget, const QString  & oldFilename, const QString & newFilename, QUndoCommand *parent)
212     : PEBaseCommand(peMainWindow, parent)
213 {
214  	m_sketchWidget = sketchWidget;
215 	m_oldFilename = oldFilename;
216 	m_newFilename = newFilename;
217 
218 }
219 
undo()220 void ChangeSvgCommand::undo()
221 {
222     m_peMainWindow->changeSvg(m_sketchWidget, m_oldFilename, -1);
223 }
224 
redo()225 void ChangeSvgCommand::redo()
226 {
227     m_peMainWindow->changeSvg(m_sketchWidget, m_newFilename, 1);
228 }
229 
getParamString() const230 QString ChangeSvgCommand::getParamString() const {
231 	return "ChangeSvgCommand " +
232         QString(" id:%1, old:%2, new:%3")
233             .arg(m_sketchWidget->viewID())
234             .arg(m_oldFilename)
235             .arg(m_newFilename)
236         ;
237 }
238 
239 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
240 
RelocateConnectorSvgCommand(PEMainWindow * peMainWindow,SketchWidget * sketchWidget,const QString & id,const QString & terminalID,const QString & oldGorn,const QString & oldGornTerminal,const QString & newGorn,const QString & newGornTerminal,QUndoCommand * parent)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)
245 {
246  	m_sketchWidget = sketchWidget;
247 	m_id = id;
248 	m_terminalID = terminalID;
249 	m_oldGorn = oldGorn;
250 	m_oldGornTerminal = oldGornTerminal;
251 	m_newGorn = newGorn;
252 	m_newGornTerminal = newGornTerminal;
253 }
254 
undo()255 void RelocateConnectorSvgCommand::undo()
256 {
257     m_peMainWindow->relocateConnectorSvg(m_sketchWidget, m_id, m_terminalID, m_newGorn, m_newGornTerminal, m_oldGorn, m_oldGornTerminal, -1);
258 }
259 
redo()260 void RelocateConnectorSvgCommand::redo()
261 {
262     m_peMainWindow->relocateConnectorSvg(m_sketchWidget, m_id, m_terminalID, m_oldGorn, m_oldGornTerminal, m_newGorn, m_newGornTerminal, 1);
263 }
264 
getParamString() const265 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->viewID())
269             .arg(m_id)
270             .arg(m_terminalID)
271             .arg(m_oldGorn)
272             .arg(m_oldGornTerminal)
273             .arg(m_newGorn)
274             .arg(m_newGornTerminal)
275         ;
276 }
277 
278 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
279 
MoveTerminalPointCommand(PEMainWindow * peMainWindow,SketchWidget * sketchWidget,const QString & id,QSizeF size,QPointF oldLocation,QPointF newLocation,QUndoCommand * parent)280 MoveTerminalPointCommand::MoveTerminalPointCommand(PEMainWindow * peMainWindow, SketchWidget * sketchWidget, const QString  & id,
281                 QSizeF size, QPointF oldLocation, QPointF newLocation, QUndoCommand *parent)
282     : PEBaseCommand(peMainWindow, parent)
283 {
284  	m_sketchWidget = sketchWidget;
285 	m_id = id;
286     m_size = size;
287 	m_oldLocation = oldLocation;
288 	m_newLocation = newLocation;
289 }
290 
undo()291 void MoveTerminalPointCommand::undo()
292 {
293     m_peMainWindow->moveTerminalPoint(m_sketchWidget, m_id, m_size, m_oldLocation, -1);
294 }
295 
redo()296 void MoveTerminalPointCommand::redo()
297 {
298     m_peMainWindow->moveTerminalPoint(m_sketchWidget, m_id, m_size, m_newLocation, 1);
299 }
300 
getParamString() const301 QString MoveTerminalPointCommand::getParamString() const {
302 	return "RelocateConnectorSvgCommand " +
303         QString(" vid:%1, id:%2, old:%3,%4, new:%5,%6")
304             .arg(m_sketchWidget->viewID())
305             .arg(m_id)
306             .arg(m_oldLocation.x())
307             .arg(m_oldLocation.y())
308             .arg(m_newLocation.x())
309             .arg(m_newLocation.y())
310         ;
311 }
312 
313 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
314 
RemoveBusConnectorCommand(PEMainWindow * peMainWindow,const QString & busID,const QString & connectorID,bool inverted,QUndoCommand * parent)315 RemoveBusConnectorCommand::RemoveBusConnectorCommand(PEMainWindow * peMainWindow, const QString & busID, const QString  & connectorID, bool inverted, QUndoCommand *parent)
316     : PEBaseCommand(peMainWindow, parent)
317 {
318  	m_busID = busID;
319 	m_connectorID = connectorID;
320 	m_inverted = inverted;
321 }
322 
undo()323 void RemoveBusConnectorCommand::undo()
324 {
325 	if (m_inverted) m_peMainWindow->removeBusConnector(m_busID, m_connectorID, true);
326     else m_peMainWindow->addBusConnector(m_busID, m_connectorID);
327 }
328 
redo()329 void RemoveBusConnectorCommand::redo()
330 {
331 	if (m_inverted) m_peMainWindow->addBusConnector(m_busID, m_connectorID);
332     else m_peMainWindow->removeBusConnector(m_busID, m_connectorID, true);
333 }
334 
getParamString() const335 QString RemoveBusConnectorCommand::getParamString() const {
336 	return "RemoveBusConnectorCommand " +
337         QString(" busID:%1, connectorID:%2 inv:%3")
338             .arg(m_busID)
339             .arg(m_connectorID)
340 			.arg(m_inverted);
341         ;
342 }
343 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
344 
ChangeSMDCommand(PEMainWindow * peMainWindow,const QString & before,const QString & after,const QString & oldFilename,const QString & newFilename,QUndoCommand * parent)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)
349 {
350  	m_before = before;
351 	m_after = after;
352 	m_oldFilename = oldFilename;
353 	m_newFilename = newFilename;
354 }
355 
undo()356 void ChangeSMDCommand::undo()
357 {
358     m_peMainWindow->changeSMD(m_before, m_oldFilename, -1);
359 }
360 
redo()361 void ChangeSMDCommand::redo()
362 {
363     m_peMainWindow->changeSMD(m_after, m_newFilename, 1);
364 }
365 
getParamString() const366 QString ChangeSMDCommand::getParamString() const {
367 	return "ChangeSMDCommand " +
368         QString(" before:%1, after:%2 oldpath:%3, newPath:%4, oldorig:%5, neworig:%6")
369             .arg(m_before)
370             .arg(m_after)
371             .arg(m_oldFilename)
372             .arg(m_newFilename)
373         ;
374 }
375 
376 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
377