Gerbview: fix regression: missing DCode highlight commands.

DCode selected by context menu or from toolbar is now highlighted.
This commit is contained in:
jean-pierre charras 2021-03-13 18:45:33 +01:00
parent 18470693fe
commit c1197903e4
9 changed files with 89 additions and 19 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2011-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -120,14 +120,16 @@ void GERBVIEW_FRAME::OnSelectActiveDCode( wxCommandEvent& event )
if( gerber_image )
{
int tool = m_DCodeSelector->GetSelectedDCodeId();
int d_code = m_DCodeSelector->GetSelectedDCodeId();
if( tool != gerber_image->m_Selected_Tool )
{
gerber_image->m_Selected_Tool = tool;
auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>(
GetCanvas()->GetView()->GetPainter() )->GetSettings();
gerber_image->m_Selected_Tool = d_code;
settings->m_dcodeHighlightValue = d_code;
GetCanvas()->GetView()->UpdateAllItems( KIGFX::COLOR );
GetCanvas()->Refresh();
}
}
}
@ -137,6 +139,14 @@ void GERBVIEW_FRAME::OnSelectActiveLayer( wxCommandEvent& event )
// Rebuild the DCode list in toolbar (but not the Layer Box) after change
syncLayerBox( false );
// Reinit highlighted dcode
auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>
( GetCanvas()->GetView()->GetPainter() )->GetSettings();
int dcodeSelected = m_DCodeSelector->GetSelectedDCodeId();
settings->m_dcodeHighlightValue = dcodeSelected;
GetCanvas()->GetView()->UpdateAllItems( KIGFX::COLOR );
GetCanvas()->Refresh();
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Jon Evans <jon@craftyjon.com>
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -46,6 +46,7 @@ GERBVIEW_RENDER_SETTINGS::GERBVIEW_RENDER_SETTINGS()
m_componentHighlightString = "";
m_netHighlightString = "";
m_attributeHighlightString = "";
m_dcodeHighlightValue = -1;
update();
}
@ -139,6 +140,10 @@ COLOR4D GERBVIEW_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer )
m_attributeHighlightString == gbrItem->GetDcodeDescr()->m_AperFunction )
return m_layerColorsHi[aLayer];
if( m_dcodeHighlightValue> 0 && gbrItem && gbrItem->GetDcodeDescr() &&
m_dcodeHighlightValue == gbrItem->GetDcodeDescr()->m_Num_Dcode )
return m_layerColorsHi[aLayer];
// Return grayish color for non-highlighted layers in the high contrast mode
if( m_hiContrastEnabled && m_highContrastLayers.count( aLayer ) == 0)
return m_hiContrastColor[aLayer];

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Jon Evans <jon@craftyjon.com>
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -136,6 +136,10 @@ public:
/// If set to anything but an empty string, will highlight items with matching attribute
wxString m_attributeHighlightString;
/// If set to anything but >0 (in fact 10 the min dcode value),
/// will highlight items with matching dcode
int m_dcodeHighlightValue;
protected:
/// Flag determining if spots should be drawn with fill
bool m_spotFill;

View File

@ -887,6 +887,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
dcode->m_Shape = APT_MACRO;
dcode->SetMacro( pam );
dcode->m_Defined = true;
}
break;

View File

