7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-07 21:05:32 +00:00

Factored out text anchor drawing

More layer classification cleanup
This commit is contained in:
Lorenzo Marcantonio 2013-04-09 18:00:46 +02:00
parent 0de48234bc
commit b525e3be55
49 changed files with 210 additions and 223 deletions

View File

@ -106,14 +106,14 @@ void LAYER_BOX_SELECTOR::ResyncBitmapOnly()
}
void LAYER_BOX_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayerIndex )
void LAYER_BOX_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer )
{
wxMemoryDC bmpDC;
wxBrush brush;
// Prepare Bitmap
bmpDC.SelectObject( aLayerbmp );
brush.SetColour( MakeColour( GetLayerColor( aLayerIndex ) ) );
brush.SetColour( MakeColour( GetLayerColor( aLayer ) ) );
brush.SetStyle( wxSOLID );
bmpDC.SetBrush( brush );

View File

@ -29,7 +29,7 @@
#include <cstdlib> // bsearch()
#include <cctype>
#include <macros.h>
#include <dsnlexer.h>
//#include "fctsys.h"

View File

@ -269,22 +269,12 @@ void EDA_TEXT::DrawOneLineOfText( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
if( aDrawMode != -1 )
GRSetDrawMode( aDC, aDrawMode );
/* Draw text anchor, if allowed */
// Draw text anchor, if requested
if( aAnchor_color != UNSPECIFIED_COLOR )
{
int anchor_size = aDC->DeviceToLogicalXRel( 2 );
aAnchor_color = (EDA_COLOR_T) ( aAnchor_color & MASKCOLOR );
int cX = aPos.x + aOffset.x;
int cY = aPos.y + aOffset.y;
GRLine( aPanel->GetClipBox(), aDC, cX - anchor_size, cY,
cX + anchor_size, cY, 0, aAnchor_color );
GRLine( aPanel->GetClipBox(), aDC, cX, cY - anchor_size,
cX, cY + anchor_size, 0, aAnchor_color );
GRDrawAnchor( aPanel->GetClipBox(), aDC,
aPos.x + aOffset.x, aPos.y + aOffset.y,
DIM_ANCRE_TEXTE, aAnchor_color );
}
if( aFillMode == SKETCH )

View File

@ -1551,3 +1551,16 @@ EDA_COLOR_T ColorFindNearest( const wxColour &aColor )
return candidate;
}
void GRDrawAnchor( EDA_RECT *aClipBox, wxDC *aDC, int x, int y,
int aSize, EDA_COLOR_T aColor )
{
int anchor_size = aDC->DeviceToLogicalXRel( aSize );
GRLine( aClipBox, aDC,
x - anchor_size, y,
x + anchor_size, y, 0, aColor );
GRLine( aClipBox, aDC,
x, y - anchor_size,
x, y + anchor_size, 0, aColor );
}

View File

@ -30,6 +30,7 @@
#include <wxstruct.h>
#include <dialog_helpers.h>
#include <base_units.h>
#include <macros.h>
/*******************************************************/

View File

@ -28,7 +28,6 @@ typedef boost::ptr_vector< COMPONENT_INFO > COMPONENT_LIST;
extern const wxString FootprintAliasFileExtension;
extern const wxString RetroFileExtension;
extern const wxString RetroFileWildcard;
extern const wxString FootprintAliasFileWildcard;
extern const wxString titleLibLoadError;

View File

@ -65,18 +65,18 @@ void GBR_LAYER_BOX_SELECTOR::Resync()
// Returns a color index from the layer id
EDA_COLOR_T GBR_LAYER_BOX_SELECTOR::GetLayerColor( LAYER_NUM aLayerIndex ) const
EDA_COLOR_T GBR_LAYER_BOX_SELECTOR::GetLayerColor( LAYER_NUM aLayer ) const
{
GERBVIEW_FRAME* frame = (GERBVIEW_FRAME*) GetParent()->GetParent();
return frame->GetLayerColor( aLayerIndex );
return frame->GetLayerColor( aLayer );
}
// Returns the name of the layer id
wxString GBR_LAYER_BOX_SELECTOR::GetLayerName( LAYER_NUM aLayerIndex ) const
wxString GBR_LAYER_BOX_SELECTOR::GetLayerName( LAYER_NUM aLayer ) const
{
wxString name;
name.Printf( _( "Layer %d" ), aLayerIndex + 1 );
name.Printf( _( "Layer %d" ), aLayer + 1 );
return name;
}

View File

@ -37,15 +37,15 @@ public:
// Returns a color index from the layer id
// Virtual function
EDA_COLOR_T GetLayerColor( LAYER_NUM aLayerIndex ) const;
EDA_COLOR_T GetLayerColor( LAYER_NUM aLayer ) const;
// Returns true if the layer id is enabled (i.e. is it should be displayed)
// Virtual function
bool IsLayerEnabled( LAYER_NUM aLayerIndex ) const { return true; };
bool IsLayerEnabled( LAYER_NUM aLayer ) const { return true; };
// Returns the name of the layer id
// Virtual function
wxString GetLayerName( LAYER_NUM aLayerIndex ) const;
wxString GetLayerName( LAYER_NUM aLayer ) const;
};
#endif //CLASS_GBR_LAYER_BOX_SELECTOR_H

