Support rotation on intersheet references.

This commit is contained in:
Jeff Young 2020-11-18 21:40:04 +00:00
parent 0e44f5128c
commit 293795fd46
3 changed files with 67 additions and 24 deletions

View File

@ -229,6 +229,15 @@ void SCH_TEXT::Rotate( wxPoint aPosition )
}
void SCH_TEXT::Rotate90( bool aClockwise )
{
if( aClockwise )
SetLabelSpinStyle( GetLabelSpinStyle().RotateCW() );
else
SetLabelSpinStyle( GetLabelSpinStyle().RotateCCW() );
}
void SCH_TEXT::SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle )
{
m_spin_style = aSpinStyle;
@ -817,8 +826,11 @@ SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text ) :
m_isDangling = true;
SetMultilineAllowed( false );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
m_intersheetRefsField.SetText( wxT( "${INTERSHEET_REFS}" ) );
m_intersheetRefsField.SetLayer( LAYER_GLOBLABEL );
m_intersheetRefsField.SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
m_fieldsAutoplaced = FIELDS_AUTOPLACED_AUTO;
}
@ -928,37 +940,75 @@ void SCH_GLOBALLABEL::SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle )
{
default:
wxASSERT_MSG( 1, "Bad spin style" );
break;
m_spin_style = LABEL_SPIN_STYLE::RIGHT;
KI_FALLTHROUGH;
case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
//
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_CENTER );
break;
case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
SetTextAngle( TEXT_ANGLE_VERT );
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation
SetTextAngle( TEXT_ANGLE_HORIZ );
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
SetTextAngle( TEXT_ANGLE_VERT );
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
}
}
void SCH_GLOBALLABEL::Rotate90( bool aClockwise )
{
SCH_TEXT::Rotate90( aClockwise );
if( m_intersheetRefsField.GetTextAngle() == TEXT_ANGLE_VERT
&& m_intersheetRefsField.GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
{
if( !aClockwise )
m_intersheetRefsField.SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
m_intersheetRefsField.SetTextAngle( TEXT_ANGLE_HORIZ );
}
else if( m_intersheetRefsField.GetTextAngle() == TEXT_ANGLE_VERT
&& m_intersheetRefsField.GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
{
if( !aClockwise )
m_intersheetRefsField.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
m_intersheetRefsField.SetTextAngle( TEXT_ANGLE_HORIZ );
}
else if( m_intersheetRefsField.GetTextAngle() == TEXT_ANGLE_HORIZ
&& m_intersheetRefsField.GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
{
if( aClockwise )
m_intersheetRefsField.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
m_intersheetRefsField.SetTextAngle( TEXT_ANGLE_VERT );
}
else if( m_intersheetRefsField.GetTextAngle() == TEXT_ANGLE_HORIZ
&& m_intersheetRefsField.GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
{
if( aClockwise )
m_intersheetRefsField.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
m_intersheetRefsField.SetTextAngle( TEXT_ANGLE_VERT );
}
wxPoint pos = m_intersheetRefsField.GetTextPos();
RotatePoint( &pos, GetPosition(), aClockwise ? -900 : 900 );
m_intersheetRefsField.SetTextPos( pos );
}
void SCH_GLOBALLABEL::UpdateIntersheetRefProps()
{
m_intersheetRefsField.SetTextSize( GetTextSize() );
@ -986,28 +1036,24 @@ void SCH_GLOBALLABEL::AutoplaceFields( SCH_SCREEN* aScreen, bool aManual )
case LABEL_SPIN_STYLE::LEFT:
m_intersheetRefsField.SetTextAngle( TEXT_ANGLE_HORIZ );
m_intersheetRefsField.SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
m_intersheetRefsField.SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
offset.x = - ( labelLen + margin / 2 );
break;
case LABEL_SPIN_STYLE::UP:
m_intersheetRefsField.SetTextAngle( TEXT_ANGLE_VERT );
m_intersheetRefsField.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
m_intersheetRefsField.SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
offset.y = - ( labelLen + margin / 2 );
break;
case LABEL_SPIN_STYLE::RIGHT:
m_intersheetRefsField.SetTextAngle( TEXT_ANGLE_HORIZ );
m_intersheetRefsField.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
m_intersheetRefsField.SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
offset.x = labelLen + margin /2 ;
break;
case LABEL_SPIN_STYLE::BOTTOM:
m_intersheetRefsField.SetTextAngle( TEXT_ANGLE_VERT );
m_intersheetRefsField.SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
m_intersheetRefsField.SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
offset.y = labelLen + margin / 2;
break;
}

View File

@ -280,6 +280,8 @@ public:
void MirrorX( int aXaxis_position ) override;
void Rotate( wxPoint aPosition ) override;
virtual void Rotate90( bool aClockwise );
bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override
{
return SCH_ITEM::Matches( GetText(), aSearchData );
@ -399,6 +401,8 @@ public:
void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
void Rotate90( bool aClockwise ) override;
void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle ) override;
wxPoint GetSchematicTextOffset( RENDER_SETTINGS* aSettings ) const override;

View File

@ -454,16 +454,10 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
{
SCH_TEXT* textItem = static_cast<SCH_TEXT*>( item );
if( clockwise )
textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().RotateCW() );
else
textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().RotateCCW() );
textItem->Rotate90( clockwise );
if( item->Type() == SCH_GLOBAL_LABEL_T )
{
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( item );
label->UpdateIntersheetRefProps();
}
if( textItem->GetFieldsAutoplaced() == FIELDS_AUTOPLACED_AUTO )
textItem->AutoplaceFields( m_frame->GetScreen(), false );
break;
}
@ -473,6 +467,7 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
// 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 )
{
pin->Rotate( sheet->GetBoundingBox().GetCenter() );
@ -483,9 +478,8 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
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:
@ -505,9 +499,8 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
case SCH_BITMAP_T:
for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
{
item->Rotate( item->GetPosition() );
}
// The bitmap is cached in Opengl: clear the cache to redraw
getView()->RecacheAllItems();
break;