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.

344 lines
10 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
14 years ago
14 years ago
14 years ago
++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
++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
++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
++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
++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
++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
  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 <class_netclass.h>
  33. // This will get mapped to "kicad_default" in the specctra_export.
  34. const wxString NETCLASS::Default = wxT("Default");
  35. // Initial values for netclass initialization
  36. int NETCLASS::DEFAULT_CLEARANCE = DMils2iu( 100 ); // track to track and track to pads clearance
  37. int NETCLASS::DEFAULT_VIA_DRILL = DMils2iu( 250 ); // default via drill
  38. int NETCLASS::DEFAULT_UVIA_DRILL = DMils2iu( 50 ); // micro via drill
  39. NETCLASS::NETCLASS( BOARD* aParent, const wxString& aName, const NETCLASS* initialParameters ) :
  40. m_Parent( aParent ),
  41. m_Name( aName )
  42. {
  43. // use initialParameters if not NULL, else set the initial
  44. // parameters from boardDesignSettings (try to change this)
  45. SetParams( initialParameters );
  46. }
  47. void NETCLASS::SetParams( const NETCLASS* defaults )
  48. {
  49. if( defaults )
  50. {
  51. SetClearance( defaults->GetClearance() );
  52. SetTrackWidth( defaults->GetTrackWidth() );
  53. SetViaDiameter( defaults->GetViaDiameter() );
  54. SetViaDrill( defaults->GetViaDrill() );
  55. SetuViaDiameter( defaults->GetuViaDiameter() );
  56. SetuViaDrill( defaults->GetuViaDrill() );
  57. }
  58. else
  59. {
  60. /* Dick 5-Feb-2012: I do not believe this comment to be true with current code.
  61. It is certainly not a constructor race. Normally items are initialized
  62. within a class according to the order of their appearance.
  63. // Note:
  64. // We use m_Parent->GetDesignSettings() to get some default values
  65. // But when this function is called when instantiating a BOARD class,
  66. // by the NETCLASSES constructor that calls NETCLASS constructor,
  67. // the BOARD constructor (see BOARD::BOARD) is not yet run,
  68. // and BOARD::m_designSettings contains not yet initialized values.
  69. // So inside the BOARD constructor itself, you SHOULD recall SetParams
  70. */
  71. const BOARD_DESIGN_SETTINGS& g = m_Parent->GetDesignSettings();
  72. SetTrackWidth( g.m_TrackMinWidth );
  73. SetViaDiameter( g.m_ViasMinSize );
  74. SetuViaDiameter( g.m_MicroViasMinSize );
  75. // Use default values for next parameters:
  76. SetClearance( DEFAULT_CLEARANCE );
  77. SetViaDrill( DEFAULT_VIA_DRILL );
  78. SetuViaDrill( DEFAULT_UVIA_DRILL );
  79. }
  80. }
  81. NETCLASS::~NETCLASS()
  82. {
  83. }
  84. NETCLASSES::NETCLASSES( BOARD* aParent ) :
  85. m_Parent( aParent ),
  86. m_Default( aParent, NETCLASS::Default )
  87. {
  88. }
  89. NETCLASSES::~NETCLASSES()
  90. {
  91. Clear();
  92. }
  93. void NETCLASSES::Clear()
  94. {
  95. // Although std::map<> will destroy the items that it contains, in this
  96. // case we have NETCLASS* (pointers) and "destroying" a pointer does not
  97. // delete the object that the pointer points to.
  98. // this NETCLASSES is owner of its NETCLASS pointers,
  99. // so delete NETCLASSes pointed to by them.
  100. for( iterator i = begin(); i!=end(); )
  101. {
  102. // http://www.sgi.com/tech/stl/Map.html says:
  103. // "Erasing an element from a map also does not invalidate any iterators,
  104. // except, of course, for iterators that actually point to the element that
  105. // is being erased."
  106. iterator e = i++; // copy, then advance.
  107. delete e->second; // delete the NETCLASS, which 'second' points to.
  108. m_NetClasses.erase( e );
  109. }
  110. }
  111. bool NETCLASSES::Add( NETCLASS* aNetClass )
  112. {
  113. const wxString& name = aNetClass->GetName();
  114. if( name == NETCLASS::Default )
  115. {
  116. // invoke operator=(), which is currently generated by compiler.
  117. m_Default = *aNetClass;
  118. delete aNetClass; // we own aNetClass, must delete it since we copied it.
  119. return true;
  120. }
  121. // Test for an existing netclass:
  122. if( !Find( name ) )
  123. {
  124. // name not found, take ownership
  125. m_NetClasses[name] = aNetClass;
  126. return true;
  127. }
  128. else
  129. {
  130. // name already exists
  131. // do not "take ownership" and return false telling caller such.
  132. return false;
  133. }
  134. }
  135. NETCLASS* NETCLASSES::Remove( const wxString& aNetName )
  136. {
  137. NETCLASSMAP::iterator found = m_NetClasses.find( aNetName );
  138. if( found != m_NetClasses.end() )
  139. {
  140. NETCLASS* netclass = found->second;
  141. m_NetClasses.erase( found );
  142. return netclass;
  143. }
  144. return NULL;
  145. }
  146. NETCLASS* NETCLASSES::Find( const wxString& aName ) const
  147. {
  148. if( aName == NETCLASS::Default )
  149. return (NETCLASS*) &m_Default;
  150. NETCLASSMAP::const_iterator found = m_NetClasses.find( aName );
  151. if( found == m_NetClasses.end() )
  152. return NULL;
  153. else
  154. return found->second;
  155. }
  156. void BOARD::SynchronizeNetsAndNetClasses()
  157. {
  158. // D(printf("start\n");) // simple performance/timing indicator.
  159. // set all NETs to the default NETCLASS, then later override some
  160. // as we go through the NETCLASSes.
  161. int count = m_NetInfo.GetNetCount();
  162. for( int i=0; i<count; ++i )
  163. {
  164. NETINFO_ITEM* net = FindNet( i );
  165. if( net )
  166. net->SetClass( m_NetClasses.GetDefault() );
  167. }
  168. // Add netclass name and pointer to nets. If a net is in more than one netclass,
  169. // set the net's name and pointer to only the first netclass. Subsequent
  170. // and therefore bogus netclass memberships will be deleted in logic below this loop.
  171. for( NETCLASSES::iterator clazz=m_NetClasses.begin(); clazz!=m_NetClasses.end(); ++clazz )
  172. {
  173. NETCLASS* netclass = clazz->second;
  174. for( NETCLASS::iterator member = netclass->begin(); member!=netclass->end(); ++member )
  175. {
  176. const wxString& netname = *member;
  177. // although this overall function seems to be adequately fast,
  178. // FindNet( wxString ) uses now a fast binary search and is fast
  179. // event for large net lists
  180. NETINFO_ITEM* net = FindNet( netname );
  181. if( net && net->GetClassName() == NETCLASS::Default )
  182. {
  183. net->SetClass( netclass );
  184. }
  185. }
  186. }
  187. // Finally, make sure that every NET is in a NETCLASS, even if that
  188. // means the Default NETCLASS. And make sure that all NETCLASSes do not
  189. // contain netnames that do not exist, by deleting all netnames from
  190. // every netclass and re-adding them.
  191. for( NETCLASSES::iterator clazz=m_NetClasses.begin(); clazz!=m_NetClasses.end(); ++clazz )
  192. {
  193. NETCLASS* netclass = clazz->second;
  194. netclass->Clear();
  195. }
  196. m_NetClasses.GetDefault()->Clear();
  197. for( int i=0; i<count; ++i )
  198. {
  199. NETINFO_ITEM* net = FindNet( i );
  200. if( net )
  201. {
  202. const wxString& classname = net->GetClassName();
  203. // because of the std:map<> this should be fast, and because of
  204. // prior logic, netclass should not be NULL.
  205. NETCLASS* netclass = m_NetClasses.Find( classname );
  206. wxASSERT( netclass );
  207. netclass->Add( net->GetNetname() );
  208. }
  209. }
  210. // D(printf("stop\n");)
  211. }
  212. #if defined(DEBUG)
  213. void NETCLASS::Show( int nestLevel, std::ostream& os ) const
  214. {
  215. // for now, make it look like XML:
  216. //NestedSpace( nestLevel, os )
  217. os << '<' << GetClass().Lower().mb_str() << ">\n";
  218. for( const_iterator i = begin(); i!=end(); ++i )
  219. {
  220. // NestedSpace( nestLevel+1, os ) << *i;
  221. os << TO_UTF8( *i );
  222. }
  223. // NestedSpace( nestLevel, os )
  224. os << "</" << GetClass().Lower().mb_str() << ">\n";
  225. }
  226. #endif
  227. int NETCLASS::GetTrackMinWidth() const
  228. {
  229. return m_Parent->GetDesignSettings().m_TrackMinWidth;
  230. }
  231. int NETCLASS::GetViaMinDiameter() const
  232. {
  233. return m_Parent->GetDesignSettings().m_ViasMinSize;
  234. }
  235. int NETCLASS::GetViaMinDrill() const
  236. {
  237. return m_Parent->GetDesignSettings().m_ViasMinDrill;
  238. }
  239. int NETCLASS::GetuViaMinDiameter() const
  240. {
  241. return m_Parent->GetDesignSettings().m_MicroViasMinSize;
  242. }
  243. int NETCLASS::GetuViaMinDrill() const
  244. {
  245. return m_Parent->GetDesignSettings().m_MicroViasMinDrill;
  246. }
  247. void NETCLASS::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
  248. throw( IO_ERROR )
  249. {
  250. aFormatter->Print( aNestLevel, "(net_class %s %s\n",
  251. aFormatter->Quotew( GetName() ).c_str(),
  252. aFormatter->Quotew( GetDescription() ).c_str() );
  253. aFormatter->Print( aNestLevel+1, "(clearance %s)\n", FMT_IU( GetClearance() ).c_str() );
  254. aFormatter->Print( aNestLevel+1, "(trace_width %s)\n", FMT_IU( GetTrackWidth() ).c_str() );
  255. aFormatter->Print( aNestLevel+1, "(via_dia %s)\n", FMT_IU( GetViaDiameter() ).c_str() );
  256. aFormatter->Print( aNestLevel+1, "(via_drill %s)\n", FMT_IU( GetViaDrill() ).c_str() );
  257. aFormatter->Print( aNestLevel+1, "(uvia_dia %s)\n", FMT_IU( GetuViaDiameter() ).c_str() );
  258. aFormatter->Print( aNestLevel+1, "(uvia_drill %s)\n", FMT_IU( GetuViaDrill() ).c_str() );
  259. for( NETCLASS::const_iterator it = begin(); it!= end(); ++it )
  260. aFormatter->Print( aNestLevel+1, "(add_net %s)\n", aFormatter->Quotew( *it ).c_str() );
  261. aFormatter->Print( aNestLevel, ")\n\n" );
  262. }