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.

285 lines
9.5 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. // This will get mapped to "kicad_default" in the specctra_export.
  34. const char NETCLASS::Default[] = "Default";
  35. // Initial values for netclass initialization
  36. const int DEFAULT_CLEARANCE = Millimeter2iu( 0.2 ); // track to track and track to pads clearance
  37. const int DEFAULT_VIA_DIAMETER = Millimeter2iu( 0.8 );
  38. const int DEFAULT_VIA_DRILL = Millimeter2iu( 0.4 );
  39. const int DEFAULT_UVIA_DIAMETER = Millimeter2iu( 0.3 );
  40. const int DEFAULT_UVIA_DRILL = Millimeter2iu( 0.1 );
  41. const int DEFAULT_TRACK_WIDTH = Millimeter2iu( 0.25 );
  42. const int DEFAULT_DIFF_PAIR_WIDTH = Millimeter2iu( 0.2 );
  43. const int DEFAULT_DIFF_PAIR_GAP = Millimeter2iu( 0.25 );
  44. const int DEFAULT_DIFF_PAIR_VIAGAP = Millimeter2iu( 0.25 );
  45. NETCLASS::NETCLASS( const wxString& aName ) :
  46. m_Name( aName )
  47. {
  48. // Default settings
  49. SetClearance( DEFAULT_CLEARANCE );
  50. SetViaDrill( DEFAULT_VIA_DRILL );
  51. SetuViaDrill( DEFAULT_UVIA_DRILL );
  52. // These defaults will be overwritten by SetParams,
  53. // from the board design parameters, later
  54. SetTrackWidth( DEFAULT_TRACK_WIDTH );
  55. SetViaDiameter( DEFAULT_VIA_DIAMETER );
  56. SetuViaDiameter( DEFAULT_UVIA_DIAMETER );
  57. SetDiffPairWidth( DEFAULT_DIFF_PAIR_WIDTH );
  58. SetDiffPairGap( DEFAULT_DIFF_PAIR_GAP );
  59. SetDiffPairViaGap( DEFAULT_DIFF_PAIR_VIAGAP );
  60. }
  61. void NETCLASS::SetParams( const NETCLASS& aDefaults )
  62. {
  63. SetClearance( aDefaults.GetClearance() );
  64. SetTrackWidth( aDefaults.GetTrackWidth() );
  65. SetViaDiameter( aDefaults.GetViaDiameter() );
  66. SetViaDrill( aDefaults.GetViaDrill() );
  67. SetuViaDiameter( aDefaults.GetuViaDiameter() );
  68. SetuViaDrill( aDefaults.GetuViaDrill() );
  69. SetDiffPairWidth( aDefaults.GetDiffPairWidth() );
  70. SetDiffPairGap( aDefaults.GetDiffPairGap() );
  71. SetDiffPairViaGap( aDefaults.GetDiffPairViaGap() );
  72. }
  73. NETCLASS::~NETCLASS()
  74. {
  75. }
  76. NETCLASSES::NETCLASSES()
  77. {
  78. m_default = std::make_shared<NETCLASS>( NETCLASS::Default );
  79. }
  80. NETCLASSES::~NETCLASSES()
  81. {
  82. }
  83. bool NETCLASSES::Add( const NETCLASSPTR& aNetClass )
  84. {
  85. const wxString& name = aNetClass->GetName();
  86. if( name == NETCLASS::Default )
  87. {
  88. m_default = aNetClass;
  89. return true;
  90. }
  91. // Test for an existing netclass:
  92. if( !Find( name ) )
  93. {
  94. // name not found, take ownership
  95. m_NetClasses[name] = aNetClass;
  96. return true;
  97. }
  98. else
  99. {
  100. // name already exists
  101. // do not "take ownership" and return false telling caller such.
  102. return false;
  103. }
  104. }
  105. NETCLASSPTR NETCLASSES::Remove( const wxString& aNetName )
  106. {
  107. NETCLASS_MAP::iterator found = m_NetClasses.find( aNetName );
  108. if( found != m_NetClasses.end() )
  109. {
  110. std::shared_ptr<NETCLASS> netclass = found->second;
  111. m_NetClasses.erase( found );
  112. return netclass;
  113. }
  114. return NETCLASSPTR();
  115. }
  116. NETCLASSPTR NETCLASSES::Find( const wxString& aName ) const
  117. {
  118. if( aName == NETCLASS::Default )
  119. return GetDefault();
  120. NETCLASS_MAP::const_iterator found = m_NetClasses.find( aName );
  121. if( found == m_NetClasses.end() )
  122. return NETCLASSPTR();
  123. else
  124. return found->second;
  125. }
  126. void BOARD::SynchronizeNetsAndNetClasses()
  127. {
  128. NETCLASSES& netClasses = m_designSettings.m_NetClasses;
  129. NETCLASSPTR defaultNetClass = netClasses.GetDefault();
  130. // set all NETs to the default NETCLASS, then later override some
  131. // as we go through the NETCLASSes.
  132. for( NETINFO_LIST::iterator net( m_NetInfo.begin() ), netEnd( m_NetInfo.end() );
  133. net != netEnd; ++net )
  134. {
  135. net->SetClass( defaultNetClass );
  136. }
  137. // Add netclass name and pointer to nets. If a net is in more than one netclass,
  138. // set the net's name and pointer to only the first netclass. Subsequent
  139. // and therefore bogus netclass memberships will be deleted in logic below this loop.
  140. for( NETCLASSES::iterator clazz = netClasses.begin(); clazz != netClasses.end(); ++clazz )
  141. {
  142. NETCLASSPTR netclass = clazz->second;
  143. for( NETCLASS::const_iterator member = netclass->begin(); member != netclass->end(); ++member )
  144. {
  145. const wxString& netname = *member;
  146. // although this overall function seems to be adequately fast,
  147. // FindNet( wxString ) uses now a fast binary search and is fast
  148. // event for large net lists
  149. NETINFO_ITEM* net = FindNet( netname );
  150. if( net && net->GetClassName() == NETCLASS::Default )
  151. {
  152. net->SetClass( netclass );
  153. }
  154. }
  155. }
  156. // Finally, make sure that every NET is in a NETCLASS, even if that
  157. // means the Default NETCLASS. And make sure that all NETCLASSes do not
  158. // contain netnames that do not exist, by deleting all netnames from
  159. // every netclass and re-adding them.
  160. for( NETCLASSES::iterator clazz = netClasses.begin(); clazz != netClasses.end(); ++clazz )
  161. {
  162. NETCLASSPTR netclass = clazz->second;
  163. netclass->Clear();
  164. }
  165. defaultNetClass->Clear();
  166. for( NETINFO_LIST::iterator net( m_NetInfo.begin() ), netEnd( m_NetInfo.end() );
  167. net != netEnd; ++net )
  168. {
  169. const wxString& classname = net->GetClassName();
  170. // because of the std:map<> this should be fast, and because of
  171. // prior logic, netclass should not be NULL.
  172. NETCLASSPTR netclass = netClasses.Find( classname );
  173. wxASSERT( netclass );
  174. netclass->Add( net->GetNetname() );
  175. }
  176. // Set initial values for custom track width & via size to match the default netclass settings
  177. m_designSettings.UseCustomTrackViaSize( false );
  178. m_designSettings.SetCustomTrackWidth( defaultNetClass->GetTrackWidth() );
  179. m_designSettings.SetCustomViaSize( defaultNetClass->GetViaDiameter() );
  180. m_designSettings.SetCustomViaDrill( defaultNetClass->GetViaDrill() );
  181. m_designSettings.SetCustomDiffPairWidth( defaultNetClass->GetDiffPairWidth() );
  182. m_designSettings.SetCustomDiffPairGap( defaultNetClass->GetDiffPairGap() );
  183. m_designSettings.SetCustomDiffPairViaGap( defaultNetClass->GetDiffPairViaGap() );
  184. }
  185. #if defined(DEBUG)
  186. void NETCLASS::Show( int nestLevel, std::ostream& os ) const
  187. {
  188. // for now, make it look like XML:
  189. //NestedSpace( nestLevel, os )
  190. os << '<' << GetClass().Lower().mb_str() << ">\n";
  191. for( const_iterator i = begin(); i!=end(); ++i )
  192. {
  193. // NestedSpace( nestLevel+1, os ) << *i;
  194. os << TO_UTF8( *i );
  195. }
  196. // NestedSpace( nestLevel, os )
  197. os << "</" << GetClass().Lower().mb_str() << ">\n";
  198. }
  199. #endif
  200. void NETCLASS::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
  201. {
  202. aFormatter->Print( aNestLevel, "(net_class %s %s\n",
  203. aFormatter->Quotew( GetName() ).c_str(),
  204. aFormatter->Quotew( GetDescription() ).c_str() );
  205. aFormatter->Print( aNestLevel+1, "(clearance %s)\n", FormatInternalUnits( GetClearance() ).c_str() );
  206. aFormatter->Print( aNestLevel+1, "(trace_width %s)\n", FormatInternalUnits( GetTrackWidth() ).c_str() );
  207. aFormatter->Print( aNestLevel+1, "(via_dia %s)\n", FormatInternalUnits( GetViaDiameter() ).c_str() );
  208. aFormatter->Print( aNestLevel+1, "(via_drill %s)\n", FormatInternalUnits( GetViaDrill() ).c_str() );
  209. aFormatter->Print( aNestLevel+1, "(uvia_dia %s)\n", FormatInternalUnits( GetuViaDiameter() ).c_str() );
  210. aFormatter->Print( aNestLevel+1, "(uvia_drill %s)\n", FormatInternalUnits( GetuViaDrill() ).c_str() );
  211. // Save the diff_pair_gap and diff_pair_width values only if not the default, to avoid unnecessary
  212. // incompatibility with previous Pcbnew versions.
  213. if( ( DEFAULT_DIFF_PAIR_WIDTH != GetDiffPairWidth() ) ||
  214. ( DEFAULT_DIFF_PAIR_GAP != GetDiffPairGap() ) )
  215. {
  216. aFormatter->Print( aNestLevel+1, "(diff_pair_width %s)\n",
  217. FormatInternalUnits( GetDiffPairWidth() ).c_str() );
  218. aFormatter->Print( aNestLevel+1, "(diff_pair_gap %s)\n",
  219. FormatInternalUnits( GetDiffPairGap() ).c_str() );
  220. // 6.0 TODO: figure out what to do with DiffPairViaGap...
  221. }
  222. for( NETCLASS::const_iterator it = begin(); it != end(); ++it )
  223. aFormatter->Print( aNestLevel+1, "(add_net %s)\n", aFormatter->Quotew( *it ).c_str() );
  224. aFormatter->Print( aNestLevel, ")\n\n" );
  225. }