diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.cpp b/3d-viewer/3d_canvas/eda_3d_canvas.cpp index eb9f096427..e6bc655646 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.cpp +++ b/3d-viewer/3d_canvas/eda_3d_canvas.cpp @@ -45,6 +45,8 @@ #include #include +#include + /** * 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(); }; + + m_3d_render_raytracing->SetBusyIndicatorFactory( busy_indicator_factory ); + m_3d_render_ogl_legacy->SetBusyIndicatorFactory( busy_indicator_factory ); + RenderEngineChanged(); wxASSERT( aBoard != NULL ); diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp index dc9dd00824..6f427841c1 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp @@ -472,7 +472,7 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, if( m_reloadRequested ) { - wxBusyCursor dummy; + std::unique_ptr busy = CreateBusyIndicator(); if( aStatusTextReporter ) aStatusTextReporter->Report( _( "Loading..." ) ); diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp index b059cfeaf3..27b2ae4bca 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp +++ b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp @@ -166,7 +166,7 @@ bool C3D_RENDER_RAYTRACING::Redraw( bool aIsMoving, REPORTER *aStatusTextReporte initialize_block_positions(); } - wxBusyCursor dummy; + std::unique_ptr busy = CreateBusyIndicator(); // Reload board if it was requested // ///////////////////////////////////////////////////////////////////////// diff --git a/3d-viewer/3d_rendering/c3d_render_base.cpp b/3d-viewer/3d_rendering/c3d_render_base.cpp index fb2cdf4124..dc1f9edd21 100644 --- a/3d-viewer/3d_rendering/c3d_render_base.cpp +++ b/3d-viewer/3d_rendering/c3d_render_base.cpp @@ -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 C3D_RENDER_BASE::CreateBusyIndicator() const +{ + std::unique_ptr busy; + + if( m_busyIndicatorFactory ) + busy = m_busyIndicatorFactory(); + + return busy; +} diff --git a/3d-viewer/3d_rendering/c3d_render_base.h b/3d-viewer/3d_rendering/c3d_render_base.h index 8d1d9a1b37..fe2d6b6e48 100644 --- a/3d-viewer/3d_rendering/c3d_render_base.h +++ b/3d-viewer/3d_rendering/c3d_render_base.h @@ -35,6 +35,8 @@ #include "../3d_canvas/cinfo3d_visu.h" #include +#include + /** * 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 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 diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 5178d81401..5c15f9c554 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -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 ) diff --git a/common/widgets/wx_busy_indicator.cpp b/common/widgets/wx_busy_indicator.cpp new file mode 100644 index 0000000000..b7da24f761 --- /dev/null +++ b/common/widgets/wx_busy_indicator.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 + +#include + +#include + + +WX_BUSY_INDICATOR::WX_BUSY_INDICATOR() : m_cursor( std::make_unique() ) +{ +} \ No newline at end of file diff --git a/include/widgets/busy_indicator.h b/include/widgets/busy_indicator.h new file mode 100644 index 0000000000..997d43a211 --- /dev/null +++ b/include/widgets/busy_indicator.h @@ -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 +#include + +/** + * 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()>; + + /** + * This class is intended to be handled by pointer-to-base class + */ + virtual ~BUSY_INDICATOR() = default; +}; + +#endif // COMMON_WIDGETS_BUSY_INDICATOR__H \ No newline at end of file diff --git a/include/widgets/wx_busy_indicator.h b/include/widgets/wx_busy_indicator.h new file mode 100644 index 0000000000..dcc9fc3285 --- /dev/null +++ b/include/widgets/wx_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 + + +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 m_cursor; +}; + +#endif // COMMON_WIDGETS_WX_BUSY_INDICATOR__H \ No newline at end of file