add option to switch between opengl and cairo in eeschema (step 1)

This commit is contained in:
jean-pierre charras 2018-09-10 15:37:28 +02:00 committed by Jeff Young
parent 42ee4f79e4
commit f283667fb0
16 changed files with 147 additions and 35 deletions

View File

@ -364,7 +364,7 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
break;
default:
assert( false );
wxASSERT( false );
// warn about unhandled GAL canvas type, but continue with the fallback option
case GAL_TYPE_NONE:
@ -387,7 +387,7 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
// from the defaults
m_options.NotifyChanged();
assert( new_gal );
wxASSERT( new_gal );
delete m_gal;
m_gal = new_gal;

View File

@ -351,7 +351,11 @@ void CAIRO_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aControl
void CAIRO_GAL::DrawBitmap( const BITMAP_BASE& aBitmap )
{
int ppi = aBitmap.GetPPI();
double worldIU_per_mm = 1/(worldUnitLength/2.54)/1000;
// We have to calculate the pixel size in users units to draw the image.
// worldUnitLength is the user unit in GAL unit value
// (GAL unit = 0.1 inch in nanometer = 2.54/1000 in mm).
// worldUnitLength * 1000 / 2.54 is the user unit in mm
double worldIU_per_mm = 1/( worldUnitLength / 0.00254 );
double pix_size_iu = worldIU_per_mm * ( 25.4 / ppi );
int w = aBitmap.GetSizePixels().x;
int h = aBitmap.GetSizePixels().y;

View File

@ -1003,8 +1003,15 @@ void OPENGL_GAL::DrawBitmap( const BITMAP_BASE& aBitmap )
{
int ppi = aBitmap.GetPPI();
double w = (double) aBitmap.GetSizePixels().x / (double) ppi / worldUnitLength * 10.0; // no idea where the factor 10 comes from...
double h = (double) aBitmap.GetSizePixels().y / (double) ppi / worldUnitLength * 10.0;
// We have to calculate the pixel size in users units to draw the image.
// worldUnitLength is the user unit in GAL unit value
// (GAL unit = 2.54/1e9 in meter).
// worldUnitLength * 1000 / 2.54 is the user unit in mm
double worldIU_per_mm = 1.0 / ( worldUnitLength / 0.00254 );
double pix_size_iu = worldIU_per_mm * ( 25.4 / ppi );
double w = (double) aBitmap.GetSizePixels().x * pix_size_iu;
double h = (double) aBitmap.GetSizePixels().y * pix_size_iu;
auto xform = currentManager->GetTransformation();

View File

@ -221,16 +221,13 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
m_FramePos.x = m_FramePos.y = 0;
m_FrameSize.y -= m_MsgFrameHeight;
printf("calling createCanvas\n");
createCanvas();
printf("Canvas %p\n", m_canvas);
m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
}
EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
{
delete m_socketServer;

View File

@ -242,6 +242,18 @@ static EDA_HOTKEY HkEditCut( _HKI( "Cut" ), HK_EDIT_CUT, GR_KB_CTRL + 'X', (int)
static EDA_HOTKEY HkEditCopy( _HKI( "Copy" ), HK_EDIT_COPY, GR_KB_CTRL + 'C', (int) wxID_COPY );
static EDA_HOTKEY HkEditPaste( _HKI( "Paste" ), HK_EDIT_PASTE, GR_KB_CTRL + 'V', (int) wxID_PASTE );
static EDA_HOTKEY HkCanvasOpenGL( _HKI( "Switch to Modern Toolset with hardware-accelerated graphics (recommended)" ),
HK_CANVAS_OPENGL,
#ifdef __WXMAC__
GR_KB_ALT +
#endif
WXK_F11, ID_MENU_CANVAS_OPENGL );
static EDA_HOTKEY HkCanvasCairo( _HKI( "Switch to Modern Toolset with software graphics (fall-back)" ),
HK_CANVAS_CAIRO,
#ifdef __WXMAC__
GR_KB_ALT +
#endif
WXK_F12, ID_MENU_CANVAS_CAIRO );
// List of common hotkey descriptors
static EDA_HOTKEY* common_Hotkey_List[] =
@ -320,6 +332,8 @@ static EDA_HOTKEY* schematic_Hotkey_List[] =
&HkLeaveSheet,
&HkDeleteNode,
&HkHighlightConnection,
&HkCanvasCairo,
&HkCanvasOpenGL,
NULL
};
@ -624,12 +638,15 @@ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
case HK_ROTATE: // Rotate schematic item.
case HK_EDIT_COMPONENT_WITH_LIBEDIT: // Call Libedit and load the current component
case HK_AUTOPLACE_FIELDS: // Autoplace all fields around component
case HK_CANVAS_CAIRO:
case HK_CANVAS_OPENGL:
{
// force a new item search on hot keys at current position,
// force a new item search on hot keys at current position,
// if there is no currently edited item,
// to avoid using a previously selected item
if( ! itemInEdit )
screen->SetCurItem( NULL );
EDA_HOTKEY_CLIENT_DATA data( aPosition );
cmd.SetInt( hotKey->m_Idcommand );
cmd.SetClientObject( &data );

View File

@ -79,7 +79,9 @@ enum hotkey_id_commnand {
HK_DELETE_NODE,
HK_AUTOPLACE_FIELDS,
HK_UPDATE_PCB_FROM_SCH,
HK_SELECT_ITEMS_ON_PCB
HK_SELECT_ITEMS_ON_PCB,
HK_CANVAS_OPENGL,
HK_CANVAS_CAIRO,
};
// List of hotkey descriptors for Eeschema

View File

@ -647,6 +647,20 @@ static void preparePreferencesMenu( SCH_EDIT_FRAME* aFrame, wxMenu* aParentMenu
aParentMenu->AppendSeparator();
wxString text = AddHotkeyName( _( "Modern Toolset (&Accelerated)" ), g_Eeschema_Hokeys_Descr,
HK_CANVAS_OPENGL );
AddMenuItem( aParentMenu, ID_MENU_CANVAS_OPENGL, text,
_( "Use Modern Toolset with hardware-accelerated graphics (recommended)" ),
KiBitmap( tools_xpm ), wxITEM_RADIO );
text = AddHotkeyName( _( "Modern Toolset (Fallba&ck)" ), g_Eeschema_Hokeys_Descr,
HK_CANVAS_CAIRO );
AddMenuItem( aParentMenu, ID_MENU_CANVAS_CAIRO, text,
_( "Use Modern Toolset with software graphics (fall-back)" ),
KiBitmap( tools_xpm ), wxITEM_RADIO );
aParentMenu->AppendSeparator();
// Import/export
AddMenuItem( aParentMenu, ID_CONFIG_SAVE, _( "&Save Project File..." ),
_( "Save project preferences into a project file" ),

View File

@ -143,7 +143,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
item = LocateAndShowItem( aPosition, SCH_COLLECTOR::AllItemsButPins, 0, &actionCancelled );
printf("Locateandshow %d %d item %p type %d\n", aPosition.x, aPosition.y,
item, item ? item->Type() : 0 ); fflush(0);
item, item ? item->Type() : 0 ); fflush(0);
// If the clarify item selection context menu is aborted, don't show the context menu.
if( item == NULL && actionCancelled )

View File

@ -91,6 +91,10 @@ SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent,
EDA_DRAW_FRAME( aKiway, aParent, aWindowType, aTitle, aPosition,
aSize, aStyle, aFrameName )
{
printf("calling createCanvas\n");
createCanvas();
printf("Canvas %p\n", m_canvas);
m_zoomLevelCoeff = 11.0; // Adjusted to roughly displays zoom level = 1
// when the screen shows a 1:1 image
// obviously depends on the monitor,
@ -100,12 +104,48 @@ SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent,
}
SCH_BASE_FRAME::~SCH_BASE_FRAME()
{
}
void SCH_BASE_FRAME::OnUpdateSwitchCanvas( wxUpdateUIEvent& aEvent )
{
wxMenuBar* menuBar = GetMenuBar();
EDA_DRAW_PANEL_GAL* gal_canvas = GetGalCanvas();
EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = gal_canvas->GetBackend();
struct { int menuId; int galType; } menuList[] =
{
{ ID_MENU_CANVAS_OPENGL, EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL },
{ ID_MENU_CANVAS_CAIRO, EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO },
};
for( auto ii: menuList )
{
wxMenuItem* item = menuBar->FindItem( ii.menuId );
if( ii.galType == canvasType )
{
item->Check( true );
}
}
}
void SCH_BASE_FRAME::OnSwitchCanvas( wxCommandEvent& aEvent )
{
auto new_type = EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL;
if( aEvent.GetId() == ID_MENU_CANVAS_CAIRO )
new_type = EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO;
if( m_canvasType == new_type )
return;
GetGalCanvas()->SwitchBackend( new_type );
}
void SCH_BASE_FRAME::OnOpenLibraryViewer( wxCommandEvent& event )
{
LIB_VIEW_FRAME* viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, true );
@ -554,11 +594,17 @@ bool SCH_BASE_FRAME::HandleBlockBegin( wxDC* aDC, EDA_KEY aKey, const wxPoint& a
return true;
}
void EDA_DRAW_FRAME::createCanvas()
void SCH_BASE_FRAME::createCanvas()
{
EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = LoadCanvasTypeSetting();
// Allows only a CAIRO or OPENGL canvas:
if( canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL &&
canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO )
canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL;
m_canvas = new SCH_DRAW_PANEL( this, wxID_ANY, wxPoint( 0, 0 ), m_FrameSize,
m_galDisplayOptions, EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
GetGalDisplayOptions(), canvasType );
m_useSingleCanvasPane = true;

View File

@ -102,11 +102,23 @@ public:
virtual ~SCH_BASE_FRAME();
void createCanvas();
SCH_DRAW_PANEL* GetCanvas() const override;
SCH_SCREEN* GetScreen() const override;
KIGFX::SCH_RENDER_SETTINGS* GetRenderSettings();
/**
* switches currently used canvas ( Cairo / OpenGL).
*/
void OnSwitchCanvas( wxCommandEvent& aEvent );
/**
* Update UI called when switches currently used canvas (Cairo / OpenGL).
*/
void OnUpdateSwitchCanvas( wxUpdateUIEvent& aEvent );
/**
* @return the increment value of the position of an item
* for the repeat command

View File

@ -60,6 +60,9 @@ BEGIN_EVENT_TABLE( SCH_DRAW_PANEL, wxScrolledWindow )
// EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, EDA_DRAW_PANEL::OnPan )
END_EVENT_TABLE()
// define our user unit value for GAL ( given in GAL unit = 2.54/(IU per meter))
// TODO: move in a header common to sch_preview_panel.cpp
#define IU_2_GAL_WORLD_UNIT 2.54/(IU_PER_MM*1000)
SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
const wxPoint& aPosition, const wxSize& aSize,
@ -74,16 +77,15 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
m_defaultCursor = m_currentCursor = wxCURSOR_ARROW;
m_showCrossHair = true;
#endif
m_view = new KIGFX::SCH_VIEW( true );
m_view->SetGAL( m_gal );
m_gal->SetWorldUnitLength( 0.01 ); // 1 unit = 0.01 inch
m_gal->SetWorldUnitLength( IU_2_GAL_WORLD_UNIT );
m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
m_view->SetPainter( m_painter.get() );
m_view->SetScaleLimits( 2000000.0, 0.002 );
m_view->SetScaleLimits( 2000.0, 0.002 );
m_view->SetMirror( false, false );
setDefaultLayerOrder();
@ -134,7 +136,7 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
m_doubleClickInterval = 250;
m_gal->SetGridColor( COLOR4D(0.0, 0.0, 0.0, 1.0) );
m_gal->SetGridColor( GetLayerColor( LAYER_SCHEMATIC_GRID ) );
m_gal->SetCursorColor( COLOR4D(0.0, 0.0, 0.0, 1.0) );
m_viewControls->SetSnapping( true );
@ -195,8 +197,12 @@ void SCH_DRAW_PANEL::setDefaultLayerOrder()
bool SCH_DRAW_PANEL::SwitchBackend( GAL_TYPE aGalType )
{
VECTOR2D grid_size = m_gal->GetGridSize();
bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
setDefaultLayerDeps();
m_gal->SetWorldUnitLength( IU_2_GAL_WORLD_UNIT );
m_gal->SetGridSize( grid_size );
m_gal->SetGridColor( GetLayerColor( LAYER_SCHEMATIC_GRID ) );
return rv;
}
@ -375,6 +381,7 @@ void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
if( event.MiddleIsDown() )
{
/* Not used in GAL canvas
wxPoint currentPosition = event.GetPosition();
double scale = GetParent()->GetScreen()->GetScalingFactor();
@ -384,6 +391,8 @@ void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
KiROUND( (double) ( m_PanStartEventPosition.y - currentPosition.y ) / scale );
GetParent()->RedrawScreen( wxPoint( x, y ), false );
*/
return;
}
// Calling the general function on mouse changes (and pseudo key commands)
@ -682,4 +691,3 @@ void SCH_DRAW_PANEL::onPaint( wxPaintEvent& aEvent )
EDA_DRAW_PANEL_GAL::onPaint( aEvent );
}

View File

@ -323,6 +323,9 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
SCH_EDIT_FRAME::Process_Special_Functions )
EVT_MENU( ID_POPUP_SCH_DISPLAYDOC_CMP, SCH_EDIT_FRAME::OnEditItem )
EVT_MENU( ID_MENU_CANVAS_CAIRO, SCH_EDIT_FRAME::OnSwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_OPENGL, SCH_EDIT_FRAME::OnSwitchCanvas )
// Tools and buttons options toolbar
EVT_TOOL( ID_TB_OPTIONS_HIDDEN_PINS, SCH_EDIT_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_BUS_WIRES_ORIENT, SCH_EDIT_FRAME::OnSelectOptionToolbar )
@ -350,6 +353,8 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_UPDATE_UI( ID_UPDATE_ONE_SHEET, SCH_EDIT_FRAME::OnUpdateSaveSheet )
EVT_UPDATE_UI( ID_POPUP_SCH_LEAVE_SHEET, SCH_EDIT_FRAME::OnUpdateHierarchySheet )
EVT_UPDATE_UI( ID_REMAP_SYMBOLS, SCH_EDIT_FRAME::OnUpdateRemapSymbols )
EVT_UPDATE_UI( ID_MENU_CANVAS_CAIRO, SCH_EDIT_FRAME::OnUpdateSwitchCanvas )
EVT_UPDATE_UI( ID_MENU_CANVAS_OPENGL, SCH_EDIT_FRAME::OnUpdateSwitchCanvas )
/* Search dialog events. */
EVT_FIND_CLOSE( wxID_ANY, SCH_EDIT_FRAME::OnFindDialogClose )

View File

@ -40,6 +40,9 @@
using namespace std::placeholders;
// define our user unit value for GAL ( given in GAL unit = 2.54/(IU per meter))
// TODO: move in a header common to sch_draw_panel.cpp
#define IU_2_GAL_WORLD_UNIT 2.54/(IU_PER_MM*1000)
SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
const wxPoint& aPosition, const wxSize& aSize,
@ -50,12 +53,12 @@ SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindo
m_view = new KIGFX::SCH_VIEW( true );
m_view->SetGAL( m_gal );
m_gal->SetWorldUnitLength( 0.01 ); // 1 unit = 0.01 inch
m_gal->SetWorldUnitLength( IU_2_GAL_WORLD_UNIT );
m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
m_view->SetPainter( m_painter.get() );
m_view->SetScaleLimits( 2000000.0, 0.002 );
m_view->SetScaleLimits( 20000.0, 0.002 );
m_view->SetMirror( false, false );
setDefaultLayerOrder();
@ -139,4 +142,3 @@ void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
if( IsShown() )
EDA_DRAW_PANEL_GAL::onPaint( aEvent );
}

View File

@ -162,7 +162,7 @@ public:
virtual void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector<MSG_PANEL_ITEM>& aList )
{
assert( false );
wxASSERT( false );
}
/**

View File

@ -78,10 +78,9 @@ class EDA_DRAW_FRAME : public KIWAY_PLAYER
///< GAL display options - this is the frame's interface to setting GAL display options
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions;
bool m_useSingleCanvasPane;
protected:
bool m_useSingleCanvasPane;
wxSocketServer* m_socketServer;
std::vector<wxSocketBase*> m_sockets; ///< interprocess communication
@ -218,8 +217,6 @@ protected:
///> Key in KifaceSettings to store the canvas type.
static const wxChar CANVAS_TYPE_KEY[];
void createCanvas();
public:
EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
FRAME_T aFrameType,

View File

@ -416,6 +416,7 @@ bool PCB_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
{
bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
setDefaultLayerDeps();
m_gal->SetWorldUnitLength( 2.54/(IU_PER_MM*1000) ); // world unit is in internal units per inch * 1000
return rv;
}