View File

@ -24,12 +24,12 @@ GBR_LAYOUT::~GBR_LAYOUT()
/* Function IsLayerVisible
* tests whether a given layer is visible
* param aLayerIndex = The index of the layer to be tested
* param aLayer = The layer to be tested
* return bool - true if the layer is visible.
*/
bool GBR_LAYOUT::IsLayerVisible( LAYER_NUM aLayerIndex ) const
bool GBR_LAYOUT::IsLayerVisible( LAYER_NUM aLayer ) const
{
return m_printLayersMask & GetLayerMask( aLayerIndex );
return m_printLayersMask & GetLayerMask( aLayer );
}

View File

@ -99,10 +99,10 @@ public:
/**
* Function IsLayerVisible
* tests whether a given layer is visible
* @param aLayerIndex = The index of the layer to be tested
* @param aLayer = The layer to be tested
* @return bool - true if the layer is visible.
*/
bool IsLayerVisible( LAYER_NUM aLayerIndex ) const;
bool IsLayerVisible( LAYER_NUM aLayer ) const;
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const; // overload

View File

@ -139,7 +139,7 @@ void DIALOG_PRINT_USING_PRINTER::InitValues( )
layer_max = NB_LAYERS;
// Create layer list
for(LAYER_NUM ii = FIRST_LAYER; ii < layer_max; ++ii )
for( LAYER_NUM ii = FIRST_LAYER; ii < layer_max; ++ii )
{
LAYER_MSK mask = GetLayerMask( ii );
msg = _( "Layer" );

View File

@ -195,7 +195,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* LayerLookUpTable )
LAYER_NUM layer = gerb_item->GetLayer();
LAYER_NUM pcb_layer_number = LayerLookUpTable[layer];
if( pcb_layer_number < FIRST_LAYER || pcb_layer_number > LAST_NON_COPPER_LAYER )
if( !IsPcbLayer( pcb_layer_number ) )
continue;
if( pcb_layer_number > LAST_COPPER_LAYER )

View File

@ -558,15 +558,15 @@ void GERBVIEW_FRAME::SetVisibleLayers( LAYER_MSK aLayerMask )
/**
* Function IsLayerVisible
* tests whether a given layer is visible
* @param aLayerIndex = The index of the layer to be tested
* @param aLayer = The layer to be tested
* @return bool - true if the layer is visible.
*/
bool GERBVIEW_FRAME::IsLayerVisible( LAYER_NUM aLayerIndex ) const
bool GERBVIEW_FRAME::IsLayerVisible( LAYER_NUM aLayer ) const
{
if( ! m_DisplayOptions.m_IsPrinting )
return m_LayersManager->IsLayerVisible( aLayerIndex );
return m_LayersManager->IsLayerVisible( aLayer );
else
return GetLayout()->IsLayerVisible( aLayerIndex );
return GetLayout()->IsLayerVisible( aLayer );
}

View File

@ -313,10 +313,10 @@ public:
/**
* Function IsLayerVisible
* tests whether a given layer is visible
* @param aLayerIndex = The index of the layer to be tested
* @param aLayer = The layer to be tested
* @return bool - true if the layer is visible.
*/
bool IsLayerVisible( LAYER_NUM aLayerIndex ) const;
bool IsLayerVisible( LAYER_NUM aLayer ) const;
/**
* Function GetVisibleElementColor

View File

@ -11,6 +11,7 @@
#include <class_GERBER.h>
#include <html_messagebox.h>
#include <macros.h>
/* Read a gerber file, RS274D or RS274X format.
*/

