Add axis origin to the Footprint Editor to align with the Legacy canvas
This commit is contained in:
parent
8f14e9e0b7
commit
34aab6f687
|
@ -30,7 +30,7 @@ using namespace KIGFX;
|
|||
|
||||
ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) :
|
||||
EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
|
||||
m_position( aPosition ), m_size( aSize ), m_color( aColor ), m_style( aStyle )
|
||||
m_position( aPosition ), m_size( aSize ), m_color( aColor ), m_style( aStyle ), m_drawAtZero( false )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,9 @@ const BOX2I ORIGIN_VIEWITEM::ViewBBox() const
|
|||
|
||||
void ORIGIN_VIEWITEM::ViewDraw( int, GAL* aGal ) const
|
||||
{
|
||||
// Legacy canvas does not draw markers if they are located in the (0, 0) point
|
||||
if( m_position.x == 0 && m_position.y == 0 )
|
||||
// Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is. This
|
||||
// mimics the Legacy canvas that doesn't display most targets at 0,0
|
||||
if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
|
||||
return;
|
||||
|
||||
aGal->SetIsStroke( true );
|
||||
|
@ -54,6 +55,9 @@ void ORIGIN_VIEWITEM::ViewDraw( int, GAL* aGal ) const
|
|||
aGal->SetLineWidth( 1 );
|
||||
aGal->SetStrokeColor( m_color );
|
||||
VECTOR2D scaledSize = m_view->ToWorld( VECTOR2D( m_size, m_size ), false );
|
||||
|
||||
// Draw a circle around the marker's centre point if the style demands it
|
||||
if( ( m_style == CIRCLE_CROSS ) || ( m_style == CIRCLE_DOT ) || ( m_style == CIRCLE_X ) )
|
||||
aGal->DrawCircle( m_position, scaledSize.x );
|
||||
|
||||
switch( m_style )
|
||||
|
@ -62,17 +66,22 @@ void ORIGIN_VIEWITEM::ViewDraw( int, GAL* aGal ) const
|
|||
break;
|
||||
|
||||
case CROSS:
|
||||
aGal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ), m_position + VECTOR2D( scaledSize.x, 0 ) );
|
||||
aGal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ), m_position + VECTOR2D( 0, scaledSize.y ) );
|
||||
case CIRCLE_CROSS:
|
||||
aGal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ),
|
||||
m_position + VECTOR2D( scaledSize.x, 0 ) );
|
||||
aGal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ),
|
||||
m_position + VECTOR2D( 0, scaledSize.y ) );
|
||||
break;
|
||||
|
||||
case X:
|
||||
case CIRCLE_X:
|
||||
aGal->DrawLine( m_position - scaledSize, m_position + scaledSize );
|
||||
scaledSize.y = -scaledSize.y;
|
||||
aGal->DrawLine( m_position - scaledSize, m_position + scaledSize );
|
||||
break;
|
||||
|
||||
case DOT:
|
||||
case CIRCLE_DOT:
|
||||
aGal->DrawCircle( m_position, scaledSize.x / 4 );
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -42,10 +42,11 @@ class ORIGIN_VIEWITEM : public EDA_ITEM
|
|||
{
|
||||
public:
|
||||
///> Marker symbol styles
|
||||
enum MARKER_STYLE { NONE, CROSS, X, DOT };
|
||||
enum MARKER_STYLE { NONE, CROSS, X, DOT, CIRCLE_CROSS, CIRCLE_X, CIRCLE_DOT };
|
||||
|
||||
ORIGIN_VIEWITEM( const COLOR4D& aColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 ), MARKER_STYLE aStyle = X,
|
||||
int aSize = 16, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) );
|
||||
ORIGIN_VIEWITEM( const COLOR4D& aColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 ),
|
||||
MARKER_STYLE aStyle = CIRCLE_X, int aSize = 16,
|
||||
const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) );
|
||||
|
||||
const BOX2I ViewBBox() const;
|
||||
|
||||
|
@ -71,6 +72,17 @@ public:
|
|||
return wxT( "ORIGIN_VIEWITEM" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Function SetDrawAtZero()
|
||||
* Set the draw at zero flag. When set the marker will be drawn when it's position is 0,0.
|
||||
* Otherwise it will not be drawn when its position is 0,0
|
||||
* @param aDrawFlag The value to set the draw at zero flag
|
||||
*/
|
||||
inline void SetDrawAtZero( bool aDrawFlag )
|
||||
{
|
||||
m_drawAtZero = aDrawFlag;
|
||||
}
|
||||
|
||||
inline void SetPosition( const VECTOR2D& aPosition )
|
||||
{
|
||||
m_position = aPosition;
|
||||
|
@ -123,6 +135,9 @@ protected:
|
|||
|
||||
///> Marker symbol.
|
||||
MARKER_STYLE m_style;
|
||||
|
||||
///> If set, the marker will be drawn even if its position is 0,0
|
||||
bool m_drawAtZero;
|
||||
};
|
||||
|
||||
} // namespace KIGFX
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <view/view_controls.h>
|
||||
#include <view/view_group.h>
|
||||
#include <pcb_painter.h>
|
||||
#include <origin_viewitem.h>
|
||||
|
||||
#include <kicad_plugin.h>
|
||||
#include <pcbnew_id.h>
|
||||
|
@ -51,6 +52,18 @@ MODULE_TOOLS::MODULE_TOOLS() :
|
|||
TOOL_INTERACTIVE( "pcbnew.ModuleEditor" ), m_view( NULL ), m_controls( NULL ),
|
||||
m_board( NULL ), m_frame( NULL )
|
||||
{
|
||||
// Generate an origin marker at 0,0 which is used as an axis origin marker (0,0)
|
||||
m_axisOrigin = new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D(0.0, 0.0, 0.8, 1.0),
|
||||
KIGFX::ORIGIN_VIEWITEM::CROSS,
|
||||
20000,
|
||||
VECTOR2D(0,0) );
|
||||
m_axisOrigin->SetDrawAtZero( true );
|
||||
}
|
||||
|
||||
|
||||
MODULE_TOOLS::~MODULE_TOOLS()
|
||||
{
|
||||
delete m_axisOrigin;
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,6 +74,13 @@ void MODULE_TOOLS::Reset( RESET_REASON aReason )
|
|||
m_controls = getViewControls();
|
||||
m_board = getModel<BOARD>();
|
||||
m_frame = getEditFrame<PCB_EDIT_FRAME>();
|
||||
|
||||
if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
|
||||
{
|
||||
// Draw the axis origin if we're editing modules (essentially in the footprint editor)
|
||||
m_view->Remove( m_axisOrigin );
|
||||
m_view->Add( m_axisOrigin );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define MODULE_TOOLS_H
|
||||
|
||||
#include <tool/tool_interactive.h>
|
||||
#include <origin_viewitem.h>
|
||||
|
||||
namespace KIGFX
|
||||
{
|
||||
|
@ -44,6 +45,7 @@ class MODULE_TOOLS : public TOOL_INTERACTIVE
|
|||
{
|
||||
public:
|
||||
MODULE_TOOLS();
|
||||
~MODULE_TOOLS();
|
||||
|
||||
/// @copydoc TOOL_INTERACTIVE::Reset()
|
||||
void Reset( RESET_REASON aReason );
|
||||
|
@ -106,6 +108,10 @@ private:
|
|||
KIGFX::VIEW_CONTROLS* m_controls;
|
||||
BOARD* m_board;
|
||||
PCB_EDIT_FRAME* m_frame;
|
||||
|
||||
///> Axis 0 marker
|
||||
KIGFX::ORIGIN_VIEWITEM* m_axisOrigin;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -85,7 +85,7 @@ PCB_EDITOR_CONTROL::PCB_EDITOR_CONTROL() :
|
|||
TOOL_INTERACTIVE( "pcbnew.EditorControl" ), m_frame( NULL ), m_zoneMenu( NULL )
|
||||
{
|
||||
m_placeOrigin = new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D( 0.8, 0.0, 0.0, 1.0 ),
|
||||
KIGFX::ORIGIN_VIEWITEM::CROSS );
|
||||
KIGFX::ORIGIN_VIEWITEM::CIRCLE_CROSS );
|
||||
m_probingSchToPcb = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue