49 const wxString& aSearchText )
57 if( !aSearchHierarchy )
76 found = ( *aPath ==
path );
80 found = ( aReference && aReference->CmpNoCase( candidate->
GetRef( &sheet ) ) == 0 );
86 sheetWithSymbolFound = &sheet;
95 int unit =
pin->GetLibPin()->GetUnit();
97 if( unit != 0 && unit != symbol->
GetUnit() )
127 sheetWithSymbolFound );
151 displayRef = *aReference;
160 msg.Printf(
_(
"%s pin %s found" ), displayRef, aSearchText );
162 msg.Printf(
_(
"%s found but pin %s not found" ), displayRef, aSearchText );
166 msg.Printf(
_(
"%s found" ), displayRef );
171 msg.Printf(
_(
"%s not found" ), displayRef );
200 strncpy( line, cmdline,
sizeof( line ) - 1 );
201 line[
sizeof( line ) - 1 ] =
'\0';
203 char* idcmd = strtok( line,
" \n\r" );
204 char*
text = strtok(
nullptr,
"\"\n\r" );
206 if( idcmd ==
nullptr )
211 if( strcmp( idcmd,
"$CONFIG" ) == 0 )
216 else if( strcmp( idcmd,
"$ERC" ) == 0 )
221 else if( strcmp( idcmd,
"$NET:" ) == 0 )
228 if(
auto sg =
Schematic().ConnectionGraph()->FindFirstSubgraphByName( netName ) )
236 SetStatusText(
_(
"Selected net:" ) + wxS(
" " ) +
UnescapeString( netName ) );
239 else if( strcmp( idcmd,
"$CLEAR:" ) == 0 )
248 if(
text ==
nullptr )
251 if( strcmp( idcmd,
"$PART:" ) != 0 )
257 idcmd = strtok(
nullptr,
" \n\r" );
259 if( idcmd ==
nullptr )
266 text = strtok(
nullptr,
"\"\n\r" );
268 if(
text ==
nullptr )
273 if( strcmp( idcmd,
"$REF:" ) == 0 )
279 else if( strcmp( idcmd,
"$VAL:" ) == 0 )
285 else if( strcmp( idcmd,
"$PAD:" ) == 0 )
298 std::vector<wxString> parts;
302 switch( item->Type() )
319 parts.push_back( wxT(
"S" ) + full_path );
342 std::string command =
"$SELECT: 0,";
344 for( wxString part : parts )
373 if( !packet.empty() )
398 if( aConnection->
IsNet() )
404 if( aConnection->
Members().empty() )
409 wxString nets = all_members[0]->Name();
411 if( all_members.size() == 1 )
421 for(
size_t i = 1; i < all_members.size(); i++ )
422 nets <<
"," << all_members[i]->Name();
426 if( !packet.empty() )
443 std::string packet =
"$CLEAR\n";
461 std::unordered_map<wxString, std::vector<SCH_REFERENCE>>& aSyncSymMap,
462 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>>& aSyncPinMap,
463 bool aRecursive =
false )
480 aSheetPath.
GetSymbols( references,
false,
true );
482 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
491 wxString fullRef = schRef.
GetRef() + refNum;
494 if( fullRef.StartsWith( wxS(
"#" ) ) )
498 if( refNum.compare( wxS(
"?" ) ) == 0 )
502 auto symMatchIt = aSyncSymMap.find( fullRef );
504 if( symMatchIt != aSyncSymMap.end() )
506 symMatchIt->second.emplace_back( schRef );
513 auto symPinMatchIt = aSyncPinMap.find( fullRef );
515 if( symPinMatchIt != aSyncPinMap.end() )
517 std::unordered_map<wxString, SCH_PIN*>& pinMap = symPinMatchIt->second;
518 std::vector<SCH_PIN*> pinsOnSheet = symbol->
GetPins( &aSheetPath );
522 int pinUnit =
pin->GetLibPin()->GetUnit();
524 if( pinUnit > 0 && pinUnit != schRef.
GetUnit() )
527 auto pinIt = pinMap.find(
pin->GetNumber() );
529 if( pinIt != pinMap.end() )
541 std::unordered_map<wxString, std::vector<SCH_REFERENCE>>& aSyncSymMap,
542 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>>& aSyncPinMap,
543 std::unordered_map<SCH_SHEET_PATH, bool>& aCache )
545 auto cacheIt = aCache.find( aSheetPath );
547 if( cacheIt != aCache.end() )
548 return cacheIt->second;
557 aSyncPinMap, aCache );
561 aCache.emplace( aSheetPath,
false );
567 aSheetPath.
GetSymbols( references,
false,
true );
571 aCache.emplace( aSheetPath,
false );
575 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
583 wxString fullRef = schRef.
GetRef() + refNum;
586 if( fullRef.StartsWith( wxS(
"#" ) ) )
590 if( refNum.compare( wxS(
"?" ) ) == 0 )
593 if( aSyncSymMap.find( fullRef ) == aSyncSymMap.end() )
595 aCache.emplace( aSheetPath,
false );
599 if( aSyncPinMap.find( fullRef ) != aSyncPinMap.end() )
601 aCache.emplace( aSheetPath,
false );
606 aCache.emplace( aSheetPath,
true );
611std::optional<std::tuple<SCH_SHEET_PATH, SCH_ITEM*, std::vector<SCH_ITEM*>>>
615 wxArrayString syncArray = wxStringTokenize( aSyncStr, wxS(
"," ) );
617 std::unordered_map<wxString, std::vector<SCH_REFERENCE>> syncSymMap;
618 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>> syncPinMap;
619 std::unordered_map<SCH_SHEET_PATH, double> symScores;
620 std::unordered_map<SCH_SHEET_PATH, bool> fullyWantedCache;
622 std::optional<wxString> focusSymbol;
623 std::optional<std::pair<wxString, wxString>> focusPin;
624 std::unordered_map<SCH_SHEET_PATH, std::vector<SCH_ITEM*>> focusItemResults;
629 std::vector<SCH_SHEET_PATH> orderedSheets;
630 orderedSheets.reserve( allSheetsList.size() );
636 orderedSheets.push_back( sheetPath );
640 for(
size_t i = 0; i < syncArray.size(); i++ )
642 wxString syncEntry = syncArray[i];
644 if( syncEntry.empty() )
647 wxString syncData = syncEntry.substr( 1 );
649 switch( syncEntry.GetChar( 0 ).GetValue() )
655 if( aFocusOnFirst && ( i == 0 ) )
656 focusSymbol = symRef;
658 syncSymMap[symRef] = std::vector<SCH_REFERENCE>();
667 if( aFocusOnFirst && ( i == 0 ) )
668 focusPin = std::make_pair( symRef, padNum );
670 syncPinMap[symRef][padNum] =
nullptr;
680 auto flattenSyncMaps =
681 [&syncSymMap, &syncPinMap]() -> std::vector<SCH_ITEM*>
683 std::vector<SCH_ITEM*> allVec;
685 for(
const auto& [symRef, symbols] : syncSymMap )
688 allVec.push_back( ref.GetSymbol() );
691 for(
const auto& [symRef, pinMap] : syncPinMap )
693 for(
const auto& [padNum,
pin] : pinMap )
696 allVec.push_back(
pin );
704 [&syncSymMap, &syncPinMap]()
706 for(
auto& [symRef, symbols] : syncSymMap )
709 for(
auto& [reference, pins] : syncPinMap )
711 for(
auto& [number,
pin] : pins )
716 auto syncMapsValuesEmpty =
717 [&syncSymMap, &syncPinMap]() ->
bool
719 for(
const auto& [symRef, symbols] : syncSymMap )
721 if( symbols.size() > 0 )
725 for(
const auto& [symRef, pins] : syncPinMap )
727 for(
const auto& [padNum,
pin] : pins )
737 auto checkFocusItems =
742 auto findIt = syncSymMap.find( *focusSymbol );
744 if( findIt != syncSymMap.end() )
746 if( findIt->second.size() > 0 )
747 focusItemResults[aSheet].push_back( findIt->second.front().GetSymbol() );
752 auto findIt = syncPinMap.find( focusPin->first );
754 if( findIt != syncPinMap.end() )
756 if( findIt->second[focusPin->second] )
757 focusItemResults[aSheet].push_back( findIt->second[focusPin->second] );
762 auto makeRetForSheet =
769 std::vector<SCH_ITEM*> itemsVector = flattenSyncMaps();
775 kiidPath.push_back( item->m_Uuid );
777 std::optional<SCH_SHEET_PATH> subsheetPath =
784 syncPinMap, fullyWantedCache ) )
786 itemsVector.push_back( item );
790 return std::make_tuple( aSheet, aFocusItem, itemsVector );
801 checkFocusItems( sheetPath );
804 if( focusItemResults.size() > 0 )
808 const std::vector<SCH_ITEM*>& items = focusItemResults[sheetPath];
811 return makeRetForSheet( sheetPath, items.front() );
823 if( !syncMapsValuesEmpty() )
826 return makeRetForSheet( sheetPath,
nullptr );
843 std::stringstream ss( payload );
847 wxCHECK_RET( symLibTbl,
"Could not load symbol lib table." );
849 while( std::getline( ss, file,
'\n' ) )
854 wxFileName fn( file );
858 if( type == SCH_IO_MGR::SCH_FILE_UNKNOWN )
860 wxLogTrace(
"KIWAY",
"Unknown file type: %s", fn.GetFullPath() );
864 pi.reset( SCH_IO_MGR::FindPlugin( type ) );
874 symLibTbl->
Save( tblName );
878 wxLogError(
_(
"Error saving project-specific library table:\n\n%s" ), ioe.
What() );
895 if( !
eeconfig()->m_CrossProbing.on_selection )
909 std::string prefix =
"$SELECT: ";
911 std::string paramStr = payload.substr( prefix.size() );
914 if( paramStr.size() < 2 )
917 std::string syncStr = paramStr.substr( 2 );
919 bool focusOnFirst = ( paramStr[0] ==
'1' );
921 std::optional<std::tuple<SCH_SHEET_PATH, SCH_ITEM*, std::vector<SCH_ITEM*>>> findRet =
926 auto& [sheetPath, focusItem, items] = *findRet;
941 if( !payload.empty() )
943 wxString annotationMessage( payload );
964 KIID uuid( payload );
970 payload =
static_cast<SCH_SHEET*
>( item )->GetShownName(
false );
974 payload = item->GetFriendlyName();
1004 std::stringstream ss( payload );
1007 std::string formatStr;
1008 wxCHECK( std::getline( ss, formatStr, delim ), );
1010 std::string fnameStr;
1011 wxCHECK( std::getline( ss, fnameStr, delim ), );
1017 importFormat = std::stoi( formatStr );
1019 catch( std::invalid_argument& )
1025 std::map<std::string, UTF8> props;
1029 std::string key, value;
1031 if( !std::getline( ss, key, delim ) )
1034 std::getline( ss, value, delim );
1036 props.emplace( key, value );
1040 if( importFormat >= 0 )
1041 importFile( fnameStr, importFormat, props.empty() ?
nullptr : &props );
1048 payload =
"success";
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION showSymbolLibTable
static TOOL_ACTION updateSchematicFromPcb
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
CROSS_PROBING_SETTINGS m_CrossProbing
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.
virtual const wxString & GetText() const
Return the string associated with the text object.
EE_TYPE OfType(KICAD_T aType) const
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()
bool IsSingle() const
Is this KIFACE running under single_top?
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
wxString AsString() const
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)
Send aPayload to aDestination from aSource.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Generate the KiCad netlist format supported by Pcbnew.
void Format(OUTPUTFORMATTER *aOutputFormatter, int aCtl)
Output this s-expression netlist into aOutputFormatter.
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
virtual const wxString SymbolLibTableName() const
Return the path and file name of this projects symbol library table.
Holds all the data relating to one schematic.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
SCH_SHEET_PATH & CurrentSheet() 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
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const
wxString Name(bool aIgnoreSheet=false) const
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members() const
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
Handle actions specific to the schematic editor.
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.
bool ReadyToNetlist(const wxString &aAnnotateMessage)
Check if we are ready to write a netlist file for the current schematic.
bool m_syncingPcbToSchSelection
void SendSelectItemsToPcb(const std::vector< EDA_ITEM * > &aItems, bool aForce)
Send items to board editor for selection.
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 RefreshNetNavigator(const NET_NAVIGATOR_ITEM_DATA *aSelection=nullptr)
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 RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
wxString m_highlightedConn
The highlighted net or bus or empty string.
void SetCrossProbeConnection(const SCH_CONNECTION *aConnection)
Send a connection (net or bus) to Pcbnew for highlighting.
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.
void FocusOnItem(EDA_ITEM *aItem) override
Focus on a particular canvas item.
void KiwayMailIn(KIWAY_EXPRESS &aEvent) override
Receive KIWAY_EXPRESS messages from other players.
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,...
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
A helper to define a symbol's reference designator in a schematic.
void Split()
Attempt to split the reference designator into a name (U) and number (1).
bool IsSplitNeeded()
Determine if this reference needs to be split or if it likely already has been.
SCH_SYMBOL * GetSymbol() const
wxString GetRefNumber() const
EE_RTREE & Items()
Get the full RTree, usually for iterating.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
std::optional< SCH_SHEET_PATH > GetSheetPathByKIIDPath(const KIID_PATH &aPath, bool aIncludeLastSheet=true) const
Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
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.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
A base class for LIB_SYMBOL and SCH_SYMBOL.
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
bool SendCommand(int aService, const std::string &aMessage)
Used by a client to sent (by a socket connection) a data to a server.
std::optional< std::tuple< SCH_SHEET_PATH, SCH_ITEM *, std::vector< SCH_ITEM * > > > findItemsFromSyncSelection(const SCHEMATIC &aSchematic, const std::string aSyncStr, bool aFocusOnFirst)
bool findSymbolsAndPins(const SCH_SHEET_LIST &aSchematicSheetList, const SCH_SHEET_PATH &aSheetPath, std::unordered_map< wxString, std::vector< SCH_REFERENCE > > &aSyncSymMap, std::unordered_map< wxString, std::unordered_map< wxString, SCH_PIN * > > &aSyncPinMap, bool aRecursive=false)
bool sheetContainsOnlyWantedItems(const SCH_SHEET_LIST &aSchematicSheetList, const SCH_SHEET_PATH &aSheetPath, std::unordered_map< wxString, std::vector< SCH_REFERENCE > > &aSyncSymMap, std::unordered_map< wxString, std::unordered_map< wxString, SCH_PIN * > > &aSyncPinMap, std::unordered_map< SCH_SHEET_PATH, bool > &aCache)
@ FRAME_SCH_SYMBOL_EDITOR
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
@ ALL
All except INITIAL_ADD.
int StrPrintf(std::string *result, const char *format,...)
This is like sprintf() but the output is appended to a std::string instead of to a character array.
SCH_SEARCH_T
Schematic search type used by the socket link with Pcbnew.
KIWAY Kiway(KFCTL_STANDALONE)
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 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.