Commit add4d5eb authored by Dick Hollenbeck's avatar Dick Hollenbeck

re-work the LSET(int,...) constructor

parent 0a1665d5
...@@ -25,7 +25,7 @@ bool LAYER_SELECTOR::SetLayersHotkeys( bool value ) ...@@ -25,7 +25,7 @@ bool LAYER_SELECTOR::SetLayersHotkeys( bool value )
} }
void LAYER_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_ID aLayer ) void LAYER_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer )
{ {
wxMemoryDC bmpDC; wxMemoryDC bmpDC;
wxBrush brush; wxBrush brush;
...@@ -120,7 +120,7 @@ void LAYER_BOX_SELECTOR::ResyncBitmapOnly() ...@@ -120,7 +120,7 @@ void LAYER_BOX_SELECTOR::ResyncBitmapOnly()
for( LAYER_NUM i = 0; i < elements; ++i ) for( LAYER_NUM i = 0; i < elements; ++i )
{ {
wxBitmap layerbmp( 14, 14 ); wxBitmap layerbmp( 14, 14 );
SetBitmapLayer( layerbmp, ToLAYER_ID( i ) ); SetBitmapLayer( layerbmp, i );
} }
} }
...@@ -37,24 +37,34 @@ LSET::LSET( const LAYER_ID* aArray, unsigned aCount ) ...@@ -37,24 +37,34 @@ LSET::LSET( const LAYER_ID* aArray, unsigned aCount )
} }
LSET::LSET( size_t aIdCount, ... ) LSET::LSET( unsigned aIdCount, LAYER_ID aFirst, ... )
{ {
va_list ap; // The constructor, without the mandatory aFirst argument, could have been confused
// by the compiler with the LSET( LAYER_ID ). With aFirst, that ambiguity is not
// present. Therefore aIdCount must always be >=1.
wxASSERT_MSG( aIdCount > 0, wxT( "aIdCount must be >= 1" ) );
va_start( ap, aIdCount ); set( aFirst );
for( size_t i=0; i<aIdCount; ++i ) if( --aIdCount )
{ {
LAYER_ID id = (LAYER_ID) va_arg( ap, int ); va_list ap;
// printf( "%s: id:%d LAYER_ID_COUNT:%d\n", __func__, id, LAYER_ID_COUNT ); va_start( ap, aFirst );
assert( unsigned( id ) < LAYER_ID_COUNT ); for( unsigned i=0; i<aIdCount; ++i )
{
LAYER_ID id = (LAYER_ID) va_arg( ap, int );
set( id ); // printf( "%s: id:%d LAYER_ID_COUNT:%d\n", __func__, id, LAYER_ID_COUNT );
}
assert( unsigned( id ) < LAYER_ID_COUNT );
set( id );
}
va_end( ap ); va_end( ap );
}
} }
...@@ -633,4 +643,10 @@ LSEQ LSET::UIOrder() const ...@@ -633,4 +643,10 @@ LSEQ LSET::UIOrder() const
return Seq( order, DIM( order ) ); return Seq( order, DIM( order ) );
} }
LAYER_ID ToLAYER_ID( int aLayer );
LAYER_ID ToLAYER_ID( int aLayer )
{
wxASSERT( unsigned( aLayer ) < LAYER_ID_COUNT );
return LAYER_ID( aLayer );
}
...@@ -49,7 +49,7 @@ void GBR_LAYER_BOX_SELECTOR::Resync() ...@@ -49,7 +49,7 @@ void GBR_LAYER_BOX_SELECTOR::Resync()
continue; continue;
// Prepare Bitmap // Prepare Bitmap
SetBitmapLayer( layerbmp, ToLAYER_ID( layerid ) ); SetBitmapLayer( layerbmp, layerid );
layername = GetLayerName( layerid ); layername = GetLayerName( layerid );
......
...@@ -35,12 +35,12 @@ public: ...@@ -35,12 +35,12 @@ public:
// Virtual function pure because GerbView uses its own functions in a derived class // Virtual function pure because GerbView uses its own functions in a derived class
virtual bool IsLayerEnabled( LAYER_NUM aLayer ) const = 0; virtual bool IsLayerEnabled( LAYER_NUM aLayer ) const = 0;
bool SetLayersOrdered(bool value); bool SetLayersOrdered( bool value );
bool SetLayersHotkeys(bool value); bool SetLayersHotkeys( bool value );
protected: protected:
// Fills the layer bitmap aLayerbmp with the layer color // Fills the layer bitmap aLayerbmp with the layer color
void SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_ID aLayer ); void SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer );
}; };
......
...@@ -149,7 +149,11 @@ typedef std::vector<LAYER_ID> BASE_SEQ; ...@@ -149,7 +149,11 @@ typedef std::vector<LAYER_ID> BASE_SEQ;
* <code> * <code>
* *
* for( LSEQ cu_stack = aSet.CuStack(); cu_stack; ++cu_stack ) * for( LSEQ cu_stack = aSet.CuStack(); cu_stack; ++cu_stack )
* {
* layer_id = *cu_stack; * layer_id = *cu_stack;
* :
* things to do with layer_id;
* }
* *
* </code> * </code>
*/ */
...@@ -198,13 +202,24 @@ class LSET : public BASE_SET ...@@ -198,13 +202,24 @@ class LSET : public BASE_SET
{ {
public: public:
// The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
// That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
// LSET s = 0; needs to be removed from the code, this accomplishes that.
// Remember LSET( LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
// to prevent that surprize. Therefore LSET's constructor suite is significantly
// different than the base class from which it is derived.
// Other member functions (non-constructor functions) are identical to the base
// class's and therefore are re-used from the base class.
/** /**
* Constructor LSET() * Constructor LSET()
* creates an empty (cleared) set. * creates an empty (cleared) set.
*/ */
LSET() : LSET() :
BASE_SET() BASE_SET() // all bits are set to zero in BASE_SET()
{} {
}
LSET( const BASE_SET& aOther ) : LSET( const BASE_SET& aOther ) :
BASE_SET( aOther ) BASE_SET( aOther )
...@@ -214,12 +229,11 @@ public: ...@@ -214,12 +229,11 @@ public:
/** /**
* Constructor LSET( LAYER_ID ) * Constructor LSET( LAYER_ID )
* takes a LAYER_ID and sets that bit. This makes the following code into * takes a LAYER_ID and sets that bit. This makes the following code into
* a bug typically: * a bug:
* *
* <code> LSET s = 0; </code> * <code> LSET s = 0; </code>
* *
* since that will call this constructor and set bit zero, probably not what was * Instead use:
* intended. Use
* *
* <code> * <code>
* LSET s; * LSET s;
...@@ -239,12 +253,16 @@ public: ...@@ -239,12 +253,16 @@ public:
LSET( const LAYER_ID* aArray, unsigned aCount ); LSET( const LAYER_ID* aArray, unsigned aCount );
/** /**
* Constructor LSET( int, ...) * Constructor LSET( unsigned, LAYER_ID, ...)
* takes a variable number of LAYER_IDs in the argument list to construct * takes one or more LAYER_IDs in the argument list to construct
* the set. Typically used only in static construction. * the set. Typically only used in static construction.
*
* @param aIdCount is the number of LAYER_IDs which follow. * @param aIdCount is the number of LAYER_IDs which follow.
* @param aFirst is the first included in @a aIdCount and must always be present, and can
* be followed by any number of additional LAYER_IDs so long as @a aIdCount accurately
* reflects the count.
*/ */
LSET( size_t aIdCount, ... ); LSET( unsigned aIdCount, LAYER_ID aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
/** /**
* Function Name * Function Name
......
...@@ -607,7 +607,7 @@ public: ...@@ -607,7 +607,7 @@ public:
* @return the selected layer id * @return the selected layer id
*/ */
LAYER_ID SelectLayer( LAYER_ID aDefaultLayer, LAYER_ID SelectLayer( LAYER_ID aDefaultLayer,
LSET aNotAllowedLayersMask = 0, LSET aNotAllowedLayersMask = LSET(),
wxPoint aDlgPosition = wxDefaultPosition ); wxPoint aDlgPosition = wxDefaultPosition );
/* Display a list of two copper layers to choose a pair of copper layers /* Display a list of two copper layers to choose a pair of copper layers
......
...@@ -363,7 +363,6 @@ public: ...@@ -363,7 +363,6 @@ public:
int GetSubRatsnest() const { return m_SubRatsnest; } int GetSubRatsnest() const { return m_SubRatsnest; }
void SetSubRatsnest( int aSubRatsnest ) { m_SubRatsnest = aSubRatsnest; } void SetSubRatsnest( int aSubRatsnest ) { m_SubRatsnest = aSubRatsnest; }
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
bool IsOnLayer( LAYER_ID aLayer ) const bool IsOnLayer( LAYER_ID aLayer ) const
......
...@@ -268,7 +268,8 @@ void DIALOG_COPPER_ZONE::initDialog() ...@@ -268,7 +268,8 @@ void DIALOG_COPPER_ZONE::initDialog()
imageList->Add( makeLayerBitmap( layerColor ) ); imageList->Add( makeLayerBitmap( layerColor ) );
int itemIndex = m_LayerSelectionCtrl->InsertItem( 0, msg, layer ); int itemIndex = m_LayerSelectionCtrl->InsertItem(
m_LayerSelectionCtrl->GetItemCount(), msg, layer );
if( m_settings.m_CurrentZone_Layer == layer ) if( m_settings.m_CurrentZone_Layer == layer )
m_LayerSelectionCtrl->Select( itemIndex ); m_LayerSelectionCtrl->Select( itemIndex );
......
...@@ -80,6 +80,7 @@ static LSEQ dlg_layers() ...@@ -80,6 +80,7 @@ static LSEQ dlg_layers()
F_Mask, F_Mask,
F_Cu, F_Cu,
In1_Cu,
In2_Cu, In2_Cu,
In3_Cu, In3_Cu,
In4_Cu, In4_Cu,
...@@ -360,14 +361,19 @@ DIALOG_LAYERS_SETUP::DIALOG_LAYERS_SETUP( wxTopLevelWindow* aParent, BOARD* aBoa ...@@ -360,14 +361,19 @@ DIALOG_LAYERS_SETUP::DIALOG_LAYERS_SETUP( wxTopLevelWindow* aParent, BOARD* aBoa
void DIALOG_LAYERS_SETUP::showCopperChoice( int copperCount ) void DIALOG_LAYERS_SETUP::showCopperChoice( int copperCount )
{ {
static const int copperCounts[] = { 2,4,6,8,10,12,14,16 }; if( copperCount > MAX_CU_LAYERS )
copperCount = MAX_CU_LAYERS;
for( unsigned i = 0; i<sizeof(copperCounts); ++i ) if( copperCount < 2 )
copperCount = 2;
for( int lyrCnt = 2; lyrCnt <= MAX_CU_LAYERS; lyrCnt += 2 )
{ {
// note this will change a one layer board to 2: // note this will change a one layer board to 2:
if( copperCount <= copperCounts[i] ) if( copperCount <= lyrCnt )
{ {
m_CopperLayersChoice->SetSelection(i); int idx = lyrCnt/2 - 1;
m_CopperLayersChoice->SetSelection(idx);
break; break;
} }
} }
......
...@@ -42,7 +42,7 @@ DIALOG_LAYERS_SETUP_BASE::DIALOG_LAYERS_SETUP_BASE( wxWindow* parent, wxWindowID ...@@ -42,7 +42,7 @@ DIALOG_LAYERS_SETUP_BASE::DIALOG_LAYERS_SETUP_BASE( wxWindow* parent, wxWindowID
m_staticTextCopperLayers->Wrap( -1 ); m_staticTextCopperLayers->Wrap( -1 );
bCopperLayersSizer->Add( m_staticTextCopperLayers, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); bCopperLayersSizer->Add( m_staticTextCopperLayers, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
wxString m_CopperLayersChoiceChoices[] = { _("2"), _("4"), _("6"), _("8"), _("10"), _("12"), _("14"), _("16"), _("18"), _("20"), _("22"), _("24"), _("26"), _("27"), _("28"), _("30"), _("32") }; wxString m_CopperLayersChoiceChoices[] = { _("2"), _("4"), _("6"), _("8"), _("10"), _("12"), _("14"), _("16"), _("18"), _("20"), _("22"), _("24"), _("26"), _("28"), _("30"), _("32") };
int m_CopperLayersChoiceNChoices = sizeof( m_CopperLayersChoiceChoices ) / sizeof( wxString ); int m_CopperLayersChoiceNChoices = sizeof( m_CopperLayersChoiceChoices ) / sizeof( wxString );
m_CopperLayersChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_CopperLayersChoiceNChoices, m_CopperLayersChoiceChoices, 0 ); m_CopperLayersChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_CopperLayersChoiceNChoices, m_CopperLayersChoiceChoices, 0 );
m_CopperLayersChoice->SetSelection( 3 ); m_CopperLayersChoice->SetSelection( 3 );
......
...@@ -394,7 +394,7 @@ ...@@ -394,7 +394,7 @@
<property name="caption"></property> <property name="caption"></property>
<property name="caption_visible">1</property> <property name="caption_visible">1</property>
<property name="center_pane">0</property> <property name="center_pane">0</property>
<property name="choices">&quot;2&quot; &quot;4&quot; &quot;6&quot; &quot;8&quot; &quot;10&quot; &quot;12&quot; &quot;14&quot; &quot;16&quot; &quot;18&quot; &quot;20&quot; &quot;22&quot; &quot;24&quot; &quot;26&quot; &quot;27&quot; &quot;28&quot; &quot;30&quot; &quot;32&quot;</property> <property name="choices">&quot;2&quot; &quot;4&quot; &quot;6&quot; &quot;8&quot; &quot;10&quot; &quot;12&quot; &quot;14&quot; &quot;16&quot; &quot;18&quot; &quot;20&quot; &quot;22&quot; &quot;24&quot; &quot;26&quot; &quot;28&quot; &quot;30&quot; &quot;32&quot;</property>
<property name="close_button">1</property> <property name="close_button">1</property>
<property name="context_help"></property> <property name="context_help"></property>
<property name="context_menu">1</property> <property name="context_menu">1</property>
...@@ -67,7 +67,7 @@ void PCB_PARSER::init() ...@@ -67,7 +67,7 @@ void PCB_PARSER::init()
std::string untranslated = TO_UTF8( wxString( LSET::Name( LAYER_ID( layer ) ) ) ); std::string untranslated = TO_UTF8( wxString( LSET::Name( LAYER_ID( layer ) ) ) );
m_layerIndices[ untranslated ] = LAYER_ID( layer ); m_layerIndices[ untranslated ] = LAYER_ID( layer );
m_layerMasks[ untranslated ] = LSET( layer ); m_layerMasks[ untranslated ] = LSET( LAYER_ID( layer ) );
} }
m_layerMasks[ "*.Cu" ] = LSET::AllCuMask(); m_layerMasks[ "*.Cu" ] = LSET::AllCuMask();
......
...@@ -366,9 +366,12 @@ PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings() ...@@ -366,9 +366,12 @@ PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings()
&DisplayOpt.DisplayZonesMode, 0, 0, 2 ) ); &DisplayOpt.DisplayZonesMode, 0, 0, 2 ) );
// layer colors: // layer colors:
wxASSERT( DIM( cds.m_LayersColors ) == LAYER_ID_COUNT );
for( int i = 0; i<LAYER_ID_COUNT; ++i ) for( int i = 0; i<LAYER_ID_COUNT; ++i )
{ {
wxString vn = wxString::Format( wxT( "ColorLayer%dEx" ), i ); wxString vn = wxString::Format(
wxT( "ColorPCBLayer:%s" ),
LSET::Name( LAYER_ID( i ) ) );
m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, vn, LOC_COLOR( i ), cds.m_LayersColors[i] ) ); m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, vn, LOC_COLOR( i ), cds.m_LayersColors[i] ) );
} }
......
...@@ -81,7 +81,6 @@ public: ...@@ -81,7 +81,6 @@ public:
{ {
m_plotter = aPlotter; m_plotter = aPlotter;
m_board = aBoard; m_board = aBoard;
m_layerMask = 0;
} }
/** /**
......
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