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: 6954 $:
22 $Author: irascibl@gmail.com $:
23 $Date: 2013-04-05 10:22:00 +0200 (Fr, 05. Apr 2013) $
24
25 ********************************************************************/
26
27 #include "commands.h"
28 #include "debugdialog.h"
29 #include "sketch/sketchwidget.h"
30 #include "waitpushundostack.h"
31 #include "items/wire.h"
32 #include "connectors/connectoritem.h"
33 #include "items/moduleidnames.h"
34 #include "utils/bezier.h"
35
36 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
37
CommandProgress()38 CommandProgress::CommandProgress() {
39 m_active = false;
40 }
41
setActive(bool active)42 void CommandProgress::setActive(bool active) {
43 m_active = active;
44 }
45
active()46 bool CommandProgress::active() {
47 return m_active;
48 }
49
emitUndo()50 void CommandProgress::emitUndo() {
51 emit incUndo();
52 }
53
emitRedo()54 void CommandProgress::emitRedo() {
55 emit incRedo();
56 }
57
58 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59
60
61 int SelectItemCommand::selectItemCommandID = 3;
62 int ChangeNoteTextCommand::changeNoteTextCommandID = 5;
63 int BaseCommand::nextIndex = 0;
64 CommandProgress BaseCommand::m_commandProgress;
65
66 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67
BaseCommand(BaseCommand::CrossViewType crossViewType,SketchWidget * sketchWidget,QUndoCommand * parent)68 BaseCommand::BaseCommand(BaseCommand::CrossViewType crossViewType, SketchWidget* sketchWidget, QUndoCommand *parent)
69 : QUndoCommand(parent)
70 {
71 m_skipFirstRedo = m_undoOnly = m_redoOnly = false;
72 m_crossViewType = crossViewType;
73 m_sketchWidget = sketchWidget;
74 m_parentCommand = parent;
75 m_index = BaseCommand::nextIndex++;
76 }
77
~BaseCommand()78 BaseCommand::~BaseCommand() {
79 foreach (BaseCommand * baseCommand, m_commands) {
80 delete baseCommand;
81 }
82 m_commands.clear();
83 }
84
crossViewType() const85 BaseCommand::CrossViewType BaseCommand::crossViewType() const {
86 return m_crossViewType;
87 }
88
setCrossViewType(BaseCommand::CrossViewType crossViewType)89 void BaseCommand::setCrossViewType(BaseCommand::CrossViewType crossViewType) {
90 m_crossViewType = crossViewType;
91 }
92
sketchWidget() const93 SketchWidget* BaseCommand::sketchWidget() const {
94 return m_sketchWidget;
95 }
96
getDebugString() const97 QString BaseCommand::getDebugString() const {
98 return QString("%1 %2").arg(getParamString()).arg(text());
99 }
100
setUndoOnly()101 void BaseCommand::setUndoOnly() {
102 m_undoOnly = true;
103 }
104
setRedoOnly()105 void BaseCommand::setRedoOnly()
106 {
107 m_redoOnly = true;
108 }
109
setSkipFirstRedo()110 void BaseCommand::setSkipFirstRedo() {
111 m_skipFirstRedo = true;
112 }
113
getParamString() const114 QString BaseCommand::getParamString() const {
115 return QString("%1 %2")
116 .arg(m_sketchWidget->viewName())
117 .arg((m_crossViewType == BaseCommand::SingleView) ? "single-view" : "cross-view");
118 }
119
subCommandCount() const120 int BaseCommand::subCommandCount() const {
121 return m_commands.count();
122 }
123
subCommand(int ix) const124 const BaseCommand * BaseCommand::subCommand(int ix) const {
125 if (ix < 0) return NULL;
126 if (ix >= m_commands.count()) return NULL;
127
128 return m_commands.at(ix);
129 }
130
addSubCommand(BaseCommand * subCommand)131 void BaseCommand::addSubCommand(BaseCommand * subCommand) {
132 m_commands.append(subCommand);
133 #ifndef QT_NO_DEBUG
134 if (m_sketchWidget != NULL) {
135 m_sketchWidget->undoStack()->writeUndo(subCommand, 4, this);
136 }
137 #endif
138 }
139
parentCommand() const140 const QUndoCommand * BaseCommand::parentCommand() const {
141 return m_parentCommand;
142 }
143
subUndo()144 void BaseCommand::subUndo() {
145 for (int i = m_commands.count() - 1; i >= 0; i--) {
146 m_commands[i]->undo();
147 }
148 }
149
subRedo()150 void BaseCommand::subRedo() {
151 foreach (BaseCommand * command, m_commands) {
152 command->redo();
153 }
154 }
155
subUndo(int index)156 void BaseCommand::subUndo(int index) {
157 if (index < 0 || index >= m_commands.count()) return;
158
159 m_commands[index]->undo();
160
161 }
162
subRedo(int index)163 void BaseCommand::subRedo(int index) {
164 if (index < 0 || index >= m_commands.count()) return;
165
166 m_commands[index]->redo();
167 }
168
index() const169 int BaseCommand::index() const {
170 return m_index;
171 }
172
undo()173 void BaseCommand::undo() {
174 if (m_commandProgress.active()) m_commandProgress.emitUndo();
175 }
176
redo()177 void BaseCommand::redo() {
178 if (m_commandProgress.active()) m_commandProgress.emitRedo();
179 }
180
initProgress()181 CommandProgress * BaseCommand::initProgress() {
182 m_commandProgress.setActive(true);
183 return &m_commandProgress;
184 }
185
clearProgress()186 void BaseCommand::clearProgress() {
187 m_commandProgress.setActive(false);
188 }
189
totalChildCount(const QUndoCommand * command)190 int BaseCommand::totalChildCount(const QUndoCommand * command) {
191 int cc = command->childCount();
192 int tcc = cc;
193 for (int i = 0; i < cc; i++) {
194 tcc += totalChildCount(command->child(i));
195 }
196 return tcc;
197 }
198
199 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
200
AddDeleteItemCommand(SketchWidget * sketchWidget,BaseCommand::CrossViewType crossViewType,QString moduleID,ViewLayer::ViewLayerPlacement viewLayerPlacement,ViewGeometry & viewGeometry,qint64 id,long modelIndex,QUndoCommand * parent)201 AddDeleteItemCommand::AddDeleteItemCommand(SketchWidget* sketchWidget, BaseCommand::CrossViewType crossViewType, QString moduleID, ViewLayer::ViewLayerPlacement viewLayerPlacement, ViewGeometry & viewGeometry, qint64 id, long modelIndex, QUndoCommand *parent)
202 : BaseCommand(crossViewType, sketchWidget, parent)
203 {
204 m_dropOrigin = NULL;
205 m_moduleID = moduleID;
206 m_viewGeometry = viewGeometry;
207 m_itemID = id;
208 m_modelIndex = modelIndex;
209 m_viewLayerPlacement = viewLayerPlacement;
210 }
211
getParamString() const212 QString AddDeleteItemCommand::getParamString() const {
213 return BaseCommand::getParamString() +
214 QString(" moduleid:%1 id:%2 modelindex:%3 flags:%4")
215 .arg(m_moduleID)
216 .arg(m_itemID)
217 .arg(m_modelIndex)
218 .arg(m_viewGeometry.flagsAsInt());
219 }
220
itemID() const221 long AddDeleteItemCommand::itemID() const {
222 return m_itemID;
223 }
224
setDropOrigin(SketchWidget * sketchWidget)225 void AddDeleteItemCommand::setDropOrigin(SketchWidget * sketchWidget) {
226 m_dropOrigin = sketchWidget;
227 }
228
dropOrigin()229 SketchWidget * AddDeleteItemCommand::dropOrigin() {
230 return m_dropOrigin;
231 }
232
233 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
234
AddItemCommand(SketchWidget * sketchWidget,BaseCommand::CrossViewType crossViewType,QString moduleID,ViewLayer::ViewLayerPlacement viewLayerPlacement,ViewGeometry & viewGeometry,qint64 id,bool updateInfoView,long modelIndex,QUndoCommand * parent)235 AddItemCommand::AddItemCommand(SketchWidget* sketchWidget, BaseCommand::CrossViewType crossViewType, QString moduleID, ViewLayer::ViewLayerPlacement viewLayerPlacement, ViewGeometry & viewGeometry, qint64 id, bool updateInfoView, long modelIndex, QUndoCommand *parent)
236 : AddDeleteItemCommand(sketchWidget, crossViewType, moduleID, viewLayerPlacement, viewGeometry, id, modelIndex, parent)
237 {
238 m_module = false;
239 m_updateInfoView = updateInfoView;
240 }
241
undo()242 void AddItemCommand::undo()
243 {
244 m_sketchWidget->deleteItem(m_itemID, true, true, false);
245 BaseCommand::undo();
246 }
247
redo()248 void AddItemCommand::redo()
249 {
250 if (!m_skipFirstRedo) {
251 m_sketchWidget->addItem(m_moduleID, m_viewLayerPlacement, m_crossViewType, m_viewGeometry, m_itemID, m_modelIndex, this);
252 }
253 m_skipFirstRedo = false;
254 BaseCommand::redo();
255 }
256
getParamString() const257 QString AddItemCommand::getParamString() const {
258 return "AddItemCommand " + AddDeleteItemCommand::getParamString() +
259 QString(" loc:%1,%2 pt1:%3,%4 pt2:%5,%6")
260 .arg(m_viewGeometry.loc().x()).arg(m_viewGeometry.loc().y())
261 .arg(m_viewGeometry.line().p1().x()).arg(m_viewGeometry.line().p1().y())
262 .arg(m_viewGeometry.line().p2().x()).arg(m_viewGeometry.line().p2().y())
263 ;
264 }
265
266 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
267
DeleteItemCommand(SketchWidget * sketchWidget,BaseCommand::CrossViewType crossViewType,QString moduleID,ViewLayer::ViewLayerPlacement viewLayerPlacement,ViewGeometry & viewGeometry,qint64 id,long modelIndex,QUndoCommand * parent)268 DeleteItemCommand::DeleteItemCommand(SketchWidget* sketchWidget,BaseCommand::CrossViewType crossViewType, QString moduleID, ViewLayer::ViewLayerPlacement viewLayerPlacement, ViewGeometry & viewGeometry, qint64 id, long modelIndex, QUndoCommand *parent)
269 : AddDeleteItemCommand(sketchWidget, crossViewType, moduleID, viewLayerPlacement, viewGeometry, id, modelIndex, parent)
270 {
271 }
272
undo()273 void DeleteItemCommand::undo()
274 {
275 m_sketchWidget->addItem(m_moduleID, m_viewLayerPlacement, m_crossViewType, m_viewGeometry, m_itemID, m_modelIndex, this);
276 BaseCommand::undo();
277 }
278
redo()279 void DeleteItemCommand::redo()
280 {
281 m_sketchWidget->deleteItem(m_itemID, true, m_crossViewType == BaseCommand::CrossView, false);
282 BaseCommand::redo();
283 }
284
getParamString() const285 QString DeleteItemCommand::getParamString() const {
286 return "DeleteItemCommand " + AddDeleteItemCommand::getParamString();
287 }
288
289 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
290
MoveItemCommand(SketchWidget * sketchWidget,long itemID,ViewGeometry & oldG,ViewGeometry & newG,bool updateRatsnest,QUndoCommand * parent)291 MoveItemCommand::MoveItemCommand(SketchWidget* sketchWidget, long itemID, ViewGeometry & oldG, ViewGeometry & newG, bool updateRatsnest, QUndoCommand *parent)
292 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
293 {
294 m_updateRatsnest = updateRatsnest;
295 m_itemID = itemID;
296 m_old = oldG;
297 m_new = newG;
298 }
299
undo()300 void MoveItemCommand::undo()
301 {
302 m_sketchWidget->moveItem(m_itemID, m_old, m_updateRatsnest);
303 BaseCommand::undo();
304 }
305
redo()306 void MoveItemCommand::redo()
307 {
308 m_sketchWidget->moveItem(m_itemID, m_new, m_updateRatsnest);
309 BaseCommand::redo();
310 }
311
getParamString() const312 QString MoveItemCommand::getParamString() const {
313 return QString("MoveItemCommand ")
314 + BaseCommand::getParamString() +
315 QString(" id:%1 old.x:%2 old.y:%3 old.px:%4 old.py:%5 new.x:%6 new.y:%7 new.px:%8 new.py:%9")
316 .arg(m_itemID)
317 .arg(m_old.loc().x())
318 .arg(m_old.loc().y())
319 .arg(m_old.line().p2().x())
320 .arg(m_old.line().p2().y())
321 .arg(m_new.loc().x())
322 .arg(m_new.loc().y())
323 .arg(m_new.line().p2().x())
324 .arg(m_new.line().p2().y())
325 ;
326 }
327
328 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
329
SimpleMoveItemCommand(SketchWidget * sketchWidget,long itemID,QPointF & oldP,QPointF & newP,QUndoCommand * parent)330 SimpleMoveItemCommand::SimpleMoveItemCommand(SketchWidget* sketchWidget, long itemID, QPointF & oldP, QPointF & newP, QUndoCommand *parent)
331 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
332 {
333 m_itemID = itemID;
334 m_old = oldP;
335 m_new = newP;
336 }
337
undo()338 void SimpleMoveItemCommand::undo()
339 {
340 m_sketchWidget->simpleMoveItem(m_itemID, m_old);
341 BaseCommand::undo();
342 }
343
redo()344 void SimpleMoveItemCommand::redo()
345 {
346 m_sketchWidget->simpleMoveItem(m_itemID, m_new);
347 BaseCommand::redo();
348 }
349
getParamString() const350 QString SimpleMoveItemCommand::getParamString() const {
351 return QString("SimpleMoveItemCommand ")
352 + BaseCommand::getParamString() +
353 QString(" id:%1 old.x:%2 old.y:%3 new.x:%4 new.y:%5")
354 .arg(m_itemID)
355 .arg(m_old.x())
356 .arg(m_old.y())
357 .arg(m_new.x())
358 .arg(m_new.y())
359 ;
360 }
361
362 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
363
MoveItemsCommand(SketchWidget * sketchWidget,bool updateRatsnest,QUndoCommand * parent)364 MoveItemsCommand::MoveItemsCommand(SketchWidget* sketchWidget, bool updateRatsnest, QUndoCommand *parent)
365 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
366 {
367 m_updateRatsnest = updateRatsnest;
368 }
369
undo()370 void MoveItemsCommand::undo()
371 {
372 foreach(MoveItemThing moveItemThing, m_items) {
373 m_sketchWidget->moveItem(moveItemThing.id, moveItemThing.oldPos, m_updateRatsnest);
374 }
375 foreach (long id, m_wires.keys()) {
376 m_sketchWidget->updateWire(id, m_wires.value(id), m_updateRatsnest);
377 }
378 BaseCommand::undo();
379 }
380
redo()381 void MoveItemsCommand::redo()
382 {
383 foreach(MoveItemThing moveItemThing, m_items) {
384 m_sketchWidget->moveItem(moveItemThing.id, moveItemThing.newPos, m_updateRatsnest);
385 }
386 foreach (long id, m_wires.keys()) {
387 m_sketchWidget->updateWire(id, m_wires.value(id), m_updateRatsnest);
388 }
389 BaseCommand::redo();
390 }
391
addWire(long id,const QString & connectorID)392 void MoveItemsCommand::addWire(long id, const QString & connectorID)
393 {
394 m_wires.insert(id, connectorID);
395 }
396
addItem(long id,const QPointF & oldPos,const QPointF & newPos)397 void MoveItemsCommand::addItem(long id, const QPointF & oldPos, const QPointF & newPos)
398 {
399 MoveItemThing moveItemThing;
400 moveItemThing.id = id;
401 moveItemThing.oldPos = oldPos;
402 moveItemThing.newPos = newPos;
403 m_items.append(moveItemThing);
404 }
405
getParamString() const406 QString MoveItemsCommand::getParamString() const {
407 return QString("MoveItemsCommand ")
408 + BaseCommand::getParamString() +
409 QString(" items:%1 wires:%2")
410 .arg(m_items.count())
411 .arg(m_wires.count())
412 ;
413 }
414
415 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
416
RotateItemCommand(SketchWidget * sketchWidget,long itemID,double degrees,QUndoCommand * parent)417 RotateItemCommand::RotateItemCommand(SketchWidget* sketchWidget, long itemID, double degrees, QUndoCommand *parent)
418 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
419 {
420 m_itemID = itemID;
421 m_degrees = degrees;
422 }
423
undo()424 void RotateItemCommand::undo()
425 {
426 m_sketchWidget->rotateItem(m_itemID, -m_degrees);
427 BaseCommand::undo();
428 }
429
redo()430 void RotateItemCommand::redo()
431 {
432 m_sketchWidget->rotateItem(m_itemID, m_degrees);
433 BaseCommand::redo();
434 }
435
getParamString() const436 QString RotateItemCommand::getParamString() const {
437 return QString("RotateItemCommand ")
438 + BaseCommand::getParamString() +
439 QString(" id:%1 by:%2")
440 .arg(m_itemID)
441 .arg(m_degrees);
442 }
443
444 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
445
FlipItemCommand(SketchWidget * sketchWidget,long itemID,Qt::Orientations orientation,QUndoCommand * parent)446 FlipItemCommand::FlipItemCommand(SketchWidget* sketchWidget, long itemID, Qt::Orientations orientation, QUndoCommand *parent)
447 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
448 {
449 m_itemID = itemID;
450 m_orientation = orientation;
451 }
452
undo()453 void FlipItemCommand::undo()
454 {
455 redo();
456 BaseCommand::undo();
457 }
458
redo()459 void FlipItemCommand::redo()
460 {
461 m_sketchWidget->flipItem(m_itemID, m_orientation);
462 BaseCommand::redo();
463 }
464
465
getParamString() const466 QString FlipItemCommand::getParamString() const {
467 return QString("FlipItemCommand ")
468 + BaseCommand::getParamString() +
469 QString(" id:%1 by:%2")
470 .arg(m_itemID)
471 .arg(m_orientation);
472 }
473
474 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
475
ChangeConnectionCommand(SketchWidget * sketchWidget,BaseCommand::CrossViewType crossView,long fromID,const QString & fromConnectorID,long toID,const QString & toConnectorID,ViewLayer::ViewLayerPlacement viewLayerPlacement,bool connect,QUndoCommand * parent)476 ChangeConnectionCommand::ChangeConnectionCommand(SketchWidget * sketchWidget, BaseCommand::CrossViewType crossView,
477 long fromID, const QString & fromConnectorID,
478 long toID, const QString & toConnectorID,
479 ViewLayer::ViewLayerPlacement viewLayerPlacement,
480 bool connect, QUndoCommand * parent)
481 : BaseCommand(crossView, sketchWidget, parent)
482 {
483 //DebugDialog::debug(QString("ccc: from %1 %2; to %3 %4").arg(fromID).arg(fromConnectorID).arg(toID).arg(toConnectorID) );
484 m_enabled = true;
485 m_fromID = fromID;
486 m_fromConnectorID = fromConnectorID;
487 m_toID = toID;
488 m_toConnectorID = toConnectorID;
489 m_connect = connect;
490 m_updateConnections = true;
491 m_viewLayerPlacement = viewLayerPlacement;
492 }
493
undo()494 void ChangeConnectionCommand::undo()
495 {
496 if (m_enabled) {
497 m_sketchWidget->changeConnection(m_fromID, m_fromConnectorID, m_toID, m_toConnectorID, m_viewLayerPlacement, !m_connect, m_crossViewType == CrossView, m_updateConnections);
498 BaseCommand::undo();
499 }
500 }
501
redo()502 void ChangeConnectionCommand::redo()
503 {
504 if (m_enabled) {
505 m_sketchWidget->changeConnection(m_fromID, m_fromConnectorID, m_toID, m_toConnectorID, m_viewLayerPlacement, m_connect, m_crossViewType == CrossView, m_updateConnections);
506 BaseCommand::redo();
507 }
508 }
509
setUpdateConnections(bool updatem)510 void ChangeConnectionCommand::setUpdateConnections(bool updatem) {
511 m_updateConnections = updatem;
512 }
513
disable()514 void ChangeConnectionCommand::disable() {
515 m_enabled = false;
516 }
517
getParamString() const518 QString ChangeConnectionCommand::getParamString() const {
519 return QString("ChangeConnectionCommand ")
520 + BaseCommand::getParamString() +
521 QString(" fromid:%1 connid:%2 toid:%3 connid:%4 vlspec:%5 connect:%6")
522 .arg(m_fromID)
523 .arg(m_fromConnectorID)
524 .arg(m_toID)
525 .arg(m_toConnectorID)
526 .arg(m_viewLayerPlacement)
527 .arg(m_connect);
528 }
529
530
531 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
532
ChangeWireCommand(SketchWidget * sketchWidget,long fromID,const QLineF & oldLine,const QLineF & newLine,QPointF oldPos,QPointF newPos,bool updateConnections,bool updateRatsnest,QUndoCommand * parent)533 ChangeWireCommand::ChangeWireCommand(SketchWidget* sketchWidget, long fromID,
534 const QLineF & oldLine, const QLineF & newLine, QPointF oldPos, QPointF newPos,
535 bool updateConnections, bool updateRatsnest,
536 QUndoCommand *parent)
537 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
538 {
539 m_updateRatsnest = updateRatsnest;
540 m_fromID = fromID;
541 m_oldLine = oldLine;
542 m_newLine = newLine;
543 m_oldPos = oldPos;
544 m_newPos = newPos;
545 m_updateConnections = updateConnections;
546 }
547
undo()548 void ChangeWireCommand::undo()
549 {
550 if (!m_redoOnly) {
551 m_sketchWidget->changeWire(m_fromID, m_oldLine, m_oldPos, m_updateConnections, m_updateRatsnest);
552 }
553 BaseCommand::undo();
554 }
555
redo()556 void ChangeWireCommand::redo()
557 {
558 if (!m_undoOnly) {
559 m_sketchWidget->changeWire(m_fromID, m_newLine, m_newPos, m_updateConnections, m_updateRatsnest);
560 }
561 BaseCommand::redo();
562 }
563
getParamString() const564 QString ChangeWireCommand::getParamString() const {
565 return QString("ChangeWireCommand ")
566 + BaseCommand::getParamString() +
567 QString(" fromid:%1 oldp:%2,%3 newP:%4,%5 oldr:%7,%8,%9,%10 newr:%11,%12,%13,%14")
568 .arg(m_fromID)
569 .arg(m_oldPos.x()).arg(m_oldPos.y())
570 .arg(m_newPos.x()).arg(m_newPos.y())
571 .arg(m_oldLine.x1()).arg(m_oldLine.y1()).arg(m_oldLine.x2()).arg(m_oldLine.y2())
572 .arg(m_newLine.x1()).arg(m_newLine.y1()).arg(m_newLine.x2()).arg(m_newLine.y2())
573 ;
574 }
575
576 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
577
ChangeWireCurveCommand(SketchWidget * sketchWidget,long fromID,const Bezier * oldBezier,const Bezier * newBezier,bool wasAutoroutable,QUndoCommand * parent)578 ChangeWireCurveCommand::ChangeWireCurveCommand(SketchWidget* sketchWidget, long fromID,
579 const Bezier * oldBezier, const Bezier * newBezier, bool wasAutoroutable,
580 QUndoCommand *parent)
581 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
582 {
583 m_fromID = fromID;
584 m_wasAutoroutable = wasAutoroutable;
585 m_oldBezier = m_newBezier = NULL;
586 if (oldBezier) {
587 m_oldBezier = new Bezier;
588 m_oldBezier->copy(oldBezier);
589 }
590 if (newBezier) {
591 m_newBezier = new Bezier;
592 m_newBezier->copy(newBezier);
593 }
594 }
595
undo()596 void ChangeWireCurveCommand::undo()
597 {
598 if (!m_redoOnly) {
599 m_sketchWidget->changeWireCurve(m_fromID, m_oldBezier, m_wasAutoroutable);
600 }
601 BaseCommand::undo();
602 }
603
redo()604 void ChangeWireCurveCommand::redo()
605 {
606 if (!m_undoOnly) {
607 if (m_skipFirstRedo) {
608 m_skipFirstRedo = false;
609 }
610 else {
611 m_sketchWidget->changeWireCurve(m_fromID, m_newBezier, false);
612 }
613 }
614 BaseCommand::redo();
615 }
616
getParamString() const617 QString ChangeWireCurveCommand::getParamString() const {
618 QString oldBezier;
619 QString newBezier;
620 if (m_oldBezier) {
621 oldBezier += QString("(%1,%2)").arg(m_oldBezier->cp0().x()).arg(m_oldBezier->cp0().y());
622 oldBezier += QString("(%1,%2)").arg(m_oldBezier->cp1().x()).arg(m_oldBezier->cp1().y());
623 }
624 if (m_newBezier) {
625 newBezier += QString("(%1,%2)").arg(m_newBezier->cp0().x()).arg(m_newBezier->cp0().y());
626 newBezier += QString("(%1,%2)").arg(m_newBezier->cp1().x()).arg(m_newBezier->cp1().y());
627 }
628
629 return QString("ChangeWireCurveCommand ")
630 + BaseCommand::getParamString() +
631 QString(" fromid:%1 oldp:%2 newp:%3")
632 .arg(m_fromID)
633 .arg(oldBezier)
634 .arg(newBezier)
635 ;
636 }
637
638 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
639
ChangeLegCommand(SketchWidget * sketchWidget,long fromID,const QString & fromConnectorID,const QPolygonF & oldLeg,const QPolygonF & newLeg,bool relative,bool active,const QString & why,QUndoCommand * parent)640 ChangeLegCommand::ChangeLegCommand(SketchWidget* sketchWidget, long fromID, const QString & fromConnectorID,
641 const QPolygonF & oldLeg, const QPolygonF & newLeg, bool relative, bool active,
642 const QString & why, QUndoCommand *parent)
643 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
644 {
645 m_why = why;
646 m_simple = false;
647 m_fromID = fromID;
648 m_oldLeg = oldLeg;
649 m_newLeg = newLeg;
650 m_relative = relative;
651 m_fromConnectorID = fromConnectorID;
652 m_active = active;
653 }
654
undo()655 void ChangeLegCommand::undo()
656 {
657 if (!m_redoOnly) {
658 m_sketchWidget->changeLeg(m_fromID, m_fromConnectorID, m_oldLeg, m_relative, m_why);
659 }
660 BaseCommand::undo();
661 }
662
setSimple()663 void ChangeLegCommand::setSimple()
664 {
665 m_simple = true;
666 }
667
redo()668 void ChangeLegCommand::redo()
669 {
670 if (!m_undoOnly) {
671 if (m_simple) {
672 m_sketchWidget->changeLeg(m_fromID, m_fromConnectorID, m_newLeg, m_relative, m_why);
673 }
674 else {
675 m_sketchWidget->recalcLeg(m_fromID, m_fromConnectorID, m_newLeg, m_relative, m_active, m_why);
676 }
677 }
678 BaseCommand::redo();
679 }
680
getParamString() const681 QString ChangeLegCommand::getParamString() const {
682
683 QString oldLeg;
684 QString newLeg;
685 foreach (QPointF p, m_oldLeg) {
686 oldLeg += QString("(%1,%2)").arg(p.x()).arg(p.y());
687 }
688 foreach (QPointF p, m_newLeg) {
689 newLeg += QString("(%1,%2)").arg(p.x()).arg(p.y());
690 }
691 return QString("ChangeLegCommand ")
692 + BaseCommand::getParamString() +
693 QString(" fromid:%1 fromc:%2 %3 old:%4 new:%5")
694 .arg(m_fromID)
695 .arg(m_fromConnectorID)
696 .arg(m_why)
697 .arg(oldLeg)
698 .arg(newLeg)
699 ;
700 }
701
702 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
703
MoveLegBendpointCommand(SketchWidget * sketchWidget,long fromID,const QString & fromConnectorID,int index,QPointF oldPos,QPointF newPos,QUndoCommand * parent)704 MoveLegBendpointCommand::MoveLegBendpointCommand(SketchWidget* sketchWidget, long fromID, const QString & fromConnectorID,
705 int index, QPointF oldPos, QPointF newPos, QUndoCommand *parent)
706 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
707 {
708 m_fromID = fromID;
709 m_oldPos = oldPos;
710 m_newPos = newPos;
711 m_fromConnectorID = fromConnectorID;
712 m_index = index;
713 }
714
undo()715 void MoveLegBendpointCommand::undo()
716 {
717 if (!m_redoOnly) {
718 m_sketchWidget->moveLegBendpoint(m_fromID, m_fromConnectorID, m_index, m_oldPos);
719 }
720 BaseCommand::undo();
721 }
722
redo()723 void MoveLegBendpointCommand::redo()
724 {
725 if (!m_undoOnly) {
726 m_sketchWidget->moveLegBendpoint(m_fromID, m_fromConnectorID, m_index, m_newPos);
727 }
728 BaseCommand::redo();
729 }
730
getParamString() const731 QString MoveLegBendpointCommand::getParamString() const {
732
733 return QString("MoveLegBendpointCommand ")
734 + BaseCommand::getParamString() +
735 QString(" fromid:%1 fromc:%2 ix:%3 old:%4,%5 new:%6,%7")
736 .arg(m_fromID)
737 .arg(m_fromConnectorID)
738 .arg(m_index)
739 .arg(m_oldPos.x())
740 .arg(m_oldPos.y())
741 .arg(m_newPos.x())
742 .arg(m_newPos.y())
743 ;
744 }
745
746 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
747
ChangeLegCurveCommand(SketchWidget * sketchWidget,long fromID,const QString & connectorID,int index,const Bezier * oldBezier,const Bezier * newBezier,QUndoCommand * parent)748 ChangeLegCurveCommand::ChangeLegCurveCommand(SketchWidget* sketchWidget, long fromID, const QString & connectorID, int index,
749 const Bezier * oldBezier, const Bezier * newBezier, QUndoCommand *parent)
750 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
751 {
752 m_fromID = fromID;
753 m_oldBezier = m_newBezier = NULL;
754 if (oldBezier) {
755 m_oldBezier = new Bezier;
756 m_oldBezier->copy(oldBezier);
757 }
758 if (newBezier) {
759 m_newBezier = new Bezier;
760 m_newBezier->copy(newBezier);
761 }
762
763 m_fromConnectorID = connectorID;
764 m_index = index;
765 }
766
undo()767 void ChangeLegCurveCommand::undo()
768 {
769 m_sketchWidget->changeLegCurve(m_fromID, m_fromConnectorID, m_index, m_oldBezier);
770 BaseCommand::undo();
771 }
772
redo()773 void ChangeLegCurveCommand::redo()
774 {
775 if (m_skipFirstRedo) {
776 m_skipFirstRedo = false;
777 }
778 else if (!m_undoOnly) {
779 m_sketchWidget->changeLegCurve(m_fromID, m_fromConnectorID, m_index, m_newBezier);
780 }
781 BaseCommand::redo();
782 }
783
getParamString() const784 QString ChangeLegCurveCommand::getParamString() const {
785 QString oldBezier;
786 QString newBezier;
787 if (m_oldBezier) {
788 oldBezier += QString("(%1,%2)").arg(m_oldBezier->cp0().x()).arg(m_oldBezier->cp0().y());
789 oldBezier += QString("(%1,%2)").arg(m_oldBezier->cp1().x()).arg(m_oldBezier->cp1().y());
790 }
791 if (m_newBezier) {
792 newBezier += QString("(%1,%2)").arg(m_newBezier->cp0().x()).arg(m_newBezier->cp0().y());
793 newBezier += QString("(%1,%2)").arg(m_newBezier->cp1().x()).arg(m_newBezier->cp1().y());
794 }
795
796 return QString("ChangeLegCurveCommand ")
797 + BaseCommand::getParamString() +
798 QString(" fromid:%1 oldp:%2 newp:%3")
799 .arg(m_fromID)
800 .arg(oldBezier)
801 .arg(newBezier)
802 ;
803 }
804
805 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
806
ChangeLegBendpointCommand(SketchWidget * sketchWidget,long fromID,const QString & connectorID,int oldCount,int newCount,int index,QPointF pos,const Bezier * bezier0,const Bezier * bezier1,const Bezier * bezier2,QUndoCommand * parent)807 ChangeLegBendpointCommand::ChangeLegBendpointCommand(SketchWidget* sketchWidget, long fromID, const QString & connectorID,
808 int oldCount, int newCount, int index, QPointF pos,
809 const Bezier * bezier0, const Bezier * bezier1, const Bezier * bezier2, QUndoCommand *parent)
810 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
811 {
812 m_fromID = fromID;
813 m_bezier0 = m_bezier1 = m_bezier2 = NULL;
814 if (bezier0 != NULL) {
815 m_bezier0 = new Bezier;
816 m_bezier0->copy(bezier0);
817 }
818 if (bezier1 != NULL) {
819 m_bezier1 = new Bezier;
820 m_bezier1->copy(bezier1);
821 }
822 if (bezier2 != NULL) {
823 m_bezier2 = new Bezier;
824 m_bezier2->copy(bezier2);
825 }
826
827 m_fromConnectorID = connectorID;
828 m_index = index;
829 m_oldCount = oldCount;
830 m_newCount = newCount;
831 m_pos = pos;
832 }
833
undo()834 void ChangeLegBendpointCommand::undo()
835 {
836 if (m_newCount < m_oldCount) {
837 m_sketchWidget->addLegBendpoint(m_fromID, m_fromConnectorID, m_index, m_pos, m_bezier0, m_bezier1);
838 }
839 else {
840 m_sketchWidget->removeLegBendpoint(m_fromID, m_fromConnectorID, m_index, m_bezier0);
841 }
842 BaseCommand::undo();
843 }
844
redo()845 void ChangeLegBendpointCommand::redo()
846 {
847 if (m_skipFirstRedo) {
848 m_skipFirstRedo = false;
849 }
850 else {
851 if (m_newCount > m_oldCount) {
852 m_sketchWidget->addLegBendpoint(m_fromID, m_fromConnectorID, m_index, m_pos, m_bezier1, m_bezier2);
853 }
854 else {
855 m_sketchWidget->removeLegBendpoint(m_fromID, m_fromConnectorID, m_index, m_bezier2);
856 }
857 }
858 BaseCommand::redo();
859 }
860
getParamString() const861 QString ChangeLegBendpointCommand::getParamString() const {
862 QString bezier;
863 if (m_bezier0) {
864 bezier += QString("(%1,%2)").arg(m_bezier0->cp0().x()).arg(m_bezier0->cp0().y());
865 bezier += QString("(%1,%2)").arg(m_bezier0->cp1().x()).arg(m_bezier0->cp1().y());
866 }
867
868 return QString("ChangeLegBendpointCommand ")
869 + BaseCommand::getParamString() +
870 QString(" fromid:%1 newp:%2")
871 .arg(m_fromID)
872 .arg(bezier)
873 ;
874 }
875
876 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
877
RotateLegCommand(SketchWidget * sketchWidget,long fromID,const QString & fromConnectorID,const QPolygonF & oldLeg,bool active,QUndoCommand * parent)878 RotateLegCommand::RotateLegCommand(SketchWidget* sketchWidget, long fromID, const QString & fromConnectorID,
879 const QPolygonF & oldLeg, bool active, QUndoCommand *parent)
880 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
881 {
882 m_fromID = fromID;
883 m_oldLeg = oldLeg;
884 m_fromConnectorID = fromConnectorID;
885 m_active = active;
886 }
887
undo()888 void RotateLegCommand::undo()
889 {
890 BaseCommand::undo();
891 }
892
redo()893 void RotateLegCommand::redo()
894 {
895 m_sketchWidget->rotateLeg(m_fromID, m_fromConnectorID, m_oldLeg, m_active);
896 BaseCommand::redo();
897 }
898
getParamString() const899 QString RotateLegCommand::getParamString() const {
900
901 QString oldLeg;
902 foreach (QPointF p, m_oldLeg) {
903 oldLeg += QString("(%1,%2)").arg(p.x()).arg(p.y());
904 }
905 return QString("RotateLegCommand ")
906 + BaseCommand::getParamString() +
907 QString(" fromid:%1 fromc:%2 old:%3")
908 .arg(m_fromID)
909 .arg(m_fromConnectorID)
910 .arg(oldLeg)
911 ;
912 }
913
914 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
915
ChangeLayerCommand(SketchWidget * sketchWidget,long fromID,double oldZ,double newZ,ViewLayer::ViewLayerID oldLayer,ViewLayer::ViewLayerID newLayer,QUndoCommand * parent)916 ChangeLayerCommand::ChangeLayerCommand(SketchWidget *sketchWidget, long fromID,
917 double oldZ, double newZ,
918 ViewLayer::ViewLayerID oldLayer, ViewLayer::ViewLayerID newLayer,
919 QUndoCommand *parent)
920 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
921 {
922 m_fromID = fromID;
923 m_oldZ = oldZ;
924 m_newZ = newZ;
925 m_oldLayer = oldLayer;
926 m_newLayer = newLayer;
927 }
928
undo()929 void ChangeLayerCommand::undo()
930 {
931 m_sketchWidget->changeLayer(m_fromID, m_oldZ, m_oldLayer);
932 BaseCommand::undo();
933 }
934
redo()935 void ChangeLayerCommand::redo()
936 {
937 m_sketchWidget->changeLayer(m_fromID, m_newZ, m_newLayer);
938 BaseCommand::redo();
939 }
940
getParamString() const941 QString ChangeLayerCommand::getParamString() const {
942 return QString("ChangeLayerCommand ")
943 + BaseCommand::getParamString() +
944 QString(" fromid:%1 oldZ:%2 newZ:%3 oldL:%4 newL:%5")
945 .arg(m_fromID)
946 .arg(m_oldZ)
947 .arg(m_newZ)
948 .arg(m_oldLayer)
949 .arg(m_newLayer)
950 ;
951 }
952
953 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
954
SelectItemCommand(SketchWidget * sketchWidget,SelectItemType type,QUndoCommand * parent)955 SelectItemCommand::SelectItemCommand(SketchWidget* sketchWidget, SelectItemType type, QUndoCommand *parent)
956 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
957 {
958 m_type = type;
959 m_updated = false;
960 }
961
id() const962 int SelectItemCommand::id() const {
963 return selectItemCommandID;
964 }
965
setSelectItemType(SelectItemType type)966 void SelectItemCommand::setSelectItemType(SelectItemType type) {
967 m_type = type;
968 }
969
copyUndo(SelectItemCommand * sother)970 void SelectItemCommand::copyUndo(SelectItemCommand * sother) {
971 this->m_undoIDs.clear();
972 for (int i = 0; i < sother->m_undoIDs.size(); i++) {
973 this->m_undoIDs.append(sother->m_undoIDs[i]);
974 }
975 }
976
copyRedo(SelectItemCommand * sother)977 void SelectItemCommand::copyRedo(SelectItemCommand * sother) {
978 this->m_redoIDs.clear();
979 for (int i = 0; i < sother->m_redoIDs.size(); i++) {
980 this->m_redoIDs.append(sother->m_redoIDs[i]);
981 }
982 }
983
clearRedo()984 void SelectItemCommand::clearRedo() {
985 m_redoIDs.clear();
986 }
987
mergeWith(const QUndoCommand * other)988 bool SelectItemCommand::mergeWith(const QUndoCommand *other)
989 {
990 // "this" is earlier; "other" is later
991
992 if (other->id() != id()) {
993 return false;
994 }
995
996 const SelectItemCommand * sother = dynamic_cast<const SelectItemCommand *>(other);
997 if (sother == NULL) return false;
998
999 if (sother->crossViewType() != this->crossViewType()) {
1000 return false;
1001 }
1002
1003 this->m_redoIDs.clear();
1004 for (int i = 0; i < sother->m_redoIDs.size(); i++) {
1005 this->m_redoIDs.append(sother->m_redoIDs[i]);
1006 }
1007
1008 this->setText(sother->text());
1009 return true;
1010 }
1011
undo()1012 void SelectItemCommand::undo()
1013 {
1014 selectAllFromStack(m_undoIDs, true, true);
1015 BaseCommand::undo();
1016 }
1017
redo()1018 void SelectItemCommand::redo()
1019 {
1020 switch( m_type ){
1021 case NormalSelect:
1022 selectAllFromStack(m_redoIDs, true, true);
1023 break;
1024 case NormalDeselect:
1025 selectAllFromStack(m_redoIDs, false, false);
1026 break;
1027 case SelectAll:
1028 m_sketchWidget->selectAllItems(true, m_crossViewType == BaseCommand::CrossView);
1029 break;
1030 case DeselectAll:
1031 m_sketchWidget->selectAllItems(false, m_crossViewType == BaseCommand::CrossView);
1032 break;
1033 }
1034 BaseCommand::redo();
1035 }
1036
selectAllFromStack(QList<long> & stack,bool select,bool updateInfoView)1037 void SelectItemCommand::selectAllFromStack(QList<long> & stack, bool select, bool updateInfoView) {
1038 m_sketchWidget->clearSelection();
1039 for (int i = 0; i < stack.size(); i++) {
1040 m_sketchWidget->selectItem(stack[i], select, updateInfoView, m_crossViewType == BaseCommand::CrossView);
1041 }
1042 }
1043
addUndo(long id)1044 void SelectItemCommand::addUndo(long id) {
1045 m_undoIDs.append(id);
1046 }
1047
addRedo(long id)1048 void SelectItemCommand::addRedo(long id) {
1049 if(m_type == NormalSelect) {
1050 m_redoIDs.append(id);
1051 }
1052 }
1053
getParamString() const1054 QString SelectItemCommand::getParamString() const {
1055 return QString("SelectItemCommand ")
1056 + BaseCommand::getParamString() +
1057 QString(" type:%1")
1058 .arg(m_type);
1059 }
1060
updated()1061 bool SelectItemCommand::updated() {
1062 return m_updated;
1063 }
1064
1065
setUpdated(bool updated)1066 void SelectItemCommand::setUpdated(bool updated) {
1067 m_updated = updated;
1068 }
1069
1070
1071 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1072
ChangeZCommand(SketchWidget * sketchWidget,QUndoCommand * parent)1073 ChangeZCommand::ChangeZCommand(SketchWidget* sketchWidget, QUndoCommand *parent)
1074 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1075 {
1076 }
1077
~ChangeZCommand()1078 ChangeZCommand::~ChangeZCommand() {
1079 foreach (RealPair * realpair, m_triplets) {
1080 delete realpair;
1081 }
1082 m_triplets.clear();
1083 }
1084
addTriplet(long id,double oldZ,double newZ)1085 void ChangeZCommand::addTriplet(long id, double oldZ, double newZ) {
1086 m_triplets.insert(id, new RealPair (oldZ, newZ));
1087 }
1088
undo()1089 void ChangeZCommand::undo()
1090 {
1091 m_sketchWidget->changeZ(m_triplets, first);
1092 BaseCommand::undo();
1093 }
1094
redo()1095 void ChangeZCommand::redo()
1096 {
1097 m_sketchWidget->changeZ(m_triplets, second);
1098 BaseCommand::redo();
1099 }
1100
first(RealPair * pair)1101 double ChangeZCommand::first(RealPair * pair) {
1102 return pair->first;
1103 }
1104
second(RealPair * pair)1105 double ChangeZCommand::second(RealPair * pair) {
1106 return pair->second;
1107 }
1108
getParamString() const1109 QString ChangeZCommand::getParamString() const {
1110 return QString("ChangeZCommand ")
1111 + BaseCommand::getParamString();
1112 }
1113
1114 //////////////////////////////////////////singlev///////////////////////////////////////////////////////////////////////
1115
CheckStickyCommand(SketchWidget * sketchWidget,BaseCommand::CrossViewType crossViewType,long itemID,bool checkCurrent,CheckType checkType,QUndoCommand * parent)1116 CheckStickyCommand::CheckStickyCommand(SketchWidget* sketchWidget, BaseCommand::CrossViewType crossViewType, long itemID, bool checkCurrent, CheckType checkType, QUndoCommand *parent)
1117 : BaseCommand(crossViewType, sketchWidget, parent)
1118 {
1119 m_itemID = itemID;
1120 m_skipFirstRedo = true;
1121 m_checkType = checkType;
1122 m_checkCurrent = checkCurrent;
1123 }
1124
~CheckStickyCommand()1125 CheckStickyCommand::~CheckStickyCommand() {
1126 foreach (StickyThing * stickyThing, m_stickyList) {
1127 delete stickyThing;
1128 }
1129
1130 m_stickyList.clear();
1131 }
1132
undo()1133 void CheckStickyCommand::undo()
1134 {
1135 if (m_checkType == RedoOnly) return;
1136
1137 foreach (StickyThing * stickyThing, m_stickyList) {
1138 if (m_checkType == RemoveOnly) {
1139 stickyThing->sketchWidget->stickem(stickyThing->fromID, stickyThing->toID, !stickyThing->stickem);
1140 }
1141 else {
1142 stickyThing->sketchWidget->stickem(stickyThing->fromID, stickyThing->toID, stickyThing->stickem);
1143 }
1144 }
1145 BaseCommand::undo();
1146 }
1147
redo()1148 void CheckStickyCommand::redo()
1149 {
1150 if (m_checkType == UndoOnly) return;
1151
1152 if (m_skipFirstRedo) {
1153 m_sketchWidget->checkSticky(m_itemID, m_crossViewType == BaseCommand::CrossView, m_checkCurrent, this);
1154 m_skipFirstRedo = false;
1155 }
1156 else {
1157 foreach (StickyThing * stickyThing, m_stickyList) {
1158 stickyThing->sketchWidget->stickem(stickyThing->fromID, stickyThing->toID, stickyThing->stickem);
1159 }
1160 }
1161 BaseCommand::redo();
1162 }
1163
getParamString() const1164 QString CheckStickyCommand::getParamString() const {
1165 return QString("CheckStickyCommand ")
1166 + BaseCommand::getParamString()
1167 + QString("id:%1")
1168 .arg(this->m_stickyList.count());
1169 }
1170
stick(SketchWidget * sketchWidget,long fromID,long toID,bool stickem)1171 void CheckStickyCommand::stick(SketchWidget * sketchWidget, long fromID, long toID, bool stickem) {
1172 StickyThing * stickyThing = new StickyThing;
1173 stickyThing->sketchWidget = sketchWidget;
1174 stickyThing->fromID = fromID;
1175 stickyThing->toID = toID;
1176 stickyThing->stickem = stickem;
1177 m_stickyList.append(stickyThing);
1178 }
1179
1180 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1181
CleanUpWiresCommand(SketchWidget * sketchWidget,CleanUpWiresCommand::Direction direction,QUndoCommand * parent)1182 CleanUpWiresCommand::CleanUpWiresCommand(SketchWidget* sketchWidget, CleanUpWiresCommand::Direction direction, QUndoCommand *parent)
1183 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
1184 {
1185 m_direction = direction;
1186 }
1187
undo()1188 void CleanUpWiresCommand::undo()
1189 {
1190 foreach (RatsnestConnectThing rct, m_ratsnestConnectThings) {
1191 m_sketchWidget->ratsnestConnect(rct.id, rct.connectorID, !rct.connect, true);
1192 }
1193
1194 if (m_sketchWidgets.count() > 0) {
1195 subUndo();
1196 }
1197
1198 if (m_direction == UndoOnly) {
1199 m_sketchWidget->cleanUpWires(m_crossViewType == BaseCommand::CrossView, NULL);
1200 }
1201 BaseCommand::undo();
1202 }
1203
redo()1204 void CleanUpWiresCommand::redo()
1205 {
1206 foreach (RatsnestConnectThing rct, m_ratsnestConnectThings) {
1207 m_sketchWidget->ratsnestConnect(rct.id, rct.connectorID, rct.connect, true);
1208 }
1209
1210 if (m_sketchWidgets.count() > 0) {
1211 subRedo();
1212 }
1213
1214 if (m_direction == RedoOnly) {
1215 m_sketchWidget->cleanUpWires(m_crossViewType == BaseCommand::CrossView, this);
1216 }
1217 BaseCommand::redo();
1218 }
1219
addRatsnestConnect(long id,const QString & connectorID,bool connect)1220 void CleanUpWiresCommand::addRatsnestConnect(long id, const QString & connectorID, bool connect)
1221 {
1222 RatsnestConnectThing rct;
1223 rct.id = id;
1224 rct.connectorID = connectorID;
1225 rct.connect = connect;
1226 m_ratsnestConnectThings.append(rct);
1227 }
1228
1229
addRoutingStatus(SketchWidget * sketchWidget,const RoutingStatus & oldRoutingStatus,const RoutingStatus & newRoutingStatus)1230 void CleanUpWiresCommand::addRoutingStatus(SketchWidget * sketchWidget, const RoutingStatus & oldRoutingStatus, const RoutingStatus & newRoutingStatus)
1231 {
1232 addSubCommand(new RoutingStatusCommand(sketchWidget, oldRoutingStatus, newRoutingStatus, NULL));
1233 }
1234
setDirection(CleanUpWiresCommand::Direction direction)1235 void CleanUpWiresCommand::setDirection(CleanUpWiresCommand::Direction direction)
1236 {
1237 m_direction = direction;
1238 }
1239
direction()1240 CleanUpWiresCommand::Direction CleanUpWiresCommand::direction()
1241 {
1242 return m_direction;
1243 }
1244
addTrace(SketchWidget * sketchWidget,Wire * wire)1245 void CleanUpWiresCommand::addTrace(SketchWidget * sketchWidget, Wire * wire)
1246 {
1247 if (m_parentCommand) {
1248 for (int i = 0; i < m_parentCommand->childCount(); i++) {
1249 const DeleteItemCommand * command = dynamic_cast<const DeleteItemCommand *>(m_parentCommand->child(i));
1250
1251 if (command == NULL) continue;
1252 if (command->itemID() == wire->id()) {
1253 return;
1254 }
1255 }
1256 }
1257
1258 m_sketchWidgets.insert(sketchWidget);
1259
1260 addSubCommand(new WireColorChangeCommand(sketchWidget, wire->id(), wire->colorString(), wire->colorString(), wire->opacity(), wire->opacity(), NULL));
1261 addSubCommand(new WireWidthChangeCommand(sketchWidget, wire->id(), wire->width(), wire->width(), NULL));
1262
1263 foreach (ConnectorItem * toConnectorItem, wire->connector0()->connectedToItems()) {
1264 addSubCommand(new ChangeConnectionCommand(sketchWidget, BaseCommand::CrossView, toConnectorItem->attachedToID(), toConnectorItem->connectorSharedID(),
1265 wire->id(), "connector0",
1266 ViewLayer::specFromID(wire->viewLayerID()),
1267 false, NULL));
1268 }
1269 foreach (ConnectorItem * toConnectorItem, wire->connector1()->connectedToItems()) {
1270 addSubCommand(new ChangeConnectionCommand(sketchWidget, BaseCommand::CrossView, toConnectorItem->attachedToID(), toConnectorItem->connectorSharedID(),
1271 wire->id(), "connector1",
1272 ViewLayer::specFromID(wire->viewLayerID()),
1273 false, NULL));
1274 }
1275
1276 addSubCommand(new DeleteItemCommand(sketchWidget, BaseCommand::CrossView, ModuleIDNames::WireModuleIDName, wire->viewLayerPlacement(), wire->getViewGeometry(), wire->id(), wire->modelPart()->modelIndex(), NULL));
1277 }
1278
hasTraces(SketchWidget * sketchWidget)1279 bool CleanUpWiresCommand::hasTraces(SketchWidget * sketchWidget) {
1280 return m_sketchWidgets.contains(sketchWidget);
1281 }
1282
getParamString() const1283 QString CleanUpWiresCommand::getParamString() const {
1284 return QString("CleanUpWiresCommand ")
1285 + BaseCommand::getParamString()
1286 + QString(" direction %1").arg(m_direction);
1287 }
1288
1289 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1290
CleanUpRatsnestsCommand(SketchWidget * sketchWidget,CleanUpWiresCommand::Direction direction,QUndoCommand * parent)1291 CleanUpRatsnestsCommand::CleanUpRatsnestsCommand(SketchWidget* sketchWidget, CleanUpWiresCommand::Direction direction, QUndoCommand *parent)
1292 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
1293 {
1294 if (direction == CleanUpWiresCommand::UndoOnly) m_undoOnly = true;
1295 if (direction == CleanUpWiresCommand::RedoOnly) m_redoOnly = true;
1296 }
1297
undo()1298 void CleanUpRatsnestsCommand::undo()
1299 {
1300 if (m_undoOnly) {
1301 m_sketchWidget->cleanupRatsnests(true);
1302 }
1303 BaseCommand::undo();
1304 }
1305
redo()1306 void CleanUpRatsnestsCommand::redo()
1307 {
1308 if (m_redoOnly) {
1309 m_sketchWidget->cleanupRatsnests(true);
1310 }
1311 BaseCommand::redo();
1312 }
1313
getParamString() const1314 QString CleanUpRatsnestsCommand::getParamString() const {
1315 return QString("CleanUpRatsnestsCommand ")
1316 + BaseCommand::getParamString()
1317 ;
1318 }
1319
1320 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1321
WireColorChangeCommand(SketchWidget * sketchWidget,long wireId,const QString & oldColor,const QString & newColor,double oldOpacity,double newOpacity,QUndoCommand * parent)1322 WireColorChangeCommand::WireColorChangeCommand(SketchWidget* sketchWidget, long wireId, const QString &oldColor, const QString &newColor, double oldOpacity, double newOpacity, QUndoCommand *parent)
1323 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1324 {
1325 m_wireId = wireId;
1326 m_oldColor = oldColor;
1327 m_newColor = newColor;
1328 m_oldOpacity = oldOpacity;
1329 m_newOpacity = newOpacity;
1330 }
1331
undo()1332 void WireColorChangeCommand::undo() {
1333 m_sketchWidget->changeWireColor(m_wireId, m_oldColor, m_oldOpacity);
1334 BaseCommand::undo();
1335 }
1336
redo()1337 void WireColorChangeCommand::redo() {
1338 m_sketchWidget->changeWireColor(m_wireId, m_newColor, m_newOpacity);
1339 BaseCommand::redo();
1340 }
1341
getParamString() const1342 QString WireColorChangeCommand::getParamString() const {
1343 return QString("WireColorChangeCommand ")
1344 + BaseCommand::getParamString()
1345 + QString(" id:%1 oldcolor:%2 oldop:%3 newcolor:%4 newop:%5")
1346 .arg(m_wireId).arg(m_oldColor).arg(m_oldOpacity).arg(m_newColor).arg(m_newOpacity);
1347
1348 }
1349
1350 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1351
WireWidthChangeCommand(SketchWidget * sketchWidget,long wireId,double oldWidth,double newWidth,QUndoCommand * parent)1352 WireWidthChangeCommand::WireWidthChangeCommand(SketchWidget* sketchWidget, long wireId, double oldWidth, double newWidth, QUndoCommand *parent)
1353 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1354 {
1355 m_wireId = wireId;
1356 m_oldWidth = oldWidth;
1357 m_newWidth = newWidth;
1358 }
1359
undo()1360 void WireWidthChangeCommand::undo() {
1361 m_sketchWidget->changeWireWidth(m_wireId, m_oldWidth);
1362 BaseCommand::undo();
1363 }
1364
redo()1365 void WireWidthChangeCommand::redo() {
1366 m_sketchWidget->changeWireWidth(m_wireId, m_newWidth);
1367 BaseCommand::redo();
1368 }
1369
1370
getParamString() const1371 QString WireWidthChangeCommand::getParamString() const {
1372 return QString("WireWidthChangeCommand ")
1373 + BaseCommand::getParamString()
1374 + QString(" id:%1 oldw:%2 neww:%3")
1375 .arg(m_wireId).arg(m_oldWidth).arg(m_newWidth);
1376
1377 }
1378
1379 ///////////////////////////////////////////
1380
RoutingStatusCommand(SketchWidget * sketchWidget,const RoutingStatus & oldRoutingStatus,const RoutingStatus & newRoutingStatus,QUndoCommand * parent)1381 RoutingStatusCommand::RoutingStatusCommand(SketchWidget * sketchWidget, const RoutingStatus & oldRoutingStatus, const RoutingStatus & newRoutingStatus, QUndoCommand * parent)
1382 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1383 {
1384 m_oldRoutingStatus = oldRoutingStatus;
1385 m_newRoutingStatus = newRoutingStatus;
1386 }
1387
undo()1388 void RoutingStatusCommand::undo() {
1389 m_sketchWidget->forwardRoutingStatus(m_oldRoutingStatus);
1390 BaseCommand::undo();
1391 }
1392
redo()1393 void RoutingStatusCommand::redo() {
1394 m_sketchWidget->forwardRoutingStatus(m_newRoutingStatus);
1395 BaseCommand::redo();
1396 }
1397
getParamString() const1398 QString RoutingStatusCommand::getParamString() const {
1399 return QString("RoutingStatusCommand ")
1400 + BaseCommand::getParamString()
1401 + QString(" oldnet:%1 oldnetrouted:%2 oldconnectors:%3 oldjumpers:%4 newnet:%51 newnetrouted:%6 newconnectors:%7 newjumpers:%8 ")
1402 .arg(m_oldRoutingStatus.m_netCount).arg(m_oldRoutingStatus.m_netRoutedCount).arg(m_oldRoutingStatus.m_connectorsLeftToRoute).arg(m_oldRoutingStatus.m_jumperItemCount)
1403 .arg(m_newRoutingStatus.m_netCount).arg(m_newRoutingStatus.m_netRoutedCount).arg(m_newRoutingStatus.m_connectorsLeftToRoute).arg(m_newRoutingStatus.m_jumperItemCount);
1404
1405 }
1406
1407 ///////////////////////////////////////////////
1408
ShowLabelFirstTimeCommand(SketchWidget * sketchWidget,CrossViewType crossView,long id,bool oldVis,bool newVis,QUndoCommand * parent)1409 ShowLabelFirstTimeCommand::ShowLabelFirstTimeCommand(SketchWidget *sketchWidget, CrossViewType crossView, long id, bool oldVis, bool newVis, QUndoCommand *parent)
1410 : BaseCommand(crossView, sketchWidget, parent)
1411 {
1412 m_itemID = id;
1413 m_oldVis = oldVis;
1414 m_newVis = newVis;
1415 }
1416
undo()1417 void ShowLabelFirstTimeCommand::undo()
1418 {
1419 BaseCommand::undo();
1420 }
1421
redo()1422 void ShowLabelFirstTimeCommand::redo()
1423 {
1424 m_sketchWidget->showLabelFirstTime(m_itemID, m_newVis, true);
1425 BaseCommand::redo();
1426 }
1427
getParamString() const1428 QString ShowLabelFirstTimeCommand::getParamString() const {
1429 return QString("ShowLabelFirstTimeCommand ")
1430 + BaseCommand::getParamString()
1431 + QString(" id:%1 %2 %3")
1432 .arg(m_itemID).arg(m_oldVis).arg(m_newVis);
1433
1434 }
1435
1436 ///////////////////////////////////////////////
1437
RestoreLabelCommand(SketchWidget * sketchWidget,long id,QDomElement & element,QUndoCommand * parent)1438 RestoreLabelCommand::RestoreLabelCommand(SketchWidget *sketchWidget,long id, QDomElement & element, QUndoCommand *parent)
1439 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1440 {
1441 m_itemID = id;
1442 m_element = element;
1443 // seems to be safe to keep a copy of the element even though the document may no longer exist
1444 }
1445
undo()1446 void RestoreLabelCommand::undo()
1447 {
1448 BaseCommand::undo();
1449 }
1450
redo()1451 void RestoreLabelCommand::redo()
1452 {
1453 m_sketchWidget->restorePartLabel(m_itemID, m_element);
1454 BaseCommand::redo();
1455 }
1456
getParamString() const1457 QString RestoreLabelCommand::getParamString() const {
1458 return QString("RestoreLabelCommand ")
1459 + BaseCommand::getParamString()
1460 + QString(" id:%1")
1461 .arg(m_itemID);
1462
1463 }
1464
1465 ///////////////////////////////////////////////
1466
MoveLabelCommand(SketchWidget * sketchWidget,long id,QPointF oldPos,QPointF oldOffset,QPointF newPos,QPointF newOffset,QUndoCommand * parent)1467 MoveLabelCommand::MoveLabelCommand(SketchWidget *sketchWidget, long id, QPointF oldPos, QPointF oldOffset, QPointF newPos, QPointF newOffset, QUndoCommand *parent)
1468 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1469 {
1470 m_itemID = id;
1471 m_oldPos = oldPos;
1472 m_newPos = newPos;
1473 m_oldOffset = oldOffset;
1474 m_newOffset = newOffset;
1475 }
1476
undo()1477 void MoveLabelCommand::undo()
1478 {
1479 m_sketchWidget->movePartLabel(m_itemID, m_oldPos, m_oldOffset);
1480 BaseCommand::undo();
1481 }
1482
redo()1483 void MoveLabelCommand::redo()
1484 {
1485 m_sketchWidget->movePartLabel(m_itemID, m_newPos, m_newOffset);
1486 BaseCommand::redo();
1487 }
1488
1489
getParamString() const1490 QString MoveLabelCommand::getParamString() const {
1491 return QString("MoveLabelCommand ")
1492 + BaseCommand::getParamString()
1493 + QString(" id:%1")
1494 .arg(m_itemID);
1495
1496 }
1497
1498 ///////////////////////////////////////////////
1499
MoveLockCommand(SketchWidget * sketchWidget,long id,bool oldLock,bool newLock,QUndoCommand * parent)1500 MoveLockCommand::MoveLockCommand(SketchWidget *sketchWidget, long id, bool oldLock, bool newLock, QUndoCommand *parent)
1501 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1502 {
1503 m_itemID = id;
1504 m_oldLock = oldLock;
1505 m_newLock = newLock;
1506 }
1507
undo()1508 void MoveLockCommand::undo()
1509 {
1510 m_sketchWidget->setMoveLock(m_itemID, m_oldLock);
1511 BaseCommand::undo();
1512 }
1513
redo()1514 void MoveLockCommand::redo()
1515 {
1516 m_sketchWidget->setMoveLock(m_itemID, m_newLock);
1517 BaseCommand::redo();
1518 }
1519
1520
getParamString() const1521 QString MoveLockCommand::getParamString() const {
1522 return QString("MoveLockCommand ")
1523 + BaseCommand::getParamString()
1524 + QString(" id:%1 o:%2 n:%3")
1525 .arg(m_itemID)
1526 .arg(m_oldLock)
1527 .arg(m_newLock);
1528
1529 }
1530
1531 ///////////////////////////////////////////////
1532
ChangeLabelTextCommand(SketchWidget * sketchWidget,long id,const QString & oldText,const QString & newText,QUndoCommand * parent)1533 ChangeLabelTextCommand::ChangeLabelTextCommand(SketchWidget *sketchWidget, long id,
1534 const QString & oldText, const QString & newText,
1535 QUndoCommand *parent)
1536 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
1537 {
1538 m_itemID = id;
1539 m_oldText = oldText;
1540 m_newText = newText;
1541 }
1542
undo()1543 void ChangeLabelTextCommand::undo() {
1544 m_sketchWidget->setInstanceTitle(m_itemID, m_newText, m_oldText, false, true);
1545 BaseCommand::undo();
1546 }
1547
redo()1548 void ChangeLabelTextCommand::redo() {
1549 m_sketchWidget->setInstanceTitle(m_itemID, m_oldText, m_newText, false, true);
1550 BaseCommand::redo();
1551 }
1552
getParamString() const1553 QString ChangeLabelTextCommand::getParamString() const {
1554 return QString("ChangeLabelTextCommand ")
1555 + BaseCommand::getParamString()
1556 + QString(" id:%1 old:%2 new:%3")
1557 .arg(m_itemID).arg(m_oldText).arg(m_newText);
1558
1559 }
1560
1561 ///////////////////////////////////////////////
1562
IncLabelTextCommand(SketchWidget * sketchWidget,long id,QUndoCommand * parent)1563 IncLabelTextCommand::IncLabelTextCommand(SketchWidget *sketchWidget, long id, QUndoCommand *parent)
1564 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
1565 {
1566 m_itemID = id;
1567 }
1568
undo()1569 void IncLabelTextCommand::undo() {
1570 // only used when creating new parts via paste
1571 BaseCommand::undo();
1572 }
1573
redo()1574 void IncLabelTextCommand::redo() {
1575 if (!m_skipFirstRedo) {
1576 m_sketchWidget->incInstanceTitle(m_itemID);
1577 }
1578 BaseCommand::redo();
1579 }
1580
getParamString() const1581 QString IncLabelTextCommand::getParamString() const {
1582 return QString("IncLabelTextCommand ")
1583 + BaseCommand::getParamString()
1584 + QString(" id:%1")
1585 .arg(m_itemID);
1586
1587 }///////////////////////////////////////////////
1588
ChangeNoteTextCommand(SketchWidget * sketchWidget,long id,const QString & oldText,const QString & newText,QSizeF oldSize,QSizeF newSize,QUndoCommand * parent)1589 ChangeNoteTextCommand::ChangeNoteTextCommand(SketchWidget *sketchWidget, long id,
1590 const QString & oldText, const QString & newText,
1591 QSizeF oldSize, QSizeF newSize, QUndoCommand *parent)
1592 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
1593 {
1594 m_itemID = id;
1595 m_oldText = oldText;
1596 m_newText = newText;
1597 m_oldSize = oldSize;
1598 m_newSize = newSize;
1599 }
1600
undo()1601 void ChangeNoteTextCommand::undo() {
1602 m_sketchWidget->setNoteText(m_itemID, m_oldText);
1603 if (m_oldSize != m_newSize) {
1604 m_sketchWidget->resizeNote(m_itemID, m_oldSize);
1605 }
1606 BaseCommand::undo();
1607 }
1608
redo()1609 void ChangeNoteTextCommand::redo() {
1610 if (m_skipFirstRedo) {
1611 m_skipFirstRedo = false;
1612 return;
1613 }
1614
1615 m_sketchWidget->setNoteText(m_itemID, m_newText);
1616 if (m_oldSize != m_newSize) {
1617 m_sketchWidget->resizeNote(m_itemID, m_newSize);
1618 }
1619 BaseCommand::redo();
1620 }
1621
id() const1622 int ChangeNoteTextCommand::id() const {
1623 return changeNoteTextCommandID;
1624 }
1625
mergeWith(const QUndoCommand * other)1626 bool ChangeNoteTextCommand::mergeWith(const QUndoCommand *other)
1627 {
1628 // "this" is earlier; "other" is later
1629
1630 if (other->id() != id()) {
1631 return false;
1632 }
1633
1634 const ChangeNoteTextCommand * sother = dynamic_cast<const ChangeNoteTextCommand *>(other);
1635 if (sother == NULL) return false;
1636
1637 if (sother->m_itemID != m_itemID) {
1638 // this is not the same label so don't merge
1639 return false;
1640 }
1641
1642 m_newSize = sother->m_newSize;
1643 m_newText = sother->m_newText;
1644 return true;
1645 }
1646
getParamString() const1647 QString ChangeNoteTextCommand::getParamString() const {
1648 return QString("ChangeNoteTextCommand ")
1649 + BaseCommand::getParamString()
1650 + QString(" id:%1 old:%2 new:%3")
1651 .arg(m_itemID).arg(m_oldText).arg(m_newText);
1652
1653 }
1654
1655 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1656
RotateFlipLabelCommand(SketchWidget * sketchWidget,long itemID,double degrees,Qt::Orientations orientation,QUndoCommand * parent)1657 RotateFlipLabelCommand::RotateFlipLabelCommand(SketchWidget* sketchWidget, long itemID, double degrees, Qt::Orientations orientation, QUndoCommand *parent)
1658 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1659 {
1660 m_itemID = itemID;
1661 m_degrees = degrees;
1662 m_orientation = orientation;
1663 }
1664
undo()1665 void RotateFlipLabelCommand::undo()
1666 {
1667 m_sketchWidget->rotateFlipPartLabel(m_itemID, -m_degrees, m_orientation);
1668 BaseCommand::undo();
1669 }
1670
redo()1671 void RotateFlipLabelCommand::redo()
1672 {
1673 m_sketchWidget->rotateFlipPartLabel(m_itemID, m_degrees, m_orientation);
1674 BaseCommand::redo();
1675 }
1676
getParamString() const1677 QString RotateFlipLabelCommand::getParamString() const {
1678 return QString("RotateFlipLabelCommand ")
1679 + BaseCommand::getParamString()
1680 + QString(" id:%1 degrees:%2 orientation:%3")
1681 .arg(m_itemID).arg(m_degrees).arg(m_orientation);
1682
1683 }
1684
1685 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1686
ResizeNoteCommand(SketchWidget * sketchWidget,long itemID,const QSizeF & oldSize,const QSizeF & newSize,QUndoCommand * parent)1687 ResizeNoteCommand::ResizeNoteCommand(SketchWidget* sketchWidget, long itemID, const QSizeF & oldSize, const QSizeF & newSize, QUndoCommand *parent)
1688 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1689 {
1690 m_itemID = itemID;
1691 m_oldSize = oldSize;
1692 m_newSize = newSize;
1693 }
1694
undo()1695 void ResizeNoteCommand::undo()
1696 {
1697 m_sketchWidget->resizeNote(m_itemID, m_oldSize);
1698 BaseCommand::undo();
1699 }
1700
redo()1701 void ResizeNoteCommand::redo()
1702 {
1703 m_sketchWidget->resizeNote(m_itemID, m_newSize);
1704 BaseCommand::redo();
1705 }
1706
getParamString() const1707 QString ResizeNoteCommand::getParamString() const {
1708 return QString("ResizeNoteCommand ")
1709 + BaseCommand::getParamString()
1710 + QString(" id:%1 oldsz:%2 %3 newsz:%4 %5")
1711 .arg(m_itemID).arg(m_oldSize.width()).arg(m_oldSize.height()).arg(m_newSize.width()).arg(m_newSize.height());
1712
1713 }
1714
1715
1716 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1717
ResizeBoardCommand(SketchWidget * sketchWidget,long itemID,double oldWidth,double oldHeight,double newWidth,double newHeight,QUndoCommand * parent)1718 ResizeBoardCommand::ResizeBoardCommand(SketchWidget * sketchWidget, long itemID, double oldWidth, double oldHeight, double newWidth, double newHeight, QUndoCommand * parent)
1719 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1720 {
1721 m_itemID = itemID;
1722 m_oldWidth = oldWidth;
1723 m_newWidth = newWidth;
1724 m_oldHeight = oldHeight;
1725 m_newHeight = newHeight;
1726 }
1727
undo()1728 void ResizeBoardCommand::undo() {
1729 if (!m_redoOnly) {
1730 m_sketchWidget->resizeBoard(m_itemID, m_oldWidth, m_oldHeight);
1731 }
1732 BaseCommand::undo();
1733 }
1734
redo()1735 void ResizeBoardCommand::redo() {
1736 if (!m_undoOnly) {
1737 m_sketchWidget->resizeBoard(m_itemID, m_newWidth, m_newHeight);
1738 }
1739 BaseCommand::redo();
1740 }
1741
getParamString() const1742 QString ResizeBoardCommand::getParamString() const {
1743
1744 return QString("ResizeBoardCommand ")
1745 + BaseCommand::getParamString() +
1746 QString(" id:%1 ow:%2 oh:%3 nw:%4 nh:%5")
1747 .arg(m_itemID)
1748 .arg(m_oldWidth)
1749 .arg(m_oldHeight)
1750 .arg(m_newWidth)
1751 .arg(m_newHeight);
1752 }
1753
1754 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1755
TransformItemCommand(SketchWidget * sketchWidget,long id,const QMatrix & oldMatrix,const QMatrix & newMatrix,QUndoCommand * parent)1756 TransformItemCommand::TransformItemCommand(SketchWidget *sketchWidget, long id, const QMatrix & oldMatrix, const QMatrix & newMatrix, QUndoCommand *parent)
1757 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1758 {
1759 m_itemID = id;
1760 m_oldMatrix = oldMatrix;
1761 m_newMatrix = newMatrix;
1762 }
1763
undo()1764 void TransformItemCommand::undo()
1765 {
1766 m_sketchWidget->transformItem(m_itemID, m_oldMatrix);
1767 BaseCommand::undo();
1768 }
1769
redo()1770 void TransformItemCommand::redo()
1771 {
1772 m_sketchWidget->transformItem(m_itemID, m_newMatrix);
1773 BaseCommand::redo();
1774 }
1775
getParamString() const1776 QString TransformItemCommand::getParamString() const {
1777 return QString("TransformItemCommand ")
1778 + BaseCommand::getParamString() +
1779 QString(" id:%1")
1780 .arg(m_itemID);
1781 }
1782
1783 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1784
SetResistanceCommand(SketchWidget * sketchWidget,long itemID,QString oldResistance,QString newResistance,QString oldPinSpacing,QString newPinSpacing,QUndoCommand * parent)1785 SetResistanceCommand::SetResistanceCommand(SketchWidget * sketchWidget, long itemID, QString oldResistance, QString newResistance, QString oldPinSpacing, QString newPinSpacing, QUndoCommand * parent)
1786 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
1787 {
1788 m_itemID = itemID;
1789 m_oldResistance = oldResistance;
1790 m_newResistance = newResistance;
1791 m_oldPinSpacing = oldPinSpacing;
1792 m_newPinSpacing = newPinSpacing;
1793 }
1794
undo()1795 void SetResistanceCommand::undo() {
1796 m_sketchWidget->setResistance(m_itemID, m_oldResistance, m_oldPinSpacing, true);
1797 BaseCommand::undo();
1798 }
1799
redo()1800 void SetResistanceCommand::redo() {
1801 m_sketchWidget->setResistance(m_itemID, m_newResistance, m_newPinSpacing, true);
1802 BaseCommand::redo();
1803 }
1804
getParamString() const1805 QString SetResistanceCommand::getParamString() const {
1806
1807 return QString("SetResistanceCommand ")
1808 + BaseCommand::getParamString() +
1809 QString(" id:%1 ov:%2 nv:%3")
1810 .arg(m_itemID)
1811 .arg(m_oldResistance)
1812 .arg(m_newResistance);
1813 }
1814
1815 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1816
SetPropCommand(SketchWidget * sketchWidget,long itemID,QString prop,QString oldValue,QString newValue,bool redraw,QUndoCommand * parent)1817 SetPropCommand::SetPropCommand(SketchWidget * sketchWidget, long itemID, QString prop, QString oldValue, QString newValue, bool redraw, QUndoCommand * parent)
1818 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
1819 {
1820 m_redraw = redraw;
1821 m_itemID = itemID;
1822 m_prop = prop;
1823 m_oldValue = oldValue;
1824 m_newValue = newValue;
1825 }
1826
undo()1827 void SetPropCommand::undo() {
1828 m_sketchWidget->setProp(m_itemID, m_prop, m_oldValue, m_redraw, true);
1829 BaseCommand::undo();
1830 }
1831
redo()1832 void SetPropCommand::redo() {
1833 m_sketchWidget->setProp(m_itemID, m_prop, m_newValue, m_redraw, true);
1834 BaseCommand::redo();
1835 }
1836
getParamString() const1837 QString SetPropCommand::getParamString() const {
1838
1839 return QString("SetPropCommand ")
1840 + BaseCommand::getParamString() +
1841 QString(" id:%1 p:%2 o:%3 n:%4")
1842 .arg(m_itemID)
1843 .arg(m_prop)
1844 .arg(m_oldValue)
1845 .arg(m_newValue);
1846 }
1847
1848 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1849
ResizeJumperItemCommand(SketchWidget * sketchWidget,long itemID,QPointF oldPos,QPointF oldC0,QPointF oldC1,QPointF newPos,QPointF newC0,QPointF newC1,QUndoCommand * parent)1850 ResizeJumperItemCommand::ResizeJumperItemCommand(SketchWidget * sketchWidget, long itemID, QPointF oldPos, QPointF oldC0, QPointF oldC1, QPointF newPos, QPointF newC0, QPointF newC1, QUndoCommand * parent)
1851 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1852 {
1853 m_itemID = itemID;
1854 m_oldPos = oldPos;
1855 m_newPos = newPos;
1856 m_oldC0 = oldC0;
1857 m_newC0 = newC0;
1858 m_oldC1 = oldC1;
1859 m_newC1 = newC1;
1860 }
1861
undo()1862 void ResizeJumperItemCommand::undo() {
1863 m_sketchWidget->resizeJumperItem(m_itemID, m_oldPos, m_oldC0, m_oldC1);
1864 BaseCommand::undo();
1865 }
1866
redo()1867 void ResizeJumperItemCommand::redo() {
1868 m_sketchWidget->resizeJumperItem(m_itemID, m_newPos, m_newC0, m_newC1);
1869 BaseCommand::redo();
1870 }
1871
getParamString() const1872 QString ResizeJumperItemCommand::getParamString() const {
1873
1874 return QString("ResizeJumperItemCommand ")
1875 + BaseCommand::getParamString() +
1876 QString(" id:%1 op:%2,%3 oc0:%4,%5 oc1:%6,%7 np:%8,%9 nc0:%10,%11 nc1:%12,%13")
1877 .arg(m_itemID)
1878 .arg(m_oldPos.x()).arg(m_oldPos.y())
1879 .arg(m_oldC0.x()).arg(m_oldC0.y())
1880 .arg(m_oldC1.x()).arg(m_oldC1.y())
1881 .arg(m_newPos.x()).arg(m_newPos.y())
1882 .arg(m_newC0.x()).arg(m_newC0.y())
1883 .arg(m_newC1.x()).arg(m_newC1.y())
1884 ;
1885 }
1886
1887 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1888
ShowLabelCommand(class SketchWidget * sketchWidget,QUndoCommand * parent)1889 ShowLabelCommand::ShowLabelCommand(class SketchWidget *sketchWidget, QUndoCommand *parent)
1890 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1891 {
1892 }
1893
undo()1894 void ShowLabelCommand::undo()
1895 {
1896 foreach (long id, m_idStates.keys()) {
1897 m_sketchWidget->showPartLabel(id, (m_idStates.value(id) & 2) != 0);
1898 }
1899 BaseCommand::undo();
1900 }
1901
redo()1902 void ShowLabelCommand::redo()
1903 {
1904 foreach (long id, m_idStates.keys()) {
1905 m_sketchWidget->showPartLabel(id, (m_idStates.value(id) & 1) != 0);
1906 }
1907 BaseCommand::redo();
1908 }
1909
add(long id,bool prev,bool post)1910 void ShowLabelCommand::add(long id, bool prev, bool post)
1911 {
1912 int v = 0;
1913 if (prev) v += 2;
1914 if (post) v += 1;
1915 m_idStates.insert(id, v);
1916 }
1917
1918
getParamString() const1919 QString ShowLabelCommand::getParamString() const {
1920
1921 return QString("ShowLabelCommand ")
1922 + BaseCommand::getParamString();
1923 }
1924
1925 ///////////////////////////////////////////////
1926
LoadLogoImageCommand(SketchWidget * sketchWidget,long id,const QString & oldSvg,const QSizeF oldAspectRatio,const QString & oldFilename,const QString & newFilename,bool addName,QUndoCommand * parent)1927 LoadLogoImageCommand::LoadLogoImageCommand(SketchWidget *sketchWidget, long id,
1928 const QString & oldSvg, const QSizeF oldAspectRatio, const QString & oldFilename,
1929 const QString & newFilename, bool addName, QUndoCommand *parent)
1930 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1931 {
1932 m_itemID = id;
1933 m_oldFilename = oldFilename;
1934 m_newFilename = newFilename;
1935 m_oldAspectRatio = oldAspectRatio;
1936 m_oldSvg = oldSvg;
1937 m_addName = addName;
1938 }
1939
undo()1940 void LoadLogoImageCommand::undo() {
1941 if (!m_redoOnly) {
1942 m_sketchWidget->loadLogoImage(m_itemID, m_oldSvg, m_oldAspectRatio, m_oldFilename);
1943 }
1944 BaseCommand::undo();
1945 }
1946
redo()1947 void LoadLogoImageCommand::redo() {
1948 if (m_newFilename.isEmpty()) {
1949 }
1950 else if (!m_undoOnly) {
1951 m_sketchWidget->loadLogoImage(m_itemID, m_newFilename, m_addName);
1952 }
1953 BaseCommand::redo();
1954 }
1955
getParamString() const1956 QString LoadLogoImageCommand::getParamString() const {
1957 return QString("LoadLogoImageCommand ")
1958 + BaseCommand::getParamString()
1959 + QString(" id:%1 old:%2 new:%3")
1960 .arg(m_itemID).arg(m_oldFilename).arg(m_newFilename);
1961
1962 }
1963
1964 ///////////////////////////////////////////////
1965
ChangeBoardLayersCommand(SketchWidget * sketchWidget,int oldLayers,int newLayers,QUndoCommand * parent)1966 ChangeBoardLayersCommand::ChangeBoardLayersCommand(SketchWidget *sketchWidget, int oldLayers, int newLayers, QUndoCommand *parent)
1967 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
1968 {
1969 m_oldLayers = oldLayers;
1970 m_newLayers = newLayers;
1971 }
1972
undo()1973 void ChangeBoardLayersCommand::undo() {
1974 m_sketchWidget->changeBoardLayers(m_oldLayers, true);
1975 for (int i = childCount() - 1; i >= 0; i--) {
1976 ((QUndoCommand *) child(i))->undo();
1977 }
1978 BaseCommand::undo();
1979 }
1980
redo()1981 void ChangeBoardLayersCommand::redo() {
1982 m_sketchWidget->changeBoardLayers(m_newLayers, true);
1983 for (int i = 0; i < childCount(); i++) {
1984 ((QUndoCommand *) child(i))->redo();
1985 }
1986 BaseCommand::redo();
1987 }
1988
getParamString() const1989 QString ChangeBoardLayersCommand::getParamString() const {
1990 return QString("ChangeBoardLayersCommand ")
1991 + BaseCommand::getParamString()
1992 + QString(" old:%1 new:%2")
1993 .arg(m_oldLayers).arg(m_newLayers);
1994
1995 }
1996
1997
1998 ///////////////////////////////////////////////
1999
SetDropOffsetCommand(SketchWidget * sketchWidget,long id,QPointF dropOffset,QUndoCommand * parent)2000 SetDropOffsetCommand::SetDropOffsetCommand(SketchWidget *sketchWidget, long id, QPointF dropOffset, QUndoCommand *parent)
2001 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
2002 {
2003 m_itemID = id;
2004 m_dropOffset = dropOffset;
2005 }
2006
undo()2007 void SetDropOffsetCommand::undo() {
2008 // only used when creating new parts
2009 BaseCommand::undo();
2010 }
2011
redo()2012 void SetDropOffsetCommand::redo() {
2013 m_sketchWidget->setItemDropOffset(m_itemID, m_dropOffset);
2014 BaseCommand::redo();
2015
2016 }
2017
getParamString() const2018 QString SetDropOffsetCommand::getParamString() const {
2019 return QString("SetDropOffsetCommand ")
2020 + BaseCommand::getParamString()
2021 + QString(" id:%1 %2,%3")
2022 .arg(m_itemID).arg(m_dropOffset.x()).arg(m_dropOffset.y());
2023
2024 }
2025
2026 ///////////////////////////////////////////////
2027
RenamePinsCommand(SketchWidget * sketchWidget,long id,const QStringList & oldOnes,const QStringList & newOnes,bool singleRow,QUndoCommand * parent)2028 RenamePinsCommand::RenamePinsCommand(SketchWidget *sketchWidget, long id, const QStringList & oldOnes, const QStringList & newOnes, bool singleRow, QUndoCommand *parent) :
2029 BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
2030 {
2031 m_oldLabels = oldOnes;
2032 m_newLabels = newOnes;
2033 m_itemID = id;
2034 m_singleRow = singleRow;
2035 }
2036
undo()2037 void RenamePinsCommand::undo() {
2038 m_sketchWidget->renamePins(m_itemID, m_oldLabels, m_singleRow);
2039 BaseCommand::undo();
2040 }
2041
redo()2042 void RenamePinsCommand::redo() {
2043 m_sketchWidget->renamePins(m_itemID, m_newLabels, m_singleRow);
2044 BaseCommand::redo();
2045 }
2046
getParamString() const2047 QString RenamePinsCommand::getParamString() const {
2048 return QString("RenamePinsCommand ")
2049 + BaseCommand::getParamString()
2050 + QString(" id:%1 sr:%2")
2051 .arg(m_itemID).arg(m_singleRow);
2052
2053 }
2054
2055 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2056
GroundFillSeedCommand(SketchWidget * sketchWidget,QUndoCommand * parent)2057 GroundFillSeedCommand::GroundFillSeedCommand(SketchWidget* sketchWidget, QUndoCommand *parent)
2058 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
2059 {
2060 setText(QObject::tr("Set Ground Fill Seed"));
2061 }
2062
undo()2063 void GroundFillSeedCommand::undo()
2064 {
2065 foreach(GFSThing gfsThing, m_items) {
2066 m_sketchWidget->setGroundFillSeed(gfsThing.id, gfsThing.connectorID, !gfsThing.seed);
2067 }
2068 BaseCommand::undo();
2069 }
2070
redo()2071 void GroundFillSeedCommand::redo()
2072 {
2073 foreach(GFSThing gfsThing, m_items) {
2074 m_sketchWidget->setGroundFillSeed(gfsThing.id, gfsThing.connectorID, gfsThing.seed);
2075 }
2076 BaseCommand::redo();
2077 }
2078
addItem(long id,const QString & connectorID,bool seed)2079 void GroundFillSeedCommand::addItem(long id, const QString & connectorID, bool seed)
2080 {
2081 GFSThing gfsThing;
2082 gfsThing.id = id;
2083 gfsThing.connectorID = connectorID;
2084 gfsThing.seed = seed;
2085 m_items.append(gfsThing);
2086 }
2087
getParamString() const2088 QString GroundFillSeedCommand::getParamString() const {
2089 return QString("GroundFillSeedCommand ")
2090 + BaseCommand::getParamString() +
2091 QString(" items:%1")
2092 .arg(m_items.count())
2093 ;
2094 }
2095
2096 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2097
WireExtrasCommand(SketchWidget * sketchWidget,long fromID,const QDomElement & oldExtras,const QDomElement & newExtras,QUndoCommand * parent)2098 WireExtrasCommand::WireExtrasCommand(SketchWidget* sketchWidget, long fromID,
2099 const QDomElement & oldExtras, const QDomElement & newExtras,
2100 QUndoCommand *parent)
2101 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
2102 {
2103
2104 m_fromID = fromID;
2105 m_newExtras = newExtras;
2106 m_oldExtras = oldExtras;
2107 }
2108
undo()2109 void WireExtrasCommand::undo()
2110 {
2111 if (!m_redoOnly) {
2112 m_sketchWidget->setWireExtras(m_fromID, m_oldExtras);
2113 }
2114 BaseCommand::undo();
2115 }
2116
redo()2117 void WireExtrasCommand::redo()
2118 {
2119 if (!m_undoOnly) {
2120 m_sketchWidget->setWireExtras(m_fromID, m_newExtras);
2121 }
2122 BaseCommand::redo();
2123 }
2124
getParamString() const2125 QString WireExtrasCommand::getParamString() const {
2126 return QString("WireExtrasCommand ")
2127 + BaseCommand::getParamString() +
2128 QString(" fromid:%1 ")
2129 .arg(m_fromID)
2130 ;
2131 }
2132
2133 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2134
HidePartLayerCommand(SketchWidget * sketchWidget,long fromID,ViewLayer::ViewLayerID layerID,bool wasHidden,bool isHidden,QUndoCommand * parent)2135 HidePartLayerCommand::HidePartLayerCommand(SketchWidget *sketchWidget, long fromID,
2136 ViewLayer::ViewLayerID layerID, bool wasHidden, bool isHidden,
2137 QUndoCommand *parent)
2138 : BaseCommand(BaseCommand::SingleView, sketchWidget, parent)
2139 {
2140 m_fromID = fromID;
2141 m_wasHidden = wasHidden;
2142 m_isHidden = isHidden;
2143 m_layerID = layerID;
2144 }
2145
undo()2146 void HidePartLayerCommand::undo()
2147 {
2148 m_sketchWidget->hidePartLayer(m_fromID, m_layerID, m_wasHidden);
2149 BaseCommand::undo();
2150 }
2151
redo()2152 void HidePartLayerCommand::redo()
2153 {
2154 m_sketchWidget->hidePartLayer(m_fromID, m_layerID, m_isHidden);
2155 BaseCommand::redo();
2156 }
2157
getParamString() const2158 QString HidePartLayerCommand::getParamString() const {
2159 return QString("HidePartLayerCommand ")
2160 + BaseCommand::getParamString() +
2161 QString(" fromid:%1 l:%2 was:%3 is:%4")
2162 .arg(m_fromID)
2163 .arg(m_layerID)
2164 .arg(m_wasHidden)
2165 .arg(m_isHidden)
2166 ;
2167 }
2168
2169 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2170
AddSubpartCommand(SketchWidget * sketchWidget,CrossViewType crossView,long id,long subpartID,QUndoCommand * parent)2171 AddSubpartCommand::AddSubpartCommand(SketchWidget *sketchWidget, CrossViewType crossView, long id, long subpartID, QUndoCommand *parent)
2172 : BaseCommand(crossView, sketchWidget, parent)
2173 {
2174 m_itemID = id;
2175 m_subpartItemID = subpartID;
2176
2177 }
2178
undo()2179 void AddSubpartCommand::undo()
2180 {
2181 if (!m_redoOnly) {
2182 m_sketchWidget->addSubpart(m_itemID, m_subpartItemID, true);
2183 }
2184 BaseCommand::undo();
2185 }
2186
redo()2187 void AddSubpartCommand::redo()
2188 {
2189 if (!m_undoOnly) {
2190 m_sketchWidget->addSubpart(m_itemID, m_subpartItemID, true);
2191 }
2192 BaseCommand::redo();
2193 }
2194
getParamString() const2195 QString AddSubpartCommand::getParamString() const {
2196 return QString("AddSubpartCommand ")
2197 + BaseCommand::getParamString() +
2198 QString(" id:%1 subpart id:%2")
2199 .arg(m_itemID)
2200 .arg(m_subpartItemID)
2201 ;
2202 }
2203
2204 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2205
PackItemsCommand(SketchWidget * sketchWidget,int columns,const QList<long> & ids,QUndoCommand * parent)2206 PackItemsCommand::PackItemsCommand(SketchWidget *sketchWidget, int columns, const QList<long> & ids, QUndoCommand *parent)
2207 : BaseCommand(BaseCommand::CrossView, sketchWidget, parent)
2208 {
2209 m_ids = ids;
2210 m_columns = columns;
2211 m_firstTime = true;
2212 }
2213
undo()2214 void PackItemsCommand::undo()
2215 {
2216 BaseCommand::undo();
2217 }
2218
redo()2219 void PackItemsCommand::redo()
2220 {
2221 if (m_firstTime) {
2222 m_sketchWidget->packItems(m_columns, m_ids, m_parentCommand, true);
2223 m_firstTime = false;
2224 }
2225
2226 BaseCommand::redo();
2227 }
2228
getParamString() const2229 QString PackItemsCommand::getParamString() const {
2230 return QString("PackItemsCommand ")
2231 + BaseCommand::getParamString() +
2232 QString(" columns:%1 count:%2")
2233 .arg(m_columns)
2234 .arg(m_ids.count())
2235 ;
2236 }
2237
2238 ////////////////////////////////////
2239
TemporaryCommand(const QString & text)2240 TemporaryCommand::TemporaryCommand(const QString & text) : QUndoCommand(text) {
2241 m_enabled = true;
2242 }
2243
~TemporaryCommand()2244 TemporaryCommand::~TemporaryCommand() {
2245 }
2246
setEnabled(bool enabled)2247 void TemporaryCommand::setEnabled(bool enabled) {
2248 m_enabled = enabled;
2249 }
2250
redo()2251 void TemporaryCommand::redo() {
2252 if (m_enabled) {
2253 QUndoCommand::redo();
2254 }
2255 }
2256
2257