Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
|
2017-02-13 11:53:58 +00:00
|
|
|
* Copyright (C) 2012-2017 Kicad Developers, see change_log.txt for contributors.
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
*
|
|
|
|
* Graphics Abstraction Layer (GAL) - base class
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/log.h>
|
|
|
|
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <gal/definitions.h>
|
2021-12-31 14:07:24 +00:00
|
|
|
#include <font/font.h>
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
|
|
|
|
2016-05-28 16:46:29 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
using namespace KIGFX;
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
|
2014-06-05 10:40:26 +00:00
|
|
|
|
2017-02-13 11:43:28 +00:00
|
|
|
GAL::GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions ) :
|
2021-03-19 21:38:53 +00:00
|
|
|
m_options( aDisplayOptions ),
|
2021-07-13 09:06:46 +00:00
|
|
|
// m_currentNativeCursor is initialized with KICURSOR::DEFAULT value to avoid
|
|
|
|
// if comparison with uninitialized value on SetNativeCursorStyle method.
|
|
|
|
// Some classes inheriting from GAL has different SetNativeCursorStyle method
|
|
|
|
// implementation and therefore it's called also on constructor
|
|
|
|
// to change the value from DEFAULT to KICURSOR::ARROW
|
|
|
|
m_currentNativeCursor( KICURSOR::DEFAULT )
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
{
|
|
|
|
// Set the default values for the internal variables
|
|
|
|
SetIsFill( false );
|
|
|
|
SetIsStroke( true );
|
|
|
|
SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
|
|
|
|
SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
|
2014-02-13 19:23:28 +00:00
|
|
|
SetLookAtPoint( VECTOR2D( 0, 0 ) );
|
2013-07-30 15:09:06 +00:00
|
|
|
SetZoomFactor( 1.0 );
|
2018-08-03 08:22:34 +00:00
|
|
|
SetRotation( 0.0 );
|
2018-11-20 09:22:45 +00:00
|
|
|
// this value for SetWorldUnitLength is only suitable for Pcbnew.
|
|
|
|
// Other editors/viewer must call SetWorldUnitLength with their internal units
|
2018-10-21 22:16:15 +00:00
|
|
|
SetWorldUnitLength( 1e-9 /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
|
|
|
|
// wxDC::GetPPI() reports 96 DPI, but somehow this value
|
|
|
|
// is the closest match to the legacy renderer
|
|
|
|
SetScreenDPI( 91 );
|
2013-09-11 09:34:10 +00:00
|
|
|
SetDepthRange( VECTOR2D( GAL::MIN_DEPTH, GAL::MAX_DEPTH ) );
|
2015-03-21 09:06:04 +00:00
|
|
|
SetLayerDepth( 0.0 );
|
2013-08-27 16:08:32 +00:00
|
|
|
SetFlip( false, false );
|
2018-09-28 10:46:20 +00:00
|
|
|
SetLineWidth( 1.0f );
|
2016-05-02 13:56:12 +00:00
|
|
|
computeWorldScale();
|
2017-03-30 07:52:40 +00:00
|
|
|
SetAxesEnabled( false );
|
2013-07-30 15:09:06 +00:00
|
|
|
|
|
|
|
// Set grid defaults
|
|
|
|
SetGridVisibility( true );
|
|
|
|
SetCoarseGrid( 10 );
|
2021-03-19 21:38:53 +00:00
|
|
|
m_gridLineWidth = 0.5f;
|
|
|
|
m_gridStyle = GRID_STYLE::LINES;
|
|
|
|
m_gridMinSpacing = 10;
|
2013-07-30 15:09:06 +00:00
|
|
|
|
|
|
|
// Initialize the cursor shape
|
|
|
|
SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
|
2021-03-19 21:38:53 +00:00
|
|
|
m_fullscreenCursor = false;
|
|
|
|
m_forceDisplayCursor = false;
|
2017-03-19 20:51:59 +00:00
|
|
|
SetCursorEnabled( false );
|
2013-07-04 09:37:43 +00:00
|
|
|
|
2021-04-05 01:35:01 +00:00
|
|
|
// Initialize the native widget to an arrow cursor
|
|
|
|
SetNativeCursorStyle( KICURSOR::ARROW );
|
|
|
|
|
2017-03-30 07:44:38 +00:00
|
|
|
// Initialize text properties
|
|
|
|
ResetTextAttributes();
|
|
|
|
|
2017-02-13 11:43:28 +00:00
|
|
|
// subscribe for settings updates
|
2021-03-19 21:38:53 +00:00
|
|
|
m_observerLink = m_options.Subscribe( this );
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GAL::~GAL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-08 09:35:51 +00:00
|
|
|
|
2017-02-13 11:43:28 +00:00
|
|
|
void GAL::OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& aOptions )
|
|
|
|
{
|
|
|
|
// defer to the child class first
|
|
|
|
updatedGalDisplayOptions( aOptions );
|
|
|
|
|
|
|
|
// there is no refresh to do at this level
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions )
|
|
|
|
{
|
|
|
|
bool refresh = false;
|
|
|
|
|
2021-03-19 21:38:53 +00:00
|
|
|
if( m_options.m_gridStyle != m_gridStyle )
|
2017-02-13 11:53:58 +00:00
|
|
|
{
|
2021-03-19 21:38:53 +00:00
|
|
|
m_gridStyle = m_options.m_gridStyle ;
|
2017-02-13 11:53:58 +00:00
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
|
2021-03-19 21:38:53 +00:00
|
|
|
if( m_options.m_gridLineWidth != m_gridLineWidth )
|
2017-02-14 15:31:21 +00:00
|
|
|
{
|
2024-01-19 17:20:06 +00:00
|
|
|
m_gridLineWidth = std::floor( m_options.m_scaleFactor * ( m_options.m_gridLineWidth + 0.5 ) );
|
2017-02-14 15:31:21 +00:00
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
|
2021-03-19 21:38:53 +00:00
|
|
|
if( m_options.m_gridMinSpacing != m_gridMinSpacing )
|
2017-02-13 03:47:50 +00:00
|
|
|
{
|
2024-01-19 17:20:06 +00:00
|
|
|
m_gridMinSpacing = m_options.m_scaleFactor * m_options.m_gridMinSpacing;
|
2017-02-13 03:47:50 +00:00
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
|
2021-03-19 21:38:53 +00:00
|
|
|
if( m_options.m_axesEnabled != m_axesEnabled )
|
2017-03-08 08:37:12 +00:00
|
|
|
{
|
2021-03-19 21:38:53 +00:00
|
|
|
m_axesEnabled = m_options.m_axesEnabled;
|
2017-03-08 08:37:12 +00:00
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
|
2021-03-19 21:38:53 +00:00
|
|
|
if( m_options.m_forceDisplayCursor != m_forceDisplayCursor )
|
2017-03-18 20:03:24 +00:00
|
|
|
{
|
2021-03-19 21:38:53 +00:00
|
|
|
m_forceDisplayCursor = m_options.m_forceDisplayCursor;
|
2017-03-18 20:03:24 +00:00
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
|
2021-03-19 21:38:53 +00:00
|
|
|
if( m_options.m_fullscreenCursor != m_fullscreenCursor )
|
2017-03-19 20:51:59 +00:00
|
|
|
{
|
2021-03-19 21:38:53 +00:00
|
|
|
m_fullscreenCursor = m_options.m_fullscreenCursor;
|
2017-03-19 20:51:59 +00:00
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
|
2017-02-13 11:43:28 +00:00
|
|
|
// tell the derived class if the base class needs an update or not
|
|
|
|
return refresh;
|
|
|
|
}
|
|
|
|
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
|
2017-03-30 07:44:38 +00:00
|
|
|
void GAL::ResetTextAttributes()
|
|
|
|
{
|
|
|
|
// Tiny but non-zero - this will always need setting
|
|
|
|
// there is no built-in default
|
2022-01-11 13:47:21 +00:00
|
|
|
SetGlyphSize( { 1, 1 } );
|
2017-03-30 07:44:38 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
|
2017-03-30 07:44:38 +00:00
|
|
|
|
|
|
|
SetFontBold( false );
|
|
|
|
SetFontItalic( false );
|
2020-10-02 20:18:07 +00:00
|
|
|
SetFontUnderlined( false );
|
2017-03-30 07:44:38 +00:00
|
|
|
SetTextMirrored( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-30 16:29:54 +00:00
|
|
|
void GAL::ComputeWorldScreenMatrix()
|
|
|
|
{
|
2016-05-02 13:56:12 +00:00
|
|
|
computeWorldScale();
|
2013-07-30 16:29:54 +00:00
|
|
|
|
|
|
|
MATRIX3x3D translation;
|
|
|
|
translation.SetIdentity();
|
2021-06-02 13:04:23 +00:00
|
|
|
// We're deliberately dividing integers to avoid fractional pixel offsets.
|
|
|
|
translation.SetTranslation( VECTOR2D( m_screenSize.x/2, m_screenSize.y/2 ) );
|
2013-07-30 16:29:54 +00:00
|
|
|
|
2018-08-03 08:22:34 +00:00
|
|
|
MATRIX3x3D rotate;
|
|
|
|
rotate.SetIdentity();
|
2021-03-19 21:38:53 +00:00
|
|
|
rotate.SetRotation( m_rotation );
|
2018-08-03 08:22:34 +00:00
|
|
|
|
2013-07-30 16:29:54 +00:00
|
|
|
MATRIX3x3D scale;
|
|
|
|
scale.SetIdentity();
|
2021-03-19 21:38:53 +00:00
|
|
|
scale.SetScale( VECTOR2D( m_worldScale, m_worldScale ) );
|
2013-07-30 16:29:54 +00:00
|
|
|
|
|
|
|
MATRIX3x3D flip;
|
|
|
|
flip.SetIdentity();
|
2021-03-19 21:38:53 +00:00
|
|
|
flip.SetScale( VECTOR2D( m_globalFlipX ? -1.0 : 1.0, m_globalFlipY ? -1.0 : 1.0 ) );
|
2013-07-30 16:29:54 +00:00
|
|
|
|
|
|
|
MATRIX3x3D lookat;
|
|
|
|
lookat.SetIdentity();
|
2021-03-19 21:38:53 +00:00
|
|
|
lookat.SetTranslation( -m_lookAtPoint );
|
2013-07-30 16:29:54 +00:00
|
|
|
|
2021-03-19 21:38:53 +00:00
|
|
|
m_worldScreenMatrix = translation * rotate * flip * scale * lookat;
|
|
|
|
m_screenWorldMatrix = m_worldScreenMatrix.Inverse();
|
2013-07-30 16:29:54 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
|
2021-04-10 20:13:01 +00:00
|
|
|
BOX2D GAL::GetVisibleWorldExtents() const
|
|
|
|
{
|
|
|
|
const MATRIX3x3D& matrix = GetScreenWorldMatrix();
|
|
|
|
|
|
|
|
VECTOR2D halfSize = VECTOR2D( matrix.GetScale().x * m_screenSize.x * 0.5,
|
|
|
|
matrix.GetScale().y * m_screenSize.y * 0.5 );
|
|
|
|
|
|
|
|
BOX2D extents;
|
|
|
|
extents.SetOrigin( GetLookAtPoint() - halfSize );
|
|
|
|
extents.SetSize( halfSize * 2 );
|
|
|
|
|
|
|
|
return extents;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-13 03:47:50 +00:00
|
|
|
double GAL::computeMinGridSpacing() const
|
|
|
|
{
|
|
|
|
// just return the current value. This could be cleverer and take
|
|
|
|
// into account other settings in future
|
2021-03-19 21:38:53 +00:00
|
|
|
return m_gridMinSpacing;
|
2017-02-13 03:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-06 11:38:06 +00:00
|
|
|
VECTOR2D GAL::GetGridPoint( const VECTOR2D& aPoint ) const
|
2013-08-28 14:25:42 +00:00
|
|
|
{
|
2017-11-07 08:45:03 +00:00
|
|
|
#if 0
|
|
|
|
// This old code expects a non zero grid size, which can be wrong here.
|
2021-03-19 21:38:53 +00:00
|
|
|
return VECTOR2D( KiROUND( ( aPoint.x - m_gridOffset.x ) / m_gridSize.x ) * m_gridSize.x + m_gridOffset.x,
|
|
|
|
KiROUND( ( aPoint.y - m_gridOffset.y ) / m_gridSize.y ) * m_gridSize.y + m_gridOffset.y );
|
2017-11-07 08:45:03 +00:00
|
|
|
#else
|
|
|
|
// if grid size == 0.0 there is no grid, so use aPoint as grid reference position
|
2021-03-19 21:38:53 +00:00
|
|
|
double cx = m_gridSize.x > 0.0 ? KiROUND( ( aPoint.x - m_gridOffset.x ) / m_gridSize.x ) * m_gridSize.x + m_gridOffset.x
|
|
|
|
: aPoint.x;
|
|
|
|
double cy = m_gridSize.y > 0.0 ? KiROUND( ( aPoint.y - m_gridOffset.y ) / m_gridSize.y ) * m_gridSize.y + m_gridOffset.y
|
|
|
|
: aPoint.y;
|
2017-11-07 08:45:03 +00:00
|
|
|
|
|
|
|
return VECTOR2D( cx, cy );
|
|
|
|
#endif
|
2013-08-28 14:25:42 +00:00
|
|
|
}
|
2015-03-30 12:09:56 +00:00
|
|
|
|
2015-03-30 20:14:37 +00:00
|
|
|
const int GAL::MIN_DEPTH = -1024;
|
|
|
|
const int GAL::MAX_DEPTH = 1023;
|
2015-03-30 12:09:56 +00:00
|
|
|
const int GAL::GRID_DEPTH = MAX_DEPTH - 1;
|
2017-03-18 22:00:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
COLOR4D GAL::getCursorColor() const
|
|
|
|
{
|
2021-03-19 21:38:53 +00:00
|
|
|
COLOR4D color = m_cursorColor;
|
2017-03-18 22:00:21 +00:00
|
|
|
|
|
|
|
// dim the cursor if it's only on because it was forced
|
|
|
|
// (this helps to provide a hint for active tools)
|
2021-03-19 21:38:53 +00:00
|
|
|
if( !m_isCursorEnabled )
|
2017-03-18 22:00:21 +00:00
|
|
|
color.a = color.a * 0.5;
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
2021-04-05 01:35:01 +00:00
|
|
|
|
|
|
|
|
2021-12-31 14:07:24 +00:00
|
|
|
/*
|
|
|
|
* Fallback for implementations that don't implement bitmap text: use stroke font
|
|
|
|
*/
|
2022-01-11 13:47:21 +00:00
|
|
|
void GAL::BitmapText( const wxString& aText, const VECTOR2I& aPosition, const EDA_ANGLE& aAngle )
|
2021-12-31 14:07:24 +00:00
|
|
|
{
|
2022-01-11 13:47:21 +00:00
|
|
|
KIFONT::FONT* font = KIFONT::FONT::GetFont();
|
|
|
|
|
|
|
|
if( aText.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
TEXT_ATTRIBUTES attrs = m_attributes;
|
|
|
|
attrs.m_Angle = aAngle;
|
|
|
|
attrs.m_Mirrored = m_globalFlipX; // Prevent text flipping when view is flipped
|
2021-12-31 14:07:24 +00:00
|
|
|
|
2022-03-07 17:41:46 +00:00
|
|
|
// Bitmap font has different metrics than the stroke font so we compensate a bit before
|
|
|
|
// stroking
|
2022-05-13 21:36:20 +00:00
|
|
|
attrs.m_Size = VECTOR2I( m_attributes.m_Size.x, m_attributes.m_Size.y * 0.95 );
|
|
|
|
attrs.m_StrokeWidth = GetLineWidth() * 0.74;
|
2021-12-31 14:07:24 +00:00
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
font->Draw( this, aText, aPosition, attrs, KIFONT::METRICS::Default() );
|
2021-12-31 14:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-05 01:35:01 +00:00
|
|
|
bool GAL::SetNativeCursorStyle( KICURSOR aCursor )
|
|
|
|
{
|
|
|
|
if( m_currentNativeCursor == aCursor )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_currentNativeCursor = aCursor;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|