3D viewer: decouple renderers from wxCursors
Provide a toolkit-agnostic interface for "busy indicators", which allows the 3D viewer to show a busy cursor, without the canvases having to to know how a wxCursore works. The motivation here is to decouple the 3D renderers from the WX GUI system, as they can then be used when when there is not an active window (e.g. for offscreen rendering). Otherwise, attempting to use a wxBusyCursor without a GUI available is an instant segfault.
This commit is contained in:
parent
f602ccd814
commit
18593d2dbb
|
@ -45,6 +45,8 @@
|
|||
#include <hotkeys_basic.h>
|
||||
#include <menus_helpers.h>
|
||||
|
||||
#include <widgets/wx_busy_indicator.h>
|
||||
|
||||
|
||||
/**
|
||||
* Flag to enable 3D canvas debug tracing.
|
||||
|
@ -141,6 +143,11 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow *aParent,
|
|||
wxASSERT( m_3d_render_raytracing != NULL );
|
||||
wxASSERT( m_3d_render_ogl_legacy != NULL );
|
||||
|
||||
auto busy_indicator_factory = []() { return std::make_unique<WX_BUSY_INDICATOR>(); };
|
||||
|
||||
m_3d_render_raytracing->SetBusyIndicatorFactory( busy_indicator_factory );
|
||||
m_3d_render_ogl_legacy->SetBusyIndicatorFactory( busy_indicator_factory );
|
||||
|
||||
RenderEngineChanged();
|
||||
|
||||
wxASSERT( aBoard != NULL );
|
||||
|
|
|
@ -472,7 +472,7 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving,
|
|||
|
||||
if( m_reloadRequested )
|
||||
{
|
||||
wxBusyCursor dummy;
|
||||
std::unique_ptr<BUSY_INDICATOR> busy = CreateBusyIndicator();
|
||||
|
||||
if( aStatusTextReporter )
|
||||
aStatusTextReporter->Report( _( "Loading..." ) );
|
||||
|
|
|
@ -166,7 +166,7 @@ bool C3D_RENDER_RAYTRACING::Redraw( bool aIsMoving, REPORTER *aStatusTextReporte
|
|||
initialize_block_positions();
|
||||
}
|
||||
|
||||
wxBusyCursor dummy;
|
||||
std::unique_ptr<BUSY_INDICATOR> busy = CreateBusyIndicator();
|
||||
|
||||
// Reload board if it was requested
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -54,3 +54,19 @@ C3D_RENDER_BASE::~C3D_RENDER_BASE()
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
void C3D_RENDER_BASE::SetBusyIndicatorFactory( BUSY_INDICATOR::FACTORY aNewFactory )
|
||||
{
|
||||
m_busyIndicatorFactory = aNewFactory;
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<BUSY_INDICATOR> C3D_RENDER_BASE::CreateBusyIndicator() const
|
||||
{
|
||||
std::unique_ptr<BUSY_INDICATOR> busy;
|
||||
|
||||
if( m_busyIndicatorFactory )
|
||||
busy = m_busyIndicatorFactory();
|
||||
|
||||
return busy;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include "../3d_canvas/cinfo3d_visu.h"
|
||||
#include <reporter.h>
|
||||
|
||||
#include <widgets/busy_indicator.h>
|
||||
|
||||
/**
|
||||
* This is a base class to hold data and functions for render targets.
|
||||
*/
|
||||
|
@ -86,9 +88,22 @@ public:
|
|||
*/
|
||||
virtual int GetWaitForEditingTimeOut() = 0;
|
||||
|
||||
/**
|
||||
* Set a new busy indicator factory.
|
||||
*
|
||||
* When set, this factory will be used to generate busy indicators when
|
||||
* suitable. If not set, no busy indicator will be used.
|
||||
*/
|
||||
void SetBusyIndicatorFactory( BUSY_INDICATOR::FACTORY aNewFactory );
|
||||
|
||||
// Attributes
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Return a created busy indicator, if a factory has been set, else
|
||||
* a null pointer.
|
||||
*/
|
||||
std::unique_ptr<BUSY_INDICATOR> CreateBusyIndicator() const;
|
||||
|
||||
/// settings refrence in use for this render
|
||||
CINFO3D_VISU &m_settings;
|
||||
|
@ -109,6 +124,10 @@ protected:
|
|||
* more information.
|
||||
*/
|
||||
static const wxChar *m_logTrace;
|
||||
|
||||
private:
|
||||
/// Factory that returns a suitable busy indicator for the context.
|
||||
BUSY_INDICATOR::FACTORY m_busyIndicatorFactory;
|
||||
};
|
||||
|
||||
#endif // C3D_RENDER_BASE_H
|
||||
|
|
|
@ -232,6 +232,7 @@ set( COMMON_WIDGET_SRCS
|
|||
widgets/unit_binder.cpp
|
||||
widgets/widget_save_restore.cpp
|
||||
widgets/widget_hotkey_list.cpp
|
||||
widgets/wx_busy_indicator.cpp
|
||||
widgets/wx_grid.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
|
||||
*
|
||||
* 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 <widgets/wx_busy_indicator.h>
|
||||
|
||||
#include <make_unique.h>
|
||||
|
||||
#include <wx/cursor.h>
|
||||
|
||||
|
||||
WX_BUSY_INDICATOR::WX_BUSY_INDICATOR() : m_cursor( std::make_unique<wxBusyCursor>() )
|
||||
{
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef COMMON_WIDGETS_BUSY_INDICATOR__H
|
||||
#define COMMON_WIDGETS_BUSY_INDICATOR__H
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* A class that can be used to implement a "busy" indicator. The exact form
|
||||
* of the busy indicator is unspecified. It could be a "spinner" cursor in a GUI
|
||||
* context, for example.
|
||||
*
|
||||
* This base class provides a "null" implementation, and can be overriden for
|
||||
* specific behaviours.
|
||||
*
|
||||
* THe busy-ness semantics are defined by this object's lifetime.
|
||||
*/
|
||||
class BUSY_INDICATOR
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* A factory function that returns a new busy indicator.
|
||||
*
|
||||
* Because BUSY_INDICATORs are RAII objects (i.e. the busy-ness is defined
|
||||
* by the object's lieftime), it's convenient to pass a factory function for
|
||||
* a client to be able to make a busy indicator when needed.
|
||||
*/
|
||||
using FACTORY = std::function<std::unique_ptr<BUSY_INDICATOR>()>;
|
||||
|
||||
/**
|
||||
* This class is intended to be handled by pointer-to-base class
|
||||
*/
|
||||
virtual ~BUSY_INDICATOR() = default;
|
||||
};
|
||||
|
||||
#endif // COMMON_WIDGETS_BUSY_INDICATOR__H
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef COMMON_WIDGETS_WX_BUSY_INDICATOR__H
|
||||
#define COMMON_WIDGETS_WX_BUSY_INDICATOR__H
|
||||
|
||||
#include <widgets/busy_indicator.h>
|
||||
|
||||
|
||||
class wxBusyCursor;
|
||||
|
||||
|
||||
/**
|
||||
* Simple wrapper around wxBusyCursor for used with the generic BUSY_INDICATOR
|
||||
* interface. Can be used to provide a WX busy cursor (spinner) to generic code
|
||||
* that otherwise has no concept of wx cursors.
|
||||
*/
|
||||
class WX_BUSY_INDICATOR : public BUSY_INDICATOR
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructs a busy indicator represented by a wxBusyCursor, which will be
|
||||
* active as long as this object exists (just like wxBustCursor itself).
|
||||
*/
|
||||
WX_BUSY_INDICATOR();
|
||||
|
||||
private:
|
||||
///> This is the actual WX cursor that is the indicator.
|
||||
std::unique_ptr<wxBusyCursor> m_cursor;
|
||||
};
|
||||
|
||||
#endif // COMMON_WIDGETS_WX_BUSY_INDICATOR__H
|
Loading…
Reference in New Issue