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.

679 lines
22 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
* 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-2021 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 <kiface_base.h>
  26. #include <kiway_express.h>
  27. #include <eda_dde.h>
  28. #include <connection_graph.h>
  29. #include <sch_symbol.h>
  30. #include <schematic.h>
  31. #include <reporter.h>
  32. #include <string_utils.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/sch_editor_control.h>
  38. #include <advanced_config.h>
  39. #include <netclass.h>
  40. #include <wx/log.h>
  41. SCH_ITEM* SCH_EDITOR_CONTROL::FindSymbolAndItem( const wxString& aReference,
  42. bool aSearchHierarchy,
  43. SCH_SEARCH_T aSearchType,
  44. const wxString& aSearchText )
  45. {
  46. SCH_SHEET_PATH* sheetWithSymbolFound = nullptr;
  47. SCH_SYMBOL* symbol = nullptr;
  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 = m_frame->Schematic().GetSheets();
  56. for( SCH_SHEET_PATH& sheet : sheetList )
  57. {
  58. SCH_SCREEN* screen = sheet.LastScreen();
  59. for( auto item : screen->Items().OfType( SCH_SYMBOL_T ) )
  60. {
  61. SCH_SYMBOL* candidate = static_cast<SCH_SYMBOL*>( item );
  62. if( aReference.CmpNoCase( candidate->GetRef( &sheet ) ) == 0 )
  63. {
  64. symbol = candidate;
  65. sheetWithSymbolFound = &sheet;
  66. if( aSearchType == HIGHLIGHT_PIN )
  67. {
  68. // temporary: will be changed if the pin is found.
  69. pos = symbol->GetPosition();
  70. pin = symbol->GetPin( aSearchText );
  71. // Ensure we have found the right unit in case of multi-units symbol
  72. if( pin )
  73. {
  74. int unit = pin->GetLibPin()->GetUnit();
  75. if( unit != 0 && unit != symbol->GetUnit() )
  76. {
  77. pin = nullptr;
  78. continue;
  79. }
  80. // Get pin position in true schematic coordinate
  81. pos = pin->GetPosition();
  82. foundItem = pin;
  83. break;
  84. }
  85. }
  86. else
  87. {
  88. pos = symbol->GetPosition();
  89. foundItem = symbol;
  90. break;
  91. }
  92. }
  93. }
  94. if( foundItem )
  95. break;
  96. }
  97. CROSS_PROBING_SETTINGS& crossProbingSettings = m_frame->eeconfig()->m_CrossProbing;
  98. if( symbol )
  99. {
  100. if( *sheetWithSymbolFound != m_frame->GetCurrentSheet() )
  101. {
  102. m_frame->Schematic().SetCurrentSheet( *sheetWithSymbolFound );
  103. m_frame->DisplayCurrentSheet();
  104. }
  105. if( crossProbingSettings.center_on_items )
  106. {
  107. if( crossProbingSettings.zoom_to_fit )
  108. {
  109. EDA_RECT bbox = symbol->GetBoundingBox();
  110. wxSize bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize();
  111. VECTOR2D screenSize = getView()->GetViewport().GetSize();
  112. // This code tries to come up with a zoom factor that doesn't simply zoom in
  113. // to the cross probed symbol, but instead shows a reasonable amount of the
  114. // circuit around it to provide context. This reduces or eliminates the need
  115. // to manually change the zoom because it's too close.
  116. // Using the default text height as a constant to compare against, use the
  117. // height of the bounding box of visible items for a footprint to figure out
  118. // if this is a big symbol (like a processor) or a small symbol (like a resistor).
  119. // This ratio is not useful by itself as a scaling factor. It must be "bent" to
  120. // provide good scaling at varying symbol sizes. Bigger symbols need less
  121. // scaling than small ones.
  122. double currTextHeight = Mils2iu( DEFAULT_TEXT_SIZE );
  123. double compRatio = bbSize.y / currTextHeight; // Ratio of symbol to text height
  124. double compRatioBent = 1.0;
  125. // LUT to scale zoom ratio to provide reasonable schematic context. Must work
  126. // with symbols of varying sizes (e.g. 0402 package and 200 pin BGA).
  127. // "first" is used as the input and "second" as the output
  128. //
  129. // "first" = compRatio (symbol height / default text height)
  130. // "second" = Amount to scale ratio by
  131. std::vector<std::pair<double, double>> lut
  132. {
  133. {1.25, 16}, // 32
  134. {2.5, 12}, //24
  135. {5, 8}, // 16
  136. {6, 6}, //
  137. {10, 4}, //8
  138. {20, 2}, //4
  139. {40, 1.5}, // 2
  140. {100, 1}
  141. };
  142. std::vector<std::pair<double, double>>::iterator it;
  143. // Large symbol default is last LUT entry (1:1).
  144. compRatioBent = lut.back().second;
  145. // Use LUT to do linear interpolation of "compRatio" within "first", then
  146. // use that result to linearly interpolate "second" which gives the scaling
  147. // factor needed.
  148. if( compRatio >= lut.front().first )
  149. {
  150. for( it = lut.begin(); it < lut.end() - 1; it++ )
  151. {
  152. if( it->first <= compRatio && next( it )->first >= compRatio )
  153. {
  154. double diffx = compRatio - it->first;
  155. double diffn = next( it )->first - it->first;
  156. compRatioBent = it->second
  157. + ( next( it )->second - it->second ) * diffx / diffn;
  158. break; // We have our interpolated value
  159. }
  160. }
  161. }
  162. else
  163. {
  164. compRatioBent = lut.front().second; // Small symbol default is first entry
  165. }
  166. // This is similar to the original KiCad code that scaled the zoom to make sure
  167. // symbols were visible on screen. It's simply a ratio of screen size to
  168. // symbol size, and its job is to zoom in to make the component fullscreen.
  169. // Earlier in the code the symbol BBox is given a 20% margin to add some
  170. // breathing room. We compare the height of this enlarged symbol bbox to the
  171. // default text height. If a symbol will end up with the sides clipped, we
  172. // adjust later to make sure it fits on screen.
  173. screenSize.x = std::max( 10.0, screenSize.x );
  174. screenSize.y = std::max( 10.0, screenSize.y );
  175. double ratio = std::max( -1.0, fabs( bbSize.y / screenSize.y ) );
  176. // Original KiCad code for how much to scale the zoom
  177. double kicadRatio = std::max( fabs( bbSize.x / screenSize.x ),
  178. fabs( bbSize.y / screenSize.y ) );
  179. // If the width of the part we're probing is bigger than what the screen width
  180. // will be after the zoom, then punt and use the KiCad zoom algorithm since it
  181. // guarantees the part's width will be encompassed within the screen.
  182. if( bbSize.x > screenSize.x * ratio * compRatioBent )
  183. {
  184. // Use standard KiCad zoom for parts too wide to fit on screen/
  185. ratio = kicadRatio;
  186. compRatioBent = 1.0; // Reset so we don't modify the "KiCad" ratio
  187. wxLogTrace( "CROSS_PROBE_SCALE",
  188. "Part TOO WIDE for screen. Using normal KiCad zoom ratio: %1.5f",
  189. ratio );
  190. }
  191. // Now that "compRatioBent" holds our final scaling factor we apply it to the
  192. // original fullscreen zoom ratio to arrive at the final ratio itself.
  193. ratio *= compRatioBent;
  194. bool alwaysZoom = false; // DEBUG - allows us to minimize zooming or not
  195. // Try not to zoom on every cross-probe; it gets very noisy
  196. if( ( ratio < 0.5 || ratio > 1.0 ) || alwaysZoom )
  197. getView()->SetScale( getView()->GetScale() / ratio );
  198. }
  199. m_frame->FocusOnItem( symbol );
  200. }
  201. }
  202. /* Print diag */
  203. wxString msg;
  204. if( symbol )
  205. {
  206. if( aSearchType == HIGHLIGHT_PIN )
  207. {
  208. if( foundItem )
  209. msg.Printf( _( "%s pin %s found" ), aReference, aSearchText );
  210. else
  211. msg.Printf( _( "%s found but pin %s not found" ), aReference, aSearchText );
  212. }
  213. else
  214. {
  215. msg.Printf( _( "%s found" ), aReference );
  216. }
  217. }
  218. else
  219. {
  220. msg.Printf( _( "%s not found" ), aReference );
  221. }
  222. m_frame->SetStatusText( msg );
  223. m_probingPcbToSch = true; // recursion guard
  224. {
  225. // Clear any existing highlighting
  226. m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
  227. if( foundItem )
  228. m_toolMgr->RunAction( EE_ACTIONS::addItemToSel, true, foundItem );
  229. }
  230. m_probingPcbToSch = false;
  231. m_frame->GetCanvas()->Refresh();
  232. return foundItem;
  233. }
  234. void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
  235. {
  236. SCH_EDITOR_CONTROL* editor = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
  237. char line[1024];
  238. strncpy( line, cmdline, sizeof( line ) - 1 );
  239. line[ sizeof( line ) - 1 ] = '\0';
  240. char* idcmd = strtok( line, " \n\r" );
  241. char* text = strtok( nullptr, "\"\n\r" );
  242. if( idcmd == nullptr )
  243. return;
  244. CROSS_PROBING_SETTINGS& crossProbingSettings = eeconfig()->m_CrossProbing;
  245. if( strcmp( idcmd, "$NET:" ) == 0 )
  246. {
  247. if( !crossProbingSettings.auto_highlight )
  248. return;
  249. wxString netName = FROM_UTF8( text );
  250. if( auto sg = Schematic().ConnectionGraph()->FindFirstSubgraphByName( netName ) )
  251. m_highlightedConn = sg->m_driver_connection;
  252. else
  253. m_highlightedConn = nullptr;
  254. GetToolManager()->RunAction( EE_ACTIONS::updateNetHighlighting, true );
  255. SetStatusText( _( "Selected net:" ) + wxS( " " ) + UnescapeString( netName ) );
  256. return;
  257. }
  258. if( strcmp( idcmd, "$CLEAR:" ) == 0 )
  259. {
  260. // Cross-probing is now done through selection so we no longer need a clear command
  261. return;
  262. }
  263. if( text == nullptr )
  264. return;
  265. if( strcmp( idcmd, "$PART:" ) != 0 )
  266. return;
  267. wxString part_ref = FROM_UTF8( text );
  268. /* look for a complement */
  269. idcmd = strtok( nullptr, " \n\r" );
  270. if( idcmd == nullptr ) // Highlight symbol only (from CvPcb or Pcbnew)
  271. {
  272. // Highlight symbol part_ref, or clear Highlight, if part_ref is not existing
  273. editor->FindSymbolAndItem( part_ref, true, HIGHLIGHT_SYMBOL, wxEmptyString );
  274. return;
  275. }
  276. text = strtok( nullptr, "\"\n\r" );
  277. if( text == nullptr )
  278. return;
  279. wxString msg = FROM_UTF8( text );
  280. if( strcmp( idcmd, "$REF:" ) == 0 )
  281. {
  282. // Highlighting the reference itself isn't actually that useful, and it's harder to
  283. // see. Highlight the parent and display the message.
  284. editor->FindSymbolAndItem( part_ref, true, HIGHLIGHT_SYMBOL, msg );
  285. }
  286. else if( strcmp( idcmd, "$VAL:" ) == 0 )
  287. {
  288. // Highlighting the value itself isn't actually that useful, and it's harder to see.
  289. // Highlight the parent and display the message.
  290. editor->FindSymbolAndItem( part_ref, true, HIGHLIGHT_SYMBOL, msg );
  291. }
  292. else if( strcmp( idcmd, "$PAD:" ) == 0 )
  293. {
  294. editor->FindSymbolAndItem( part_ref, true, HIGHLIGHT_PIN, msg );
  295. }
  296. else
  297. {
  298. editor->FindSymbolAndItem( part_ref, true, HIGHLIGHT_SYMBOL, wxEmptyString );
  299. }
  300. }
  301. std::string FormatProbeItem( EDA_ITEM* aItem, SCH_SYMBOL* aSymbol )
  302. {
  303. // This is a keyword followed by a quoted string.
  304. // Cross probing to Pcbnew if a pin or a symbol is found.
  305. switch( aItem->Type() )
  306. {
  307. case SCH_FIELD_T:
  308. if( aSymbol )
  309. {
  310. return StrPrintf( "$PART: \"%s\"",
  311. TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
  312. }
  313. break;
  314. case SCH_SYMBOL_T:
  315. aSymbol = (SCH_SYMBOL*) aItem;
  316. return StrPrintf( "$PART: \"%s\"",
  317. TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
  318. case SCH_SHEET_T:
  319. {
  320. // For cross probing, we need the full path of the sheet, because
  321. // in complex hierarchies the sheet uuid of not unique
  322. SCH_SHEET* sheet = (SCH_SHEET*)aItem;
  323. wxString full_path;
  324. SCH_SHEET* parent = sheet;
  325. while( (parent = dynamic_cast<SCH_SHEET*>( parent->GetParent() ) ) )
  326. {
  327. if( parent->GetParent() ) // The root sheet has no parent and path is just "/"
  328. {
  329. full_path.Prepend( parent->m_Uuid.AsString() );
  330. full_path.Prepend( "/" );
  331. }
  332. }
  333. full_path += "/" + sheet->m_Uuid.AsString();
  334. return StrPrintf( "$SHEET: \"%s\"", TO_UTF8( full_path ) );
  335. }
  336. case SCH_PIN_T:
  337. {
  338. SCH_PIN* pin = (SCH_PIN*) aItem;
  339. aSymbol = pin->GetParentSymbol();
  340. if( !pin->GetShownNumber().IsEmpty() )
  341. {
  342. return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"",
  343. TO_UTF8( pin->GetShownNumber() ),
  344. TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
  345. }
  346. else
  347. {
  348. return StrPrintf( "$PART: \"%s\"",
  349. TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
  350. }
  351. }
  352. default:
  353. break;
  354. }
  355. return "";
  356. }
  357. void SCH_EDIT_FRAME::SendMessageToPCBNEW( EDA_ITEM* aObjectToSync, SCH_SYMBOL* aLibItem )
  358. {
  359. wxASSERT( aObjectToSync ); // fix the caller
  360. if( !aObjectToSync )
  361. return;
  362. std::string packet = FormatProbeItem( aObjectToSync, aLibItem );
  363. if( !packet.empty() )
  364. {
  365. if( Kiface().IsSingle() )
  366. {
  367. SendCommand( MSG_TO_PCB, packet );
  368. }
  369. else
  370. {
  371. // Typically ExpressMail is going to be s-expression packets, but since
  372. // we have existing interpreter of the cross probe packet on the other
  373. // side in place, we use that here.
  374. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_CROSS_PROBE, packet, this );
  375. }
  376. }
  377. }
  378. void SCH_EDIT_FRAME::SendCrossProbeNetName( const wxString& aNetName )
  379. {
  380. // The command is a keyword followed by a quoted string.
  381. std::string packet = StrPrintf( "$NET: \"%s\"", TO_UTF8( aNetName ) );
  382. if( !packet.empty() )
  383. {
  384. if( Kiface().IsSingle() )
  385. {
  386. SendCommand( MSG_TO_PCB, packet );
  387. }
  388. else
  389. {
  390. // Typically ExpressMail is going to be s-expression packets, but since
  391. // we have existing interpreter of the cross probe packet on the other
  392. // side in place, we use that here.
  393. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_CROSS_PROBE, packet, this );
  394. }
  395. }
  396. }
  397. void SCH_EDIT_FRAME::SetCrossProbeConnection( const SCH_CONNECTION* aConnection )
  398. {
  399. if( !aConnection )
  400. {
  401. SendCrossProbeClearHighlight();
  402. return;
  403. }
  404. if( aConnection->IsNet() )
  405. {
  406. SendCrossProbeNetName( aConnection->Name() );
  407. return;
  408. }
  409. if( aConnection->Members().empty() )
  410. return;
  411. auto all_members = aConnection->AllMembers();
  412. wxString nets = all_members[0]->Name();
  413. if( all_members.size() == 1 )
  414. {
  415. SendCrossProbeNetName( nets );
  416. return;
  417. }
  418. // TODO: This could be replaced by just sending the bus name once we have bus contents
  419. // included as part of the netlist sent from Eeschema to Pcbnew (and thus Pcbnew can
  420. // natively keep track of bus membership)
  421. for( size_t i = 1; i < all_members.size(); i++ )
  422. nets << "," << all_members[i]->Name();
  423. std::string packet = StrPrintf( "$NETS: \"%s\"", TO_UTF8( nets ) );
  424. if( !packet.empty() )
  425. {
  426. if( Kiface().IsSingle() )
  427. SendCommand( MSG_TO_PCB, packet );
  428. else
  429. {
  430. // Typically ExpressMail is going to be s-expression packets, but since
  431. // we have existing interpreter of the cross probe packet on the other
  432. // side in place, we use that here.
  433. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_CROSS_PROBE, packet, this );
  434. }
  435. }
  436. }
  437. void SCH_EDIT_FRAME::SendCrossProbeClearHighlight()
  438. {
  439. std::string packet = "$CLEAR\n";
  440. if( Kiface().IsSingle() )
  441. {
  442. SendCommand( MSG_TO_PCB, packet );
  443. }
  444. else
  445. {
  446. // Typically ExpressMail is going to be s-expression packets, but since
  447. // we have existing interpreter of the cross probe packet on the other
  448. // side in place, we use that here.
  449. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_CROSS_PROBE, packet, this );
  450. }
  451. }
  452. void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
  453. {
  454. std::string& payload = mail.GetPayload();
  455. switch( mail.Command() )
  456. {
  457. case MAIL_CROSS_PROBE:
  458. ExecuteRemoteCommand( payload.c_str() );
  459. break;
  460. case MAIL_SCH_GET_NETLIST:
  461. {
  462. if( !payload.empty() )
  463. {
  464. wxString annotationMessage( payload );
  465. // Ensure schematic is OK for netlist creation (especially that it is fully annotated):
  466. if( !ReadyToNetlist( annotationMessage ) )
  467. return;
  468. }
  469. NETLIST_EXPORTER_KICAD exporter( &Schematic() );
  470. STRING_FORMATTER formatter;
  471. // TODO remove once real-time connectivity is a given
  472. if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
  473. // Ensure the netlist data is up to date:
  474. RecalculateConnections( NO_CLEANUP );
  475. exporter.Format( &formatter, GNL_ALL | GNL_OPT_KICAD );
  476. payload = formatter.GetString();
  477. }
  478. break;
  479. case MAIL_ASSIGN_FOOTPRINTS:
  480. try
  481. {
  482. SCH_EDITOR_CONTROL* controlTool = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
  483. controlTool->AssignFootprints( payload );
  484. }
  485. catch( const IO_ERROR& )
  486. {
  487. }
  488. break;
  489. case MAIL_SCH_REFRESH:
  490. {
  491. TestDanglingEnds();
  492. GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
  493. GetCanvas()->Refresh();
  494. }
  495. break;
  496. case MAIL_SCH_CLEAN_NETCLASSES:
  497. {
  498. NET_SETTINGS& netSettings = Prj().GetProjectFile().NetSettings();
  499. netSettings.m_NetClassAssignments.clear();
  500. // Establish the set of nets which is currently valid
  501. for( const wxString& name : Schematic().GetNetClassAssignmentCandidates() )
  502. netSettings.m_NetClassAssignments[ name ] = "Default";
  503. // Copy their netclass assignments, dropping any assignments to non-current nets.
  504. for( auto& ii : netSettings.m_NetClasses )
  505. {
  506. for( const wxString& member : *ii.second )
  507. {
  508. if( netSettings.m_NetClassAssignments.count( member ) )
  509. netSettings.m_NetClassAssignments[ member ] = ii.first;
  510. }
  511. ii.second->Clear();
  512. }
  513. // Update the membership lists to contain only the current nets.
  514. for( const std::pair<const wxString, wxString>& ii : netSettings.m_NetClassAssignments )
  515. {
  516. if( ii.second == "Default" )
  517. continue;
  518. NETCLASSPTR netclass = netSettings.m_NetClasses.Find( ii.second );
  519. if( netclass )
  520. netclass->Add( ii.first );
  521. }
  522. }
  523. break;
  524. case MAIL_IMPORT_FILE:
  525. {
  526. // Extract file format type and path (plugin type and path separated with \n)
  527. size_t split = payload.find( '\n' );
  528. wxCHECK( split != std::string::npos, /*void*/ );
  529. int importFormat;
  530. try
  531. {
  532. importFormat = std::stoi( payload.substr( 0, split ) );
  533. }
  534. catch( std::invalid_argument& )
  535. {
  536. wxFAIL;
  537. importFormat = -1;
  538. }
  539. std::string path = payload.substr( split + 1 );
  540. wxASSERT( !path.empty() );
  541. if( importFormat >= 0 )
  542. importFile( path, importFormat );
  543. }
  544. break;
  545. case MAIL_SCH_SAVE:
  546. if( SaveProject() )
  547. payload = "success";
  548. break;
  549. case MAIL_SCH_UPDATE:
  550. m_toolManager->RunAction( ACTIONS::updateSchematicFromPcb, true );
  551. break;
  552. default:;
  553. }
  554. }