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 #ifndef COMMANDS_H 28 #define COMMANDS_H 29 30 #include <QUndoCommand> 31 #include <QHash> 32 #include <QPainterPath> 33 34 #include "viewgeometry.h" 35 #include "viewlayer.h" 36 #include "routingstatus.h" 37 #include "utils/misc.h" 38 #include "items/itembase.h" 39 40 ///////////////////////////////////////////// 41 42 class CommandProgress : public QObject { 43 Q_OBJECT 44 45 public: 46 CommandProgress(); 47 48 void setActive(bool); 49 bool active(); 50 void emitUndo(); 51 void emitRedo(); 52 53 signals: 54 void incUndo(); 55 void incRedo(); 56 57 protected: 58 bool m_active; 59 }; 60 61 ///////////////////////////////////////////// 62 63 class BaseCommand : public QUndoCommand 64 { 65 public: 66 enum CrossViewType { 67 SingleView, 68 CrossView 69 }; 70 71 public: 72 BaseCommand(BaseCommand::CrossViewType, class SketchWidget*, QUndoCommand* parent); 73 ~BaseCommand(); 74 75 BaseCommand::CrossViewType crossViewType() const; 76 void setCrossViewType(BaseCommand::CrossViewType); 77 class SketchWidget* sketchWidget() const; 78 int subCommandCount() const; 79 const BaseCommand * subCommand(int index) const; 80 virtual QString getDebugString() const; 81 const QUndoCommand * parentCommand() const; 82 void addSubCommand(BaseCommand * subCommand); 83 void subUndo(); 84 void subRedo(); 85 void subUndo(int index); 86 void subRedo(int index); 87 int index() const; 88 void setUndoOnly(); 89 void setRedoOnly(); 90 void setSkipFirstRedo(); 91 void undo(); 92 void redo(); 93 94 static int totalChildCount(const QUndoCommand *); 95 static CommandProgress * initProgress(); 96 static void clearProgress(); 97 98 protected: 99 virtual QString getParamString() const; 100 101 static int nextIndex; 102 103 protected: 104 BaseCommand::CrossViewType m_crossViewType; 105 class SketchWidget *m_sketchWidget; 106 QList<BaseCommand *> m_commands; 107 QUndoCommand * m_parentCommand; 108 int m_index; 109 bool m_undoOnly; 110 bool m_redoOnly; 111 bool m_skipFirstRedo; 112 113 static CommandProgress m_commandProgress; 114 }; 115 116 ///////////////////////////////////////////// 117 118 class AddDeleteItemCommand : public BaseCommand 119 { 120 public: 121 AddDeleteItemCommand(class SketchWidget * sketchWidget, BaseCommand::CrossViewType, QString moduleID, ViewLayer::ViewLayerPlacement, ViewGeometry &, qint64 id, long modelIndex, QUndoCommand *parent); 122 123 long itemID() const; 124 void setDropOrigin(class SketchWidget *); 125 class SketchWidget * dropOrigin(); 126 127 protected: 128 QString getParamString() const; 129 130 protected: 131 QString m_moduleID; 132 long m_itemID; 133 ViewGeometry m_viewGeometry; 134 long m_modelIndex; 135 class SketchWidget * m_dropOrigin; 136 ViewLayer::ViewLayerPlacement m_viewLayerPlacement; 137 }; 138 139 ///////////////////////////////////////////// 140 141 class AddItemCommand : public AddDeleteItemCommand 142 { 143 public: 144 AddItemCommand(class SketchWidget *sketchWidget, BaseCommand::CrossViewType, QString moduleID, ViewLayer::ViewLayerPlacement, ViewGeometry &, qint64 id, bool updateInfoView, long modelIndex, QUndoCommand *parent); 145 void undo(); 146 void redo(); 147 void addRestoreIndexesCommand(class RestoreIndexesCommand *); 148 149 protected: 150 QString getParamString() const; 151 152 protected: 153 bool m_updateInfoView; 154 bool m_module; 155 RestoreIndexesCommand * m_restoreIndexesCommand; 156 }; 157 158 ///////////////////////////////////////////// 159 160 class DeleteItemCommand : public AddDeleteItemCommand 161 { 162 public: 163 DeleteItemCommand(class SketchWidget *sketchWidget, BaseCommand::CrossViewType, QString moduleID, ViewLayer::ViewLayerPlacement, ViewGeometry &, qint64 id, long modelIndex, QUndoCommand *parent); 164 void undo(); 165 void redo(); 166 167 protected: 168 QString getParamString() const; 169 170 }; 171 172 ///////////////////////////////////////////// 173 174 class MoveItemCommand : public BaseCommand 175 { 176 public: 177 MoveItemCommand(class SketchWidget *sketchWidget, long id, ViewGeometry & oldG, ViewGeometry & newG, bool updateRatsnest, QUndoCommand *parent); 178 void undo(); 179 void redo(); 180 181 protected: 182 QString getParamString() const; 183 184 protected: 185 bool m_updateRatsnest; 186 long m_itemID; 187 ViewGeometry m_old; 188 ViewGeometry m_new; 189 }; 190 191 ///////////////////////////////////////////// 192 193 class SimpleMoveItemCommand : public BaseCommand 194 { 195 public: 196 SimpleMoveItemCommand(class SketchWidget *sketchWidget, long id, QPointF & oldP, QPointF & newP, QUndoCommand *parent); 197 void undo(); 198 void redo(); 199 200 protected: 201 QString getParamString() const; 202 203 protected: 204 long m_itemID; 205 QPointF m_old; 206 QPointF m_new; 207 }; 208 209 ///////////////////////////////////////////// 210 211 struct MoveItemThing { 212 long id; 213 QPointF oldPos; 214 QPointF newPos; 215 }; 216 217 class MoveItemsCommand : public BaseCommand 218 { 219 public: 220 MoveItemsCommand(class SketchWidget *sketchWidget, bool updateRatsnest, QUndoCommand *parent); 221 void undo(); 222 void redo(); 223 void addItem(long id, const QPointF & oldPos, const QPointF & newPos); 224 void addWire(long id, const QString & connectorID); 225 226 protected: 227 QString getParamString() const; 228 229 protected: 230 bool m_updateRatsnest; 231 QHash<long, QString> m_wires; 232 QList<MoveItemThing> m_items; 233 }; 234 235 ///////////////////////////////////////////// 236 237 class RotateItemCommand : public BaseCommand 238 { 239 public: 240 RotateItemCommand(class SketchWidget *sketchWidget, long id, double degrees, QUndoCommand *parent); 241 void undo(); 242 void redo(); 243 244 protected: 245 virtual QString getParamString() const; 246 247 protected: 248 long m_itemID; 249 double m_degrees; 250 }; 251 252 ///////////////////////////////////////////// 253 254 class FlipItemCommand : public BaseCommand 255 { 256 257 public: 258 FlipItemCommand(class SketchWidget *sketchWidget, long id, Qt::Orientations orientation, QUndoCommand *parent); 259 void undo(); 260 void redo(); 261 262 protected: 263 QString getParamString() const; 264 265 protected: 266 long m_itemID; 267 Qt::Orientations m_orientation; 268 }; 269 270 ///////////////////////////////////////////// 271 272 class TransformItemCommand : public BaseCommand 273 { 274 275 public: 276 TransformItemCommand(class SketchWidget *sketchWidget, long id, const class QMatrix & oldMatrix, const class QMatrix & newMatrix, QUndoCommand *parent); 277 void undo(); 278 void redo(); 279 280 protected: 281 QString getParamString() const; 282 283 protected: 284 long m_itemID; 285 QMatrix m_oldMatrix; 286 QMatrix m_newMatrix; 287 }; 288 289 ///////////////////////////////////////////// 290 291 class ChangeConnectionCommand : public BaseCommand 292 { 293 public: 294 ChangeConnectionCommand(class SketchWidget * sketchWidget, BaseCommand::CrossViewType, 295 long fromID, const QString & fromConnectorID, 296 long toID, const QString & toConnectorID, 297 ViewLayer::ViewLayerPlacement, 298 bool connect, QUndoCommand * parent); 299 void undo(); 300 void redo(); 301 void setUpdateConnections(bool updatem); 302 void disable(); 303 304 protected: 305 QString getParamString() const; 306 307 protected: 308 long m_fromID; 309 long m_toID; 310 QString m_fromConnectorID; 311 QString m_toConnectorID; 312 bool m_connect; 313 bool m_updateConnections; 314 ViewLayer::ViewLayerPlacement m_viewLayerPlacement; 315 bool m_enabled; 316 317 }; 318 319 ///////////////////////////////////////////// 320 321 class ChangeWireCommand : public BaseCommand 322 { 323 public: 324 ChangeWireCommand(class SketchWidget *sketchWidget, long fromID, 325 const QLineF & oldLine, const QLineF & newLine, QPointF oldPos, QPointF newPos, 326 bool updateConnections, bool updateRatsnest, 327 QUndoCommand *parent); 328 void undo(); 329 void redo(); 330 331 protected: 332 QString getParamString() const; 333 334 protected: 335 bool m_updateRatsnest; 336 long m_fromID; 337 QLineF m_newLine; 338 QLineF m_oldLine; 339 QPointF m_newPos; 340 QPointF m_oldPos; 341 bool m_updateConnections; 342 }; 343 344 ///////////////////////////////////////////// 345 346 class ChangeWireCurveCommand : public BaseCommand 347 { 348 public: 349 ChangeWireCurveCommand(class SketchWidget *sketchWidget, long fromID, 350 const class Bezier * oldBezier, const class Bezier * newBezier, bool wasAutoroutable, 351 QUndoCommand *parent); 352 void undo(); 353 void redo(); 354 355 protected: 356 QString getParamString() const; 357 358 protected: 359 long m_fromID; 360 class Bezier * m_newBezier; 361 class Bezier * m_oldBezier; 362 bool m_wasAutoroutable; 363 }; 364 365 ///////////////////////////////////////////// 366 367 class ChangeLegCommand : public BaseCommand 368 { 369 public: 370 ChangeLegCommand(class SketchWidget *sketchWidget, long fromID, const QString & fromConnectorID, 371 const QPolygonF & oldLeg, const QPolygonF & newLeg, bool relative, bool active, const QString & why, QUndoCommand *parent); 372 void undo(); 373 void redo(); 374 375 void setSimple(); 376 377 protected: 378 QString getParamString() const; 379 380 protected: 381 QString m_fromConnectorID; 382 long m_fromID; 383 QPolygonF m_newLeg; 384 QPolygonF m_oldLeg; 385 bool m_relative; 386 bool m_active; 387 bool m_simple; 388 QString m_why; 389 }; 390 391 ///////////////////////////////////////////// 392 393 class MoveLegBendpointCommand : public BaseCommand 394 { 395 public: 396 MoveLegBendpointCommand(class SketchWidget *sketchWidget, long fromID, const QString & fromConnectorID, 397 int index, QPointF oldPos, QPointF newPos, QUndoCommand *parent); 398 void undo(); 399 void redo(); 400 401 protected: 402 QString getParamString() const; 403 404 protected: 405 QString m_fromConnectorID; 406 long m_fromID; 407 QPointF m_newPos; 408 QPointF m_oldPos; 409 }; 410 411 ///////////////////////////////////////////// 412 413 class ChangeLegCurveCommand : public BaseCommand 414 { 415 public: 416 ChangeLegCurveCommand(class SketchWidget *sketchWidget, long fromID, const QString & fromConnectorID, int index, 417 const class Bezier * oldBezier, const class Bezier * newBezier, 418 QUndoCommand *parent); 419 void undo(); 420 void redo(); 421 422 protected: 423 QString getParamString() const; 424 425 protected: 426 long m_fromID; 427 class Bezier * m_newBezier; 428 class Bezier * m_oldBezier; 429 QString m_fromConnectorID; 430 int m_index; 431 }; 432 433 ///////////////////////////////////////////// 434 435 class ChangeLegBendpointCommand : public BaseCommand 436 { 437 public: 438 ChangeLegBendpointCommand(class SketchWidget *sketchWidget, long fromID, const QString & fromConnectorID, 439 int oldCount, int newCount, int index, QPointF pos, 440 const class Bezier *, const class Bezier *, const class Bezier *, QUndoCommand *parent); 441 void undo(); 442 void redo(); 443 444 protected: 445 QString getParamString() const; 446 447 protected: 448 long m_fromID; 449 class Bezier * m_bezier0; 450 class Bezier * m_bezier1; 451 class Bezier * m_bezier2; 452 QString m_fromConnectorID; 453 int m_index; 454 int m_oldCount; 455 int m_newCount; 456 QPointF m_pos; 457 }; 458 459 ///////////////////////////////////////////// 460 461 class RotateLegCommand : public BaseCommand 462 { 463 public: 464 RotateLegCommand(class SketchWidget *sketchWidget, long fromID, const QString & fromConnectorID, 465 const QPolygonF & oldLeg, bool active, QUndoCommand *parent); 466 void undo(); 467 void redo(); 468 469 protected: 470 QString getParamString() const; 471 472 protected: 473 QString m_fromConnectorID; 474 long m_fromID; 475 QPolygonF m_oldLeg; 476 bool m_active; 477 }; 478 479 ///////////////////////////////////////////// 480 481 class ChangeLayerCommand : public BaseCommand 482 { 483 public: 484 ChangeLayerCommand(class SketchWidget *sketchWidget, long fromID, 485 double oldZ, double newZ, 486 ViewLayer::ViewLayerID oldLayer, ViewLayer::ViewLayerID newLayer, 487 QUndoCommand *parent); 488 void undo(); 489 void redo(); 490 491 protected: 492 QString getParamString() const; 493 494 protected: 495 long m_fromID; 496 double m_newZ; 497 double m_oldZ; 498 ViewLayer::ViewLayerID m_newLayer; 499 ViewLayer::ViewLayerID m_oldLayer; 500 }; 501 502 ///////////////////////////////////////////// 503 504 class SelectItemCommand : public BaseCommand 505 { 506 public: 507 enum SelectItemType { 508 NormalSelect, 509 NormalDeselect, 510 SelectAll, 511 DeselectAll 512 }; 513 514 public: 515 SelectItemCommand(class SketchWidget *sketchWidget, SelectItemType type, QUndoCommand *parent); 516 517 void undo(); 518 void redo(); 519 void addUndo(long id); 520 void addRedo(long id); 521 void clearRedo(); 522 int id() const; 523 bool mergeWith(const QUndoCommand *other); 524 void copyUndo(SelectItemCommand * sother); 525 void copyRedo(SelectItemCommand * sother); 526 void setSelectItemType(SelectItemType); 527 bool updated(); 528 void setUpdated(bool); 529 530 protected: 531 void selectAllFromStack(QList<long> & stack, bool select, bool updateInfoView); 532 QString getParamString() const; 533 534 protected: 535 QList<long> m_undoIDs; 536 QList<long> m_redoIDs; 537 SelectItemType m_type; 538 bool m_updated; 539 540 protected: 541 static int selectItemCommandID; 542 }; 543 544 ///////////////////////////////////////////// 545 546 class ChangeZCommand : public BaseCommand 547 { 548 public: 549 ChangeZCommand(class SketchWidget *sketchWidget, QUndoCommand *parent); 550 ~ChangeZCommand(); 551 552 void addTriplet(long id, double oldZ, double newZ); 553 void undo(); 554 void redo(); 555 556 protected: 557 QString getParamString() const; 558 559 protected: 560 static double first(RealPair *); 561 static double second(RealPair *); 562 563 protected: 564 QHash<long, RealPair *> m_triplets; 565 }; 566 567 struct StickyThing { 568 SketchWidget * sketchWidget; 569 bool stickem; 570 long fromID; 571 long toID; 572 }; 573 574 ///////////////////////////////////////////// 575 576 class CheckStickyCommand : public BaseCommand 577 { 578 public: 579 enum CheckType { 580 UndoOnly = 0, 581 RedoOnly, 582 RemoveOnly 583 }; 584 585 public: 586 CheckStickyCommand(class SketchWidget *sketchWidget, BaseCommand::CrossViewType, long itemID, bool checkCurrent, CheckType, QUndoCommand *parent); 587 ~CheckStickyCommand(); 588 589 void undo(); 590 void redo(); 591 void stick(SketchWidget *, long fromID, long toID, bool stickem); 592 593 594 protected: 595 QString getParamString() const; 596 597 protected: 598 long m_itemID; 599 QList<StickyThing *> m_stickyList; 600 bool m_checkCurrent; 601 CheckType m_checkType; 602 }; 603 604 ///////////////////////////////////////////// 605 606 class WireColorChangeCommand : public BaseCommand 607 { 608 public: 609 WireColorChangeCommand( 610 SketchWidget* sketchWidget, 611 long wireId, const QString &oldColor, const QString &newColor, 612 double oldOpacity, double newOpacity, 613 QUndoCommand *parent=0); 614 void undo(); 615 void redo(); 616 617 618 protected: 619 QString getParamString() const; 620 621 protected: 622 long m_wireId; 623 QString m_oldColor; 624 QString m_newColor; 625 double m_oldOpacity; 626 double m_newOpacity; 627 }; 628 629 ///////////////////////////////////////////// 630 631 class WireWidthChangeCommand : public BaseCommand 632 { 633 public: 634 WireWidthChangeCommand( 635 SketchWidget* sketchWidget, 636 long wireId, double oldWidth, double newWidth, 637 QUndoCommand *parent); 638 void undo(); 639 void redo(); 640 641 protected: 642 QString getParamString() const; 643 644 protected: 645 long m_wireId; 646 double m_oldWidth; 647 double m_newWidth; 648 }; 649 650 ///////////////////////////////////////////// 651 652 class RoutingStatusCommand : public BaseCommand 653 { 654 public: 655 RoutingStatusCommand(class SketchWidget *, const RoutingStatus & oldRoutingStatus, const RoutingStatus & newRoutingStatus, QUndoCommand * parent); 656 void undo(); 657 void redo(); 658 659 protected: 660 QString getParamString() const; 661 662 protected: 663 RoutingStatus m_oldRoutingStatus; 664 RoutingStatus m_newRoutingStatus; 665 }; 666 667 ///////////////////////////////////////////// 668 669 struct RatsnestConnectThing 670 { 671 long id; 672 QString connectorID; 673 bool connect; 674 }; 675 676 class CleanUpWiresCommand : public BaseCommand 677 { 678 public: 679 enum Direction { 680 UndoOnly = 0, 681 RedoOnly, 682 Noop 683 }; 684 685 public: 686 CleanUpWiresCommand(class SketchWidget * sketchWidget, CleanUpWiresCommand::Direction, QUndoCommand * parent); 687 void undo(); 688 void redo(); 689 void addRoutingStatus(SketchWidget *, const RoutingStatus & oldRoutingStatus, const RoutingStatus & newRoutingStatus); 690 void setDirection(CleanUpWiresCommand::Direction); 691 void addTrace(SketchWidget * sketchWidget, Wire * wire); 692 bool hasTraces(SketchWidget *); 693 void addRatsnestConnect(long id, const QString & connectorID, bool connect); 694 CleanUpWiresCommand::Direction direction(); 695 696 protected: 697 QString getParamString() const; 698 699 protected: 700 QSet<SketchWidget *> m_sketchWidgets; 701 QList<RatsnestConnectThing> m_ratsnestConnectThings; 702 CleanUpWiresCommand::Direction m_direction; 703 }; 704 705 ///////////////////////////////////////////// 706 707 class CleanUpRatsnestsCommand : public BaseCommand 708 { 709 public: 710 CleanUpRatsnestsCommand(class SketchWidget * sketchWidget, CleanUpWiresCommand::Direction, QUndoCommand * parent); 711 void undo(); 712 void redo(); 713 714 protected: 715 QString getParamString() const; 716 717 }; 718 719 ///////////////////////////////////////////// 720 721 class RestoreLabelCommand : public BaseCommand 722 { 723 public: 724 RestoreLabelCommand(class SketchWidget *sketchWidget, long id, QDomElement &, QUndoCommand *parent); 725 void undo(); 726 void redo(); 727 728 protected: 729 QString getParamString() const; 730 731 protected: 732 long m_itemID; 733 QDomElement m_element; 734 }; 735 736 ///////////////////////////////////////////// 737 738 class ShowLabelFirstTimeCommand : public BaseCommand 739 { 740 public: 741 ShowLabelFirstTimeCommand(class SketchWidget *sketchWidget, CrossViewType crossView, long id, bool oldVis, bool newVis, QUndoCommand *parent); 742 void undo(); 743 void redo(); 744 745 protected: 746 QString getParamString() const; 747 748 protected: 749 long m_itemID; 750 bool m_oldVis; 751 bool m_newVis; 752 }; 753 754 ///////////////////////////////////////////// 755 756 class MoveLabelCommand : public BaseCommand 757 { 758 public: 759 MoveLabelCommand(class SketchWidget *sketchWidget, long id, QPointF oldPos, QPointF oldOffset, QPointF newPos, QPointF newOffset, QUndoCommand *parent); 760 void undo(); 761 void redo(); 762 763 protected: 764 QString getParamString() const; 765 766 protected: 767 long m_itemID; 768 QPointF m_oldPos; 769 QPointF m_newPos; 770 QPointF m_oldOffset; 771 QPointF m_newOffset; 772 }; 773 774 ///////////////////////////////////////////// 775 776 class MoveLockCommand : public BaseCommand 777 { 778 public: 779 MoveLockCommand(class SketchWidget *sketchWidget, long id, bool oldLock, bool newLock, QUndoCommand *parent); 780 void undo(); 781 void redo(); 782 783 protected: 784 QString getParamString() const; 785 786 protected: 787 long m_itemID; 788 bool m_oldLock; 789 bool m_newLock; 790 }; 791 792 ///////////////////////////////////////////// 793 794 class IncLabelTextCommand : public BaseCommand 795 { 796 public: 797 IncLabelTextCommand(class SketchWidget *sketchWidget, long id, QUndoCommand *parent); 798 void undo(); 799 void redo(); 800 801 protected: 802 QString getParamString() const; 803 804 protected: 805 long m_itemID; 806 }; 807 808 ///////////////////////////////////////////// 809 810 class ChangeLabelTextCommand : public BaseCommand 811 { 812 public: 813 ChangeLabelTextCommand(class SketchWidget *sketchWidget, long id, const QString & oldText, const QString & newText, QUndoCommand *parent); 814 void undo(); 815 void redo(); 816 817 protected: 818 QString getParamString() const; 819 820 protected: 821 long m_itemID; 822 QString m_oldText; 823 QString m_newText; 824 }; 825 826 ///////////////////////////////////////////// 827 828 class ChangeNoteTextCommand : public BaseCommand 829 { 830 public: 831 ChangeNoteTextCommand(class SketchWidget *sketchWidget, long id, const QString & oldText, const QString & newText, QSizeF oldSize, QSizeF newSize, QUndoCommand *parent); 832 void undo(); 833 void redo(); 834 int id() const; 835 bool mergeWith(const QUndoCommand *other); 836 837 protected: 838 QString getParamString() const; 839 840 protected: 841 long m_itemID; 842 QString m_oldText; 843 QString m_newText; 844 QSizeF m_oldSize; 845 QSizeF m_newSize; 846 847 static int changeNoteTextCommandID; 848 }; 849 850 ///////////////////////////////////////////// 851 852 class RotateFlipLabelCommand : public BaseCommand 853 { 854 public: 855 RotateFlipLabelCommand(class SketchWidget *sketchWidget, long id, double degrees, Qt::Orientations, QUndoCommand *parent); 856 void undo(); 857 void redo(); 858 859 protected: 860 QString getParamString() const; 861 862 protected: 863 long m_itemID; 864 double m_degrees; 865 Qt::Orientations m_orientation; 866 }; 867 868 ///////////////////////////////////////////// 869 870 class ResizeNoteCommand : public BaseCommand 871 { 872 public: 873 ResizeNoteCommand(class SketchWidget *sketchWidget, long id, const QSizeF & oldSize, const QSizeF & newSize, QUndoCommand *parent); 874 void undo(); 875 void redo(); 876 877 protected: 878 QString getParamString() const; 879 880 protected: 881 long m_itemID; 882 QSizeF m_oldSize; 883 QSizeF m_newSize; 884 }; 885 886 ///////////////////////////////////////////// 887 888 class ResizeBoardCommand : public BaseCommand 889 { 890 public: 891 ResizeBoardCommand(class SketchWidget *, long itemID, double oldWidth, double oldHeight, double newWidth, double newHeight, QUndoCommand * parent); 892 void undo(); 893 void redo(); 894 895 protected: 896 QString getParamString() const; 897 898 protected: 899 double m_oldWidth; 900 double m_oldHeight; 901 double m_newWidth; 902 double m_newHeight; 903 long m_itemID; 904 }; 905 906 ///////////////////////////////////////////// 907 908 class SetResistanceCommand : public BaseCommand 909 { 910 public: 911 SetResistanceCommand(class SketchWidget *, long itemID, QString oldResistance, QString newResistance, QString oldPinSpacing, QString newPinSpacing, QUndoCommand * parent); 912 void undo(); 913 void redo(); 914 915 protected: 916 QString getParamString() const; 917 918 protected: 919 QString m_oldResistance; 920 QString m_newResistance; 921 QString m_oldPinSpacing; 922 QString m_newPinSpacing; 923 long m_itemID; 924 }; 925 926 ///////////////////////////////////////////// 927 928 class SetPropCommand : public BaseCommand 929 { 930 public: 931 SetPropCommand(class SketchWidget *, long itemID, QString prop, QString oldValue, QString newValue, bool redraw, QUndoCommand * parent); 932 void undo(); 933 void redo(); 934 935 protected: 936 QString getParamString() const; 937 938 protected: 939 bool m_redraw; 940 QString m_prop; 941 QString m_oldValue; 942 QString m_newValue; 943 long m_itemID; 944 }; 945 946 ///////////////////////////////////////////// 947 948 class ResizeJumperItemCommand : public BaseCommand 949 { 950 public: 951 ResizeJumperItemCommand(class SketchWidget *, long itemID, QPointF oldPos, QPointF oldC0, QPointF oldC1, QPointF newPos, QPointF newC0, QPointF newC1, QUndoCommand * parent); 952 void undo(); 953 void redo(); 954 955 protected: 956 QString getParamString() const; 957 958 protected: 959 QPointF m_oldPos; 960 QPointF m_oldC0; 961 QPointF m_oldC1; 962 QPointF m_newPos; 963 QPointF m_newC0; 964 QPointF m_newC1; 965 long m_itemID; 966 }; 967 968 ///////////////////////////////////////////// 969 970 class ShowLabelCommand : public BaseCommand 971 { 972 public: 973 ShowLabelCommand(class SketchWidget *sketchWidget, QUndoCommand *parent); 974 975 void undo(); 976 void redo(); 977 void add(long id, bool prev, bool post); 978 979 protected: 980 QString getParamString() const; 981 982 protected: 983 QHash<long, int> m_idStates; 984 985 }; 986 987 ///////////////////////////////////////////// 988 989 class LoadLogoImageCommand : public BaseCommand 990 { 991 public: 992 LoadLogoImageCommand(class SketchWidget *sketchWidget, long id, const QString & oldSvg, const QSizeF oldAspectRatio, const QString & oldFilename, const QString & newFilename, bool addName, QUndoCommand *parent); 993 void undo(); 994 void redo(); 995 996 protected: 997 QString getParamString() const; 998 999 protected: 1000 long m_itemID; 1001 QString m_oldSvg; 1002 QSizeF m_oldAspectRatio; 1003 QString m_oldFilename; 1004 QString m_newFilename; 1005 bool m_addName; 1006 }; 1007 1008 ///////////////////////////////////////////// 1009 1010 class ChangeBoardLayersCommand : public BaseCommand 1011 { 1012 public: 1013 ChangeBoardLayersCommand(class SketchWidget *sketchWidget, int oldLayers, int newLayers, QUndoCommand *parent); 1014 void undo(); 1015 void redo(); 1016 1017 protected: 1018 QString getParamString() const; 1019 1020 protected: 1021 int m_oldLayers; 1022 int m_newLayers; 1023 }; 1024 1025 ///////////////////////////////////////////// 1026 1027 class SetDropOffsetCommand : public BaseCommand 1028 { 1029 public: 1030 SetDropOffsetCommand(class SketchWidget *sketchWidget, long id, QPointF dropOffset, QUndoCommand *parent); 1031 void undo(); 1032 void redo(); 1033 1034 protected: 1035 QString getParamString() const; 1036 1037 protected: 1038 long m_itemID; 1039 QPointF m_dropOffset; 1040 }; 1041 1042 ///////////////////////////////////////////// 1043 1044 class RenamePinsCommand : public BaseCommand 1045 { 1046 public: 1047 RenamePinsCommand(class SketchWidget *sketchWidget, long id, const QStringList & oldOnes, const QStringList & newOnes, bool singleRow, QUndoCommand *parent); 1048 void undo(); 1049 void redo(); 1050 1051 protected: 1052 QString getParamString() const; 1053 1054 protected: 1055 long m_itemID; 1056 QStringList m_oldLabels; 1057 QStringList m_newLabels; 1058 bool m_singleRow; 1059 }; 1060 1061 ///////////////////////////////////////////// 1062 1063 struct GFSThing { 1064 long id; 1065 QString connectorID; 1066 bool seed; 1067 }; 1068 1069 class GroundFillSeedCommand : public BaseCommand 1070 { 1071 public: 1072 GroundFillSeedCommand(class SketchWidget *sketchWidget, QUndoCommand *parent); 1073 void undo(); 1074 void redo(); 1075 void addItem(long id, const QString & connectorID, bool seed); 1076 1077 protected: 1078 QString getParamString() const; 1079 1080 protected: 1081 QList<GFSThing> m_items; 1082 }; 1083 1084 ///////////////////////////////////////////// 1085 1086 class WireExtrasCommand : public BaseCommand 1087 { 1088 public: 1089 WireExtrasCommand(class SketchWidget *sketchWidget, long fromID, 1090 const QDomElement & oldExtras, const QDomElement & newExtras, 1091 QUndoCommand *parent); 1092 void undo(); 1093 void redo(); 1094 1095 protected: 1096 QString getParamString() const; 1097 1098 protected: 1099 long m_fromID; 1100 QDomElement m_oldExtras; 1101 QDomElement m_newExtras; 1102 1103 }; 1104 1105 ///////////////////////////////////////////// 1106 1107 class HidePartLayerCommand : public BaseCommand 1108 { 1109 public: 1110 HidePartLayerCommand(class SketchWidget *sketchWidget, long fromID, 1111 ViewLayer::ViewLayerID layerID, bool wasHidden, bool isHidden, 1112 QUndoCommand *parent); 1113 void undo(); 1114 void redo(); 1115 1116 protected: 1117 QString getParamString() const; 1118 1119 protected: 1120 long m_fromID; 1121 double m_wasHidden; 1122 double m_isHidden; 1123 ViewLayer::ViewLayerID m_layerID; 1124 ViewLayer::ViewLayerID m_oldLayer; 1125 }; 1126 1127 ///////////////////////////////////////////// 1128 1129 class TemporaryCommand : public QUndoCommand 1130 { 1131 1132 public: 1133 TemporaryCommand(const QString & text); 1134 ~TemporaryCommand(); 1135 1136 void setEnabled(bool); 1137 1138 void redo(); 1139 1140 protected: 1141 bool m_enabled; 1142 }; 1143 1144 ///////////////////////////////////////////// 1145 1146 class AddSubpartCommand : public BaseCommand 1147 { 1148 public: 1149 AddSubpartCommand(class SketchWidget *sketchWidget, CrossViewType crossView, long id, long subpartID, QUndoCommand *parent); 1150 void undo(); 1151 void redo(); 1152 1153 protected: 1154 QString getParamString() const; 1155 1156 protected: 1157 long m_itemID; 1158 long m_subpartItemID; 1159 }; 1160 1161 ///////////////////////////////////////////// 1162 1163 class PackItemsCommand : public BaseCommand 1164 { 1165 public: 1166 PackItemsCommand(class SketchWidget *sketchWidget, int columns, const QList<long> & ids, QUndoCommand *parent); 1167 void undo(); 1168 void redo(); 1169 1170 protected: 1171 QString getParamString() const; 1172 1173 protected: 1174 int m_columns; 1175 QList<long> m_ids; 1176 bool m_firstTime; 1177 }; 1178 1179 ///////////////////////////////////////////// 1180 1181 #endif // COMMANDS_H 1182