Make global labels have the same spin style as net/hierarchical labels

For legacy reasons, it stored left and right "spin" as flipped integers in the file format.
But the code handled the flip in multiple locations rather than just doing it on file io.
This change unifies the internal code and does the mapping in the file I/O.
This commit is contained in:
Mark Roszko 2020-01-08 19:07:55 +00:00 committed by Ian McInerney
parent fd0d5fdb38
commit ca34ade00c
19 changed files with 883 additions and 1017 deletions

View File

@ -54,38 +54,6 @@
class OUTPUTFORMATTER;
class wxFindReplaceData;
// Sadly we store the orientation of hierarchical and global labels using a different
// int encoding than that for local labels:
// Global Local
// Left justified 0 2
// Up 1 3
// Right justified 2 0
// Down 3 1
int EDA_TEXT::MapOrientation( KICAD_T labelType, int aOrientation )
{
if( labelType == SCH_LABEL_T )
return aOrientation;
switch( aOrientation )
{
case 0: return 2;
case 2: return 0;
default: return aOrientation;
}
}
int EDA_TEXT::MapOrientation( KICAD_T fromLabelType, KICAD_T toLabelType, int aOrientation )
{
bool fromNormal = ( ( fromLabelType == SCH_TEXT_T ) || ( fromLabelType == SCH_LABEL_T ) );
bool toNormal = ( ( toLabelType == SCH_TEXT_T ) || ( toLabelType == SCH_LABEL_T ) );
if( fromNormal != toNormal )
return MapOrientation( SCH_GLOBAL_LABEL_T, aOrientation );
else
return aOrientation;
}
EDA_TEXT_HJUSTIFY_T EDA_TEXT::MapHorizJustify( int aHorizJustify )
{

View File

@ -98,7 +98,7 @@ bool CONNECTION_SUBGRAPH::ResolveDrivers( bool aCreateMarkers )
{
auto p = static_cast<SCH_SHEET_PIN*>( c );
if( p->GetShape() == NET_OUTPUT )
if( p->GetShape() == PINSHEETLABEL_SHAPE::OUTPUT )
{
m_driver = c;
break;

View File

@ -212,10 +212,9 @@ bool DIALOG_LABEL_EDITOR::TransferDataToWindow()
}
// Set text options:
int orient = m_CurrentText->GetLabelSpinStyle();
m_TextOrient->SetSelection( EDA_TEXT::MapOrientation( m_CurrentText->Type(), orient ) );
m_TextOrient->SetSelection( static_cast<int>( m_CurrentText->GetLabelSpinStyle() ) );
m_TextShape->SetSelection( m_CurrentText->GetShape() );
m_TextShape->SetSelection( static_cast<int>( m_CurrentText->GetShape() ) );
int style = 0;
@ -320,8 +319,7 @@ bool DIALOG_LABEL_EDITOR::TransferDataFromWindow()
return false;
}
int orient = m_TextOrient->GetSelection();
m_CurrentText->SetLabelSpinStyle( EDA_TEXT::MapOrientation( m_CurrentText->Type(), orient ) );
m_CurrentText->SetLabelSpinStyle( m_TextOrient->GetSelection() );
m_CurrentText->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 30 2017)
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -12,31 +12,31 @@
DIALOG_LABEL_EDITOR_BASE::DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bMainSizer;
bMainSizer = new wxBoxSizer( wxVERTICAL );
m_textEntrySizer = new wxFlexGridSizer( 4, 2, 3, 3 );
m_textEntrySizer->AddGrowableCol( 1 );
m_textEntrySizer->AddGrowableRow( 1 );
m_textEntrySizer->SetFlexibleDirection( wxBOTH );
m_textEntrySizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_labelSingleLine = new wxStaticText( this, wxID_ANY, _("Label:"), wxDefaultPosition, wxDefaultSize, 0 );
m_labelSingleLine->Wrap( -1 );
m_labelSingleLine->SetToolTip( _("Enter the text to be used within the schematic") );
m_textEntrySizer->Add( m_labelSingleLine, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 3 );
m_valueSingleLine = new wxTextCtrl( this, wxID_VALUESINGLE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER|wxTE_RICH );
m_valueSingleLine->SetMinSize( wxSize( 360,-1 ) );
m_textEntrySizer->Add( m_valueSingleLine, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 3 );
m_labelMultiLine = new wxStaticText( this, wxID_ANY, _("Text:"), wxDefaultPosition, wxDefaultSize, 0 );
m_labelMultiLine->Wrap( -1 );
m_textEntrySizer->Add( m_labelMultiLine, 0, wxRIGHT, 5 );
m_valueMultiLine = new wxStyledTextCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
m_valueMultiLine->SetUseTabs( true );
m_valueMultiLine->SetTabWidth( 4 );
@ -67,76 +67,76 @@ DIALOG_LABEL_EDITOR_BASE::DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID
m_valueMultiLine->SetSelBackground( true, wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
m_valueMultiLine->SetSelForeground( true, wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
m_valueMultiLine->SetMinSize( wxSize( 480,100 ) );
m_textEntrySizer->Add( m_valueMultiLine, 1, wxEXPAND | wxALL, 5 );
m_labelCombo = new wxStaticText( this, wxID_ANY, _("Label:"), wxDefaultPosition, wxDefaultSize, 0 );
m_labelCombo->Wrap( -1 );
m_textEntrySizer->Add( m_labelCombo, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
m_valueCombo = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxTE_PROCESS_ENTER );
m_valueCombo = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxTE_PROCESS_ENTER );
m_valueCombo->SetMinSize( wxSize( 360,-1 ) );
m_textEntrySizer->Add( m_valueCombo, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
m_textSizeLabel = new wxStaticText( this, wxID_ANY, _("Text Size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_textSizeLabel->Wrap( -1 );
m_textEntrySizer->Add( m_textSizeLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 3 );
wxBoxSizer* bSizeCtrlSizer;
bSizeCtrlSizer = new wxBoxSizer( wxHORIZONTAL );
m_textSizeCtrl = new wxTextCtrl( this, wxID_SIZE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bSizeCtrlSizer->Add( m_textSizeCtrl, 0, wxEXPAND|wxLEFT|wxRIGHT, 3 );
m_textSizeUnits = new wxStaticText( this, wxID_ANY, _("units"), wxDefaultPosition, wxDefaultSize, 0 );
m_textSizeUnits->Wrap( -1 );
bSizeCtrlSizer->Add( m_textSizeUnits, 0, wxALIGN_CENTER_VERTICAL, 2 );
m_textEntrySizer->Add( bSizeCtrlSizer, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 3 );
bMainSizer->Add( m_textEntrySizer, 1, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 12 );
wxBoxSizer* m_OptionsSizer;
m_OptionsSizer = new wxBoxSizer( wxHORIZONTAL );
wxString m_TextOrientChoices[] = { _("Right"), _("Up"), _("Left"), _("Down") };
wxString m_TextOrientChoices[] = { _("Left"), _("Up"), _("Right"), _("Down") };
int m_TextOrientNChoices = sizeof( m_TextOrientChoices ) / sizeof( wxString );
m_TextOrient = new wxRadioBox( this, wxID_ANY, _("Orientation"), wxDefaultPosition, wxDefaultSize, m_TextOrientNChoices, m_TextOrientChoices, 1, wxRA_SPECIFY_COLS );
m_TextOrient->SetSelection( 0 );
m_OptionsSizer->Add( m_TextOrient, 1, wxRIGHT|wxTOP|wxEXPAND, 3 );
wxString m_TextStyleChoices[] = { _("Normal"), _("Italic"), _("Bold"), _("Bold and italic") };
int m_TextStyleNChoices = sizeof( m_TextStyleChoices ) / sizeof( wxString );
m_TextStyle = new wxRadioBox( this, wxID_ANY, _("Style"), wxDefaultPosition, wxDefaultSize, m_TextStyleNChoices, m_TextStyleChoices, 1, wxRA_SPECIFY_COLS );
m_TextStyle->SetSelection( 3 );
m_OptionsSizer->Add( m_TextStyle, 1, wxLEFT|wxRIGHT|wxTOP|wxEXPAND, 3 );
wxString m_TextShapeChoices[] = { _("Input"), _("Output"), _("Bidirectional"), _("Tri-state"), _("Passive") };
int m_TextShapeNChoices = sizeof( m_TextShapeChoices ) / sizeof( wxString );
m_TextShape = new wxRadioBox( this, wxID_ANY, _("Shape"), wxDefaultPosition, wxDefaultSize, m_TextShapeNChoices, m_TextShapeChoices, 1, wxRA_SPECIFY_COLS );
m_TextShape->SetSelection( 3 );
m_OptionsSizer->Add( m_TextShape, 1, wxEXPAND|wxTOP|wxLEFT, 3 );
bMainSizer->Add( m_OptionsSizer, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 10 );
m_sdbSizer1 = new wxStdDialogButtonSizer();
m_sdbSizer1OK = new wxButton( this, wxID_OK );
m_sdbSizer1->AddButton( m_sdbSizer1OK );
m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL );
m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
m_sdbSizer1->Realize();
bMainSizer->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 5 );
this->SetSizer( bMainSizer );
this->Layout();
bMainSizer->Fit( this );
// Connect Events
m_valueSingleLine->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
m_valueCombo->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
@ -147,5 +147,5 @@ DIALOG_LABEL_EDITOR_BASE::~DIALOG_LABEL_EDITOR_BASE()
// Disconnect Events
m_valueSingleLine->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
m_valueCombo->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
}

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,11 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 30 2017)
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_EDIT_LABEL_BASE_H__
#define __DIALOG_EDIT_LABEL_BASE_H__
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
@ -34,14 +33,14 @@
class DIALOG_LABEL_EDITOR_BASE : public DIALOG_SHIM
{
private:
protected:
enum
{
wxID_VALUESINGLE = 1000,
wxID_SIZE
};
wxFlexGridSizer* m_textEntrySizer;
wxStaticText* m_labelSingleLine;
wxTextCtrl* m_valueSingleLine;
@ -58,16 +57,15 @@ class DIALOG_LABEL_EDITOR_BASE : public DIALOG_SHIM
wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK;
wxButton* m_sdbSizer1Cancel;
// Virtual event handlers, overide them in your derived class
virtual void OnEnterKey( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Text Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Text Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_LABEL_EDITOR_BASE();
};
#endif //__DIALOG_EDIT_LABEL_BASE_H__

View File

@ -81,7 +81,7 @@ bool DIALOG_EDIT_SHEET_PIN::TransferDataToWindow()
m_textName->SelectAll();
m_textWidth.SetValue( m_sheetPin->GetTextWidth() );
m_textHeight.SetValue( m_sheetPin->GetTextHeight() );
m_choiceConnectionType->SetSelection( m_sheetPin->GetShape() );
m_choiceConnectionType->SetSelection( static_cast<int>( m_sheetPin->GetShape() ) );
return true;
}

View File

@ -225,8 +225,7 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem( const SCH_SHEET_PATH& aS
{
if( m_orientation->GetStringSelection() != INDETERMINATE )
{
int orient = m_orientation->GetSelection();
sch_text->SetLabelSpinStyle( EDA_TEXT::MapOrientation( sch_text->Type(), orient ) );
sch_text->SetLabelSpinStyle( m_orientation->GetSelection() );
}
}

View File

@ -39,8 +39,8 @@
#include "invoke_sch_dialog.h"
static PINSHEETLABEL_SHAPE lastGlobalLabelShape = NET_INPUT;
static int lastTextOrientation = 0;
static PINSHEETLABEL_SHAPE lastGlobalLabelShape = PINSHEETLABEL_SHAPE::INPUT;
static LABEL_SPIN_STYLE lastTextOrientation = LABEL_SPIN_STYLE::LEFT;
static bool lastTextBold = false;
static bool lastTextItalic = false;
@ -197,10 +197,10 @@ void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aNewType )
if( oldType == aNewType )
return;
SCH_TEXT* newtext = nullptr;
const wxPoint& position = aText->GetPosition();
int orientation = aText->GetLabelSpinStyle();
wxString txt = UnescapeString( aText->GetText() );
SCH_TEXT* newtext = nullptr;
const wxPoint& position = aText->GetPosition();
LABEL_SPIN_STYLE orientation = aText->GetLabelSpinStyle();
wxString txt = UnescapeString( aText->GetText() );
// There can be characters in a SCH_TEXT object that can break labels so we have to
// fix them here.
@ -234,7 +234,7 @@ void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aNewType )
//
newtext->SetFlags( aText->GetEditFlags() );
newtext->SetShape( aText->GetShape() );
newtext->SetLabelSpinStyle( EDA_TEXT::MapOrientation( oldType, aNewType, orientation ) );
newtext->SetLabelSpinStyle( orientation );
newtext->SetTextSize( aText->GetTextSize() );
newtext->SetThickness( aText->GetThickness() );
newtext->SetItalic( aText->IsItalic() );

