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.

396 lines
16 KiB

3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 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. #include "wx/html/m_templ.h"
  24. #include "wx/html/styleparams.h"
  25. #include <erc.h>
  26. #include <eda_draw_frame.h>
  27. #include <marker_base.h>
  28. #include <sch_edit_frame.h>
  29. // These, being statically-defined, require specialized I18N handling. We continue to
  30. // use the _() macro so that string harvesting by the I18N framework doesn't have to be
  31. // specialized, but we don't translate on initialization and instead do it in the getters.
  32. #undef _
  33. #define _(s) s
  34. // NOTE: Avoid changing the settings key for an ERC item after it has been created
  35. ERC_ITEM ERC_ITEM::heading_connections( 0, _( "Connections" ), "" );
  36. ERC_ITEM ERC_ITEM::heading_conflicts( 0, _( "Conflicts" ), "" );
  37. ERC_ITEM ERC_ITEM::heading_misc( 0, _( "Miscellaneous" ), "" );
  38. ERC_ITEM ERC_ITEM::duplicateSheetName( ERCE_DUPLICATE_SHEET_NAME,
  39. _( "Duplicate sheet names within a given sheet" ),
  40. wxT( "duplicate_sheet_names" ) );
  41. ERC_ITEM ERC_ITEM::endpointOffGrid( ERCE_ENDPOINT_OFF_GRID,
  42. _( "Symbol pin or wire end off connection grid" ),
  43. wxT( "endpoint_off_grid" ) );
  44. ERC_ITEM ERC_ITEM::pinNotConnected( ERCE_PIN_NOT_CONNECTED,
  45. _( "Pin not connected" ),
  46. wxT( "pin_not_connected" ) );
  47. ERC_ITEM ERC_ITEM::pinNotDriven( ERCE_PIN_NOT_DRIVEN,
  48. _( "Input pin not driven by any Output pins" ),
  49. wxT( "pin_not_driven" ) );
  50. ERC_ITEM ERC_ITEM::powerpinNotDriven( ERCE_POWERPIN_NOT_DRIVEN,
  51. _( "Input Power pin not driven by any Output Power pins" ),
  52. wxT( "power_pin_not_driven" ) );
  53. ERC_ITEM ERC_ITEM::pinTableWarning( ERCE_PIN_TO_PIN_WARNING,
  54. _( "Conflict problem between pins" ),
  55. wxT( "pin_to_pin" ) );
  56. ERC_ITEM ERC_ITEM::pinTableError( ERCE_PIN_TO_PIN_ERROR,
  57. _( "Conflict problem between pins" ),
  58. wxT( "pin_to_pin" ) );
  59. ERC_ITEM ERC_ITEM::hierLabelMismatch( ERCE_HIERACHICAL_LABEL,
  60. _( "Mismatch between hierarchical labels and sheet pins" ),
  61. wxT( "hier_label_mismatch" ) );
  62. ERC_ITEM ERC_ITEM::noConnectConnected( ERCE_NOCONNECT_CONNECTED,
  63. _( "A pin with a \"no connection\" flag is connected" ),
  64. wxT( "no_connect_connected" ) );
  65. ERC_ITEM ERC_ITEM::noConnectDangling( ERCE_NOCONNECT_NOT_CONNECTED,
  66. _( "Unconnected \"no connection\" flag" ),
  67. wxT( "no_connect_dangling" ) );
  68. ERC_ITEM ERC_ITEM::labelDangling( ERCE_LABEL_NOT_CONNECTED,
  69. _( "Label not connected to anything" ),
  70. wxT( "label_dangling" ) );
  71. ERC_ITEM ERC_ITEM::globalLabelDangling( ERCE_GLOBLABEL,
  72. _( "Global label not connected anywhere else in the schematic" ),
  73. wxT( "global_label_dangling" ) );
  74. ERC_ITEM ERC_ITEM::similarLabels( ERCE_SIMILAR_LABELS,
  75. _( "Labels are similar (lower/upper case difference only)"),
  76. wxT( "similar_labels" ) );
  77. ERC_ITEM ERC_ITEM::differentUnitFootprint( ERCE_DIFFERENT_UNIT_FP,
  78. _( "Different footprint assigned in another unit of the symbol" ),
  79. wxT( "different_unit_footprint" ) );
  80. ERC_ITEM ERC_ITEM::differentUnitNet( ERCE_DIFFERENT_UNIT_NET,
  81. _( "Different net assigned to a shared pin in another unit of the symbol" ),
  82. wxT( "different_unit_net" ) );
  83. ERC_ITEM ERC_ITEM::busDefinitionConflict( ERCE_BUS_ALIAS_CONFLICT,
  84. _( "Conflict between bus alias definitions across schematic sheets" ),
  85. wxT( "bus_definition_conflict" ) );
  86. ERC_ITEM ERC_ITEM::multipleNetNames( ERCE_DRIVER_CONFLICT,
  87. _( "More than one name given to this bus or net" ),
  88. wxT( "multiple_net_names" ) );
  89. ERC_ITEM ERC_ITEM::netclassConflict( ERCE_NETCLASS_CONFLICT,
  90. _( "Conflicting netclass assignments" ),
  91. wxT( "conflicting_netclasses" ) );
  92. ERC_ITEM ERC_ITEM::netNotBusMember( ERCE_BUS_ENTRY_CONFLICT,
  93. _( "Net is graphically connected to a bus but not a bus member" ),
  94. wxT( "net_not_bus_member" ) );
  95. ERC_ITEM ERC_ITEM::busToBusConflict( ERCE_BUS_TO_BUS_CONFLICT,
  96. _( "Buses are graphically connected but share no bus members" ),
  97. wxT( "bus_to_bus_conflict" ) );
  98. ERC_ITEM ERC_ITEM::busToNetConflict( ERCE_BUS_TO_NET_CONFLICT,
  99. _( "Invalid connection between bus and net items" ),
  100. wxT( "bus_to_net_conflict" ) );
  101. ERC_ITEM ERC_ITEM::unresolvedVariable( ERCE_UNRESOLVED_VARIABLE,
  102. _( "Unresolved text variable" ),
  103. wxT( "unresolved_variable" ) );
  104. ERC_ITEM ERC_ITEM::undefinedNetclass( ERCE_UNDEFINED_NETCLASS,
  105. _( "Undefined netclass" ),
  106. wxT( "undefined_netclass" ) );
  107. ERC_ITEM ERC_ITEM::simulationModelIssues( ERCE_SIMULATION_MODEL,
  108. _( "SPICE model issue" ),
  109. wxT( "simulation_model_issue" ) );
  110. ERC_ITEM ERC_ITEM::wireDangling( ERCE_WIRE_DANGLING,
  111. _( "Wires not connected to anything" ),
  112. wxT( "wire_dangling" ) );
  113. ERC_ITEM ERC_ITEM::libSymbolIssues( ERCE_LIB_SYMBOL_ISSUES,
  114. _( "Library symbol issue" ),
  115. wxT( "lib_symbol_issues" ) );
  116. ERC_ITEM ERC_ITEM::libSymbolMismatch( ERCE_LIB_SYMBOL_MISMATCH,
  117. _( "Symbol doesn't match copy in library" ),
  118. wxT( "lib_symbol_mismatch" ) );
  119. ERC_ITEM ERC_ITEM::footprintLinkIssues( ERCE_FOOTPRINT_LINK_ISSUES,
  120. _( "Footprint link issue" ),
  121. wxT( "footprint_link_issues" ) );
  122. ERC_ITEM ERC_ITEM::unannotated( ERCE_UNANNOTATED,
  123. _( "Symbol is not annotated" ),
  124. wxT( "unannotated" ) );
  125. ERC_ITEM ERC_ITEM::extraUnits( ERCE_EXTRA_UNITS,
  126. _( "Symbol has more units than are defined" ),
  127. wxT( "extra_units" ) );
  128. ERC_ITEM ERC_ITEM::missingUnits( ERCE_MISSING_UNIT,
  129. _( "Symbol has units that are not placed" ),
  130. wxT( "missing_unit" ) );
  131. ERC_ITEM ERC_ITEM::missingInputPin( ERCE_MISSING_INPUT_PIN,
  132. _( "Symbol has input pins that are not placed" ),
  133. wxT( "missing_input_pin" ) );
  134. ERC_ITEM ERC_ITEM::missingBidiPin( ERCE_MISSING_BIDI_PIN,
  135. _( "Symbol has bidirectional pins that are not placed" ),
  136. wxT( "missing_bidi_pin" ) );
  137. ERC_ITEM ERC_ITEM::missingPowerInputPin( ERCE_MISSING_POWER_INPUT_PIN,
  138. _( "Symbol has power input pins that are not placed" ),
  139. wxT( "missing_power_pin" ) );
  140. ERC_ITEM ERC_ITEM::differentUnitValue( ERCE_DIFFERENT_UNIT_VALUE,
  141. _( "Units of same symbol have different values" ),
  142. wxT( "unit_value_mismatch" ) );
  143. ERC_ITEM ERC_ITEM::duplicateReference( ERCE_DUPLICATE_REFERENCE,
  144. _( "Duplicate reference designators" ),
  145. wxT( "duplicate_reference" ) );
  146. ERC_ITEM ERC_ITEM::busEntryNeeded( ERCE_BUS_ENTRY_NEEDED,
  147. _( "Bus Entry needed" ),
  148. wxT( "bus_entry_needed" ) );
  149. std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes( {
  150. ERC_ITEM::heading_connections,
  151. ERC_ITEM::pinNotConnected,
  152. ERC_ITEM::pinNotDriven,
  153. ERC_ITEM::powerpinNotDriven,
  154. ERC_ITEM::noConnectConnected,
  155. ERC_ITEM::noConnectDangling,
  156. ERC_ITEM::labelDangling,
  157. ERC_ITEM::globalLabelDangling,
  158. ERC_ITEM::wireDangling,
  159. ERC_ITEM::busEntryNeeded,
  160. ERC_ITEM::endpointOffGrid,
  161. ERC_ITEM::heading_conflicts,
  162. ERC_ITEM::duplicateReference,
  163. ERC_ITEM::pinTableWarning,
  164. ERC_ITEM::differentUnitValue,
  165. ERC_ITEM::differentUnitFootprint,
  166. ERC_ITEM::differentUnitNet,
  167. ERC_ITEM::duplicateSheetName,
  168. ERC_ITEM::hierLabelMismatch,
  169. ERC_ITEM::multipleNetNames,
  170. ERC_ITEM::busDefinitionConflict,
  171. ERC_ITEM::busToBusConflict,
  172. ERC_ITEM::busToNetConflict,
  173. ERC_ITEM::netNotBusMember,
  174. ERC_ITEM::netclassConflict,
  175. ERC_ITEM::heading_misc,
  176. ERC_ITEM::unannotated,
  177. ERC_ITEM::unresolvedVariable,
  178. ERC_ITEM::simulationModelIssues,
  179. ERC_ITEM::similarLabels,
  180. // Commented out until the logic for this element is coded
  181. // TODO: Add bus label syntax checking
  182. // ERC_ITEM::busLabelSyntax,
  183. ERC_ITEM::libSymbolIssues,
  184. ERC_ITEM::libSymbolMismatch,
  185. ERC_ITEM::footprintLinkIssues,
  186. ERC_ITEM::extraUnits,
  187. ERC_ITEM::missingUnits,
  188. ERC_ITEM::missingInputPin,
  189. ERC_ITEM::missingBidiPin,
  190. ERC_ITEM::missingPowerInputPin
  191. } );
  192. std::shared_ptr<ERC_ITEM> ERC_ITEM::Create( int aErrorCode )
  193. {
  194. switch( aErrorCode )
  195. {
  196. case ERCE_DUPLICATE_SHEET_NAME: return std::make_shared<ERC_ITEM>( duplicateSheetName );
  197. case ERCE_ENDPOINT_OFF_GRID: return std::make_shared<ERC_ITEM>( endpointOffGrid );
  198. case ERCE_PIN_NOT_CONNECTED: return std::make_shared<ERC_ITEM>( pinNotConnected );
  199. case ERCE_PIN_NOT_DRIVEN: return std::make_shared<ERC_ITEM>( pinNotDriven );
  200. case ERCE_POWERPIN_NOT_DRIVEN: return std::make_shared<ERC_ITEM>( powerpinNotDriven );
  201. case ERCE_PIN_TO_PIN_WARNING: return std::make_shared<ERC_ITEM>( pinTableWarning );
  202. case ERCE_PIN_TO_PIN_ERROR: return std::make_shared<ERC_ITEM>( pinTableError );
  203. case ERCE_HIERACHICAL_LABEL: return std::make_shared<ERC_ITEM>( hierLabelMismatch );
  204. case ERCE_NOCONNECT_CONNECTED: return std::make_shared<ERC_ITEM>( noConnectConnected );
  205. case ERCE_NOCONNECT_NOT_CONNECTED: return std::make_shared<ERC_ITEM>( noConnectDangling );
  206. case ERCE_LABEL_NOT_CONNECTED: return std::make_shared<ERC_ITEM>( labelDangling );
  207. case ERCE_SIMILAR_LABELS: return std::make_shared<ERC_ITEM>( similarLabels );
  208. case ERCE_DIFFERENT_UNIT_FP: return std::make_shared<ERC_ITEM>( differentUnitFootprint );
  209. case ERCE_DIFFERENT_UNIT_NET: return std::make_shared<ERC_ITEM>( differentUnitNet );
  210. case ERCE_BUS_ALIAS_CONFLICT: return std::make_shared<ERC_ITEM>( busDefinitionConflict );
  211. case ERCE_DRIVER_CONFLICT: return std::make_shared<ERC_ITEM>( multipleNetNames );
  212. case ERCE_BUS_ENTRY_CONFLICT: return std::make_shared<ERC_ITEM>( netNotBusMember );
  213. case ERCE_BUS_TO_BUS_CONFLICT: return std::make_shared<ERC_ITEM>( busToBusConflict );
  214. case ERCE_BUS_TO_NET_CONFLICT: return std::make_shared<ERC_ITEM>( busToNetConflict );
  215. case ERCE_NETCLASS_CONFLICT: return std::make_shared<ERC_ITEM>( netclassConflict );
  216. case ERCE_GLOBLABEL: return std::make_shared<ERC_ITEM>( globalLabelDangling );
  217. case ERCE_UNRESOLVED_VARIABLE: return std::make_shared<ERC_ITEM>( unresolvedVariable );
  218. case ERCE_UNDEFINED_NETCLASS: return std::make_shared<ERC_ITEM>( undefinedNetclass );
  219. case ERCE_SIMULATION_MODEL: return std::make_shared<ERC_ITEM>( simulationModelIssues );
  220. case ERCE_WIRE_DANGLING: return std::make_shared<ERC_ITEM>( wireDangling );
  221. case ERCE_LIB_SYMBOL_ISSUES: return std::make_shared<ERC_ITEM>( libSymbolIssues );
  222. case ERCE_LIB_SYMBOL_MISMATCH: return std::make_shared<ERC_ITEM>( libSymbolMismatch );
  223. case ERCE_FOOTPRINT_LINK_ISSUES: return std::make_shared<ERC_ITEM>( footprintLinkIssues );
  224. case ERCE_UNANNOTATED: return std::make_shared<ERC_ITEM>( unannotated );
  225. case ERCE_EXTRA_UNITS: return std::make_shared<ERC_ITEM>( extraUnits );
  226. case ERCE_DIFFERENT_UNIT_VALUE: return std::make_shared<ERC_ITEM>( differentUnitValue );
  227. case ERCE_DUPLICATE_REFERENCE: return std::make_shared<ERC_ITEM>( duplicateReference );
  228. case ERCE_BUS_ENTRY_NEEDED: return std::make_shared<ERC_ITEM>( busEntryNeeded );
  229. case ERCE_MISSING_UNIT: return std::make_shared<ERC_ITEM>( missingUnits );
  230. case ERCE_MISSING_INPUT_PIN: return std::make_shared<ERC_ITEM>( missingInputPin );
  231. case ERCE_MISSING_POWER_INPUT_PIN: return std::make_shared<ERC_ITEM>( missingPowerInputPin );
  232. case ERCE_MISSING_BIDI_PIN: return std::make_shared<ERC_ITEM>( missingBidiPin );
  233. case ERCE_UNSPECIFIED:
  234. default:
  235. wxFAIL_MSG( wxS( "Unknown ERC error code" ) );
  236. break;
  237. }
  238. return nullptr;
  239. }
  240. /**
  241. * Override of RC_TREE_MODEL::GetValue which returns item descriptions in a specific
  242. * SCH_SHEET_PATH context, if a context is available on the given SCH_MARKER or ERC_ITEM
  243. * targets.
  244. */
  245. void ERC_TREE_MODEL::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
  246. unsigned int aCol ) const
  247. {
  248. SCH_EDIT_FRAME* schEditFrame = static_cast<SCH_EDIT_FRAME*>( m_editFrame );
  249. const RC_TREE_NODE* node = ToNode( aItem );
  250. std::shared_ptr<ERC_ITEM> ercItem = std::static_pointer_cast<ERC_ITEM>( node->m_RcItem );
  251. MARKER_BASE* marker = ercItem->GetParent();
  252. wxString msg;
  253. auto getItemDesc =
  254. [&]( EDA_ITEM* aCurrItem, SCH_SHEET_PATH& aSheet )
  255. {
  256. SCH_SHEET_PATH curSheet = schEditFrame->GetCurrentSheet();
  257. wxString desc;
  258. if( aSheet != curSheet )
  259. {
  260. schEditFrame->SetCurrentSheet( aSheet );
  261. aSheet.UpdateAllScreenReferences();
  262. {
  263. desc = aCurrItem->GetItemDescription( m_editFrame );
  264. }
  265. schEditFrame->SetCurrentSheet( curSheet );
  266. curSheet.UpdateAllScreenReferences();
  267. }
  268. else
  269. {
  270. desc = aCurrItem->GetItemDescription( m_editFrame );
  271. }
  272. return desc;
  273. };
  274. switch( node->m_Type )
  275. {
  276. case RC_TREE_NODE::MARKER:
  277. if( marker )
  278. {
  279. SEVERITY severity = ercItem->GetParent()->GetSeverity();
  280. if( severity == RPT_SEVERITY_EXCLUSION )
  281. {
  282. if( schEditFrame->GetSeverity( ercItem->GetErrorCode() ) == RPT_SEVERITY_WARNING )
  283. msg = _( "Excluded warning: " );
  284. else
  285. msg = _( "Excluded error: " );
  286. }
  287. else if( severity == RPT_SEVERITY_WARNING )
  288. {
  289. msg = _( "Warning: " );
  290. }
  291. else
  292. {
  293. msg = _( "Error: " );
  294. }
  295. }
  296. msg += ercItem->GetErrorMessage();
  297. break;
  298. case RC_TREE_NODE::MAIN_ITEM:
  299. if( marker && marker->GetMarkerType() == MARKER_BASE::MARKER_DRAWING_SHEET )
  300. {
  301. msg = _( "Drawing Sheet" );
  302. }
  303. else
  304. {
  305. msg = getItemDesc( schEditFrame->GetItem( ercItem->GetMainItemID() ),
  306. ercItem->MainItemHasSheetPath() ? ercItem->GetMainItemSheetPath()
  307. : schEditFrame->GetCurrentSheet() );
  308. }
  309. break;
  310. case RC_TREE_NODE::AUX_ITEM:
  311. msg = getItemDesc( schEditFrame->GetItem( ercItem->GetAuxItemID() ),
  312. ercItem->AuxItemHasSheetPath() ? ercItem->GetAuxItemSheetPath()
  313. : schEditFrame->GetCurrentSheet() );
  314. break;
  315. case RC_TREE_NODE::AUX_ITEM2:
  316. msg = getItemDesc( schEditFrame->GetItem( ercItem->GetAuxItem2ID() ),
  317. schEditFrame->GetCurrentSheet() );
  318. break;
  319. case RC_TREE_NODE::AUX_ITEM3:
  320. msg = getItemDesc( schEditFrame->GetItem( ercItem->GetAuxItem3ID() ),
  321. schEditFrame->GetCurrentSheet() );
  322. break;
  323. case RC_TREE_NODE::COMMENT:
  324. if( marker )
  325. msg = marker->GetComment();
  326. break;
  327. }
  328. msg.Replace( wxS( "\n" ), wxS( " " ) );
  329. aVariant = msg;
  330. }