Use GAL axes instead of a ORIGIN_VIEWITEM in module editor

This commit is contained in:
Maciej Suminski 2017-03-08 10:35:51 +01:00
parent 2513f0b002
commit 62235348d1
6 changed files with 198 additions and 184 deletions

View File

@ -79,6 +79,7 @@ GAL::~GAL()
{
}
void GAL::OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& aOptions )
{
// defer to the child class first
@ -179,9 +180,6 @@ double GAL::computeMinGridSpacing() const
void GAL::DrawGrid()
{
if( !gridVisibility )
return;
SetTarget( TARGET_NONCACHED );
// Draw the grid
@ -202,146 +200,6 @@ void GAL::DrawGrid()
double marker = std::max( 1.0, gridLineWidth ) / worldScale;
double doubleMarker = 2.0 * marker;
// Check if the grid would not be too dense
if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) > gridThreshold )
{
// Compute grid variables
int gridStartX = KiROUND( worldStartPoint.x / gridSize.x );
int gridEndX = KiROUND( worldEndPoint.x / gridSize.x );
int gridStartY = KiROUND( worldStartPoint.y / gridSize.y );
int gridEndY = KiROUND( worldEndPoint.y / gridSize.y );
// Correct the index, else some lines are not correctly painted
gridStartY -= std::abs( gridOrigin.y / gridSize.y ) + 1;
gridEndY += std::abs( gridOrigin.y / gridSize.y ) + 1;
if ( gridStartX <= gridEndX )
{
gridStartX -= std::abs( gridOrigin.x / gridSize.x ) + 1;
gridEndX += std::abs( gridOrigin.x / gridSize.x ) + 1;
}
else
{
gridStartX += std::abs( gridOrigin.x / gridSize.x ) + 1;
gridEndX -= std::abs( gridOrigin.x / gridSize.x ) + 1;
}
int dirX = gridEndX >= gridStartX ? 1 : -1;
int dirY = gridEndY >= gridStartY ? 1 : -1;
// Draw the grid behind all other layers
SetLayerDepth( depthRange.y * 0.75 );
if( gridStyle == GRID_STYLE::LINES )
{
SetIsFill( false );
SetIsStroke( true );
SetStrokeColor( gridColor );
// Now draw the grid, every coarse grid line gets the double width
// Vertical lines
for( int j = gridStartY; j != gridEndY; j += dirY )
{
if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
SetLineWidth( doubleMarker );
else
SetLineWidth( marker );
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
drawGridLine( VECTOR2D( gridStartX * gridSize.x, j * gridSize.y + gridOrigin.y ),
VECTOR2D( gridEndX * gridSize.x, j * gridSize.y + gridOrigin.y ) );
}
}
// Horizontal lines
for( int i = gridStartX; i != gridEndX; i += dirX )
{
if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
SetLineWidth( doubleMarker );
else
SetLineWidth( marker );
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
drawGridLine( VECTOR2D( i * gridSize.x + gridOrigin.x, gridStartY * gridSize.y ),
VECTOR2D( i * gridSize.x + gridOrigin.x, gridEndY * gridSize.y ) );
}
}
}
else if( gridStyle == GRID_STYLE::SMALL_CROSS )
{
SetIsFill( false );
SetIsStroke( true );
SetStrokeColor( gridColor );
SetLineWidth( marker );
double lineLen = GetLineWidth() * 2;
// Vertical positions:
for( int j = gridStartY; j != gridEndY; j += dirY )
{
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
int posY = j * gridSize.y + gridOrigin.y;
// Horizontal positions:
for( int i = gridStartX; i != gridEndX; i += dirX )
{
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
int posX = i * gridSize.x + gridOrigin.x;
drawGridLine( VECTOR2D( posX - lineLen, posY ),
VECTOR2D( posX + lineLen, posY ) );
drawGridLine( VECTOR2D( posX, posY - lineLen ),
VECTOR2D( posX, posY + lineLen ) );
}
}
}
}
}
else // Dotted grid
{
bool tickX, tickY;
SetIsFill( true );
SetIsStroke( false );
SetFillColor( gridColor );
for( int j = gridStartY; j != gridEndY; j += dirY )
{
if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
tickY = true;
else
tickY = false;
for( int i = gridStartX; i != gridEndX; i += dirX )
{
if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
tickX = true;
else
tickX = false;
if( tickX || tickY || gridScreenSizeDense > gridThreshold )
{
double radius = ( ( tickX && tickY ) ? doubleMarker : marker ) / 2.0;
DrawRectangle( VECTOR2D( i * gridSize.x - radius + gridOrigin.x,
j * gridSize.y - radius + gridOrigin.y ),
VECTOR2D( i * gridSize.x + radius + gridOrigin.x,
j * gridSize.y + radius + gridOrigin.y ) );
}
}
}
}
}
// Draw axes if desired
if( axesEnabled )
{
@ -356,6 +214,158 @@ void GAL::DrawGrid()
drawGridLine( VECTOR2D( 0, worldStartPoint.y ),
VECTOR2D( 0, worldEndPoint.y ) );
}
if( !gridVisibility )
return;
// Check if the grid would not be too dense
if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) <= gridThreshold )
return;
// Compute grid variables
int gridStartX = KiROUND( worldStartPoint.x / gridSize.x );
int gridEndX = KiROUND( worldEndPoint.x / gridSize.x );
int gridStartY = KiROUND( worldStartPoint.y / gridSize.y );
int gridEndY = KiROUND( worldEndPoint.y / gridSize.y );
// Correct the index, else some lines are not correctly painted
gridStartY -= std::abs( gridOrigin.y / gridSize.y ) + 1;
gridEndY += std::abs( gridOrigin.y / gridSize.y ) + 1;
if( gridStartX <= gridEndX )
{
gridStartX -= std::abs( gridOrigin.x / gridSize.x ) + 1;
gridEndX += std::abs( gridOrigin.x / gridSize.x ) + 1;
}
else
{
gridStartX += std::abs( gridOrigin.x / gridSize.x ) + 1;
gridEndX -= std::abs( gridOrigin.x / gridSize.x ) + 1;
}
int dirX = gridEndX >= gridStartX ? 1 : -1;
int dirY = gridEndY >= gridStartY ? 1 : -1;
// Draw the grid behind all other layers
SetLayerDepth( depthRange.y * 0.75 );
if( gridStyle == GRID_STYLE::LINES )
{
SetIsFill( false );
SetIsStroke( true );
SetStrokeColor( gridColor );
// Now draw the grid, every coarse grid line gets the double width
// Vertical lines
for( int j = gridStartY; j != gridEndY; j += dirY )
{
const double y = j * gridSize.y + gridOrigin.y;
if( axesEnabled && y == 0 )
continue;
if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
SetLineWidth( doubleMarker );
else
SetLineWidth( marker );
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
drawGridLine( VECTOR2D( gridStartX * gridSize.x, y ),
VECTOR2D( gridEndX * gridSize.x, y ) );
}
}
// Horizontal lines
for( int i = gridStartX; i != gridEndX; i += dirX )
{
const double x = i * gridSize.x + gridOrigin.x;
if( axesEnabled && x == 0 )
continue;
if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
SetLineWidth( doubleMarker );
else
SetLineWidth( marker );
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
drawGridLine( VECTOR2D( x, gridStartY * gridSize.y ),
VECTOR2D( x, gridEndY * gridSize.y ) );
}
}
}
else if( gridStyle == GRID_STYLE::SMALL_CROSS )
{
SetIsFill( false );
SetIsStroke( true );
SetStrokeColor( gridColor );
SetLineWidth( marker );
double lineLen = GetLineWidth() * 2;
// Vertical positions:
for( int j = gridStartY; j != gridEndY; j += dirY )
{
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
int posY = j * gridSize.y + gridOrigin.y;
// Horizontal positions:
for( int i = gridStartX; i != gridEndX; i += dirX )
{
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
int posX = i * gridSize.x + gridOrigin.x;
drawGridLine( VECTOR2D( posX - lineLen, posY ),
VECTOR2D( posX + lineLen, posY ) );
drawGridLine( VECTOR2D( posX, posY - lineLen ),
VECTOR2D( posX, posY + lineLen ) );
}
}
}
}
}
else // Dotted grid
{
bool tickX, tickY;
SetIsFill( true );
SetIsStroke( false );
SetFillColor( gridColor );
for( int j = gridStartY; j != gridEndY; j += dirY )
{
if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
tickY = true;
else
tickY = false;
for( int i = gridStartX; i != gridEndX; i += dirX )
{
if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
tickX = true;
else
tickX = false;
if( tickX || tickY || gridScreenSizeDense > gridThreshold )
{
double radius = ( ( tickX && tickY ) ? doubleMarker : marker ) / 2.0;
DrawRectangle( VECTOR2D( i * gridSize.x - radius + gridOrigin.x,
j * gridSize.y - radius + gridOrigin.y ),
VECTOR2D( i * gridSize.x + radius + gridOrigin.x,
j * gridSize.y + radius + gridOrigin.y ) );
}
}
}
}
}