View File

@ -930,7 +930,7 @@ void SCH_EAGLE_PLUGIN::loadSegments(
label->SetPosition( firstWire->GetStartPoint() );
label->SetText( escapeName( netName ) );
label->SetTextSize( wxSize( Mils2iu( 10 ), Mils2iu( 10 ) ) );
label->SetLabelSpinStyle( 0 );
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
screen->Append( label.release() );
}
}
@ -996,16 +996,16 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadLabel( wxXmlNode* aLabelNode, const wxString& aN
label->SetPosition( elabelpos );
label->SetText( escapeName( elabel.netname ) );
label->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) );
label->SetLabelSpinStyle( global ? 2 : 0 );
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
if( elabel.rot )
{
int offset = global ? 2 : 0;
label->SetLabelSpinStyle( int( elabel.rot->degrees / 90 + offset ) % 4 );
label->SetLabelSpinStyle( KiROUND( elabel.rot->degrees / 90 ) % 4 );
if( elabel.rot->mirror
&& ( label->GetLabelSpinStyle() == 0 || label->GetLabelSpinStyle() == 2 ) )
label->SetLabelSpinStyle( ( label->GetLabelSpinStyle() + 2 ) % 4 );
if( elabel.rot->mirror )
{
label->SetLabelSpinStyle( label->GetLabelSpinStyle().MirrorY() );
}
}
return label.release();
@ -2580,7 +2580,7 @@ void SCH_EAGLE_PLUGIN::addImplicitConnections(
netLabel->SetPosition( aComponent->GetPinPhysicalPosition( pin ) );
netLabel->SetText( extractNetName( pin->GetName() ) );
netLabel->SetTextSize( wxSize( Mils2iu( 10 ), Mils2iu( 10 ) ) );
netLabel->SetLabelSpinStyle( 0 );
netLabel->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
aScreen->Append( netLabel );
}

