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.

167 lines
5.1 KiB

  1. /**
  2. * @file eeschema/tools/backannotate.h
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 2019 Alexander Shuklin <Jasuramme@gmail.com>
  8. * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #ifndef BACKANNOTATE_H
  28. #define BACKANNOTATE_H
  29. #include <deque>
  30. #include <map>
  31. #include <memory>
  32. #include <sch_reference_list.h>
  33. #include <template_fieldnames.h>
  34. #include <wx/string.h>
  35. // Forward declarations
  36. class REPORTER;
  37. class SCH_SHEET_LIST;
  38. class SCH_EDIT_FRAME;
  39. /**
  40. * @brief Back annotation algorithm class. It used to recieve, check and apply \ref NETLIST
  41. * from PCBNEW. Class check for following collisions:
  42. * - Schematic symbol exists, but linked PCBnew module missing
  43. * - PCBnew module exists but no schematic symbol connected to
  44. * - PCBnew module is standalone
  45. * - Schematic sheet is reused one or more times and user trying to change footprint or value
  46. * only for few of them.
  47. * - Schematic symbols share same path
  48. * - More than one PCBnew module linked to same path
  49. */
  50. class BACK_ANNOTATE
  51. {
  52. public:
  53. /**
  54. * @brief settings struct to set up back annotation
  55. */
  56. struct SETTINGS
  57. {
  58. REPORTER& reporter;
  59. bool processFootprints;
  60. bool processValues;
  61. bool processReferences;
  62. bool ignoreOtherProjects;
  63. bool dryRun;
  64. };
  65. /**
  66. * @brief Struct to hold PCBnew module data
  67. */
  68. struct PCB_MODULE_DATA
  69. {
  70. PCB_MODULE_DATA(wxString aRef, wxString aFootprint, wxString aValue) :
  71. ref(aRef),
  72. footprint(aFootprint),
  73. value(aValue){};
  74. wxString ref;
  75. wxString footprint;
  76. wxString value;
  77. };
  78. ///> Map to hold NETLIST modules data
  79. using PCB_MODULES_MAP = std::map<wxString, std::shared_ptr<PCB_MODULE_DATA>>;
  80. using CHANGELIST_ITEM = std::pair<SCH_REFERENCE, std::shared_ptr<PCB_MODULE_DATA>>;
  81. ///> To hold match between reference and PCBnew module
  82. using CHANGELIST = std::deque<CHANGELIST_ITEM>;
  83. BACK_ANNOTATE( SCH_EDIT_FRAME* aFrame, SETTINGS aSettings );
  84. ~BACK_ANNOTATE();
  85. /**
  86. * @brief Get netlist from the PCBnew.
  87. * @param aNetlist reference to where netlist will be stored
  88. * @return true if success
  89. */
  90. bool FetchNetlistFromPCB( std::string& aNetlist );
  91. /**
  92. * @brief Run back annotation algorithm. If any errors, back annotation doesn't run.
  93. * only report
  94. * @param aNetlist netlist to run back annotation from
  95. * @return true if success
  96. */
  97. bool BackAnnotateSymbols( const std::string& aNetlist );
  98. private:
  99. SETTINGS m_settings;
  100. PCB_MODULES_MAP m_pcbModules;
  101. SCH_REFERENCE_LIST m_refs;
  102. SCH_MULTI_UNIT_REFERENCE_MAP m_multiUnitsRefs;
  103. CHANGELIST m_changelist;
  104. SCH_EDIT_FRAME* m_frame;
  105. ///> To count number of changes applied to the schematic
  106. int m_changesCount;
  107. ///> Get text from symbol's field ( such as Footprint or Value )
  108. wxString getTextFromField( const SCH_REFERENCE& aRef, const NumFieldType aField );
  109. /**
  110. * @brief Check if modules has different data. Check only if corresponding \ref m_boardAdapter
  111. * flag is rised
  112. * @param aFirst first module to compare
  113. * @param aSecond second module to compare
  114. * @return true if no violation
  115. */
  116. bool checkReuseViolation( PCB_MODULE_DATA& aFirst, PCB_MODULE_DATA& aSecond );
  117. /**
  118. * @brief Parse netlist sent over KiWay epress mail interface and fill \ref m_pcbModules
  119. * @param aPayload - netlist from PCBnew
  120. * @return number of errors during parsing
  121. */
  122. int getPcbModulesFromString( const std::string& aPayload );
  123. ///> Create changelist
  124. int getChangeList();
  125. /**
  126. * @brief Check if some symbols are not represented in PCB modules and vice versa.
  127. * \ref m_refs must be sorted by path
  128. * @return number of errors
  129. */
  130. int checkForUnusedSymbols();
  131. /**
  132. * @brief Check for errors connected to reusing schematic in project or between projects
  133. * @return number of errors
  134. */
  135. int checkSharedSchematicErrors();
  136. /**
  137. * @brief Apply changelist to the schematic
  138. */
  139. void applyChangelist();
  140. };
  141. #endif