22#include <wx/tokenzr.h>
24#include <api/common/commands/cross_probe_commands.pb.h>
60 const wxString& aSearchText )
68 if( !aSearchHierarchy )
69 sheetList.push_back(
m_frame->GetCurrentSheet() );
71 sheetList =
m_frame->Schematic().Hierarchy();
87 found = ( *aPath ==
path );
91 found = ( aReference && aReference->CmpNoCase( candidate->
GetRef( &sheet ) ) == 0 );
97 sheetWithSymbolFound = &sheet;
107 m_frame->Schematic().GetCurrentVariant() );
112 int unit =
pin->GetLibPin()->GetUnit();
114 if( unit != 0 && unit != symbol->
GetUnit() )
141 if( *sheetWithSymbolFound !=
m_frame->GetCurrentSheet() )
144 sheetWithSymbolFound );
159 m_frame->FocusOnItem( symbol );
168 displayRef = *aReference;
177 msg.Printf(
_(
"%s pin %s found" ), displayRef, aSearchText );
179 msg.Printf(
_(
"%s found but pin %s not found" ), displayRef, aSearchText );
183 msg.Printf(
_(
"%s found" ), displayRef );
188 msg.Printf(
_(
"%s not found" ), displayRef );
192 m_frame->GetCanvas()->Refresh();
226 strncpy( line, cmdline,
sizeof( line ) - 1 );
227 line[
sizeof( line ) - 1 ] =
'\0';
229 char* idcmd = strtok( line,
" \n\r" );
230 char*
text = strtok(
nullptr,
"\"\n\r" );
232 if( idcmd ==
nullptr )
237 if( strcmp( idcmd,
"$CONFIG" ) == 0 )
242 else if( strcmp( idcmd,
"$ERC" ) == 0 )
247 else if( strcmp( idcmd,
"$NET:" ) == 0 )
255 else if( strcmp( idcmd,
"$CLEAR:" ) == 0 )
264 if(
text ==
nullptr )
267 if( strcmp( idcmd,
"$PART:" ) != 0 )
273 idcmd = strtok(
nullptr,
" \n\r" );
275 if( idcmd ==
nullptr )
282 text = strtok(
nullptr,
"\"\n\r" );
284 if(
text ==
nullptr )
289 if( strcmp( idcmd,
"$REF:" ) == 0 )
295 else if( strcmp( idcmd,
"$VAL:" ) == 0 )
301 else if( strcmp( idcmd,
"$PAD:" ) == 0 )
329 kiapi::common::commands::SyncSelection sync;
333 switch( item->Type() )
338 kiapi::common::commands::SelectionSpec* spec = sync.add_items();
348 path.push_back( item->m_Uuid );
350 kiapi::common::commands::SelectionSpec* spec = sync.add_items();
367 kiapi::common::commands::SelectionSpec* spec = sync.add_items();
368 spec->mutable_pad()->set_reference( ref.ToUTF8() );
369 spec->mutable_pad()->set_number(
pad.ToUTF8() );
380 if( sync.items_size() == 0 )
383 sync.set_context( aForce ? commands::SyncSelectionContext::SSC_EXPLICIT
384 : commands::SyncSelectionContext::SSC_IMPLICIT );
416 kiapi::common::commands::HighlightNets message;
418 message.add_net_name( aNetName.ToUTF8() );
433 kiapi::common::commands::HighlightNets message;
435 for(
const wxString&
name : names )
436 message.add_net_name(
name.ToUTF8() );
456 std::stringstream ss( payload );
464 wxCHECK_RET( optTable.has_value(),
"Could not load symbol lib table." );
470 std::string srcProjDir;
471 std::getline( ss, srcProjDir,
'\n' );
473 std::vector<wxString> toLoad;
475 while( std::getline( ss, file,
'\n' ) )
480 wxFileName fn( file );
484 if( type == SCH_IO_MGR::SCH_FILE_UNKNOWN )
486 wxLogTrace(
"KIWAY",
"Unknown file type: %s", fn.GetFullPath() );
490 pi.reset( SCH_IO_MGR::FindPlugin( type ) );
492 wxString libTableUri;
493 bool isProjectLocal = fn.GetFullPath().StartsWith( wxString( srcProjDir ) );
499 if( !fn.FileExists() )
502 wxFileName projectFn( projectPath, fn.GetFullName() );
504 if( fn.GetFullPath() != projectFn.GetFullPath() && !projectFn.FileExists() )
505 wxCopyFile( fn.GetFullPath(), projectFn.GetFullPath() );
507 libTableUri = wxS(
"${KIPRJMOD}/" ) + fn.GetFullName();
512 libTableUri = fn.GetFullPath();
515 if( !
table->HasRow( fn.GetName() ) )
519 row.
SetURI( libTableUri );
521 toLoad.emplace_back( fn.GetName() );
525 if( !toLoad.empty() )
529 table->Save().map_error(
532 wxLogError( wxT(
"Error saving project library table:\n\n" ) + aError.
message );
541 std::ranges::for_each( toLoad,
542 [adapter](
const wxString& aNick )
559 if( ApiRequest request; request.ParseFromString( payload.c_str() ) )
566 if( !payload.empty() )
568 wxString annotationMessage( payload );
571 bool userCancelled =
false;
599 KIID uuid( payload );
607 payload =
static_cast<SCH_SYMBOL*
>( item )->GetRef( &
path,
true );
609 payload = item->GetFriendlyName();
639 std::stringstream ss( payload );
642 std::string formatStr;
643 wxCHECK( std::getline( ss, formatStr, delim ), );
645 std::string fnameStr;
646 wxCHECK( std::getline( ss, fnameStr, delim ), );
652 importFormat = std::stoi( formatStr );
654 catch( std::invalid_argument& )
660 std::map<std::string, UTF8> props;
664 std::string key, value;
666 if( !std::getline( ss, key, delim ) )
669 std::getline( ss, value, delim );
671 props.emplace( key, value );
677 if( importFormat >= 0 &&
importFile( fnameStr, importFormat, props.empty() ?
nullptr : &props )
678 && importFormat == SCH_IO_MGR::SCH_ORCAD )
681 std::map<wxString, wxString> names;
722 wxString targetFile( payload );
728 if( screen && screen->
GetFileName() == targetFile )
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION showSymbolLibTable
static TOOL_ACTION updateSchematicFromPcb
CROSS_PROBING_SETTINGS m_CrossProbing
static bool SendToFrame(FRAME_T aTarget, const google::protobuf::Message &aRequest)
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
EE_TYPE OfType(KICAD_T aType) const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
wxString AsString() const
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
std::string & GetPayload()
Return the payload, which can be any text but it typically self identifying s-expression.
MAIL_T Command()
Returns the MAIL_T associated with this mail.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
std::vector< KI_ERROR > GetLibraryLoadErrors() const
Returns all library load errors as newline-separated strings for display.
std::optional< LIBRARY_TABLE * > Table(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope)
Retrieves a given table; creating a new empty project table if a valid project is loaded and the give...
void AbortAsyncLoads()
Abort any async library loading operations in progress.
void LoadProjectTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the project library tables in the given list, or all tables if no list is given
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
static LOAD_INFO_REPORTER & GetInstance()
void SetKiway(KIWAY *aKiway)
Generate the KiCad netlist format supported by Pcbnew.
void Format(OUTPUTFORMATTER *aOutputFormatter, int aCtl)
Output this s-expression netlist into aOutputFormatter.
virtual LIBRARY_MANAGER & GetLibraryManager() const
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
virtual const wxString GetProjectPath() const
Return the full path of the project.
const IMPORT_NET_MAP * GetImportNetMap() const
static TOOL_ACTION runERC
Inspection and Editing.
static TOOL_ACTION changeSheet
static TOOL_ACTION updateNetHighlighting
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SyncView()
Mark all items for refresh.
EESCHEMA_SETTINGS * eeconfig() const
Net membership for one UI operation.
bool HasNet(const wxString &aName) const
std::vector< wxString > SignalNames(const wxString &aName) const
Signal itself or leaf signals of a bus, suitable for PCB cross-probing.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void AssignFootprints(const std::string &aChangedSetOfReferences)
SCH_ITEM * FindSymbolAndItem(const wxString *aPath, const wxString *aReference, bool aSearchHierarchy, SCH_SEARCH_T aSearchType, const wxString &aSearchText)
Find a symbol in the schematic and an item in this symbol and select it.
Schematic editor (Eeschema) main window.
std::unique_ptr< API_HANDLER_SCH > m_apiHandler
void RefreshConnectivity(bool aForce=false)
Refresh connectivity-dependent display state after a model rebuild.
friend class SCH_EDITOR_CONTROL
void SendSelectItemsToPcb(const std::vector< EDA_ITEM * > &aItems, bool aForce)
Send items to board editor for selection.
bool ReadyToNetlist(const wxString &aAnnotateMessage, bool *aUserCancelled=nullptr)
Check if we are ready to write a netlist file for the current schematic.
void SendCrossProbeClearHighlight()
Tell Pcbnew to clear the existing highlighted net, if one exists.
SCHEMATIC * m_schematic
The currently loaded schematic.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void ExecuteRemoteCommand(const char *cmdline) override
Execute a remote command sent via a socket on port KICAD_SCH_PORT_SERVICE_NUMBER (which defaults to 4...
void PrepareForNetlist()
Commit source cleanup before the exporter's full connectivity rebuild.
SCH_DESIGN_BLOCK_PANE * m_designBlocksPane
bool importFile(const wxString &aFileName, int aFileType, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load the given filename but sets the path to the current project path.
void SendCrossProbeNetName(const wxString &aNetName)
Send a net name to Pcbnew for highlighting.
void KiwayMailIn(KIWAY_MAIL_EVENT &aEvent) override
Receive #KIWAY_ROUTED_EVENT messages from other players.
void SetHighlightedConnection(const wxString &aConnection, const NET_NAVIGATOR_ITEM_DATA *aSelection=nullptr, bool aForceNetNavigatorRefresh=false)
void SetHighlightedNetChain(const wxString &aNetChain)
void SetCrossProbeConnection(const wxString &aName)
Send a connection (net or bus) to Pcbnew for highlighting.
void UpdateNetHighlightStatus()
void HandleRemoteNetHighlight(const wxString &aNetName)
wxString m_highlightedConn
The highlighted net or bus or empty string.
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
bool SaveProject(bool aSaveAs=false)
Save the currently-open schematic (including its hierarchy) and associated project.
virtual const wxString & GetText() const override
Return the string associated with the text object.
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
Base class for any item which can be embedded within the SCHEMATIC container class,...
A net chain is a collection of nets that are connected together through passive components.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
const wxString & GetFileName() const
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
SCH_PIN * GetPinByEffectivePadNumber(const wxString &aPadNumber, const SCH_SHEET_PATH *aSheet, const wxString &aVariantName=wxEmptyString) const
Find the pin whose effective footprint pad number (issue #2282) is aPadNumber on aSheet,...
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
Loads or reloads the given library, if it exists.
A base class for LIB_SYMBOL and SCH_SYMBOL.
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
static void sendHighlightNets(SCH_EDIT_FRAME *aFrame, const kiapi::common::commands::HighlightNets &aMessage)
@ FRAME_SCH_SYMBOL_EDITOR
std::map< wxString, wxString > GetBoardNetNameMap(const IMPORT_NET_MAP &aMap, REPORTER &aReporter)
Reduce the map to the board net renames it justifies.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
@ MAIL_SCH_NAVIGATE_TO_SHEET
#define MAIL_SCH_GET_NETLIST_CANCELLED
Reply payload for MAIL_SCH_GET_NETLIST when the user deliberately aborts netlist generation (for exam...
wxString JoinNetNameMap(const std::map< wxString, wxString > &aNames)
Encode source-to-imported net names as a single property value.
@ ALL
All except INITIAL_ADD.
KICOMMON_API void PackSheetPath(types::SheetPath &aOutput, const KIID_PATH &aInput)
KICOMMON_API bool PackKiwayApiMessage(const google::protobuf::Message &aMessage, std::string &aBytes)
PGM_BASE & Pgm()
The global program "get" accessor.
SCH_SEARCH_T
Schematic search type used by the socket link with Pcbnew.
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< wxString > ExpandStackedPinNotation(const wxString &aPinName, bool *aValid)
Expand stacked pin notation like [1,2,3], [1-4], [A1-A4], or [AA1-AA3,AB4,CD12-CD14] into individual ...
wxString From_UTF8(const char *cstring)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
bool on_selection
Synchronize the selection for multiple items too.
bool zoom_to_fit
Zoom to fit items (ignored if center_on_items is off).
bool center_on_items
Automatically pan to cross-probed items.
bool auto_highlight
Automatically turn on highlight mode in the target frame.
Import provenance, held only for the lifetime of the importing SCHEMATIC.
@ REFERENCE
Field Reference of part, i.e. "IC21".
const SHAPE_LINE_CHAIN chain
wxLogTrace helper definitions.