View File

@ -1033,23 +1033,23 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::loadSheet( LINE_READER& aReader )
switch( parseChar( aReader, line, &line ) )
{
case 'I':
sheetPin->SetShape( NET_INPUT );
sheetPin->SetShape( PINSHEETLABEL_SHAPE::INPUT );
break;
case 'O':
sheetPin->SetShape( NET_OUTPUT );
sheetPin->SetShape( PINSHEETLABEL_SHAPE::OUTPUT );
break;
case 'B':
sheetPin->SetShape( NET_BIDI );
sheetPin->SetShape( PINSHEETLABEL_SHAPE::BIDI );
break;
case 'T':
sheetPin->SetShape( NET_TRISTATE );
sheetPin->SetShape( PINSHEETLABEL_SHAPE::TRISTATE );
break;
case 'U':
sheetPin->SetShape( NET_UNSPECIFIED );
sheetPin->SetShape( PINSHEETLABEL_SHAPE::UNSPECIFIED );
break;
default:
SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
@ -1361,6 +1361,17 @@ SCH_BUS_ENTRY_BASE* SCH_LEGACY_PLUGIN::loadBusEntry( LINE_READER& aReader )
return busEntry.release();
}
// clang-format off
const std::map<PINSHEETLABEL_SHAPE, const char*> sheetLabelNames
{
{ PINSHEETLABEL_SHAPE::INPUT, "Input" },
{ PINSHEETLABEL_SHAPE::OUTPUT, "Output" },
{ PINSHEETLABEL_SHAPE::BIDI, "BiDi" },
{ PINSHEETLABEL_SHAPE::TRISTATE, "3State" },
{ PINSHEETLABEL_SHAPE::UNSPECIFIED, "UnSpc" },
};
// clang-format on
SCH_TEXT* SCH_LEGACY_PLUGIN::loadText( LINE_READER& aReader )
{
@ -1393,7 +1404,26 @@ SCH_TEXT* SCH_LEGACY_PLUGIN::loadText( LINE_READER& aReader )
position.x = Mils2Iu( parseInt( aReader, line, &line ) );
position.y = Mils2Iu( parseInt( aReader, line, &line ) );
text->SetPosition( position );
text->SetLabelSpinStyle( parseInt( aReader, line, &line ) );
int spinStyle = parseInt( aReader, line, &line );
// Sadly we store the orientation of hierarchical and global labels using a different
// int encoding than that for local labels:
// Global Local
// Left justified 0 2
// Up 1 3
// Right justified 2 0
// Down 3 1
// So we must flip it as the enum is setup with the "global" numbering
if( text->Type() != SCH_GLOBAL_LABEL_T && text->Type() != SCH_HIER_LABEL_T )
{
if( spinStyle == 0 )
spinStyle = 2;
else if( spinStyle == 2 )
spinStyle = 0;
}
text->SetLabelSpinStyle( spinStyle );
int size = Mils2Iu( parseInt( aReader, line, &line ) );
@ -1402,16 +1432,14 @@ SCH_TEXT* SCH_LEGACY_PLUGIN::loadText( LINE_READER& aReader )
// Parse the global and hierarchical label type.
if( text->Type() == SCH_HIER_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
{
if( strCompare( SheetLabelType[NET_INPUT], line, &line ) )
text->SetShape( NET_INPUT );
else if( strCompare( SheetLabelType[NET_OUTPUT], line, &line ) )
text->SetShape( NET_OUTPUT );
else if( strCompare( SheetLabelType[NET_BIDI], line, &line ) )
text->SetShape( NET_BIDI );
else if( strCompare( SheetLabelType[NET_TRISTATE], line, &line ) )
text->SetShape( NET_TRISTATE );
else if( strCompare( SheetLabelType[NET_UNSPECIFIED], line, &line ) )
text->SetShape( NET_UNSPECIFIED );
auto resultIt = std::find_if( sheetLabelNames.begin(), sheetLabelNames.end(),
[ &line ]( const auto& it )
{
return strCompare( it.second, line, &line );
} );
if( resultIt != sheetLabelNames.end() )
text->SetShape( resultIt->first );
else
SCH_PARSE_ERROR( "invalid label type", aReader, line );
}
@ -2159,12 +2187,22 @@ void SCH_LEGACY_PLUGIN::saveSheet( SCH_SHEET* aSheet )
switch( pin.GetShape() )
{
case NET_INPUT: type = 'I'; break;
case NET_OUTPUT: type = 'O'; break;
case NET_BIDI: type = 'B'; break;
case NET_TRISTATE: type = 'T'; break;
case PINSHEETLABEL_SHAPE::INPUT:
type = 'I';
break;
case PINSHEETLABEL_SHAPE::OUTPUT:
type = 'O';
break;
case PINSHEETLABEL_SHAPE::BIDI:
type = 'B';
break;
case PINSHEETLABEL_SHAPE::TRISTATE:
type = 'T';
break;
default:
case NET_UNSPECIFIED: type = 'U'; break;
case PINSHEETLABEL_SHAPE::UNSPECIFIED:
type = 'U';
break;
}
m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n", pin.GetNumber(),
@ -2293,9 +2331,17 @@ void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText )
textType = "Label";
}
// Local labels must have their spin style inverted for left and right
int spinStyle = static_cast<int>( aText->GetLabelSpinStyle() );
if( spinStyle == 0 )
spinStyle = 2;
else if( spinStyle == 2 )
spinStyle = 0;
m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
aText->GetLabelSpinStyle(),
spinStyle,
Iu2Mils( aText->GetTextWidth() ),
italics, Iu2Mils( aText->GetThickness() ), TO_UTF8( text ) );
}
@ -2303,11 +2349,14 @@ void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText )
{
textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
auto shapeLabelIt = sheetLabelNames.find( aText->GetShape() );
wxCHECK_RET( shapeLabelIt != sheetLabelNames.end(), "Shape not found in names list" );
m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
aText->GetLabelSpinStyle(),
static_cast<int>( aText->GetLabelSpinStyle() ),
Iu2Mils( aText->GetTextWidth() ),
SheetLabelType[aText->GetShape()],
shapeLabelIt->second,
italics,
Iu2Mils( aText->GetThickness() ), TO_UTF8( text ) );
}

