31#include <wx/tokenzr.h>
33#include <api/common/commands/cross_probe_commands.pb.h>
75#include <unordered_set>
77#include <wx/filename.h>
82using namespace kiapi::common::commands;
102 bool multiHighlight =
false;
110 strncpy( line, cmdline,
sizeof(line) - 1 );
111 line[
sizeof(line) - 1] = 0;
113 idcmd = strtok( line,
" \n\r" );
114 text = strtok(
nullptr,
"\"\n\r" );
116 if( idcmd ==
nullptr )
119 if( strcmp( idcmd,
"$CONFIG" ) == 0 )
124 else if( strcmp( idcmd,
"$CUSTOM_RULES" ) == 0 )
129 else if( strcmp( idcmd,
"$DRC" ) == 0 )
134 else if( strcmp( idcmd,
"$CLEAR" ) == 0 )
139 bool hadChain = pcbRender && !pcbRender->GetHighlightedNetChain().IsEmpty();
145 pcbRender->SetHighlightedNetChain( wxString() );
147 if( hadHighlight || hadChain )
159 else if( strcmp( idcmd,
"$NET:" ) == 0 )
172 std::vector<MSG_PANEL_ITEM> items;
179 const wxString& chainName = netinfo->
GetNetChain();
181 if( !chainName.IsEmpty() )
185 multiHighlight =
true;
189 if( !candidate || candidate == netinfo )
192 if( candidate->GetNetChain() == chainName )
195 renderSettings->
SetHighlight(
true, candidate->GetNetCode(),
true );
200 pcbRender->SetHighlightedNetChain( chainName );
208 else if( strcmp( idcmd,
"$NETS:" ) == 0 )
213 wxStringTokenizer netsTok = wxStringTokenizer(
From_UTF8(
text ),
",", wxTOKEN_STRTOK );
216 while( netsTok.HasMoreTokens() )
225 std::vector<MSG_PANEL_ITEM> items;
232 multiHighlight =
true;
249 if( netcode > 0 || multiHighlight )
251 if( !multiHighlight )
253 renderSettings->
SetHighlight( ( netcode >= 0 ), netcode );
267 if( aItem->GetNetCode() == netcode )
268 bbox.
Merge( aItem->GetBoundingBox() );
281 for(
PAD* p : fp->Pads() )
312 bool multiHighlight =
false;
319 if( aNetNames.empty() || ( aNetNames.size() == 1 && aNetNames[0].empty() ) )
324 bool hadChain = pcbRender && !pcbRender->GetHighlightedNetChain().IsEmpty();
330 pcbRender->SetHighlightedNetChain( wxString() );
332 if( hadHighlight || hadChain )
345 if( aNetNames.size() == 1 && ( netinfo = pcb->
FindNet( aNetNames[0] ) ) !=
nullptr )
349 std::vector<MSG_PANEL_ITEM> items;
356 const wxString& chainName = netinfo->
GetNetChain();
358 if( !chainName.IsEmpty() )
362 multiHighlight =
true;
366 if( !candidate || candidate == netinfo )
369 if( candidate->GetNetChain() == chainName )
372 renderSettings->
SetHighlight(
true, candidate->GetNetCode(),
true );
377 pcbRender->SetHighlightedNetChain( chainName );
386 for(
const wxString& netName : aNetNames )
388 netinfo = pcb->
FindNet( netName );
395 std::vector<MSG_PANEL_ITEM> items;
402 multiHighlight =
true;
417 if( netcode > 0 || multiHighlight )
419 if( !multiHighlight )
421 renderSettings->
SetHighlight( ( netcode >= 0 ), netcode );
435 if( aItem->GetNetCode() == netcode )
436 bbox.
Merge( aItem->GetBoundingBox() );
449 for(
PAD* p : fp->Pads() )
478 switch( aItem->
Type() )
483 aSpec.mutable_footprint()->set_reference( footprint->
GetReference().ToUTF8() );
489 const PAD*
pad =
static_cast<const PAD*
>( aItem );
491 if(
const FOOTPRINT* footprint =
pad->GetParentFootprint() )
493 aSpec.mutable_pad()->set_reference( footprint->GetReference().ToUTF8() );
494 aSpec.mutable_pad()->set_number(
pad->GetNumber().ToUTF8() );
515 SelectionSpec focusSpec;
519 sync.set_mode( SyncSelectionMode::SSM_ITEMS_AND_NETS );
520 sync.mutable_focus_item()->CopyFrom( focusSpec );
521 sync.mutable_items()->Add()->CopyFrom( focusSpec );
525 std::vector<EDA_ITEM*> collectedItems;
531 static_cast<const PCB_GROUP*
>( item )->RunOnChildren(
535 collectedItems.push_back( aChild );
540 collectedItems.push_back( item );
544 for(
EDA_ITEM* item : collectedItems )
547 if( sync.items_size() == 0 )
550 sync.set_context( aForce ? SyncSelectionContext::SSC_EXPLICIT : SyncSelectionContext::SSC_IMPLICIT );
567 kiapi::common::commands::HighlightNets
message;
569 message.add_net_name( aNetName.ToUTF8() );
592 kiapi::common::commands::FocusOnItem
message;
593 SelectionSpec* spec =
message.mutable_focus_item();
595 switch( aSyncItem->
Type() )
600 spec->mutable_footprint()->set_reference( footprint->
GetReference().ToUTF8() );
606 PAD*
pad =
static_cast<PAD*
>( aSyncItem );
609 spec->mutable_pad()->set_reference( footprint->
GetReference().ToUTF8() );
610 spec->mutable_pad()->set_number(
pad->GetNumber().ToUTF8() );
618 spec->mutable_footprint()->set_reference( footprint->
GetReference().ToUTF8() );
646 wxCommandEvent event( EDA_EVT_PCB_LAST_SCH_SHEET_CHANGED, GetId() );
647 event.SetEventObject(
this );
648 wxPostEvent(
this, event );
672 COMPONENT* component =
new COMPONENT( footprint->GetFPID(), footprint->GetReference(),
673 footprint->GetValue(), footprint->GetPath(), {} );
675 for(
PAD*
pad : footprint->Pads() )
677 const wxString& netname =
pad->GetShortNetname();
679 if( !netname.IsEmpty() )
680 component->
AddNet(
pad->GetNumber(), netname,
pad->GetPinFunction(),
pad->GetPinType() );
683 nlohmann::ordered_map<wxString, wxString> fields;
685 for(
PCB_FIELD* field : footprint->GetFields() )
687 wxCHECK2( field,
continue );
689 fields[field->GetUntranslatedName()] = field->GetText();
695 std::map<wxString, wxString> properties;
697 if( footprint->GetAttributes() &
FP_DNP )
698 properties.emplace(
"dnp",
"" );
701 properties.emplace(
"exclude_from_bom",
"" );
704 properties.emplace(
"exclude_from_sim",
"" );
707 properties.emplace(
"exclude_from_pos_files",
"" );
711 netlist.AddComponent( component );
746 std::stringstream ss( payload );
750 std::string srcProjDir;
751 std::getline( ss, srcProjDir,
'\n' );
753 std::vector<wxString> libraries;
755 while( std::getline( ss, file,
'\n' ) )
756 libraries.push_back( wxString::FromUTF8( file ) );
771 if( ApiRequest request; request.ParseFromString( payload ) )
784 std::string netlistText;
788 if( netlistText.empty() )
806 "the board nets keep their names: %s\n" ),
818 if( renamed > 0 ||
result.m_renamed > 0 ||
result.m_unconnectedAssigned > 0 || filled > 0 )
825 footprint->InvalidateGeometryCaches();
842 std::stringstream ss( payload );
845 std::string formatStr;
846 wxCHECK( std::getline( ss, formatStr, delim ), );
848 std::string fnameStr;
849 wxCHECK( std::getline( ss, fnameStr, delim ), );
850 wxASSERT( !fnameStr.empty() );
856 importFormat = std::stoi( formatStr );
858 catch( std::invalid_argument& )
864 std::map<std::string, UTF8> props;
866 std::string key, value;
870 if( !std::getline( ss, key, delim ) )
873 if( !std::getline( ss, value, delim ) )
876 props.emplace( key, value );
882 if( importFormat >= 0 &&
importFile( fnameStr, importFormat, props.empty() ?
nullptr : &props ) )
908 if( !payload.empty() )
910 wxArrayString changed = wxSplit( wxString::FromUTF8( payload.c_str() ),
'\n' );
912 wxString boardFile = wxFileName( file ).GetFullPath();
914 for(
const wxString& changedFile : changed )
916 if( !changedFile.IsEmpty() && boardFile == wxFileName( changedFile ).GetFullPath() )
931 wxMessageDialog dlg(
this,
932 _(
"The board changed on disk while you were editing it.\n\n"
933 "Reloading loses your unsaved edits. Keeping them means your "
934 "next save overwrites the changes that just arrived. To get those "
935 "back later, use Discard Changes on the file in the Version Control "
936 "panel, which drops your edits to it." ),
937 _(
"Board Changed on Disk" ), wxYES_NO | wxNO_DEFAULT | wxICON_WARNING | wxCENTER );
938 dlg.SetYesNoLabels(
_(
"&Reload" ),
_(
"&Keep My Edits" ) );
940 if( dlg.ShowModal() != wxID_YES )
954 if( !
GetBoard()->SynchronizeComponentClasses( std::unordered_set<wxString>() ) )
955 wxLogTrace(
traceGit, wxS(
"Could not load component class assignment rules" ) );
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 SetWillDrag(bool aWillDrag)
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 SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
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.
void SynchronizeTuningProfileProperties()
Ensure that all time domain properties providers are in sync with current settings.
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 const wxString What() const
A composite of Problem() and Where()
Read the new s-expression based KiCad netlist format.
virtual void LoadNetlist() override
Load the contents of the netlist file into aNetlist.
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.
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
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.
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.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
void DisplayBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Add all items from the current board to the VIEW, so they can be displayed by GAL.
void OnModify() override
Must be called after a board change to set the modified flag.
std::unique_ptr< API_HANDLER_PCB > m_apiHandler
void KiwayMailIn(KIWAY_MAIL_EVENT &aEvent) override
Receive KIWAY_MAIL_EVENT messages from other players.
bool ReloadFromDisk()
Reload the board from disk.
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...
bool IsContentModified() const override
Get if the current board has been modified but not saved.
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).
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
void IncrementNetclassesTicker()
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
void IncrementTextVarsTicker()
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
static REPORTER & GetInstance()
Handle a list of polygons defining a copper zone.
#define CTL_OMIT_FILTERS
Omit the ki_fp_filters attribute in .kicad_xxx files.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
const wxChar *const traceGit
Flag to enable Git debugging output.
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.
int ReconcileImportedReferences(BOARD &aBoard, NETLIST &aNetlist)
Give an imported board footprint the reference its schematic symbol uses.
int FillImportedFootprintFields(BOARD &aBoard, NETLIST &aNetlist)
Copy what an imported board footprint lacks from the schematic symbol it is linked to.
NET_RECONCILE_RESULT ReconcileImportedNetNames(BOARD &aBoard, NETLIST &aNetlist, REPORTER &aReporter)
Give each net of an imported board the name its schematic uses.
@ MAIL_PCB_GET_FOOTPRINT_IDS
@ MAIL_PCB_RECONCILE_NETS
@ MAIL_PCB_PROJECT_SETTINGS_CHANGED
wxString JoinTaggedMap(const char *aTag, const std::map< wxString, wxString > &aPairs)
Encode a string map as a single property value led by a tag.
constexpr char FOOTPRINT_ID_MAP_TAG[]
Leading field marking a value as an encoded map from reference to footprint LIB_ID.
@ ALL
All except INITIAL_ADD.
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)
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.
Outcome of naming the nets of an imported board after the nets of its schematic.
wxString result
Test unit parsing edge cases and error handling.
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