Pcbnew: footprint text layer visibility improvements. (fixes lp:1527994)

* Always hide footprint text when the layer that the text resides is disabled
  in the layer manager.  There is no longer a difference between the value and
  reference text compared to other field text.
* The usual smattering of coding policy fixes and general code cleaning.
This commit is contained in:
Wayne Stambaugh 2016-04-20 11:28:44 -04:00
parent 67982a4851
commit 2b6889bc7a
2 changed files with 35 additions and 54 deletions

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -123,6 +123,7 @@ void TEXTE_MODULE::Move( const wxPoint& aMoveVector )
SetLocalCoord(); SetLocalCoord();
} }
void TEXTE_MODULE::Copy( TEXTE_MODULE* source ) void TEXTE_MODULE::Copy( TEXTE_MODULE* source )
{ {
if( source == NULL ) if( source == NULL )
@ -201,11 +202,6 @@ bool TEXTE_MODULE::HitTest( const wxPoint& aPosition ) const
} }
/*
* Function GetBoundingBox (virtual)
* returns the bounding box of this Text (according to text and footprint
* orientation)
*/
const EDA_RECT TEXTE_MODULE::GetBoundingBox() const const EDA_RECT TEXTE_MODULE::GetBoundingBox() const
{ {
double angle = GetDrawRotation(); double angle = GetDrawRotation();
@ -218,18 +214,10 @@ const EDA_RECT TEXTE_MODULE::GetBoundingBox() const
} }
/** void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode,
* Function Draw const wxPoint& aOffset )
* Draw the text according to the footprint pos and orient
* @param panel = draw panel, Used to know the clip box
* @param DC = Current Device Context
* @param offset = draw offset (usually wxPoint(0,0)
* @param draw_mode = GR_OR, GR_XOR..
*/
void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
const wxPoint& offset )
{ {
if( panel == NULL ) if( aPanel == NULL )
return; return;
/* parent must *not* be NULL (a footprint text without a footprint /* parent must *not* be NULL (a footprint text without a footprint
@ -238,20 +226,11 @@ void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
BOARD* brd = GetBoard( ); BOARD* brd = GetBoard( );
EDA_COLOR_T color = brd->GetLayerColor( GetLayer() ); EDA_COLOR_T color = brd->GetLayerColor( GetLayer() );
/* For reference and value suppress the element if the layer it is
* on is on a disabled side, user text also has standard layer
* hiding.
* If the whole module side is disabled this isn't even called */
LAYER_ID text_layer = GetLayer(); LAYER_ID text_layer = GetLayer();
if( (IsFrontLayer( text_layer ) && !brd->IsElementVisible( MOD_TEXT_FR_VISIBLE )) || if( !brd->IsLayerVisible( m_Layer )
(IsBackLayer( text_layer ) && !brd->IsElementVisible( MOD_TEXT_BK_VISIBLE )) ) || (IsFrontLayer( text_layer ) && !brd->IsElementVisible( MOD_TEXT_FR_VISIBLE ))
return; || (IsBackLayer( text_layer ) && !brd->IsElementVisible( MOD_TEXT_BK_VISIBLE )) )
// text which are not ref or value are shown only if the layer is visible
// ref or value have a specific display option
if( GetType() == TEXT_is_DIVERS && ! brd->IsLayerVisible( m_Layer ) )
return; return;
// Invisible texts are still drawn (not plotted) in MOD_TEXT_INVISIBLE // Invisible texts are still drawn (not plotted) in MOD_TEXT_INVISIBLE
@ -260,16 +239,16 @@ void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
{ {
if( !brd->IsElementVisible( MOD_TEXT_INVISIBLE ) ) if( !brd->IsElementVisible( MOD_TEXT_INVISIBLE ) )
return; return;
color = brd->GetVisibleElementColor( MOD_TEXT_INVISIBLE ); color = brd->GetVisibleElementColor( MOD_TEXT_INVISIBLE );
} }
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)panel->GetDisplayOptions(); DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)aPanel->GetDisplayOptions();
// shade text if high contrast mode is active // shade text if high contrast mode is active
if( ( draw_mode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && if( ( aDrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
displ_opts->m_ContrastModeDisplay )
{ {
LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer; LAYER_ID curr_layer = ( (PCB_SCREEN*) aPanel->GetScreen() )->m_Active_Layer;
if( !IsOnLayer( curr_layer ) ) if( !IsOnLayer( curr_layer ) )
ColorTurnToDarkDarkGray( &color ); ColorTurnToDarkDarkGray( &color );
@ -281,15 +260,14 @@ void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
if( displ_opts && displ_opts->m_DisplayModTextFill == SKETCH ) if( displ_opts && displ_opts->m_DisplayModTextFill == SKETCH )
width = -width; width = -width;
GRSetDrawMode( DC, draw_mode ); GRSetDrawMode( aDC, aDrawMode );
wxPoint pos = m_Pos - offset; wxPoint pos = m_Pos - aOffset;
// Draw the text anchor point // Draw the text anchor point
if( brd->IsElementVisible( ANCHOR_VISIBLE ) ) if( brd->IsElementVisible( ANCHOR_VISIBLE ) )
{ {
EDA_COLOR_T anchor_color = brd->GetVisibleElementColor(ANCHOR_VISIBLE); EDA_COLOR_T anchor_color = brd->GetVisibleElementColor(ANCHOR_VISIBLE);
GRDrawAnchor( panel->GetClipBox(), DC, pos.x, pos.y, GRDrawAnchor( aPanel->GetClipBox(), aDC, pos.x, pos.y, DIM_ANCRE_TEXTE, anchor_color );
DIM_ANCRE_TEXTE, anchor_color );
} }
// Draw the text proper, with the right attributes // Draw the text proper, with the right attributes
@ -300,20 +278,19 @@ void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
if( m_Mirror ) if( m_Mirror )
size.x = -size.x; size.x = -size.x;
DrawGraphicText( panel->GetClipBox(), DC, pos, color, GetShownText(), orient, DrawGraphicText( aPanel->GetClipBox(), aDC, pos, color, GetShownText(), orient,
size, m_HJustify, m_VJustify, width, m_Italic, m_Bold ); size, m_HJustify, m_VJustify, width, m_Italic, m_Bold );
// Enable these line to draw the bounding box (debug test purpose only) // Enable these line to draw the bounding box (debug test purpose only)
#if 0 #if 0
{ {
EDA_RECT BoundaryBox = GetBoundingBox(); EDA_RECT BoundaryBox = GetBoundingBox();
GRRect( panel->GetClipBox(), DC, BoundaryBox, 0, BROWN ); GRRect( aPanel->GetClipBox(), aDC, BoundaryBox, 0, BROWN );
} }
#endif #endif
} }
/* Draws a line from the TEXTE_MODULE origin to parent MODULE origin.
*/
void TEXTE_MODULE::DrawUmbilical( EDA_DRAW_PANEL* aPanel, void TEXTE_MODULE::DrawUmbilical( EDA_DRAW_PANEL* aPanel,
wxDC* aDC, wxDC* aDC,
GR_DRAWMODE aDrawMode, GR_DRAWMODE aDrawMode,
@ -330,8 +307,7 @@ void TEXTE_MODULE::DrawUmbilical( EDA_DRAW_PANEL* aPanel,
0, UMBILICAL_COLOR); 0, UMBILICAL_COLOR);
} }
/* Return text rotation for drawings and plotting
*/
double TEXTE_MODULE::GetDrawRotation() const double TEXTE_MODULE::GetDrawRotation() const
{ {
MODULE* module = (MODULE*) m_Parent; MODULE* module = (MODULE*) m_Parent;
@ -489,9 +465,6 @@ unsigned int TEXTE_MODULE::ViewGetLOD( int aLayer ) const
} }
/**
* Macro-expansion for text in library modules
*/
wxString TEXTE_MODULE::GetShownText() const wxString TEXTE_MODULE::GetShownText() const
{ {
/* First order optimization: no % means that no processing is /* First order optimization: no % means that no processing is
@ -507,8 +480,7 @@ wxString TEXTE_MODULE::GetShownText() const
wxString newbuf; wxString newbuf;
const MODULE *module = static_cast<MODULE*>( GetParent() ); const MODULE *module = static_cast<MODULE*>( GetParent() );
for( wxString::const_iterator it = m_Text.begin(); for( wxString::const_iterator it = m_Text.begin(); it != m_Text.end(); ++it )
it != m_Text.end(); ++it )
{ {
// Process '%' and copy everything else // Process '%' and copy everything else
if( *it != '%' ) if( *it != '%' )
@ -518,6 +490,7 @@ wxString TEXTE_MODULE::GetShownText() const
/* Look at the next character (if is it there) and append /* Look at the next character (if is it there) and append
* its expansion */ * its expansion */
++it; ++it;
if( it != m_Text.end() ) if( it != m_Text.end() )
{ {
switch( char(*it) ) switch( char(*it) )
@ -545,7 +518,6 @@ wxString TEXTE_MODULE::GetShownText() const
break; // The string is over and we can't ++ anymore break; // The string is over and we can't ++ anymore
} }
} }
return newbuf; return newbuf;
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -132,10 +132,19 @@ public:
void SetLocalCoord(); void SetLocalCoord();
/* drawing functions */ /* drawing functions */
void Draw( EDA_DRAW_PANEL* panel,
wxDC* DC, /**
* Function Draw
* Draw the text according to the footprint pos and orient
* @param aPanel = draw panel, Used to know the clip box
* @param aDC = Current Device Context
* @param aOffset = draw offset (usually wxPoint(0,0)
* @param aDrawMode = GR_OR, GR_XOR..
*/
void Draw( EDA_DRAW_PANEL* aPanel,
wxDC* aDC,
GR_DRAWMODE aDrawMode, GR_DRAWMODE aDrawMode,
const wxPoint& offset = ZeroOffset ); const wxPoint& aOffset = ZeroOffset );
/** /**
* Function DrawUmbilical * Function DrawUmbilical