Commit 1833ff24 authored by charras's avatar charras

eeschema: fixed: incorrect position of texts fields in some components orientations

parent 5d887ebc
...@@ -29,11 +29,11 @@ SCH_CMP_FIELD::SCH_CMP_FIELD( const wxPoint& aPos, int aFieldId, ...@@ -29,11 +29,11 @@ SCH_CMP_FIELD::SCH_CMP_FIELD( const wxPoint& aPos, int aFieldId,
SCH_ITEM( aParent, DRAW_PART_TEXT_STRUCT_TYPE ), SCH_ITEM( aParent, DRAW_PART_TEXT_STRUCT_TYPE ),
EDA_TextStruct() EDA_TextStruct()
{ {
m_Pos = aPos; m_Pos = aPos;
m_FieldId = aFieldId; m_FieldId = aFieldId;
m_AddExtraText = false; m_AddExtraText = false;
m_Attributs = TEXT_NO_VISIBLE; m_Attributs = TEXT_NO_VISIBLE;
m_Name = aName; m_Name = aName;
SetLayer( LAYER_FIELDS ); SetLayer( LAYER_FIELDS );
} }
...@@ -47,9 +47,9 @@ SCH_CMP_FIELD::~SCH_CMP_FIELD() ...@@ -47,9 +47,9 @@ SCH_CMP_FIELD::~SCH_CMP_FIELD()
/** Function GetPenSize /** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item * @return the size of the "pen" that be used to draw or plot this item
*/ */
int SCH_CMP_FIELD::GetPenSize( ) int SCH_CMP_FIELD::GetPenSize()
{ {
int pensize = m_Width; int pensize = m_Width;
if( pensize == 0 ) // Use default values for pen size if( pensize == 0 ) // Use default values for pen size
{ {
...@@ -58,11 +58,13 @@ int SCH_CMP_FIELD::GetPenSize( ) ...@@ -58,11 +58,13 @@ int SCH_CMP_FIELD::GetPenSize( )
else else
pensize = g_DrawDefaultLineThickness; pensize = g_DrawDefaultLineThickness;
} }
// Clip pen size for small texts: // Clip pen size for small texts:
pensize = Clamp_Text_PenSize( pensize, m_Size, m_Bold ); pensize = Clamp_Text_PenSize( pensize, m_Size, m_Bold );
return pensize; return pensize;
} }
/** /**
* Routine de trace des textes type Field du composant. * Routine de trace des textes type Field du composant.
* entree: * entree:
...@@ -73,15 +75,13 @@ void SCH_CMP_FIELD::Draw( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -73,15 +75,13 @@ void SCH_CMP_FIELD::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
{ {
int orient; int orient;
EDA_Colors color; EDA_Colors color;
wxPoint pos; /* Position des textes */ wxPoint textpos;
SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) m_Parent; SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent;
GRTextHorizJustifyType hjustify;
GRTextVertJustifyType vjustify;
int LineWidth = m_Width; int LineWidth = m_Width;
if (LineWidth == 0) // Use default values for pen size if( LineWidth == 0 ) // Use default values for pen size
{ {
if ( m_Bold ) if( m_Bold )
LineWidth = GetPenSizeForBold( m_Size.x ); LineWidth = GetPenSizeForBold( m_Size.x );
else else
LineWidth = g_DrawDefaultLineThickness; LineWidth = g_DrawDefaultLineThickness;
...@@ -96,79 +96,31 @@ void SCH_CMP_FIELD::Draw( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -96,79 +96,31 @@ void SCH_CMP_FIELD::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
GRSetDrawMode( DC, DrawMode ); GRSetDrawMode( DC, DrawMode );
/* Calcul de la position des textes, selon orientation du composant */ /* Calculate the text orientation, according to the component orientation/mirror */
orient = m_Orient; orient = m_Orient;
hjustify = m_HJustify; vjustify = m_VJustify; if( parentComponent->m_Transform[0][1] ) // Rotation du composant de 90deg
pos = m_Pos - DrawLibItem->m_Pos;
pos = DrawLibItem->GetScreenCoord( pos );
pos += DrawLibItem->m_Pos;
/* Y a t-il rotation (pour l'orientation, la justification)*/
if( DrawLibItem->m_Transform[0][1] ) // Rotation du composant de 90deg
{ {
if( orient == TEXT_ORIENT_HORIZ ) if( orient == TEXT_ORIENT_HORIZ )
orient = TEXT_ORIENT_VERT; orient = TEXT_ORIENT_VERT;
else else
orient = TEXT_ORIENT_HORIZ; orient = TEXT_ORIENT_HORIZ;
/* Y a t-il rotation, miroir (pour les justifications)*/
GRTextHorizJustifyType tmp = hjustify;
hjustify = (GRTextHorizJustifyType) vjustify;
vjustify = (GRTextVertJustifyType) tmp;
if( DrawLibItem->m_Transform[1][0] < 0 )
switch ( vjustify )
{
case GR_TEXT_VJUSTIFY_BOTTOM:
vjustify = GR_TEXT_VJUSTIFY_TOP;
break;
case GR_TEXT_VJUSTIFY_TOP:
vjustify = GR_TEXT_VJUSTIFY_BOTTOM;
break;
default:
break;
}
if( DrawLibItem->m_Transform[1][0] > 0 )
switch ( hjustify )
{
case GR_TEXT_HJUSTIFY_LEFT:
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
break;
case GR_TEXT_HJUSTIFY_RIGHT:
hjustify = GR_TEXT_HJUSTIFY_LEFT;
break;
default:
break;
}
}
else
{
/* Texte horizontal: Y a t-il miroir (pour les justifications)*/
if( DrawLibItem->m_Transform[0][0] < 0 )
switch ( hjustify )
{
case GR_TEXT_HJUSTIFY_LEFT:
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
break;
case GR_TEXT_HJUSTIFY_RIGHT:
hjustify = GR_TEXT_HJUSTIFY_LEFT;
break;
default:
break;
}
if( DrawLibItem->m_Transform[1][1] > 0 )
switch ( vjustify )
{
case GR_TEXT_VJUSTIFY_BOTTOM:
vjustify = GR_TEXT_VJUSTIFY_TOP;
break;
case GR_TEXT_VJUSTIFY_TOP:
vjustify = GR_TEXT_VJUSTIFY_BOTTOM;
break;
default:
break;
}
} }
/* Calculate the text justification, according to the component orientation/mirror
* this is a bit complicated due to cumulative calculations:
* - numerous cases (mirrored or not, rotation)
* - the DrawGraphicText function recalculate also H and H vustifications
* according to the text orienation.
* - When a component is mirrored, the text is not mirrored and justifications
* are complicated to calculate
* so the more easily way is to use no justifications ( Centered text )
* and use GetBoundaryBox to know the text coordinate considered as centered
*/
EDA_Rect BoundaryBox = GetBoundaryBox();
GRTextHorizJustifyType hjustify = GR_TEXT_HJUSTIFY_CENTER;
GRTextVertJustifyType vjustify = GR_TEXT_VJUSTIFY_CENTER;
textpos = BoundaryBox.Centre();
if( m_FieldId == REFERENCE ) if( m_FieldId == REFERENCE )
color = ReturnLayerColor( LAYER_REFERENCEPART ); color = ReturnLayerColor( LAYER_REFERENCEPART );
else if( m_FieldId == VALUE ) else if( m_FieldId == VALUE )
...@@ -178,29 +130,53 @@ void SCH_CMP_FIELD::Draw( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -178,29 +130,53 @@ void SCH_CMP_FIELD::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
if( !m_AddExtraText || (m_FieldId != REFERENCE) ) if( !m_AddExtraText || (m_FieldId != REFERENCE) )
{ {
DrawGraphicText( panel, DC, pos, color, m_Text, DrawGraphicText( panel, DC, textpos, color, m_Text,
orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ, orient,
m_Size, hjustify, vjustify, LineWidth, m_Italic, m_Bold ); m_Size, hjustify, vjustify,
LineWidth, m_Italic, m_Bold );
} }
else else
{ {
/* For more than one part per package, we must add the part selection /* For more than one part per package, we must add the part selection
* A, B, ... or 1, 2, .. to the reference. */ * A, B, ... or 1, 2, .. to the reference. */
wxString fulltext = m_Text; wxString fulltext = m_Text;
char part_id; char part_id;
#if defined(KICAD_GOST) #if defined(KICAD_GOST)
fulltext.Append( '.'); fulltext.Append( '.' );
part_id = '1' - 1 + DrawLibItem->m_Multi; part_id = '1' - 1 + parentComponent->m_Multi;
#else #else
part_id = 'A' - 1 + DrawLibItem->m_Multi; part_id = 'A' - 1 + parentComponent->m_Multi;
#endif #endif
fulltext.Append( part_id ); fulltext.Append( part_id );
DrawGraphicText( panel, DC, pos, color, fulltext, DrawGraphicText( panel, DC, textpos, color, fulltext,
orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ, orient,
m_Size, hjustify, vjustify, LineWidth, m_Italic, m_Size, hjustify, vjustify,
LineWidth, m_Italic,
m_Bold, false ); m_Bold, false );
} }
/* Enable this to draw the bounding box around the text field to validate
* the bounding box calculations.
*/
#if 0
// Draw boundary box:
int x1 = BoundaryBox.GetX();
int y1 = BoundaryBox.GetY();
int x2 = BoundaryBox.GetRight();
int y2 = BoundaryBox.GetBottom();
GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
// Draw the text anchor point
/* Calculate the text position, according to the component orientation/mirror */
textpos = m_Pos - parentComponent->m_Pos;
textpos = parentComponent->GetScreenCoord( textpos );
textpos += parentComponent->m_Pos;
x1 = textpos.x;
y1 = textpos.y;
int len = 10;
GRLine( &panel->m_ClipBox, DC, x1 - len, y1, x1 + len, y1, 0, BLUE );
GRLine( &panel->m_ClipBox, DC, x1, y1 - len, x1, y1 +len, 0, BLUE );
#endif
} }
...@@ -224,6 +200,7 @@ void SCH_CMP_FIELD::ImportValues( const LIB_FIELD& aSource ) ...@@ -224,6 +200,7 @@ void SCH_CMP_FIELD::ImportValues( const LIB_FIELD& aSource )
m_Mirror = aSource.m_Mirror; m_Mirror = aSource.m_Mirror;
} }
/** /**
* Used if undo / redo command: * Used if undo / redo command:
* swap data between this and copyitem * swap data between this and copyitem
...@@ -270,44 +247,48 @@ EDA_Rect SCH_CMP_FIELD::GetBoundaryBox() const ...@@ -270,44 +247,48 @@ EDA_Rect SCH_CMP_FIELD::GetBoundaryBox() const
int orient; int orient;
int dx, dy, x1, y1, x2, y2; int dx, dy, x1, y1, x2, y2;
SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) m_Parent; SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent;
orient = m_Orient; orient = m_Orient;
wxPoint pos = DrawLibItem->m_Pos; wxPoint pos = parentComponent->m_Pos;
x1 = m_Pos.x - pos.x; x1 = m_Pos.x - pos.x;
y1 = m_Pos.y - pos.y; y1 = m_Pos.y - pos.y;
dx = LenSize(m_Text); dx = LenSize( m_Text );
dy = m_Size.y; dy = m_Size.y;
hjustify = m_HJustify; hjustify = m_HJustify;
vjustify = m_VJustify; vjustify = m_VJustify;
x2 = pos.x + (DrawLibItem->m_Transform[0][0] * x1) x2 = pos.x + (parentComponent->m_Transform[0][0] *x1)
+ (DrawLibItem->m_Transform[0][1] * y1); + (parentComponent->m_Transform[0][1] *y1);
y2 = pos.y + (DrawLibItem->m_Transform[1][0] * x1) y2 = pos.y + (parentComponent->m_Transform[1][0] *x1)
+ (DrawLibItem->m_Transform[1][1] * y1); + (parentComponent->m_Transform[1][1] *y1);
/* If the component orientation is +/- 90 deg, the text orientation must /* Calculate the text orientation, according to the component orientation/mirror */
* be changed */ if( parentComponent->m_Transform[0][1] )
if( DrawLibItem->m_Transform[0][1] )
{ {
if( orient == TEXT_ORIENT_HORIZ ) if( orient == TEXT_ORIENT_HORIZ )
orient = TEXT_ORIENT_VERT; orient = TEXT_ORIENT_VERT;
else else
orient = TEXT_ORIENT_HORIZ; orient = TEXT_ORIENT_HORIZ;
}
/* Calculate the text justification, according to the component orientation/mirror */
if( parentComponent->m_Transform[0][1] )
{
/* is it mirrored (for text justify)*/ /* is it mirrored (for text justify)*/
EXCHG( hjustify, vjustify ); EXCHG( hjustify, vjustify );
if( DrawLibItem->m_Transform[1][0] < 0 ) if( parentComponent->m_Transform[1][0] < 0 )
vjustify = -vjustify; NEGATE( vjustify );
if( DrawLibItem->m_Transform[0][1] > 0 ) if( parentComponent->m_Transform[0][1] > 0 )
hjustify = -hjustify; NEGATE( hjustify );
} }
else /* component horizontal: is it mirrored (for text justify)*/ else /* component horizontal: is it mirrored (for text justify)*/
{ {
if( DrawLibItem->m_Transform[0][0] < 0 ) if( parentComponent->m_Transform[0][0] < 0 )
hjustify = -hjustify; NEGATE( hjustify );
if( DrawLibItem->m_Transform[1][1] > 0 ) if( parentComponent->m_Transform[1][1] > 0 )
vjustify = -vjustify; NEGATE( vjustify );
} }
if( orient == TEXT_ORIENT_VERT ) if( orient == TEXT_ORIENT_VERT )
...@@ -349,8 +330,8 @@ EDA_Rect SCH_CMP_FIELD::GetBoundaryBox() const ...@@ -349,8 +330,8 @@ EDA_Rect SCH_CMP_FIELD::GetBoundaryBox() const
BoundaryBox.SetHeight( dy ); BoundaryBox.SetHeight( dy );
// Take thickness in account: // Take thickness in account:
int linewidth = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width; int linewidth = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width;
BoundaryBox.Inflate( linewidth,linewidth ); BoundaryBox.Inflate( linewidth, linewidth );
return BoundaryBox; return BoundaryBox;
} }
...@@ -359,6 +340,7 @@ EDA_Rect SCH_CMP_FIELD::GetBoundaryBox() const ...@@ -359,6 +340,7 @@ EDA_Rect SCH_CMP_FIELD::GetBoundaryBox() const
bool SCH_CMP_FIELD::Save( FILE* aFile ) const bool SCH_CMP_FIELD::Save( FILE* aFile ) const
{ {
char hjustify = 'C'; char hjustify = 'C';
if( m_HJustify == GR_TEXT_HJUSTIFY_LEFT ) if( m_HJustify == GR_TEXT_HJUSTIFY_LEFT )
hjustify = 'L'; hjustify = 'L';
else if( m_HJustify == GR_TEXT_HJUSTIFY_RIGHT ) else if( m_HJustify == GR_TEXT_HJUSTIFY_RIGHT )
...@@ -404,7 +386,7 @@ bool SCH_CMP_FIELD::Save( FILE* aFile ) const ...@@ -404,7 +386,7 @@ bool SCH_CMP_FIELD::Save( FILE* aFile ) const
void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC ) void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
{ {
int fieldNdx; int fieldNdx;
LIB_COMPONENT* Entry; LIB_COMPONENT* Entry;
frame->DrawPanel->ManageCurseur = NULL; frame->DrawPanel->ManageCurseur = NULL;
...@@ -413,7 +395,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC ) ...@@ -413,7 +395,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent(); SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
// save old cmp in undo list // save old cmp in undo list
if( g_ItemToUndoCopy && ( g_ItemToUndoCopy->Type() == component->Type()) ) if( g_ItemToUndoCopy && ( g_ItemToUndoCopy->Type() == component->Type() ) )
{ {
component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy ); component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
frame->SaveCopyInUndoList( component, UR_CHANGED ); frame->SaveCopyInUndoList( component, UR_CHANGED );
...@@ -432,7 +414,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC ) ...@@ -432,7 +414,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
} }
} }
Draw( frame->DrawPanel, DC, wxPoint(0,0), GR_DEFAULT_DRAWMODE ); Draw( frame->DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
m_Flags = 0; m_Flags = 0;
frame->GetScreen()->SetCurItem( NULL ); frame->GetScreen()->SetCurItem( NULL );
frame->GetScreen()->SetModify(); frame->GetScreen()->SetModify();
......
...@@ -85,9 +85,7 @@ static void PlotTextField( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem, ...@@ -85,9 +85,7 @@ static void PlotTextField( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem,
*/ */
{ {
wxPoint textpos; /* Position des textes */
SCH_CMP_FIELD* field = DrawLibItem->GetField( FieldNumber ); SCH_CMP_FIELD* field = DrawLibItem->GetField( FieldNumber );
int orient;
EDA_Colors color = UNSPECIFIED_COLOR; EDA_Colors color = UNSPECIFIED_COLOR;
color = ReturnLayerColor( field->GetLayer() ); color = ReturnLayerColor( field->GetLayer() );
...@@ -98,98 +96,37 @@ static void PlotTextField( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem, ...@@ -98,98 +96,37 @@ static void PlotTextField( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem,
if( field->IsVoid() ) if( field->IsVoid() )
return; return;
/* Calcul de la position des textes, selon orientation du composant */ /* Calculate the text orientation, according to the component orientation/mirror */
orient = field->m_Orient; int orient = field->m_Orient;
GRTextHorizJustifyType hjustify = field->m_HJustify; if( DrawLibItem->m_Transform[0][1] ) // Rotation du composant de 90deg
GRTextVertJustifyType vjustify = field->m_VJustify;
textpos = field->m_Pos - DrawLibItem->m_Pos; // textpos is the text position relative to the component anchor
textpos = TransformCoordinate( DrawLibItem->m_Transform, textpos ) + DrawLibItem->m_Pos;
/* Y a t-il rotation */
if( DrawLibItem->m_Transform[0][1] )
{ {
if( orient == TEXT_ORIENT_HORIZ ) if( orient == TEXT_ORIENT_HORIZ )
orient = TEXT_ORIENT_VERT; orient = TEXT_ORIENT_VERT;
else else
orient = TEXT_ORIENT_HORIZ; orient = TEXT_ORIENT_HORIZ;
/* Y a t-il rotation, miroir (pour les justifications)*/
GRTextHorizJustifyType tmp = hjustify;
hjustify = (GRTextHorizJustifyType) vjustify;
vjustify = (GRTextVertJustifyType) tmp;
if( DrawLibItem->m_Transform[1][0] < 0 )
switch( vjustify )
{
case GR_TEXT_VJUSTIFY_BOTTOM:
vjustify = GR_TEXT_VJUSTIFY_TOP;
break;
case GR_TEXT_VJUSTIFY_TOP:
vjustify = GR_TEXT_VJUSTIFY_BOTTOM;
break;
default:
break;
}
if( DrawLibItem->m_Transform[1][0] > 0 )
switch( hjustify )
{
case GR_TEXT_HJUSTIFY_LEFT:
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
break;
case GR_TEXT_HJUSTIFY_RIGHT:
hjustify = GR_TEXT_HJUSTIFY_LEFT;
break;
default:
break;
}
} }
else
{
/* Texte horizontal: Y a t-il miroir (pour les justifications)*/
if( DrawLibItem->m_Transform[0][0] < 0 )
switch( hjustify )
{
case GR_TEXT_HJUSTIFY_LEFT:
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
break;
case GR_TEXT_HJUSTIFY_RIGHT:
hjustify = GR_TEXT_HJUSTIFY_LEFT;
break;
default:
break;
}
if( DrawLibItem->m_Transform[1][1] > 0 ) /* Calculate the text justification, according to the component orientation/mirror
switch( vjustify ) * this is a bit complicated due to cumulative calculations:
{ * - numerous cases (mirrored or not, rotation)
case GR_TEXT_VJUSTIFY_BOTTOM: * - the DrawGraphicText function recalculate also H and H vustifications
vjustify = GR_TEXT_VJUSTIFY_TOP; * according to the text orienation.
break; * - When a component is mirrored, the text is not mirrored and justifications
* are complicated to calculate
case GR_TEXT_VJUSTIFY_TOP: * so the more easily way is to use no justifications ( Centered text )
vjustify = GR_TEXT_VJUSTIFY_BOTTOM; * and use GetBoundaryBox to know the text coordinate considered as centered
break; */
EDA_Rect BoundaryBox = field->GetBoundaryBox();
default: GRTextHorizJustifyType hjustify = GR_TEXT_HJUSTIFY_CENTER;
break; GRTextVertJustifyType vjustify = GR_TEXT_VJUSTIFY_CENTER;
} wxPoint textpos = BoundaryBox.Centre();
}
int thickness = field->GetPenSize(); int thickness = field->GetPenSize();
if( !IsMulti || (FieldNumber != REFERENCE) ) if( !IsMulti || (FieldNumber != REFERENCE) )
{ {
plotter->text( textpos, color, field->m_Text, plotter->text( textpos, color, field->m_Text,
orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ, orient,
field->m_Size, field->m_Size,
hjustify, vjustify, hjustify, vjustify,
thickness, field->m_Italic, field->m_Bold ); thickness, field->m_Italic, field->m_Bold );
...@@ -208,7 +145,7 @@ static void PlotTextField( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem, ...@@ -208,7 +145,7 @@ static void PlotTextField( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem,
#endif #endif
Text.Append( unit_id ); Text.Append( unit_id );
plotter->text( textpos, color, Text, plotter->text( textpos, color, Text,
orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ, orient,
field->m_Size, hjustify, vjustify, field->m_Size, hjustify, vjustify,
thickness, field->m_Italic, field->m_Bold ); thickness, field->m_Italic, field->m_Bold );
} }
......
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