Move '~' pin name processing to LIB_PIN and SCH_PIN.

This will also allow us to do variable processing in the future if
desired.
This commit is contained in:
Jeff Young 2021-06-12 19:54:34 +01:00
parent ceb23c3aac
commit bcdec0dea7
8 changed files with 84 additions and 59 deletions

View File

@ -945,7 +945,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
if( connection->SubgraphCode() > 0 )
continue;
connection->SetName( pin->GetName() );
connection->SetName( pin->GetShownName() );
int code = assignNewNetCode( *connection );
@ -1241,7 +1241,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
{
auto pin = static_cast<SCH_PIN*>( driver );
if( pin->IsPowerConnection() && pin->GetName() == test_name )
if( pin->IsPowerConnection() && pin->GetShownName() == test_name )
{
match = true;
break;

View File

@ -168,6 +168,15 @@ int LIB_PIN::GetPenWidth() const
}
wxString LIB_PIN::GetShownName() const
{
if( m_name == "~" )
return wxEmptyString;
else
return m_name;
}
void LIB_PIN::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
const TRANSFORM& aTransform )
{
@ -349,9 +358,15 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos,
case PIN_RIGHT: x1 += m_length; break;
}
if( m_name.IsEmpty() )
wxString name = GetShownName();
wxString number = GetShownNumber();
if( name.IsEmpty() )
aDrawPinName = false;
if( number.IsEmpty() )
aDrawPinNum = false;
if( aTextInside ) // Draw the text inside, but the pin numbers outside.
{
if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
@ -362,22 +377,22 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos,
if( aPinOrient == PIN_RIGHT )
{
x = x1 + aTextInside;
GRText( DC, wxPoint( x, y1 ), NameColor, m_name, TEXT_ANGLE_HORIZ,
PinNameSize, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
namePenWidth, false, false );
GRText( DC, wxPoint( x, y1 ), NameColor, name, TEXT_ANGLE_HORIZ, PinNameSize,
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
false );
}
else // Orient == PIN_LEFT
{
x = x1 - aTextInside;
GRText( DC, wxPoint( x, y1 ), NameColor, m_name, TEXT_ANGLE_HORIZ,
PinNameSize, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER,
namePenWidth, false, false );
GRText( DC, wxPoint( x, y1 ), NameColor, name, TEXT_ANGLE_HORIZ, PinNameSize,
GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
false );
}
}
if( aDrawPinNum )
{
GRText( DC, wxPoint(( x1 + aPinPos.x) / 2, y1 - num_offset ), NumColor, m_number,
GRText( DC, wxPoint(( x1 + aPinPos.x) / 2, y1 - num_offset ), NumColor, number,
TEXT_ANGLE_HORIZ, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
}
@ -391,7 +406,7 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos,
if( aDrawPinName )
{
GRText( DC, wxPoint( x1, y ), NameColor, m_name, TEXT_ANGLE_VERT, PinNameSize,
GRText( DC, wxPoint( x1, y ), NameColor, name, TEXT_ANGLE_VERT, PinNameSize,
GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
false );
}
@ -399,7 +414,7 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos,
if( aDrawPinNum )
{
GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
m_number, TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
number, TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
}
}
@ -409,7 +424,7 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos,
if( aDrawPinName )
{
GRText( DC, wxPoint( x1, y ), NameColor, m_name, TEXT_ANGLE_VERT, PinNameSize,
GRText( DC, wxPoint( x1, y ), NameColor, name, TEXT_ANGLE_VERT, PinNameSize,
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
false );
}
@ -417,7 +432,7 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos,
if( aDrawPinNum )
{
GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
m_number, TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
number, TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
}
}
@ -431,14 +446,14 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos,
if( aDrawPinName )
{
x = ( x1 + aPinPos.x) / 2;
GRText( DC, wxPoint( x, y1 - name_offset ), NameColor, m_name, TEXT_ANGLE_HORIZ,
GRText( DC, wxPoint( x, y1 - name_offset ), NameColor, name, TEXT_ANGLE_HORIZ,
PinNameSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM,
namePenWidth, false, false );
}
if( aDrawPinNum )
{
x = ( x1 + aPinPos.x) / 2;
GRText( DC, wxPoint( x, y1 + num_offset ), NumColor, m_number, TEXT_ANGLE_HORIZ,
GRText( DC, wxPoint( x, y1 + num_offset ), NumColor, number, TEXT_ANGLE_HORIZ,
PinNumSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, numPenWidth,
false, false );
}
@ -448,14 +463,14 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos,
if( aDrawPinName )
{
y = ( y1 + aPinPos.y) / 2;
GRText( DC, wxPoint( x1 - name_offset, y ), NameColor, m_name, TEXT_ANGLE_VERT,
GRText( DC, wxPoint( x1 - name_offset, y ), NameColor, name, TEXT_ANGLE_VERT,
PinNameSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM,
namePenWidth, false, false );
}
if( aDrawPinNum )
{
GRText( DC, wxPoint( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), NumColor, m_number,
GRText( DC, wxPoint( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), NumColor, number,
TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP,
numPenWidth, false, false );
}
@ -650,10 +665,13 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinOrient, int aTextInside,
bool aDrawPinNum, bool aDrawPinName ) const
{
if( m_name.IsEmpty() || m_name == wxT( "~" ) )
wxString name = GetShownName();
wxString number = GetShownNumber();
if( name.IsEmpty() )
aDrawPinName = false;
if( m_number.IsEmpty() )
if( number.IsEmpty() )
aDrawPinNum = false;
if( !aDrawPinNum && !aDrawPinName )
@ -705,14 +723,14 @@ void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinO
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
}
aPlotter->Text( wxPoint( x, y1 ), nameColor, m_name, TEXT_ANGLE_HORIZ, pinNameSize,
aPlotter->Text( wxPoint( x, y1 ), nameColor, name, TEXT_ANGLE_HORIZ, pinNameSize,
hjustify, GR_TEXT_VJUSTIFY_CENTER, namePenWidth,
false, false );
}
if( aDrawPinNum )
{
aPlotter->Text( wxPoint( ( x1 + aPinPos.x) / 2, y1 - num_offset ), numColor,
m_number, TEXT_ANGLE_HORIZ, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
number, TEXT_ANGLE_HORIZ, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
}
}
@ -723,14 +741,14 @@ void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinO
y = y1 + aTextInside;
if( aDrawPinName )
aPlotter->Text( wxPoint( x1, y ), nameColor, m_name, TEXT_ANGLE_VERT,
aPlotter->Text( wxPoint( x1, y ), nameColor, name, TEXT_ANGLE_VERT,
pinNameSize, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER,
namePenWidth, false, false );
if( aDrawPinNum )
{
aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
m_number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
}
}
@ -740,7 +758,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinO
if( aDrawPinName )
{
aPlotter->Text( wxPoint( x1, y ), nameColor, m_name, TEXT_ANGLE_VERT,
aPlotter->Text( wxPoint( x1, y ), nameColor, name, TEXT_ANGLE_VERT,
pinNameSize, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
namePenWidth, false, false );
}
@ -748,7 +766,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinO
if( aDrawPinNum )
{
aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
m_number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
}
}
@ -762,7 +780,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinO
if( aDrawPinName )
{
x = ( x1 + aPinPos.x) / 2;
aPlotter->Text( wxPoint( x, y1 - name_offset ), nameColor, m_name,
aPlotter->Text( wxPoint( x, y1 - name_offset ), nameColor, name,
TEXT_ANGLE_HORIZ, pinNameSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
}
@ -770,7 +788,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinO
if( aDrawPinNum )
{
x = ( x1 + aPinPos.x ) / 2;
aPlotter->Text( wxPoint( x, y1 + num_offset ), numColor, m_number,
aPlotter->Text( wxPoint( x, y1 + num_offset ), numColor, number,
TEXT_ANGLE_HORIZ, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
}
@ -780,7 +798,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinO
if( aDrawPinName )
{
y = ( y1 + aPinPos.y ) / 2;
aPlotter->Text( wxPoint( x1 - name_offset, y ), nameColor, m_name,
aPlotter->Text( wxPoint( x1 - name_offset, y ), nameColor, name,
TEXT_ANGLE_VERT, pinNameSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
}
@ -788,7 +806,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinO
if( aDrawPinNum )
{
aPlotter->Text( wxPoint( x1 + num_offset, ( y1 + aPinPos.y ) / 2 ), numColor,
m_number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
}
}
@ -1002,20 +1020,16 @@ void LIB_PIN::Plot( PLOTTER* aPlotter, const wxPoint& aPffset, bool aFill,
void LIB_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
{
wxString text = m_number.IsEmpty() ? wxT( "?" ) : m_number;
LIB_ITEM::GetMsgPanelInfo( aFrame, aList );
aList.push_back( MSG_PANEL_ITEM( _( "Name" ), m_name ) );
aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text ) );
aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetShownName() ) );
aList.push_back( MSG_PANEL_ITEM( _( "Number" ), GetShownNumber() ) );
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( m_type ) ) );
aList.push_back( MSG_PANEL_ITEM( _( "Style" ), PinShapeGetText( m_shape ) ) );
text = PinShapeGetText( m_shape );
wxString text = IsVisible() ? _( "Yes" ) : _( "No" );
aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text ) );
text = IsVisible() ? _( "Yes" ) : _( "No" );
aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), text ) );
// Display pin length
text = StringFromValue( aFrame->GetUserUnits(), m_length );
aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text ) );
@ -1041,8 +1055,10 @@ const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly )
wxPoint begin;
wxPoint end;
int nameTextOffset = 0;
bool showName = !m_name.IsEmpty() && ( m_name != wxT( "~" ) );
bool showNum = !m_number.IsEmpty();
wxString name = GetShownName();
wxString number = GetShownNumber();
bool showName = !name.IsEmpty();
bool showNum = !number.IsEmpty();
int minsizeV = TARGET_PIN_RADIUS;
if( !aIncludeInvisibles && !IsVisible() )
@ -1066,7 +1082,7 @@ const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly )
}
// First, calculate boundary box corners position
int numberTextLength = showNum ? m_numTextSize * m_number.Len() : 0;
int numberTextLength = showNum ? m_numTextSize * number.Len() : 0;
// Actual text height is bigger than text size
int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
@ -1085,12 +1101,9 @@ const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly )
if( showName )
{
int length = m_name.Len();
// Don't count the line over text symbol.
if( m_name.Left( 1 ) == wxT( "~" ) )
length -= 1;
int length = name.Len();
// TODO: exclude markup characters!
nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
// Actual text height are bigger than text size
@ -1196,7 +1209,5 @@ void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
void LIB_PIN::CalcEdit( const wxPoint& aPosition )
{
if( IsMoving() )
{
MoveTo( aPosition );
}
}

View File

@ -104,6 +104,7 @@ public:
}
const wxString& GetName() const { return m_name; }
wxString GetShownName() const;
void SetName( const wxString& aName )
{
m_name = aName;
@ -113,6 +114,7 @@ public:
}
const wxString& GetNumber() const { return m_number; }
wxString GetShownNumber() const { return m_number; }
void SetNumber( const wxString& aNumber )
{
m_number = aNumber;

View File

@ -583,8 +583,8 @@ XNODE* NETLIST_EXPORTER_XML::makeLibParts()
XNODE* pin;
pins->AddChild( pin = node( "pin" ) );
pin->AddAttribute( "num", pinList[i]->GetNumber() );
pin->AddAttribute( "name", pinList[i]->GetName() );
pin->AddAttribute( "num", pinList[i]->GetShownNumber() );
pin->AddAttribute( "name", pinList[i]->GetShownName() );
pin->AddAttribute( "type", pinList[i]->GetCanonicalElectricalTypeName() );
// caution: construction work site here, drive slowly
@ -738,7 +738,7 @@ XNODE* NETLIST_EXPORTER_XML::makeListOfNets( unsigned aCtl )
xnode->AddAttribute( "ref", refText );
xnode->AddAttribute( "pin", pinText );
wxString pinName = netNode.m_Pin->GetName();
wxString pinName = netNode.m_Pin->GetShownName();
wxString pinType = netNode.m_Pin->GetCanonicalElectricalTypeName();
// ~ is a char used to code empty strings in libs.

View File

@ -980,12 +980,12 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
size [INSIDE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
thickness[INSIDE] = nameLineWidth;
colour [INSIDE] = getRenderColor( aPin, LAYER_PINNAM, drawingShadows );
text [INSIDE] = aPin->GetName();
text [INSIDE] = aPin->GetShownName();
size [ABOVE] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
thickness[ABOVE] = numLineWidth;
colour [ABOVE] = getRenderColor( aPin, LAYER_PINNUM, drawingShadows );
text [ABOVE] = aPin->GetNumber();
text [ABOVE] = aPin->GetShownNumber();
}
// Otherwise pin NAMES go above and pin NUMBERS go below
else
@ -993,12 +993,12 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
size [ABOVE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
thickness[ABOVE] = nameLineWidth;
colour [ABOVE] = getRenderColor( aPin, LAYER_PINNAM, drawingShadows );
text [ABOVE] = aPin->GetName();
text [ABOVE] = aPin->GetShownName();
size [BELOW] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
thickness[BELOW] = numLineWidth;
colour [BELOW] = getRenderColor( aPin, LAYER_PINNUM, drawingShadows );
text [BELOW] = aPin->GetNumber();
text [BELOW] = aPin->GetShownNumber();
}
if( m_schSettings.m_ShowPinsElectricalType )
@ -1472,7 +1472,7 @@ void SCH_PAINTER::draw( SCH_SYMBOL* aSymbol, int aLayer )
tempPin->ClearFlags();
tempPin->SetFlags( symbolPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED
tempPin->SetName( symbolPin->GetName() );
tempPin->SetName( symbolPin->GetShownName() );
tempPin->SetType( symbolPin->GetType() );
tempPin->SetShape( symbolPin->GetShape() );

View File

@ -85,6 +85,15 @@ wxString SCH_PIN::GetName() const
}
wxString SCH_PIN::GetShownName() const
{
if( !m_alt.IsEmpty() )
return m_alt;
return m_libPin->GetShownName();
}
ELECTRICAL_PINTYPE SCH_PIN::GetType() const
{
if( !m_alt.IsEmpty() )
@ -174,8 +183,8 @@ void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg ) );
aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetName() ) );
msg = GetNumber().IsEmpty() ? wxT( "?" ) : GetNumber();
aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetShownName() ) );
msg = GetNumber().IsEmpty() ? wxT( "?" ) : GetShownNumber();
aList.push_back( MSG_PANEL_ITEM( _( "Number" ), msg ) );
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( GetType() ) ) );

View File

@ -103,8 +103,11 @@ public:
bool IsVisible() const { return m_libPin->IsVisible(); }
wxString GetName() const;
wxString GetShownName() const;
wxString GetNumber() const { return m_number; }
wxString GetShownNumber() const { return m_number; }
void SetNumber( const wxString& aNumber ) { m_number = aNumber; }
ELECTRICAL_PINTYPE GetType() const;

View File

@ -659,7 +659,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
else if( primitive == "d" )
param = wxT( "Id" );
else
param = wxString::Format( wxT( "I%s" ), pin->GetName().Lower() );
param = wxString::Format( wxT( "I%s" ), pin->GetShownName().Lower() );
simFrame->AddCurrentPlot( symbol->GetRef( &m_frame->GetCurrentSheet() ),
param );