View File

@ -1234,22 +1234,16 @@ void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer )
switch( aText->GetLabelSpinStyle() )
{
case 0:
if( aText->Type() == SCH_LABEL_T || aText->Type() == SCH_TEXT_T )
text_offset.x -= getShadowWidth() / 2;
else
text_offset.x += getShadowWidth() / 2;
case LABEL_SPIN_STYLE::LEFT:
text_offset.x += getShadowWidth() / 2;
break;
case 1:
case LABEL_SPIN_STYLE::UP:
text_offset.y += getShadowWidth() / 2;
break;
case 2:
if( aText->Type() == SCH_LABEL_T || aText->Type() == SCH_TEXT_T )
text_offset.x += getShadowWidth() / 2;
else
text_offset.x -= getShadowWidth() / 2;
case LABEL_SPIN_STYLE::RIGHT:
text_offset.x -= getShadowWidth() / 2;
break;
case 3:
case LABEL_SPIN_STYLE::BOTTOM:
text_offset.y -= getShadowWidth() / 2;
break;
}

View File

@ -50,7 +50,7 @@ SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent, const wxPoint& pos, const wxStr
else
SetEdge( SHEET_LEFT_SIDE );
m_shape = NET_INPUT;
m_shape = PINSHEETLABEL_SHAPE::INPUT;
m_isDangling = true;
m_number = 2;
}
@ -117,25 +117,25 @@ void SCH_SHEET_PIN::SetEdge( SHEET_SIDE aEdge )
case SHEET_LEFT_SIDE:
m_edge = aEdge;
SetTextX( Sheet->m_pos.x );
SetLabelSpinStyle( 2 ); // Orientation horiz inverse
SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT ); // Orientation horiz inverse
break;
case SHEET_RIGHT_SIDE:
m_edge = aEdge;
SetTextX( Sheet->m_pos.x + Sheet->m_size.x );
SetLabelSpinStyle( 0 ); // Orientation horiz normal
SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT ); // Orientation horiz normal
break;
case SHEET_TOP_SIDE:
m_edge = aEdge;
SetTextY( Sheet->m_pos.y );
SetLabelSpinStyle( 3 ); // Orientation vert BOTTOM
SetLabelSpinStyle( LABEL_SPIN_STYLE::BOTTOM ); // Orientation vert BOTTOM
break;
case SHEET_BOTTOM_SIDE:
m_edge = aEdge;
SetTextY( Sheet->m_pos.y + Sheet->m_size.y );
SetLabelSpinStyle( 1 ); // Orientation vert UP
SetLabelSpinStyle( LABEL_SPIN_STYLE::UP ); // Orientation vert UP
break;
default:
@ -252,9 +252,14 @@ void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wx
switch( m_shape )
{
case NET_INPUT: m_shape = NET_OUTPUT; break;
case NET_OUTPUT: m_shape = NET_INPUT; break;
default: break;
case PINSHEETLABEL_SHAPE::INPUT:
m_shape = PINSHEETLABEL_SHAPE::OUTPUT;
break;
case PINSHEETLABEL_SHAPE::OUTPUT:
m_shape = PINSHEETLABEL_SHAPE::INPUT;
break;
default:
break;
}
SCH_HIERLABEL::CreateGraphicShape( aPoints, aPos );

View File

