46 const wxString& aSearchText )
54 if( !aSearchHierarchy )
73 found = ( *aPath ==
path );
77 found = ( aReference && aReference->CmpNoCase( candidate->
GetRef( &sheet ) ) == 0 );
83 sheetWithSymbolFound = &sheet;
92 int unit =
pin->GetLibPin()->GetUnit();
94 if( unit != 0 && unit != symbol->
GetUnit() )
148 displayRef = *aReference;
157 msg.Printf(
_(
"%s pin %s found" ), displayRef, aSearchText );
159 msg.Printf(
_(
"%s found but pin %s not found" ), displayRef, aSearchText );
163 msg.Printf(
_(
"%s found" ), displayRef );
168 msg.Printf(
_(
"%s not found" ), displayRef );
197 strncpy( line, cmdline,
sizeof( line ) - 1 );
198 line[
sizeof( line ) - 1 ] =
'\0';
200 char* idcmd = strtok( line,
" \n\r" );
201 char*
text = strtok(
nullptr,
"\"\n\r" );
203 if( idcmd ==
nullptr )
208 if( strcmp( idcmd,
"$CONFIG" ) == 0 )
213 else if( strcmp( idcmd,
"$ERC" ) == 0 )
218 else if( strcmp( idcmd,
"$NET:" ) == 0 )
225 if(
auto sg =
Schematic().ConnectionGraph()->FindFirstSubgraphByName( netName ) )
233 SetStatusText(
_(
"Selected net:" ) + wxS(
" " ) +
UnescapeString( netName ) );
236 else if( strcmp( idcmd,
"$CLEAR:" ) == 0 )
245 if(
text ==
nullptr )
248 if( strcmp( idcmd,
"$PART:" ) != 0 )
254 idcmd = strtok(
nullptr,
" \n\r" );
256 if( idcmd ==
nullptr )
263 text = strtok(
nullptr,
"\"\n\r" );
265 if(
text ==
nullptr )
270 if( strcmp( idcmd,
"$REF:" ) == 0 )
276 else if( strcmp( idcmd,
"$VAL:" ) == 0 )
282 else if( strcmp( idcmd,
"$PAD:" ) == 0 )
295 std::vector<wxString> parts;
299 switch( item->Type() )
316 parts.push_back( wxT(
"S" ) + full_path );
339 std::string command =
"$SELECT: 0,";
341 for( wxString part : parts )
370 if( !packet.empty() )
395 if( aConnection->
IsNet() )
401 if( aConnection->
Members().empty() )
406 wxString nets = all_members[0]->Name();
408 if( all_members.size() == 1 )
418 for(
size_t i = 1; i < all_members.size(); i++ )
419 nets <<
"," << all_members[i]->Name();
423 if( !packet.empty() )
440 std::string packet =
"$CLEAR\n";
458 std::unordered_map<wxString, std::vector<SCH_REFERENCE>>& aSyncSymMap,
459 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>>& aSyncPinMap,
460 bool aRecursive =
false )
477 aSheetPath.
GetSymbols( references,
false,
true );
479 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
488 wxString fullRef = schRef.
GetRef() + refNum;
491 if( fullRef.StartsWith( wxS(
"#" ) ) )
495 if( refNum.compare( wxS(
"?" ) ) == 0 )
499 auto symMatchIt = aSyncSymMap.find( fullRef );
501 if( symMatchIt != aSyncSymMap.end() )
503 symMatchIt->second.emplace_back( schRef );
510 auto symPinMatchIt = aSyncPinMap.find( fullRef );
512 if( symPinMatchIt != aSyncPinMap.end() )
514 std::unordered_map<wxString, SCH_PIN*>& pinMap = symPinMatchIt->second;
515 std::vector<SCH_PIN*> pinsOnSheet = symbol->
GetPins( &aSheetPath );
519 int pinUnit =
pin->GetLibPin()->GetUnit();
521 if( pinUnit > 0 && pinUnit != schRef.
GetUnit() )
524 auto pinIt = pinMap.find(
pin->GetNumber() );
526 if( pinIt != pinMap.end() )
538 std::unordered_map<wxString, std::vector<SCH_REFERENCE>>& aSyncSymMap,
539 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>>& aSyncPinMap,
540 std::unordered_map<SCH_SHEET_PATH, bool>& aCache )
542 auto cacheIt = aCache.find( aSheetPath );
544 if( cacheIt != aCache.end() )
545 return cacheIt->second;
554 aSyncPinMap, aCache );
558 aCache.emplace( aSheetPath,
false );
564 aSheetPath.
GetSymbols( references,
false,
true );
568 aCache.emplace( aSheetPath,
false );
572 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
580 wxString fullRef = schRef.
GetRef() + refNum;
583 if( fullRef.StartsWith( wxS(
"#" ) ) )
587 if( refNum.compare( wxS(
"?" ) ) == 0 )
590 if( aSyncSymMap.find( fullRef ) == aSyncSymMap.end() )
592 aCache.emplace( aSheetPath,
false );
596 if( aSyncPinMap.find( fullRef ) != aSyncPinMap.end() )
598 aCache.emplace( aSheetPath,
false );
603 aCache.emplace( aSheetPath,
true );
608std::optional<std::tuple<SCH_SHEET_PATH, SCH_ITEM*, std::vector<SCH_ITEM*>>>
612 wxArrayString syncArray = wxStringTokenize( aSyncStr, wxS(
"," ) );
614 std::unordered_map<wxString, std::vector<SCH_REFERENCE>> syncSymMap;
615 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>> syncPinMap;
616 std::unordered_map<SCH_SHEET_PATH, double> symScores;
617 std::unordered_map<SCH_SHEET_PATH, bool> fullyWantedCache;
619 std::optional<wxString> focusSymbol;
620 std::optional<std::pair<wxString, wxString>> focusPin;
621 std::unordered_map<SCH_SHEET_PATH, std::vector<SCH_ITEM*>> focusItemResults;
626 std::vector<SCH_SHEET_PATH> orderedSheets;
627 orderedSheets.reserve( allSheetsList.size() );
633 orderedSheets.push_back( sheetPath );
637 for(
size_t i = 0; i < syncArray.size(); i++ )
639 wxString syncEntry = syncArray[i];
641 if( syncEntry.empty() )
644 wxString syncData = syncEntry.substr( 1 );
646 switch( syncEntry.GetChar( 0 ).GetValue() )
652 if( aFocusOnFirst && ( i == 0 ) )
653 focusSymbol = symRef;
655 syncSymMap[symRef] = std::vector<SCH_REFERENCE>();
664 if( aFocusOnFirst && ( i == 0 ) )
665 focusPin = std::make_pair( symRef, padNum );
667 syncPinMap[symRef][padNum] =
nullptr;
677 auto flattenSyncMaps =
678 [&syncSymMap, &syncPinMap]() -> std::vector<SCH_ITEM*>
680 std::vector<SCH_ITEM*> allVec;
682 for(
const auto& [symRef, symbols] : syncSymMap )
685 allVec.push_back( ref.GetSymbol() );
688 for(
const auto& [symRef, pinMap] : syncPinMap )
690 for(
const auto& [padNum,
pin] : pinMap )
693 allVec.push_back(
pin );
701 [&syncSymMap, &syncPinMap]()
703 for(
auto& [symRef, symbols] : syncSymMap )
706 for(
auto& [reference, pins] : syncPinMap )
708 for(
auto& [number,
pin] : pins )
713 auto syncMapsValuesEmpty =
714 [&syncSymMap, &syncPinMap]() ->
bool
716 for(
const auto& [symRef, symbols] : syncSymMap )
718 if( symbols.size() > 0 )
722 for(
const auto& [symRef, pins] : syncPinMap )
724 for(
const auto& [padNum,
pin] : pins )
734 auto checkFocusItems =
739 auto findIt = syncSymMap.find( *focusSymbol );
741 if( findIt != syncSymMap.end() )
743 if( findIt->second.size() > 0 )
744 focusItemResults[aSheet].push_back( findIt->second.front().GetSymbol() );
749 auto findIt = syncPinMap.find( focusPin->first );
751 if( findIt != syncPinMap.end() )
753 if( findIt->second[focusPin->second] )
754 focusItemResults[aSheet].push_back( findIt->second[focusPin->second] );
759 auto makeRetForSheet =
766 std::vector<SCH_ITEM*> itemsVector = flattenSyncMaps();
772 kiidPath.push_back( item->m_Uuid );
774 std::optional<SCH_SHEET_PATH> subsheetPath =
781 syncPinMap, fullyWantedCache ) )
783 itemsVector.push_back( item );
787 return std::make_tuple( aSheet, aFocusItem, itemsVector );
798 checkFocusItems( sheetPath );
801 if( focusItemResults.size() > 0 )
805 const std::vector<SCH_ITEM*>& items = focusItemResults[sheetPath];
808 return makeRetForSheet( sheetPath, items.front() );
820 if( !syncMapsValuesEmpty() )
823 return makeRetForSheet( sheetPath,
nullptr );
843 if( !
eeconfig()->m_CrossProbing.on_selection )
856 std::string prefix =
"$SELECT: ";
858 std::string paramStr = payload.substr( prefix.size() );
860 if( paramStr.size() < 2 )
863 std::string syncStr = paramStr.substr( 2 );
865 bool focusOnFirst = ( paramStr[0] ==
'1' );
867 std::optional<std::tuple<SCH_SHEET_PATH, SCH_ITEM*, std::vector<SCH_ITEM*>>> findRet =
872 auto& [sheetPath, focusItem, items] = *findRet;
887 if( !payload.empty() )
889 wxString annotationMessage( payload );
910 KIID uuid( payload );
916 payload =
static_cast<SCH_SHEET*
>( item )->GetShownName(
false );
920 payload = item->GetFriendlyName();
949 std::stringstream ss( payload );
952 std::string formatStr;
953 wxCHECK( std::getline( ss, formatStr, delim ), );
955 std::string fnameStr;
956 wxCHECK( std::getline( ss, fnameStr, delim ), );
957 wxASSERT( !fnameStr.empty() );
963 importFormat = std::stoi( formatStr );
965 catch( std::invalid_argument& )
971 std::map<std::string, UTF8> props;
975 std::string key, value;
977 if( !std::getline( ss, key, delim ) )
980 std::getline( ss, value, delim );
982 props.emplace( key, value );
986 if( importFormat >= 0 )
987 importFile( fnameStr, importFormat, props.empty() ?
nullptr : &props );
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.
static TOOL_ACTION runERC
Inspection and Editing.
static TOOL_ACTION updateNetHighlighting
EE_TYPE OfType(KICAD_T aType) const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
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.
Generate the KiCad netlist format supported by Pcbnew.
void Format(OUTPUTFORMATTER *aOutputFormatter, int aCtl)
Output this s-expression netlist into aOutputFormatter.
Holds all the data relating to one schematic.
SCH_SHEET_PATH & CurrentSheet() const override
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
SCH_SHEET_LIST Hierarchy() const override
Return the full schematic flattened hierarchical sheet list.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
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)
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.
void DisplayCurrentSheet()
Draw the current sheet on the display.
DESIGN_BLOCK_PANE * m_designBlocksPane
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(SCH_ITEM *aItem)
void KiwayMailIn(KIWAY_EXPRESS &aEvent) override
Receive KIWAY_EXPRESS messages from other players.
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()
Gets 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.
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
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
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)
#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.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".