Commit e262b321 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

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
parent ef2c9406
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -57,6 +57,10 @@ option(KICAD_SCRIPTING_WXPYTHON
    "set this option ON to build wxpython implementation for wx interface building in python and py.shell"
    )
    
option(KICAD_GAL
    "set this option ON to build KICAD using Graphics Abstraction Layer as a rendering backend"
    )

# when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled:
# PYTHON_EXECUTABLE can be defined when invoking cmake
# ( use -DPYTHON_EXECUTABLE=<python path>/python.exe or python2 )
@@ -189,6 +193,10 @@ if(USE_WX_GRAPHICS_CONTEXT)
    add_definitions(-DUSE_WX_GRAPHICS_CONTEXT)
endif()

if(KICAD_GAL)
    add_definitions(-DKICAD_GAL)
endif()

# Allow user to override the default settings for adding images to menu items.  By default
# images in menu items are enabled on all platforms except OSX.  This can be over ridden by
# defining -DUSE_IMAGES_IN_MENUS=ON/OFF to force the preferred behavior.
@@ -257,6 +265,20 @@ add_definitions(-DWX_COMPATIBILITY)
find_package(OpenGL QUIET)
check_find_package_result(OPENGL_FOUND "OpenGL")

if(KICAD_GAL)
#####################
# Find GLEW library #
#####################
find_package(GLEW)
check_find_package_result(GLEW_FOUND "GLEW")

######################
# Find Cairo library #
######################
find_package(Cairo 1.8.1 QUIET)
check_find_package_result(CAIRO_FOUND "Cairo")
endif(KICAD_GAL)

######################
# Find Boost library #
######################
+31 −0
Original line number Diff line number Diff line
@@ -4,12 +4,29 @@ include_directories(
    ./dialogs
    ./dialog_about
    ${Boost_INCLUDE_DIR}
    ${CAIRO_INCLUDE_DIR}
    ../3d-viewer
    ../pcbnew
    ../polygon
    ${INC_AFTER}
    )

if(KICAD_GAL)
set(GAL_SRCS
    drawpanel_gal.cpp
    painter.cpp
    gal/graphics_abstraction_layer.cpp
    gal/stroke_font.cpp
    gal/color4d.cpp
    gal/opengl/opengl_gal.cpp
    gal/opengl/shader.cpp
    gal/cairo/cairo_gal.cpp
    view/wx_view_controls.cpp
    )

add_library(gal STATIC ${GAL_SRCS})
endif(KICAD_GAL)

set(COMMON_ABOUT_DLG_SRCS
    dialog_about/AboutDialog_main.cpp
    dialog_about/dialog_about.cpp
@@ -82,6 +99,14 @@ set(COMMON_SRCS
    zoom.cpp
    )

if(KICAD_GAL)
set(COMMON_SRCS
	${COMMON_SRCS}
	view/view.cpp
	view/view_item.cpp
    )
endif(KICAD_GAL)

add_library(common STATIC ${COMMON_SRCS})

set(PCB_COMMON_SRCS
@@ -131,6 +156,12 @@ set(PCB_COMMON_SRCS
    fp_lib_table.cpp
)

if(KICAD_GAL)
set(PCB_COMMON_SRCS
    ${PCB_COMMON_SRCS} 
    ../pcbnew/pcb_painter.cpp
    )
endif(KICAD_GAL)

# add -DPCBNEW to compilation of these PCBNEW sources
set_source_files_properties( ${PCB_COMMON_SRCS} PROPERTIES
+16 −0
Original line number Diff line number Diff line
@@ -222,6 +222,22 @@ EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem )
}


const BOX2I EDA_ITEM::ViewBBox() const
{
    // Basic fallback
    return BOX2I( VECTOR2I( GetBoundingBox().GetOrigin() ),
                  VECTOR2I( GetBoundingBox().GetSize() ) );
}


void EDA_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
{
    // Basic fallback
    aCount      = 1;
    aLayers[0]  = 0;
}


#if defined(DEBUG)

// A function that should have been in wxWidgets
+28 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <macros.h>
#include <id.h>
#include <class_drawpanel.h>
#include <class_drawpanel_gal.h>
#include <class_base_screen.h>
#include <msgpanel.h>
#include <wxstruct.h>
@@ -66,6 +67,7 @@ BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, EDA_BASE_FRAME )
    EVT_MENU_OPEN( EDA_DRAW_FRAME::OnMenuOpen )
    EVT_ACTIVATE( EDA_DRAW_FRAME::OnActivate )
    EVT_MENU_RANGE( ID_ZOOM_IN, ID_ZOOM_REDRAW, EDA_DRAW_FRAME::OnZoom )
    EVT_MENU( ID_SWITCH_CANVAS, EDA_DRAW_FRAME::OnZoom )
    EVT_MENU_RANGE( ID_OFFCENTER_ZOOM_IN, ID_OFFCENTER_ZOOM_OUT, EDA_DRAW_FRAME::OnZoom )
    EVT_MENU_RANGE( ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE,
                    EDA_DRAW_FRAME::OnZoom )
@@ -100,6 +102,8 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* aParent,
    m_HotkeysZoomAndGridList = NULL;

    m_canvas              = NULL;
    m_galCanvas           = NULL;
    m_galCanvasActive     = false;
    m_messagePanel        = NULL;
    m_currentScreen       = NULL;
    m_toolId              = ID_NO_TOOL_SELECTED;
@@ -937,3 +941,27 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
                             screen->m_ScrollbarPos.x,
                             screen->m_ScrollbarPos.y, noRefresh );
}


void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
{
    if( !( aEnable ^ m_galCanvasActive ) )
        return;

    if( aEnable )
    {
        m_canvas->Hide();
        m_galCanvas->Show();
        m_galCanvas->Raise();
        m_galCanvas->Refresh();
    }
    else
    {
        m_galCanvas->Hide();
        m_canvas->Show();
        m_canvas->Raise();
        m_canvas->Refresh();
    }

    m_galCanvasActive = aEnable;
}
+16 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <macros.h>
#include <id.h>
#include <class_drawpanel.h>
#include <class_drawpanel_gal.h>
#include <class_base_screen.h>
#include <wxstruct.h>

@@ -74,6 +75,9 @@ BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow )
    EVT_ERASE_BACKGROUND( EDA_DRAW_PANEL::OnEraseBackground )
    EVT_SCROLLWIN( EDA_DRAW_PANEL::OnScroll )
    EVT_ACTIVATE( EDA_DRAW_PANEL::OnActivate )
#ifdef KICAD_GAL
    EVT_SIZE( EDA_DRAW_PANEL::OnSize )
#endif
    EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, EDA_DRAW_PANEL::OnPan )
END_EVENT_TABLE()

@@ -1377,6 +1381,18 @@ void EDA_DRAW_PANEL::OnPan( wxCommandEvent& event )
}


#ifdef KICAD_GAL
void EDA_DRAW_PANEL::OnSize( wxSizeEvent& SizeEv )
{
    if( GetParent()->GetGalCanvas() != NULL )
    {
        GetParent()->GetGalCanvas()->SetPosition( GetPosition() );
        GetParent()->GetGalCanvas()->SetSize( GetSize() );
    }
}
#endif


void EDA_DRAW_PANEL::EndMouseCapture( int id, int cursor, const wxString& title,
                                      bool aCallEndFunc )
{
Loading