View File

@ -848,9 +848,6 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition,
void OPENGL_GAL::DrawGrid()
{
if( !gridVisibility )
return;
int gridScreenSizeDense = KiROUND( gridSize.x * worldScale );
int gridScreenSizeCoarse = KiROUND( gridSize.x * static_cast<double>( gridTick ) * worldScale );
@ -873,6 +870,26 @@ void OPENGL_GAL::DrawGrid()
VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize );
// Draw axes if desired
if( axesEnabled )
{
glLineWidth( minorLineWidth );
glColor4d( axesColor.r, axesColor.g, axesColor.b, 1.0 );
glBegin( GL_LINES );
glVertex2d( worldStartPoint.x, 0 );
glVertex2d( worldEndPoint.x, 0 );
glEnd();
glBegin( GL_LINES );
glVertex2d( 0, worldStartPoint.y );
glVertex2d( 0, worldEndPoint.y );
glEnd();
}
if( !gridVisibility )
return;
// Compute grid variables
int gridStartX = KiROUND( worldStartPoint.x / gridSize.x );
int gridEndX = KiROUND( worldEndPoint.x / gridSize.x );
@ -883,7 +900,7 @@ void OPENGL_GAL::DrawGrid()
gridStartY -= std::abs( gridOrigin.y / gridSize.y ) + 1;
gridEndY += std::abs( gridOrigin.y / gridSize.y ) + 1;
if ( gridStartX <= gridEndX )
if( gridStartX <= gridEndX )
{
gridStartX -= std::abs( gridOrigin.x / gridSize.x ) + 1;
gridEndX += std::abs( gridOrigin.x / gridSize.x ) + 1;
@ -952,6 +969,12 @@ void OPENGL_GAL::DrawGrid()
// Vertical lines
for( int j = gridStartY; j != gridEndY; j += dirY )
{
const double y = j * gridSize.y + gridOrigin.y;
// If axes are drawn, skip the lines that would cover them
if( axesEnabled && y == 0 )
continue;
if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
glLineWidth( majorLineWidth );
else
@ -961,8 +984,8 @@ void OPENGL_GAL::DrawGrid()
|| gridScreenSizeDense > gridThreshold )
{
glBegin( GL_LINES );
glVertex2d( gridStartX * gridSize.x, j * gridSize.y + gridOrigin.y );
glVertex2d( gridEndX * gridSize.x, j * gridSize.y + gridOrigin.y );
glVertex2d( gridStartX * gridSize.x, y );
glVertex2d( gridEndX * gridSize.x, y );
glEnd();
}
}
@ -976,6 +999,12 @@ void OPENGL_GAL::DrawGrid()
// Horizontal lines
for( int i = gridStartX; i != gridEndX; i += dirX )
{
const double x = i * gridSize.x + gridOrigin.x;
// If axes are drawn, skip the lines that would cover them
if( axesEnabled && x == 0 )
continue;
if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
glLineWidth( majorLineWidth );
else
@ -995,23 +1024,6 @@ void OPENGL_GAL::DrawGrid()
glDisable( GL_STENCIL_TEST );
}
// Draw axes if desired
if( axesEnabled )
{
glLineWidth( minorLineWidth );
glColor4d( axesColor.r, axesColor.g, axesColor.b, 1.0 );
glBegin( GL_LINES );
glVertex2d( worldStartPoint.x, 0 );
glVertex2d( worldEndPoint.x, 0 );
glEnd();
glBegin( GL_LINES );
glVertex2d( 0, worldStartPoint.y );
glVertex2d( 0, worldEndPoint.y );
glEnd();
}
glEnable( GL_DEPTH_TEST );
glEnable( GL_TEXTURE_2D );
}

