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.

297 lines
10 KiB

Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time). Now, nets are saved with consecutive net codes (both modern & legacy plugins). Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp). Performed tests: - Changed a pad's net name from empty to existent - ok, name was changed. - Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty. - Changed a pad's net name from existent to empty - ok, net name became empty - Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed. - Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled. - Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes). - KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications). - A few boards were also saved using the legacy format and were opened with the master KiCad without any issues. - Change a net name for a pad, restore with undo/redo - ok - Remove everything, restore with undo - ok - Remove everything, reload netlist - ok Differences observed between files saved by the master branch KiCad and this one: - list of nets are not saved in any particular order, so net codes may differ - the default net class does not contain the unconnected net
12 years ago
14 years ago
14 years ago
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time). Now, nets are saved with consecutive net codes (both modern & legacy plugins). Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp). Performed tests: - Changed a pad's net name from empty to existent - ok, name was changed. - Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty. - Changed a pad's net name from existent to empty - ok, net name became empty - Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed. - Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled. - Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes). - KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications). - A few boards were also saved using the legacy format and were opened with the master KiCad without any issues. - Change a net name for a pad, restore with undo/redo - ok - Remove everything, restore with undo - ok - Remove everything, reload netlist - ok Differences observed between files saved by the master branch KiCad and this one: - list of nets are not saved in any particular order, so net codes may differ - the default net class does not contain the unconnected net
12 years ago
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time). Now, nets are saved with consecutive net codes (both modern & legacy plugins). Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp). Performed tests: - Changed a pad's net name from empty to existent - ok, name was changed. - Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty. - Changed a pad's net name from existent to empty - ok, net name became empty - Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed. - Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled. - Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes). - KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications). - A few boards were also saved using the legacy format and were opened with the master KiCad without any issues. - Change a net name for a pad, restore with undo/redo - ok - Remove everything, restore with undo - ok - Remove everything, reload netlist - ok Differences observed between files saved by the master branch KiCad and this one: - list of nets are not saved in any particular order, so net codes may differ - the default net class does not contain the unconnected net
12 years ago
  1. #ifndef LEGACY_PLUGIN_H_
  2. #define LEGACY_PLUGIN_H_
  3. /*
  4. * This program source code file is part of KiCad, a free EDA CAD application.
  5. *
  6. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  7. * Copyright (C) 2012 KiCad Developers, see change_log.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <io_mgr.h>
  27. #include <boost/shared_ptr.hpp>
  28. #include <string>
  29. #include <layers_id_colors_and_visibility.h>
  30. #define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
  31. #define FOOTPRINT_LIBRARY_HEADER_CNT 18
  32. class PCB_TARGET;
  33. class MODULE;
  34. class DRAWSEGMENT;
  35. class NETINFO;
  36. class TEXTE_PCB;
  37. class TRACK;
  38. class NETCLASS;
  39. class NETCLASSES;
  40. class ZONE_CONTAINER;
  41. class DIMENSION;
  42. class NETINFO_ITEM;
  43. class NETINFO_MAPPING;
  44. class TEXTE_MODULE;
  45. class EDGE_MODULE;
  46. class TRACK;
  47. class SEGZONE;
  48. class D_PAD;
  49. struct LP_CACHE;
  50. /**
  51. * Class LEGACY_PLUGIN
  52. * is a PLUGIN derivation which could possibly be put into a DLL/DSO.
  53. * As with any PLUGIN, there is no UI, i.e. windowing calls allowed.
  54. */
  55. class LEGACY_PLUGIN : public PLUGIN
  56. {
  57. friend struct LP_CACHE;
  58. public:
  59. //-----<PLUGIN IMPLEMENTATION>----------------------------------------------
  60. const wxString PluginName() const
  61. {
  62. return wxT( "KiCad-Legacy" );
  63. }
  64. const wxString GetFileExtension() const
  65. {
  66. return wxT( "brd" );
  67. }
  68. BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties = NULL );
  69. /* we let go of "save" support when the number of CU layers were expanded from 16 to 32.
  70. void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
  71. void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
  72. const PROPERTIES* aProperties = NULL );
  73. void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
  74. void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
  75. */
  76. wxArrayString FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL);
  77. MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
  78. const PROPERTIES* aProperties = NULL );
  79. bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
  80. bool IsFootprintLibWritable( const wxString& aLibraryPath );
  81. //-----</PLUGIN IMPLEMENTATION>---------------------------------------------
  82. typedef int BIU;
  83. LEGACY_PLUGIN();
  84. ~LEGACY_PLUGIN();
  85. void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
  86. void SetFilePtr( FILE* aFile ) { m_fp = aFile; }
  87. void SaveModule3D( const MODULE* aModule ) const;
  88. static LAYER_ID leg_layer2new( int cu_count, LAYER_NUM aLayerNum );
  89. static LSET leg_mask2new( int cu_count, unsigned aMask );
  90. protected:
  91. int m_cu_count;
  92. wxString m_error; ///< for throwing exceptions
  93. BOARD* m_board; ///< which BOARD, no ownership here
  94. const PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL.
  95. LINE_READER* m_reader; ///< no ownership here.
  96. FILE* m_fp; ///< no ownership here.
  97. wxString m_filename; ///< for saves only, name is in m_reader for loads
  98. wxString m_field; ///< reused to stuff MODULE fields.
  99. int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing?
  100. LP_CACHE* m_cache;
  101. NETINFO_MAPPING* m_mapping; ///< mapping for net codes, so only not empty nets
  102. ///< are stored with consecutive integers as net codes
  103. std::vector<int> m_netCodes; ///< net codes mapping for boards being loaded
  104. /// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
  105. void init( const PROPERTIES* aProperties );
  106. double biuToDisk; ///< convert from BIUs to disk engineering units
  107. ///< with this scale factor
  108. double diskToBiu; ///< convert from disk engineering units to BIUs
  109. ///< with this scale factor
  110. ///> Converts net code using the mapping table if available,
  111. ///> otherwise returns unchanged net code
  112. inline int getNetCode( int aNetCode )
  113. {
  114. if( aNetCode < (int) m_netCodes.size() )
  115. return m_netCodes[aNetCode];
  116. return aNetCode;
  117. }
  118. /**
  119. * Function biuParse
  120. * parses an ASCII decimal floating point value and scales it into a BIU
  121. * according to the current value of diskToBui. This fuction is the complement of
  122. * fmtBIU(). One has to know what the other is doing.
  123. *
  124. * @param aValue is the ASCII value in C locale form with possible leading whitespace
  125. *
  126. * @param nptrptr may be NULL, but if not, then it tells where to put a
  127. * pointer to the next unconsumed input text. See "man strtod" for more information.
  128. *
  129. * @return BIU - the converted Board Internal Unit.
  130. */
  131. BIU biuParse( const char* aValue, const char** nptrptr = NULL );
  132. /**
  133. * Function degParse
  134. * parses an ASCII decimal floating point value which is certainly an angle. This
  135. * is a dedicated function for encapsulating support for the migration from
  136. * tenths of degrees to degrees in floating point. This function is the complement of
  137. * fmtDEG(). One has to know what the other is doing.
  138. *
  139. * @param aValue is the ASCII value in C locale form with possible leading whitespace
  140. *
  141. * @param nptrptr may be NULL, but if not, then it tells where to put a
  142. * pointer to the next unconsumed input text. See "man strtod" for more information.
  143. *
  144. * @return double - the string converted to a primitive double type
  145. */
  146. double degParse( const char* aValue, const char** nptrptr = NULL );
  147. //-----<load/parse functions>-----------------------------------------------
  148. void checkVersion();
  149. void loadAllSections( bool doAppend );
  150. void loadGENERAL();
  151. void loadSETUP();
  152. void loadSHEET();
  153. void load3D( MODULE* aModule );
  154. void loadPAD( MODULE* aModule );
  155. void loadMODULE_TEXT( TEXTE_MODULE* aText );
  156. void loadMODULE_EDGE( MODULE* aModule );
  157. void loadPCB_LINE();
  158. void loadNETINFO_ITEM();
  159. void loadPCB_TEXT();
  160. void loadNETCLASS();
  161. void loadMODULE( MODULE* aModule );
  162. /**
  163. * Function loadTrackList
  164. * reads a list of segments (Tracks and Vias, or Segzones)
  165. *
  166. * @param aStructType is either PCB_TRACE_T to indicate tracks and vias, or
  167. * PCB_ZONE_T to indicate oldschool zone segments (before polygons came to be).
  168. */
  169. void loadTrackList( int aStructType );
  170. void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
  171. void loadDIMENSION(); // "$COTATION"
  172. void loadPCB_TARGET(); // "$PCB_TARGET"
  173. //-----</ load/parse functions>---------------------------------------------
  174. //-----<save functions>-----------------------------------------------------
  175. #if 0
  176. /**
  177. * Function writeError
  178. * returns an error message wxString containing the filename being
  179. * currently written.
  180. */
  181. wxString writeError() const;
  182. /// encapsulate the BIU formatting tricks in one place.
  183. int biuSprintf( char* buf, BIU aValue ) const;
  184. /**
  185. * Function fmtBIU
  186. * converts a BIU to engineering units by scaling and formatting to ASCII.
  187. * This function is the complement of biuParse(). One has to know what the
  188. * other is doing.
  189. */
  190. std::string fmtBIU( BIU aValue ) const;
  191. std::string fmtBIUPair( BIU first, BIU second ) const;
  192. std::string fmtBIUPoint( const wxPoint& aPoint ) const
  193. {
  194. return fmtBIUPair( aPoint.x, aPoint.y );
  195. }
  196. std::string fmtBIUSize( const wxSize& aSize ) const
  197. {
  198. return fmtBIUPair( aSize.x, aSize.y );
  199. }
  200. /**
  201. * Function fmtDEG
  202. * formats an angle in a way particular to a board file format. This function
  203. * is the opposite or complement of degParse(). One has to know what the
  204. * other is doing.
  205. */
  206. std::string fmtDEG( double aAngle ) const;
  207. void saveGENERAL( const BOARD* aBoard ) const;
  208. void saveSHEET( const BOARD* aBoard ) const;
  209. void saveSETUP( const BOARD* aBoard ) const;
  210. void saveBOARD_ITEMS( const BOARD* aBoard ) const;
  211. void saveMODULE_TEXT( const TEXTE_MODULE* aText ) const;
  212. void saveMODULE_EDGE( const EDGE_MODULE* aGraphic ) const;
  213. void savePAD( const D_PAD* aPad ) const;
  214. void saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const;
  215. void saveNETCLASSES( const NETCLASSES* aNetClasses ) const;
  216. void saveNETCLASS( const boost::shared_ptr<NETCLASS> aNetclass ) const;
  217. void savePCB_TEXT( const TEXTE_PCB* aText ) const;
  218. void savePCB_TARGET( const PCB_TARGET* aTarget ) const;
  219. void savePCB_LINE( const DRAWSEGMENT* aStroke ) const;
  220. void saveDIMENSION( const DIMENSION* aDimension ) const;
  221. void saveTRACK( const TRACK* aTrack ) const;
  222. void saveBOARD( const BOARD* aBoard ) const;
  223. /**
  224. * Function saveZONE_CONTAINER
  225. * saves the new polygon zones.
  226. */
  227. void saveZONE_CONTAINER( const ZONE_CONTAINER* aZone ) const;
  228. //-----</save functions>----------------------------------------------------
  229. #endif
  230. /// we only cache one footprint library for now, this determines which one.
  231. void cacheLib( const wxString& aLibraryPath );
  232. };
  233. #endif // LEGACY_PLUGIN_H_