View File

@ -360,12 +360,12 @@ void LAYERS_MAP_DIALOG::OnSelectLayer( wxCommandEvent& event )
}
LAYER_NUM jj = m_layersLookUpTable[m_buttonTable[ii]];
if( ( jj < FIRST_LAYER ) || ( jj > NB_LAYERS ) )
if( !IsValidLayer( jj ) )
jj = LAYER_N_BACK; // (Defaults to "Copper" layer.)
jj = m_Parent->SelectPCBLayer( jj, m_exportBoardCopperLayersCount, true );
if( ( jj < FIRST_LAYER ) || ( jj > NB_LAYERS ) )
if( !IsValidLayer( jj ) )
return;
if( jj != m_layersLookUpTable[m_buttonTable[ii]] )

View File

@ -75,26 +75,22 @@ public:
/**
* Function IsLayerVisible
* tests whether a given layer is visible
* @param aLayerIndex = The index of the layer to be tested
* @param aLayer = The layer to be tested
* @return bool - true if the layer is visible.
*/
bool IsLayerVisible( LAYER_NUM aLayerIndex ) const
bool IsLayerVisible( LAYER_NUM aLayer ) const
{
// @@IMB: Altough Pcbnew uses only 29, GerbView uses all 32 layers
if( aLayerIndex < FIRST_LAYER || aLayerIndex >= NB_LAYERS )
return false;
// If a layer is disabled, it is automatically invisible
return bool( m_VisibleLayers & m_EnabledLayers & GetLayerMask( aLayerIndex ) );
return m_VisibleLayers & m_EnabledLayers & GetLayerMask( aLayer );
}
/**
* Function SetLayerVisibility
* changes the visibility of a given layer
* @param aLayerIndex = The index of the layer to be changed
* @param aLayer = The layer to be changed
* @param aNewState = The new visibility state of the layer
*/
void SetLayerVisibility( LAYER_NUM aLayerIndex, bool aNewState );
void SetLayerVisibility( LAYER_NUM aLayer, bool aNewState );
/**
* Function GetVisibleElements
@ -158,12 +154,12 @@ public:
/**
* Function IsLayerEnabled
* tests whether a given layer is enabled
* @param aLayerIndex = The index of the layer to be tested
* @param aLayer = The of the layer to be tested
* @return bool - true if the layer is enabled
*/
bool IsLayerEnabled( LAYER_NUM aLayerIndex ) const
bool IsLayerEnabled( LAYER_NUM aLayer ) const
{
return bool( m_EnabledLayers & GetLayerMask( aLayerIndex ) );
return m_EnabledLayers & GetLayerMask( aLayer );
}
/**

View File

@ -35,15 +35,15 @@ public:
// Returns a color index from the layer id
// Virtual function because GerbView uses its own functions in a derived class
virtual EDA_COLOR_T GetLayerColor( LAYER_NUM aLayerIndex ) const = 0;
virtual EDA_COLOR_T GetLayerColor( LAYER_NUM aLayer ) const = 0;
// Returns the name of the layer id
// Virtual pure function because GerbView uses its own functions in a derived class
virtual wxString GetLayerName( LAYER_NUM aLayerIndex ) const = 0;
virtual wxString GetLayerName( LAYER_NUM aLayer ) const = 0;
// Returns true if the layer id is enabled (i.e. is it should be displayed)
// Virtual function pure because GerbView uses its own functions in a derived class
virtual bool IsLayerEnabled( LAYER_NUM aLayerIndex ) const = 0;
virtual bool IsLayerEnabled( LAYER_NUM aLayer ) const = 0;
// Get Current Item #
int GetChoice();
@ -66,7 +66,7 @@ public:
protected:
// Fills the layer bitmap aLayerbmp with the layer color
void SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayerIndex );
void SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer );
};
#define DECLARE_LAYERS_HOTKEY(list) int list[NB_LAYERS] = \

View File

@ -10,6 +10,9 @@
#include <base_struct.h>
#include <eda_text.h> // EDA_TEXT_HJUSTIFY_T and EDA_TEXT_VJUSTIFY_T
/// Minimum dimension in pixel for drawing text
#define MIN_TEXT_SIZE 5
class EDA_DRAW_PANEL;
class PLOTTER;

View File

@ -62,6 +62,7 @@ enum EDA_DRAW_MODE_T {
#define DEFAULT_SIZE_TEXT 60 /* default text height (in mils or 1/1000") */
#define TEXT_NO_VISIBLE 1 //< EDA_TEXT::m_Attribut(e?) visibility flag.
#define DIM_ANCRE_TEXTE 2 // Anchor size for text
/**

View File

@ -260,4 +260,7 @@ void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC,std::vector<wxPoint>& aLines,
int aWidth, EDA_COLOR_T aColor );
void GRDrawAnchor( EDA_RECT* aClipBox, wxDC *aDC, int x, int y, int aSize,
EDA_COLOR_T aColor );
#endif /* define GR_BASIC */

