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.

288 lines
9.6 KiB

++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@inpg.fr
  6. * Copyright (C) 2009 KiCad Developers, see change_log.txt for contributors.
  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
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <fctsys.h>
  26. #include <common.h>
  27. #include <kicad_string.h>
  28. #include <pcbnew.h>
  29. #include <richio.h>
  30. #include <macros.h>
  31. #include <class_board.h>
  32. #include <netclass.h>
  33. /// Abbrevation for fomatting internal units to a string.
  34. #define FMT_IU BOARD_ITEM::FormatInternalUnits
  35. #define FMT_ANGLE BOARD_ITEM::FormatAngle
  36. // This will get mapped to "kicad_default" in the specctra_export.
  37. const char NETCLASS::Default[] = "Default";
  38. // Initial values for netclass initialization
  39. const int DEFAULT_CLEARANCE = Millimeter2iu( 0.2 ); // track to track and track to pads clearance
  40. const int DEFAULT_VIA_DIAMETER = Millimeter2iu( 0.8 );
  41. const int DEFAULT_VIA_DRILL = Millimeter2iu( 0.4 );
  42. const int DEFAULT_UVIA_DIAMETER = Millimeter2iu( 0.3 );
  43. const int DEFAULT_UVIA_DRILL = Millimeter2iu( 0.1 );
  44. const int DEFAULT_TRACK_WIDTH = Millimeter2iu( 0.25 );
  45. const int DEFAULT_DIFF_PAIR_WIDTH = Millimeter2iu( 0.2 );
  46. const int DEFAULT_DIFF_PAIR_GAP = Millimeter2iu( 0.25 );
  47. const int DEFAULT_DIFF_PAIR_VIAGAP = Millimeter2iu( 0.25 );
  48. NETCLASS::NETCLASS( const wxString& aName ) :
  49. m_Name( aName )
  50. {
  51. // Default settings
  52. SetClearance( DEFAULT_CLEARANCE );
  53. SetViaDrill( DEFAULT_VIA_DRILL );
  54. SetuViaDrill( DEFAULT_UVIA_DRILL );
  55. // These defaults will be overwritten by SetParams,
  56. // from the board design parameters, later
  57. SetTrackWidth( DEFAULT_TRACK_WIDTH );
  58. SetViaDiameter( DEFAULT_VIA_DIAMETER );
  59. SetuViaDiameter( DEFAULT_UVIA_DIAMETER );
  60. SetDiffPairWidth( DEFAULT_DIFF_PAIR_WIDTH );
  61. SetDiffPairGap( DEFAULT_DIFF_PAIR_GAP );
  62. SetDiffPairViaGap( DEFAULT_DIFF_PAIR_VIAGAP );
  63. }
  64. void NETCLASS::SetParams( const NETCLASS& aDefaults )
  65. {
  66. SetClearance( aDefaults.GetClearance() );
  67. SetTrackWidth( aDefaults.GetTrackWidth() );
  68. SetViaDiameter( aDefaults.GetViaDiameter() );
  69. SetViaDrill( aDefaults.GetViaDrill() );
  70. SetuViaDiameter( aDefaults.GetuViaDiameter() );
  71. SetuViaDrill( aDefaults.GetuViaDrill() );
  72. SetDiffPairWidth( aDefaults.GetDiffPairWidth() );
  73. SetDiffPairGap( aDefaults.GetDiffPairGap() );
  74. SetDiffPairViaGap( aDefaults.GetDiffPairViaGap() );
  75. }
  76. NETCLASS::~NETCLASS()
  77. {
  78. }
  79. NETCLASSES::NETCLASSES()
  80. {
  81. m_default = std::make_shared<NETCLASS>( NETCLASS::Default );
  82. }
  83. NETCLASSES::~NETCLASSES()
  84. {
  85. }
  86. bool NETCLASSES::Add( const NETCLASSPTR& aNetClass )
  87. {
  88. const wxString& name = aNetClass->GetName();
  89. if( name == NETCLASS::Default )
  90. {
  91. m_default = aNetClass;
  92. return true;
  93. }
  94. // Test for an existing netclass:
  95. if( !Find( name ) )
  96. {
  97. // name not found, take ownership
  98. m_NetClasses[name] = aNetClass;
  99. return true;
  100. }
  101. else
  102. {
  103. // name already exists
  104. // do not "take ownership" and return false telling caller such.
  105. return false;
  106. }
  107. }
  108. NETCLASSPTR NETCLASSES::Remove( const wxString& aNetName )
  109. {
  110. NETCLASS_MAP::iterator found = m_NetClasses.find( aNetName );
  111. if( found != m_NetClasses.end() )
  112. {
  113. std::shared_ptr<NETCLASS> netclass = found->second;
  114. m_NetClasses.erase( found );
  115. return netclass;
  116. }
  117. return NETCLASSPTR();
  118. }
  119. NETCLASSPTR NETCLASSES::Find( const wxString& aName ) const
  120. {
  121. if( aName == NETCLASS::Default )
  122. return GetDefault();
  123. NETCLASS_MAP::const_iterator found = m_NetClasses.find( aName );
  124. if( found == m_NetClasses.end() )
  125. return NETCLASSPTR();
  126. else
  127. return found->second;
  128. }
  129. void BOARD::SynchronizeNetsAndNetClasses()
  130. {
  131. NETCLASSES& netClasses = m_designSettings.m_NetClasses;
  132. NETCLASSPTR defaultNetClass = netClasses.GetDefault();
  133. // set all NETs to the default NETCLASS, then later override some
  134. // as we go through the NETCLASSes.
  135. for( NETINFO_LIST::iterator net( m_NetInfo.begin() ), netEnd( m_NetInfo.end() );
  136. net != netEnd; ++net )
  137. {
  138. net->SetClass( defaultNetClass );
  139. }
  140. // Add netclass name and pointer to nets. If a net is in more than one netclass,
  141. // set the net's name and pointer to only the first netclass. Subsequent
  142. // and therefore bogus netclass memberships will be deleted in logic below this loop.
  143. for( NETCLASSES::iterator clazz = netClasses.begin(); clazz != netClasses.end(); ++clazz )
  144. {
  145. NETCLASSPTR netclass = clazz->second;
  146. for( NETCLASS::const_iterator member = netclass->begin(); member != netclass->end(); ++member )
  147. {
  148. const wxString& netname = *member;
  149. // although this overall function seems to be adequately fast,
  150. // FindNet( wxString ) uses now a fast binary search and is fast
  151. // event for large net lists
  152. NETINFO_ITEM* net = FindNet( netname );
  153. if( net && net->GetClassName() == NETCLASS::Default )
  154. {
  155. net->SetClass( netclass );
  156. }
  157. }
  158. }
  159. // Finally, make sure that every NET is in a NETCLASS, even if that
  160. // means the Default NETCLASS. And make sure that all NETCLASSes do not
  161. // contain netnames that do not exist, by deleting all netnames from
  162. // every netclass and re-adding them.
  163. for( NETCLASSES::iterator clazz = netClasses.begin(); clazz != netClasses.end(); ++clazz )
  164. {
  165. NETCLASSPTR netclass = clazz->second;
  166. netclass->Clear();
  167. }
  168. defaultNetClass->Clear();
  169. for( NETINFO_LIST::iterator net( m_NetInfo.begin() ), netEnd( m_NetInfo.end() );
  170. net != netEnd; ++net )
  171. {
  172. const wxString& classname = net->GetClassName();
  173. // because of the std:map<> this should be fast, and because of
  174. // prior logic, netclass should not be NULL.
  175. NETCLASSPTR netclass = netClasses.Find( classname );
  176. wxASSERT( netclass );
  177. netclass->Add( net->GetNetname() );
  178. }
  179. // Set initial values for custom track width & via size to match the default netclass settings
  180. m_designSettings.UseCustomTrackViaSize( false );
  181. m_designSettings.SetCustomTrackWidth( defaultNetClass->GetTrackWidth() );
  182. m_designSettings.SetCustomViaSize( defaultNetClass->GetViaDiameter() );
  183. m_designSettings.SetCustomViaDrill( defaultNetClass->GetViaDrill() );
  184. m_designSettings.SetCustomDiffPairWidth( defaultNetClass->GetDiffPairWidth() );
  185. m_designSettings.SetCustomDiffPairGap( defaultNetClass->GetDiffPairGap() );
  186. m_designSettings.SetCustomDiffPairViaGap( defaultNetClass->GetDiffPairViaGap() );
  187. }
  188. #if defined(DEBUG)
  189. void NETCLASS::Show( int nestLevel, std::ostream& os ) const
  190. {
  191. // for now, make it look like XML:
  192. //NestedSpace( nestLevel, os )
  193. os << '<' << GetClass().Lower().mb_str() << ">\n";
  194. for( const_iterator i = begin(); i!=end(); ++i )
  195. {
  196. // NestedSpace( nestLevel+1, os ) << *i;
  197. os << TO_UTF8( *i );
  198. }
  199. // NestedSpace( nestLevel, os )
  200. os << "</" << GetClass().Lower().mb_str() << ">\n";
  201. }
  202. #endif
  203. void NETCLASS::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
  204. {
  205. aFormatter->Print( aNestLevel, "(net_class %s %s\n",
  206. aFormatter->Quotew( GetName() ).c_str(),
  207. aFormatter->Quotew( GetDescription() ).c_str() );
  208. aFormatter->Print( aNestLevel+1, "(clearance %s)\n", FMT_IU( GetClearance() ).c_str() );
  209. aFormatter->Print( aNestLevel+1, "(trace_width %s)\n", FMT_IU( GetTrackWidth() ).c_str() );
  210. aFormatter->Print( aNestLevel+1, "(via_dia %s)\n", FMT_IU( GetViaDiameter() ).c_str() );
  211. aFormatter->Print( aNestLevel+1, "(via_drill %s)\n", FMT_IU( GetViaDrill() ).c_str() );
  212. aFormatter->Print( aNestLevel+1, "(uvia_dia %s)\n", FMT_IU( GetuViaDiameter() ).c_str() );
  213. aFormatter->Print( aNestLevel+1, "(uvia_drill %s)\n", FMT_IU( GetuViaDrill() ).c_str() );
  214. // Save the diff_pair_gap and diff_pair_width values only if not the default, to avoid unnecessary
  215. // incompatibility with previous Pcbnew versions.
  216. if( ( DEFAULT_DIFF_PAIR_WIDTH != GetDiffPairWidth() ) ||
  217. ( DEFAULT_DIFF_PAIR_GAP != GetDiffPairGap() ) )
  218. {
  219. aFormatter->Print( aNestLevel+1, "(diff_pair_width %s)\n", FMT_IU( GetDiffPairWidth() ).c_str() );
  220. aFormatter->Print( aNestLevel+1, "(diff_pair_gap %s)\n", FMT_IU( GetDiffPairGap() ).c_str() );
  221. // 6.0 TODO: figure out what to do with DiffPairViaGap...
  222. }
  223. for( NETCLASS::const_iterator it = begin(); it != end(); ++it )
  224. aFormatter->Print( aNestLevel+1, "(add_net %s)\n", aFormatter->Quotew( *it ).c_str() );
  225. aFormatter->Print( aNestLevel, ")\n\n" );
  226. }