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.

579 lines
18 KiB

11 years ago
* 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
* 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
* 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
* 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
6 years ago
6 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.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 <kiface_i.h>
  27. #include <kiway_express.h>
  28. #include <eda_dde.h>
  29. #include <connection_graph.h>
  30. #include <sch_component.h>
  31. #include <schematic.h>
  32. #include <reporter.h>
  33. #include <netlist_exporters/netlist_exporter_kicad.h>
  34. #include <project/project_file.h>
  35. #include <project/net_settings.h>
  36. #include <tools/ee_actions.h>
  37. #include <tools/reannotate.h>
  38. #include <tools/sch_editor_control.h>
  39. #include <advanced_config.h>
  40. #include <netclass.h>
  41. SCH_ITEM* SCH_EDITOR_CONTROL::FindComponentAndItem( const wxString& aReference,
  42. bool aSearchHierarchy,
  43. SCH_SEARCH_T aSearchType,
  44. const wxString& aSearchText )
  45. {
  46. SCH_SHEET_PATH* sheetWithComponentFound = NULL;
  47. SCH_COMPONENT* component = NULL;
  48. wxPoint pos;
  49. SCH_PIN* pin = nullptr;
  50. SCH_SHEET_LIST sheetList;
  51. SCH_ITEM* foundItem = nullptr;
  52. if( !aSearchHierarchy )
  53. sheetList.push_back( m_frame->GetCurrentSheet() );
  54. else
  55. sheetList.BuildSheetList( &m_frame->Schematic().Root() );
  56. for( SCH_SHEET_PATH& sheet : sheetList )
  57. {
  58. SCH_SCREEN* screen = sheet.LastScreen();
  59. for( auto item : screen->Items().OfType( SCH_COMPONENT_T ) )
  60. {
  61. SCH_COMPONENT* candidate = static_cast<SCH_COMPONENT*>( item );
  62. if( aReference.CmpNoCase( candidate->GetRef( &sheet ) ) == 0 )
  63. {
  64. component = candidate;
  65. sheetWithComponentFound = &sheet;
  66. if( aSearchType == HIGHLIGHT_PIN )
  67. {
  68. pos = component->GetPosition(); // temporary: will be changed if the pin is found.
  69. pin = component->GetPin( aSearchText );
  70. if( pin )
  71. {
  72. pos = pin->GetPosition();
  73. foundItem = component;
  74. break;
  75. }
  76. }
  77. else
  78. {
  79. pos = component->GetPosition();
  80. foundItem = component;
  81. break;
  82. }
  83. }
  84. }
  85. if( foundItem )
  86. break;
  87. }
  88. CROSS_PROBING_SETTINGS& crossProbingSettings = m_frame->eeconfig()->m_CrossProbing;
  89. if( component )
  90. {
  91. if( *sheetWithComponentFound != m_frame->GetCurrentSheet() )
  92. {
  93. m_frame->Schematic().SetCurrentSheet( *sheetWithComponentFound );
  94. m_frame->DisplayCurrentSheet();
  95. }
  96. wxPoint delta;
  97. pos -= component->GetPosition();
  98. delta = component->GetTransform().TransformCoordinate( pos );
  99. pos = delta + component->GetPosition();
  100. if( crossProbingSettings.center_on_items )
  101. {
  102. m_frame->GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( pos, false );
  103. m_frame->CenterScreen( pos, false );
  104. if( crossProbingSettings.zoom_to_fit )
  105. {
  106. // Pass "false" to only include visible fields of component in bbox calculations
  107. EDA_RECT bbox = component->GetBoundingBox( false );
  108. wxSize bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize();
  109. VECTOR2D screenSize = getView()->GetViewport().GetSize();
  110. screenSize.x = std::max( 10.0, screenSize.x );
  111. screenSize.y = std::max( 10.0, screenSize.y );
  112. double ratio = std::max( fabs( bbSize.x / screenSize.x ),
  113. fabs( bbSize.y / screenSize.y ) );
  114. // Try not to zoom on every cross-probe; it gets very noisy
  115. if( ratio < 0.5 || ratio > 1.0 )
  116. getView()->SetScale( getView()->GetScale() / ratio );
  117. }
  118. }
  119. }
  120. /* Print diag */
  121. wxString msg_item;
  122. wxString msg;
  123. if( aSearchType == HIGHLIGHT_PIN )
  124. msg_item.Printf( _( "pin %s" ), aSearchText );
  125. else
  126. msg_item = _( "component" );
  127. if( component )
  128. {
  129. if( foundItem )
  130. msg.Printf( _( "%s %s found" ), aReference, msg_item );
  131. else
  132. msg.Printf( _( "%s found but %s not found" ), aReference, msg_item );
  133. }
  134. else
  135. msg.Printf( _( "Component %s not found" ), aReference );
  136. m_frame->SetStatusText( msg );
  137. m_probingPcbToSch = true; // recursion guard
  138. {
  139. // Clear any existing highlighting
  140. m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
  141. if( foundItem )
  142. m_toolMgr->RunAction( EE_ACTIONS::addItemToSel, true, foundItem );
  143. }
  144. m_probingPcbToSch = false;
  145. m_frame->GetCanvas()->Refresh();
  146. return foundItem;
  147. }
  148. void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
  149. {
  150. SCH_EDITOR_CONTROL* editor = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
  151. char line[1024];
  152. strncpy( line, cmdline, sizeof(line) - 1 );
  153. line[ sizeof(line) - 1 ] = '\0';
  154. char* idcmd = strtok( line, " \n\r" );
  155. char* text = strtok( NULL, "\"\n\r" );
  156. if( idcmd == NULL )
  157. return;
  158. CROSS_PROBING_SETTINGS& crossProbingSettings = eeconfig()->m_CrossProbing;
  159. if( strcmp( idcmd, "$NET:" ) == 0 )
  160. {
  161. if( !crossProbingSettings.auto_highlight )
  162. return;
  163. wxString netName = FROM_UTF8( text );
  164. if( auto sg = Schematic().ConnectionGraph()->FindFirstSubgraphByName( netName ) )
  165. m_highlightedConn = sg->m_driver_connection;
  166. GetToolManager()->RunAction( EE_ACTIONS::updateNetHighlighting, true );
  167. SetStatusText( _( "Selected net: " ) + UnescapeString( netName ) );
  168. return;
  169. }
  170. if( strcmp( idcmd, "$CLEAR:" ) == 0 )
  171. {
  172. // Cross-probing is now done through selection so we no longer need a clear command
  173. return;
  174. }
  175. if( text == NULL )
  176. return;
  177. if( strcmp( idcmd, "$PART:" ) != 0 )
  178. return;
  179. wxString part_ref = FROM_UTF8( text );
  180. /* look for a complement */
  181. idcmd = strtok( NULL, " \n\r" );
  182. if( idcmd == NULL ) // Highlight component only (from Cvpcb or Pcbnew)
  183. {
  184. // Highlight component part_ref, or clear Highlight, if part_ref is not existing
  185. editor->FindComponentAndItem( part_ref, true, HIGHLIGHT_COMPONENT, wxEmptyString );
  186. return;
  187. }
  188. text = strtok( NULL, "\"\n\r" );
  189. if( text == NULL )
  190. return;
  191. wxString msg = FROM_UTF8( text );
  192. if( strcmp( idcmd, "$REF:" ) == 0 )
  193. {
  194. // Highlighting the reference itself isn't actually that useful, and it's harder to
  195. // see. Highlight the parent and display the message.
  196. editor->FindComponentAndItem( part_ref, true, HIGHLIGHT_COMPONENT, msg );
  197. }
  198. else if( strcmp( idcmd, "$VAL:" ) == 0 )
  199. {
  200. // Highlighting the value itself isn't actually that useful, and it's harder to see.
  201. // Highlight the parent and display the message.
  202. editor->FindComponentAndItem( part_ref, true, HIGHLIGHT_COMPONENT, msg );
  203. }
  204. else if( strcmp( idcmd, "$PAD:" ) == 0 )
  205. {
  206. editor->FindComponentAndItem( part_ref, true, HIGHLIGHT_PIN, msg );
  207. }
  208. else
  209. {
  210. editor->FindComponentAndItem( part_ref, true, HIGHLIGHT_COMPONENT, wxEmptyString );
  211. }
  212. }
  213. std::string FormatProbeItem( EDA_ITEM* aItem, SCH_COMPONENT* aComp )
  214. {
  215. // This is a keyword followed by a quoted string.
  216. // Cross probing to Pcbnew if a pin or a component is found
  217. switch( aItem->Type() )
  218. {
  219. case SCH_FIELD_T:
  220. if( aComp )
  221. return StrPrintf( "$PART: \"%s\"", TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
  222. break;
  223. case SCH_COMPONENT_T:
  224. aComp = (SCH_COMPONENT*) aItem;
  225. return StrPrintf( "$PART: \"%s\"", TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
  226. case SCH_SHEET_T:
  227. {
  228. // For cross probing, we need the full path of the sheet, because
  229. // in complex hierarchies the sheet uuid of not unique
  230. SCH_SHEET* sheet = (SCH_SHEET*)aItem;
  231. wxString full_path;
  232. SCH_SHEET* parent = sheet;
  233. while( (parent = dynamic_cast<SCH_SHEET*>( parent->GetParent() ) ) )
  234. {
  235. if( parent->GetParent() ) // The root sheet has no parent and path is just "/"
  236. {
  237. full_path.Prepend( parent->m_Uuid.AsString() );
  238. full_path.Prepend( "/" );
  239. }
  240. }
  241. full_path += "/" + sheet->m_Uuid.AsString();
  242. return StrPrintf( "$SHEET: \"%s\"", TO_UTF8( full_path ) );
  243. }
  244. case SCH_PIN_T:
  245. {
  246. SCH_PIN* pin = (SCH_PIN*) aItem;
  247. aComp = pin->GetParentComponent();
  248. if( !pin->GetNumber().IsEmpty() )
  249. {
  250. return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"",
  251. TO_UTF8( pin->GetNumber() ),
  252. TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
  253. }
  254. else
  255. {
  256. return StrPrintf( "$PART: \"%s\"",
  257. TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
  258. }
  259. }
  260. default:
  261. break;
  262. }
  263. return "";
  264. }
  265. void SCH_EDIT_FRAME::SendMessageToPCBNEW( EDA_ITEM* aObjectToSync, SCH_COMPONENT* aLibItem )
  266. {
  267. wxASSERT( aObjectToSync ); // fix the caller
  268. if( !aObjectToSync )
  269. return;
  270. std::string packet = FormatProbeItem( aObjectToSync, aLibItem );
  271. if( !packet.empty() )
  272. {
  273. if( Kiface().IsSingle() )
  274. SendCommand( MSG_TO_PCB, packet.c_str() );
  275. else
  276. {
  277. // Typically ExpressMail is going to be s-expression packets, but since
  278. // we have existing interpreter of the cross probe packet on the other
  279. // side in place, we use that here.
  280. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_CROSS_PROBE, packet, this );
  281. }
  282. }
  283. }
  284. void SCH_EDIT_FRAME::SendCrossProbeNetName( const wxString& aNetName )
  285. {
  286. // The command is a keyword followed by a quoted string.
  287. std::string packet = StrPrintf( "$NET: \"%s\"", TO_UTF8( aNetName ) );
  288. if( !packet.empty() )
  289. {
  290. if( Kiface().IsSingle() )
  291. SendCommand( MSG_TO_PCB, packet.c_str() );
  292. else
  293. {
  294. // Typically ExpressMail is going to be s-expression packets, but since
  295. // we have existing interpreter of the cross probe packet on the other
  296. // side in place, we use that here.
  297. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_CROSS_PROBE, packet, this );
  298. }
  299. }
  300. }
  301. void SCH_EDIT_FRAME::SetCrossProbeConnection( const SCH_CONNECTION* aConnection )
  302. {
  303. if( !aConnection )
  304. {
  305. SendCrossProbeClearHighlight();
  306. return;
  307. }
  308. if( aConnection->IsNet() )
  309. {
  310. SendCrossProbeNetName( aConnection->Name() );
  311. return;
  312. }
  313. if( aConnection->Members().empty() )
  314. return;
  315. auto all_members = aConnection->AllMembers();
  316. wxString nets = all_members[0]->Name();
  317. if( all_members.size() == 1 )
  318. {
  319. SendCrossProbeNetName( nets );
  320. return;
  321. }
  322. // TODO: This could be replaced by just sending the bus name once we have bus contents
  323. // included as part of the netlist sent from eeschema to pcbnew (and thus pcbnew can
  324. // natively keep track of bus membership)
  325. for( size_t i = 1; i < all_members.size(); i++ )
  326. nets << "," << all_members[i]->Name();
  327. std::string packet = StrPrintf( "$NETS: \"%s\"", TO_UTF8( nets ) );
  328. if( !packet.empty() )
  329. {
  330. if( Kiface().IsSingle() )
  331. SendCommand( MSG_TO_PCB, packet.c_str() );
  332. else
  333. {
  334. // Typically ExpressMail is going to be s-expression packets, but since
  335. // we have existing interpreter of the cross probe packet on the other
  336. // side in place, we use that here.
  337. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_CROSS_PROBE, packet, this );
  338. }
  339. }
  340. }
  341. void SCH_EDIT_FRAME::SendCrossProbeClearHighlight()
  342. {
  343. std::string packet = "$CLEAR\n";
  344. if( Kiface().IsSingle() )
  345. SendCommand( MSG_TO_PCB, packet.c_str() );
  346. else
  347. {
  348. // Typically ExpressMail is going to be s-expression packets, but since
  349. // we have existing interpreter of the cross probe packet on the other
  350. // side in place, we use that here.
  351. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_CROSS_PROBE, packet, this );
  352. }
  353. }
  354. void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
  355. {
  356. std::string& payload = mail.GetPayload();
  357. switch( mail.Command() )
  358. {
  359. case MAIL_CROSS_PROBE:
  360. ExecuteRemoteCommand( payload.c_str() );
  361. break;
  362. case MAIL_SCH_GET_NETLIST:
  363. {
  364. if( payload.find( "quiet-annotate" ) != std::string::npos )
  365. {
  366. Schematic().GetSheets().AnnotatePowerSymbols();
  367. AnnotateComponents( true, UNSORTED, INCREMENTAL_BY_REF, 0, false, false, true,
  368. NULL_REPORTER::GetInstance() );
  369. }
  370. if( payload.find( "no-annotate" ) == std::string::npos )
  371. {
  372. // Ensure schematic is OK for netlist creation (especially that it is fully annotated):
  373. if( !ReadyToNetlist() )
  374. return;
  375. }
  376. NETLIST_EXPORTER_KICAD exporter( &Schematic() );
  377. STRING_FORMATTER formatter;
  378. // TODO remove once real-time connectivity is a given
  379. if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
  380. // Ensure the netlist data is up to date:
  381. RecalculateConnections( NO_CLEANUP );
  382. exporter.Format( &formatter, GNL_ALL | GNL_OPT_KICAD );
  383. payload = formatter.GetString();
  384. }
  385. break;
  386. case MAIL_BACKANNOTATE_FOOTPRINTS:
  387. try
  388. {
  389. SCH_EDITOR_CONTROL* controlTool = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
  390. controlTool->BackAnnotateFootprints( payload );
  391. }
  392. catch( const IO_ERROR& )
  393. {
  394. }
  395. break;
  396. case MAIL_SCH_REFRESH:
  397. {
  398. SCH_SCREENS schematic( Schematic().Root() );
  399. schematic.TestDanglingEnds();
  400. GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
  401. GetCanvas()->Refresh();
  402. }
  403. break;
  404. case MAIL_SCH_CLEAN_NETCLASSES:
  405. {
  406. NET_SETTINGS& netSettings = Prj().GetProjectFile().NetSettings();
  407. netSettings.m_NetClassAssignments.clear();
  408. // Establish the set of nets which is currently valid
  409. for( const wxString& name : Schematic().GetNetClassAssignmentCandidates() )
  410. netSettings.m_NetClassAssignments[ name ] = "Default";
  411. // Copy their netclass assignments, dropping any assignments to non-current nets.
  412. for( auto& ii : netSettings.m_NetClasses )
  413. {
  414. for( const wxString& member : *ii.second )
  415. {
  416. if( netSettings.m_NetClassAssignments.count( member ) )
  417. netSettings.m_NetClassAssignments[ member ] = ii.first;
  418. }
  419. ii.second->Clear();
  420. }
  421. // Update the membership lists to contain only the current nets.
  422. for( const std::pair<const wxString, wxString>& ii : netSettings.m_NetClassAssignments )
  423. {
  424. if( ii.second == "Default" )
  425. continue;
  426. NETCLASSPTR netclass = netSettings.m_NetClasses.Find( ii.second );
  427. if( netclass )
  428. netclass->Add( ii.first );
  429. }
  430. netSettings.ResolveNetClassAssignments();
  431. }
  432. break;
  433. case MAIL_IMPORT_FILE:
  434. {
  435. // Extract file format type and path (plugin type and path separated with \n)
  436. size_t split = payload.find( '\n' );
  437. wxCHECK( split != std::string::npos, /*void*/ );
  438. int importFormat;
  439. try
  440. {
  441. importFormat = std::stoi( payload.substr( 0, split ) );
  442. }
  443. catch( std::invalid_argument& )
  444. {
  445. wxFAIL;
  446. importFormat = -1;
  447. }
  448. std::string path = payload.substr( split + 1 );
  449. wxASSERT( !path.empty() );
  450. if( importFormat >= 0 )
  451. importFile( path, importFormat );
  452. }
  453. break;
  454. case MAIL_SCH_SAVE:
  455. if( SaveProject() )
  456. payload = "success";
  457. break;
  458. case MAIL_SCH_UPDATE:
  459. m_toolManager->RunAction( ACTIONS::updateSchematicFromPcb, true );
  460. break;
  461. case MAIL_REANNOTATE:
  462. //Reannotate the schematic as per the netlist.
  463. ReannotateFromPCBNew( this, payload );
  464. break;
  465. default:;
  466. }
  467. }