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.

155 lines
5.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program 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 this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef SCH_RULE_AREA_H
  24. #define SCH_RULE_AREA_H
  25. #include <unordered_set>
  26. #include <utility>
  27. #include <plotters/plotter.h>
  28. #include <sch_plotter.h>
  29. #include <sch_screen.h>
  30. #include <sch_shape.h>
  31. #include <sch_label.h>
  32. #include <sch_sheet_path.h>
  33. #include <sch_view.h>
  34. class SCHEMATIC;
  35. class SCH_RULE_AREA : public SCH_SHAPE
  36. {
  37. public:
  38. SCH_RULE_AREA() :
  39. SCH_SHAPE( SHAPE_T::POLY, LAYER_RULE_AREAS, 0 /* line width */, FILL_T::NO_FILL, SCH_RULE_AREA_T ),
  40. m_excludedFromSim( false ),
  41. m_excludedFromBOM( false ),
  42. m_excludedFromBoard( false ),
  43. m_DNP( false )
  44. {
  45. SetLayer( LAYER_RULE_AREAS );
  46. }
  47. virtual ~SCH_RULE_AREA() {}
  48. wxString GetClass() const override;
  49. wxString GetFriendlyName() const override;
  50. EDA_ITEM* Clone() const override;
  51. /**
  52. * Set or clear the exclude from simulation flag.
  53. */
  54. void SetExcludedFromSim( bool aExcludeFromSim ) override { m_excludedFromSim = aExcludeFromSim; }
  55. bool GetExcludedFromSim() const override { return m_excludedFromSim; }
  56. /**
  57. * Set or clear the exclude from schematic bill of materials flag.
  58. */
  59. void SetExcludedFromBOM( bool aExcludeFromBOM ) override { m_excludedFromBOM = aExcludeFromBOM; }
  60. bool GetExcludedFromBOM() const override { return m_excludedFromBOM; }
  61. /**
  62. * Set or clear exclude from board netlist flag.
  63. */
  64. void SetExcludedFromBoard( bool aExcludeFromBoard ) override { m_excludedFromBoard = aExcludeFromBoard; }
  65. bool GetExcludedFromBoard() const override { return m_excludedFromBoard; }
  66. /**
  67. * Set or clear the 'Do Not Populate' flag.
  68. */
  69. bool GetDNP() const override { return m_DNP; }
  70. void SetDNP( bool aDNP ) override { m_DNP = aDNP; }
  71. std::vector<int> ViewGetLayers() const override;
  72. bool IsFilledForHitTesting() const override
  73. {
  74. return false;
  75. }
  76. virtual std::vector<SHAPE*> MakeEffectiveShapes( bool aEdgeOnly = false ) const override;
  77. virtual void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
  78. int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
  79. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  80. /// Refresh the list of items which this rule area affects.
  81. void RefreshContainedItemsAndDirectives( SCH_SCREEN* screen );
  82. /// Update all rule area connectvity / caches in the given sheet paths.
  83. ///
  84. /// @return A map of all updated rule areas and their owning screen.
  85. static std::vector<std::pair<SCH_RULE_AREA*, SCH_SCREEN*>>
  86. UpdateRuleAreasInScreens( std::unordered_set<SCH_SCREEN*>& screens, KIGFX::SCH_VIEW* view );
  87. /// Return a set of all items contained within the rule area.
  88. const std::unordered_set<SCH_ITEM*>& GetContainedItems() const;
  89. const std::unordered_set<KIID>& GetPastContainedItems() const;
  90. /// Return the set of all directive labels attached to the rule area border.
  91. const std::unordered_set<SCH_DIRECTIVE_LABEL*>& GetDirectives() const;
  92. /// Resolve the netclass of this rule area from connected directive labels.
  93. ///
  94. /// @return The resolved netclass (if any), and the SCH_ITEM providing the declaration.
  95. const std::vector<std::pair<wxString, SCH_ITEM*>> GetResolvedNetclasses() const;
  96. /// Get the message panel info for the rule area.
  97. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  98. protected:
  99. /// Add a directive label which applies to items within ths rule area.
  100. void addDirective( SCH_DIRECTIVE_LABEL* label );
  101. /// Add an item to the list of items which this rule area affects.
  102. void addContainedItem( SCH_ITEM* item );
  103. /// Reset all item and directive caches, saving the current state first.
  104. void resetCaches();
  105. protected:
  106. bool m_excludedFromSim;
  107. bool m_excludedFromBOM;
  108. bool m_excludedFromBoard;
  109. bool m_DNP; ///< True if symbol is set to 'Do Not Populate'.
  110. /// All #SCH_ITEM objects currently contained or intersecting the rule area. No ownership.
  111. std::unordered_set<SCH_ITEM*> m_items;
  112. std::unordered_set<KIID> m_itemIDs;
  113. /// All #SCH_DIRECTIVE_LABEL objects attached to the rule area border. No ownership.
  114. std::unordered_set<SCH_DIRECTIVE_LABEL*> m_directives;
  115. std::unordered_set<KIID> m_directiveIDs;
  116. /// All #SCH_ITEM objectss contained or intersecting the rule area in the previous update.
  117. std::unordered_set<KIID> m_prev_items;
  118. /// All SCH_DIRECTIVE_LABEL objects attached to the rule area border in the previous update.
  119. std::unordered_set<KIID> m_prev_directives;
  120. };
  121. #endif