47 const wxString& aSearchText )
56 if( !aSearchHierarchy )
75 found = ( *aPath ==
path );
79 found = ( aReference && aReference->CmpNoCase( candidate->
GetRef( &sheet ) ) == 0 );
85 sheetWithSymbolFound = &sheet;
96 int unit =
pin->GetLibPin()->GetUnit();
98 if( unit != 0 && unit != symbol->
GetUnit() )
105 pos =
pin->GetPosition();
155 displayRef = *aReference;
164 msg.Printf(
_(
"%s pin %s found" ), displayRef, aSearchText );
166 msg.Printf(
_(
"%s found but pin %s not found" ), displayRef, aSearchText );
170 msg.Printf(
_(
"%s found" ), displayRef );
175 msg.Printf(
_(
"%s not found" ), displayRef );
191 strncpy( line, cmdline,
sizeof( line ) - 1 );
192 line[
sizeof( line ) - 1 ] =
'\0';
194 char* idcmd = strtok( line,
" \n\r" );
195 char*
text = strtok(
nullptr,
"\"\n\r" );
197 if( idcmd ==
nullptr )
202 if( strcmp( idcmd,
"$NET:" ) == 0 )
209 if(
auto sg =
Schematic().ConnectionGraph()->FindFirstSubgraphByName( netName ) )
216 SetStatusText(
_(
"Selected net:" ) + wxS(
" " ) +
UnescapeString( netName ) );
220 if( strcmp( idcmd,
"$CLEAR:" ) == 0 )
229 if(
text ==
nullptr )
232 if( strcmp( idcmd,
"$PART:" ) != 0 )
238 idcmd = strtok(
nullptr,
" \n\r" );
240 if( idcmd ==
nullptr )
247 text = strtok(
nullptr,
"\"\n\r" );
249 if(
text ==
nullptr )
254 if( strcmp( idcmd,
"$REF:" ) == 0 )
260 else if( strcmp( idcmd,
"$VAL:" ) == 0 )
266 else if( strcmp( idcmd,
"$PAD:" ) == 0 )
279 std::vector<wxString> parts;
283 switch( item->Type() )
303 parts.push_back( wxT(
"S" ) + full_path );
330 std::string command =
"$SELECT: 0,";
332 for( wxString part : parts )
361 if( !packet.empty() )
386 if( aConnection->
IsNet() )
392 if( aConnection->
Members().empty() )
397 wxString nets = all_members[0]->Name();
399 if( all_members.size() == 1 )
409 for(
size_t i = 1; i < all_members.size(); i++ )
410 nets <<
"," << all_members[i]->Name();
414 if( !packet.empty() )
431 std::string packet =
"$CLEAR\n";
449 std::unordered_map<wxString, std::vector<SCH_REFERENCE>>& aSyncSymMap,
450 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>>& aSyncPinMap,
451 bool aRecursive =
false )
467 aSheetPath.
GetSymbols( references,
false,
true );
469 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
478 wxString fullRef = schRef.
GetRef() + refNum;
481 if( fullRef.StartsWith( wxS(
"#" ) ) )
485 if( refNum.compare( wxS(
"?" ) ) == 0 )
489 auto symMatchIt = aSyncSymMap.find( fullRef );
491 if( symMatchIt != aSyncSymMap.end() )
493 symMatchIt->second.emplace_back( schRef );
500 auto symPinMatchIt = aSyncPinMap.find( fullRef );
502 if( symPinMatchIt != aSyncPinMap.end() )
504 std::unordered_map<wxString, SCH_PIN*>& pinMap = symPinMatchIt->second;
505 std::vector<SCH_PIN*> pinsOnSheet = symbol->
GetPins( &aSheetPath );
509 int pinUnit =
pin->GetLibPin()->GetUnit();
511 if( pinUnit > 0 && pinUnit != schRef.
GetUnit() )
514 auto pinIt = pinMap.find(
pin->GetNumber() );
516 if( pinIt != pinMap.end() )
528 std::unordered_map<wxString, std::vector<SCH_REFERENCE>>& aSyncSymMap,
529 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>>& aSyncPinMap,
530 std::unordered_map<SCH_SHEET_PATH, bool>& aCache )
532 auto cacheIt = aCache.find( aSheetPath );
534 if( cacheIt != aCache.end() )
535 return cacheIt->second;
544 aSyncPinMap, aCache );
548 aCache.emplace( aSheetPath,
false );
554 aSheetPath.
GetSymbols( references,
false,
true );
558 aCache.emplace( aSheetPath,
false );
562 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
570 wxString fullRef = schRef.
GetRef() + refNum;
573 if( fullRef.StartsWith( wxS(
"#" ) ) )
577 if( refNum.compare( wxS(
"?" ) ) == 0 )
580 if( aSyncSymMap.find( fullRef ) == aSyncSymMap.end() )
582 aCache.emplace( aSheetPath,
false );
586 if( aSyncPinMap.find( fullRef ) != aSyncPinMap.end() )
588 aCache.emplace( aSheetPath,
false );
593 aCache.emplace( aSheetPath,
true );
598std::optional<std::tuple<SCH_SHEET_PATH, SCH_ITEM*, std::vector<SCH_ITEM*>>>
602 wxArrayString syncArray = wxStringTokenize( aSyncStr, wxS(
"," ) );
604 std::unordered_map<wxString, std::vector<SCH_REFERENCE>> syncSymMap;
605 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>> syncPinMap;
606 std::unordered_map<SCH_SHEET_PATH, double> symScores;
607 std::unordered_map<SCH_SHEET_PATH, bool> fullyWantedCache;
609 std::optional<wxString> focusSymbol;
610 std::optional<std::pair<wxString, wxString>> focusPin;
611 std::unordered_map<SCH_SHEET_PATH, std::vector<SCH_ITEM*>> focusItemResults;
617 orderedSheets.reserve( allSheetsList.size() );
623 orderedSheets.push_back( sheetPath );
627 for(
size_t i = 0; i < syncArray.size(); i++ )
629 wxString syncEntry = syncArray[i];
631 if( syncEntry.empty() )
634 wxString syncData = syncEntry.substr( 1 );
636 switch( syncEntry.GetChar( 0 ).GetValue() )
642 if( aFocusOnFirst && ( i == 0 ) )
643 focusSymbol = symRef;
645 syncSymMap[symRef] = std::vector<SCH_REFERENCE>();
653 if( aFocusOnFirst && ( i == 0 ) )
654 focusPin = std::make_pair( symRef, padNum );
656 syncPinMap[symRef][padNum] =
nullptr;
664 auto flattenSyncMaps = [&syncSymMap, &syncPinMap]() -> std::vector<SCH_ITEM*>
666 std::vector<SCH_ITEM*> allVec;
668 for(
auto const& pairSym : syncSymMap )
676 for(
auto const& pairSym : syncPinMap )
678 for(
auto const& pairPin : pairSym.second )
681 allVec.push_back( pairPin.second );
688 auto clearSyncMaps = [&syncSymMap, &syncPinMap]()
690 for(
auto& pairSym : syncSymMap )
692 pairSym.second.clear();
695 for(
auto& pairSym : syncPinMap )
697 for(
auto& pairPin : pairSym.second )
699 pairPin.second =
nullptr;
704 auto syncMapsValuesEmpty = [&syncSymMap, &syncPinMap]() ->
bool
706 for(
auto const& pairSym : syncSymMap )
708 if( pairSym.second.size() > 0 )
712 for(
auto const& pairSym : syncPinMap )
714 for(
auto const& pairPin : pairSym.second )
728 auto findIt = syncSymMap.find( *focusSymbol );
729 if( findIt != syncSymMap.end() )
731 if( findIt->second.size() > 0 )
733 focusItemResults[aSheetPath].push_back( findIt->second.front().GetSymbol() );
739 auto findIt = syncPinMap.find( focusPin->first );
740 if( findIt != syncPinMap.end() )
742 if( findIt->second[focusPin->second] )
744 focusItemResults[aSheetPath].push_back( findIt->second[focusPin->second] );
756 std::vector<SCH_ITEM*> itemsVector = flattenSyncMaps();
762 kiidPath.push_back( item->m_Uuid );
764 std::optional<SCH_SHEET_PATH> subsheetPath =
773 itemsVector.push_back( item );
777 return std::make_tuple( aSheet, aFocusItem, itemsVector );
788 checkFocusItems( sheetPath );
791 if( focusItemResults.size() > 0 )
795 auto vec = focusItemResults[sheetPath];
798 return makeRetForSheet( sheetPath, vec.front() );
810 if( !syncMapsValuesEmpty() )
813 return makeRetForSheet( sheetPath,
nullptr );
833 if( !
eeconfig()->m_CrossProbing.on_selection )
846 std::string prefix =
"$SELECT: ";
848 std::string paramStr = payload.substr( prefix.size() );
850 if( paramStr.size() < 2 )
853 std::string syncStr = paramStr.substr( 2 );
855 bool focusOnFirst = ( paramStr[0] ==
'1' );
857 std::optional<std::tuple<SCH_SHEET_PATH, SCH_ITEM*, std::vector<SCH_ITEM*>>> findRet =
862 auto& [sheetPath, focusItem, items] = *findRet;
877 if( !payload.empty() )
879 wxString annotationMessage( payload );
918 size_t split = payload.find(
'\n' );
919 wxCHECK(
split != std::string::npos, );
924 importFormat = std::stoi( payload.substr( 0,
split ) );
926 catch( std::invalid_argument& )
932 std::string
path = payload.substr(
split + 1 );
933 wxASSERT( !
path.empty() );
935 if( importFormat >= 0 )
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION updateSchematicFromPcb
CROSS_PROBING_SETTINGS m_CrossProbing
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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 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.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
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 GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
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
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
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)
Sends items to Pcbnew for selection.
void SendCrossProbeClearHighlight()
Tell Pcbnew to clear the existing highlighted net, if one exists.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void ExecuteRemoteCommand(const char *cmdline) override
Execute a remote command sent by Pcbnew via a socket connection.
void SendCrossProbeNetName(const wxString &aNetName)
Sends a net name to Pcbnew for highlighting.
bool importFile(const wxString &aFileName, int aFileType)
Load the given filename but sets the path to the current project path.
void DisplayCurrentSheet()
Draw the current sheet on the display.
const SCH_CONNECTION * m_highlightedConn
The highlighted net or bus, or nullptr.
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.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
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.
VECTOR2I GetPosition() const override
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
bool SendCommand(int aService, const std::string &aMessage)
Used by a client to sent (by a socket connection) a data to a server.
bool findSymbolsAndPins(const SCHEMATIC &aSchematic, 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)
std::optional< std::tuple< SCH_SHEET_PATH, SCH_ITEM *, std::vector< SCH_ITEM * > > > findItemsFromSyncSelection(const SCHEMATIC &aSchematic, const std::string aSyncStr, bool aFocusOnFirst)
bool sheetContainsOnlyWantedItems(const SCHEMATIC &aSchematic, 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 ...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
@ 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.
std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
static std::vector< std::string > split(const std::string &aStr, const std::string &aDelim)
Split the input string into a vector of output strings.
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".