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:
parent
af218a5dc0
commit
6f1204cfd7
|
@ -42,6 +42,7 @@
|
|||
#include <pcb_display_options.h>
|
||||
#include <pcb_draw_panel_gal.h>
|
||||
#include <lib_id.h>
|
||||
#include <pcb_origin_transforms.h>
|
||||
|
||||
/* 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;
|
||||
|
||||
|
|
|
@ -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<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
|
||||
{
|
||||
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<double>( cursorPos.x ) );
|
||||
double userYpos = m_OriginTransforms.ToDisplayAbsY( static_cast<double>( 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 ) );
|
||||
|
|
Loading…
Reference in New Issue