@ -105,7 +105,8 @@ TOOL_ACTION GERBVIEW_ACTIONS::layerChanged( "gerbview.Control.layerChanged",
TOOL_ACTION GERBVIEW_ACTIONS::highlightClear( "gerbview.Control.highlightClear",
AS_GLOBAL, 0, "",
_( "Clear Highlight" ), "" );
_( "Clear Highlight" ), "",
BITMAPS::cancel );
TOOL_ACTION GERBVIEW_ACTIONS::highlightNet( "gerbview.Control.highlightNet",
AS_GLOBAL, 0, "",
@ -122,6 +123,11 @@ TOOL_ACTION GERBVIEW_ACTIONS::highlightAttribute( "gerbview.Control.highlightAtt
_( "Highlight Attribute" ), "",
BITMAPS::flag );
TOOL_ACTION GERBVIEW_ACTIONS::highlightDCode( "gerbview.Control.highlightDCode",
AS_GLOBAL, 0, "",
_( "Highlight DCode" ), "",
BITMAPS::show_dcodenumber );
TOOL_ACTION GERBVIEW_ACTIONS::layerNext( "gerbview.Control.layerNext",
AS_GLOBAL,
'+', LEGACY_HK_NAME( "Switch to Next Layer" ),

View File

@ -90,6 +90,7 @@ public:
static TOOL_ACTION highlightNet;
static TOOL_ACTION highlightComponent;
static TOOL_ACTION highlightAttribute;
static TOOL_ACTION highlightDCode;
///< @copydoc COMMON_ACTIONS::TranslateLegacyId()
virtual OPT<TOOL_EVENT> TranslateLegacyId( int aId ) override { return OPT<TOOL_EVENT>(); }

View File

@ -166,18 +166,24 @@ int GERBVIEW_CONTROL::HighlightControl( const TOOL_EVENT& aEvent )
settings->m_netHighlightString = "";
settings->m_componentHighlightString = "";
settings->m_attributeHighlightString = "";
settings->m_dcodeHighlightValue = -1;
GERBER_FILE_IMAGE* gerber = m_frame->GetGbrImage( m_frame->GetActiveLayer() );
if( gerber )
gerber->m_Selected_Tool = settings->m_dcodeHighlightValue;
}
else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightNet ) )
{
auto string = item->GetNetAttributes().m_Netname;
settings->m_netHighlightString = string;
m_frame->m_SelNetnameBox->SetStringSelection( UnescapeString( string ) );
wxString net_name = item->GetNetAttributes().m_Netname;
settings->m_netHighlightString = net_name;
m_frame->m_SelNetnameBox->SetStringSelection( UnescapeString( net_name ) );
}
else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightComponent ) )
{
auto string = item->GetNetAttributes().m_Cmpref;
settings->m_componentHighlightString = string;
m_frame->m_SelComponentBox->SetStringSelection( string );
wxString net_attr = item->GetNetAttributes().m_Cmpref;
settings->m_componentHighlightString = net_attr;
m_frame->m_SelComponentBox->SetStringSelection( net_attr );
}
else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightAttribute ) )
{
@ -185,9 +191,29 @@ int GERBVIEW_CONTROL::HighlightControl( const TOOL_EVENT& aEvent )
if( apertDescr )
{
auto string = apertDescr->m_AperFunction;
settings->m_attributeHighlightString = string;
m_frame->m_SelAperAttributesBox->SetStringSelection( string );
wxString ap_name = apertDescr->m_AperFunction;
settings->m_attributeHighlightString = ap_name;
m_frame->m_SelAperAttributesBox->SetStringSelection( ap_name );
}
}
else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightDCode ) )
{
D_CODE* apertDescr = item->GetDcodeDescr();
if( apertDescr )
{
int dcodeSelected = -1;
GERBER_FILE_IMAGE* gerber = m_frame->GetGbrImage( m_frame->GetActiveLayer() );
if( gerber )
dcodeSelected = apertDescr->m_Num_Dcode;
if( dcodeSelected > 0 )
{
settings->m_dcodeHighlightValue = dcodeSelected;
gerber->m_Selected_Tool = dcodeSelected;
m_frame->syncLayerBox( false );
}
}
}
@ -370,6 +396,7 @@ void GERBVIEW_CONTROL::setTransitions()
Go( &GERBVIEW_CONTROL::HighlightControl, GERBVIEW_ACTIONS::highlightNet.MakeEvent() );
Go( &GERBVIEW_CONTROL::HighlightControl, GERBVIEW_ACTIONS::highlightComponent.MakeEvent() );
Go( &GERBVIEW_CONTROL::HighlightControl, GERBVIEW_ACTIONS::highlightAttribute.MakeEvent() );
Go( &GERBVIEW_CONTROL::HighlightControl, GERBVIEW_ACTIONS::highlightDCode.MakeEvent() );
Go( &GERBVIEW_CONTROL::LayerNext, GERBVIEW_ACTIONS::layerNext.MakeEvent() );
Go( &GERBVIEW_CONTROL::LayerPrev, GERBVIEW_ACTIONS::layerPrev.MakeEvent() );

View File

@ -89,6 +89,14 @@ private:
apertDescr->m_AperFunction ) );
addSeparator = true;
}
if( apertDescr )
{
auto menuEntry = Add( GERBVIEW_ACTIONS::highlightDCode );
menuEntry->SetItemLabel( wxString::Format( _( "Highlight DCode D%d" ),
apertDescr->m_Num_Dcode ) );
addSeparator = true;
}
}
if( addSeparator )

View File

@ -37,6 +37,7 @@
#include "layer_widget.h"
#include "gbr_layer_box_selector.h"
#include "gerbview_layer_widget.h"
#include "dcode_selection_box.h"
/*
* GERBER_LAYER_WIDGET
@ -273,8 +274,15 @@ bool GERBER_LAYER_WIDGET::OnLayerSelect( int aLayer )
if( layer != myframe->GetActiveLayer() )
{
if( ! OnLayerSelected() )
{
auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>
( myframe->GetCanvas()->GetView()->GetPainter() )->GetSettings();
int dcodeSelected = myframe->m_DCodeSelector->GetSelectedDCodeId();
settings->m_dcodeHighlightValue = dcodeSelected;
myframe->GetCanvas()->GetView()->UpdateAllItems( KIGFX::COLOR );
myframe->GetCanvas()->Refresh();
}
}
return true;
}