You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 Ethan Chien <liangtie.qian@gmail.com>
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef DIALOG_SYNC_SHEET_PINS_H
  25. #define DIALOG_SYNC_SHEET_PINS_H
  26. #include "dialog_sync_sheet_pins_base.h"
  27. #include <sch_sheet_path.h>
  28. #include <list>
  29. #include <memory>
  30. #include <unordered_map>
  31. class SCH_SHEET;
  32. class EDA_ITEM;
  33. class SHEET_SYNCHRONIZATION_AGENT;
  34. class PANEL_SYNC_SHEET_PINS;
  35. class SCH_HIERLABEL;
  36. class DIALOG_SYNC_SHEET_PINS : public DIALOG_SYNC_SHEET_PINS_BASE
  37. {
  38. public:
  39. enum class PlaceItemKind
  40. {
  41. UNDEFINED,
  42. SHEET_PIN,
  43. HIERLABEL
  44. };
  45. DIALOG_SYNC_SHEET_PINS( wxWindow* aParent, std::list<SCH_SHEET_PATH> aSheetPath,
  46. std::shared_ptr<SHEET_SYNCHRONIZATION_AGENT> aAgent );
  47. ~DIALOG_SYNC_SHEET_PINS() override;
  48. void OnClose( wxCloseEvent& aEvent );
  49. /**
  50. * Either the selected #HIERLABEL or #SHEET_PIN will be used as templates for placing the new ones.
  51. *
  52. * @param aSheet The sheet where the new #HIERLABEL or #SHEET_PIN will be placed. For #SHEET_PIN,
  53. * it's the corresponding sheet symbol.
  54. * @param aKind Either PlaceItemKind::HIERLABEL or PlaceItemKind::SHEET_PIN
  55. * @param aPlacementTemplateSet All the selected HIERLABELs or SHEET_PINs
  56. */
  57. void PreparePlacementTemplate( SCH_SHEET* aSheet, PlaceItemKind aKind,
  58. std::set<EDA_ITEM*> const& aPlacementTemplateSet );
  59. /**
  60. * Get the Placement Template SHEET_PIN / HIERLABEL used for place a new #HIERLABEL/#SHEET_PIN.
  61. *
  62. * @return SCH_HIERLABEL*
  63. */
  64. SCH_HIERLABEL* GetPlacementTemplate() const;
  65. /**
  66. * End place a new #HIERLABEL/#SHEET_PIN , and add the new item to the corresponding table.
  67. *
  68. * @param aNewItem The new #HIERLABEL/#SHEET_PIN to be placed.
  69. */
  70. void EndPlaceItem( EDA_ITEM* aNewItem );
  71. /**
  72. * Check if there are more items to be placed.
  73. */
  74. bool CanPlaceMore() const;
  75. void EndPlacement();
  76. private:
  77. /// It's the agent that performs modification and placement.
  78. std::shared_ptr<SHEET_SYNCHRONIZATION_AGENT> m_agent;
  79. SCH_SHEET* m_lastEditSheet;
  80. /// The same sheet may have multiple instances.
  81. std::unordered_map<SCH_SHEET*, PANEL_SYNC_SHEET_PINS*> m_panels;
  82. PlaceItemKind m_placeItemKind;
  83. EDA_ITEM* m_currentTemplate;
  84. std::set<EDA_ITEM*> m_placementTemplateSet;
  85. };
  86. #endif