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.

245 lines
8.1 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /**
  2. * @file pcbnew/netlist.cpp
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 1992-2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
  8. * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  9. * Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@verizon.net>
  10. * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, you may find one here:
  24. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  25. * or you may search the http://www.gnu.org website for the version 2 license,
  26. * or you may write to the Free Software Foundation, Inc.,
  27. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  28. */
  29. #include <functional>
  30. using namespace std::placeholders;
  31. #include <fctsys.h>
  32. #include <pgm_base.h>
  33. #include <class_draw_panel_gal.h>
  34. #include <confirm.h>
  35. #include <dialog_helpers.h>
  36. #include <pcb_edit_frame.h>
  37. #include <pcb_netlist.h>
  38. #include <netlist_reader.h>
  39. #include <reporter.h>
  40. #include <wildcards_and_files_ext.h>
  41. #include <lib_id.h>
  42. #include <fp_lib_table.h>
  43. #include <class_board.h>
  44. #include <class_module.h>
  45. #include <ratsnest_data.h>
  46. #include <pcbnew.h>
  47. #include <io_mgr.h>
  48. #include <board_netlist_updater.h>
  49. #include <tool/tool_manager.h>
  50. #include <tools/pcb_actions.h>
  51. #include <tools/selection_tool.h>
  52. #include <view/view.h>
  53. bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename,
  54. NETLIST& aNetlist,
  55. REPORTER& aReporter )
  56. {
  57. wxString msg;
  58. try
  59. {
  60. std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
  61. &aNetlist, aFilename, wxEmptyString ) );
  62. if( !netlistReader.get() )
  63. {
  64. msg.Printf( _( "Cannot open netlist file \"%s\"." ), GetChars( aFilename ) );
  65. wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this );
  66. return false;
  67. }
  68. SetLastNetListRead( aFilename );
  69. netlistReader->LoadNetlist();
  70. LoadFootprints( aNetlist, aReporter );
  71. }
  72. catch( const IO_ERROR& ioe )
  73. {
  74. msg.Printf( _( "Error loading netlist.\n%s" ), ioe.What().GetData() );
  75. wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
  76. return false;
  77. }
  78. SetLastNetListRead( aFilename );
  79. return true;
  80. }
  81. void PCB_EDIT_FRAME::OnNetlistChanged( BOARD_NETLIST_UPDATER& aUpdater,
  82. bool* aRunDragCommand )
  83. {
  84. BOARD* board = GetBoard();
  85. SetMsgPanel( board );
  86. // Update rendered tracks and vias net labels
  87. auto view = GetGalCanvas()->GetView();
  88. // TODO is there a way to extract information about which nets were modified?
  89. for( auto track : board->Tracks() )
  90. view->Update( track );
  91. std::vector<MODULE*> newFootprints = aUpdater.GetAddedComponents();
  92. // Spread new footprints.
  93. wxPoint areaPosition = GetCrossHairPosition();
  94. EDA_RECT bbox = board->GetBoundingBox();
  95. GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
  96. SpreadFootprints( &newFootprints, false, false, areaPosition, false );
  97. // Start drag command for new modules
  98. if( !newFootprints.empty() )
  99. {
  100. for( MODULE* footprint : newFootprints )
  101. GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, footprint );
  102. *aRunDragCommand = true;
  103. // Now fix a reference point to move the footprints.
  104. // We use the first footprint in list as reference point
  105. // The graphic cursor will be on this fp when moving the footprints.
  106. SELECTION_TOOL* selTool = GetToolManager()->GetTool<SELECTION_TOOL>();
  107. SELECTION& selection = selTool->GetSelection();
  108. selection.SetReferencePoint( newFootprints[0]->GetPosition() );
  109. }
  110. GetGalCanvas()->Refresh();
  111. }
  112. #define ALLOW_PARTIAL_FPID 1
  113. void PCB_EDIT_FRAME::LoadFootprints( NETLIST& aNetlist, REPORTER& aReporter )
  114. {
  115. wxString msg;
  116. LIB_ID lastFPID;
  117. COMPONENT* component;
  118. MODULE* module = 0;
  119. MODULE* fpOnBoard;
  120. if( aNetlist.IsEmpty() || Prj().PcbFootprintLibs()->IsEmpty() )
  121. return;
  122. aNetlist.SortByFPID();
  123. for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ )
  124. {
  125. component = aNetlist.GetComponent( ii );
  126. #if ALLOW_PARTIAL_FPID
  127. // The FPID is ok as long as there is a footprint portion coming
  128. // from eeschema.
  129. if( !component->GetFPID().GetLibItemName().size() )
  130. #else
  131. if( component->GetFPID().empty() )
  132. #endif
  133. {
  134. msg.Printf( _( "No footprint defined for symbol \"%s\".\n" ),
  135. component->GetReference() );
  136. aReporter.Report( msg, REPORTER::RPT_ERROR );
  137. continue;
  138. }
  139. // Check if component footprint is already on BOARD and only load the footprint from
  140. // the library if it's needed. Nickname can be blank.
  141. if( aNetlist.IsFindByTimeStamp() )
  142. fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetTimeStamp(), true );
  143. else
  144. fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetReference() );
  145. bool footprintMisMatch = fpOnBoard && fpOnBoard->GetFPID() != component->GetFPID();
  146. if( footprintMisMatch && !aNetlist.GetReplaceFootprints() )
  147. {
  148. msg.Printf( _( "Footprint of %s changed: board footprint \"%s\", netlist footprint \"%s\"." ),
  149. component->GetReference(),
  150. GetChars( fpOnBoard->GetFPID().Format() ),
  151. GetChars( component->GetFPID().Format() ) );
  152. aReporter.Report( msg, REPORTER::RPT_WARNING );
  153. continue;
  154. }
  155. if( !aNetlist.GetReplaceFootprints() )
  156. footprintMisMatch = false;
  157. if( fpOnBoard && !footprintMisMatch ) // nothing else to do here
  158. continue;
  159. if( component->GetFPID() != lastFPID )
  160. {
  161. module = NULL;
  162. #if ALLOW_PARTIAL_FPID
  163. // The LIB_ID is ok as long as there is a footprint portion coming
  164. // the library if it's needed. Nickname can be blank.
  165. if( !component->GetFPID().GetLibItemName().size() )
  166. #else
  167. if( !component->GetFPID().IsValid() )
  168. #endif
  169. {
  170. msg.Printf( _( "%s footprint ID \"%s\" is not valid." ),
  171. component->GetReference(),
  172. GetChars( component->GetFPID().Format() ) );
  173. aReporter.Report( msg, REPORTER::RPT_ERROR );
  174. continue;
  175. }
  176. // loadFootprint() can find a footprint with an empty nickname in fpid.
  177. module = PCB_BASE_FRAME::loadFootprint( component->GetFPID() );
  178. if( module )
  179. {
  180. lastFPID = component->GetFPID();
  181. }
  182. else
  183. {
  184. msg.Printf( _( "%s footprint \"%s\" not found in any libraries in the footprint library table.\n" ),
  185. component->GetReference(),
  186. GetChars( component->GetFPID().GetLibItemName() ) );
  187. aReporter.Report( msg, REPORTER::RPT_ERROR );
  188. continue;
  189. }
  190. }
  191. else
  192. {
  193. // Footprint already loaded from a library, duplicate it (faster)
  194. if( module == NULL )
  195. continue; // Module does not exist in any library.
  196. module = new MODULE( *module );
  197. }
  198. if( module )
  199. component->SetModule( module );
  200. }
  201. }