Commit 8931b1fc authored by charras's avatar charras

fixed issues 2970757 and 2970825

parent 458f7626
...@@ -305,15 +305,54 @@ void LIB_TEXT::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, ...@@ -305,15 +305,54 @@ void LIB_TEXT::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
GRSetDrawMode( aDC, aDrawMode ); GRSetDrawMode( aDC, aDrawMode );
/* Calculate the text orientation, according to the component
* orientation/mirror (needed when draw text in schematic)
*/
int orient = m_Orient;
if( aTransformMatrix[0][1] ) // Rotate component 90 degrees.
{
if( orient == TEXT_ORIENT_HORIZ )
orient = TEXT_ORIENT_VERT;
else
orient = TEXT_ORIENT_HORIZ;
}
/* 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 justifications
* according to the text orientation.
* - 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 bBox = GetBoundingBox();
pos1 = bBox.Centre(); // this is the coordinates of the graphic text relative to the component position
// in schematic Y axis orientation
/* convert y coordinate from schematic to library Y axis orientation
* because we want to call TransformCoordinate to calculate real coordinates
*/
NEGATE( pos1.y );
pos1 = TransformCoordinate( aTransformMatrix, pos1 ) + aOffset;
DrawGraphicText( aPanel, aDC, pos1, (EDA_Colors) color, m_Text, DrawGraphicText( aPanel, aDC, pos1, (EDA_Colors) color, m_Text,
m_Orient, m_Size, m_HJustify, m_VJustify, orient, m_Size, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
GetPenSize( ), m_Italic, m_Bold ); GetPenSize( ), m_Italic, m_Bold );
/* Enable this to draw the bounding box around the text field to validate
* the bounding box calculations.
*/
#if 0 #if 0
EDA_Rect bBox = GetBoundingBox(); EDA_Rect grBox;
bBox.Inflate( 1, 1 ); bBox.SetY( -bBox.GetY() );
GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.SetHeight( -bBox.GetHeight());
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); grBox.SetOrigin( TransformCoordinate( aTransformMatrix, bBox.GetOrigin() ) );
grBox.SetEnd( TransformCoordinate( aTransformMatrix, bBox.GetEnd() ) );
grBox.Move( aOffset );
GRRect( &aPanel->m_ClipBox, aDC, grBox.GetOrigin().x, grBox.GetOrigin().y,
grBox.GetEnd().x, grBox.GetEnd().y, 0, LIGHTMAGENTA );
#endif #endif
} }
...@@ -331,11 +370,18 @@ void LIB_TEXT::DisplayInfo( WinEDA_DrawFrame* frame ) ...@@ -331,11 +370,18 @@ void LIB_TEXT::DisplayInfo( WinEDA_DrawFrame* frame )
} }
/**
* @return the boundary box for this, in schematic coordinates
*/
EDA_Rect LIB_TEXT::GetBoundingBox() EDA_Rect LIB_TEXT::GetBoundingBox()
{ {
/* remenber Y coordinates in lib are bottom to top, so we must
* negate the Y position befire calling GetTextBox() that works using top to bottom
* Y axis orientation
*/
NEGATE(m_Pos.y );
EDA_Rect rect = GetTextBox(); EDA_Rect rect = GetTextBox();
rect.m_Pos.y *= -1; NEGATE(m_Pos.y ); // restore Y cooordinate for the graphic text
rect.m_Pos.y -= rect.GetHeight();
wxPoint orig = rect.GetOrigin(); wxPoint orig = rect.GetOrigin();
wxPoint end = rect.GetEnd(); wxPoint end = rect.GetEnd();
...@@ -345,6 +391,6 @@ EDA_Rect LIB_TEXT::GetBoundingBox() ...@@ -345,6 +391,6 @@ EDA_Rect LIB_TEXT::GetBoundingBox()
RotatePoint( &end, center, m_Orient ); RotatePoint( &end, center, m_Orient );
rect.SetOrigin( orig ); rect.SetOrigin( orig );
rect.SetEnd( end ); rect.SetEnd( end );
rect.Normalize();
return rect; return rect;
} }
...@@ -155,10 +155,10 @@ void SCH_FIELD::Draw( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -155,10 +155,10 @@ void SCH_FIELD::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
LineWidth, m_Italic, LineWidth, m_Italic,
m_Bold, false ); m_Bold, false );
} }
/* Enable this to draw the bounding box around the text field to validate /* Enable this to draw the bounding box around the text field to validate
* the bounding box calculations. * the bounding box calculations.
*/ */
#if 0 #if 0
// Draw boundary box: // Draw boundary box:
int x1 = BoundaryBox.GetX(); int x1 = BoundaryBox.GetX();
...@@ -243,27 +243,24 @@ bool SCH_FIELD::IsVoid() ...@@ -243,27 +243,24 @@ bool SCH_FIELD::IsVoid()
*/ */
EDA_Rect SCH_FIELD::GetBoundaryBox() const EDA_Rect SCH_FIELD::GetBoundaryBox() const
{ {
EDA_Rect BoundaryBox; EDA_Rect BoundaryBox;
int hjustify, vjustify; int hjustify, vjustify;
int orient; int orient;
int dx, dy, x1, y1, x2, y2; wxSize size;
wxPoint pos1, pos2;
SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent; SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent;
orient = m_Orient; orient = m_Orient;
wxPoint pos = parentComponent->m_Pos; wxPoint pos = parentComponent->m_Pos;
x1 = m_Pos.x - pos.x; pos1 = m_Pos - pos;
y1 = m_Pos.y - pos.y;
dx = LenSize( m_Text ); size.x = LenSize( m_Text );
dy = m_Size.y; size.y = m_Size.y;
hjustify = m_HJustify; hjustify = m_HJustify;
vjustify = m_VJustify; vjustify = m_VJustify;
x2 = pos.x + ( parentComponent->m_Transform[0][0] * x1 ) pos2 = pos + TransformCoordinate( parentComponent->m_Transform, pos1 );
+ ( parentComponent->m_Transform[0][1] * y1 );
y2 = pos.y + ( parentComponent->m_Transform[1][0] * x1 )
+ ( parentComponent->m_Transform[1][1] * y1 );
/* Calculate the text orientation, according to the component /* Calculate the text orientation, according to the component
* orientation/mirror */ * orientation/mirror */
...@@ -295,42 +292,40 @@ EDA_Rect SCH_FIELD::GetBoundaryBox() const ...@@ -295,42 +292,40 @@ EDA_Rect SCH_FIELD::GetBoundaryBox() const
} }
if( orient == TEXT_ORIENT_VERT ) if( orient == TEXT_ORIENT_VERT )
EXCHG( dx, dy ); EXCHG( size.x, size.y );
switch( hjustify ) switch( hjustify )
{ {
case GR_TEXT_HJUSTIFY_CENTER: case GR_TEXT_HJUSTIFY_CENTER:
x1 = x2 - (dx / 2); pos1.x = pos2.x - (size.x / 2);
break; break;
case GR_TEXT_HJUSTIFY_RIGHT: case GR_TEXT_HJUSTIFY_RIGHT:
x1 = x2 - dx; pos1.x = pos2.x - size.x;
break; break;
default: default:
x1 = x2; pos1.x = pos2.x;
break; break;
} }
switch( vjustify ) switch( vjustify )
{ {
case GR_TEXT_VJUSTIFY_CENTER: case GR_TEXT_VJUSTIFY_CENTER:
y1 = y2 - (dy / 2); pos1.y = pos2.y - (size.y / 2);
break; break;
case GR_TEXT_VJUSTIFY_BOTTOM: case GR_TEXT_VJUSTIFY_BOTTOM:
y1 = y2 - dy; pos1.y = pos2.y - size.y;
break; break;
default: default:
y1 = y2; pos1.y = pos2.y;
break; break;
} }
BoundaryBox.SetX( x1 ); BoundaryBox.SetOrigin( pos1 );
BoundaryBox.SetY( y1 ); BoundaryBox.SetSize( size );
BoundaryBox.SetWidth( dx );
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;
......
...@@ -1219,5 +1219,6 @@ EDA_Rect SCH_TEXT::GetBoundingBox() ...@@ -1219,5 +1219,6 @@ EDA_Rect SCH_TEXT::GetBoundingBox()
rect.SetEnd(end); rect.SetEnd(end);
} }
rect.Normalize();
return rect; return rect;
} }
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