Eeschema: better position of texts (pin texts and labels), taking in account the line thickness.

This commit is contained in:
unknown 2016-04-16 09:49:17 +02:00 committed by jean-pierre charras
parent bcd345c29f
commit 698197ec8d
3 changed files with 60 additions and 34 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors.
* 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
@ -37,7 +37,6 @@ class SCH_SHEET;
#define EESCHEMA_VERSION 2
#define SCHEMATIC_HEAD_STRING "Schematic File Version"
#define TXTMARGE 10 // Offset in mils for placement of labels and pin numbers
#define DANGLING_SYMBOL_SIZE 12

View File

@ -55,10 +55,11 @@ static const int pin_orientation_codes[] =
PIN_UP,
PIN_DOWN
};
#define PIN_ORIENTATION_CNT DIM( pin_orientation_codes )
// small margin in internal units between the pin text and the pin line
#define PIN_TEXT_MARGIN 4
// bitmaps to show pins orientations in dialog editor
// must have same order than pin_orientation_names
static const BITMAP_DEF iconsPinsOrientations[] =
@ -1165,9 +1166,14 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
int nameLineWidth = GetPenSize();
nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
int numLineWidth = GetPenSize();
int numLineWidth = GetPenSize();
numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
int name_offset = PIN_TEXT_MARGIN +
( nameLineWidth + GetDefaultLineThickness() ) / 2;
int num_offset = PIN_TEXT_MARGIN +
( numLineWidth + GetDefaultLineThickness() ) / 2;
GRSetDrawMode( DC, DrawMode );
EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
@ -1243,7 +1249,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
{
DrawGraphicText( clipbox, DC,
wxPoint( (x1 + pin_pos.x) / 2,
y1 - TXTMARGE ), NumColor,
y1 - num_offset ), NumColor,
StringPinNum,
TEXT_ORIENT_HORIZ, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1268,7 +1274,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
if( DrawPinNum )
DrawGraphicText( clipbox, DC,
wxPoint( x1 - TXTMARGE,
wxPoint( x1 - num_offset,
(y1 + pin_pos.y) / 2 ), NumColor,
StringPinNum,
TEXT_ORIENT_VERT, PinNumSize,
@ -1290,7 +1296,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
if( DrawPinNum )
DrawGraphicText( clipbox, DC,
wxPoint( x1 - TXTMARGE,
wxPoint( x1 - num_offset,
(y1 + pin_pos.y) / 2 ), NumColor,
StringPinNum,
TEXT_ORIENT_VERT, PinNumSize,
@ -1308,7 +1314,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
if( DrawPinName )
{
x = (x1 + pin_pos.x) / 2;
DrawGraphicText( clipbox, DC, wxPoint( x, y1 - TXTMARGE ),
DrawGraphicText( clipbox, DC, wxPoint( x, y1 - name_offset ),
NameColor, m_name,
TEXT_ORIENT_HORIZ, PinNameSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1318,7 +1324,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
if( DrawPinNum )
{
x = (x1 + pin_pos.x) / 2;
DrawGraphicText( clipbox, DC, wxPoint( x, y1 + TXTMARGE ),
DrawGraphicText( clipbox, DC, wxPoint( x, y1 + num_offset ),
NumColor, StringPinNum,
TEXT_ORIENT_HORIZ, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1331,7 +1337,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
if( DrawPinName )
{
y = (y1 + pin_pos.y) / 2;
DrawGraphicText( clipbox, DC, wxPoint( x1 - TXTMARGE, y ),
DrawGraphicText( clipbox, DC, wxPoint( x1 - name_offset, y ),
NameColor, m_name,
TEXT_ORIENT_VERT, PinNameSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1342,7 +1348,8 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
if( DrawPinNum )
{
DrawGraphicText( clipbox, DC,
wxPoint( x1 + TXTMARGE, (y1 + pin_pos.y) / 2 ),
wxPoint( x1 + num_offset, (y1 + pin_pos.y)
/ 2 ),
NumColor, StringPinNum,
TEXT_ORIENT_VERT, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1526,6 +1533,16 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
wxSize PinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
wxSize PinNumSize = wxSize( m_numTextSize, m_numTextSize );
int nameLineWidth = GetPenSize();
nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
int numLineWidth = GetPenSize();
numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
int name_offset = PIN_TEXT_MARGIN +
( nameLineWidth + GetDefaultLineThickness() ) / 2;
int num_offset = PIN_TEXT_MARGIN +
( numLineWidth + GetDefaultLineThickness() ) / 2;
/* Get the num and name colors */
EDA_COLOR_T NameColor = GetLayerColor( LAYER_PINNAM );
EDA_COLOR_T NumColor = GetLayerColor( LAYER_PINNUM );
@ -1585,7 +1602,8 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
}
if( DrawPinNum )
{
plotter->Text( wxPoint( (x1 + pin_pos.x) / 2, y1 - TXTMARGE ),
plotter->Text( wxPoint( (x1 + pin_pos.x) / 2,
y1 - num_offset ),
NumColor, StringPinNum,
TEXT_ORIENT_HORIZ, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1609,7 +1627,8 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
if( DrawPinNum )
{
plotter->Text( wxPoint( x1 - TXTMARGE, (y1 + pin_pos.y) / 2 ),
plotter->Text( wxPoint( x1 - num_offset,
(y1 + pin_pos.y) / 2 ),
NumColor, StringPinNum,
TEXT_ORIENT_VERT, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1631,7 +1650,8 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
if( DrawPinNum )
{
plotter->Text( wxPoint( x1 - TXTMARGE, (y1 + pin_pos.y) / 2 ),
plotter->Text( wxPoint( x1 - num_offset,
(y1 + pin_pos.y) / 2 ),
NumColor, StringPinNum,
TEXT_ORIENT_VERT, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1649,7 +1669,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
if( DrawPinName )
{
x = (x1 + pin_pos.x) / 2;
plotter->Text( wxPoint( x, y1 - TXTMARGE ),
plotter->Text( wxPoint( x, y1 - name_offset ),
NameColor, m_name,
TEXT_ORIENT_HORIZ, PinNameSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1660,7 +1680,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
if( DrawPinNum )
{
x = ( x1 + pin_pos.x ) / 2;
plotter->Text( wxPoint( x, y1 + TXTMARGE ),
plotter->Text( wxPoint( x, y1 + num_offset ),
NumColor, StringPinNum,
TEXT_ORIENT_HORIZ, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1673,7 +1693,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
if( DrawPinName )
{
y = ( y1 + pin_pos.y ) / 2;
plotter->Text( wxPoint( x1 - TXTMARGE, y ),
plotter->Text( wxPoint( x1 - name_offset, y ),
NameColor, m_name,
TEXT_ORIENT_VERT, PinNameSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -1683,7 +1703,8 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
if( DrawPinNum )
{
plotter->Text( wxPoint( x1 + TXTMARGE, ( y1 + pin_pos.y ) / 2 ),
plotter->Text( wxPoint( x1 + num_offset,
( y1 + pin_pos.y ) / 2 ),
NumColor, StringPinNum,
TEXT_ORIENT_VERT, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
@ -2034,7 +2055,7 @@ const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles ) const
// calculate top left corner position
// for the default pin orientation (PIN_RIGHT)
begin.y = std::max( minsizeV, numberTextHeight + TXTMARGE );
begin.y = std::max( minsizeV, numberTextHeight + PIN_TEXT_MARGIN );
begin.x = std::min( -TARGET_PIN_RADIUS, m_length - (numberTextLength / 2) );
// calculate bottom right corner position and adjust top left corner position
@ -2052,7 +2073,7 @@ const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles ) const
nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
// Actual text height are bigger than text size
nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + TXTMARGE;
nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + PIN_TEXT_MARGIN;
}
if( nameTextOffset ) // for values > 0, pin name is inside the body

View File

@ -49,6 +49,9 @@ extern void IncrementLabelMember( wxString& name, int aIncrement );
// Only for tests: set DRAW_BBOX to 1 to draw the bounding box of labels
#define DRAW_BBOX 0
// Margin in internal units (mils) between labels and wires
#define TXT_MARGIN 4
/* Names of sheet label types. */
const char* SheetLabelType[] =
{
@ -141,25 +144,28 @@ wxPoint SCH_TEXT::GetSchematicTextOffset() const
{
wxPoint text_offset;
// add a small offset (TXTMARGE) to x ( or y) position to allow a text to
// add an offset to x ( or y) position to allow a text to
// be on a wire or a line and be readable
int thick_offset = TXT_MARGIN +
( GetPenSize() + GetDefaultLineThickness() ) / 2;
switch( m_schematicOrientation )
{
default:
case 0: /* Horiz Normal Orientation (left justified) */
text_offset.y = -TXTMARGE;
text_offset.y = -thick_offset;
break;
case 1: /* Vert Orientation UP */
text_offset.x = -TXTMARGE;
text_offset.x = -thick_offset;
break;
case 2: /* Horiz Orientation - Right justified */
text_offset.y = -TXTMARGE;
text_offset.y = -thick_offset;
break;
case 3: /* Vert Orientation BOTTOM */
text_offset.x = -TXTMARGE;
text_offset.x = -thick_offset;
break;
}
@ -656,9 +662,7 @@ bool SCH_TEXT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
void SCH_TEXT::Plot( PLOTTER* aPlotter )
{
static std::vector <wxPoint> Poly;
EDA_COLOR_T color = GetLayerColor( GetLayer() );
wxPoint textpos = m_Pos + GetSchematicTextOffset();
int thickness = GetPenSize();
aPlotter->SetCurrentLineWidth( thickness );
@ -674,13 +678,15 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter )
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
{
wxPoint textpos = positions[ii] + GetSchematicTextOffset();
wxString& txt = strings_list.Item( ii );
aPlotter->Text( positions[ii], color, txt, m_Orient, m_Size, m_HJustify,
aPlotter->Text( textpos, color, txt, m_Orient, m_Size, m_HJustify,
m_VJustify, thickness, m_Italic, m_Bold );
}
}
else
{
wxPoint textpos = m_Pos + GetSchematicTextOffset();
aPlotter->Text( textpos, color, GetShownText(), m_Orient, m_Size, m_HJustify,
m_VJustify, thickness, m_Italic, m_Bold );
}
@ -1155,7 +1161,7 @@ wxPoint SCH_GLOBALLABEL::GetSchematicTextOffset() const
case NET_OUTPUT:
case NET_UNSPECIFIED:
offset += TXTMARGE;
offset += TXT_MARGIN;
break;
default:
@ -1268,7 +1274,7 @@ void SCH_GLOBALLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const
aPoints.clear();
int symb_len = LenSize( GetShownText() ) + ( TXTMARGE * 2 );
int symb_len = LenSize( GetShownText() ) + ( TXT_MARGIN * 2 );
// Create outline shape : 6 points
int x = symb_len + linewidth + 3;
@ -1378,7 +1384,7 @@ const EDA_RECT SCH_GLOBALLABEL::GetBoundingBox() const
dx = dy = 0;
int width = (m_Thickness == 0) ? GetDefaultLineThickness() : m_Thickness;
height = ( (m_Size.y * 15) / 10 ) + width + 2 * TXTMARGE;
height = ( (m_Size.y * 15) / 10 ) + width + 2 * TXT_MARGIN;
// text X size add height for triangular shapes(bidirectional)
length = LenSize( GetShownText() ) + height + DANGLING_SYMBOL_SIZE;
@ -1642,7 +1648,7 @@ const EDA_RECT SCH_HIERLABEL::GetBoundingBox() const
dx = dy = 0;
int width = (m_Thickness == 0) ? GetDefaultLineThickness() : m_Thickness;
height = m_Size.y + width + 2 * TXTMARGE;
height = m_Size.y + width + 2 * TXT_MARGIN;
length = LenSize( GetShownText() )
+ height // add height for triangular shapes
+ 2 * DANGLING_SYMBOL_SIZE;
@ -1690,7 +1696,7 @@ wxPoint SCH_HIERLABEL::GetSchematicTextOffset() const
int width = std::max( m_Thickness, GetDefaultLineThickness() );
int ii = m_Size.x + TXTMARGE + width;
int ii = m_Size.x + TXT_MARGIN + width;
switch( m_schematicOrientation )
{