eeschema: improved highlighting of PCB->SCH cross-probed components/labels/pins

Fixes: lp:1796990
* https://bugs.launchpad.net/kicad/+bug/1796990
This commit is contained in:
Tomasz Włostowski 2018-12-24 12:17:35 +01:00
parent 5b4e6b21f2
commit c777eac000
8 changed files with 133 additions and 46 deletions

View File

@ -117,8 +117,9 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference,
SCH_COMPONENT* Component = NULL;
wxPoint pos;
bool notFound = true;
LIB_PIN* pin;
LIB_PIN* pin = nullptr;
SCH_SHEET_LIST sheetList( g_RootSheet );
EDA_ITEM* foundItem = nullptr;
if( !aSearchHierarchy )
sheetList.push_back( *m_CurrentSheet );
@ -148,6 +149,7 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference,
case FIND_COMPONENT_ONLY: // Find component only
notFound = false;
pos = pSch->GetPosition();
foundItem = Component;
break;
case FIND_PIN: // find a pin
@ -159,11 +161,13 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference,
notFound = false;
pos += pin->GetPosition();
foundItem = Component;
break;
case FIND_REFERENCE: // find reference
notFound = false;
pos = pSch->GetField( REFERENCE )->GetPosition();
foundItem = pSch->GetField( REFERENCE );
break;
case FIND_VALUE: // find value
@ -174,6 +178,8 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference,
notFound = false;
pos = pSch->GetField( VALUE )->GetPosition();
foundItem = pSch->GetField( VALUE );
break;
}
}
@ -229,6 +235,10 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference,
SetStatusText( msg );
// highlight selection
GetCanvas()->GetView()->HighlightItem( foundItem, pin );
GetCanvas()->Refresh();
return item;
}

View File

@ -1974,3 +1974,20 @@ void SCH_COMPONENT::Plot( PLOTTER* aPlotter )
}
}
}
void SCH_COMPONENT::ClearHighlightedPins()
{
m_highlightedPins.clear();
}
void SCH_COMPONENT::HighlightPin( LIB_PIN* aPin )
{
m_highlightedPins.insert( aPin->GetNumber() );
}
bool SCH_COMPONENT::IsPinHighlighted( const LIB_PIN* aPin )
{
return m_highlightedPins.find( aPin->GetNumber() ) != m_highlightedPins.end();
}

View File

@ -38,6 +38,7 @@
#include <transform.h>
#include <general.h>
#include <vector>
#include <set>
#include <lib_draw_item.h>
class SCH_SCREEN;
@ -92,6 +93,7 @@ private:
std::vector<bool> m_isDangling; ///< One isDangling per pin
std::vector<wxPoint> m_Pins;
std::set<wxString> m_highlightedPins; ///< God forgive me - Tom
AUTOPLACED m_fieldsAutoplaced; ///< indicates status of field autoplacement
@ -147,6 +149,11 @@ public:
~SCH_COMPONENT() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_COMPONENT_T == aItem->Type();
}
wxString GetClass() const override
{
return wxT( "SCH_COMPONENT" );
@ -642,6 +649,12 @@ public:
void Show( int nestLevel, std::ostream& os ) const override;
#endif
void ClearHighlightedPins();
void HighlightPin( LIB_PIN* aPin );
bool IsPinHighlighted( const LIB_PIN* aPin );
private:
bool doIsConnected( const wxPoint& aPosition ) const override;
};

View File

