diff --git a/gerbview/events_called_functions.cpp b/gerbview/events_called_functions.cpp index d6d4f3265d..5888ffd2b9 100644 --- a/gerbview/events_called_functions.cpp +++ b/gerbview/events_called_functions.cpp @@ -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,13 +120,15 @@ 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; - GetCanvas()->Refresh(); - } + auto settings = static_cast( + 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 + ( GetCanvas()->GetView()->GetPainter() )->GetSettings(); + int dcodeSelected = m_DCodeSelector->GetSelectedDCodeId(); + settings->m_dcodeHighlightValue = dcodeSelected; + GetCanvas()->GetView()->UpdateAllItems( KIGFX::COLOR ); + GetCanvas()->Refresh(); } diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp index 8090a7d9b7..982cff9bf9 100644 --- a/gerbview/gerbview_painter.cpp +++ b/gerbview/gerbview_painter.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jon Evans - * 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]; diff --git a/gerbview/gerbview_painter.h b/gerbview/gerbview_painter.h index 3bee2ffe04..755e534aef 100644 --- a/gerbview/gerbview_painter.h +++ b/gerbview/gerbview_painter.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jon Evans - * 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; diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index e9e98de200..1aeb3ec807 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -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; diff --git a/gerbview/tools/gerbview_actions.cpp b/gerbview/tools/gerbview_actions.cpp index bcf318fd24..623e0d1d42 100644 --- a/gerbview/tools/gerbview_actions.cpp +++ b/gerbview/tools/gerbview_actions.cpp @@ -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" ), diff --git a/gerbview/tools/gerbview_actions.h b/gerbview/tools/gerbview_actions.h index 5644da3e95..87b41816f5 100644 --- a/gerbview/tools/gerbview_actions.h +++ b/gerbview/tools/gerbview_actions.h @@ -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 TranslateLegacyId( int aId ) override { return OPT(); } diff --git a/gerbview/tools/gerbview_control.cpp b/gerbview/tools/gerbview_control.cpp index e5c1e9fad7..ec66bdf569 100644 --- a/gerbview/tools/gerbview_control.cpp +++ b/gerbview/tools/gerbview_control.cpp @@ -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() ); diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp index 61abc878b6..5d46214024 100644 --- a/gerbview/tools/gerbview_selection_tool.cpp +++ b/gerbview/tools/gerbview_selection_tool.cpp @@ -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 ) diff --git a/gerbview/widgets/gerbview_layer_widget.cpp b/gerbview/widgets/gerbview_layer_widget.cpp index e3b8a58d2a..7f5f950a8b 100644 --- a/gerbview/widgets/gerbview_layer_widget.cpp +++ b/gerbview/widgets/gerbview_layer_widget.cpp @@ -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,7 +274,14 @@ bool GERBER_LAYER_WIDGET::OnLayerSelect( int aLayer ) if( layer != myframe->GetActiveLayer() ) { if( ! OnLayerSelected() ) + { + auto settings = static_cast + ( 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;