diff --git a/common/common_plotDXF_functions.cpp b/common/common_plotDXF_functions.cpp index 7958292074..2b878b3295 100644 --- a/common/common_plotDXF_functions.cpp +++ b/common/common_plotDXF_functions.cpp @@ -203,7 +203,7 @@ bool DXF_PLOTTER::StartPlot() { "YELLOW4", 2 } }; - for( EDA_COLOR_T i = BLACK; i < NBCOLORS; ++i ) + for( EDA_COLOR_T i = BLACK; i < NBCOLORS; i = NextColor(i) ) { fprintf( outputFile, " 0\n" diff --git a/common/confirm.cpp b/common/confirm.cpp index 32eb3f4afe..2a76b4e6ba 100644 --- a/common/confirm.cpp +++ b/common/confirm.cpp @@ -1,6 +1,6 @@ -/* +/** * @file confirm.cpp - * utilities to display some error, warning and info short messges + * @brief utilities to display some error, warning and info short messges */ #include diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index eb38f55cd7..9ed374f4be 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -1456,7 +1456,7 @@ void GRBezier( EDA_RECT* ClipBox, EDA_COLOR_T ColorMix( EDA_COLOR_T aColor1, EDA_COLOR_T aColor2 ) { /* Memoization storage. This could be potentially called for each - * color merge so a cache is useful (there are few colours anyway) */ + * color merge so a cache is useful (there are few colours anyway) */ static EDA_COLOR_T mix_cache[NBCOLORS][NBCOLORS]; // TODO how is alpha used? it's a mac only thing, I have no idea @@ -1469,7 +1469,7 @@ EDA_COLOR_T ColorMix( EDA_COLOR_T aColor1, EDA_COLOR_T aColor2 ) if( aColor2 == BLACK) return aColor1; - /* Now we are sure that black can't occur, so the rule is: + /* Now we are sure that black can't occur, so the rule is: * BLACK means not computed yet. If we're lucky we already have * an answer */ EDA_COLOR_T candidate = mix_cache[aColor1][aColor2]; @@ -1477,11 +1477,11 @@ EDA_COLOR_T ColorMix( EDA_COLOR_T aColor1, EDA_COLOR_T aColor2 ) return candidate; // Blend the two colors (i.e. OR the RGB values) - const StructColors &c1 = g_ColorRefs[aColor1]; - const StructColors &c2 = g_ColorRefs[aColor2]; + const StructColors &c1 = g_ColorRefs[aColor1]; + const StructColors &c2 = g_ColorRefs[aColor2]; // Ask the palette for the nearest color to the mix - wxColour mixed( c1.m_Red | c2.m_Red, + wxColour mixed( c1.m_Red | c2.m_Red, c1.m_Green | c2.m_Green, c1.m_Blue | c2.m_Blue ); candidate = ColorFindNearest( mixed ); @@ -1489,7 +1489,7 @@ EDA_COLOR_T ColorMix( EDA_COLOR_T aColor1, EDA_COLOR_T aColor2 ) /* Here, BLACK is *not* a good answer, since it would recompute the next time. * Even theorically its not possible (with the current rules), but * maybe the metric will change in the future */ - if( candidate == BLACK) + if( candidate == BLACK) candidate = DARKDARKGRAY; // Store the result in the cache. The operation is commutative, too @@ -1502,12 +1502,12 @@ EDA_COLOR_T ColorMix( EDA_COLOR_T aColor1, EDA_COLOR_T aColor2 ) EDA_COLOR_T ColorByName( const wxChar *aName ) { // look for a match in the palette itself - for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; ++trying ) + for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) ) { if( 0 == wxStricmp( aName, g_ColorRefs[trying].m_Name ) ) return trying; } - + // Not found, no idea... return UNSPECIFIED_COLOR; } @@ -1525,23 +1525,23 @@ EDA_COLOR_T ColorFindNearest( const wxColour &aColor ) /* Find the 'nearest' color in the palette. This is fun. There is a gazilion of metrics for the color space and no one of the useful one is in the RGB color space. Who cares, this is a CAD, - not a photosomething... - + not a photosomething... + I hereby declare that the distance is the sum of the square of the component difference. Think about the RGB color cube. Now get the - euclidean distance, but without the square root... for ordering + euclidean distance, but without the square root... for ordering purposes it's the same, obviously. Also each component can't be less of the target one, since I found this currently work better... */ int nearest_distance = 255 * 255 * 3 + 1; // Can't beat this - for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; ++trying ) + for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) ) { - const StructColors &c = g_ColorRefs[trying]; + const StructColors &c = g_ColorRefs[trying]; int distance = (r - c.m_Red) * (r - c.m_Red) + (g - c.m_Green) * (g - c.m_Green) + (b - c.m_Blue) * (b - c.m_Blue); - if( distance < nearest_distance && c.m_Red >= r && + if( distance < nearest_distance && c.m_Red >= r && c.m_Green >= g && c.m_Blue >= b ) { nearest_distance = distance; diff --git a/gerbview/class_gerbview_layer_widget.cpp b/gerbview/class_gerbview_layer_widget.cpp index bb6a3a57df..911f2594f3 100644 --- a/gerbview/class_gerbview_layer_widget.cpp +++ b/gerbview/class_gerbview_layer_widget.cpp @@ -55,6 +55,8 @@ GERBER_LAYER_WIDGET::GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFo LAYER_WIDGET( aParent, aFocusOwner, aPointSize ), myframe( aParent ) { + m_alwaysShowActiveLayer = false; + ReFillRender(); // Update default tabs labels for GerbView @@ -67,7 +69,8 @@ GERBER_LAYER_WIDGET::GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFo // since Popupmenu() calls this->ProcessEvent() we must call this->Connect() // and not m_LayerScrolledWindow->Connect() - Connect( ID_SHOW_ALL_COPPERS, ID_SHOW_NO_COPPERS_BUT_ACTIVE, wxEVT_COMMAND_MENU_SELECTED, + Connect( ID_SHOW_ALL_LAYERS, ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE, + wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GERBER_LAYER_WIDGET::onPopupSelection ), NULL, this ); // install the right click handler into each control at end of ReFill() @@ -144,13 +147,16 @@ void GERBER_LAYER_WIDGET::onRightDownLayers( wxMouseEvent& event ) // menu text is capitalized: // http://library.gnome.org/devel/hig-book/2.20/design-text-labels.html.en#layout-capitalization - menu.Append( new wxMenuItem( &menu, ID_SHOW_ALL_COPPERS, + menu.Append( new wxMenuItem( &menu, ID_SHOW_ALL_LAYERS, _("Show All Layers") ) ); - menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_COPPERS_BUT_ACTIVE, + menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_LAYERS_BUT_ACTIVE, _( "Hide All Layers But Active" ) ) ); - menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_COPPERS, + menu.Append( new wxMenuItem( &menu, ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE, + _( "Always Hide All Layers But Active" ) ) ); + + menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_LAYERS, _( "Hide All Layers" ) ) ); PopupMenu( &menu ); @@ -162,24 +168,32 @@ void GERBER_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event ) { int rowCount; int menuId = event.GetId(); - bool visible = (menuId == ID_SHOW_ALL_COPPERS) ? true : false;; + bool visible = (menuId == ID_SHOW_ALL_LAYERS) ? true : false;; LAYER_MSK visibleLayers = NO_LAYERS; + bool force_active_layer_visible; + + m_alwaysShowActiveLayer = ( menuId == ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE ); + force_active_layer_visible = ( menuId == ID_SHOW_NO_LAYERS_BUT_ACTIVE || + menuId == ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE ); switch( menuId ) { - case ID_SHOW_ALL_COPPERS: - case ID_SHOW_NO_COPPERS: - case ID_SHOW_NO_COPPERS_BUT_ACTIVE: + case ID_SHOW_ALL_LAYERS: + case ID_SHOW_NO_LAYERS: + case ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE: + case ID_SHOW_NO_LAYERS_BUT_ACTIVE: rowCount = GetLayerRowCount(); for( int row=0; row < rowCount; ++row ) { + wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, 3 ); + LAYER_NUM layer = getDecodedId( cb->GetId() ); bool loc_visible = visible; - if( (menuId == ID_SHOW_NO_COPPERS_BUT_ACTIVE ) && - (row == m_CurrentRow ) ) + + if( force_active_layer_visible && (layer == myframe->getActiveLayer() ) ) loc_visible = true; - wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, 3 ); cb->SetValue( loc_visible ); + if( loc_visible ) visibleLayers |= GetLayerMask( row ); else @@ -192,6 +206,18 @@ void GERBER_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event ) } } +bool GERBER_LAYER_WIDGET::OnLayerSelected() +{ + if( !m_alwaysShowActiveLayer ) + return false; + + // postprocess after an active layer selection + // ensure active layer visible + wxCommandEvent event; + event.SetId( ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE ); + onPopupSelection( event ); + return true; +} void GERBER_LAYER_WIDGET::ReFill() @@ -227,7 +253,10 @@ bool GERBER_LAYER_WIDGET::OnLayerSelect( LAYER_NUM aLayer ) myframe->syncLayerBox(); if( layer != myframe->getActiveLayer( ) ) - myframe->GetCanvas()->Refresh(); + { + if( ! OnLayerSelected() ) + myframe->GetCanvas()->Refresh(); + } return true; } diff --git a/gerbview/class_gerbview_layer_widget.h b/gerbview/class_gerbview_layer_widget.h index cd974e08ea..b92a301d9f 100644 --- a/gerbview/class_gerbview_layer_widget.h +++ b/gerbview/class_gerbview_layer_widget.h @@ -42,11 +42,14 @@ class GERBER_LAYER_WIDGET : public LAYER_WIDGET { GERBVIEW_FRAME* myframe; + bool m_alwaysShowActiveLayer; // If true: Only shows the current active layer + // even if it is changed // popup menu ids. -#define ID_SHOW_ALL_COPPERS wxID_HIGHEST -#define ID_SHOW_NO_COPPERS (wxID_HIGHEST+1) -#define ID_SHOW_NO_COPPERS_BUT_ACTIVE (wxID_HIGHEST+2) +#define ID_SHOW_ALL_LAYERS wxID_HIGHEST +#define ID_SHOW_NO_LAYERS (wxID_HIGHEST+1) +#define ID_SHOW_NO_LAYERS_BUT_ACTIVE (wxID_HIGHEST+2) +#define ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE (wxID_HIGHEST+3) /** * Function OnRightDownLayers @@ -101,6 +104,18 @@ public: void SetLayersManagerTabsText( ); //--------------- + /** + * Function OnLayerSelected + * ensure the active layer is visible, and other layers not visible + * when m_alwaysShowActiveLayer is true + * Otherwise do nothing. + * @return true m_alwaysShowActiveLayer is true and the canvas is refreshed, + * and false if do nothing + */ + bool OnLayerSelected(); // postprocess after an active layer selection + // ensure active layer visible if + // m_alwaysShowActiveCopperLayer is true; + /** * Function UpdateLayerIcons * Update the layer manager icons (layers only) diff --git a/gerbview/events_called_functions.cpp b/gerbview/events_called_functions.cpp index 28df5efb48..828021cb2d 100644 --- a/gerbview/events_called_functions.cpp +++ b/gerbview/events_called_functions.cpp @@ -240,7 +240,10 @@ void GERBVIEW_FRAME::OnSelectActiveLayer( wxCommandEvent& event ) setActiveLayer( event.GetSelection() ); if( layer != getActiveLayer() ) - m_canvas->Refresh(); + { + if( m_LayersManager->OnLayerSelected() ) + m_canvas->Refresh(); + } } diff --git a/gerbview/toolbars_gerber.cpp b/gerbview/toolbars_gerber.cpp index 2247e83f51..bc878db1d4 100644 --- a/gerbview/toolbars_gerber.cpp +++ b/gerbview/toolbars_gerber.cpp @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2013 Wayne Stambaugh + * Copyright (C) 1992-2013 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 @@ -87,8 +87,9 @@ void GERBVIEW_FRAME::ReCreateHToolbar( void ) m_mainToolBar->AddSeparator(); - m_SelLayerBox = new GBR_LAYER_BOX_SELECTOR( m_mainToolBar, ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, - wxDefaultPosition, wxSize( 150, -1 ), 0,NULL); + m_SelLayerBox = new GBR_LAYER_BOX_SELECTOR( m_mainToolBar, + ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, + wxDefaultPosition, wxSize( 150, -1 ), 0,NULL); m_SelLayerBox->Resync(); m_mainToolBar->AddControl( m_SelLayerBox ); diff --git a/include/colors.h b/include/colors.h index 123544d071..eff6e49a55 100644 --- a/include/colors.h +++ b/include/colors.h @@ -37,12 +37,12 @@ enum EDA_COLOR_T LIGHTRED, LIGHTMAGENTA, YELLOW, - PUREBLUE, - PUREGREEN, - PURECYAN, - PURERED, + PUREBLUE, + PUREGREEN, + PURECYAN, + PURERED, PUREMAGENTA, - PUREYELLOW, + PUREYELLOW, NBCOLORS, ///< Number of colors HIGHLIGHT_FLAG = ( 1<<19 ), MASKCOLOR = 31 ///< mask for color index into g_ColorRefs[] @@ -55,7 +55,7 @@ inline EDA_COLOR_T ColorFromInt( int aColor ) return static_cast( aColor ); } -inline EDA_COLOR_T operator++( EDA_COLOR_T& aColor ) +inline EDA_COLOR_T NextColor( EDA_COLOR_T& aColor ) { // We have to accept NBCOLORS for loop termination conditions wxASSERT( aColor >= UNSPECIFIED_COLOR && aColor <= NBCOLORS ); @@ -63,7 +63,6 @@ inline EDA_COLOR_T operator++( EDA_COLOR_T& aColor ) return aColor; } - /// Return only the plain color part inline EDA_COLOR_T ColorGetBase( EDA_COLOR_T aColor) { diff --git a/include/sch_item_struct.h b/include/sch_item_struct.h index 11b7d4866c..82e2e50eed 100644 --- a/include/sch_item_struct.h +++ b/include/sch_item_struct.h @@ -32,7 +32,7 @@ #include #include -#include +#include using namespace std; diff --git a/pcbnew/class_pcb_layer_widget.cpp b/pcbnew/class_pcb_layer_widget.cpp index 87e6364358..ef2199251a 100644 --- a/pcbnew/class_pcb_layer_widget.cpp +++ b/pcbnew/class_pcb_layer_widget.cpp @@ -91,7 +91,8 @@ PCB_LAYER_WIDGET::PCB_LAYER_WIDGET( PCB_EDIT_FRAME* aParent, wxWindow* aFocusOwn // since Popupmenu() calls this->ProcessEvent() we must call this->Connect() // and not m_LayerScrolledWindow->Connect() - Connect( ID_SHOW_ALL_COPPERS, ID_ALWAYS_SHOW_NO_COPPERS_BUT_ACTIVE, wxEVT_COMMAND_MENU_SELECTED, + Connect( ID_SHOW_ALL_COPPERS, ID_ALWAYS_SHOW_NO_COPPERS_BUT_ACTIVE, + wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PCB_LAYER_WIDGET::onPopupSelection ), NULL, this ); // install the right click handler into each control at end of ReFill() @@ -102,9 +103,9 @@ PCB_LAYER_WIDGET::PCB_LAYER_WIDGET( PCB_EDIT_FRAME* aParent, wxWindow* aFocusOwn void PCB_LAYER_WIDGET::installRightLayerClickHandler() { int rowCount = GetLayerRowCount(); - for( int row=0; row---------- - void OnLayerSelected(); // postprocess after an active layer selection + /** + * Function OnLayerSelected + * ensure the active layer is visible, and other layers not visible + * when m_alwaysShowActiveLayer is true + * Otherwise do nothing. + * @return true m_alwaysShowActiveLayer is true and the canvas is refreshed, + * and false if do nothing + */ + bool OnLayerSelected(); // postprocess after an active layer selection // ensure active layer visible if // m_alwaysShowActiveCopperLayer is true;