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.

214 lines
8.0 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 symbol have different
  46. ///< footprints assigned.
  47. ERCE_DIFFERENT_UNIT_NET, ///< Shared pin in a multi-unit symbol 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_BUS_ENTRY_NEEDED, ///< Importer failed to auto-place a bus entry.
  67. ERCE_LAST = ERCE_BUS_ENTRY_NEEDED,
  68. // Errors after this point will not automatically appear in the Severities Panel
  69. ERCE_PIN_TO_PIN_WARNING, // pin connected to an other pin: warning level
  70. ERCE_PIN_TO_PIN_ERROR, // pin connected to an other pin: error level
  71. ERCE_ANNOTATION_ACTION // Not actually an error; just an action performed during
  72. // annotation which is passed back through the error handler.
  73. };
  74. /// The values a pin-to-pin entry in the pin matrix can take on
  75. enum class PIN_ERROR
  76. {
  77. OK,
  78. WARNING,
  79. PP_ERROR,
  80. UNCONNECTED
  81. };
  82. /// Types of drive on a net (used for legacy ERC)
  83. #define NPI 4 // Net with Pin isolated, this pin has type Not Connected and must be left N.C.
  84. #define DRV 3 // Net driven by a signal (a pin output for instance)
  85. #define NET_NC 2 // Net "connected" to a "NoConnect symbol"
  86. #define NOD 1 // Net not driven ( Such as 2 or more connected inputs )
  87. #define NOC 0 // initial state of a net: no connection
  88. /**
  89. * Container for ERC settings
  90. *
  91. * Currently only stores flags about checks to run, but could later be expanded
  92. * to contain the matrix of electrical pin types.
  93. */
  94. class ERC_SETTINGS : public NESTED_SETTINGS
  95. {
  96. public:
  97. ERC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath );
  98. virtual ~ERC_SETTINGS();
  99. bool operator==( const ERC_SETTINGS& other ) const
  100. {
  101. return ( other.m_Severities == m_Severities );
  102. }
  103. bool operator!=( const ERC_SETTINGS& other ) const
  104. {
  105. return !( other == *this );
  106. }
  107. bool IsTestEnabled( int aErrorCode ) const
  108. {
  109. return GetSeverity( aErrorCode ) != RPT_SEVERITY_IGNORE;
  110. }
  111. SEVERITY GetSeverity( int aErrorCode ) const;
  112. void SetSeverity( int aErrorCode, SEVERITY aSeverity );
  113. void ResetPinMap();
  114. PIN_ERROR GetPinMapValue( int aFirstType, int aSecondType ) const
  115. {
  116. wxASSERT( aFirstType < ELECTRICAL_PINTYPES_TOTAL
  117. && aSecondType < ELECTRICAL_PINTYPES_TOTAL );
  118. return m_PinMap[aFirstType][aSecondType];
  119. }
  120. PIN_ERROR GetPinMapValue( ELECTRICAL_PINTYPE aFirstType, ELECTRICAL_PINTYPE aSecondType ) const
  121. {
  122. return m_PinMap[static_cast<int>( aFirstType )][static_cast<int>( aSecondType )];
  123. }
  124. void SetPinMapValue( int aFirstType, int aSecondType, PIN_ERROR aValue )
  125. {
  126. wxASSERT( aFirstType < ELECTRICAL_PINTYPES_TOTAL
  127. && aSecondType < ELECTRICAL_PINTYPES_TOTAL );
  128. m_PinMap[aFirstType][aSecondType] = aValue;
  129. }
  130. void SetPinMapValue( ELECTRICAL_PINTYPE aFirstType, ELECTRICAL_PINTYPE aSecondType,
  131. PIN_ERROR aValue )
  132. {
  133. m_PinMap[static_cast<int>( aFirstType )][static_cast<int>( aSecondType )] = aValue;
  134. }
  135. int GetPinMinDrive( ELECTRICAL_PINTYPE aFirstType, ELECTRICAL_PINTYPE aSecondType ) const
  136. {
  137. return m_PinMinDrive[static_cast<int>( aFirstType )][static_cast<int>( aSecondType )];
  138. }
  139. public:
  140. std::map<int, SEVERITY> m_Severities;
  141. std::set<wxString> m_ErcExclusions;
  142. PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL];
  143. static int m_PinMinDrive[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL];
  144. private:
  145. static PIN_ERROR m_defaultPinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL];
  146. };
  147. /**
  148. * An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST
  149. * to fulfill the contract.
  150. */
  151. class SHEETLIST_ERC_ITEMS_PROVIDER : public RC_ITEMS_PROVIDER
  152. {
  153. private:
  154. SCHEMATIC* m_schematic;
  155. int m_severities;
  156. std::vector<SCH_MARKER*> m_filteredMarkers;
  157. public:
  158. SHEETLIST_ERC_ITEMS_PROVIDER( SCHEMATIC* aSchematic ) :
  159. m_schematic( aSchematic ),
  160. m_severities( 0 )
  161. { }
  162. void SetSeverities( int aSeverities ) override;
  163. int GetCount( int aSeverity = -1 ) const override;
  164. std::shared_ptr<RC_ITEM> GetItem( int aIndex ) const override;
  165. std::shared_ptr<ERC_ITEM> GetERCItem( int aIndex ) const;
  166. void DeleteItem( int aIndex, bool aDeep ) override;
  167. void DeleteAllItems( bool aIncludeExclusions, bool aDeep ) override;
  168. private:
  169. void visitMarkers( std::function<void( SCH_MARKER* )> aVisitor ) const;
  170. };
  171. #endif // _ERC_SETTINGS_H