View File

@ -216,39 +216,52 @@ enum PCB_VISIBLE
END_PCB_VISIBLE_LIST // sentinel
};
/**
* Function IsValidPcbLayerIndex
* tests whether a given integer is a valid layer index
* @param aLayerIndex = Layer index to test
* Function IsValidLayer
* tests whether a given integer is a valid layer index, i.e. can
* be safely put in a LAYER_NUM
* @param aLayerIndex = Layer index to test. It can be an int, so its
* useful during I/O
* @return true if aLayerIndex is a valid layer index
*/
inline bool IsValidPcbLayerIndex( LAYER_NUM aLayerIndex )
inline bool IsValidLayer( int aLayerIndex )
{
return aLayerIndex >= FIRST_LAYER && aLayerIndex < NB_PCB_LAYERS;
return aLayerIndex >= FIRST_LAYER && aLayerIndex < NB_LAYERS;
}
/**
* Function IsValidCopperLayerIndex
* tests whether an integer is a valid copper layer index
* @param aLayerIndex = Layer index to test
* @return true if aLayerIndex is a valid copper layer index
* Function IsPcbLayer
* tests whether a layer is a valid layer for pcbnew
* @param aLayer = Layer to test
* @return true if aLayer is a layer valid in pcbnew
*/
inline bool IsValidCopperLayerIndex( LAYER_NUM aLayerIndex )
inline bool IsPcbLayer( LAYER_NUM aLayer )
{
return aLayerIndex >= FIRST_COPPER_LAYER && aLayerIndex <= LAST_COPPER_LAYER;
return aLayer >= FIRST_LAYER && aLayer < NB_PCB_LAYERS;
}
/**
* Function IsValidNonCopperLayerIndex
* tests whether an integer is a valid non copper layer index
* @param aLayerIndex = Layer index to test
* @return true if aLayerIndex is a valid non copper layer index
* Function IsCopperLayer
* tests whether a layer is a copper layer
* @param aLayer = Layer to test
* @return true if aLayer is a valid copper layer
*/
inline bool IsValidNonCopperLayerIndex( LAYER_NUM aLayerIndex )
inline bool IsCopperLayer( LAYER_NUM aLayer )
{
return aLayerIndex >= FIRST_NON_COPPER_LAYER
&& aLayerIndex <= LAST_NON_COPPER_LAYER;
return aLayer >= FIRST_COPPER_LAYER
&& aLayer <= LAST_COPPER_LAYER;
}
/**
* Function IsNonCopperLayer
* tests whether a layer is a non copper layer
* @param aLayer = Layer to test
* @return true if aLayer is a non copper layer
*/
inline bool IsNonCopperLayer( LAYER_NUM aLayer )
{
return aLayer >= FIRST_NON_COPPER_LAYER
&& aLayer <= LAST_NON_COPPER_LAYER;
}
/* IMPORTANT: If a layer is not a front layer not necessarily is true

View File

@ -38,6 +38,7 @@
#include <wildcards_and_files_ext.h>
#include <vector>
#include <build_version.h>
#include <macros.h>
#include <wx/dir.h>
#include <wx/filename.h>

View File

@ -315,7 +315,7 @@ void PCB_BASE_FRAME::SwitchLayer( wxDC* DC, LAYER_NUM layer )
// Copper layers cannot be selected unconditionally; how many
// of those layers are currently enabled needs to be checked.
if( IsValidCopperLayerIndex( layer ) )
if( IsCopperLayer( layer ) )
{
// If only one copper layer is enabled, the only such layer
// that can be selected to is the "Copper" layer (so the

View File

@ -356,23 +356,23 @@ bool BOARD::SetLayer( LAYER_NUM aIndex, const LAYER& aLayer )
}
wxString BOARD::GetLayerName( LAYER_NUM aLayerIndex ) const
wxString BOARD::GetLayerName( LAYER_NUM aLayer ) const
{
if( !IsValidPcbLayerIndex( aLayerIndex ) )
if( !IsPcbLayer( aLayer ) )
return wxEmptyString;
// All layer names are stored in the BOARD.
if( IsLayerEnabled( aLayerIndex ) )
if( IsLayerEnabled( aLayer ) )
{
// Standard names were set in BOARD::BOARD() but they may be
// over-ridden by BOARD::SetLayerName().
// For copper layers, return the actual copper layer name,
// otherwise return the Standard English layer name.
if( aLayerIndex < FIRST_NON_COPPER_LAYER )
return m_Layer[aLayerIndex].m_Name;
if( IsCopperLayer( aLayer ) )
return m_Layer[aLayer].m_Name;
}
return GetStandardLayerName( aLayerIndex );
return GetStandardLayerName( aLayer );
}
@ -422,9 +422,9 @@ wxString BOARD::GetStandardLayerName( LAYER_NUM aLayerNumber )
}
bool BOARD::SetLayerName( LAYER_NUM aLayerIndex, const wxString& aLayerName )
bool BOARD::SetLayerName( LAYER_NUM aLayer, const wxString& aLayerName )
{
if( !IsValidCopperLayerIndex( aLayerIndex ) )
if( !IsCopperLayer( aLayer ) )
return false;
if( aLayerName == wxEmptyString || aLayerName.Len() > 20 )
@ -439,15 +439,15 @@ bool BOARD::SetLayerName( LAYER_NUM aLayerIndex, const wxString& aLayerName )
// replace any spaces with underscores before we do any comparing
NameTemp.Replace( wxT( " " ), wxT( "_" ) );
if( IsLayerEnabled( aLayerIndex ) )
if( IsLayerEnabled( aLayer ) )
{
for( LAYER_NUM i = FIRST_COPPER_LAYER; i < NB_COPPER_LAYERS; ++i )
{
if( i != aLayerIndex && IsLayerEnabled( i ) && NameTemp == m_Layer[i].m_Name )
if( i != aLayer && IsLayerEnabled( i ) && NameTemp == m_Layer[i].m_Name )
return false;
}
m_Layer[aLayerIndex].m_Name = NameTemp;
m_Layer[aLayer].m_Name = NameTemp;
return true;
}
@ -456,30 +456,30 @@ bool BOARD::SetLayerName( LAYER_NUM aLayerIndex, const wxString& aLayerName )
}
LAYER_T BOARD::GetLayerType( LAYER_NUM aLayerIndex ) const
LAYER_T BOARD::GetLayerType( LAYER_NUM aLayer ) const
{
if( !IsValidCopperLayerIndex( aLayerIndex ) )
if( !IsCopperLayer( aLayer ) )
return LT_SIGNAL;
//@@IMB: The original test was broken due to the discontinuity
// in the layer sequence.
if( IsLayerEnabled( aLayerIndex ) )
return m_Layer[aLayerIndex].m_Type;
if( IsLayerEnabled( aLayer ) )
return m_Layer[aLayer].m_Type;
return LT_SIGNAL;
}
bool BOARD::SetLayerType( LAYER_NUM aLayerIndex, LAYER_T aLayerType )
bool BOARD::SetLayerType( LAYER_NUM aLayer, LAYER_T aLayerType )
{
if( !IsValidCopperLayerIndex( aLayerIndex ) )
if( !IsCopperLayer( aLayer ) )
return false;
//@@IMB: The original test was broken due to the discontinuity
// in the layer sequence.
if( IsLayerEnabled( aLayerIndex ) )
if( IsLayerEnabled( aLayer ) )
{
m_Layer[aLayerIndex].m_Type = aLayerType;
m_Layer[aLayer].m_Type = aLayerType;
return true;
}

Some files were not shown because too many files have changed in this diff Show More