@ -56,17 +56,6 @@ extern void IncrementLabelMember( wxString& name, int aIncrement );
// Margin in internal units (mils) between labels and wires
#define TXT_MARGIN 4
// Names of sheet label types.
const char* SheetLabelType[] =
{
"Input",
"Output",
"BiDi",
"3State",
"UnSpc",
"???"
};
/* Coding polygons for global symbol graphic shapes.
* the first parml is the number of corners
* others are the corners coordinates in reduced units
@ -107,17 +96,15 @@ static int* TemplateShape[5][4] =
};
SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) :
SCH_ITEM( NULL, aType ),
EDA_TEXT( text ),
m_shape( NET_INPUT )
SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType )
: SCH_ITEM( NULL, aType ), EDA_TEXT( text ), m_shape( PINSHEETLABEL_SHAPE::INPUT )
{
m_Layer = LAYER_NOTES;
SetTextPos( pos );
m_isDangling = false;
m_Layer = LAYER_NOTES;
m_isDangling = false;
m_connectionType = CONNECTION_NONE;
m_spin_style = 0;
m_spin_style = LABEL_SPIN_STYLE::LEFT;
SetTextPos( pos );
SetMultilineAllowed( true );
}
@ -156,11 +143,15 @@ wxPoint SCH_TEXT::GetSchematicTextOffset() const
switch( GetLabelSpinStyle() )
{
case LABEL_SPIN_STYLE::UP:
case LABEL_SPIN_STYLE::BOTTOM:
text_offset.x = -thick_offset;
break; // Vert Orientation
default:
case 0: text_offset.y = -thick_offset; break; // Horiz Normal Orientation (left justified)
case 1: text_offset.x = -thick_offset; break; // Vert Orientation UP
case 2: text_offset.y = -thick_offset; break; // Horiz Orientation - Right justified
case 3: text_offset.x = -thick_offset; break; // Vert Orientation BOTTOM
case LABEL_SPIN_STYLE::LEFT:
case LABEL_SPIN_STYLE::RIGHT:
text_offset.y = -thick_offset;
break; // Horiz Orientation
}
return text_offset;
@ -170,14 +161,7 @@ wxPoint SCH_TEXT::GetSchematicTextOffset() const
void SCH_TEXT::MirrorY( int aYaxis_position )
{
// Text is NOT really mirrored; it is moved to a suitable horizontal position
switch( GetLabelSpinStyle() )
{
default:
case 0: SetLabelSpinStyle( 2 ); break; // horizontal text
case 1: break; // Vert Orientation UP
case 2: SetLabelSpinStyle( 0 ); break; // invert horizontal text
case 3: break; // Vert Orientation BOTTOM
}
SetLabelSpinStyle( GetLabelSpinStyle().MirrorY() );
SetTextX( Mirror( GetTextPos().x, aYaxis_position ) );
}
@ -186,14 +170,7 @@ void SCH_TEXT::MirrorY( int aYaxis_position )
void SCH_TEXT::MirrorX( int aXaxis_position )
{
// Text is NOT really mirrored; it is moved to a suitable vertical position
switch( GetLabelSpinStyle() )
{
default:
case 0: break; // horizontal text
case 1: SetLabelSpinStyle( 3 ); break; // Vert Orientation UP
case 2: break; // invert horizontal text
case 3: SetLabelSpinStyle( 1 ); break; // Vert Orientation BOTTOM
}
SetLabelSpinStyle( GetLabelSpinStyle().MirrorX() );
SetTextY( Mirror( GetTextPos().y, aXaxis_position ) );
}
@ -201,30 +178,28 @@ void SCH_TEXT::MirrorX( int aXaxis_position )
void SCH_TEXT::Rotate( wxPoint aPosition )
{
int dy;
int dy = 0;
wxPoint pt = GetTextPos();
RotatePoint( &pt, aPosition, 900 );
SetTextPos( pt );
int spin = GetLabelSpinStyle();
// Global and hierarchical labels spin backwards. Fix here because
// changing SetLabelSpinStyle would break existing designs.
if( this->Type() == SCH_GLOBAL_LABEL_T || this->Type() == SCH_HIER_LABEL_T )
SetLabelSpinStyle( ( spin - 1 >= 0 ? ( spin - 1 ) : 3 ) );
else
SetLabelSpinStyle( ( spin + 1 ) % 4 );
SetLabelSpinStyle( GetLabelSpinStyle().RotateCW() );
if( this->Type() == SCH_TEXT_T )
{
switch( GetLabelSpinStyle() )
{
case 0: dy = GetTextHeight(); break; // horizontal text
case 1: dy = 0; break; // Vert Orientation UP
case 2: dy = GetTextHeight(); break; // invert horizontal text
case 3: dy = 0; break; // Vert Orientation BOTTOM
default: dy = 0; break;
case LABEL_SPIN_STYLE::LEFT:
case LABEL_SPIN_STYLE::RIGHT:
dy = GetTextHeight();
break;
case LABEL_SPIN_STYLE::UP:
case LABEL_SPIN_STYLE::BOTTOM:
default:
dy = 0;
dy = 0;
break;
}
SetTextY( GetTextPos().y + dy );
@ -232,35 +207,37 @@ void SCH_TEXT::Rotate( wxPoint aPosition )
}
void SCH_TEXT::SetLabelSpinStyle( int aSpinStyle )
void SCH_TEXT::SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle )
{
m_spin_style = aSpinStyle;
// Assume "Right" and Left" mean which side of the anchor the text will be on
// Thus we want to left justify text up agaisnt the anchor if we are on the right
switch( aSpinStyle )
{
default:
wxASSERT_MSG( 1, "Bad spin style" );
case 0: // Horiz Normal Orientation
case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
//
m_spin_style = 0; // Handle the error spin style by resetting
m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
SetTextAngle( TEXT_ANGLE_HORIZ );
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
break;
case 1: // Vert Orientation UP
case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
SetTextAngle( TEXT_ANGLE_VERT );
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
break;
case 2: // Horiz Orientation - Right justified
case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation - Right justified
SetTextAngle( TEXT_ANGLE_HORIZ );
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
break;
case 3: // Vert Orientation BOTTOM
case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
SetTextAngle( TEXT_ANGLE_VERT );
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
@ -575,11 +552,21 @@ void SCH_TEXT::GetMsgPanelInfo( EDA_UNITS aUnits, MSG_PANEL_ITEMS& aList )
switch( GetLabelSpinStyle() )
{
case 0: msg = _( "Horizontal" ); break;
case 1: msg = _( "Vertical up" ); break;
case 2: msg = _( "Horizontal invert" ); break;
case 3: msg = _( "Vertical down" ); break;
default: msg = wxT( "???" ); break;
case LABEL_SPIN_STYLE::LEFT:
msg = _( "Horizontal left" );
break;
case LABEL_SPIN_STYLE::UP:
msg = _( "Vertical up" );
break;
case LABEL_SPIN_STYLE::RIGHT:
msg = _( "Horizontal right" );
break;
case LABEL_SPIN_STYLE::BOTTOM:
msg = _( "Vertical down" );
break;
default:
msg = wxT( "???" );
break;
}
aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, BROWN ) );
@ -600,12 +587,24 @@ void SCH_TEXT::GetMsgPanelInfo( EDA_UNITS aUnits, MSG_PANEL_ITEMS& aList )
{
switch( GetShape() )
{
case NET_INPUT: msg = _( "Input" ); break;
case NET_OUTPUT: msg = _( "Output" ); break;
case NET_BIDI: msg = _( "Bidirectional" ); break;
case NET_TRISTATE: msg = _( "Tri-State" ); break;
case NET_UNSPECIFIED: msg = _( "Passive" ); break;
default: msg = wxT( "???" ); break;
case PINSHEETLABEL_SHAPE::INPUT:
msg = _( "Input" );
break;
case PINSHEETLABEL_SHAPE::OUTPUT:
msg = _( "Output" );
break;
case PINSHEETLABEL_SHAPE::BIDI:
msg = _( "Bidirectional" );
break;
case PINSHEETLABEL_SHAPE::TRISTATE:
msg = _( "Tri-State" );
break;
case PINSHEETLABEL_SHAPE::UNSPECIFIED:
msg = _( "Passive" );
break;
default:
msg = wxT( "???" );
break;
}
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, BLUE ) );
@ -634,7 +633,7 @@ void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
<< " layer=\"" << m_Layer << '"'
<< " shape=\"" << m_shape << '"'
<< " shape=\"" << static_cast<int>( m_shape ) << '"'
<< " dangling=\"" << m_isDangling << '"'
<< '>'
<< TO_UTF8( GetText() )
@ -644,11 +643,11 @@ void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const
#endif
SCH_LABEL::SCH_LABEL( const wxPoint& pos, const wxString& text ) :
SCH_TEXT( pos, text, SCH_LABEL_T )
SCH_LABEL::SCH_LABEL( const wxPoint& pos, const wxString& text )
: SCH_TEXT( pos, text, SCH_LABEL_T )
{
m_Layer = LAYER_LOCLABEL;
m_shape = NET_INPUT;
m_Layer = LAYER_LOCLABEL;
m_shape = PINSHEETLABEL_SHAPE::INPUT;
m_isDangling = true;
SetMultilineAllowed( false );
}
@ -728,11 +727,11 @@ BITMAP_DEF SCH_LABEL::GetMenuImage() const
}
SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text ) :
SCH_TEXT( pos, text, SCH_GLOBAL_LABEL_T )
SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text )
: SCH_TEXT( pos, text, SCH_GLOBAL_LABEL_T )
{
m_Layer = LAYER_GLOBLABEL;
m_shape = NET_BIDI;
m_Layer = LAYER_GLOBLABEL;
m_shape = PINSHEETLABEL_SHAPE::BIDI;
m_isDangling = true;
SetMultilineAllowed( false );
}
@ -755,14 +754,14 @@ wxPoint SCH_GLOBALLABEL::GetSchematicTextOffset() const
switch( m_shape )
{
case NET_INPUT:
case NET_BIDI:
case NET_TRISTATE:
case PINSHEETLABEL_SHAPE::INPUT:
case PINSHEETLABEL_SHAPE::BIDI:
case PINSHEETLABEL_SHAPE::TRISTATE:
offset += halfSize;
break;
case NET_OUTPUT:
case NET_UNSPECIFIED:
case PINSHEETLABEL_SHAPE::OUTPUT:
case PINSHEETLABEL_SHAPE::UNSPECIFIED:
offset += TXT_MARGIN;
break;
@ -773,17 +772,25 @@ wxPoint SCH_GLOBALLABEL::GetSchematicTextOffset() const
switch( GetLabelSpinStyle() )
{
default:
case 0: text_offset.x -= offset; break; // Orientation horiz normal
case 1: text_offset.y -= offset; break; // Orientation vert UP
case 2: text_offset.x += offset; break; // Orientation horiz inverse
case 3: text_offset.y += offset; break; // Orientation vert BOTTOM
case LABEL_SPIN_STYLE::LEFT:
text_offset.x -= offset;
break; // Orientation horiz normal
case LABEL_SPIN_STYLE::UP:
text_offset.y -= offset;
break; // Orientation vert UP
case LABEL_SPIN_STYLE::RIGHT:
text_offset.x += offset;
break; // Orientation horiz inverse
case LABEL_SPIN_STYLE::BOTTOM:
text_offset.y += offset;
break; // Orientation vert BOTTOM
}
return text_offset;
}
void SCH_GLOBALLABEL::SetLabelSpinStyle( int aSpinStyle )
void SCH_GLOBALLABEL::SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle )
{
m_spin_style = aSpinStyle;
@ -791,27 +798,27 @@ void SCH_GLOBALLABEL::SetLabelSpinStyle( int aSpinStyle )
{
default:
wxASSERT_MSG( 1, "Bad spin style" );
case 0: // Horiz Normal Orientation
case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
//
m_spin_style = 0; // Handle the error spin style by resetting
m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
SetTextAngle( TEXT_ANGLE_HORIZ );
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
case 1: // Vert Orientation UP
case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
SetTextAngle( TEXT_ANGLE_VERT );
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
case 2: // Horiz Orientation
case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation
SetTextAngle( TEXT_ANGLE_HORIZ );
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
case 3: // Vert Orientation BOTTOM
case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
SetTextAngle( TEXT_ANGLE_VERT );
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
@ -888,23 +895,23 @@ void SCH_GLOBALLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const
switch( m_shape )
{
case NET_INPUT:
case PINSHEETLABEL_SHAPE::INPUT:
x_offset = -halfSize;
aPoints[0].x += halfSize;
break;
case NET_OUTPUT:
case PINSHEETLABEL_SHAPE::OUTPUT:
aPoints[3].x -= halfSize;
break;
case NET_BIDI:
case NET_TRISTATE:
case PINSHEETLABEL_SHAPE::BIDI:
case PINSHEETLABEL_SHAPE::TRISTATE:
x_offset = -halfSize;
aPoints[0].x += halfSize;
aPoints[3].x -= halfSize;
break;
case NET_UNSPECIFIED:
case PINSHEETLABEL_SHAPE::UNSPECIFIED:
default:
break;
}
@ -914,10 +921,17 @@ void SCH_GLOBALLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const
switch( GetLabelSpinStyle() )
{
default:
case 0: break; // Orientation horiz normal
case 1: angle = -900; break; // Orientation vert UP
case 2: angle = 1800; break; // Orientation horiz inverse
case 3: angle = 900; break; // Orientation vert BOTTOM
case LABEL_SPIN_STYLE::LEFT:
break; // Orientation horiz normal
case LABEL_SPIN_STYLE::UP:
angle = -900;
break; // Orientation vert UP
case LABEL_SPIN_STYLE::RIGHT:
angle = 1800;
break; // Orientation horiz inverse
case LABEL_SPIN_STYLE::BOTTOM:
angle = 900;
break; // Orientation vert BOTTOM
}
// Rotate outlines and move corners in real position
@ -954,28 +968,28 @@ const EDA_RECT SCH_GLOBALLABEL::GetBoundingBox() const
switch( GetLabelSpinStyle() ) // respect orientation
{
default:
case 0: // Horiz Normal Orientation (left justified)
case LABEL_SPIN_STYLE::LEFT:
dx = -length;
dy = height;
x += Mils2iu( DANGLING_SYMBOL_SIZE );
y -= height / 2;
break;
case 1: // Vert Orientation UP
case LABEL_SPIN_STYLE::UP:
dx = height;
dy = -length;
x -= height / 2;
y += Mils2iu( DANGLING_SYMBOL_SIZE );
break;
case 2: // Horiz Orientation - Right justified
case LABEL_SPIN_STYLE::RIGHT:
dx = length;
dy = height;
x -= Mils2iu( DANGLING_SYMBOL_SIZE );
y -= height / 2;
break;
case 3: // Vert Orientation BOTTOM
case LABEL_SPIN_STYLE::BOTTOM:
dx = height;
dy = length;
x -= height / 2;
@ -1001,12 +1015,11 @@ BITMAP_DEF SCH_GLOBALLABEL::GetMenuImage() const
}
SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text, KICAD_T aType ) :
SCH_TEXT( pos, text, aType )
SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text, KICAD_T aType )
: SCH_TEXT( pos, text, aType )
{
m_Layer = LAYER_HIERLABEL;
m_shape = NET_INPUT;
m_Layer = LAYER_HIERLABEL;
m_shape = PINSHEETLABEL_SHAPE::INPUT;
m_isDangling = true;
SetMultilineAllowed( false );
}
@ -1018,35 +1031,37 @@ EDA_ITEM* SCH_HIERLABEL::Clone() const
}
void SCH_HIERLABEL::SetLabelSpinStyle( int aSpinStyle )
void SCH_HIERLABEL::SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle )
{
m_spin_style = aSpinStyle;
// Assume "Right" and Left" mean which side of the port symbol the text will be on
// If we are left of the symbol, we want to right justify to line up with the symbol
switch( aSpinStyle )
{
default:
wxASSERT_MSG( 1, "Bad spin style" );
case 0: // Horiz Normal Orientation
wxLogWarning( "SetLabelSpinStyle bad spin style" );
case LABEL_SPIN_STYLE::LEFT:
//
m_spin_style = 0; // Handle the error spin style by resetting
m_spin_style = LABEL_SPIN_STYLE::LEFT; // Handle the error spin style by resetting
SetTextAngle( TEXT_ANGLE_HORIZ );
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
case 1: // Vert Orientation UP
case LABEL_SPIN_STYLE::UP:
SetTextAngle( TEXT_ANGLE_VERT );
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
case 2: // Horiz Orientation
case LABEL_SPIN_STYLE::RIGHT:
SetTextAngle( TEXT_ANGLE_HORIZ );
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
case 3: // Vert Orientation BOTTOM
case LABEL_SPIN_STYLE::BOTTOM:
SetTextAngle( TEXT_ANGLE_VERT );
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
@ -1080,7 +1095,7 @@ void SCH_HIERLABEL::Print( wxDC* DC, const wxPoint& offset )
void SCH_HIERLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos )
{
int* Template = TemplateShape[m_shape][m_spin_style];
int* Template = TemplateShape[static_cast<int>( m_shape )][static_cast<int>( m_spin_style )];
int halfSize = GetTextWidth() / 2;
int imax = *Template; Template++;
@ -1118,28 +1133,28 @@ const EDA_RECT SCH_HIERLABEL::GetBoundingBox() const
switch( GetLabelSpinStyle() )
{
default:
case 0: // Horiz Normal Orientation (left justified)
case LABEL_SPIN_STYLE::LEFT:
dx = -length;
dy = height;
x += Mils2iu( DANGLING_SYMBOL_SIZE );
y -= height / 2;
break;
case 1: // Vert Orientation UP
case LABEL_SPIN_STYLE::UP:
dx = height;
dy = -length;
x -= height / 2;
y += Mils2iu( DANGLING_SYMBOL_SIZE );
break;
case 2: // Horiz Orientation - Right justified
case LABEL_SPIN_STYLE::RIGHT:
dx = length;
dy = height;
x -= Mils2iu( DANGLING_SYMBOL_SIZE );
y -= height / 2;
break;
case 3: // Vert Orientation BOTTOM
case LABEL_SPIN_STYLE::BOTTOM:
dx = height;
dy = length;
x -= height / 2;
@ -1162,10 +1177,18 @@ wxPoint SCH_HIERLABEL::GetSchematicTextOffset() const
switch( GetLabelSpinStyle() )
{
default:
case 0: text_offset.x = -ii; break; // Orientation horiz normale
case 1: text_offset.y = -ii; break; // Orientation vert UP
case 2: text_offset.x = ii; break; // Orientation horiz inverse
case 3: text_offset.y = ii; break; // Orientation vert BOTTOM
case LABEL_SPIN_STYLE::LEFT:
text_offset.x = -ii;
break; // Orientation horiz normale
case LABEL_SPIN_STYLE::UP:
text_offset.y = -ii;
break; // Orientation vert UP
case LABEL_SPIN_STYLE::RIGHT:
text_offset.x = ii;
break; // Orientation horiz inverse
case LABEL_SPIN_STYLE::BOTTOM:
text_offset.y = ii;
break; // Orientation vert BOTTOM
}
return text_offset;

View File

@ -40,16 +40,167 @@
class LINE_READER;
class NETLIST_OBJECT_LIST;
/*
* Spin style for text items of all kinds on schematics
* Basically a higher level abstraction of rotation and justification of text
*/
class LABEL_SPIN_STYLE
{
public:
enum SPIN : int
{
LEFT = 0,
UP = 1,
RIGHT = 2,
BOTTOM = 3
};
LABEL_SPIN_STYLE() = default;
constexpr LABEL_SPIN_STYLE( SPIN aSpin ) : m_spin( aSpin )
{
}
LABEL_SPIN_STYLE( int aSpin )
{
m_spin = static_cast<SPIN>( aSpin );
}
constexpr bool operator==( SPIN a ) const
{
return m_spin == a;
}
constexpr bool operator!=( SPIN a ) const
{
return m_spin != a;
}
operator int() const
{
return static_cast<int>( m_spin );
}
LABEL_SPIN_STYLE RotateCW()
{
SPIN newSpin = m_spin;
switch( m_spin )
{
default:
wxLogWarning( "RotateCCW encountered unknown current spin style" );
case LABEL_SPIN_STYLE::LEFT:
newSpin = LABEL_SPIN_STYLE::UP;
break;
case LABEL_SPIN_STYLE::UP:
newSpin = LABEL_SPIN_STYLE::RIGHT;
break;
case LABEL_SPIN_STYLE::RIGHT:
newSpin = LABEL_SPIN_STYLE::BOTTOM;
break;
case LABEL_SPIN_STYLE::BOTTOM:
newSpin = LABEL_SPIN_STYLE::LEFT;
break;
}
return LABEL_SPIN_STYLE( newSpin );
}
LABEL_SPIN_STYLE RotateCCW()
{
SPIN newSpin = m_spin;
switch( m_spin )
{
default:
wxLogWarning( "RotateCCW encountered unknown current spin style" );
case LABEL_SPIN_STYLE::LEFT:
newSpin = LABEL_SPIN_STYLE::BOTTOM;
break;
case LABEL_SPIN_STYLE::BOTTOM:
newSpin = LABEL_SPIN_STYLE::RIGHT;
break;
case LABEL_SPIN_STYLE::RIGHT:
newSpin = LABEL_SPIN_STYLE::UP;
break;
case LABEL_SPIN_STYLE::UP:
newSpin = LABEL_SPIN_STYLE::LEFT;
break;
}
return LABEL_SPIN_STYLE( newSpin );
}
/*
* Mirrors the label spin style across the X axis or simply swaps up and bottom
*/
LABEL_SPIN_STYLE MirrorX()
{
SPIN newSpin = m_spin;
switch( m_spin )
{
default:
wxLogWarning( "MirrorX encountered unknown current spin style" );
case LABEL_SPIN_STYLE::UP:
newSpin = LABEL_SPIN_STYLE::BOTTOM;
break;
case LABEL_SPIN_STYLE::BOTTOM:
newSpin = LABEL_SPIN_STYLE::UP;
break;
case LABEL_SPIN_STYLE::LEFT:
break;
case LABEL_SPIN_STYLE::RIGHT:
break;
}
return LABEL_SPIN_STYLE( newSpin );
}
/*
* Mirrors the label spin style across the Y axis or simply swaps left and right
*/
LABEL_SPIN_STYLE MirrorY()
{
SPIN newSpin = m_spin;
switch( m_spin )
{
default:
wxLogWarning( "MirrorY encountered unknown current spin style" );
case LABEL_SPIN_STYLE::LEFT:
newSpin = LABEL_SPIN_STYLE::RIGHT;
break;
case LABEL_SPIN_STYLE::RIGHT:
newSpin = LABEL_SPIN_STYLE::LEFT;
break;
case LABEL_SPIN_STYLE::UP:
break;
case LABEL_SPIN_STYLE::BOTTOM:
break;
}
return LABEL_SPIN_STYLE( newSpin );
}
private:
SPIN m_spin;
};
/* Shape/Type of SCH_HIERLABEL and SCH_GLOBALLABEL
* mainly used to handle the graphic associated shape
*/
enum PINSHEETLABEL_SHAPE {
NET_INPUT,
NET_OUTPUT,
NET_BIDI,
NET_TRISTATE,
NET_UNSPECIFIED
enum class PINSHEETLABEL_SHAPE
{
INPUT,
OUTPUT,
BIDI,
TRISTATE,
UNSPECIFIED
};
@ -76,7 +227,7 @@ protected:
* This is a duplicattion of m_Orient, m_HJustified, and m_VJustified in #EDA_TEXT but is
* easier to handle than 3 parameters when editing and reading and saving files.
*/
int m_spin_style;
LABEL_SPIN_STYLE m_spin_style;
public:
SCH_TEXT( const wxPoint& pos = wxPoint( 0, 0 ),
@ -114,14 +265,13 @@ public:
* Set a spin or rotation angle, along with specific horizontal and vertical justification
* styles with each angle.
*
* @param aSpinStyle =
* 0 = normal (horizontal, left justified).
* 1 = up (vertical)
* 2 = (horizontal, right justified). This can be seen as the mirrored position of 0
* 3 = bottom . This can be seen as the mirrored position of up
* @param aSpinStyle Spin style as per LABEL_SPIN_STYLE storage class, may be the enum values or int value
*/
virtual void SetLabelSpinStyle( int aSpinStyle );
int GetLabelSpinStyle() const { return m_spin_style; }
virtual void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle );
LABEL_SPIN_STYLE GetLabelSpinStyle() const
{
return m_spin_style;
}
PINSHEETLABEL_SHAPE GetShape() const { return m_shape; }
@ -278,7 +428,7 @@ public:
return wxT( "SCH_GLOBALLABEL" );
}
void SetLabelSpinStyle( int aSpinStyle ) override;
void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle ) override;
wxPoint GetSchematicTextOffset() const override;
@ -328,7 +478,7 @@ public:
return wxT( "SCH_HIERLABEL" );
}
void SetLabelSpinStyle( int aSpinStyle ) override;
void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle ) override;
wxPoint GetSchematicTextOffset() const override;