View File

@ -809,6 +809,14 @@ public:
axesColor = aAxesColor;
}
/**
* @brief Enables drawing the axes.
*/
inline void SetAxesEnabled( bool aAxesEnabled )
{
axesEnabled = aAxesEnabled;
}
/**
* @brief Draw every tick line wider.
*

View File

@ -43,6 +43,7 @@
#include <msgpanel.h>
#include <fp_lib_table.h>
#include <bitmaps.h>
#include <gal/graphics_abstraction_layer.h>
#include <class_board.h>
#include <class_module.h>
@ -330,6 +331,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
// Create the manager and dispatcher & route draw panel events to the dispatcher
setupTools();
GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
UseGalCanvas( parentFrame->IsGalCanvasActive() );
if( m_auimgr.GetPane( "m_LayersManagerToolBar" ).IsShown() )

View File

@ -83,18 +83,11 @@ MODULE_EDITOR_TOOLS::MODULE_EDITOR_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_EDITOR_TOOLS::~MODULE_EDITOR_TOOLS()
{
delete m_axisOrigin;
}
@ -105,13 +98,6 @@ void MODULE_EDITOR_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 );
}
}

View File

@ -26,7 +26,6 @@
#define MODULE_EDITOR_TOOLS_H
#include <tool/tool_interactive.h>
#include <origin_viewitem.h>
namespace KIGFX
{
@ -106,9 +105,6 @@ private:
BOARD* m_board;
PCB_EDIT_FRAME* m_frame;
///> Axis 0 marker
KIGFX::ORIGIN_VIEWITEM* m_axisOrigin;
};
#endif