31#include <wx/tokenzr.h>
33#include <api/common/commands/cross_probe_commands.pb.h>
68#include <wx/filename.h>
72using namespace kiapi::common::commands;
92 bool multiHighlight =
false;
100 strncpy( line, cmdline,
sizeof(line) - 1 );
101 line[
sizeof(line) - 1] = 0;
103 idcmd = strtok( line,
" \n\r" );
104 text = strtok(
nullptr,
"\"\n\r" );
106 if( idcmd ==
nullptr )
109 if( strcmp( idcmd,
"$CONFIG" ) == 0 )
114 else if( strcmp( idcmd,
"$CUSTOM_RULES" ) == 0 )
119 else if( strcmp( idcmd,
"$DRC" ) == 0 )
124 else if( strcmp( idcmd,
"$CLEAR" ) == 0 )
129 bool hadChain = pcbRender && !pcbRender->GetHighlightedNetChain().IsEmpty();
135 pcbRender->SetHighlightedNetChain( wxString() );
137 if( hadHighlight || hadChain )
149 else if( strcmp( idcmd,
"$NET:" ) == 0 )
162 std::vector<MSG_PANEL_ITEM> items;
169 const wxString& chainName = netinfo->
GetNetChain();
171 if( !chainName.IsEmpty() )
175 multiHighlight =
true;
179 if( !candidate || candidate == netinfo )
182 if( candidate->GetNetChain() == chainName )
185 renderSettings->
SetHighlight(
true, candidate->GetNetCode(),
true );
190 pcbRender->SetHighlightedNetChain( chainName );
198 else if( strcmp( idcmd,
"$NETS:" ) == 0 )
203 wxStringTokenizer netsTok = wxStringTokenizer(
From_UTF8(
text ),
",", wxTOKEN_STRTOK );
206 while( netsTok.HasMoreTokens() )
215 std::vector<MSG_PANEL_ITEM> items;
222 multiHighlight =
true;
239 if( netcode > 0 || multiHighlight )
241 if( !multiHighlight )
243 renderSettings->
SetHighlight( ( netcode >= 0 ), netcode );
257 if( aItem->GetNetCode() == netcode )
258 bbox.
Merge( aItem->GetBoundingBox() );
271 for(
PAD* p : fp->Pads() )
302 bool multiHighlight =
false;
309 if( aNetNames.empty() || ( aNetNames.size() == 1 && aNetNames[0].empty() ) )
314 bool hadChain = pcbRender && !pcbRender->GetHighlightedNetChain().IsEmpty();
320 pcbRender->SetHighlightedNetChain( wxString() );
322 if( hadHighlight || hadChain )
335 if( aNetNames.size() == 1 && ( netinfo = pcb->
FindNet( aNetNames[0] ) ) !=
nullptr )
339 std::vector<MSG_PANEL_ITEM> items;
346 const wxString& chainName = netinfo->
GetNetChain();
348 if( !chainName.IsEmpty() )
352 multiHighlight =
true;
356 if( !candidate || candidate == netinfo )
359 if( candidate->GetNetChain() == chainName )
362 renderSettings->
SetHighlight(
true, candidate->GetNetCode(),
true );
367 pcbRender->SetHighlightedNetChain( chainName );
376 for(
const wxString& netName : aNetNames )
378 netinfo = pcb->
FindNet( netName );
385 std::vector<MSG_PANEL_ITEM> items;
392 multiHighlight =
true;
407 if( netcode > 0 || multiHighlight )
409 if( !multiHighlight )
411 renderSettings->
SetHighlight( ( netcode >= 0 ), netcode );
425 if( aItem->GetNetCode() == netcode )
426 bbox.
Merge( aItem->GetBoundingBox() );
439 for(
PAD* p : fp->Pads() )
468 switch( aItem->
Type() )
473 aSpec.mutable_footprint()->set_reference( footprint->
GetReference().ToUTF8() );
479 const PAD*
pad =
static_cast<const PAD*
>( aItem );
481 if(
const FOOTPRINT* footprint =
pad->GetParentFootprint() )
483 aSpec.mutable_pad()->set_reference( footprint->GetReference().ToUTF8() );
484 aSpec.mutable_pad()->set_number(
pad->GetNumber().ToUTF8() );
506 SelectionSpec focusSpec;
510 sync.set_mode( SyncSelectionMode::SSM_ITEMS_AND_NETS );
511 sync.mutable_focus_item()->CopyFrom( focusSpec );
512 sync.mutable_items()->Add()->CopyFrom( focusSpec );
516 std::vector<EDA_ITEM*> collectedItems;
522 static_cast<const PCB_GROUP*
>( item )->RunOnChildren(
526 collectedItems.push_back( aChild );
531 collectedItems.push_back( item );
535 for(
EDA_ITEM* item : collectedItems )
538 if( sync.items_size() == 0 )
541 sync.set_context( aForce ? SyncSelectionContext::SSC_EXPLICIT : SyncSelectionContext::SSC_IMPLICIT );
558 kiapi::common::commands::HighlightNets
message;
560 message.add_net_name( aNetName.ToUTF8() );
583 kiapi::common::commands::FocusOnItem
message;
584 SelectionSpec* spec =
message.mutable_focus_item();
586 switch( aSyncItem->
Type() )
591 spec->mutable_footprint()->set_reference( footprint->
GetReference().ToUTF8() );
597 PAD*
pad =
static_cast<PAD*
>( aSyncItem );
600 spec->mutable_pad()->set_reference( footprint->
GetReference().ToUTF8() );
601 spec->mutable_pad()->set_number(
pad->GetNumber().ToUTF8() );
609 spec->mutable_footprint()->set_reference( footprint->
GetReference().ToUTF8() );
637 wxCommandEvent event( EDA_EVT_PCB_LAST_SCH_SHEET_CHANGED, GetId() );
638 event.SetEventObject(
this );
639 wxPostEvent(
this, event );
663 COMPONENT* component =
new COMPONENT( footprint->GetFPID(), footprint->GetReference(),
664 footprint->GetValue(), footprint->GetPath(), {} );
666 for(
PAD*
pad : footprint->Pads() )
668 const wxString& netname =
pad->GetShortNetname();
670 if( !netname.IsEmpty() )
672 component->
AddNet(
pad->GetNumber(), netname,
pad->GetPinFunction(),
677 nlohmann::ordered_map<wxString, wxString> fields;
679 for(
PCB_FIELD* field : footprint->GetFields() )
681 wxCHECK2( field,
continue );
683 fields[field->GetUntranslatedName()] = field->GetText();
689 std::map<wxString, wxString> properties;
691 if( footprint->GetAttributes() &
FP_DNP )
692 properties.emplace(
"dnp",
"" );
695 properties.emplace(
"exclude_from_bom",
"" );
698 properties.emplace(
"exclude_from_sim",
"" );
701 properties.emplace(
"exclude_from_pos_files",
"" );
705 netlist.AddComponent( component );
739 std::stringstream ss( payload );
747 wxCHECK_RET( optTable.has_value(),
"Could not load footprint lib table." );
753 std::string srcProjDir;
754 std::getline( ss, srcProjDir,
'\n' );
756 wxString srcProjectPath = wxString::FromUTF8( srcProjDir );
757 std::vector<wxString> toLoad;
759 while( std::getline( ss, file,
'\n' ) )
764 wxFileName fn( wxString::FromUTF8( file ) );
769 wxLogTrace(
"KIWAY",
"Unknown file type: %s", fn.GetFullPath() );
775 wxFileName relFn( fn );
776 bool isProjectLocal =
777 !srcProjectPath.IsEmpty() && relFn.MakeRelativeTo( srcProjectPath )
778 && !relFn.IsAbsolute()
779 && !relFn.GetFullPath().StartsWith( wxS(
".." ) );
781 wxString libTableUri;
787 if( !fn.FileExists() )
790 wxFileName projectFn( projectPath, fn.GetFullName() );
792 if( fn.GetFullPath() != projectFn.GetFullPath() && !projectFn.FileExists()
793 && !wxCopyFile( fn.GetFullPath(), projectFn.GetFullPath(),
false ) )
795 wxLogError(
_(
"Error copying footprint library '%s'." ), fn.GetFullPath() );
799 libTableUri = wxS(
"${KIPRJMOD}/" ) + fn.GetFullName();
804 libTableUri = fn.GetFullPath();
807 if( !
table->HasRow( fn.GetName() ) )
811 row.
SetURI( libTableUri );
813 toLoad.emplace_back( fn.GetName() );
817 if( !toLoad.empty() )
821 table->Save().map_error(
824 wxLogError( wxT(
"Error saving project library table:\n\n" ) + aError.
message );
833 for(
const wxString& nick : toLoad )
848 if( ApiRequest request; request.ParseFromString( payload.c_str() ) )
860 std::stringstream ss( payload );
863 std::string formatStr;
864 wxCHECK( std::getline( ss, formatStr, delim ), );
866 std::string fnameStr;
867 wxCHECK( std::getline( ss, fnameStr, delim ), );
868 wxASSERT( !fnameStr.empty() );
874 importFormat = std::stoi( formatStr );
876 catch( std::invalid_argument& )
882 std::map<std::string, UTF8> props;
884 std::string key, value;
887 if( !std::getline( ss, key, delim ) )
890 if( !std::getline( ss, value, delim ) )
893 props.emplace( key, value );
897 if( importFormat >= 0 )
898 importFile( fnameStr, importFormat, props.empty() ?
nullptr : &props );
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)
static bool SendToFrame(FRAME_T aTarget, const google::protobuf::Message &aRequest)
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.
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_ITEM objects.
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
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)
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
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
std::unique_ptr< API_HANDLER_PCB > m_apiHandler
void KiwayMailIn(KIWAY_MAIL_EVENT &aEvent) override
Receive KIWAY_MAIL_EVENT messages from other players.
void SetLastSchematicSheetPath(const KIID_PATH &aPath)
void ShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString, wxWindow *aParent=nullptr)
void OnNetlistChanged(BOARD_NETLIST_UPDATER &aUpdater, bool *aRunDragCommand)
Called after netlist is updated.
KIID_PATH m_lastSchematicSheetPath
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...
void HandleRemoteNetHighlight(const std::vector< wxString > &aNetNames)
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.
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
KICOMMON_API bool PackKiwayApiMessage(const google::protobuf::Message &aMessage, std::string &aBytes)
Class to handle a set of BOARD_ITEMs.
static bool selectionSpecFromItem(const EDA_ITEM *aItem, SelectionSpec &aSpec)
PGM_BASE & Pgm()
The global program "get" accessor.
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< FAB_LAYER_COLOR > dummy
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.
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