From 7ad21fefe5cd8f46f5c9ce6c459093bdfb51ebc0 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 31 Dec 2018 13:54:26 +0100 Subject: [PATCH] Cross probing: Trying to fix a crash, certainly due to a call to clear the HIGHLIGHTED flag of a structure that is not a EDA_ITEM. Minor enhancement: use a specific message in cross probing to clear the HIGHLIGHTED flag. --- cvpcb/cvpcb_mainframe.cpp | 2 +- eeschema/cross-probing.cpp | 9 +++++++++ eeschema/find.cpp | 2 +- eeschema/sch_component.cpp | 14 ++++++++++++++ eeschema/sch_component.h | 6 ++++++ eeschema/sch_view.cpp | 17 +++++++++++------ pcbnew/cross-probing.cpp | 2 +- 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index a5422dde8b..12502b92e5 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -728,7 +728,7 @@ void CVPCB_MAINFRAME::SendMessageToEESCHEMA( bool aClearHighligntOnly ) // clear highlight of previously selected components (if any): // Selecting a non existing symbol clears any previously highlighted symbols - std::string packet = "$PART: \"$DUMMY$\""; + std::string packet = "$CLEAR: \"HIGHLIGHTED\""; if( Kiface().IsSingle() ) SendCommand( MSG_TO_SCH, packet.c_str() ); diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index d0da2c80f9..022a0f5291 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -58,6 +58,7 @@ * \li \c \$PART: \c "reference" \c \$VAL: \c "value" Put cursor on component value. * \li \c \$PART: \c "reference" \c \$PAD: \c "pin name" Put cursor on the component pin. * \li \c \$NET: \c "netname" Highlight a specified net + * \li \c \$CLEAR: \c "HIGHLIGHTED" Clear components highlight *

* @param cmdline = received command from Pcbnew */ @@ -97,6 +98,14 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) return; } + if( strcmp( idcmd, "$CLEAR:" ) == 0 ) + { + if( text && strcmp( text, "HIGHLIGHTED" ) == 0 ) + GetCanvas()->GetView()->HighlightItem( nullptr, nullptr ); + + return; + } + if( text == NULL ) return; diff --git a/eeschema/find.cpp b/eeschema/find.cpp index 83f645b67b..30b41d5c3a 100644 --- a/eeschema/find.cpp +++ b/eeschema/find.cpp @@ -235,7 +235,7 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, SetStatusText( msg ); - // highlight selection if foundItem is not null, or clear any highlight selection + // highlight selection if foundItem is not null, or clear any highlighted selection GetCanvas()->GetView()->HighlightItem( foundItem, pin ); GetCanvas()->Refresh(); diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 268e9380d8..200785c27a 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -1975,6 +1975,7 @@ void SCH_COMPONENT::Plot( PLOTTER* aPlotter ) } } + void SCH_COMPONENT::ClearHighlightedPins() { m_highlightedPins.clear(); @@ -1991,3 +1992,16 @@ bool SCH_COMPONENT::IsPinHighlighted( const LIB_PIN* aPin ) { return m_highlightedPins.find( aPin->GetNumber() ) != m_highlightedPins.end(); } + + +void SCH_COMPONENT::ClearAllHighlightFlags() +{ + ClearFlags( HIGHLIGHTED ); + + // Clear the HIGHLIGHTED flag of pins + ClearHighlightedPins(); + + // Clear the HIGHLIGHTED flag of other items, currently only fields + for( SCH_FIELD& each_field : m_Fields ) + each_field.ClearFlags( HIGHLIGHTED ); +} diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 5ef4400e51..e935c01f9a 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -329,6 +329,12 @@ public: */ void SetTimeStamp( timestamp_t aNewTimeStamp ); + /** + * Clear the HIGHLIGHTED flag of all items of the component + * (fields, pins ...) + */ + void ClearAllHighlightFlags(); + const EDA_RECT GetBoundingBox() const override; /** diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index 2e5da60a0c..40817fcd97 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -194,12 +194,19 @@ void SCH_VIEW::HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin ) { for( auto item : *m_allItems ) { - auto eitem = static_cast( item ); - eitem->ClearFlags( HIGHLIGHTED ); + // Not all view items can be highlighted, only EDA_ITEMs + // So clear flag of only EDA_ITEMs. + auto eitem = dynamic_cast( item ); - if( eitem->Type() == SCH_COMPONENT_T ) + if( eitem ) { - static_cast( eitem )->ClearHighlightedPins(); + eitem->ClearFlags( HIGHLIGHTED ); + + if( eitem->Type() == SCH_COMPONENT_T ) + { + // Items inside a component (pins, fields can be highlighted. + static_cast( eitem )->ClearAllHighlightFlags(); + } } } } @@ -210,9 +217,7 @@ void SCH_VIEW::HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin ) static_cast( aItem )->HighlightPin( aPin ); } else - { aItem->SetFlags( HIGHLIGHTED ); - } } // ugly but I guess OK for the moment... diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp index b2b795c316..ba3efa19d9 100644 --- a/pcbnew/cross-probing.cpp +++ b/pcbnew/cross-probing.cpp @@ -253,7 +253,7 @@ std::string FormatProbeItem( BOARD_ITEM* aItem ) MODULE* module; if( !aItem ) - return "$PART: \"UNUSED0\""; // dummy message clears highlight state + return "$CLEAR: \"HIGHLIGHTED\""; // message to clear highlight state switch( aItem->Type() ) {