2011-09-23 20:00:30 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2011-09-23 20:00:30 +00:00
|
|
|
*
|
2014-11-23 11:41:57 +00:00
|
|
|
* Copyright (C) 2004-2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2011-09-23 20:00:30 +00:00
|
|
|
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2011-09-30 18:15:37 +00:00
|
|
|
* Copyright (C) 2010 KiCad Developers, see change_log.txt for contributors.
|
2011-09-23 20:00:30 +00:00
|
|
|
*
|
|
|
|
* 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 Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file class_gerbview_layer_widget.cpp
|
|
|
|
* @brief GerbView layers manager.
|
|
|
|
*/
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <pcbstruct.h>
|
|
|
|
#include <macros.h>
|
2012-05-04 17:44:42 +00:00
|
|
|
#include <class_gbr_layer_box_selector.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <gerbview.h>
|
2014-06-27 17:07:42 +00:00
|
|
|
#include <gerbview_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_GERBER.h>
|
|
|
|
#include <layer_widget.h>
|
|
|
|
#include <class_gerbview_layer_widget.h>
|
2014-11-22 11:52:57 +00:00
|
|
|
#include <class_X2_gerber_attributes.h>
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class GERBER_LAYER_WIDGET
|
|
|
|
* is here to implement the abtract functions of LAYER_WIDGET so they
|
|
|
|
* may be tied into the GERBVIEW_FRAME's data and so we can add a popup
|
2011-09-30 18:15:37 +00:00
|
|
|
* menu which is specific to Pcbnew's needs.
|
2011-09-23 20:00:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
GERBER_LAYER_WIDGET::GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFocusOwner,
|
|
|
|
int aPointSize ) :
|
|
|
|
LAYER_WIDGET( aParent, aFocusOwner, aPointSize ),
|
|
|
|
myframe( aParent )
|
|
|
|
{
|
2013-04-06 12:01:53 +00:00
|
|
|
m_alwaysShowActiveLayer = false;
|
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
ReFillRender();
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// Update default tabs labels for GerbView
|
2011-09-23 20:00:30 +00:00
|
|
|
SetLayersManagerTabsText( );
|
|
|
|
|
|
|
|
//-----<Popup menu>-------------------------------------------------
|
|
|
|
// handle the popup menu over the layer window.
|
|
|
|
m_LayerScrolledWindow->Connect( wxEVT_RIGHT_DOWN,
|
|
|
|
wxMouseEventHandler( GERBER_LAYER_WIDGET::onRightDownLayers ), NULL, this );
|
|
|
|
|
|
|
|
// since Popupmenu() calls this->ProcessEvent() we must call this->Connect()
|
|
|
|
// and not m_LayerScrolledWindow->Connect()
|
2014-11-22 11:52:57 +00:00
|
|
|
Connect( ID_LAYER_MANAGER_START, ID_LAYER_MANAGER_END,
|
2013-04-06 12:01:53 +00:00
|
|
|
wxEVT_COMMAND_MENU_SELECTED,
|
2011-09-23 20:00:30 +00:00
|
|
|
wxCommandEventHandler( GERBER_LAYER_WIDGET::onPopupSelection ), NULL, this );
|
|
|
|
|
|
|
|
// install the right click handler into each control at end of ReFill()
|
|
|
|
// using installRightLayerClickHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetLayersManagerTabsText
|
|
|
|
* Update the layer manager tabs labels
|
|
|
|
* Useful when changing Language or to set labels to a non default value
|
|
|
|
*/
|
|
|
|
void GERBER_LAYER_WIDGET::SetLayersManagerTabsText( )
|
|
|
|
{
|
|
|
|
m_notebook->SetPageText(0, _("Layer") );
|
|
|
|
m_notebook->SetPageText(1, _("Render") );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ReFillRender
|
|
|
|
* Rebuild Render for instance after the config is read
|
|
|
|
*/
|
|
|
|
void GERBER_LAYER_WIDGET::ReFillRender()
|
|
|
|
{
|
|
|
|
ClearRenderRows();
|
|
|
|
|
|
|
|
// Fixed "Rendering" tab rows within the LAYER_WIDGET, only the initial color
|
|
|
|
// is changed before appending to the LAYER_WIDGET. This is an automatic variable
|
|
|
|
// not a static variable, change the color & state after copying from code to renderRows
|
|
|
|
// on the stack.
|
2013-01-06 13:31:49 +00:00
|
|
|
LAYER_WIDGET::ROW renderRows[3] = {
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
#define RR LAYER_WIDGET::ROW // Render Row abreviation to reduce source width
|
|
|
|
|
|
|
|
// text id color tooltip checked
|
|
|
|
RR( _( "Grid" ), GERBER_GRID_VISIBLE, WHITE, _( "Show the (x,y) grid dots" ) ),
|
|
|
|
RR( _( "DCodes" ), DCODES_VISIBLE, WHITE, _( "Show DCodes identification" ) ),
|
2013-01-06 13:31:49 +00:00
|
|
|
RR( _( "Neg. Obj." ), NEGATIVE_OBJECTS_VISIBLE, DARKGRAY,
|
|
|
|
_( "Show negative objects in this color" ) ),
|
2011-09-23 20:00:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for( unsigned row=0; row<DIM(renderRows); ++row )
|
|
|
|
{
|
|
|
|
if( renderRows[row].color != -1 ) // does this row show a color?
|
|
|
|
{
|
2012-09-12 17:28:55 +00:00
|
|
|
renderRows[row].color = myframe->GetVisibleElementColor(
|
|
|
|
(GERBER_VISIBLE_ID)renderRows[row].id );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
2012-09-12 17:28:55 +00:00
|
|
|
renderRows[row].state = myframe->IsElementVisible(
|
|
|
|
(GERBER_VISIBLE_ID)renderRows[row].id );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AppendRenderRows( renderRows, DIM(renderRows) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void GERBER_LAYER_WIDGET::installRightLayerClickHandler()
|
|
|
|
{
|
|
|
|
int rowCount = GetLayerRowCount();
|
|
|
|
for( int row=0; row<rowCount; ++row )
|
|
|
|
{
|
|
|
|
for( int col=0; col<LYR_COLUMN_COUNT; ++col )
|
|
|
|
{
|
|
|
|
wxWindow* w = getLayerComp( row, col );
|
|
|
|
|
|
|
|
w->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler(
|
|
|
|
GERBER_LAYER_WIDGET::onRightDownLayers ), NULL, this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_LAYER_WIDGET::onRightDownLayers( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
wxMenu menu;
|
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
// Remember: menu text is capitalized (see our rules_for_capitalization_in_Kicad_UI.txt)
|
2013-04-06 12:01:53 +00:00
|
|
|
menu.Append( new wxMenuItem( &menu, ID_SHOW_ALL_LAYERS,
|
2012-02-17 19:43:43 +00:00
|
|
|
_("Show All Layers") ) );
|
|
|
|
|
2013-04-06 12:01:53 +00:00
|
|
|
menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_LAYERS_BUT_ACTIVE,
|
2012-02-17 19:43:43 +00:00
|
|
|
_( "Hide All Layers But Active" ) ) );
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2013-04-06 12:01:53 +00:00
|
|
|
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,
|
2012-02-17 19:43:43 +00:00
|
|
|
_( "Hide All Layers" ) ) );
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
menu.Append( new wxMenuItem( &menu, ID_SORT_GBR_LAYERS,
|
|
|
|
_( "Sort Layers if X2 Mode" ) ) );
|
2011-09-23 20:00:30 +00:00
|
|
|
PopupMenu( &menu );
|
|
|
|
|
|
|
|
passOnFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GERBER_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event )
|
|
|
|
{
|
2014-06-27 17:07:42 +00:00
|
|
|
int rowCount;
|
|
|
|
int menuId = event.GetId();
|
2015-01-17 08:01:16 +00:00
|
|
|
bool visible = (menuId == ID_SHOW_ALL_LAYERS) ? true : false;
|
2014-06-27 17:07:42 +00:00
|
|
|
long visibleLayers = 0;
|
2013-04-06 12:01:53 +00:00
|
|
|
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 );
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
switch( menuId )
|
|
|
|
{
|
2013-04-06 12:01:53 +00:00
|
|
|
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:
|
2011-09-23 20:00:30 +00:00
|
|
|
rowCount = GetLayerRowCount();
|
|
|
|
for( int row=0; row < rowCount; ++row )
|
|
|
|
{
|
2014-07-20 17:41:12 +00:00
|
|
|
wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
|
2014-06-27 17:07:42 +00:00
|
|
|
int layer = getDecodedId( cb->GetId() );
|
2012-02-17 19:43:43 +00:00
|
|
|
bool loc_visible = visible;
|
2013-04-06 12:01:53 +00:00
|
|
|
|
|
|
|
if( force_active_layer_visible && (layer == myframe->getActiveLayer() ) )
|
2012-02-17 19:43:43 +00:00
|
|
|
loc_visible = true;
|
|
|
|
|
|
|
|
cb->SetValue( loc_visible );
|
2013-04-06 12:01:53 +00:00
|
|
|
|
2012-02-17 19:43:43 +00:00
|
|
|
if( loc_visible )
|
2014-06-27 17:07:42 +00:00
|
|
|
visibleLayers |= 1 << row;
|
2011-09-23 20:00:30 +00:00
|
|
|
else
|
2014-06-27 17:07:42 +00:00
|
|
|
visibleLayers &= ~( 1 << row );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 17:44:42 +00:00
|
|
|
myframe->SetVisibleLayers( visibleLayers );
|
2011-12-22 13:28:11 +00:00
|
|
|
myframe->GetCanvas()->Refresh();
|
2011-09-23 20:00:30 +00:00
|
|
|
break;
|
2014-11-22 11:52:57 +00:00
|
|
|
|
|
|
|
case ID_SORT_GBR_LAYERS:
|
|
|
|
g_GERBER_List.SortImagesByZOrder( myframe->GetItemsList() );
|
|
|
|
myframe->ReFillLayerWidget();
|
|
|
|
myframe->syncLayerBox();
|
|
|
|
myframe->GetCanvas()->Refresh();
|
|
|
|
break;
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-06 12:01:53 +00:00
|
|
|
bool GERBER_LAYER_WIDGET::OnLayerSelected()
|
|
|
|
{
|
|
|
|
if( !m_alwaysShowActiveLayer )
|
|
|
|
return false;
|
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
// postprocess after active layer selection
|
2013-04-06 12:01:53 +00:00
|
|
|
// ensure active layer visible
|
|
|
|
wxCommandEvent event;
|
|
|
|
event.SetId( ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE );
|
|
|
|
onPopupSelection( event );
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
void GERBER_LAYER_WIDGET::ReFill()
|
|
|
|
{
|
2014-11-22 11:52:57 +00:00
|
|
|
Freeze();
|
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
ClearLayerRows();
|
2011-12-22 13:28:11 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2014-11-22 11:52:57 +00:00
|
|
|
wxString msg = g_GERBER_List.GetDisplayName( layer );
|
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
AppendLayerRow( LAYER_WIDGET::ROW( msg, layer,
|
2012-05-04 17:44:42 +00:00
|
|
|
myframe->GetLayerColor( layer ), wxEmptyString, true ) );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
Thaw();
|
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
installRightLayerClickHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----<LAYER_WIDGET callbacks>-------------------------------------------
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
void GERBER_LAYER_WIDGET::OnLayerColorChange( int aLayer, EDA_COLOR_T aColor )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2012-05-04 17:44:42 +00:00
|
|
|
myframe->SetLayerColor( aLayer, aColor );
|
2011-09-23 20:00:30 +00:00
|
|
|
myframe->m_SelLayerBox->ResyncBitmapOnly();
|
2011-12-22 13:28:11 +00:00
|
|
|
myframe->GetCanvas()->Refresh();
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
bool GERBER_LAYER_WIDGET::OnLayerSelect( int aLayer )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
|
|
|
// the layer change from the GERBER_LAYER_WIDGET can be denied by returning
|
|
|
|
// false from this function.
|
2014-06-27 17:07:42 +00:00
|
|
|
int layer = myframe->getActiveLayer( );
|
2011-09-23 20:00:30 +00:00
|
|
|
myframe->setActiveLayer( aLayer, false );
|
|
|
|
myframe->syncLayerBox();
|
2011-12-22 13:28:11 +00:00
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
if( layer != myframe->getActiveLayer( ) )
|
2013-04-06 12:01:53 +00:00
|
|
|
{
|
|
|
|
if( ! OnLayerSelected() )
|
|
|
|
myframe->GetCanvas()->Refresh();
|
|
|
|
}
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
void GERBER_LAYER_WIDGET::OnLayerVisible( int aLayer, bool isVisible, bool isFinal )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2014-06-27 17:07:42 +00:00
|
|
|
long visibleLayers = myframe->GetVisibleLayers();
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
if( isVisible )
|
2014-06-27 17:07:42 +00:00
|
|
|
visibleLayers |= 1 << aLayer;
|
2011-09-23 20:00:30 +00:00
|
|
|
else
|
2014-06-27 17:07:42 +00:00
|
|
|
visibleLayers &= ~( 1 << aLayer );
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2012-05-04 17:44:42 +00:00
|
|
|
myframe->SetVisibleLayers( visibleLayers );
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
if( isFinal )
|
2011-12-22 13:28:11 +00:00
|
|
|
myframe->GetCanvas()->Refresh();
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
void GERBER_LAYER_WIDGET::OnRenderColorChange( int aId, EDA_COLOR_T aColor )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2012-09-12 17:28:55 +00:00
|
|
|
myframe->SetVisibleElementColor( (GERBER_VISIBLE_ID)aId, aColor );
|
2011-12-22 13:28:11 +00:00
|
|
|
myframe->GetCanvas()->Refresh();
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GERBER_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled )
|
|
|
|
{
|
2012-09-12 17:28:55 +00:00
|
|
|
myframe->SetElementVisibility( (GERBER_VISIBLE_ID)aId, isEnabled );
|
2011-12-22 13:28:11 +00:00
|
|
|
myframe->GetCanvas()->Refresh();
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----</LAYER_WIDGET callbacks>------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Virtual Function useAlternateBitmap
|
|
|
|
* return true if bitmaps shown in Render layer list
|
|
|
|
* must be alternate bitmaps, or false to use "normal" bitmaps
|
|
|
|
*/
|
|
|
|
bool GERBER_LAYER_WIDGET::useAlternateBitmap(int aRow)
|
|
|
|
{
|
2014-11-22 11:52:57 +00:00
|
|
|
return g_GERBER_List.IsUsed( aRow );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
/*
|
2011-09-23 20:00:30 +00:00
|
|
|
* Update the layer manager icons (layers only)
|
|
|
|
* Useful when loading a file or clearing a layer because they change
|
|
|
|
*/
|
|
|
|
void GERBER_LAYER_WIDGET::UpdateLayerIcons()
|
|
|
|
{
|
|
|
|
int row_count = GetLayerRowCount();
|
|
|
|
for( int row = 0; row < row_count ; row++ )
|
|
|
|
{
|
2014-07-20 17:41:12 +00:00
|
|
|
wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( row, COLUMN_ICON_ACTIVE );
|
2011-09-23 20:00:30 +00:00
|
|
|
if( bm == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( row == m_CurrentRow )
|
2014-11-22 11:52:57 +00:00
|
|
|
bm->SetBitmap( useAlternateBitmap(row) ? *m_RightArrowAlternateBitmap :
|
|
|
|
*m_RightArrowBitmap );
|
2011-09-23 20:00:30 +00:00
|
|
|
else
|
|
|
|
bm->SetBitmap( useAlternateBitmap(row) ? *m_BlankAlternateBitmap : *m_BlankBitmap );
|
|
|
|
}
|
|
|
|
}
|