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

View File

@ -280,6 +280,8 @@ public:
void MirrorX( int aXaxis_position ) override; void MirrorX( int aXaxis_position ) override;
void Rotate( wxPoint aPosition ) override; void Rotate( wxPoint aPosition ) override;
virtual void Rotate90( bool aClockwise );
bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override
{ {
return SCH_ITEM::Matches( GetText(), aSearchData ); return SCH_ITEM::Matches( GetText(), aSearchData );
@ -399,6 +401,8 @@ public:
void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override; void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
void Rotate90( bool aClockwise ) override;
void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle ) override; void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle ) override;
wxPoint GetSchematicTextOffset( RENDER_SETTINGS* aSettings ) const 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 ); SCH_TEXT* textItem = static_cast<SCH_TEXT*>( item );
if( clockwise ) textItem->Rotate90( clockwise );
textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().RotateCW() );
else
textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().RotateCCW() );
if( item->Type() == SCH_GLOBAL_LABEL_T ) if( textItem->GetFieldsAutoplaced() == FIELDS_AUTOPLACED_AUTO )
{ textItem->AutoplaceFields( m_frame->GetScreen(), false );
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( item );
label->UpdateIntersheetRefProps();
}
break; break;
} }
@ -473,6 +467,7 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
// Rotate pin within parent sheet // Rotate pin within parent sheet
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item ); SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
SCH_SHEET* sheet = pin->GetParent(); SCH_SHEET* sheet = pin->GetParent();
for( int i = 0; clockwise ? i < 1 : i < 3; ++i ) for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
{ {
pin->Rotate( sheet->GetBoundingBox().GetCenter() ); 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_BUS_ENTRY_T:
case SCH_BUS_WIRE_ENTRY_T: case SCH_BUS_WIRE_ENTRY_T:
for( int i = 0; clockwise ? i < 1 : i < 3; ++i ) for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
{
item->Rotate( item->GetPosition() ); item->Rotate( item->GetPosition() );
}
break; break;
case SCH_FIELD_T: case SCH_FIELD_T:
@ -505,9 +499,8 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
case SCH_BITMAP_T: case SCH_BITMAP_T:
for( int i = 0; clockwise ? i < 1 : i < 3; ++i ) for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
{
item->Rotate( item->GetPosition() ); item->Rotate( item->GetPosition() );
}
// The bitmap is cached in Opengl: clear the cache to redraw // The bitmap is cached in Opengl: clear the cache to redraw
getView()->RecacheAllItems(); getView()->RecacheAllItems();
break; break;