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.

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