View File

@ -766,7 +766,7 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy,
}
PINSHEETLABEL_SHAPE SCH_EDIT_FRAME::m_lastSheetPinType = NET_INPUT;
PINSHEETLABEL_SHAPE SCH_EDIT_FRAME::m_lastSheetPinType = PINSHEETLABEL_SHAPE::INPUT;
wxSize SCH_EDIT_FRAME::m_lastSheetPinTextSize( -1, -1 );
wxPoint SCH_EDIT_FRAME::m_lastSheetPinPosition;

View File

@ -383,87 +383,101 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
if( !moving )
saveCopyInUndoList( item, UR_CHANGED );
for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
switch( item->Type() )
{
switch( item->Type() )
case SCH_COMPONENT_T:
{
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
if( clockwise )
component->SetOrientation( CMP_ROTATE_CLOCKWISE );
else
component->SetOrientation( CMP_ROTATE_COUNTERCLOCKWISE );
if( m_frame->GetAutoplaceFields() )
component->AutoAutoplaceFields( m_frame->GetScreen() );
break;
}
case SCH_TEXT_T:
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIER_LABEL_T:
{
SCH_TEXT* textItem = static_cast<SCH_TEXT*>( item );
if( clockwise )
textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().RotateCW() );
else
textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().RotateCCW() );
break;
}
case SCH_SHEET_PIN_T:
{
// Rotate pin within parent sheet
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
SCH_SHEET* sheet = pin->GetParent();
for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
{
case SCH_COMPONENT_T:
{
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
if( clockwise )
component->SetOrientation( CMP_ROTATE_CLOCKWISE );
else
component->SetOrientation( CMP_ROTATE_COUNTERCLOCKWISE );
if( m_frame->GetAutoplaceFields() )
component->AutoAutoplaceFields( m_frame->GetScreen() );
break;
}
case SCH_TEXT_T:
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIER_LABEL_T:
{
SCH_TEXT* textItem = static_cast<SCH_TEXT*>( item );
textItem->SetLabelSpinStyle( ( textItem->GetLabelSpinStyle() + 1 ) & 3 );
break;
}
case SCH_SHEET_PIN_T:
{
// Rotate pin within parent sheet
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
SCH_SHEET* sheet = pin->GetParent();
pin->Rotate( sheet->GetBoundingBox().GetCenter() );
break;
}
break;
}
case SCH_BUS_BUS_ENTRY_T:
case SCH_BUS_WIRE_ENTRY_T:
for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
{
item->Rotate( item->GetPosition() );
}
break;
case SCH_FIELD_T:
{
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
if( field->GetTextAngle() == TEXT_ANGLE_HORIZ )
field->SetTextAngle( TEXT_ANGLE_VERT );
else
field->SetTextAngle( TEXT_ANGLE_HORIZ );
// Now that we're moving a field, they're no longer autoplaced.
if( item->GetParent()->Type() == SCH_COMPONENT_T )
{
SCH_COMPONENT* parent = static_cast<SCH_COMPONENT*>( item->GetParent() );
parent->ClearFieldsAutoplaced();
}
case SCH_BUS_BUS_ENTRY_T:
case SCH_BUS_WIRE_ENTRY_T:
item->Rotate( item->GetPosition() );
break;
break;
}
case SCH_FIELD_T:
case SCH_BITMAP_T:
for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
{
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
if( field->GetTextAngle() == TEXT_ANGLE_HORIZ )
field->SetTextAngle( TEXT_ANGLE_VERT );
else
field->SetTextAngle( TEXT_ANGLE_HORIZ );
// Now that we're moving a field, they're no longer autoplaced.
if( item->GetParent()->Type() == SCH_COMPONENT_T )
{
SCH_COMPONENT *parent = static_cast<SCH_COMPONENT*>( item->GetParent() );
parent->ClearFieldsAutoplaced();
}
break;
item->Rotate( item->GetPosition() );
}
// The bitmap is cached in Opengl: clear the cache to redraw
getView()->RecacheAllItems();
break;
case SCH_BITMAP_T:
item->Rotate( item->GetPosition() );
// The bitmap is cached in Opengl: clear the cache to redraw
getView()->RecacheAllItems();
break;
case SCH_SHEET_T:
{
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
case SCH_SHEET_T:
// Rotate the sheet on itself. Sheets do not have an anchor point.
for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
{
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
// Rotate the sheet on itself. Sheets do not have an anchor point.
rotPoint = m_frame->GetNearestGridPosition( sheet->GetRotationCenter() );
sheet->Rotate( rotPoint );
break;
}
break;
}
default:
break;
}
default:
break;
}
connections = item->IsConnectable();
@ -580,12 +594,11 @@ int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
case SCH_HIER_LABEL_T:
{
SCH_TEXT* textItem = static_cast<SCH_TEXT*>( item );
int spin = textItem->GetLabelSpinStyle();
if( xAxis && spin % 2 )
textItem->SetLabelSpinStyle( ( spin + 2 ) % 4 );
else if ( !xAxis && !( spin % 2 ) )
textItem->SetLabelSpinStyle( ( spin + 2 ) % 4 );
if( xAxis )
textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().MirrorX() );
else
textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().MirrorY() );
break;
}

View File

@ -365,7 +365,7 @@ SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus( const wxString& aNet )
m_busUnfold.label = new SCH_LABEL( m_busUnfold.entry->m_End(), aNet );
m_busUnfold.label->SetTextSize( wxSize( GetDefaultTextSize(), GetDefaultTextSize() ) );
m_busUnfold.label->SetLabelSpinStyle( 0 );
m_busUnfold.label->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
m_busUnfold.label->SetParent( m_frame->GetScreen() );
m_busUnfold.label->SetFlags( IS_NEW | IS_MOVED );

View File

@ -238,9 +238,6 @@ public:
void Empty() { m_text.Empty(); }
static int MapOrientation( KICAD_T labelType, int aOrientation );
static int MapOrientation( KICAD_T fromLabelType, KICAD_T toLabelType, int aOrientation );
static EDA_TEXT_HJUSTIFY_T MapHorizJustify( int aHorizJustify );
static EDA_TEXT_VJUSTIFY_T MapVertJustify( int aVertJustify );