Commit ca4a3651 authored by jean-pierre charras's avatar jean-pierre charras

Gerbview, layer manager: add option (popup menu) to always keep layers not...

Gerbview, layer manager: add option (popup menu) to always keep layers not visible but the active layer, even when the active layer is changed.
Pcbnew: fix swig warning for operator EDA_COLOR_T::++  (changed to function EDA_COLOR_T:: NextColor)
parent 74a57d4e
......@@ -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"
......
/*
/**
* @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 <fctsys.h>
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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( );
//-----</implement LAYER_WIDGET abstract callback functions>----------
/**
* 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)
......
......@@ -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();
}
}
......
/*
* 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 <stambaughw@verizon.net>
* 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 <stambaughw@verizon.net>
* 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 );
......
......@@ -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<EDA_COLOR_T>( 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)
{
......
......@@ -32,7 +32,7 @@
#include <vector>
#include <class_base_screen.h>
#include <eeschema/general.h>
#include <general.h>
using namespace std;
......
......@@ -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<rowCount; ++row )
for( int row=0; row<rowCount; ++row )
{
for( int col=0; col<LYR_COLUMN_COUNT; ++col )
for( int col=0; col<LYR_COLUMN_COUNT; ++col )
{
wxWindow* w = getLayerComp( row, col );
......@@ -143,16 +144,17 @@ void PCB_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event )
bool visible;
bool force_active_layer_visible;
visible = menuId == ID_SHOW_ALL_COPPERS;
m_alwaysShowActiveCopperLayer = ( menuId == ID_ALWAYS_SHOW_NO_COPPERS_BUT_ACTIVE );
force_active_layer_visible = ( menuId == ID_SHOW_NO_COPPERS_BUT_ACTIVE ||
menuId == ID_ALWAYS_SHOW_NO_COPPERS_BUT_ACTIVE );
switch( menuId )
{
case ID_SHOW_ALL_COPPERS:
case ID_ALWAYS_SHOW_NO_COPPERS_BUT_ACTIVE:
case ID_SHOW_NO_COPPERS_BUT_ACTIVE:
case ID_SHOW_NO_COPPERS:
visible = menuId == ID_SHOW_ALL_COPPERS;
m_alwaysShowActiveCopperLayer = ( menuId == ID_ALWAYS_SHOW_NO_COPPERS_BUT_ACTIVE );
force_active_layer_visible = ( menuId == ID_SHOW_NO_COPPERS_BUT_ACTIVE ||
menuId == ID_ALWAYS_SHOW_NO_COPPERS_BUT_ACTIVE );
// Search the last copper layer row index:
int lastCu = -1;
rowCount = GetLayerRowCount();
......@@ -353,16 +355,18 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( LAYER_NUM aLayer )
return true;
}
void PCB_LAYER_WIDGET::OnLayerSelected()
bool PCB_LAYER_WIDGET::OnLayerSelected()
{
if( !m_alwaysShowActiveCopperLayer )
return;
return false;
// postprocess after an active layer selection
// ensure active layer visible
wxCommandEvent event;
event.SetId( ID_ALWAYS_SHOW_NO_COPPERS_BUT_ACTIVE );
onPopupSelection( event );
return true;
}
......
......@@ -89,7 +89,15 @@ public:
void OnRenderEnable( int aId, bool isEnabled );
//-----</implement LAYER_WIDGET abstract callback functions>----------
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment