22#include <wx/tokenzr.h>
24#include <api/common/commands/cross_probe_commands.pb.h>
62 const wxString& aSearchText )
70 if( !aSearchHierarchy )
71 sheetList.push_back(
m_frame->GetCurrentSheet() );
73 sheetList =
m_frame->Schematic().Hierarchy();
89 found = ( *aPath ==
path );
93 found = ( aReference && aReference->CmpNoCase( candidate->
GetRef( &sheet ) ) == 0 );
99 sheetWithSymbolFound = &sheet;
109 m_frame->Schematic().GetCurrentVariant() );
114 int unit =
pin->GetLibPin()->GetUnit();
143 if( *sheetWithSymbolFound !=
m_frame->GetCurrentSheet() )
146 sheetWithSymbolFound );
161 m_frame->FocusOnItem( symbol );
170 displayRef = *aReference;
179 msg.Printf(
_(
"%s pin %s found" ), displayRef, aSearchText );
181 msg.Printf(
_(
"%s found but pin %s not found" ), displayRef, aSearchText );
185 msg.Printf(
_(
"%s found" ), displayRef );
190 msg.Printf(
_(
"%s not found" ), displayRef );
194 m_frame->GetCanvas()->Refresh();
228 strncpy( line, cmdline,
sizeof( line ) - 1 );
229 line[
sizeof( line ) - 1 ] =
'\0';
231 char* idcmd = strtok( line,
" \n\r" );
232 char*
text = strtok(
nullptr,
"\"\n\r" );
234 if( idcmd ==
nullptr )
239 if( strcmp( idcmd,
"$CONFIG" ) == 0 )
244 else if( strcmp( idcmd,
"$ERC" ) == 0 )
249 else if( strcmp( idcmd,
"$NET:" ) == 0 )
257 else if( strcmp( idcmd,
"$CLEAR:" ) == 0 )
266 if(
text ==
nullptr )
269 if( strcmp( idcmd,
"$PART:" ) != 0 )
275 idcmd = strtok(
nullptr,
" \n\r" );
277 if( idcmd ==
nullptr )
284 text = strtok(
nullptr,
"\"\n\r" );
286 if(
text ==
nullptr )
291 if( strcmp( idcmd,
"$REF:" ) == 0 )
297 else if( strcmp( idcmd,
"$VAL:" ) == 0 )
303 else if( strcmp( idcmd,
"$PAD:" ) == 0 )
331 kiapi::common::commands::SyncSelection sync;
335 switch( item->Type() )
340 kiapi::common::commands::SelectionSpec* spec = sync.add_items();
350 path.push_back( item->m_Uuid );
352 kiapi::common::commands::SelectionSpec* spec = sync.add_items();
369 kiapi::common::commands::SelectionSpec* spec = sync.add_items();
370 spec->mutable_pad()->set_reference( ref.ToUTF8() );
371 spec->mutable_pad()->set_number(
pad.ToUTF8() );
382 if( sync.items_size() == 0 )
385 sync.set_context( aForce ? commands::SyncSelectionContext::SSC_EXPLICIT
386 : commands::SyncSelectionContext::SSC_IMPLICIT );
418 kiapi::common::commands::HighlightNets
message;
420 message.add_net_name( aNetName.ToUTF8() );
435 kiapi::common::commands::HighlightNets
message;
437 for(
const wxString&
name : names )
458 std::stringstream ss( payload );
466 wxCHECK_RET( optTable.has_value(),
"Could not load symbol lib table." );
472 std::string srcProjDir;
473 std::getline( ss, srcProjDir,
'\n' );
475 std::vector<wxString> toLoad;
477 while( std::getline( ss, file,
'\n' ) )
482 wxFileName fn( file );
486 if( type == SCH_IO_MGR::SCH_FILE_UNKNOWN )
488 wxLogTrace(
"KIWAY",
"Unknown file type: %s", fn.GetFullPath() );
492 pi.reset( SCH_IO_MGR::FindPlugin( type ) );
494 wxString libTableUri;
495 bool isProjectLocal = fn.GetFullPath().StartsWith( wxString( srcProjDir ) );
501 if( !fn.FileExists() )
504 wxFileName projectFn( projectPath, fn.GetFullName() );
506 if( fn.GetFullPath() != projectFn.GetFullPath() && !projectFn.FileExists() )
507 wxCopyFile( fn.GetFullPath(), projectFn.GetFullPath() );
509 libTableUri = wxS(
"${KIPRJMOD}/" ) + fn.GetFullName();
514 libTableUri = fn.GetFullPath();
517 if( !
table->HasRow( fn.GetName() ) )
521 row.
SetURI( libTableUri );
523 toLoad.emplace_back( fn.GetName() );
527 if( !toLoad.empty() )
531 table->Save().map_error(
534 wxLogError( wxT(
"Error saving project library table:\n\n" ) + aError.
message );
543 std::ranges::for_each( toLoad,
544 [adapter](
const wxString& aNick )
561 if( ApiRequest request; request.ParseFromString( payload.c_str() ) )
568 if( !payload.empty() )
570 wxString annotationMessage( payload );
573 bool userCancelled =
false;
600 KIID uuid( payload );
608 payload =
static_cast<SCH_SYMBOL*
>( item )->GetRef( &
path,
true );
610 payload = item->GetFriendlyName();
640 std::stringstream ss( payload );
643 std::string formatStr;
644 wxCHECK( std::getline( ss, formatStr, delim ), );
646 std::string fnameStr;
647 wxCHECK( std::getline( ss, fnameStr, delim ), );
653 importFormat = std::stoi( formatStr );
655 catch( std::invalid_argument& )
661 std::map<std::string, UTF8> props;
665 std::string key, value;
667 if( !std::getline( ss, key, delim ) )
670 std::getline( ss, value, delim );
672 props.emplace( key, value );
678 if( importFormat >= 0 &&
importFile( fnameStr, importFormat, props.empty() ?
nullptr : &props )
679 && importFormat == SCH_IO_MGR::SCH_ORCAD )
682 std::map<wxString, wxString> names;
720 wxString targetFile( payload );
726 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()
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.
EESCHEMA_SETTINGS * eeconfig() const
One UI operation's hierarchy index.
bool HasNet(const wxString &aName) const
std::vector< wxString > SignalNames(const wxString &aName) const
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the KIGFX::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
friend class SCH_EDITOR_CONTROL
void RefreshConnectivity(bool aForce=false, const SCH_CONNECTIVITY::CHANGE_SET *aChanges=nullptr)
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...
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_MAIL_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
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
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 ...
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.