Gerbview: better management of d_codes list in toolbars.
This commit is contained in:
parent
3f1a90c8a4
commit
7909de6127
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors.
|
||||
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2016 KiCad Developers, see CHANGELOG.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
|
||||
|
@ -35,13 +35,13 @@
|
|||
|
||||
DCODE_SELECTION_BOX::DCODE_SELECTION_BOX( wxAuiToolBar* aParent, wxWindowID aId,
|
||||
const wxPoint& aLocation, const wxSize& aSize,
|
||||
const wxArrayString& aChoices ) :
|
||||
const wxArrayString* aChoices ) :
|
||||
wxComboBox( aParent, aId, wxEmptyString, aLocation, aSize, 0, NULL, wxCB_READONLY )
|
||||
{
|
||||
m_dcodeList = &aChoices;
|
||||
if( aChoices )
|
||||
// Append aChoices here is by far faster than use aChoices inside
|
||||
// the wxComboBox constructor
|
||||
Append(aChoices);
|
||||
Append( *aChoices );
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,27 +56,43 @@ int DCODE_SELECTION_BOX::GetSelectedDCodeId()
|
|||
|
||||
if( ii > 0 )
|
||||
{
|
||||
wxString msg = (*m_dcodeList)[ii].AfterFirst( wxChar( ' ' ) );
|
||||
// in strings displayed by the combo box, the dcode number
|
||||
// is the second word. get it:
|
||||
wxString msg = GetString( ii ).AfterFirst( ' ' ).BeforeFirst( ' ' );
|
||||
long id;
|
||||
msg.ToLong(&id);
|
||||
|
||||
if( msg.ToLong(&id) )
|
||||
return id;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* SetDCodeSelection
|
||||
* aDCodeId = the DCode Id to select or -1 to select "no dcode"
|
||||
* aDCodeId = the DCode Id to select or <= 0 to select "no selection"
|
||||
*/
|
||||
void DCODE_SELECTION_BOX::SetDCodeSelection( int aDCodeId )
|
||||
{
|
||||
if( aDCodeId > LAST_DCODE )
|
||||
aDCodeId = LAST_DCODE;
|
||||
wxString msg;
|
||||
|
||||
int index = 0;
|
||||
if( aDCodeId >= FIRST_DCODE )
|
||||
index = aDCodeId - FIRST_DCODE + 1;
|
||||
for( unsigned index = 1; index < GetCount(); ++index )
|
||||
{
|
||||
msg = GetString( index ).AfterFirst( ' ' ).BeforeFirst( ' ' );
|
||||
long id;
|
||||
|
||||
SetSelection(index);
|
||||
if( msg.ToLong(&id) && id == aDCodeId )
|
||||
{
|
||||
SetSelection( index );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SetSelection( 0 );
|
||||
}
|
||||
|
||||
|
||||
void DCODE_SELECTION_BOX::AppendDCodeList( const wxArrayString& aChoices )
|
||||
{
|
||||
Append( aChoices );
|
||||
}
|
||||
|
|
|
@ -35,24 +35,28 @@
|
|||
|
||||
class DCODE_SELECTION_BOX : public wxComboBox
|
||||
{
|
||||
private:
|
||||
const wxArrayString* m_dcodeList;
|
||||
|
||||
public: DCODE_SELECTION_BOX( wxAuiToolBar* aParent, wxWindowID aId,
|
||||
const wxPoint& aLocation, const wxSize& aSize,
|
||||
const wxArrayString& aChoices);
|
||||
const wxArrayString* aChoices = NULL );
|
||||
~DCODE_SELECTION_BOX();
|
||||
|
||||
/**
|
||||
* Function GetSelectedDCodeId
|
||||
* @return the current selected DCode Id or -1 if no dcode
|
||||
* @return the current selected DCode Id or 0 if no dcode
|
||||
*/
|
||||
int GetSelectedDCodeId();
|
||||
|
||||
/**
|
||||
* Function SetDCodeSelection
|
||||
* @param aDCodeId = the DCode Id to select or -1 to select "no dcode"
|
||||
* @param aDCodeId = the DCode Id to select or <= 0 to select "no dcode"
|
||||
*/
|
||||
void SetDCodeSelection( int aDCodeId );
|
||||
|
||||
/**
|
||||
* Function AppendDCodeList
|
||||
* @param aChoices = the DCode Id list to add to the combo box
|
||||
*/
|
||||
void AppendDCodeList( const wxArrayString& aChoices );
|
||||
};
|
||||
|
||||
#endif //CLASS_DCODESELECTIONBOX_H
|
||||
|
|
|
@ -95,7 +95,7 @@ GERBER_FILE_IMAGE::GERBER_FILE_IMAGE( int aLayer )
|
|||
m_IsVisible = true; // must be drawn
|
||||
m_PositiveDrawColor = WHITE; // The color used to draw positive items for this image
|
||||
|
||||
m_Selected_Tool = FIRST_DCODE;
|
||||
m_Selected_Tool = 0;
|
||||
m_FileFunction = NULL; // file function parameters
|
||||
|
||||
ResetDefaultValues();
|
||||
|
@ -209,7 +209,7 @@ void GERBER_FILE_IMAGE::ResetDefaultValues()
|
|||
m_FilesPtr = 0;
|
||||
m_PolygonFillMode = false;
|
||||
m_PolygonFillModeState = 0;
|
||||
m_Selected_Tool = FIRST_DCODE;
|
||||
m_Selected_Tool = 0;
|
||||
m_Last_Pen_Command = 0;
|
||||
m_Exposure = false;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version May 10 2016)
|
||||
// C++ code generated with wxFormBuilder (version May 6 2016)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO "NOT" EDIT THIS FILE!
|
||||
|
@ -58,7 +58,7 @@ DIALOG_DISPLAY_OPTIONS_BASE::DIALOG_DISPLAY_OPTIONS_BASE( wxWindow* parent, wxWi
|
|||
|
||||
wxString m_OptDisplayFlashedItemsChoices[] = { _("Sketch"), _("Filled") };
|
||||
int m_OptDisplayFlashedItemsNChoices = sizeof( m_OptDisplayFlashedItemsChoices ) / sizeof( wxString );
|
||||
m_OptDisplayFlashedItems = new wxRadioBox( this, wxID_ANY, _("Pads"), wxDefaultPosition, wxDefaultSize, m_OptDisplayFlashedItemsNChoices, m_OptDisplayFlashedItemsChoices, 1, wxRA_SPECIFY_COLS );
|
||||
m_OptDisplayFlashedItems = new wxRadioBox( this, wxID_ANY, _("Flashed items"), wxDefaultPosition, wxDefaultSize, m_OptDisplayFlashedItemsNChoices, m_OptDisplayFlashedItemsChoices, 1, wxRA_SPECIFY_COLS );
|
||||
m_OptDisplayFlashedItems->SetSelection( 1 );
|
||||
bMiddleSizer->Add( m_OptDisplayFlashedItems, 0, wxALL|wxEXPAND, 5 );
|
||||
|
||||
|
|
|
@ -603,7 +603,7 @@
|
|||
<property name="gripper">0</property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="label">Pads</property>
|
||||
<property name="label">Flashed items</property>
|
||||
<property name="majorDimension">1</property>
|
||||
<property name="max_size"></property>
|
||||
<property name="maximize_button">0</property>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version May 10 2016)
|
||||
// C++ code generated with wxFormBuilder (version May 6 2016)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO "NOT" EDIT THIS FILE!
|
||||
|
|
|
@ -417,6 +417,7 @@ void GERBVIEW_FRAME::syncLayerBox( bool aRebuildLayerBox )
|
|||
|
||||
if( m_DCodeSelector )
|
||||
{
|
||||
updateDCodeSelectBox();
|
||||
m_DCodeSelector->SetDCodeSelection( dcodeSelected );
|
||||
m_DCodeSelector->Enable( gerber != NULL );
|
||||
}
|
||||
|
@ -868,3 +869,9 @@ unsigned GERBVIEW_FRAME::ImagesMaxCount() const
|
|||
return m_gerberLayout->GetImagesList()->ImagesMaxCount();
|
||||
}
|
||||
|
||||
|
||||
void GERBVIEW_FRAME::unitsChangeRefresh()
|
||||
{ // Called on units change (see EDA_DRAW_FRAME)
|
||||
EDA_DRAW_FRAME::unitsChangeRefresh();
|
||||
updateDCodeSelectBox();
|
||||
}
|
|
@ -166,7 +166,6 @@ public:
|
|||
DCODE_SELECTION_BOX* m_DCodeSelector; // a list box to select the dcode Id to highlight.
|
||||
wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about
|
||||
// gerber data (format..)
|
||||
wxArrayString m_DCodesList; // an array string containing all decodes Id (10 to 999)
|
||||
|
||||
private:
|
||||
/// Auxiliary tool bar typically shown below the main tool bar at the top of the
|
||||
|
@ -192,6 +191,8 @@ private:
|
|||
void updateComponentListSelectBox();
|
||||
void updateNetnameListSelectBox();
|
||||
void updateAperAttributesSelectBox();
|
||||
void updateDCodeSelectBox();
|
||||
virtual void unitsChangeRefresh() override; // See class EDA_DRAW_FRAME
|
||||
|
||||
// An array string to store warning messages when reading a gerber file.
|
||||
wxArrayString m_Messages;
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
|
||||
void GERBVIEW_FRAME::ReCreateHToolbar( void )
|
||||
{
|
||||
int ii;
|
||||
wxString msg;
|
||||
|
||||
if( m_mainToolBar != NULL )
|
||||
|
@ -97,24 +96,6 @@ void GERBVIEW_FRAME::ReCreateHToolbar( void )
|
|||
|
||||
m_mainToolBar->AddControl( m_SelLayerBox );
|
||||
|
||||
m_mainToolBar->AddSeparator();
|
||||
|
||||
m_DCodesList.Alloc(TOOLS_MAX_COUNT+1);
|
||||
m_DCodesList.Add( _( "No tool" ) );
|
||||
|
||||
for( ii = FIRST_DCODE; ii < TOOLS_MAX_COUNT; ii++ )
|
||||
{
|
||||
msg = _( "Tool " );
|
||||
msg << ii;
|
||||
m_DCodesList.Add( msg );
|
||||
}
|
||||
|
||||
m_DCodeSelector = new DCODE_SELECTION_BOX( m_mainToolBar,
|
||||
ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
|
||||
wxDefaultPosition, wxSize( 150, -1 ),
|
||||
m_DCodesList );
|
||||
m_mainToolBar->AddControl( m_DCodeSelector );
|
||||
|
||||
m_TextInfo = new wxTextCtrl( m_mainToolBar, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
||||
wxDefaultSize, wxTE_READONLY );
|
||||
m_mainToolBar->AddControl( m_TextInfo );
|
||||
|
@ -132,6 +113,7 @@ void GERBVIEW_FRAME::ReCreateAuxiliaryToolbar()
|
|||
updateComponentListSelectBox();
|
||||
updateNetnameListSelectBox();
|
||||
updateAperAttributesSelectBox();
|
||||
updateDCodeSelectBox();
|
||||
|
||||
// combobox sizes can have changed: apply new best sizes
|
||||
wxSize size;
|
||||
|
@ -147,6 +129,10 @@ void GERBVIEW_FRAME::ReCreateAuxiliaryToolbar()
|
|||
size.x = std::max( size.x, 100 );
|
||||
m_SelAperAttributesBox->SetMinSize( size );
|
||||
|
||||
size = m_DCodeSelector->GetBestSize();
|
||||
size.x = std::max( size.x, 100 );
|
||||
m_DCodeSelector->SetMinSize( size );
|
||||
|
||||
m_auimgr.Update();
|
||||
return;
|
||||
}
|
||||
|
@ -155,28 +141,42 @@ void GERBVIEW_FRAME::ReCreateAuxiliaryToolbar()
|
|||
wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT );
|
||||
|
||||
// Creates box to display and choose components:
|
||||
wxStaticText* text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _("Cmp:") );
|
||||
m_auxiliaryToolBar->AddControl( text );
|
||||
m_SelComponentBox = new wxChoice( m_auxiliaryToolBar,
|
||||
ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
|
||||
m_SelComponentBox->SetToolTip( _("Selected a component and highlight its graphic items") );
|
||||
m_SelComponentBox->SetToolTip( _("Select a component and highlight items belonging to this component") );
|
||||
updateComponentListSelectBox();
|
||||
m_auxiliaryToolBar->AddControl( m_SelComponentBox );
|
||||
m_auxiliaryToolBar->AddSeparator();
|
||||
|
||||
// Creates choice box to display net names and highlight selected:
|
||||
text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _("Net:") );
|
||||
m_auxiliaryToolBar->AddControl( text );
|
||||
m_SelNetnameBox = new wxChoice( m_auxiliaryToolBar,
|
||||
ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
|
||||
m_SelNetnameBox->SetToolTip( _("Selected a net name and highlight graphic items belonging to this net") );
|
||||
m_SelNetnameBox->SetToolTip( _("Select a net name and highlight graphic items belonging to this net") );
|
||||
m_auxiliaryToolBar->AddControl( m_SelNetnameBox );
|
||||
updateNetnameListSelectBox();
|
||||
m_auxiliaryToolBar->AddSeparator();
|
||||
|
||||
// Creates choice box to display aperture attributes and highlight selected:
|
||||
text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _("Attr:") );
|
||||
m_auxiliaryToolBar->AddControl( text );
|
||||
m_SelAperAttributesBox = new wxChoice( m_auxiliaryToolBar,
|
||||
ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE );
|
||||
m_SelAperAttributesBox->SetToolTip( _("Selected an aperture attribute and highlight graphic items having this attribute") );
|
||||
m_SelAperAttributesBox->SetToolTip( _("Select an aperture attribute and highlight graphic items having this attribute") );
|
||||
m_auxiliaryToolBar->AddControl( m_SelAperAttributesBox );
|
||||
updateAperAttributesSelectBox();
|
||||
|
||||
m_auxiliaryToolBar->AddSeparator();
|
||||
text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _("DCode:") );
|
||||
m_auxiliaryToolBar->AddControl( text );
|
||||
m_DCodeSelector = new DCODE_SELECTION_BOX( m_auxiliaryToolBar,
|
||||
ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
|
||||
wxDefaultPosition, wxSize( 150, -1 ) );
|
||||
updateDCodeSelectBox();
|
||||
m_auxiliaryToolBar->AddControl( m_DCodeSelector );
|
||||
|
||||
// after adding the buttons to the toolbar, must call Realize()
|
||||
m_auxiliaryToolBar->Realize();
|
||||
|
@ -296,7 +296,64 @@ void GERBVIEW_FRAME::ReCreateOptToolbar( void )
|
|||
|
||||
#define NO_SELECTION_STRING _("<No selection>")
|
||||
|
||||
void GERBVIEW_FRAME:: updateComponentListSelectBox()
|
||||
void GERBVIEW_FRAME::updateDCodeSelectBox()
|
||||
{
|
||||
m_DCodeSelector->Clear();
|
||||
|
||||
// Add an empty string to deselect net highlight
|
||||
m_DCodeSelector->Append( NO_SELECTION_STRING );
|
||||
|
||||
int layer = getActiveLayer();
|
||||
GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
|
||||
|
||||
if( !gerber || gerber->GetDcodesCount() == 0 )
|
||||
{
|
||||
if( m_DCodeSelector->GetSelection() != 0 )
|
||||
m_DCodeSelector->SetSelection( 0 );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the aperture list of the current layer, and add it to the combo box:
|
||||
wxArrayString dcode_list;
|
||||
wxString msg;
|
||||
const char* units = g_UserUnit == INCHES ? "mils" : "mm";
|
||||
double scale = g_UserUnit == INCHES ? IU_PER_MILS : IU_PER_MM;
|
||||
|
||||
for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
|
||||
{
|
||||
D_CODE* dcode = gerber->GetDCODE( ii + FIRST_DCODE, false );
|
||||
|
||||
if( dcode == NULL )
|
||||
continue;
|
||||
|
||||
if( !dcode->m_InUse && !dcode->m_Defined )
|
||||
continue;
|
||||
|
||||
msg.Printf( "tool %d [%.3fx%.3f %s] %s",
|
||||
dcode->m_Num_Dcode,
|
||||
dcode->m_Size.y / scale, dcode->m_Size.x / scale,
|
||||
units,
|
||||
D_CODE::ShowApertureType( dcode->m_Shape )
|
||||
);
|
||||
if( !dcode->m_AperFunction.IsEmpty() )
|
||||
msg << ", " << dcode->m_AperFunction;
|
||||
|
||||
dcode_list.Add( msg );
|
||||
}
|
||||
|
||||
m_DCodeSelector->AppendDCodeList( dcode_list );
|
||||
|
||||
if( dcode_list.size() > 1 )
|
||||
{
|
||||
wxSize size = m_DCodeSelector->GetBestSize();
|
||||
size.x = std::max( size.x, 100 );
|
||||
m_DCodeSelector->SetMinSize( size );
|
||||
m_auimgr.Update();
|
||||
}
|
||||
}
|
||||
|
||||
void GERBVIEW_FRAME::updateComponentListSelectBox()
|
||||
{
|
||||
m_SelComponentBox->Clear();
|
||||
|
||||
|
@ -473,14 +530,22 @@ void GERBVIEW_FRAME::OnUpdateShowLayerManager( wxUpdateUIEvent& aEvent )
|
|||
|
||||
void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
|
||||
{
|
||||
if( !m_DCodeSelector )
|
||||
return;
|
||||
|
||||
int layer = getActiveLayer();
|
||||
GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
|
||||
int selected = ( gerber ) ? gerber->m_Selected_Tool : 0;
|
||||
|
||||
if( m_DCodeSelector && m_DCodeSelector->GetSelectedDCodeId() != selected )
|
||||
m_DCodeSelector->SetDCodeSelection( selected );
|
||||
|
||||
aEvent.Enable( gerber != NULL );
|
||||
|
||||
if( m_DCodeSelector->GetSelectedDCodeId() != selected )
|
||||
{
|
||||
m_DCodeSelector->SetDCodeSelection( selected );
|
||||
// Be sure the selection can be made. If no, set to
|
||||
// a correct value
|
||||
gerber->m_Selected_Tool = m_DCodeSelector->GetSelectedDCodeId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue