From 293795fd46b19e0525cfd86f20c0da473e618923 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 18 Nov 2020 21:40:04 +0000 Subject: [PATCH] Support rotation on intersheet references. --- eeschema/sch_text.cpp | 68 ++++++++++++++++++++++++++------ eeschema/sch_text.h | 4 ++ eeschema/tools/sch_edit_tool.cpp | 19 +++------ 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 4d23eba409..3905bf1754 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -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; } diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index 5a618fad32..cc21786a5d 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -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& aFunction ) override; + void Rotate90( bool aClockwise ) override; + void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle ) override; wxPoint GetSchematicTextOffset( RENDER_SETTINGS* aSettings ) const override; diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 401c2d7e52..40a33a975e 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -454,16 +454,10 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) { SCH_TEXT* textItem = static_cast( 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( 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( 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;