Code cleaning and enhancements about EDA_TextStruct
This commit is contained in:
parent
86a40a93c3
commit
dfa7e1d618
|
@ -185,23 +185,114 @@ EDA_TextStruct::~EDA_TextStruct()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/********************************/
|
/**
|
||||||
int EDA_TextStruct::Len_Size()
|
* Function LenSize
|
||||||
/********************************/
|
* @return the text lenght in internal units
|
||||||
|
* @param aLine : the line of text to consider.
|
||||||
// Return the text lenght in internal units
|
* For single line text, this parameter is always m_Text
|
||||||
|
*/
|
||||||
|
int EDA_TextStruct::LenSize( const wxString& aLine )
|
||||||
{
|
{
|
||||||
int nbchar = m_Text.Len();
|
int nbchar = aLine.Len();
|
||||||
int len;
|
|
||||||
|
|
||||||
if( nbchar == 0 )
|
int len = ( ( (10 * m_Size.x ) / 9 ) + m_Width ) * nbchar;
|
||||||
return 0;
|
|
||||||
|
|
||||||
len = ( ( (10 * m_Size.x ) / 9 ) + m_Width ) * nbchar;
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Function GetTextBox
|
||||||
|
* useful in multiline texts to calculate the full text or a line area (for zones filling, locate functions....)
|
||||||
|
* @return the rect containing the line of text (i.e. the position and the size of one line)
|
||||||
|
* this rectangle is calculated for 0 orient text. if orient is not 0 the rect must be rotated to match the physical area
|
||||||
|
* @param aLine : the line of text to consider.
|
||||||
|
* for single line text, aLine is unused
|
||||||
|
* If aLine == -1, the full area (considering all lines) is returned
|
||||||
|
*/
|
||||||
|
EDA_Rect EDA_TextStruct::GetTextBox( int aLine )
|
||||||
|
{
|
||||||
|
EDA_Rect rect;
|
||||||
|
wxPoint pos;
|
||||||
|
wxArrayString* list = NULL;
|
||||||
|
|
||||||
|
wxString* text = &m_Text;
|
||||||
|
|
||||||
|
if( m_MultilineAllowed )
|
||||||
|
{
|
||||||
|
list = wxStringSplit( m_Text, '\n' );
|
||||||
|
if( aLine >= 0 && (aLine < (int)list->GetCount()) )
|
||||||
|
text = &list->Item( aLine );
|
||||||
|
else
|
||||||
|
text = &list->Item( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// calculate the H and V size
|
||||||
|
int dx = LenSize( *text );
|
||||||
|
int dy = m_Size.y + m_Width;
|
||||||
|
int extra_dy = (m_Size.y * 3)/10; // extra dy value for letters like j and y
|
||||||
|
|
||||||
|
/* Creates bounding box (rectangle) for an horizontal text */
|
||||||
|
wxSize textsize = wxSize( dx, dy );
|
||||||
|
rect.SetOrigin( m_Pos );
|
||||||
|
|
||||||
|
// for multiline texts ans aLine < 0, merge all rectangles
|
||||||
|
if( m_MultilineAllowed && aLine < 0 )
|
||||||
|
{
|
||||||
|
dy = GetInterline();
|
||||||
|
for( unsigned ii = 1; ii < list->GetCount(); ii++ )
|
||||||
|
{
|
||||||
|
text = &list->Item( ii );
|
||||||
|
dx = LenSize( *text );
|
||||||
|
textsize.x = MAX( textsize.x, dx );
|
||||||
|
textsize.y += dy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete list;
|
||||||
|
|
||||||
|
textsize.y += extra_dy;
|
||||||
|
rect.SetSize( textsize );
|
||||||
|
|
||||||
|
/* Now, calculate the rect origin, according to text justification
|
||||||
|
* At this point the area origin is the text origin.
|
||||||
|
* This is true only for left and top text justified.
|
||||||
|
* and must be recalculated for others justifications
|
||||||
|
* also, note the V justification is relative to the first line
|
||||||
|
*/
|
||||||
|
switch( m_HJustify )
|
||||||
|
{
|
||||||
|
case GR_TEXT_HJUSTIFY_LEFT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GR_TEXT_HJUSTIFY_CENTER:
|
||||||
|
rect.SetX( rect.GetX() - (rect.GetWidth() / 2) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GR_TEXT_HJUSTIFY_RIGHT:
|
||||||
|
rect.SetX( rect.GetX() - rect.GetWidth() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dy = m_Size.y + m_Width;
|
||||||
|
switch( m_VJustify )
|
||||||
|
{
|
||||||
|
case GR_TEXT_VJUSTIFY_TOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GR_TEXT_VJUSTIFY_CENTER:
|
||||||
|
rect.SetY( rect.GetY() - (dy / 2) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GR_TEXT_VJUSTIFY_BOTTOM:
|
||||||
|
rect.SetY( rect.GetY() + (dy / 2) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
rect.Normalize(); // Make h and v sizes always >= 0
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
bool EDA_TextStruct::HitTest( const wxPoint& posref )
|
bool EDA_TextStruct::HitTest( const wxPoint& posref )
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
|
@ -212,21 +303,13 @@ bool EDA_TextStruct::HitTest( const wxPoint& posref )
|
||||||
* false else.
|
* false else.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
int dx, dy;
|
EDA_Rect rect = GetTextBox( -1 ); // Get the full text area.
|
||||||
wxPoint location;
|
|
||||||
|
|
||||||
dx = (int) ( ( Pitch() * GetLength() ) / 2 );
|
|
||||||
dy = m_Size.y / 2;
|
|
||||||
|
|
||||||
/* Is the ref point inside the text area ? */
|
/* Is the ref point inside the text area ? */
|
||||||
location = posref - m_Pos;
|
wxPoint location = posref;
|
||||||
|
RotatePoint( &location, m_Pos, -m_Orient );
|
||||||
|
|
||||||
RotatePoint( &location, -m_Orient );
|
return rect.Inside ( location);
|
||||||
|
|
||||||
if( ( abs( location.x ) <= abs( dx ) ) && ( abs( location.y ) <= abs( dy ) ) )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,46 +362,42 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{
|
{
|
||||||
|
if( m_MultilineAllowed )
|
||||||
if ( m_MultilineAllowed )
|
|
||||||
{
|
{
|
||||||
wxPoint pos = m_Pos;
|
wxPoint pos = m_Pos;
|
||||||
wxArrayString* list = wxStringSplit( m_Text, '\n' );
|
wxArrayString* list = wxStringSplit( m_Text, '\n' );
|
||||||
wxPoint offset;
|
wxPoint offset;
|
||||||
|
|
||||||
offset.y = (int) (m_Size.y * 1.5 );
|
offset.y = GetInterline();
|
||||||
|
|
||||||
RotatePoint( &offset, m_Orient );
|
RotatePoint( &offset, m_Orient );
|
||||||
if( m_Mirror )
|
|
||||||
offset.x = -offset.x;
|
|
||||||
for( unsigned i = 0; i<list->Count(); i++ )
|
for( unsigned i = 0; i<list->Count(); i++ )
|
||||||
{
|
{
|
||||||
wxString txt = list->Item( i );
|
wxString txt = list->Item( i );
|
||||||
DrawOneLineOfText( aPanel,
|
DrawOneLineOfText( aPanel,
|
||||||
aDC,
|
aDC,
|
||||||
aOffset,
|
aOffset,
|
||||||
aColor,
|
aColor,
|
||||||
aDrawMode,
|
aDrawMode,
|
||||||
aDisplayMode,
|
aDisplayMode,
|
||||||
aAnchor_color,
|
aAnchor_color,
|
||||||
txt,
|
txt,
|
||||||
pos );
|
pos );
|
||||||
pos += offset;
|
pos += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete (list);
|
delete (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
DrawOneLineOfText( aPanel,
|
DrawOneLineOfText( aPanel,
|
||||||
aDC,
|
aDC,
|
||||||
aOffset,
|
aOffset,
|
||||||
aColor,
|
aColor,
|
||||||
aDrawMode,
|
aDrawMode,
|
||||||
aDisplayMode,
|
aDisplayMode,
|
||||||
aAnchor_color,
|
aAnchor_color,
|
||||||
m_Text,
|
m_Text,
|
||||||
m_Pos );
|
m_Pos );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -336,10 +415,10 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
||||||
* @param EDA_Colors aPos = the position of this line ).
|
* @param EDA_Colors aPos = the position of this line ).
|
||||||
*/
|
*/
|
||||||
void EDA_TextStruct::DrawOneLineOfText( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
void EDA_TextStruct::DrawOneLineOfText( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
||||||
const wxPoint& aOffset, EDA_Colors aColor,
|
const wxPoint& aOffset, EDA_Colors aColor,
|
||||||
int aDrawMode,
|
int aDrawMode,
|
||||||
GRFillMode aDisplayMode, EDA_Colors aAnchor_color,
|
GRFillMode aDisplayMode, EDA_Colors aAnchor_color,
|
||||||
wxString& aText, wxPoint aPos )
|
wxString& aText, wxPoint aPos )
|
||||||
{
|
{
|
||||||
int width = m_Width;
|
int width = m_Width;
|
||||||
|
|
||||||
|
@ -353,7 +432,7 @@ void EDA_TextStruct::DrawOneLineOfText( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
||||||
if( aAnchor_color != UNSPECIFIED_COLOR )
|
if( aAnchor_color != UNSPECIFIED_COLOR )
|
||||||
{
|
{
|
||||||
int anchor_size = aPanel->GetScreen()->Unscale( 2 );
|
int anchor_size = aPanel->GetScreen()->Unscale( 2 );
|
||||||
aAnchor_color = (EDA_Colors) (aAnchor_color & MASKCOLOR);
|
aAnchor_color = (EDA_Colors) ( aAnchor_color & MASKCOLOR );
|
||||||
|
|
||||||
int cX = aPos.x + aOffset.x;
|
int cX = aPos.x + aOffset.x;
|
||||||
int cY = aPos.y + aOffset.y;
|
int cY = aPos.y + aOffset.y;
|
||||||
|
|
|
@ -709,9 +709,9 @@ void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& Center )
|
||||||
DrawText = (SCH_TEXT*) DrawStruct;
|
DrawText = (SCH_TEXT*) DrawStruct;
|
||||||
px = DrawText->m_Pos;
|
px = DrawText->m_Pos;
|
||||||
if( DrawText->m_Orient == 0 ) /* horizontal text */
|
if( DrawText->m_Orient == 0 ) /* horizontal text */
|
||||||
dx = DrawText->Len_Size() / 2;
|
dx = DrawText->LenSize(DrawText->m_Text) / 2;
|
||||||
else if( DrawText->m_Orient == 2 ) /* invert horizontal text*/
|
else if( DrawText->m_Orient == 2 ) /* invert horizontal text*/
|
||||||
dx = -DrawText->Len_Size() / 2;
|
dx = -DrawText->LenSize(DrawText->m_Text) / 2;
|
||||||
else
|
else
|
||||||
dx = 0;
|
dx = 0;
|
||||||
px.x += dx;
|
px.x += dx;
|
||||||
|
|
|
@ -567,10 +567,31 @@ public:
|
||||||
bool HitTest( EDA_Rect& refArea );
|
bool HitTest( EDA_Rect& refArea );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function Len_Size
|
* Function LenSize
|
||||||
* Return the text lenght in internal units
|
* @return the text lenght in internal units
|
||||||
|
* @param aLine : the line of text to consider.
|
||||||
|
* For single line text, this parameter is always m_Text
|
||||||
*/
|
*/
|
||||||
int Len_Size();
|
int LenSize(const wxString & aLine);
|
||||||
|
|
||||||
|
/** Function GetTextBox
|
||||||
|
* useful in multiline texts to calculate the full text or a line area (for zones filling, locate functions....)
|
||||||
|
* @return the rect containing the line of text (i.e. the position and the size of one line)
|
||||||
|
* this rectangle is calculated for 0 orient text. if orient is not 0 the rect must be rotated to match the physical area
|
||||||
|
* @param aLine : the line of text to consider.
|
||||||
|
* for single line text, aLine is unused
|
||||||
|
* If aLine == -1, the full area (considering all lines) is returned
|
||||||
|
*/
|
||||||
|
EDA_Rect GetTextBox( int aLine = -1);
|
||||||
|
|
||||||
|
/** Function GetInterline
|
||||||
|
* return the distance between 2 text lines
|
||||||
|
* has meaning only for multiline texts
|
||||||
|
*/
|
||||||
|
int GetInterline()
|
||||||
|
{
|
||||||
|
return (( m_Size.y * 13 ) / 10) + m_Width;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BASE_STRUCT_H */
|
#endif /* BASE_STRUCT_H */
|
||||||
|
|
|
@ -277,8 +277,6 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TYPE_TEXTE:
|
case TYPE_TEXTE:
|
||||||
if( ( (TEXTE_PCB*) item )->GetLength() == 0 )
|
|
||||||
break;
|
|
||||||
AddTextBoxWithClearancePolygon( booleng, (TEXTE_PCB*) item, m_ZoneClearance );
|
AddTextBoxWithClearancePolygon( booleng, (TEXTE_PCB*) item, m_ZoneClearance );
|
||||||
have_poly_to_substract = true;
|
have_poly_to_substract = true;
|
||||||
break;
|
break;
|
||||||
|
@ -1234,36 +1232,29 @@ void AddRingPolygon( Bool_Engine* aBooleng, wxPoint aCentre,
|
||||||
void AddTextBoxWithClearancePolygon( Bool_Engine* aBooleng,
|
void AddTextBoxWithClearancePolygon( Bool_Engine* aBooleng,
|
||||||
TEXTE_PCB* aText, int aClearanceValue )
|
TEXTE_PCB* aText, int aClearanceValue )
|
||||||
{
|
{
|
||||||
int corners[8]; // Buffer of coordinates
|
if ( aText->GetLength() == 0 )
|
||||||
int ii;
|
return;
|
||||||
|
|
||||||
int dx = aText->Pitch() * aText->GetLength();
|
wxPoint corners[4]; // Buffer of polygon corners
|
||||||
int dy = aText->m_Size.y + aText->m_Width;
|
|
||||||
|
|
||||||
/* Creates bounding box (rectangle) for an horizontal text */
|
EDA_Rect rect = aText->GetTextBox( -1 );
|
||||||
dx /= 2; dy /= 2; /* dx et dy = demi dimensionx X et Y */
|
rect.Inflate( aClearanceValue, aClearanceValue );
|
||||||
dx += aClearanceValue;
|
corners[0] = rect.GetOrigin();
|
||||||
dy += aClearanceValue;
|
corners[1].y = corners[0].y;
|
||||||
corners[0] = aText->m_Pos.x - dx;
|
corners[1].x = rect.GetRight();
|
||||||
corners[1] = aText->m_Pos.y - dy;
|
corners[2].x = corners[1].x;
|
||||||
corners[2] = aText->m_Pos.x + dx;
|
corners[2].y = rect.GetBottom();
|
||||||
corners[3] = aText->m_Pos.y - dy;
|
corners[3].y = corners[2].y;
|
||||||
corners[4] = aText->m_Pos.x + dx;
|
corners[3].x = corners[0].x;
|
||||||
corners[5] = aText->m_Pos.y + dy;
|
|
||||||
corners[6] = aText->m_Pos.x - dx;
|
|
||||||
corners[7] = aText->m_Pos.y + dy;
|
|
||||||
|
|
||||||
// Rotate rectangle
|
|
||||||
RotatePoint( &corners[0], &corners[1], aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
|
|
||||||
RotatePoint( &corners[2], &corners[3], aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
|
|
||||||
RotatePoint( &corners[4], &corners[5], aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
|
|
||||||
RotatePoint( &corners[6], &corners[7], aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
|
|
||||||
|
|
||||||
if( aBooleng->StartPolygonAdd( GROUP_B ) )
|
if( aBooleng->StartPolygonAdd( GROUP_B ) )
|
||||||
{
|
{
|
||||||
for( ii = 0; ii < 8; ii += 2 )
|
for( int ii = 0; ii < 4; ii ++ )
|
||||||
{
|
{
|
||||||
aBooleng->AddPoint( corners[ii], corners[ii + 1] );
|
// Rotate polygon
|
||||||
|
RotatePoint( &corners[ii].x, &corners[ii].y, aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
|
||||||
|
aBooleng->AddPoint( corners[ii].x, corners[ii].y );
|
||||||
}
|
}
|
||||||
|
|
||||||
aBooleng->EndPolygonAdd();
|
aBooleng->EndPolygonAdd();
|
||||||
|
|
Loading…
Reference in New Issue