From 7739cfef2f4b78ac17a455ef3a8f4a809e29cef1 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 16 Jul 2013 13:40:53 +0200 Subject: [PATCH] Added support for multiple active layers (colored ones in the high contrast mode). Added separate layers for pad netnames (now these are divided into multilayer/top/bottom pads). More appropriate layers are selecting a copper layer in the high contrast mode (now it shows the copper layer itself, vias & multilayer pads and netnames). --- common/painter.cpp | 1 - common/view/view.cpp | 3 ++ include/layers_id_colors_and_visibility.h | 10 +++- include/painter.h | 23 +++++++--- include/wxPcbStruct.h | 16 ++++++- pcbnew/basepcbframe.cpp | 5 +- pcbnew/class_pad.cpp | 56 ++++++++--------------- pcbnew/dialogs/dialog_general_options.cpp | 25 ++++------ pcbnew/pcb_painter.cpp | 6 ++- pcbnew/pcbframe.cpp | 47 +++++++++++++++---- 10 files changed, 115 insertions(+), 77 deletions(-) diff --git a/common/painter.cpp b/common/painter.cpp index f9350c2665..6d0f2d8543 100644 --- a/common/painter.cpp +++ b/common/painter.cpp @@ -39,7 +39,6 @@ RENDER_SETTINGS::RENDER_SETTINGS() m_highlightEnabled = false; m_hiContrastEnabled = false; m_hiContrastFactor = 0.2; - m_activeLayer = 0; m_outlineWidth = 1; // Store the predefined colors used in KiCad in format used by GAL diff --git a/common/view/view.cpp b/common/view/view.cpp index b8f72a0f01..8e1b031d31 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -431,6 +431,9 @@ void VIEW::EnableTopLayer( bool aEnable ) for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it ) m_layers[*it].renderingOrder -= TOP_LAYER_MODIFIER; } + + UpdateAllLayersOrder(); + UpdateAllLayersColor(); } diff --git a/include/layers_id_colors_and_visibility.h b/include/layers_id_colors_and_visibility.h index 7688dee9e6..270a3a870f 100644 --- a/include/layers_id_colors_and_visibility.h +++ b/include/layers_id_colors_and_visibility.h @@ -236,6 +236,8 @@ enum PCB_VISIBLE LAYER_14_NETNAMES_VISIBLE, LAYER_15_NETNAMES_VISIBLE, LAYER_16_NETNAMES_VISIBLE, // Top layer + PAD_FR_NETNAMES_VISIBLE, + PAD_BK_NETNAMES_VISIBLE, PADS_NETNAMES_VISIBLE, END_PCB_VISIBLE_LIST // sentinel @@ -264,7 +266,7 @@ const int GalLayerOrder[] = ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( VIAS_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ), - ITEM_GAL_LAYER( PAD_FR_VISIBLE ), + ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_FR_VISIBLE ), ITEM_GAL_LAYER( LAYER_16_NETNAMES_VISIBLE ), LAYER_N_FRONT, ITEM_GAL_LAYER( LAYER_15_NETNAMES_VISIBLE ), LAYER_N_15, ITEM_GAL_LAYER( LAYER_14_NETNAMES_VISIBLE ), LAYER_N_14, @@ -281,7 +283,7 @@ const int GalLayerOrder[] = ITEM_GAL_LAYER( LAYER_3_NETNAMES_VISIBLE ), LAYER_N_3, ITEM_GAL_LAYER( LAYER_2_NETNAMES_VISIBLE ), LAYER_N_2, ITEM_GAL_LAYER( LAYER_1_NETNAMES_VISIBLE ), LAYER_N_BACK, - ITEM_GAL_LAYER( PAD_BK_VISIBLE ), + ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_BK_VISIBLE ), SOLDERMASK_N_BACK, ADHESIVE_N_BACK, SOLDERPASTE_N_BACK, SILKSCREEN_N_BACK, ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ) @@ -408,6 +410,10 @@ inline LAYER_NUM GetNetnameLayer( LAYER_NUM aLayer ) } else if( aLayer == ITEM_GAL_LAYER( PADS_VISIBLE ) ) return ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ); + else if( aLayer == ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ) + return ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ); + else if( aLayer == ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ) + return ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ); // Fallback return COMMENT_N; diff --git a/include/painter.h b/include/painter.h index 775137dcbf..379bc744ee 100644 --- a/include/painter.h +++ b/include/painter.h @@ -27,8 +27,8 @@ #ifndef __CLASS_PAINTER_H #define __CLASS_PAINTER_H -#include #include +#include #include #include @@ -51,8 +51,6 @@ class VIEW_ITEM; * - drawing quality control (sketch/outline mode) * The class acts as an interface between the PAINTER object and the GUI (i.e. Layers/Items * widget or display options dialog). - * - * Todo: properties/introspection */ class RENDER_SETTINGS { @@ -81,9 +79,21 @@ public: * (eg. highlighted, so it differs from other layers). * @param aLayerId is a layer number that should be displayed in a specific mode. */ - inline void SetActiveLayer( int aLayerId ) + inline void SetActiveLayer( int aLayerId, bool aEnabled = true ) { - m_activeLayer = aLayerId; + if( aEnabled ) + m_activeLayers.insert( aLayerId ); + else + m_activeLayers.erase( aLayerId ); + } + + /** + * Function ClearActiveLayers + * Clears the list of active layers. + */ + inline void ClearActiveLayers() + { + m_activeLayers.clear(); } /** @@ -112,8 +122,7 @@ public: } protected: - - int m_activeLayer; /// Stores active layer number + std::set m_activeLayers; /// Stores active layers number /// Parameters for display modes bool m_hiContrastEnabled; /// High contrast display mode on/off diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index a79e660104..7d9845e4ef 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -133,7 +133,15 @@ protected: * will change the currently active layer to \a aLayer and also * update the PCB_LAYER_WIDGET. */ - void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true ); + void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true ) + { + ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; + + setHighContrastLayer( aLayer ); + + if( doLayerWidgetUpdate ) + syncLayerWidgetLayer(); + } /** * Function getActiveLayer @@ -144,6 +152,12 @@ protected: return ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer; } + /** + * Function setHighContrastLayer + * takes care of display settings for the given layer to be displayed in high contrast mode. + */ + void setHighContrastLayer( LAYER_NUM aLayer ); + /** * Function syncLayerWidgetLayer * updates the currently layer "selection" within the PCB_LAYER_WIDGET. diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 73327f6e51..229030de37 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -203,11 +203,10 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) // Netnames are drawn only when scale is sufficient (level of details) // so there is no point in caching them - for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) + for( LAYER_NUM layer = FIRST_NETNAME_LAYER; layer <= LAST_NETNAME_LAYER; ++layer ) { - view->SetLayerCached( GetNetnameLayer( layer ), false ); + view->SetLayerCached( layer, false ); } - view->SetLayerCached( ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ), false ); // Load layer & elements visibility settings for( unsigned int i = 0; i < NB_LAYERS; ++i ) diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index a6bb82f0c7..8b59239662 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -748,48 +748,32 @@ void D_PAD::ViewGetLayers( int aLayers[], int& aCount ) const { aCount = 0; - if( m_Attribute == PAD_SMD || m_Attribute == PAD_CONN ) + if( IsOnLayer( LAYER_N_FRONT ) && IsOnLayer( LAYER_N_BACK ) ) { - // Single layer pad (smd) without hole - if( IsOnLayer( LAYER_N_FRONT ) ) - aLayers[aCount++] = ITEM_GAL_LAYER( PAD_FR_VISIBLE ); - else if( IsOnLayer( LAYER_N_BACK ) ) - aLayers[aCount++] = ITEM_GAL_LAYER( PAD_BK_VISIBLE ); -#ifdef __WXDEBUG__ - else // Should not occur - { - wxLogWarning( wxT("D_PAD::ViewGetLayers():PAD on layer different than FRONT/BACK") ); - } -#endif + // Multi layer pad + aLayers[aCount++] = ITEM_GAL_LAYER( PADS_VISIBLE ); + aLayers[aCount++] = ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ); } - else + else if( IsOnLayer( LAYER_N_FRONT ) ) { - if( IsOnLayer( LAYER_N_FRONT ) && IsOnLayer( LAYER_N_BACK ) ) - { - // Multi layer pad - aLayers[aCount++] = ITEM_GAL_LAYER( PADS_VISIBLE ); - } - else if( IsOnLayer( LAYER_N_FRONT ) ) - { - aLayers[aCount++] = ITEM_GAL_LAYER( PAD_FR_VISIBLE ); - } - else if( IsOnLayer( LAYER_N_BACK ) ) - { - aLayers[aCount++] = ITEM_GAL_LAYER( PAD_BK_VISIBLE ); - } + aLayers[aCount++] = ITEM_GAL_LAYER( PAD_FR_VISIBLE ); + aLayers[aCount++] = ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ); + } + else if( IsOnLayer( LAYER_N_BACK ) ) + { + aLayers[aCount++] = ITEM_GAL_LAYER( PAD_BK_VISIBLE ); + aLayers[aCount++] = ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ); + } #ifdef __WXDEBUG__ - else // Should not occur - { - wxLogWarning( wxT("D_PAD::ViewGetLayers():PAD on layer different than FRONT/BACK") ); - } + else // Should not occur + { + wxLogWarning( wxT("D_PAD::ViewGetLayers():PAD on layer different than FRONT/BACK") ); + } #endif - // Draw a hole + // These types of pads contain a hole + if( m_Attribute == PAD_STANDARD || m_Attribute == PAD_HOLE_NOT_PLATED ) aLayers[aCount++] = ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ); - } - - // Pad description layer (number & net) - aLayers[aCount++] = ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ); } @@ -805,7 +789,7 @@ void D_PAD::ViewGetRequiredLayers( int aLayers[], int& aCount ) const unsigned int D_PAD::ViewGetLOD( int aLayer ) const { // Netnames will be shown only if zoom is appropriate - if( aLayer == ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ) ) + if( IsNetnameLayer( aLayer ) ) { return ( 100000000 / std::max( m_Size.x, m_Size.y ) ); } diff --git a/pcbnew/dialogs/dialog_general_options.cpp b/pcbnew/dialogs/dialog_general_options.cpp index 996c0f9e92..0619451bb8 100644 --- a/pcbnew/dialogs/dialog_general_options.cpp +++ b/pcbnew/dialogs/dialog_general_options.cpp @@ -199,35 +199,35 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) case ID_TB_OPTIONS_SHOW_ZONES: DisplayOpt.DisplayZonesMode = 0; recache = true; - if( !IsGalCanvasActive() ) + if( !m_galCanvasActive ) m_canvas->Refresh(); break; case ID_TB_OPTIONS_SHOW_ZONES_DISABLE: DisplayOpt.DisplayZonesMode = 1; recache = true; - if( !IsGalCanvasActive() ) + if( !m_galCanvasActive ) m_canvas->Refresh(); break; case ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY: DisplayOpt.DisplayZonesMode = 2; recache = true; - if( !IsGalCanvasActive() ) + if( !m_galCanvasActive ) m_canvas->Refresh(); break; case ID_TB_OPTIONS_SHOW_VIAS_SKETCH: m_DisplayViaFill = DisplayOpt.DisplayViaFill = !state; recache = true; - if( !IsGalCanvasActive() ) + if( !m_galCanvasActive ) m_canvas->Refresh(); break; case ID_TB_OPTIONS_SHOW_TRACKS_SKETCH: m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill = !state; recache = true; - if( !IsGalCanvasActive() ) + if( !m_galCanvasActive ) m_canvas->Refresh(); break; @@ -238,19 +238,12 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) // Apply new display options to the GAL canvas (this is faster than recaching) settings->LoadDisplayOptions( DisplayOpt ); - KiGfx::VIEW* view = m_galCanvas->GetView(); - LAYER_NUM layer = getActiveLayer(); + setHighContrastLayer( getActiveLayer() ); + m_galCanvas->GetView()->EnableTopLayer( state ); - view->GetPainter()->GetSettings()->SetActiveLayer( layer ); - view->UpdateAllLayersColor(); + if( m_galCanvasActive ) + m_galCanvas->Refresh(); - view->EnableTopLayer( state ); - view->ClearTopLayers(); - view->SetTopLayer( layer ); - view->UpdateAllLayersOrder(); - - if( !IsGalCanvasActive() ) - m_canvas->Refresh(); break; } diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index dc3670e6ec..eb8da2fa87 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -73,6 +73,8 @@ void PCB_RENDER_SETTINGS::ImportLegacyColors( COLORS_DESIGN_SETTINGS* aSettings m_itemColors[VIAS_VISIBLE] = COLOR4D( 0.7, 0.7, 0.7, 1.0 ); m_itemColors[PADS_VISIBLE] = COLOR4D( 0.7, 0.7, 0.7, 1.0 ); m_itemColors[PADS_NETNAMES_VISIBLE] = COLOR4D( 0.8, 0.8, 0.8, 0.7 ); + m_itemColors[PAD_FR_NETNAMES_VISIBLE] = COLOR4D( 0.8, 0.8, 0.8, 0.7 ); + m_itemColors[PAD_BK_NETNAMES_VISIBLE] = COLOR4D( 0.8, 0.8, 0.8, 0.7 ); // Netnames for copper layers for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) { @@ -156,7 +158,7 @@ const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer ) const COLOR4D& PCB_PAINTER::getLayerColor( int aLayer, int aNetCode ) const { - if( m_pcbSettings->m_hiContrastEnabled && m_pcbSettings->m_activeLayer != aLayer ) + if( m_pcbSettings->m_hiContrastEnabled && m_pcbSettings->m_activeLayers.count( aLayer ) == 0 ) { return m_pcbSettings->m_hiContrastColor; } @@ -376,7 +378,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) orientation = orientation * M_PI / 1800.0; // Draw description layer - if( aLayer == ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ) ) + if( IsNetnameLayer( aLayer ) ) { size = VECTOR2D( aPad->GetSize() / 2 ); double scale = m_gal->GetZoomFactor(); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index a9cafce5cb..8b8c85f296 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -743,28 +743,57 @@ bool PCB_EDIT_FRAME::IsMicroViaAcceptable( void ) } -void PCB_EDIT_FRAME::setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate ) +void PCB_EDIT_FRAME::setHighContrastLayer( LAYER_NUM aLayer ) { - ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; - // Set display settings for high contrast mode KiGfx::VIEW* view = m_galCanvas->GetView(); + KiGfx::RENDER_SETTINGS* rSettings = view->GetPainter()->GetSettings(); if( DisplayOpt.ContrastModeDisplay ) { - view->GetPainter()->GetSettings()->SetActiveLayer( aLayer ); - view->UpdateAllLayersColor(); - view->ClearTopLayers(); view->SetTopLayer( aLayer ); + + rSettings->ClearActiveLayers(); + rSettings->SetActiveLayer( aLayer ); + + if( IsCopperLayer( aLayer ) ) + { + // Bring some other layers to the front in case of copper layers and make them colored + LAYER_NUM layers[] = { + GetNetnameLayer( aLayer ), ITEM_GAL_LAYER( VIAS_VISIBLE ), + ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ), + ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ) + }; + + for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) + { + view->SetTopLayer( layers[i] ); + rSettings->SetActiveLayer( layers[i] ); + } + + // Pads should be shown too + if( aLayer == FIRST_COPPER_LAYER ) + { + view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); + } + else if( aLayer == LAST_COPPER_LAYER ) + { + view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); + } + } view->UpdateAllLayersOrder(); + view->UpdateAllLayersColor(); if( m_galCanvasActive ) m_galCanvas->Refresh(); } - - if( doLayerWidgetUpdate ) - syncLayerWidgetLayer(); }