@ -84,12 +84,27 @@ const COLOR4D& SCH_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer
return m_layerColors[ aLayer ];
}
static COLOR4D selectedBrightening( const COLOR4D& aColor )
static const COLOR4D getOverlayColor( const EDA_ITEM* aItem, const COLOR4D& aColor, bool aOnBackgroundLayer )
{
return aColor.Brightened( 0.5 );
}
if( aItem->IsMoving() || ( aItem->GetParent() && aItem->GetParent()->IsMoving() ) )
{
return aColor.Brightened( 0.5 );
}
else if( aItem->IsHighlighted() || ( aItem->GetParent() && aItem->GetParent()->IsHighlighted() ) )
{
if ( aOnBackgroundLayer )
{
auto bri = aColor.GetBrightness();
return COLOR4D( bri, 0.0, 0.0, 0.3 );
}
else
{
return COLOR4D( 1.0, 0.3, 0.3, 1.0 );
}
}
return aColor;
}
/**
* Used when a LIB_PART is not found in library to draw a dummy shape.
@ -275,10 +290,7 @@ bool SCH_PAINTER::setColors( const LIB_ITEM* aItem, int aLayer )
{
if( aLayer == LAYER_DEVICE_BACKGROUND && aItem->GetFillMode() == FILLED_WITH_BG_BODYCOLOR )
{
COLOR4D color = m_schSettings.GetLayerColor( LAYER_DEVICE_BACKGROUND );
if( aItem->IsMoving() || ( aItem->GetParent() && aItem->GetParent()->IsMoving() ) )
color = selectedBrightening( color );
COLOR4D color = getOverlayColor( aItem, m_schSettings.GetLayerColor( LAYER_DEVICE_BACKGROUND ), true );
m_gal->SetIsFill( true );
m_gal->SetFillColor( color );
@ -288,10 +300,7 @@ bool SCH_PAINTER::setColors( const LIB_ITEM* aItem, int aLayer )
}
else if( aLayer == LAYER_DEVICE )
{
COLOR4D color = m_schSettings.GetLayerColor( LAYER_DEVICE );
if( aItem->IsMoving() || ( aItem->GetParent() && aItem->GetParent()->IsMoving() ) )
color = selectedBrightening( color );
COLOR4D color = getOverlayColor( aItem, m_schSettings.GetLayerColor( LAYER_DEVICE ), false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
@ -377,10 +386,7 @@ void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
if( !isUnitAndConversionShown( aField ) )
return;
COLOR4D color = aField->GetDefaultColor();
if( aField->IsMoving() || ( aField->GetParent() && aField->GetParent()->IsMoving() ) )
color = selectedBrightening( color );
auto color = getOverlayColor( aField, aField->GetDefaultColor(), false );
if( !aField->IsVisible() )
{
@ -421,10 +427,7 @@ void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer )
if( !isUnitAndConversionShown( aText ) )
return;
COLOR4D color = m_schSettings.GetLayerColor( LAYER_DEVICE );
if( aText->IsMoving() || ( aText->GetParent() && aText->GetParent()->IsMoving() ) )
color = selectedBrightening( color );
auto color = getOverlayColor( aText, m_schSettings.GetLayerColor( LAYER_DEVICE ), false );
if( !aText->IsVisible() )
{
@ -491,11 +494,9 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMovin
if( aPin->IsMoving() )
isMoving = true;
COLOR4D color = m_schSettings.GetLayerColor( LAYER_PIN );
VECTOR2I pos = mapCoords( aPin->GetPosition() );
if( isMoving )
color = selectedBrightening( color );
COLOR4D color = getOverlayColor( aPin, m_schSettings.GetLayerColor( LAYER_PIN ), false );
if( !aPin->IsVisible() )
{
@ -692,7 +693,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMovin
else if( isMoving )
{
for( COLOR4D& c : colour )
c = selectedBrightening( c );
c = getOverlayColor( aPin, c, false );
}
int insideOffset = textOffset;
@ -858,8 +859,8 @@ void SCH_PAINTER::draw( SCH_JUNCTION *aJct, int aLayer )
if( aJct->GetState( BRIGHTENED ) )
color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED );
else if( aJct->IsMoving() )
color = selectedBrightening( color );
else
color = getOverlayColor( aJct, color, false );
m_gal->SetIsStroke(true);
m_gal->SetIsFill(true);
@ -875,8 +876,8 @@ void SCH_PAINTER::draw( SCH_LINE *aLine, int aLayer )
if( aLine->GetState( BRIGHTENED ) )
color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED );
else if( aLine->IsMoving() )
color = selectedBrightening( color );
color = getOverlayColor( aLine, color, false );
int width = aLine->GetPenSize();
@ -957,8 +958,8 @@ void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer )
if( aText->GetState( BRIGHTENED ) )
color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED );
if( aText->IsMoving() )
color = selectedBrightening( color );
color = getOverlayColor( aText, color, false );
if( !aText->IsVisible() )
{
@ -1049,6 +1050,9 @@ void SCH_PAINTER::draw( SCH_COMPONENT *aComp, int aLayer )
if( aComp->IsMoving() )
temp->SetFlags( IS_MOVED );
if( aComp->IsHighlighted() )
temp->SetFlags( HIGHLIGHTED );
orientComponent( temp.get(), aComp->GetOrientation() );
for( auto& item : temp->GetDrawItems() )
@ -1056,6 +1060,15 @@ void SCH_PAINTER::draw( SCH_COMPONENT *aComp, int aLayer )
auto rp = aComp->GetPosition();
auto ip = item.GetPosition();
item.Move( wxPoint( rp.x + ip.x, ip.y - rp.y ) );
if( item.Type() == LIB_PIN_T )
{
auto pin = static_cast<LIB_PIN*>( &item );
if( aComp->IsPinHighlighted( pin ) )
{
pin->SetFlags( HIGHLIGHTED );
}
}
}
draw( temp.get(), aLayer, false,
@ -1086,8 +1099,7 @@ void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer )
default: color = m_schSettings.GetLayerColor( LAYER_FIELDS ); break;
}
if( aField->IsMoving() || ( aField->GetParent() && aField->GetParent()->IsMoving() ) )
color = selectedBrightening( color );
color = getOverlayColor( aField, color, false );
if( !aField->IsVisible() )
{
@ -1155,8 +1167,8 @@ void SCH_PAINTER::draw( SCH_GLOBALLABEL *aLabel, int aLayer )
if( aLabel->GetState( BRIGHTENED ) )
color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED );
if( aLabel->IsMoving() )
color = selectedBrightening( color );
color = getOverlayColor( aLabel, color, false );
std::vector<wxPoint> pts;
std::deque<VECTOR2D> pts2;
@ -1183,8 +1195,8 @@ void SCH_PAINTER::draw( SCH_HIERLABEL *aLabel, int aLayer )
if( aLabel->GetState( BRIGHTENED ) )
color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED );
if( aLabel->IsMoving() )
color = selectedBrightening( color );
color = getOverlayColor( aLabel, color, false );
std::vector<wxPoint> pts;
std::deque<VECTOR2D> pts2;
@ -1321,8 +1333,7 @@ void SCH_PAINTER::draw( SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
m_schSettings.GetLayerColor( LAYER_BUS )
: m_schSettings.GetLayerColor( LAYER_WIRE );
if( aEntry->IsMoving() )
color = selectedBrightening( color );
color = getOverlayColor( aEntry, color, false );
m_gal->SetStrokeColor( color );
m_gal->SetIsStroke( true );

View File

@ -33,6 +33,8 @@
#include <class_libentry.h>
#include <sch_sheet.h>
#include <sch_screen.h>
#include <sch_component.h>
#include <lib_pin.h>
#include <preview_items/selection_area.h>
#include <sch_edit_frame.h>
@ -186,5 +188,36 @@ void SCH_VIEW::HideWorksheet()
// SetVisible( m_worksheet.get(), false );
}
void SCH_VIEW::HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin )
{
if(! aItem )
{
for( auto item : *m_allItems )
{
auto eitem = static_cast<EDA_ITEM *>( item );
eitem->ClearFlags( HIGHLIGHTED );
if( eitem->Type() == SCH_COMPONENT_T )
{
static_cast<SCH_COMPONENT*>( eitem )->ClearHighlightedPins();
}
}
}
else
{
if( ( aItem->Type() == SCH_COMPONENT_T ) && aPin )
{
static_cast<SCH_COMPONENT*>( aItem )->HighlightPin( aPin );
}
else
{
aItem->SetFlags( HIGHLIGHTED );
}
}
// ugly but I guess OK for the moment...
UpdateAllItems( ALL );
}
}; // namespace KIGFX

View File

@ -35,6 +35,7 @@
class SCH_SHEET;
class SCH_SCREEN;
class LIB_PART;
class LIB_PIN;
class SCH_BASE_FRAME;
// Eeschema uses mils as the internal units
@ -95,6 +96,8 @@ public:
void ClearHiddenFlags();
void HideWorksheet();
void HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin = nullptr );
private:
SCH_BASE_FRAME* m_frame; // The frame using this view. Can be null. Used mainly
// to know the sheet path name when drawing the page layout

View File

@ -252,6 +252,9 @@ std::string FormatProbeItem( BOARD_ITEM* aItem )
{
MODULE* module;
if( !aItem )
return "$PART: \"UNUSED0\""; // dummy message clears highlight state
switch( aItem->Type() )
{
case PCB_MODULE_T:
@ -309,13 +312,6 @@ std::string FormatProbeItem( BOARD_ITEM* aItem )
*/
void PCB_EDIT_FRAME::SendMessageToEESCHEMA( BOARD_ITEM* aSyncItem )
{
#if 1
wxASSERT( aSyncItem ); // can't we fix the caller?
#else
if( !aSyncItem )
return;
#endif
std::string packet = FormatProbeItem( aSyncItem );
if( packet.size() )

View File

@ -827,6 +827,8 @@ int PCB_EDITOR_CONTROL::CrossProbePcbToSch( const TOOL_EVENT& aEvent )
if( selection.Size() == 1 )
m_frame->SendMessageToEESCHEMA( static_cast<BOARD_ITEM*>( selection.Front() ) );
else
m_frame->SendMessageToEESCHEMA( nullptr );
return 0;
}
@ -1229,6 +1231,8 @@ void PCB_EDITOR_CONTROL::setTransitions()
Go( &PCB_EDITOR_CONTROL::LockSelected, PCB_ACTIONS::lock.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::UnlockSelected, PCB_ACTIONS::unlock.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::CrossProbePcbToSch, SELECTION_TOOL::SelectedEvent );
Go( &PCB_EDITOR_CONTROL::CrossProbePcbToSch, SELECTION_TOOL::UnselectedEvent );
Go( &PCB_EDITOR_CONTROL::CrossProbePcbToSch, SELECTION_TOOL::ClearedEvent );
Go( &PCB_EDITOR_CONTROL::CrossProbeSchToPcb, PCB_ACTIONS::crossProbeSchToPcb.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::DrillOrigin, PCB_ACTIONS::drillOrigin.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::HighlightNet, PCB_ACTIONS::highlightNet.MakeEvent() );