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.

213 lines
7.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018-2020 CERN
  5. * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Jon Evans <jon@craftyjon.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef _ERC_SETTINGS_H
  22. #define _ERC_SETTINGS_H
  23. #include <erc_item.h>
  24. #include <pin_type.h>
  25. #include <settings/nested_settings.h>
  26. #include <widgets/ui_common.h>
  27. class SCH_MARKER;
  28. class SCHEMATIC;
  29. /// ERC error codes
  30. enum ERCE_T
  31. {
  32. ERCE_UNSPECIFIED = 0,
  33. ERCE_FIRST,
  34. ERCE_DUPLICATE_SHEET_NAME = ERCE_FIRST, ///< Duplicate sheet names within a given sheet.
  35. ERCE_PIN_NOT_CONNECTED, ///< Pin not connected and not no connect symbol.
  36. ERCE_PIN_NOT_DRIVEN, ///< Pin connected to some others pins but no pin to drive it.
  37. ///< pins to drive it can be output, passive, 3sttae, I/O
  38. ERCE_POWERPIN_NOT_DRIVEN, ///< Power input pin connected to some others pins but no
  39. ///< power out pin to drive it.
  40. ERCE_HIERACHICAL_LABEL, ///< Mismatch between hierarchical labels and pins sheets.
  41. ERCE_NOCONNECT_CONNECTED, ///< A no connect symbol is connected to more than 1 pin.
  42. ERCE_NOCONNECT_NOT_CONNECTED, ///< A no connect symbol is not connected to anything.
  43. ERCE_LABEL_NOT_CONNECTED, ///< Label not connected to anything.
  44. ERCE_SIMILAR_LABELS, ///< 2 labels are equal for case insensitive comparisons.
  45. ERCE_DIFFERENT_UNIT_FP, ///< Different units of the same component have different
  46. ///< footprints assigned.
  47. ERCE_DIFFERENT_UNIT_NET, ///< Shared pin in a multi-unit component is connected to
  48. ///< more than one net.
  49. ERCE_BUS_ALIAS_CONFLICT, ///< Conflicting bus alias definitions across sheets.
  50. ERCE_DRIVER_CONFLICT, ///< Conflicting drivers (labels, etc) on a subgraph.
  51. ERCE_BUS_ENTRY_CONFLICT, ///< A wire connected to a bus doesn't match the bus.
  52. ERCE_BUS_LABEL_ERROR, ///< A label attached to a bus isn't in bus format.
  53. ERCE_BUS_TO_BUS_CONFLICT, ///< A connection between bus objects doesn't share at least
  54. ///< one net.
  55. ERCE_BUS_TO_NET_CONFLICT, ///< A bus wire is graphically connected to a net port/pin
  56. ///< (or vice versa).
  57. ERCE_GLOBLABEL, ///< A global label is unique.
  58. ERCE_UNRESOLVED_VARIABLE, ///< A text variable could not be resolved.
  59. ERCE_WIRE_DANGLING, ///< Some wires are not connected to anything else.
  60. ERCE_LIB_SYMBOL_ISSUES, ///< Library symbol changed from current symbol in schematic or
  61. ///< the library symbol link no longer valid.
  62. ERCE_UNANNOTATED, ///< Symbol has not been annotated.
  63. ERCE_EXTRA_UNITS, ///< Symbol has more units than are defined.
  64. ERCE_DIFFERENT_UNIT_VALUE, ///< Units of same symbol have different values.
  65. ERCE_DUPLICATE_REFERENCE, ///< More than one symbol with the same reference.
  66. ERCE_LAST = ERCE_DUPLICATE_REFERENCE,
  67. // Errors after this point will not automatically appear in the Severities Panel
  68. ERCE_PIN_TO_PIN_WARNING, // pin connected to an other pin: warning level
  69. ERCE_PIN_TO_PIN_ERROR, // pin connected to an other pin: error level
  70. ERCE_ANNOTATION_ACTION // Not actually an error; just an action performed during
  71. // annotation which is passed back through the error handler.
  72. };
  73. /// The values a pin-to-pin entry in the pin matrix can take on
  74. enum class PIN_ERROR
  75. {
  76. OK,
  77. WARNING,
  78. PP_ERROR,
  79. UNCONNECTED
  80. };
  81. /// Types of drive on a net (used for legacy ERC)
  82. #define NPI 4 // Net with Pin isolated, this pin has type Not Connected and must be left N.C.
  83. #define DRV 3 // Net driven by a signal (a pin output for instance)
  84. #define NET_NC 2 // Net "connected" to a "NoConnect symbol"
  85. #define NOD 1 // Net not driven ( Such as 2 or more connected inputs )
  86. #define NOC 0 // initial state of a net: no connection
  87. /**
  88. * Container for ERC settings
  89. *
  90. * Currently only stores flags about checks to run, but could later be expanded
  91. * to contain the matrix of electrical pin types.
  92. */
  93. class ERC_SETTINGS : public NESTED_SETTINGS
  94. {
  95. public:
  96. ERC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath );
  97. virtual ~ERC_SETTINGS();
  98. bool operator==( const ERC_SETTINGS& other ) const
  99. {
  100. return ( other.m_Severities == m_Severities );
  101. }
  102. bool operator!=( const ERC_SETTINGS& other ) const
  103. {
  104. return !( other == *this );
  105. }
  106. bool IsTestEnabled( int aErrorCode ) const
  107. {
  108. return GetSeverity( aErrorCode ) != RPT_SEVERITY_IGNORE;
  109. }
  110. SEVERITY GetSeverity( int aErrorCode ) const;
  111. void SetSeverity( int aErrorCode, SEVERITY aSeverity );
  112. void ResetPinMap();
  113. PIN_ERROR GetPinMapValue( int aFirstType, int aSecondType ) const
  114. {
  115. wxASSERT( aFirstType < ELECTRICAL_PINTYPES_TOTAL
  116. && aSecondType < ELECTRICAL_PINTYPES_TOTAL );
  117. return m_PinMap[aFirstType][aSecondType];
  118. }
  119. PIN_ERROR GetPinMapValue( ELECTRICAL_PINTYPE aFirstType, ELECTRICAL_PINTYPE aSecondType ) const
  120. {
  121. return m_PinMap[static_cast<int>( aFirstType )][static_cast<int>( aSecondType )];
  122. }
  123. void SetPinMapValue( int aFirstType, int aSecondType, PIN_ERROR aValue )
  124. {
  125. wxASSERT( aFirstType < ELECTRICAL_PINTYPES_TOTAL
  126. && aSecondType < ELECTRICAL_PINTYPES_TOTAL );
  127. m_PinMap[aFirstType][aSecondType] = aValue;
  128. }
  129. void SetPinMapValue( ELECTRICAL_PINTYPE aFirstType, ELECTRICAL_PINTYPE aSecondType,
  130. PIN_ERROR aValue )
  131. {
  132. m_PinMap[static_cast<int>( aFirstType )][static_cast<int>( aSecondType )] = aValue;
  133. }
  134. int GetPinMinDrive( ELECTRICAL_PINTYPE aFirstType, ELECTRICAL_PINTYPE aSecondType ) const
  135. {
  136. return m_PinMinDrive[static_cast<int>( aFirstType )][static_cast<int>( aSecondType )];
  137. }
  138. public:
  139. std::map<int, SEVERITY> m_Severities;
  140. std::set<wxString> m_ErcExclusions;
  141. PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL];
  142. static int m_PinMinDrive[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL];
  143. private:
  144. static PIN_ERROR m_defaultPinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL];
  145. };
  146. /**
  147. * An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST
  148. * to fulfill the contract.
  149. */
  150. class SHEETLIST_ERC_ITEMS_PROVIDER : public RC_ITEMS_PROVIDER
  151. {
  152. private:
  153. SCHEMATIC* m_schematic;
  154. int m_severities;
  155. std::vector<SCH_MARKER*> m_filteredMarkers;
  156. public:
  157. SHEETLIST_ERC_ITEMS_PROVIDER( SCHEMATIC* aSchematic ) :
  158. m_schematic( aSchematic ),
  159. m_severities( 0 )
  160. { }
  161. void SetSeverities( int aSeverities ) override;
  162. int GetCount( int aSeverity = -1 ) override;
  163. std::shared_ptr<RC_ITEM> GetItem( int aIndex ) override;
  164. std::shared_ptr<ERC_ITEM> GetERCItem( int aIndex );
  165. void DeleteItem( int aIndex, bool aDeep ) override;
  166. void DeleteAllItems( bool aIncludeExclusions, bool aDeep ) override;
  167. private:
  168. void visitMarkers( std::function<void( SCH_MARKER* )> aVisitor );
  169. };
  170. #endif