diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 475887f0ac..60bf9ef1bd 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -42,6 +42,7 @@ #include #include #include +#include /* Forward declarations of classes. */ class APP_SETTINGS_BASE; @@ -77,6 +78,8 @@ protected: PCB_DISPLAY_OPTIONS m_DisplayOptions; + PCB_ORIGIN_TRANSFORMS m_OriginTransforms; + PCBNEW_SETTINGS* m_Settings; // No ownership, just a shortcut virtual void unitsChangeRefresh() override; @@ -144,6 +147,15 @@ public: const wxPoint& GetGridOrigin() const override; void SetGridOrigin( const wxPoint& aPoint ) override; + const wxPoint& GetAuxOrigin() const; + + const wxPoint GetUserOrigin() const; + + /** + * Return a reference to the default ORIGIN_TRANSFORMS object + */ + ORIGIN_TRANSFORMS& GetOriginTransforms() override; + const TITLE_BLOCK& GetTitleBlock() const override; void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override; diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 723d16cb9a..03070e1f66 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -59,7 +59,8 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize, long aStyle, const wxString & aFrameName ) : EDA_DRAW_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ), - m_Pcb( nullptr ) + m_Pcb( nullptr ), + m_OriginTransforms( *this ) { m_Settings = static_cast( Kiface().KifaceSettings() ); } @@ -269,6 +270,43 @@ void PCB_BASE_FRAME::SetGridOrigin( const wxPoint& aPoint ) } +const wxPoint& PCB_BASE_FRAME::GetAuxOrigin() const +{ + wxASSERT( m_Pcb ); + return m_Pcb->GetDesignSettings().m_AuxOrigin; +} + + +const wxPoint PCB_BASE_FRAME::GetUserOrigin() const +{ + auto& displ_opts = GetDisplayOptions(); + wxPoint origin( 0, 0 ); + + switch( displ_opts.m_DisplayOrigin ) + { + case PCB_DISPLAY_OPTIONS::PCB_ORIGIN_PAGE: + // No-op + break; + case PCB_DISPLAY_OPTIONS::PCB_ORIGIN_AUX: + origin = GetAuxOrigin(); + break; + case PCB_DISPLAY_OPTIONS::PCB_ORIGIN_GRID: + origin = GetGridOrigin(); + break; + default: + wxASSERT( false ); + break; + } + + return origin; +} + +ORIGIN_TRANSFORMS& PCB_BASE_FRAME::GetOriginTransforms() +{ + return m_OriginTransforms; +} + + const TITLE_BLOCK& PCB_BASE_FRAME::GetTitleBlock() const { wxASSERT( m_Pcb ); @@ -526,9 +564,13 @@ void PCB_BASE_FRAME::UpdateStatusBar() SetStatusText( line, 3 ); } + // Transform absolute coordinates for user origin preferences + double userXpos = m_OriginTransforms.ToDisplayAbsX( static_cast( cursorPos.x ) ); + double userYpos = m_OriginTransforms.ToDisplayAbsY( static_cast( cursorPos.y ) ); + // Display absolute coordinates: - double dXpos = To_User_Unit( GetUserUnits(), cursorPos.x ); - double dYpos = To_User_Unit( GetUserUnits(), cursorPos.y ); + double dXpos = To_User_Unit( GetUserUnits(), userXpos ); + double dYpos = To_User_Unit( GetUserUnits(), userYpos ); // The following sadly is an if Eeschema/if Pcbnew wxString absformatter; @@ -561,9 +603,17 @@ void PCB_BASE_FRAME::UpdateStatusBar() if( !GetShowPolarCoords() ) // display relative cartesian coordinates { + // Calculate relative coordinates + double relXpos = cursorPos.x - screen->m_LocalOrigin.x; + double relYpos = cursorPos.y - screen->m_LocalOrigin.y; + + // Transform relative coordinates for user origin preferences + userXpos = m_OriginTransforms.ToDisplayRelX( relXpos ); + userYpos = m_OriginTransforms.ToDisplayRelY( relYpos ); + // Display relative coordinates: - dXpos = To_User_Unit( GetUserUnits(), cursorPos.x - screen->m_LocalOrigin.x ); - dYpos = To_User_Unit( GetUserUnits(), cursorPos.y - screen->m_LocalOrigin.y ); + dXpos = To_User_Unit( GetUserUnits(), userXpos ); + dYpos = To_User_Unit( GetUserUnits(), userYpos ); // We already decided the formatter above line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );