Add Display Origin Transforms support to the PCB_BASE_FRAME class

This commit adds support for display origin transforms to the PCB_BASE_FRAME
class. This instantiates a PCB_ORIGIN_TRANSFORMS object, and overrides the
GetOriginTransforms method in the EDA_DRAW_FRAME class to reference it.

The formatting of the status line has been updated to display coordinates
relative to the user-selected origin, and with the coordinates increasing
in the user-selected direction.
This commit is contained in:
Reece R. Pollack 2020-07-04 21:59:29 -04:00 committed by Seth Hillbrand
parent af218a5dc0
commit 6f1204cfd7
2 changed files with 67 additions and 5 deletions

View File

@ -42,6 +42,7 @@
#include <pcb_display_options.h> #include <pcb_display_options.h>
#include <pcb_draw_panel_gal.h> #include <pcb_draw_panel_gal.h>
#include <lib_id.h> #include <lib_id.h>
#include <pcb_origin_transforms.h>
/* Forward declarations of classes. */ /* Forward declarations of classes. */
class APP_SETTINGS_BASE; class APP_SETTINGS_BASE;
@ -77,6 +78,8 @@ protected:
PCB_DISPLAY_OPTIONS m_DisplayOptions; PCB_DISPLAY_OPTIONS m_DisplayOptions;
PCB_ORIGIN_TRANSFORMS m_OriginTransforms;
PCBNEW_SETTINGS* m_Settings; // No ownership, just a shortcut PCBNEW_SETTINGS* m_Settings; // No ownership, just a shortcut
virtual void unitsChangeRefresh() override; virtual void unitsChangeRefresh() override;
@ -144,6 +147,15 @@ public:
const wxPoint& GetGridOrigin() const override; const wxPoint& GetGridOrigin() const override;
void SetGridOrigin( const wxPoint& aPoint ) 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; const TITLE_BLOCK& GetTitleBlock() const override;
void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override; void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;

View File

@ -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, const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
long aStyle, const wxString & aFrameName ) : long aStyle, const wxString & aFrameName ) :
EDA_DRAW_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, 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<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ); m_Settings = static_cast<PCBNEW_SETTINGS*>( 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 const TITLE_BLOCK& PCB_BASE_FRAME::GetTitleBlock() const
{ {
wxASSERT( m_Pcb ); wxASSERT( m_Pcb );
@ -526,9 +564,13 @@ void PCB_BASE_FRAME::UpdateStatusBar()
SetStatusText( line, 3 ); SetStatusText( line, 3 );
} }
// Transform absolute coordinates for user origin preferences
double userXpos = m_OriginTransforms.ToDisplayAbsX( static_cast<double>( cursorPos.x ) );
double userYpos = m_OriginTransforms.ToDisplayAbsY( static_cast<double>( cursorPos.y ) );
// Display absolute coordinates: // Display absolute coordinates:
double dXpos = To_User_Unit( GetUserUnits(), cursorPos.x ); double dXpos = To_User_Unit( GetUserUnits(), userXpos );
double dYpos = To_User_Unit( GetUserUnits(), cursorPos.y ); double dYpos = To_User_Unit( GetUserUnits(), userYpos );
// The following sadly is an if Eeschema/if Pcbnew // The following sadly is an if Eeschema/if Pcbnew
wxString absformatter; wxString absformatter;
@ -561,9 +603,17 @@ void PCB_BASE_FRAME::UpdateStatusBar()
if( !GetShowPolarCoords() ) // display relative cartesian coordinates 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: // Display relative coordinates:
dXpos = To_User_Unit( GetUserUnits(), cursorPos.x - screen->m_LocalOrigin.x ); dXpos = To_User_Unit( GetUserUnits(), userXpos );
dYpos = To_User_Unit( GetUserUnits(), cursorPos.y - screen->m_LocalOrigin.y ); dYpos = To_User_Unit( GetUserUnits(), userYpos );
// We already decided the formatter above // We already decided the formatter above
line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) ); line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );