30#include <wx/tokenzr.h>
65#include <wx/filename.h>
86 bool multiHighlight =
false;
94 strncpy( line, cmdline,
sizeof(line) - 1 );
95 line[
sizeof(line) - 1] = 0;
97 idcmd = strtok( line,
" \n\r" );
98 text = strtok(
nullptr,
"\"\n\r" );
100 if( idcmd ==
nullptr )
103 if( strcmp( idcmd,
"$CONFIG" ) == 0 )
108 else if( strcmp( idcmd,
"$CUSTOM_RULES" ) == 0 )
113 else if( strcmp( idcmd,
"$DRC" ) == 0 )
118 else if( strcmp( idcmd,
"$CLEAR" ) == 0 )
123 bool hadChain = pcbRender && !pcbRender->GetHighlightedNetChain().IsEmpty();
129 pcbRender->SetHighlightedNetChain( wxString() );
131 if( hadHighlight || hadChain )
143 else if( strcmp( idcmd,
"$NET:" ) == 0 )
156 std::vector<MSG_PANEL_ITEM> items;
163 const wxString& chainName = netinfo->
GetNetChain();
165 if( !chainName.IsEmpty() )
169 multiHighlight =
true;
173 if( !candidate || candidate == netinfo )
176 if( candidate->GetNetChain() == chainName )
179 renderSettings->
SetHighlight(
true, candidate->GetNetCode(),
true );
184 pcbRender->SetHighlightedNetChain( chainName );
192 else if( strcmp( idcmd,
"$NETS:" ) == 0 )
197 wxStringTokenizer netsTok = wxStringTokenizer(
From_UTF8(
text ),
",", wxTOKEN_STRTOK );
200 while( netsTok.HasMoreTokens() )
209 std::vector<MSG_PANEL_ITEM> items;
216 multiHighlight =
true;
233 if( netcode > 0 || multiHighlight )
235 if( !multiHighlight )
237 renderSettings->
SetHighlight( ( netcode >= 0 ), netcode );
251 if( aItem->GetNetCode() == netcode )
252 bbox.
Merge( aItem->GetBoundingBox() );
265 for(
PAD* p : fp->Pads() )
295 return "$CLEAR: \"HIGHLIGHTED\"";
297 switch( aItem->
Type() )
310 return fmt::format(
"$PART: \"{}\" $PAD: \"{}\"",
319 const char* text_key;
330 return fmt::format(
"$PART: \"{}\" {} \"{}\"",
344template <
typename ItemContainer>
349 switch( item->Type() )
370 wxString ref =
pad->GetParentFootprint()->GetReference();
386 std::string command =
"$SELECT: ";
390 std::deque<EDA_ITEM*> focusItems = { aFocusItem };
391 std::set<wxString> focusParts;
394 if( focusParts.size() > 0 )
397 command += *focusParts.begin();
410 std::set<wxString> parts;
416 for( wxString part : parts )
441 std::string packet = fmt::format(
"$NET: \"{}\"",
TO_UTF8( aNetName ) );
443 if( !packet.empty() )
464 if( !packet.empty() )
483 wxArrayString syncArray = wxStringTokenize( syncStr,
"," );
485 std::vector<std::pair<int, BOARD_ITEM*>> orderPairs;
489 if( footprint ==
nullptr )
492 wxString fpSheetPath = footprint->GetPath().AsString().BeforeLast(
'/' );
493 wxString fpUUID = footprint->m_Uuid.AsString();
495 if( fpSheetPath.IsEmpty() )
505 wxString syncEntry = syncArray[
index];
507 if( syncEntry.empty() )
510 wxString syncData = syncEntry.substr( 1 );
512 switch( syncEntry.GetChar( 0 ).GetValue() )
515 if( fpSheetPath.StartsWith( syncData ) )
517 orderPairs.emplace_back(
index, footprint );
521 if( syncData == fpRefEscaped )
523 orderPairs.emplace_back(
index, footprint );
528 if( syncData.StartsWith( fpRefEscaped ) )
530 wxString selectPadNumberEscaped =
531 syncData.substr( fpRefEscaped.size() + 1 );
533 wxString selectPadNumber =
UnescapeString( selectPadNumberEscaped );
535 for(
PAD*
pad : footprint->Pads() )
537 if( selectPadNumber ==
pad->GetNumber() )
539 orderPairs.emplace_back(
index,
pad );
551 orderPairs.begin(), orderPairs.end(),
552 [](
const std::pair<int, BOARD_ITEM*>& a,
const std::pair<int, BOARD_ITEM*>& b ) ->
bool
554 return a.first < b.first;
557 std::vector<BOARD_ITEM*> items;
558 items.reserve( orderPairs.size() );
560 for(
const std::pair<int, BOARD_ITEM*>& pair : orderPairs )
561 items.push_back( pair.second );
583 COMPONENT* component =
new COMPONENT( footprint->GetFPID(), footprint->GetReference(),
584 footprint->GetValue(), footprint->GetPath(), {} );
586 for(
PAD*
pad : footprint->Pads() )
588 const wxString& netname =
pad->GetShortNetname();
590 if( !netname.IsEmpty() )
592 component->
AddNet(
pad->GetNumber(), netname,
pad->GetPinFunction(),
597 nlohmann::ordered_map<wxString, wxString> fields;
599 for(
PCB_FIELD* field : footprint->GetFields() )
601 wxCHECK2( field,
continue );
603 fields[field->GetCanonicalName()] = field->GetText();
609 std::map<wxString, wxString> properties;
611 if( footprint->GetAttributes() &
FP_DNP )
612 properties.emplace(
"dnp",
"" );
615 properties.emplace(
"exclude_from_bom",
"" );
618 properties.emplace(
"exclude_from_pos_files",
"" );
622 netlist.AddComponent( component );
656 std::stringstream ss( payload );
664 wxCHECK_RET( optTable.has_value(),
"Could not load footprint lib table." );
670 std::string srcProjDir;
671 std::getline( ss, srcProjDir,
'\n' );
673 wxString srcProjectPath = wxString::FromUTF8( srcProjDir );
674 std::vector<wxString> toLoad;
676 while( std::getline( ss, file,
'\n' ) )
681 wxFileName fn( wxString::FromUTF8( file ) );
686 wxLogTrace(
"KIWAY",
"Unknown file type: %s", fn.GetFullPath() );
692 wxFileName relFn( fn );
693 bool isProjectLocal =
694 !srcProjectPath.IsEmpty() && relFn.MakeRelativeTo( srcProjectPath )
695 && !relFn.IsAbsolute()
696 && !relFn.GetFullPath().StartsWith( wxS(
".." ) );
698 wxString libTableUri;
704 if( !fn.FileExists() )
707 wxFileName projectFn( projectPath, fn.GetFullName() );
709 if( fn.GetFullPath() != projectFn.GetFullPath() && !projectFn.FileExists()
710 && !wxCopyFile( fn.GetFullPath(), projectFn.GetFullPath(),
false ) )
712 wxLogError(
_(
"Error copying footprint library '%s'." ), fn.GetFullPath() );
716 libTableUri = wxS(
"${KIPRJMOD}/" ) + fn.GetFullName();
721 libTableUri = fn.GetFullPath();
724 if( !
table->HasRow( fn.GetName() ) )
728 row.
SetURI( libTableUri );
730 toLoad.emplace_back( fn.GetName() );
734 if( !toLoad.empty() )
738 table->Save().map_error(
741 wxLogError( wxT(
"Error saving project library table:\n\n" ) + aError.
message );
750 for(
const wxString& nick : toLoad )
776 std::string prefix =
"$SELECT: ";
778 if( !payload.compare( 0, prefix.size(), prefix ) )
780 std::string del =
",";
781 std::string paramStr = payload.substr( prefix.size() );
782 size_t modeEnd = paramStr.find( del );
783 bool selectConnections =
false;
787 if( std::stoi( paramStr.substr( 0, modeEnd ) ) == 1 )
788 selectConnections =
true;
790 catch( std::invalid_argument& )
795 std::vector<BOARD_ITEM*> items =
800 if( selectConnections )
812 wxLogTrace(
traceCrossProbeFlash,
"MAIL_SELECTION(_FORCE) PCB: flash enabled, items=%zu", items.size() );
819 std::vector<BOARD_ITEM*> boardItems;
820 std::copy( items.begin(), items.end(), std::back_inserter( boardItems ) );
840 std::stringstream ss( payload );
843 std::string formatStr;
844 wxCHECK( std::getline( ss, formatStr, delim ), );
846 std::string fnameStr;
847 wxCHECK( std::getline( ss, fnameStr, delim ), );
848 wxASSERT( !fnameStr.empty() );
854 importFormat = std::stoi( formatStr );
856 catch( std::invalid_argument& )
862 std::map<std::string, UTF8> props;
864 std::string key, value;
867 if( !std::getline( ss, key, delim ) )
870 if( !std::getline( ss, value, delim ) )
873 props.emplace( key, value );
877 if( importFormat >= 0 )
878 importFile( fnameStr, importFormat, props.empty() ?
nullptr : &props );
903 if( !errors.IsEmpty() )
904 statusBar->AddWarningMessages(
"load", errors );
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION updatePcbFromSchematic
static TOOL_ACTION pluginsReload
static TOOL_ACTION showFootprintLibTable
CROSS_PROBING_SETTINGS m_CrossProbing
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
FOOTPRINT * GetParentFootprint() const
Update the BOARD with a new netlist.
bool UpdateNetlist(NETLIST &aNetlist)
Update the board's components according to the new netlist.
void SetDeleteUnusedFootprints(bool aEnabled)
void SetReplaceFootprints(bool aEnabled)
void SetLookupByTimestamp(bool aEnabled)
void SetTransferGroups(bool aEnabled)
Information pertinent to a Pcbnew printed circuit board.
const NETINFO_LIST & GetNetInfo() const
const std::set< int > & GetHighLightNetCodes() const
void SetHighLightNet(int aNetCode, bool aMulti=false)
Select the netcode to be highlighted.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
const ZONES & Zones() const
void ResetNetHighLight()
Reset all high light data to the init state.
const FOOTPRINTS & Footprints() const
const TRACKS & Tracks() const
bool IsHighLightNetON() const
void HighLightON(bool aValue=true)
Enable or disable net highlighting.
constexpr size_type GetWidth() const
constexpr Vec Centre() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr size_type GetHeight() const
Store all of the related component information found in a netlist.
void SetProperties(std::map< wxString, wxString > aProps)
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
void SetFields(nlohmann::ordered_map< wxString, wxString > aFields)
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void FocusOnLocation(const VECTOR2I &aPos, bool aAllowScroll=true)
Useful to focus on a particular location, in find functions.
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.
KICAD_T Type() const
Returns the type of object.
virtual const wxString & GetText() const
Return the string associated with the text object.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
bool IsHighlightEnabled() const
Return current highlight setting.
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
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.
wxString 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)
Handle the data for a net.
const wxString & GetNetChain() const
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Return the information about the NETINFO_ITEM in aList to display in the message panel.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
static TOOL_ACTION runDRC
static TOOL_ACTION syncSelection
Sets selection to specified items, zooms to fit, if enabled.
static TOOL_ACTION syncSelectionWithNets
Sets selection to specified items with connected nets, zooms to fit, if enabled.
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
void StartCrossProbeFlash(const std::vector< BOARD_ITEM * > &aItems)
void KiwayMailIn(KIWAY_MAIL_EVENT &aEvent) override
Receive #KIWAY_ROUTED_EVENT messages from other players.
void ShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString, wxWindow *aParent=nullptr)
void OnNetlistChanged(BOARD_NETLIST_UPDATER &aUpdater, bool *aRunDragCommand)
Called after netlist is updated.
void ExecuteRemoteCommand(const char *cmdline) override
Execute a remote command send by Eeschema via a socket, port KICAD_PCB_PORT_SERVICE_NUMBER (currently...
void SendCrossProbeItem(BOARD_ITEM *aSyncItem)
Send a message to the schematic editor so that it may move its cursor to an item with the same refere...
bool FetchNetlistFromSchematic(NETLIST &aNetlist, const wxString &aAnnotateMessage)
void SendSelectItemsToSch(const std::deque< EDA_ITEM * > &aItems, EDA_ITEM *aFocusItem, bool aForce)
Send a message to the schematic editor to try to find schematic counterparts of specified PCB items a...
std::vector< BOARD_ITEM * > FindItemsFromSyncSelection(std::string syncStr)
Used to find items by selection synchronization spec string.
PCB_DESIGN_BLOCK_PANE * m_designBlocksPane
bool SavePcbFile(const wxString &aFileName, bool addToHistory=true, bool aChangeProject=true)
Write the board data structures to a aFileName.
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 Eeschema for highlighting.
A set of BOARD_ITEMs (i.e., without duplicates).
PCB_FILE_T
The set of file types that the PCB_IO_MGR knows about, and for which there has been a plugin written,...
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a footprint library's libPath.
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
virtual LIBRARY_MANAGER & GetLibraryManager() const
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
virtual const wxString GetProjectPath() const
Return the full path of the project.
Handle a list of polygons defining a copper zone.
#define CTL_OMIT_FILTERS
Omit the ki_fp_filters attribute in .kicad_xxx files.
bool SendCommand(int aService, const std::string &aMessage)
Used by a client to sent (by a socket connection) a data to a server.
const wxChar *const traceCrossProbeFlash
Flag to enable debug output for cross-probe flash operations.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Class to handle a set of BOARD_ITEMs.
void collectItemsForSyncParts(ItemContainer &aItems, std::set< wxString > &parts)
std::string FormatProbeItem(BOARD_ITEM *aItem)
PGM_BASE & Pgm()
The global program "get" accessor.
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
wxString From_UTF8(const char *cstring)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
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.
std::vector< std::vector< std::string > > table
wxLogTrace helper definitions.
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_PAD_T
class PAD, a pad in a footprint