From 38b805260f177429b4dfec7ba525065e741740a8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 2 Apr 2018 22:22:40 -0500 Subject: [PATCH 001/305] Add tests to check if apply_config invaldiates existing steps for perimeter count and infill. --- t/config.t | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/t/config.t b/t/config.t index 829ef5f39..d36912301 100644 --- a/t/config.t +++ b/t/config.t @@ -1,4 +1,4 @@ -use Test::More tests => 1; +use Test::More tests => 4; use strict; use warnings; @@ -15,6 +15,22 @@ use Slic3r::Test; my $config = Slic3r::Config->new_from_defaults; $config->set('perimeter_extrusion_width', '250%'); ok $config->validate, 'percent extrusion width is validated'; + + my $print = Slic3r::Test::init_print('20mm_cube', config => $config, scale => 2); + { + my $invalid = $print->apply_config($config); + ok !($invalid), 're-applying same config does not invalidate'; + } + $config->set('perimeters', 20); + { + my $invalid = $print->apply_config($config); + ok $invalid, 're-applying with changed perimeters does invalidate previous config'; + } + $config->set('fill_density', '75%'); + { + my $invalid = $print->apply_config($config); + ok $invalid, 're-applying with changed fill_density does invalidate previous config'; + } } __END__ From 3dfe61de4823f78ccade383529706bdcdf9bc097 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 08:07:32 -0500 Subject: [PATCH 002/305] experiment to stub out C++ only GUI --- src/CMakeLists.txt | 58 ++++++++++++++++------------ src/GUI/GUI.cpp | 22 +++++++++++ src/GUI/GUI.hpp | 10 +++++ src/GUI/MainFrame.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++ src/GUI/MainFrame.hpp | 31 +++++++++++++++ src/slic3r.cpp | 6 +++ 6 files changed, 193 insertions(+), 24 deletions(-) create mode 100644 src/GUI/GUI.cpp create mode 100644 src/GUI/GUI.hpp create mode 100644 src/GUI/MainFrame.cpp create mode 100644 src/GUI/MainFrame.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fb34b5ae8..0bdf4397a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 2.8) +cmake_minimum_required (VERSION 3.10) project (slic3r) # only on newer GCCs: -ftemplate-backtrace-limit=0 @@ -17,14 +17,17 @@ IF(CMAKE_HOST_APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE") set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework CoreFoundation -lc++") ELSE(CMAKE_HOST_APPLE) - set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") +# set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -L.") ENDIF(CMAKE_HOST_APPLE) -set(Boost_USE_STATIC_LIBS ON) -set(Boost_USE_STATIC_RUNTIME ON) -set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_STATIC_RUNTIME OFF) +find_package(Threads REQUIRED) + find_package(Boost COMPONENTS system thread filesystem) set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/../xs/src/) +set(GUI_LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/GUI/) include_directories(${LIBDIR}) include_directories(${LIBDIR}/libslic3r) @@ -53,6 +56,7 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/Fill/FillHoneycomb.cpp ${LIBDIR}/libslic3r/Fill/FillPlanePath.cpp ${LIBDIR}/libslic3r/Fill/FillRectilinear.cpp + ${LIBDIR}/libslic3r/Fill/FillGyroid.cpp ${LIBDIR}/libslic3r/Flow.cpp ${LIBDIR}/libslic3r/GCode.cpp ${LIBDIR}/libslic3r/GCode/CoolingBuffer.cpp @@ -122,29 +126,29 @@ add_library(poly2tri STATIC ) add_executable(slic3r slic3r.cpp) -set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1) -set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1) +#set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1) +#set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1) -add_executable(extrude-tin utils/extrude-tin.cpp) -set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_START_STATIC 1) -set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_END_STATIC 1) +#add_executable(extrude-tin utils/extrude-tin.cpp) +#set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_START_STATIC 1) +#set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_END_STATIC 1) -set(wxWidgets_USE_STATIC) -SET(wxWidgets_USE_LIBS) +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_STATIC_RUNTIME OFF) -set(Boost_USE_STATIC_LIBS ON) -set(Boost_USE_STATIC_RUNTIME ON) -set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") find_library(bsystem_l boost_system) -add_library(bsystem STATIC IMPORTED) +add_library(bsystem SHARED IMPORTED) set_target_properties(bsystem PROPERTIES IMPORTED_LOCATION ${bsystem_l}) find_library(bthread_l boost_thread) -add_library(bthread STATIC IMPORTED) +add_library(bthread SHARED IMPORTED) set_target_properties(bthread PROPERTIES IMPORTED_LOCATION ${bthread_l}) include_directories(${Boost_INCLUDE_DIRS}) -#find_package(wxWidgets) -#disable wx for the time being - we're not building any of the gui yet +set(wxWidgets_USE_STATIC OFF) +set(wxWidgets_USE_UNICODE ON) + +find_package(wxWidgets COMPONENTS base aui core) + IF(CMAKE_HOST_UNIX) #set(Boost_LIBRARIES bsystem bthread bfilesystem) ENDIF(CMAKE_HOST_UNIX) @@ -154,9 +158,15 @@ target_link_libraries (slic3r libslic3r admesh BSpline clipper expat polypartiti IF(wxWidgets_FOUND) MESSAGE("wx found!") INCLUDE("${wxWidgets_USE_FILE}") - add_library(slic3r_gui STATIC ${LIBDIR}/slic3r/GUI/3DScene.cpp ${LIBDIR}/slic3r/GUI/GUI.cpp) + include_directories(${GUI_LIBDIR}) + include_directories(${wxWidgets_INCLUDE}) + + add_library(slic3r_gui STATIC + ${GUI_LIBDIR}/MainFrame.cpp + ${GUI_LIBDIR}/GUI.cpp + ) #only build GUI lib if building with wx - target_link_libraries (slic3r slic3r-gui ${wxWidgets_LIBRARIES}) + target_link_libraries (slic3r slic3r_gui ${wxWidgets_LIBRARIES}) ELSE(wxWidgets_FOUND) # For convenience. When we cannot continue, inform the user MESSAGE("wx not found!") @@ -169,8 +179,8 @@ IF (WIN32) ${LIBDIR}/boost/nowide/iostream.cpp ) - target_link_libraries(slic3r boost-nowide) - target_link_libraries(extrude-tin boost-nowide) + target_link_libraries(slic3r STATIC boost-nowide) +# target_link_libraries(extrude-tin boost-nowide) ENDIF(WIN32) -target_link_libraries (extrude-tin libslic3r admesh BSpline clipper expat polypartition poly2tri ${Boost_LIBRARIES}) +#target_link_libraries (extrude-tin libslic3r admesh BSpline clipper expat polypartition poly2tri ${Boost_LIBRARIES}) diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp new file mode 100644 index 000000000..3c669754f --- /dev/null +++ b/src/GUI/GUI.cpp @@ -0,0 +1,22 @@ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "MainFrame.hpp" +#include "GUI.hpp" +//using namespace Slic3r; + + +enum +{ + ID_Hello = 1 +}; +bool Slic3rGUI::OnInit() +{ + MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize); + + frame->Show( true ); + return true; +} + diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp new file mode 100644 index 000000000..d287c9a9b --- /dev/null +++ b/src/GUI/GUI.hpp @@ -0,0 +1,10 @@ +#ifndef GUI_HPP +#define GUI_HPP +#include "MainFrame.hpp" +class Slic3rGUI: public wxApp +{ +public: + virtual bool OnInit(); +}; + +#endif // GUI_HPP diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp new file mode 100644 index 000000000..d21d2767e --- /dev/null +++ b/src/GUI/MainFrame.cpp @@ -0,0 +1,90 @@ +#include "MainFrame.hpp" + +wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) +wxEND_EVENT_TABLE() + +MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) + : wxFrame(NULL, wxID_ANY, title, pos, size), loaded(false), + tabpanel(NULL) +{ + // Set icon to either the .ico if windows or png for everything else. + + this->init_tabpanel(); + this->init_menubar(); + + wxToolTip::SetAutoPop(TOOLTIP_TIMER); + + // STUB: Initialize status bar with text. + /* # initialize status bar + $self->{statusbar} = Slic3r::GUI::ProgressStatusBar->new($self, -1); + $self->{statusbar}->SetStatusText("Version $Slic3r::VERSION - Remember to check for updates at http://slic3r.org/"); + $self->SetStatusBar($self->{statusbar}); */ + + this->loaded = 1; + + // Initialize layout + { + wxSizer* sizer = new wxBoxSizer(wxVERTICAL); + sizer->Add(this->tabpanel, 1, wxEXPAND); + sizer->SetSizeHints(this); + this->Fit(); + this->SetMinSize(wxSize(760, 490)); + this->SetSize(this->GetMinSize()); + wxTheApp->SetTopWindow(this); + this->Show(); + this->Layout(); + } + +} + +/// Private initialization function for the main frame tab panel. +void MainFrame::init_tabpanel() +{ + this->tabpanel = new wxAuiNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP); + auto panel = this->tabpanel; + + panel->Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, ([=](wxAuiNotebookEvent& e) + { + auto panel = this->tabpanel->GetPage(this->tabpanel->GetSelection()); + if panel->can('OnActivate') panel->OnActivate(); + }), panel->GetId()); + +// this->plater = Slic3r::GUI::Plater(panel, _("Plater")); +// this->controller = Slic3r::GUI::Controller(panel, _("Controller")); + +/* +sub _init_tabpanel { + my ($self) = @_; + + $self->{tabpanel} = my $panel = Wx::AuiNotebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP); + EVT_AUINOTEBOOK_PAGE_CHANGED($self, $self->{tabpanel}, sub { + my $panel = $self->{tabpanel}->GetPage($self->{tabpanel}->GetSelection); + $panel->OnActivate if $panel->can('OnActivate'); + if ($self->{tabpanel}->GetSelection > 1) { + $self->{tabpanel}->SetWindowStyle($self->{tabpanel}->GetWindowStyleFlag | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); + } elsif(($Slic3r::GUI::Settings->{_}{show_host} == 0) && ($self->{tabpanel}->GetSelection == 1)){ + $self->{tabpanel}->SetWindowStyle($self->{tabpanel}->GetWindowStyleFlag | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); + } else { + $self->{tabpanel}->SetWindowStyle($self->{tabpanel}->GetWindowStyleFlag & ~wxAUI_NB_CLOSE_ON_ACTIVE_TAB); + } + }); + EVT_AUINOTEBOOK_PAGE_CLOSE($self, $self->{tabpanel}, sub { + my $panel = $self->{tabpanel}->GetPage($self->{tabpanel}->GetSelection); + if ($panel->isa('Slic3r::GUI::PresetEditor')) { + delete $self->{preset_editor_tabs}{$panel->name}; + } + wxTheApp->CallAfter(sub { + $self->{tabpanel}->SetSelection(0); + }); + }); + + $panel->AddPage($self->{plater} = Slic3r::GUI::Plater->new($panel), "Plater"); + $panel->AddPage($self->{controller} = Slic3r::GUI::Controller->new($panel), "Controller") + if ($Slic3r::GUI::Settings->{_}{show_host}); +*/ + +} + +void MainFrame::init_menubar() +{ +} diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp new file mode 100644 index 000000000..a1b32feb8 --- /dev/null +++ b/src/GUI/MainFrame.hpp @@ -0,0 +1,31 @@ + +#ifndef MAINFRAME_HPP +#define MAINFRAME_HPP +#include +#ifndef WX_PRECOMP + #include +#endif +#include +#include + +constexpr unsigned int TOOLTIP_TIMER = 32767; + +class MainFrame: public wxFrame +{ +public: + MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size); +private: + wxDECLARE_EVENT_TABLE(); + + void init_menubar(); //< Routine to intialize all top-level menu items. + void init_tabpanel(); //< Routine to initialize all of the tabs. + + bool loaded; //< Main frame itself has finished loading. + // STUB: preset editor tabs storage + // STUB: Statusbar reference + + wxAuiNotebook* tabpanel; + +}; + +#endif // MAINFRAME_HPP diff --git a/src/slic3r.cpp b/src/slic3r.cpp index bf2fb2be7..558d3f810 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -13,6 +13,7 @@ #include #include #include +#include "GUI/GUI.hpp" using namespace Slic3r; @@ -39,6 +40,11 @@ main(int argc, char **argv) cli_config.apply(config, true); DynamicPrintConfig print_config; + + Slic3rGUI *gui = new Slic3rGUI; + + Slic3rGUI::SetInstance(gui); + wxEntry(argc, argv); // load config files supplied via --load for (const std::string &file : cli_config.load.values) { From a06755c3dd27d345faf308ba79aed53d039ff77b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 16:05:47 -0500 Subject: [PATCH 003/305] Exercise build environment. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 864d76b3c..4f2b0580b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ branches: only: - master - xsgui + - cppgui cache: apt: true directories: From b04d58ecef7d6afe3cd6947b846ca6eb96708277 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 17:21:18 -0500 Subject: [PATCH 004/305] Stubbing out more of the UI. --- src/GUI/Controller.hpp | 15 +++++++++++++++ src/GUI/GUI.cpp | 7 ++++--- src/GUI/GUI.hpp | 7 ++++++- src/GUI/MainFrame.cpp | 24 ++++++++++++++++++++---- src/GUI/MainFrame.hpp | 15 +++++++++++++++ src/GUI/Plater.hpp | 17 +++++++++++++++++ src/GUI/Settings.hpp | 15 +++++++++++++++ src/slic3r.cpp | 6 ++++-- 8 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 src/GUI/Controller.hpp create mode 100644 src/GUI/Plater.hpp create mode 100644 src/GUI/Settings.hpp diff --git a/src/GUI/Controller.hpp b/src/GUI/Controller.hpp new file mode 100644 index 000000000..ef3650886 --- /dev/null +++ b/src/GUI/Controller.hpp @@ -0,0 +1,15 @@ +#ifndef CONTROLLER_UI_HPP +#define CONTROLLER_UI_HPP + +namespace Slic3r { namespace GUI { + +class Controller : public wxPanel { +public: + Controller(wxWindow* parent, const wxString& title) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title) + { } +}; + +}} // Namespace Slic3r::GUI + +#endif // CONTROLLER_UI_HPP diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index 3c669754f..7c249b3b0 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -5,18 +5,19 @@ #include "MainFrame.hpp" #include "GUI.hpp" -//using namespace Slic3r; +namespace Slic3r { namespace GUI { enum { ID_Hello = 1 }; -bool Slic3rGUI::OnInit() +bool App::OnInit() { - MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize); + MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize, this->gui_config); frame->Show( true ); return true; } +}} // namespace Slic3r::GUI diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index d287c9a9b..1339d1d34 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -1,10 +1,15 @@ #ifndef GUI_HPP #define GUI_HPP #include "MainFrame.hpp" -class Slic3rGUI: public wxApp + +namespace Slic3r { namespace GUI { +class App: public wxApp { + std::shared_ptr gui_config; // GUI-specific configuration options public: virtual bool OnInit(); + App(std::shared_ptr config) : wxApp(), gui_config(config) {} }; +}} // namespace Slic3r::GUI #endif // GUI_HPP diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index d21d2767e..c3684c27b 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -1,11 +1,17 @@ #include "MainFrame.hpp" +#include "Plater.hpp" +#include "Controller.hpp" + +namespace Slic3r { namespace GUI { wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) wxEND_EVENT_TABLE() MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) + : MainFrame(title, pos, size, nullptr) {} +MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr config) : wxFrame(NULL, wxID_ANY, title, pos, size), loaded(false), - tabpanel(NULL) + tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(config) { // Set icon to either the .ico if windows or png for everything else. @@ -46,11 +52,19 @@ void MainFrame::init_tabpanel() panel->Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, ([=](wxAuiNotebookEvent& e) { auto panel = this->tabpanel->GetPage(this->tabpanel->GetSelection()); - if panel->can('OnActivate') panel->OnActivate(); + auto tabpanel = this->tabpanel; + // todo: trigger processing for activation(?) + if (tabpanel->GetSelection() > 1) { + tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); + } else if (this->gui_config->show_host == false && tabpanel->GetSelection() == 1) { + tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); + } else { + tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | ~wxAUI_NB_CLOSE_ON_ACTIVE_TAB); + } }), panel->GetId()); -// this->plater = Slic3r::GUI::Plater(panel, _("Plater")); -// this->controller = Slic3r::GUI::Controller(panel, _("Controller")); + this->plater = new Slic3r::GUI::Plater(panel, _("Plater")); + this->controller = new Slic3r::GUI::Controller(panel, _("Controller")); /* sub _init_tabpanel { @@ -88,3 +102,5 @@ sub _init_tabpanel { void MainFrame::init_menubar() { } + +}} // Namespace Slic3r::GUI diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index a1b32feb8..8631ac78a 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -8,12 +8,21 @@ #include #include +#include + +#include "Controller.hpp" +#include "Plater.hpp" +#include "Settings.hpp" + +namespace Slic3r { namespace GUI { + constexpr unsigned int TOOLTIP_TIMER = 32767; class MainFrame: public wxFrame { public: MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size); + MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr gui_config); private: wxDECLARE_EVENT_TABLE(); @@ -25,7 +34,13 @@ private: // STUB: Statusbar reference wxAuiNotebook* tabpanel; + Controller* controller; + Plater* plater; + + + std::shared_ptr gui_config; }; +}} // Namespace Slic3r::GUI #endif // MAINFRAME_HPP diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp new file mode 100644 index 000000000..bf7aa917a --- /dev/null +++ b/src/GUI/Plater.hpp @@ -0,0 +1,17 @@ +#ifndef PLATER_HPP +#define PLATER_HPP + +namespace Slic3r { namespace GUI { + +class Plater : public wxPanel +{ +public: + Plater(wxWindow* parent, const wxString& title) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title) + { } + +}; + +} } // Namespace Slic3r::GUI + +#endif // PLATER_HPP diff --git a/src/GUI/Settings.hpp b/src/GUI/Settings.hpp new file mode 100644 index 000000000..07e219406 --- /dev/null +++ b/src/GUI/Settings.hpp @@ -0,0 +1,15 @@ +#ifndef SETTINGS_HPP +#define SETTINGS_HPP +namespace Slic3r { namespace GUI { + +/// Stub class to hold onto GUI-specific settings options. +/// TODO: Incorporate a copy of Slic3r::Config +class Settings { + public: + bool show_host; + Settings(): show_host(false) {} //< Show host/controller tab +}; + +}} //namespace Slic3r::GUI + +#endif // SETTINGS_HPP diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 558d3f810..9dc862400 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -41,9 +41,11 @@ main(int argc, char **argv) DynamicPrintConfig print_config; - Slic3rGUI *gui = new Slic3rGUI; + std::shared_ptr gui_config = std::make_shared(); - Slic3rGUI::SetInstance(gui); + GUI::App *gui = new GUI::App(gui_config); + + GUI::App::SetInstance(gui); wxEntry(argc, argv); // load config files supplied via --load From 17daf0d908e3993b14bc34fee412191046b7d692 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 17:32:40 -0500 Subject: [PATCH 005/305] Try to get travis to build cppgui instead. --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4f2b0580b..a0f8c92c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,8 @@ install: script: - bash package/linux/travis-setup.sh - perlbrew switch slic3r-perl -- perl ./Build.PL +- cmake src/ +- make -j4 after_success: - eval $(perl -Mlocal::lib=$TRAVIS_BUILD_DIR/local-lib) - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 @@ -37,6 +38,10 @@ addons: - libgtk2.0-0 - libgtk2.0-dev - freeglut3 + - cmake + - wx3.0-headers + - libwxgtk3.0-dev + - wx-common ssh_known_hosts: dl.slic3r.org notifications: irc: From 19bc2eabdcc5c4bee704a0073f5d5e40b68171a6 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 20:17:04 -0500 Subject: [PATCH 006/305] Tab panel initializes. --- src/GUI/MainFrame.cpp | 78 +++++++++++++++++++++------------------- src/GUI/MainFrame.hpp | 4 +++ src/GUI/PresetEditor.hpp | 11 ++++++ src/slic3r.cpp | 2 ++ 4 files changed, 58 insertions(+), 37 deletions(-) create mode 100644 src/GUI/PresetEditor.hpp diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index c3684c27b..8c2575cf8 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -1,6 +1,4 @@ #include "MainFrame.hpp" -#include "Plater.hpp" -#include "Controller.hpp" namespace Slic3r { namespace GUI { @@ -11,7 +9,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si : MainFrame(title, pos, size, nullptr) {} MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr config) : wxFrame(NULL, wxID_ANY, title, pos, size), loaded(false), - tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(config) + tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(config), preset_editor_tabs(std::map()) { // Set icon to either the .ico if windows or png for everything else. @@ -40,7 +38,34 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si this->Show(); this->Layout(); } - +/* + # declare events + EVT_CLOSE($self, sub { + my (undef, $event) = @_; + + if ($event->CanVeto) { + if (!$self->{plater}->prompt_unsaved_changes) { + $event->Veto; + return; + } + + if ($self->{controller} && $self->{controller}->printing) { + my $confirm = Wx::MessageDialog->new($self, "You are currently printing. Do you want to stop printing and continue anyway?", + 'Unfinished Print', wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT); + if ($confirm->ShowModal == wxID_NO) { + $event->Veto; + return; + } + } + } + + # save window size + wxTheApp->save_window_pos($self, "main_frame"); + + # propagate event + $event->Skip; + }); +*/ } /// Private initialization function for the main frame tab panel. @@ -51,9 +76,8 @@ void MainFrame::init_tabpanel() panel->Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, ([=](wxAuiNotebookEvent& e) { - auto panel = this->tabpanel->GetPage(this->tabpanel->GetSelection()); auto tabpanel = this->tabpanel; - // todo: trigger processing for activation(?) + // TODO: trigger processing for activation event if (tabpanel->GetSelection() > 1) { tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); } else if (this->gui_config->show_host == false && tabpanel->GetSelection() == 1) { @@ -63,40 +87,20 @@ void MainFrame::init_tabpanel() } }), panel->GetId()); + panel->Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, ([=](wxAuiNotebookEvent& e) + { + if (typeid(panel) == typeid(Slic3r::GUI::PresetEditor)) { + wxDELETE(this->preset_editor_tabs[panel->GetId()]); + } + wxTheApp->CallAfter([=] { this->tabpanel->SetSelection(0); }); + }), panel->GetId()); + this->plater = new Slic3r::GUI::Plater(panel, _("Plater")); this->controller = new Slic3r::GUI::Controller(panel, _("Controller")); - -/* -sub _init_tabpanel { - my ($self) = @_; - - $self->{tabpanel} = my $panel = Wx::AuiNotebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP); - EVT_AUINOTEBOOK_PAGE_CHANGED($self, $self->{tabpanel}, sub { - my $panel = $self->{tabpanel}->GetPage($self->{tabpanel}->GetSelection); - $panel->OnActivate if $panel->can('OnActivate'); - if ($self->{tabpanel}->GetSelection > 1) { - $self->{tabpanel}->SetWindowStyle($self->{tabpanel}->GetWindowStyleFlag | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); - } elsif(($Slic3r::GUI::Settings->{_}{show_host} == 0) && ($self->{tabpanel}->GetSelection == 1)){ - $self->{tabpanel}->SetWindowStyle($self->{tabpanel}->GetWindowStyleFlag | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); - } else { - $self->{tabpanel}->SetWindowStyle($self->{tabpanel}->GetWindowStyleFlag & ~wxAUI_NB_CLOSE_ON_ACTIVE_TAB); - } - }); - EVT_AUINOTEBOOK_PAGE_CLOSE($self, $self->{tabpanel}, sub { - my $panel = $self->{tabpanel}->GetPage($self->{tabpanel}->GetSelection); - if ($panel->isa('Slic3r::GUI::PresetEditor')) { - delete $self->{preset_editor_tabs}{$panel->name}; - } - wxTheApp->CallAfter(sub { - $self->{tabpanel}->SetSelection(0); - }); - }); - - $panel->AddPage($self->{plater} = Slic3r::GUI::Plater->new($panel), "Plater"); - $panel->AddPage($self->{controller} = Slic3r::GUI::Controller->new($panel), "Controller") - if ($Slic3r::GUI::Settings->{_}{show_host}); -*/ + panel->AddPage(this->plater, this->plater->GetName()); + if (this->gui_config->show_host) panel->AddPage(this->controller, this->controller->GetName()); + } void MainFrame::init_menubar() diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index 8631ac78a..76a2146eb 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -9,9 +9,12 @@ #include #include +#include + #include "Controller.hpp" #include "Plater.hpp" +#include "PresetEditor.hpp" #include "Settings.hpp" namespace Slic3r { namespace GUI { @@ -39,6 +42,7 @@ private: std::shared_ptr gui_config; + std::map preset_editor_tabs; }; diff --git a/src/GUI/PresetEditor.hpp b/src/GUI/PresetEditor.hpp new file mode 100644 index 000000000..8d6359eab --- /dev/null +++ b/src/GUI/PresetEditor.hpp @@ -0,0 +1,11 @@ +#ifndef PRESETEDITOR_HPP +#define PRESETEDITOR_HPP + +namespace Slic3r { namespace GUI { + +class PresetEditor : public wxPanel { + +}; + +}} // namespace Slic3r::GUI +#endif // PRESETEDITOR_HPP diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 9dc862400..82a04a1f1 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -44,6 +44,8 @@ main(int argc, char **argv) std::shared_ptr gui_config = std::make_shared(); GUI::App *gui = new GUI::App(gui_config); + + gui_config->show_host = true; GUI::App::SetInstance(gui); wxEntry(argc, argv); From 1d4b369e733689c871a0e4f5b509c642151f8ef3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 20:19:31 -0500 Subject: [PATCH 007/305] Relaxed cmake version. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0bdf4397a..30ba81484 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.10) +cmake_minimum_required (VERSION 3.9) project (slic3r) # only on newer GCCs: -ftemplate-backtrace-limit=0 From 7d9079ef62c8c1a347039d3e4a4ab28bb4a888fd Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 20:27:24 -0500 Subject: [PATCH 008/305] set cc to gcc not g++ --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e04403854..dae9f3102 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ install: - export BOOST_DIR=$HOME/boost_1_63_0 - export SLIC3R_STATIC=1 - export CXX=g++-4.9 -- export CC=g++-4.9 +- export CC=gcc-4.9 - source $HOME/perl5/perlbrew/etc/bashrc script: - bash package/linux/travis-setup.sh From 221432d2eadea311d8f4cc22cf17a455308ce28e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 22:46:26 -0500 Subject: [PATCH 009/305] stub out more menus --- src/GUI/GUI.cpp | 3 +++ src/GUI/GUI.hpp | 15 +++++++++++- src/GUI/MainFrame.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++ src/GUI/MainFrame.hpp | 12 ++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index 7c249b3b0..b2a1e280b 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -17,6 +17,9 @@ bool App::OnInit() MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize, this->gui_config); frame->Show( true ); + + this->SetAppName("Slic3r"); + return true; } diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index 1339d1d34..d4ee0461b 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -3,12 +3,25 @@ #include "MainFrame.hpp" namespace Slic3r { namespace GUI { + +enum class PresetID { + PRINT = 0, + FILAMENT = 1, + PRINTER = 2 +}; + class App: public wxApp { - std::shared_ptr gui_config; // GUI-specific configuration options public: virtual bool OnInit(); App(std::shared_ptr config) : wxApp(), gui_config(config) {} + + void check_version(bool manual) { /* stub */} + +private: + std::shared_ptr gui_config; // GUI-specific configuration options + Notifier* notifier; + }; }} // namespace Slic3r::GUI diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 8c2575cf8..56afce0dd 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -1,4 +1,6 @@ #include "MainFrame.hpp" +#include +#include namespace Slic3r { namespace GUI { @@ -105,6 +107,59 @@ void MainFrame::init_tabpanel() void MainFrame::init_menubar() { + + wxMenu* menuFile = new wxMenu(); + { + } + + wxMenu* menuPlater = new wxMenu(); + { + } + wxMenu* menuObject = new wxMenu(); + { + } + wxMenu* menuSettings = new wxMenu(); + { + } + wxMenu* menuView = new wxMenu(); + { + } + wxMenu* menuWindow = new wxMenu(); + { + } + wxMenu* menuHelp = new wxMenu(); + { + // TODO: Reimplement config wizard + //menuHelp->AppendSeparator(); + append_menu_item(menuHelp, _("Slic3r &Website"), _("Open the Slic3r website in your browser"), [=](wxCommandEvent& e) + { + wxLaunchDefaultBrowser("http://www.slic3r.org"); + }); + append_menu_item(menuHelp, _("Check for &Updates..."), _("Check for new Slic3r versions"), [=](wxCommandEvent& e) + { +// parent->check_version(true); + }); + append_menu_item(menuHelp, _("Slic3r &Manual"), _("Open the Slic3r manual in your browser"), [=](wxCommandEvent& e) + { + wxLaunchDefaultBrowser("http://manual.slic3r.org/"); + }); + append_menu_item(menuHelp, _("&About Slic3r"), _("Show about dialog"), [=](wxCommandEvent& e) + { + }, wxID_ABOUT); + + } + + wxMenuBar* menubar = new wxMenuBar(); + menubar->Append(menuFile, _("&File")); + menubar->Append(menuPlater, _("&Plater")); + menubar->Append(menuObject, _("&Object")); + menubar->Append(menuSettings, _("&Settings")); + menubar->Append(menuView, _("&View")); + menubar->Append(menuWindow, _("&Window")); + menubar->Append(menuHelp, _("&Help")); + + this->SetMenuBar(menubar); + } }} // Namespace Slic3r::GUI diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index 76a2146eb..e4014a27c 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -16,9 +16,21 @@ #include "Plater.hpp" #include "PresetEditor.hpp" #include "Settings.hpp" +#include "GUI.hpp" namespace Slic3r { namespace GUI { +template +void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxBitmap& icon = wxBitmap(), const wxString& accel = "") { + wxMenuItem* tmp = menu->Append(wxID_ANY, name, help); + wxAcceleratorEntry* a = new wxAcceleratorEntry(); + if (a->FromString(accel)) + tmp->SetAccel(a); // set the accelerator if and only if the accelerator is fine + tmp->SetHelp(help); + + menu->Bind(wxEVT_MENU, lambda, tmp->GetId(), tmp->GetId()); +} + constexpr unsigned int TOOLTIP_TIMER = 32767; class MainFrame: public wxFrame From 7211acc32df098b24365ea8b44b40c5287010865 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 23:00:53 -0500 Subject: [PATCH 010/305] stubbed Notifier class and misc helper function --- src/CMakeLists.txt | 1 + src/GUI/GUI.hpp | 1 + src/GUI/MainFrame.cpp | 3 ++- src/GUI/Notifier.hpp | 15 +++++++++++++++ src/GUI/misc_ui.cpp | 15 +++++++++++++++ src/GUI/misc_ui.hpp | 15 +++++++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/GUI/Notifier.hpp create mode 100644 src/GUI/misc_ui.cpp create mode 100644 src/GUI/misc_ui.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30ba81484..bd8f28ffb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -164,6 +164,7 @@ IF(wxWidgets_FOUND) add_library(slic3r_gui STATIC ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/GUI.cpp + ${GUI_LIBDIR}/misc_ui.cpp ) #only build GUI lib if building with wx target_link_libraries (slic3r slic3r_gui ${wxWidgets_LIBRARIES}) diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index d4ee0461b..c693e847b 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -1,6 +1,7 @@ #ifndef GUI_HPP #define GUI_HPP #include "MainFrame.hpp" +#include "Notifier.hpp" namespace Slic3r { namespace GUI { diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 56afce0dd..547c0757b 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -1,4 +1,5 @@ #include "MainFrame.hpp" +#include "misc_ui.hpp" #include #include @@ -137,7 +138,7 @@ void MainFrame::init_menubar() }); append_menu_item(menuHelp, _("Check for &Updates..."), _("Check for new Slic3r versions"), [=](wxCommandEvent& e) { -// parent->check_version(true); + check_version(true); }); append_menu_item(menuHelp, _("Slic3r &Manual"), _("Open the Slic3r manual in your browser"), [=](wxCommandEvent& e) { diff --git a/src/GUI/Notifier.hpp b/src/GUI/Notifier.hpp new file mode 100644 index 000000000..f7a9c0d92 --- /dev/null +++ b/src/GUI/Notifier.hpp @@ -0,0 +1,15 @@ +#ifndef NOTIFIER_HPP +#define NOTIFIER_HPP + +namespace Slic3r { namespace GUI { + +/// Class to perform window manager notifications using Growl and/or DBus XWindow + +class Notifier { +public: + Notifier() { } +}; + +}} // Namespace Slic3r::GUI + +#endif // NOTIFIER_HPP diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp new file mode 100644 index 000000000..b509cf097 --- /dev/null +++ b/src/GUI/misc_ui.cpp @@ -0,0 +1,15 @@ +#include "misc_ui.hpp" +namespace Slic3r { namespace GUI { + + +#ifdef SLIC3R_DEV +void check_version(bool manual) { +} +#else +void check_version(bool manual) { +} + +#endif + +}} // namespace Slic3r::GUI + diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp new file mode 100644 index 000000000..83ef2646c --- /dev/null +++ b/src/GUI/misc_ui.hpp @@ -0,0 +1,15 @@ +#ifndef MISC_UI_HPP +#define MISC_UI_HPP + +/// Common static (that is, free-standing) functions, not part of an object hierarchy. + +namespace Slic3r { namespace GUI { + +/// Performs a check via the Internet for a new version of Slic3r. +/// If this version of Slic3r was compiled with SLIC3R_DEV, check the development +/// space instead of release. +void check_version(bool manual = false); + +}} // namespace Slic3r::GUI + +#endif // MISC_UI_HPP From 137716b8a36c2c46fd8dd06dc5aa010f81a57623 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 23:52:13 -0500 Subject: [PATCH 011/305] added misc utility functions for the UI, including functions to get user home (for slic3r directory) and path to var. --- src/GUI/GUI.hpp | 5 ++++- src/GUI/MainFrame.cpp | 5 +++++ src/GUI/misc_ui.cpp | 15 +++++++++++++++ src/GUI/misc_ui.hpp | 31 ++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index c693e847b..e6c89b90f 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -2,14 +2,17 @@ #define GUI_HPP #include "MainFrame.hpp" #include "Notifier.hpp" +#include namespace Slic3r { namespace GUI { +// Friendly indices for the preset lists. enum class PresetID { PRINT = 0, FILAMENT = 1, PRINTER = 2 }; +using preset_list = std::vector; class App: public wxApp { @@ -22,7 +25,7 @@ public: private: std::shared_ptr gui_config; // GUI-specific configuration options Notifier* notifier; - + std::vector presets { preset_list(), preset_list(), preset_list() }; }; }} // namespace Slic3r::GUI diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 547c0757b..f006423b1 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -15,6 +15,11 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(config), preset_editor_tabs(std::map()) { // Set icon to either the .ico if windows or png for everything else. + if (the_os == OS::Windows) + this->SetIcon(wxIcon(var("Slic3r.ico"), wxBITMAP_TYPE_ICO)); + else + this->SetIcon(wxIcon(var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG)); + this->init_tabpanel(); this->init_menubar(); diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index b509cf097..278f6e4d7 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -11,5 +11,20 @@ void check_version(bool manual) { #endif +const wxString var(const wxString& in) { + wxFileName f(wxStandardPaths::Get().GetExecutablePath()); + wxString appPath(f.GetPath()); + + // replace center string with path to VAR in actual distribution later + return appPath + "/../var/" + in; +} + +/// Returns the path to Slic3r's default user data directory. +const wxString home(const wxString& in) { + if (the_os == OS::Windows) + return wxGetHomeDir() + "/" + in + "/"; + return wxGetHomeDir() + "/." + in + "/"; +} + }} // namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index 83ef2646c..cc92e5a03 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -1,15 +1,44 @@ #ifndef MISC_UI_HPP #define MISC_UI_HPP +#include +#ifndef WX_PRECOMP + #include +#endif + +#include +#include + /// Common static (that is, free-standing) functions, not part of an object hierarchy. namespace Slic3r { namespace GUI { +enum class OS { Linux, Mac, Windows } ; +// constants to reduce the proliferation of macros in the rest of the code +#ifdef __WIN32 +constexpr OS the_os = OS::Windows; +#elif __APPLE__ +constexpr OS the_os = OS::Mac; +#elif __linux__ +constexpr OS the_os = OS::Linux; +#endif + +#ifdef SLIC3R_DEV +constexpr bool isDev = true; +#else +constexpr bool isDev = false; +#endif + /// Performs a check via the Internet for a new version of Slic3r. -/// If this version of Slic3r was compiled with SLIC3R_DEV, check the development +/// If this version of Slic3r was compiled with -DSLIC3R_DEV, check the development /// space instead of release. void check_version(bool manual = false); +const wxString var(const wxString& in); + +/// Always returns path to home directory. +const wxString home(const wxString& in = "Slic3r"); + }} // namespace Slic3r::GUI #endif // MISC_UI_HPP From 0682c75541d2b484dd3cfcbc4c9640e3bab192cc Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 24 Apr 2018 23:56:09 -0500 Subject: [PATCH 012/305] point cmake to boost_root --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dae9f3102..7c46228f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,10 @@ install: script: - bash package/linux/travis-setup.sh - perlbrew switch slic3r-perl -- cmake src/ +- cmake -DBOOST_ROOT=$BOOST_DIR src/ +- cd src - make -j4 +- cd .. after_success: - eval $(perl -Mlocal::lib=$TRAVIS_BUILD_DIR/local-lib) - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 From 9eefa5708934a439cd46c2bffa1c5c7a65fb701c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 25 Apr 2018 00:10:15 -0500 Subject: [PATCH 013/305] Less magic --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c46228f4..54876ed57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,7 @@ script: - bash package/linux/travis-setup.sh - perlbrew switch slic3r-perl - cmake -DBOOST_ROOT=$BOOST_DIR src/ -- cd src - make -j4 -- cd .. after_success: - eval $(perl -Mlocal::lib=$TRAVIS_BUILD_DIR/local-lib) - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 From cb5456f528a6de03e6382138a15ee32a0899e2a9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 25 Apr 2018 00:20:02 -0500 Subject: [PATCH 014/305] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 54876ed57..738368ffc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ script: - bash package/linux/travis-setup.sh - perlbrew switch slic3r-perl - cmake -DBOOST_ROOT=$BOOST_DIR src/ -- make -j4 +- make after_success: - eval $(perl -Mlocal::lib=$TRAVIS_BUILD_DIR/local-lib) - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 From a677002886ee7dea234381c43ef277ca6b61d86e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 25 Apr 2018 00:30:47 -0500 Subject: [PATCH 015/305] Update GUI.hpp --- src/GUI/GUI.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index e6c89b90f..82d6de746 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -3,6 +3,7 @@ #include "MainFrame.hpp" #include "Notifier.hpp" #include +#include namespace Slic3r { namespace GUI { From 5fc089ef993cea0da56c674b8770c2739088f320 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 26 Apr 2018 21:43:00 -0500 Subject: [PATCH 016/305] Stub out more of the interface, working our way out from GUI::App::OnInit() --- src/CMakeLists.txt | 3 +- src/GUI/GUI.cpp | 137 +++++++++++++++++++++++++++++++++++++++++- src/GUI/GUI.hpp | 15 ++++- src/GUI/MainFrame.hpp | 9 --- src/GUI/Preset.hpp | 17 ++++++ src/GUI/Settings.cpp | 15 +++++ src/GUI/Settings.hpp | 49 ++++++++++++++- src/GUI/misc_ui.cpp | 59 ++++++++++++++++++ src/GUI/misc_ui.hpp | 25 ++++++++ 9 files changed, 312 insertions(+), 17 deletions(-) create mode 100644 src/GUI/Preset.hpp create mode 100644 src/GUI/Settings.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd8f28ffb..15382d8b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -136,7 +136,7 @@ add_executable(slic3r slic3r.cpp) set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_STATIC_RUNTIME OFF) -find_library(bsystem_l boost_system) +find_library(bsystem_l boost_system log) add_library(bsystem SHARED IMPORTED) set_target_properties(bsystem PROPERTIES IMPORTED_LOCATION ${bsystem_l}) find_library(bthread_l boost_thread) @@ -164,6 +164,7 @@ IF(wxWidgets_FOUND) add_library(slic3r_gui STATIC ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/GUI.cpp + ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp ) #only build GUI lib if building with wx diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index b2a1e280b..67d5485c1 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -2,9 +2,13 @@ #ifndef WX_PRECOMP #include #endif +#include + #include "MainFrame.hpp" #include "GUI.hpp" +#include "misc_ui.hpp" +#include "Preset.hpp" namespace Slic3r { namespace GUI { @@ -14,13 +18,142 @@ enum }; bool App::OnInit() { - MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize, this->gui_config); - frame->Show( true ); this->SetAppName("Slic3r"); + // TODO: Call a logging function with channel GUI, severity info + + this->notifier = std::unique_ptr(); + + wxString datadir {decode_path(wxStandardPaths::Get().GetUserDataDir())}; + wxString enc_datadir = encode_path(datadir); + std::cerr << datadir << "\n"; + + // TODO: Call a logging function with channel GUI, severity info for datadir path + + /* Check to make sure if datadir exists + * + */ + + // Load settings + this->gui_config->save_settings(); + this->load_presets(); + + + wxImage::AddHandler(new wxPNGHandler()); + MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize, this->gui_config); + this->SetTopWindow(frame); + frame->Show( true ); + + // Load init bundle + // + + // Run the wizard if we don't have an initial config + /* + $self->check_version + if $self->have_version_check + && ($Settings->{_}{version_check} // 1) + && (!$Settings->{_}{last_version_check} || (time - $Settings->{_}{last_version_check}) >= 86400); + */ + + // run callback functions during idle + /* + EVT_IDLE($frame, sub { + while (my $cb = shift @cb) { + $cb->(); + } + }); + */ + + // Handle custom version check event + /* + EVT_COMMAND($self, -1, $VERSION_CHECK_EVENT, sub { + my ($self, $event) = @_; + my ($success, $response, $manual_check) = @{$event->GetData}; + + if ($success) { + if ($response =~ /^obsolete ?= ?([a-z0-9.-]+,)*\Q$Slic3r::VERSION\E(?:,|$)/) { + my $res = Wx::MessageDialog->new(undef, "A new version is available. Do you want to open the Slic3r website now?", + 'Update', wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_INFORMATION | wxICON_ERROR)->ShowModal; + Wx::LaunchDefaultBrowser('http://slic3r.org/') if $res == wxID_YES; + } else { + Slic3r::GUI::show_info(undef, "You're using the latest version. No updates are available.") if $manual_check; + } + $Settings->{_}{last_version_check} = time(); + $self->save_settings; + } else { + Slic3r::GUI::show_error(undef, "Failed to check for updates. Try later.") if $manual_check; + } + }); + */ return true; } +void App::save_window_pos(const wxTopLevelWindow* window, const wxString& name ) { + this->gui_config->window_pos[name] = + std::make_tuple( + window->GetScreenPosition(), + window->GetSize(), + window->IsMaximized()); + + this->gui_config->save_settings(); +} + +void App::restore_window_pos(wxTopLevelWindow* window, const wxString& name ) { + try { + auto tmp = gui_config->window_pos[name]; + const auto& size = std::get<1>(tmp); + const auto& pos = std::get<0>(tmp); + window->SetSize(size); + + auto display = wxDisplay().GetClientArea(); + if (((pos.x + size.x / 2) < display.GetRight()) && (pos.y + size.y/2 < display.GetBottom())) + window->Move(pos); + + window->Maximize(std::get<2>(tmp)); + } + catch (std::out_of_range e) { + // config was empty + } +} + +void App::load_presets() { +/* + for my $group (qw(printer filament print)) { + my $presets = $self->{presets}{$group}; + + # keep external or dirty presets + @$presets = grep { ($_->external && $_->file_exists) || $_->dirty } @$presets; + + my $dir = "$Slic3r::GUI::datadir/$group"; + opendir my $dh, Slic3r::encode_path($dir) + or die "Failed to read directory $dir (errno: $!)\n"; + foreach my $file (grep /\.ini$/i, readdir $dh) { + $file = Slic3r::decode_path($file); + my $name = basename($file); + $name =~ s/\.ini$//i; + + # skip if we already have it + next if any { $_->name eq $name } @$presets; + + push @$presets, Slic3r::GUI::Preset->new( + group => $group, + name => $name, + file => "$dir/$file", + ); + } + closedir $dh; + + @$presets = sort { $a->name cmp $b->name } @$presets; + + unshift @$presets, Slic3r::GUI::Preset->new( + group => $group, + default => 1, + name => '- default -', + ); + } +*/ +} + }} // namespace Slic3r::GUI diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index 82d6de746..219970806 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -1,9 +1,11 @@ #ifndef GUI_HPP #define GUI_HPP +#include #include "MainFrame.hpp" #include "Notifier.hpp" #include -#include +#include + namespace Slic3r { namespace GUI { @@ -21,12 +23,19 @@ public: virtual bool OnInit(); App(std::shared_ptr config) : wxApp(), gui_config(config) {} - void check_version(bool manual) { /* stub */} + /// Save position, size, and maximize state for a TopLevelWindow (includes Frames) by name in Settings. + void save_window_pos(const wxTopLevelWindow* window, const wxString& name ); + + /// Move/resize a named TopLevelWindow (includes Frames) from Settings + void restore_window_pos(wxTopLevelWindow* window, const wxString& name ); private: std::shared_ptr gui_config; // GUI-specific configuration options - Notifier* notifier; + std::unique_ptr notifier {nullptr}; std::vector presets { preset_list(), preset_list(), preset_list() }; + + void load_presets(); + }; }} // namespace Slic3r::GUI diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index e4014a27c..085cc3922 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -20,16 +20,7 @@ namespace Slic3r { namespace GUI { -template -void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxBitmap& icon = wxBitmap(), const wxString& accel = "") { - wxMenuItem* tmp = menu->Append(wxID_ANY, name, help); - wxAcceleratorEntry* a = new wxAcceleratorEntry(); - if (a->FromString(accel)) - tmp->SetAccel(a); // set the accelerator if and only if the accelerator is fine - tmp->SetHelp(help); - menu->Bind(wxEVT_MENU, lambda, tmp->GetId(), tmp->GetId()); -} constexpr unsigned int TOOLTIP_TIMER = 32767; diff --git a/src/GUI/Preset.hpp b/src/GUI/Preset.hpp new file mode 100644 index 000000000..e169c4827 --- /dev/null +++ b/src/GUI/Preset.hpp @@ -0,0 +1,17 @@ +#ifndef PRESET_HPP +#define PRESET_HPP + +#include "PrintConfig.hpp" + +namespace Slic3r { namespace GUI { + +class Preset { + +private: + Slic3r::DynamicPrintConfig config { Slic3r::DynamicPrintConfig() }; + +}; + +}} // namespace Slic3r::GUI + +#endif // PRESET_HPP diff --git a/src/GUI/Settings.cpp b/src/GUI/Settings.cpp new file mode 100644 index 000000000..8affa6886 --- /dev/null +++ b/src/GUI/Settings.cpp @@ -0,0 +1,15 @@ +#include "Settings.hpp" + +namespace Slic3r { namespace GUI { + +void Settings::save_settings() { +/* +sub save_settings { + my ($self) = @_; + Slic3r::Config->write_ini("$datadir/slic3r.ini", $Settings); +} + +*/ +} + +}} // namespace Slic3r::GUI diff --git a/src/GUI/Settings.hpp b/src/GUI/Settings.hpp index 07e219406..9c135cec3 100644 --- a/src/GUI/Settings.hpp +++ b/src/GUI/Settings.hpp @@ -1,13 +1,58 @@ #ifndef SETTINGS_HPP #define SETTINGS_HPP + +#include +#ifndef WX_PRECOMP + #include +#endif +#include +#include + +#include "libslic3r.h" + namespace Slic3r { namespace GUI { +enum class PathColor { + role +}; + +enum class ColorScheme { + solarized, slic3r +}; + +enum class ReloadBehavior { + all, copy, discard +}; + /// Stub class to hold onto GUI-specific settings options. /// TODO: Incorporate a copy of Slic3r::Config class Settings { public: - bool show_host; - Settings(): show_host(false) {} //< Show host/controller tab + bool show_host {false}; + bool version_check {true}; + bool autocenter {true}; + bool autoalignz {true}; + bool invert_zoom {false}; + bool background_processing {false}; + + bool preset_editor_tabs {false}; + + bool hide_reload_dialog {false}; + + ReloadBehavior reload {ReloadBehavior::all}; + ColorScheme color {ColorScheme::slic3r}; + PathColor color_toolpaths_by {PathColor::role}; + + float nudge {1.0}; //< 2D plater nudge amount in mm + + unsigned int threads {1}; //< Number of threads to use when slicing + + const wxString version { wxString(SLIC3R_VERSION) }; + + void save_settings(); + + /// Storage for window positions + std::map > window_pos { std::map >() }; }; }} //namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index 278f6e4d7..ef00fa2d3 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -1,4 +1,6 @@ #include "misc_ui.hpp" +#include + namespace Slic3r { namespace GUI { @@ -26,5 +28,62 @@ const wxString home(const wxString& in) { return wxGetHomeDir() + "/." + in + "/"; } + +wxString decode_path(const wxString& in) { + // TODO Stub + return in; +} + +wxString encode_path(const wxString& in) { + // TODO Stub + return in; +} +/* +sub append_submenu { + my ($self, $menu, $string, $description, $submenu, $id, $icon) = @_; + + $id //= &Wx::NewId(); + my $item = Wx::MenuItem->new($menu, $id, $string, $description // ''); + $self->set_menu_item_icon($item, $icon); + $item->SetSubMenu($submenu); + $menu->Append($item); + + return $item; +} +*/ + +/* +sub scan_serial_ports { + my ($self) = @_; + + my @ports = (); + + if ($^O eq 'MSWin32') { + # Windows + if (eval "use Win32::TieRegistry; 1") { + my $ts = Win32::TieRegistry->new("HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM", + { Access => 'KEY_READ' }); + if ($ts) { + # when no serial ports are available, the registry key doesn't exist and + # TieRegistry->new returns undef + $ts->Tie(\my %reg); + push @ports, sort values %reg; + } + } + } else { + # UNIX and OS X + push @ports, glob '/dev/{ttyUSB,ttyACM,tty.,cu.,rfcomm}*'; + } + + return grep !/Bluetooth|FireFly/, @ports; +} +*/ +/* +sub show_error { + my ($parent, $message) = @_; + Wx::MessageDialog->new($parent, $message, 'Error', wxOK | wxICON_ERROR)->ShowModal; +} +*/ + }} // namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index cc92e5a03..5276a3f8c 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -39,6 +39,31 @@ const wxString var(const wxString& in); /// Always returns path to home directory. const wxString home(const wxString& in = "Slic3r"); +template +void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxString& icon = "", const wxString& accel = "") { + wxMenuItem* tmp = menu->Append(wxID_ANY, name, help); + wxAcceleratorEntry* a = new wxAcceleratorEntry(); + if (!accel.IsEmpty()) { + a->FromString(accel); + tmp->SetAccel(a); // set the accelerator if and only if the accelerator is fine + } + tmp->SetHelp(help); + if (!icon.IsEmpty()) + tmp->SetBitmap(wxBitmap(var(icon))); + + menu->Bind(wxEVT_MENU, lambda, tmp->GetId(), tmp->GetId()); +} + +/* +sub CallAfter { + my ($self, $cb) = @_; + push @cb, $cb; +} +*/ + +wxString decode_path(const wxString& in); +wxString encode_path(const wxString& in); + }} // namespace Slic3r::GUI #endif // MISC_UI_HPP From 2ec07cb93c6336cb1e6a1af29c94ca5e1abffe78 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 12:32:54 -0500 Subject: [PATCH 017/305] Added CATCH v2.2.2 header --- src/test/catch.hpp | 13050 ++++++++++++++++ .../libslic3r/{Config.cpp => ConfigBase.cpp} | 0 .../libslic3r/{Config.hpp => ConfigBase.hpp} | 0 3 files changed, 13050 insertions(+) create mode 100644 src/test/catch.hpp rename xs/src/libslic3r/{Config.cpp => ConfigBase.cpp} (100%) rename xs/src/libslic3r/{Config.hpp => ConfigBase.hpp} (100%) diff --git a/src/test/catch.hpp b/src/test/catch.hpp new file mode 100644 index 000000000..ecd8907ea --- /dev/null +++ b/src/test/catch.hpp @@ -0,0 +1,13050 @@ +/* + * Catch v2.2.2 + * Generated: 2018-04-06 12:05:03.186665 + * ---------------------------------------------------------- + * This file has been merged from multiple headers. Please don't edit it directly + * Copyright (c) 2018 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +// start catch.hpp + + +#define CATCH_VERSION_MAJOR 2 +#define CATCH_VERSION_MINOR 2 +#define CATCH_VERSION_PATCH 2 + +#ifdef __clang__ +# pragma clang system_header +#elif defined __GNUC__ +# pragma GCC system_header +#endif + +// start catch_suppress_warnings.h + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(push) +# pragma warning(disable: 161 1682) +# else // __ICC +# pragma clang diagnostic ignored "-Wunused-variable" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +# pragma clang diagnostic ignored "-Wswitch-enum" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +# endif +#elif defined __GNUC__ +# pragma GCC diagnostic ignored "-Wparentheses" +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Wpadded" +#endif +// end catch_suppress_warnings.h +#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) +# define CATCH_IMPL +# define CATCH_CONFIG_ALL_PARTS +#endif + +// In the impl file, we want to have access to all parts of the headers +// Can also be used to sanely support PCHs +#if defined(CATCH_CONFIG_ALL_PARTS) +# define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) +// start catch_platform.h + +#ifdef __APPLE__ +# include +# if TARGET_OS_OSX == 1 +# define CATCH_PLATFORM_MAC +# elif TARGET_OS_IPHONE == 1 +# define CATCH_PLATFORM_IPHONE +# endif + +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX + +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) +# define CATCH_PLATFORM_WINDOWS +#endif + +// end catch_platform.h + +#ifdef CATCH_IMPL +# ifndef CLARA_CONFIG_MAIN +# define CLARA_CONFIG_MAIN_NOT_DEFINED +# define CLARA_CONFIG_MAIN +# endif +#endif + +// start catch_user_interfaces.h + +namespace Catch { + unsigned int rngSeed(); +} + +// end catch_user_interfaces.h +// start catch_tag_alias_autoregistrar.h + +// start catch_common.h + +// start catch_compiler_capabilities.h + +// Detect a number of compiler features - by compiler +// The following features are defined: +// +// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? +// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? +// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// **************** +// Note to maintainers: if new toggles are added please document them +// in configuration.md, too +// **************** + +// In general each macro has a _NO_ form +// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. +// Many features, at point of detection, define an _INTERNAL_ macro, so they +// can be combined, en-mass, with the _NO_ forms later. + +#ifdef __cplusplus + +# if __cplusplus >= 201402L +# define CATCH_CPP14_OR_GREATER +# endif + +# if __cplusplus >= 201703L +# define CATCH_CPP17_OR_GREATER +# endif + +#endif + +#if defined(CATCH_CPP17_OR_GREATER) +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#endif + +#ifdef __clang__ + +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic push" ) \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") +# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic pop" ) + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic push" ) \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) +# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic pop" ) + +#endif // __clang__ + +//////////////////////////////////////////////////////////////////////////////// +// Assume that non-Windows platforms support posix signals by default +#if !defined(CATCH_PLATFORM_WINDOWS) + #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS +#endif + +//////////////////////////////////////////////////////////////////////////////// +// We know some environments not to support full POSIX signals +#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) + #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +#endif + +#ifdef __OS400__ +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +# define CATCH_CONFIG_COLOUR_NONE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Cygwin +#ifdef __CYGWIN__ + +// Required for some versions of Cygwin to declare gettimeofday +// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin +# define _BSD_SOURCE + +#endif // __CYGWIN__ + +//////////////////////////////////////////////////////////////////////////////// +// Visual C++ +#ifdef _MSC_VER + +# if _MSC_VER >= 1900 // Visual Studio 2015 or newer +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +# endif + +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif + +#endif // _MSC_VER + +//////////////////////////////////////////////////////////////////////////////// + +// DJGPP +#ifdef __DJGPP__ +# define CATCH_INTERNAL_CONFIG_NO_WCHAR +#endif // __DJGPP__ + +//////////////////////////////////////////////////////////////////////////////// + +// Use of __COUNTER__ is suppressed during code analysis in +// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly +// handled by it. +// Otherwise all supported compilers support COUNTER macro, +// but user still might want to turn it off +#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) + #define CATCH_INTERNAL_CONFIG_COUNTER +#endif + +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif +// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. +#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) +# define CATCH_CONFIG_WCHAR +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) +# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#endif + +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS +# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS +#endif + +// end catch_compiler_capabilities.h +#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line +#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) +#ifdef CATCH_CONFIG_COUNTER +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) +#else +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#endif + +#include +#include +#include + +namespace Catch { + + struct CaseSensitive { enum Choice { + Yes, + No + }; }; + + class NonCopyable { + NonCopyable( NonCopyable const& ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable& operator = ( NonCopyable const& ) = delete; + NonCopyable& operator = ( NonCopyable && ) = delete; + + protected: + NonCopyable(); + virtual ~NonCopyable(); + }; + + struct SourceLineInfo { + + SourceLineInfo() = delete; + SourceLineInfo( char const* _file, std::size_t _line ) noexcept + : file( _file ), + line( _line ) + {} + + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo( SourceLineInfo && ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo& operator = ( SourceLineInfo && ) = default; + + bool empty() const noexcept; + bool operator == ( SourceLineInfo const& other ) const noexcept; + bool operator < ( SourceLineInfo const& other ) const noexcept; + + char const* file; + std::size_t line; + }; + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); + + // Use this in variadic streaming macros to allow + // >> +StreamEndStop + // as well as + // >> stuff +StreamEndStop + struct StreamEndStop { + std::string operator+() const; + }; + template + T const& operator + ( T const& value, StreamEndStop ) { + return value; + } +} + +#define CATCH_INTERNAL_LINEINFO \ + ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) + +// end catch_common.h +namespace Catch { + + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); + }; + +} // end namespace Catch + +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS + +// end catch_tag_alias_autoregistrar.h +// start catch_test_registry.h + +// start catch_interfaces_testcase.h + +#include +#include + +namespace Catch { + + class TestSpec; + + struct ITestInvoker { + virtual void invoke () const = 0; + virtual ~ITestInvoker(); + }; + + using ITestCasePtr = std::shared_ptr; + + class TestCase; + struct IConfig; + + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; + }; + + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + +} + +// end catch_interfaces_testcase.h +// start catch_stringref.h + +#include +#include +#include + +namespace Catch { + + class StringData; + + /// A non-owning string class (similar to the forthcoming std::string_view) + /// Note that, because a StringRef may be a substring of another string, + /// it may not be null terminated. c_str() must return a null terminated + /// string, however, and so the StringRef will internally take ownership + /// (taking a copy), if necessary. In theory this ownership is not externally + /// visible - but it does mean (substring) StringRefs should not be shared between + /// threads. + class StringRef { + public: + using size_type = std::size_t; + + private: + friend struct StringRefTestAccess; + + char const* m_start; + size_type m_size; + + char* m_data = nullptr; + + void takeOwnership(); + + static constexpr char const* const s_empty = ""; + + public: // construction/ assignment + StringRef() noexcept + : StringRef( s_empty, 0 ) + {} + + StringRef( StringRef const& other ) noexcept + : m_start( other.m_start ), + m_size( other.m_size ) + {} + + StringRef( StringRef&& other ) noexcept + : m_start( other.m_start ), + m_size( other.m_size ), + m_data( other.m_data ) + { + other.m_data = nullptr; + } + + StringRef( char const* rawChars ) noexcept; + + StringRef( char const* rawChars, size_type size ) noexcept + : m_start( rawChars ), + m_size( size ) + {} + + StringRef( std::string const& stdString ) noexcept + : m_start( stdString.c_str() ), + m_size( stdString.size() ) + {} + + ~StringRef() noexcept { + delete[] m_data; + } + + auto operator = ( StringRef const &other ) noexcept -> StringRef& { + delete[] m_data; + m_data = nullptr; + m_start = other.m_start; + m_size = other.m_size; + return *this; + } + + operator std::string() const; + + void swap( StringRef& other ) noexcept; + + public: // operators + auto operator == ( StringRef const& other ) const noexcept -> bool; + auto operator != ( StringRef const& other ) const noexcept -> bool; + + auto operator[] ( size_type index ) const noexcept -> char; + + public: // named queries + auto empty() const noexcept -> bool { + return m_size == 0; + } + auto size() const noexcept -> size_type { + return m_size; + } + + auto numberOfCharacters() const noexcept -> size_type; + auto c_str() const -> char const*; + + public: // substrings and searches + auto substr( size_type start, size_type size ) const noexcept -> StringRef; + + // Returns the current start pointer. + // Note that the pointer can change when if the StringRef is a substring + auto currentData() const noexcept -> char const*; + + private: // ownership queries - may not be consistent between calls + auto isOwned() const noexcept -> bool; + auto isSubstring() const noexcept -> bool; + }; + + auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string; + auto operator + ( StringRef const& lhs, char const* rhs ) -> std::string; + auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string; + + auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; + + inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + return StringRef( rawChars, size ); + } + +} // namespace Catch + +// end catch_stringref.h +namespace Catch { + +template +class TestInvokerAsMethod : public ITestInvoker { + void (C::*m_testAsMethod)(); +public: + TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {} + + void invoke() const override { + C obj; + (obj.*m_testAsMethod)(); + } +}; + +auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*; + +template +auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* { + return new(std::nothrow) TestInvokerAsMethod( testAsMethod ); +} + +struct NameAndTags { + NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept; + StringRef name; + StringRef tags; +}; + +struct AutoReg : NonCopyable { + AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept; + ~AutoReg(); +}; + +} // end namespace Catch + +#if defined(CATCH_CONFIG_DISABLE) + #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \ + static void TestName() + #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \ + namespace{ \ + struct TestName : ClassName { \ + void test(); \ + }; \ + } \ + void TestName::test() + +#endif + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \ + static void TestName(); \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ + static void TestName() + #define INTERNAL_CATCH_TESTCASE( ... ) \ + INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ \ + struct TestName : ClassName{ \ + void test(); \ + }; \ + Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ + } \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ + void TestName::test() + #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ + INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS + +// end catch_test_registry.h +// start catch_capture.hpp + +// start catch_assertionhandler.h + +// start catch_assertioninfo.h + +// start catch_result_type.h + +namespace Catch { + + // ResultWas::OfType enum + struct ResultWas { enum OfType { + Unknown = -1, + Ok = 0, + Info = 1, + Warning = 2, + + FailureBit = 0x10, + + ExpressionFailed = FailureBit | 1, + ExplicitFailure = FailureBit | 2, + + Exception = 0x100 | FailureBit, + + ThrewException = Exception | 1, + DidntThrowException = Exception | 2, + + FatalErrorCondition = 0x200 | FailureBit + + }; }; + + bool isOk( ResultWas::OfType resultType ); + bool isJustInfo( int flags ); + + // ResultDisposition::Flags enum + struct ResultDisposition { enum Flags { + Normal = 0x01, + + ContinueOnFailure = 0x02, // Failures fail test, but execution continues + FalseTest = 0x04, // Prefix expression with ! + SuppressFail = 0x08 // Failures are reported but do not fail the test + }; }; + + ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ); + + bool shouldContinueOnFailure( int flags ); + inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } + bool shouldSuppressFailure( int flags ); + +} // end namespace Catch + +// end catch_result_type.h +namespace Catch { + + struct AssertionInfo + { + StringRef macroName; + SourceLineInfo lineInfo; + StringRef capturedExpression; + ResultDisposition::Flags resultDisposition; + + // We want to delete this constructor but a compiler bug in 4.8 means + // the struct is then treated as non-aggregate + //AssertionInfo() = delete; + }; + +} // end namespace Catch + +// end catch_assertioninfo.h +// start catch_decomposer.h + +// start catch_tostring.h + +#include +#include +#include +#include +// start catch_stream.h + +#include +#include +#include + +namespace Catch { + + std::ostream& cout(); + std::ostream& cerr(); + std::ostream& clog(); + + class StringRef; + + struct IStream { + virtual ~IStream(); + virtual std::ostream& stream() const = 0; + }; + + auto makeStream( StringRef const &filename ) -> IStream const*; + + class ReusableStringStream { + std::size_t m_index; + std::ostream* m_oss; + public: + ReusableStringStream(); + ~ReusableStringStream(); + + auto str() const -> std::string; + + template + auto operator << ( T const& value ) -> ReusableStringStream& { + *m_oss << value; + return *this; + } + auto get() -> std::ostream& { return *m_oss; } + + static void cleanup(); + }; +} + +// end catch_stream.h + +#ifdef __OBJC__ +// start catch_objc_arc.hpp + +#import + +#ifdef __has_feature +#define CATCH_ARC_ENABLED __has_feature(objc_arc) +#else +#define CATCH_ARC_ENABLED 0 +#endif + +void arcSafeRelease( NSObject* obj ); +id performOptionalSelector( id obj, SEL sel ); + +#if !CATCH_ARC_ENABLED +inline void arcSafeRelease( NSObject* obj ) { + [obj release]; +} +inline id performOptionalSelector( id obj, SEL sel ) { + if( [obj respondsToSelector: sel] ) + return [obj performSelector: sel]; + return nil; +} +#define CATCH_UNSAFE_UNRETAINED +#define CATCH_ARC_STRONG +#else +inline void arcSafeRelease( NSObject* ){} +inline id performOptionalSelector( id obj, SEL sel ) { +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" +#endif + if( [obj respondsToSelector: sel] ) + return [obj performSelector: sel]; +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + return nil; +} +#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained +#define CATCH_ARC_STRONG __strong +#endif + +// end catch_objc_arc.hpp +#endif + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless +#endif + +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); + +namespace Catch { + // Bring in operator<< from global namespace into Catch namespace + using ::operator<<; + + namespace Detail { + + extern const std::string unprintableString; + + std::string rawMemoryToString( const void *object, std::size_t size ); + + template + std::string rawMemoryToString( const T& object ) { + return rawMemoryToString( &object, sizeof(object) ); + } + + template + class IsStreamInsertable { + template + static auto test(int) + -> decltype(std::declval() << std::declval(), std::true_type()); + + template + static auto test(...)->std::false_type; + + public: + static const bool value = decltype(test(0))::value; + }; + + template + std::string convertUnknownEnumToString( E e ); + + template + typename std::enable_if::value, std::string>::type convertUnstreamable( T const& value ) { +#if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER) + (void)value; + return Detail::unprintableString; +#else + return CATCH_CONFIG_FALLBACK_STRINGIFIER(value); +#endif + } + template + typename std::enable_if::value, std::string>::type convertUnstreamable( T const& value ) { + return convertUnknownEnumToString( value ); + } + +#if defined(_MANAGED) + //! Convert a CLR string to a utf8 std::string + template + std::string clrReferenceToString( T^ ref ) { + if (ref == nullptr) + return std::string("null"); + auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString()); + cli::pin_ptr p = &bytes[0]; + return std::string(reinterpret_cast(p), bytes->Length); + } +#endif + + } // namespace Detail + + // If we decide for C++14, change these to enable_if_ts + template + struct StringMaker { + template + static + typename std::enable_if<::Catch::Detail::IsStreamInsertable::value, std::string>::type + convert(const Fake& value) { + ReusableStringStream rss; + rss << value; + return rss.str(); + } + + template + static + typename std::enable_if::value, std::string>::type + convert( const Fake& value ) { + return Detail::convertUnstreamable( value ); + } + }; + + namespace Detail { + + // This function dispatches all stringification requests inside of Catch. + // Should be preferably called fully qualified, like ::Catch::Detail::stringify + template + std::string stringify(const T& e) { + return ::Catch::StringMaker::type>::type>::convert(e); + } + + template + std::string convertUnknownEnumToString( E e ) { + return ::Catch::Detail::stringify(static_cast::type>(e)); + } + +#if defined(_MANAGED) + template + std::string stringify( T^ e ) { + return ::Catch::StringMaker::convert(e); + } +#endif + + } // namespace Detail + + // Some predefined specializations + + template<> + struct StringMaker { + static std::string convert(const std::string& str); + }; +#ifdef CATCH_CONFIG_WCHAR + template<> + struct StringMaker { + static std::string convert(const std::wstring& wstr); + }; +#endif + + template<> + struct StringMaker { + static std::string convert(char const * str); + }; + template<> + struct StringMaker { + static std::string convert(char * str); + }; + +#ifdef CATCH_CONFIG_WCHAR + template<> + struct StringMaker { + static std::string convert(wchar_t const * str); + }; + template<> + struct StringMaker { + static std::string convert(wchar_t * str); + }; +#endif + + // TBD: Should we use `strnlen` to ensure that we don't go out of the buffer, + // while keeping string semantics? + template + struct StringMaker { + static std::string convert(char const* str) { + return ::Catch::Detail::stringify(std::string{ str }); + } + }; + template + struct StringMaker { + static std::string convert(signed char const* str) { + return ::Catch::Detail::stringify(std::string{ reinterpret_cast(str) }); + } + }; + template + struct StringMaker { + static std::string convert(unsigned char const* str) { + return ::Catch::Detail::stringify(std::string{ reinterpret_cast(str) }); + } + }; + + template<> + struct StringMaker { + static std::string convert(int value); + }; + template<> + struct StringMaker { + static std::string convert(long value); + }; + template<> + struct StringMaker { + static std::string convert(long long value); + }; + template<> + struct StringMaker { + static std::string convert(unsigned int value); + }; + template<> + struct StringMaker { + static std::string convert(unsigned long value); + }; + template<> + struct StringMaker { + static std::string convert(unsigned long long value); + }; + + template<> + struct StringMaker { + static std::string convert(bool b); + }; + + template<> + struct StringMaker { + static std::string convert(char c); + }; + template<> + struct StringMaker { + static std::string convert(signed char c); + }; + template<> + struct StringMaker { + static std::string convert(unsigned char c); + }; + + template<> + struct StringMaker { + static std::string convert(std::nullptr_t); + }; + + template<> + struct StringMaker { + static std::string convert(float value); + }; + template<> + struct StringMaker { + static std::string convert(double value); + }; + + template + struct StringMaker { + template + static std::string convert(U* p) { + if (p) { + return ::Catch::Detail::rawMemoryToString(p); + } else { + return "nullptr"; + } + } + }; + + template + struct StringMaker { + static std::string convert(R C::* p) { + if (p) { + return ::Catch::Detail::rawMemoryToString(p); + } else { + return "nullptr"; + } + } + }; + +#if defined(_MANAGED) + template + struct StringMaker { + static std::string convert( T^ ref ) { + return ::Catch::Detail::clrReferenceToString(ref); + } + }; +#endif + + namespace Detail { + template + std::string rangeToString(InputIterator first, InputIterator last) { + ReusableStringStream rss; + rss << "{ "; + if (first != last) { + rss << ::Catch::Detail::stringify(*first); + for (++first; first != last; ++first) + rss << ", " << ::Catch::Detail::stringify(*first); + } + rss << " }"; + return rss.str(); + } + } + +#ifdef __OBJC__ + template<> + struct StringMaker { + static std::string convert(NSString * nsstring) { + if (!nsstring) + return "nil"; + return std::string("@") + [nsstring UTF8String]; + } + }; + template<> + struct StringMaker { + static std::string convert(NSObject* nsObject) { + return ::Catch::Detail::stringify([nsObject description]); + } + + }; + namespace Detail { + inline std::string stringify( NSString* nsstring ) { + return StringMaker::convert( nsstring ); + } + + } // namespace Detail +#endif // __OBJC__ + +} // namespace Catch + +////////////////////////////////////////////////////// +// Separate std-lib types stringification, so it can be selectively enabled +// This means that we do not bring in + +#if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS) +# define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER +# define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +#endif + +// Separate std::pair specialization +#if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER) +#include +namespace Catch { + template + struct StringMaker > { + static std::string convert(const std::pair& pair) { + ReusableStringStream rss; + rss << "{ " + << ::Catch::Detail::stringify(pair.first) + << ", " + << ::Catch::Detail::stringify(pair.second) + << " }"; + return rss.str(); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER + +// Separate std::tuple specialization +#if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER) +#include +namespace Catch { + namespace Detail { + template< + typename Tuple, + std::size_t N = 0, + bool = (N < std::tuple_size::value) + > + struct TupleElementPrinter { + static void print(const Tuple& tuple, std::ostream& os) { + os << (N ? ", " : " ") + << ::Catch::Detail::stringify(std::get(tuple)); + TupleElementPrinter::print(tuple, os); + } + }; + + template< + typename Tuple, + std::size_t N + > + struct TupleElementPrinter { + static void print(const Tuple&, std::ostream&) {} + }; + + } + + template + struct StringMaker> { + static std::string convert(const std::tuple& tuple) { + ReusableStringStream rss; + rss << '{'; + Detail::TupleElementPrinter>::print(tuple, rss.get()); + rss << " }"; + return rss.str(); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER + +namespace Catch { + struct not_this_one {}; // Tag type for detecting which begin/ end are being selected + + // Import begin/ end from std here so they are considered alongside the fallback (...) overloads in this namespace + using std::begin; + using std::end; + + not_this_one begin( ... ); + not_this_one end( ... ); + + template + struct is_range { + static const bool value = + !std::is_same())), not_this_one>::value && + !std::is_same())), not_this_one>::value; + }; + +#if defined(_MANAGED) // Managed types are never ranges + template + struct is_range { + static const bool value = false; + }; +#endif + + template + std::string rangeToString( Range const& range ) { + return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); + } + + // Handle vector specially + template + std::string rangeToString( std::vector const& v ) { + ReusableStringStream rss; + rss << "{ "; + bool first = true; + for( bool b : v ) { + if( first ) + first = false; + else + rss << ", "; + rss << ::Catch::Detail::stringify( b ); + } + rss << " }"; + return rss.str(); + } + + template + struct StringMaker::value && !::Catch::Detail::IsStreamInsertable::value>::type> { + static std::string convert( R const& range ) { + return rangeToString( range ); + } + }; + + template + struct StringMaker { + static std::string convert(T const(&arr)[SZ]) { + return rangeToString(arr); + } + }; + +} // namespace Catch + +// Separate std::chrono::duration specialization +#if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +#include +#include +#include + +namespace Catch { + +template +struct ratio_string { + static std::string symbol(); +}; + +template +std::string ratio_string::symbol() { + Catch::ReusableStringStream rss; + rss << '[' << Ratio::num << '/' + << Ratio::den << ']'; + return rss.str(); +} +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; + + //////////// + // std::chrono::duration specializations + template + struct StringMaker> { + static std::string convert(std::chrono::duration const& duration) { + ReusableStringStream rss; + rss << duration.count() << ' ' << ratio_string::symbol() << 's'; + return rss.str(); + } + }; + template + struct StringMaker>> { + static std::string convert(std::chrono::duration> const& duration) { + ReusableStringStream rss; + rss << duration.count() << " s"; + return rss.str(); + } + }; + template + struct StringMaker>> { + static std::string convert(std::chrono::duration> const& duration) { + ReusableStringStream rss; + rss << duration.count() << " m"; + return rss.str(); + } + }; + template + struct StringMaker>> { + static std::string convert(std::chrono::duration> const& duration) { + ReusableStringStream rss; + rss << duration.count() << " h"; + return rss.str(); + } + }; + + //////////// + // std::chrono::time_point specialization + // Generic time_point cannot be specialized, only std::chrono::time_point + template + struct StringMaker> { + static std::string convert(std::chrono::time_point const& time_point) { + return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch"; + } + }; + // std::chrono::time_point specialization + template + struct StringMaker> { + static std::string convert(std::chrono::time_point const& time_point) { + auto converted = std::chrono::system_clock::to_time_t(time_point); + +#ifdef _MSC_VER + std::tm timeInfo = {}; + gmtime_s(&timeInfo, &converted); +#else + std::tm* timeInfo = std::gmtime(&converted); +#endif + + auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); + char timeStamp[timeStampSize]; + const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + +#ifdef _MSC_VER + std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); +#else + std::strftime(timeStamp, timeStampSize, fmt, timeInfo); +#endif + return std::string(timeStamp); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// end catch_tostring.h +#include + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4389) // '==' : signed/unsigned mismatch +#pragma warning(disable:4018) // more "signed/unsigned mismatch" +#pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform) +#pragma warning(disable:4180) // qualifier applied to function type has no meaning +#endif + +namespace Catch { + + struct ITransientExpression { + auto isBinaryExpression() const -> bool { return m_isBinaryExpression; } + auto getResult() const -> bool { return m_result; } + virtual void streamReconstructedExpression( std::ostream &os ) const = 0; + + ITransientExpression( bool isBinaryExpression, bool result ) + : m_isBinaryExpression( isBinaryExpression ), + m_result( result ) + {} + + // We don't actually need a virtual destructor, but many static analysers + // complain if it's not here :-( + virtual ~ITransientExpression(); + + bool m_isBinaryExpression; + bool m_result; + + }; + + void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ); + + template + class BinaryExpr : public ITransientExpression { + LhsT m_lhs; + StringRef m_op; + RhsT m_rhs; + + void streamReconstructedExpression( std::ostream &os ) const override { + formatReconstructedExpression + ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) ); + } + + public: + BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs ) + : ITransientExpression{ true, comparisonResult }, + m_lhs( lhs ), + m_op( op ), + m_rhs( rhs ) + {} + }; + + template + class UnaryExpr : public ITransientExpression { + LhsT m_lhs; + + void streamReconstructedExpression( std::ostream &os ) const override { + os << Catch::Detail::stringify( m_lhs ); + } + + public: + explicit UnaryExpr( LhsT lhs ) + : ITransientExpression{ false, lhs ? true : false }, + m_lhs( lhs ) + {} + }; + + // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int) + template + auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast(lhs == rhs); } + template + auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } + template + auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } + template + auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } + template + auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } + + template + auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast(lhs != rhs); } + template + auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } + template + auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } + template + auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) != rhs; } + template + auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) != rhs; } + + template + class ExprLhs { + LhsT m_lhs; + public: + explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {} + + template + auto operator == ( RhsT const& rhs ) -> BinaryExpr const { + return { compareEqual( m_lhs, rhs ), m_lhs, "==", rhs }; + } + auto operator == ( bool rhs ) -> BinaryExpr const { + return { m_lhs == rhs, m_lhs, "==", rhs }; + } + + template + auto operator != ( RhsT const& rhs ) -> BinaryExpr const { + return { compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs }; + } + auto operator != ( bool rhs ) -> BinaryExpr const { + return { m_lhs != rhs, m_lhs, "!=", rhs }; + } + + template + auto operator > ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs > rhs), m_lhs, ">", rhs }; + } + template + auto operator < ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs < rhs), m_lhs, "<", rhs }; + } + template + auto operator >= ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs >= rhs), m_lhs, ">=", rhs }; + } + template + auto operator <= ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs <= rhs), m_lhs, "<=", rhs }; + } + + auto makeUnaryExpr() const -> UnaryExpr { + return UnaryExpr{ m_lhs }; + } + }; + + void handleExpression( ITransientExpression const& expr ); + + template + void handleExpression( ExprLhs const& expr ) { + handleExpression( expr.makeUnaryExpr() ); + } + + struct Decomposer { + template + auto operator <= ( T const& lhs ) -> ExprLhs { + return ExprLhs{ lhs }; + } + + auto operator <=( bool value ) -> ExprLhs { + return ExprLhs{ value }; + } + }; + +} // end namespace Catch + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// end catch_decomposer.h +// start catch_interfaces_capture.h + +#include + +namespace Catch { + + class AssertionResult; + struct AssertionInfo; + struct SectionInfo; + struct SectionEndInfo; + struct MessageInfo; + struct Counts; + struct BenchmarkInfo; + struct BenchmarkStats; + struct AssertionReaction; + + struct ITransientExpression; + + struct IResultCapture { + + virtual ~IResultCapture(); + + virtual bool sectionStarted( SectionInfo const& sectionInfo, + Counts& assertions ) = 0; + virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0; + virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0; + + virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0; + virtual void benchmarkEnded( BenchmarkStats const& stats ) = 0; + + virtual void pushScopedMessage( MessageInfo const& message ) = 0; + virtual void popScopedMessage( MessageInfo const& message ) = 0; + + virtual void handleFatalErrorCondition( StringRef message ) = 0; + + virtual void handleExpr + ( AssertionInfo const& info, + ITransientExpression const& expr, + AssertionReaction& reaction ) = 0; + virtual void handleMessage + ( AssertionInfo const& info, + ResultWas::OfType resultType, + StringRef const& message, + AssertionReaction& reaction ) = 0; + virtual void handleUnexpectedExceptionNotThrown + ( AssertionInfo const& info, + AssertionReaction& reaction ) = 0; + virtual void handleUnexpectedInflightException + ( AssertionInfo const& info, + std::string const& message, + AssertionReaction& reaction ) = 0; + virtual void handleIncomplete + ( AssertionInfo const& info ) = 0; + virtual void handleNonExpr + ( AssertionInfo const &info, + ResultWas::OfType resultType, + AssertionReaction &reaction ) = 0; + + virtual bool lastAssertionPassed() = 0; + virtual void assertionPassed() = 0; + + // Deprecated, do not use: + virtual std::string getCurrentTestName() const = 0; + virtual const AssertionResult* getLastResult() const = 0; + virtual void exceptionEarlyReported() = 0; + }; + + IResultCapture& getResultCapture(); +} + +// end catch_interfaces_capture.h +namespace Catch { + + struct TestFailureException{}; + struct AssertionResultData; + struct IResultCapture; + class RunContext; + + class LazyExpression { + friend class AssertionHandler; + friend struct AssertionStats; + friend class RunContext; + + ITransientExpression const* m_transientExpression = nullptr; + bool m_isNegated; + public: + LazyExpression( bool isNegated ); + LazyExpression( LazyExpression const& other ); + LazyExpression& operator = ( LazyExpression const& ) = delete; + + explicit operator bool() const; + + friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&; + }; + + struct AssertionReaction { + bool shouldDebugBreak = false; + bool shouldThrow = false; + }; + + class AssertionHandler { + AssertionInfo m_assertionInfo; + AssertionReaction m_reaction; + bool m_completed = false; + IResultCapture& m_resultCapture; + + public: + AssertionHandler + ( StringRef macroName, + SourceLineInfo const& lineInfo, + StringRef capturedExpression, + ResultDisposition::Flags resultDisposition ); + ~AssertionHandler() { + if ( !m_completed ) { + m_resultCapture.handleIncomplete( m_assertionInfo ); + } + } + + template + void handleExpr( ExprLhs const& expr ) { + handleExpr( expr.makeUnaryExpr() ); + } + void handleExpr( ITransientExpression const& expr ); + + void handleMessage(ResultWas::OfType resultType, StringRef const& message); + + void handleExceptionThrownAsExpected(); + void handleUnexpectedExceptionNotThrown(); + void handleExceptionNotThrownAsExpected(); + void handleThrowingCallSkipped(); + void handleUnexpectedInflightException(); + + void complete(); + void setCompleted(); + + // query + auto allowThrows() const -> bool; + }; + + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ); + +} // namespace Catch + +// end catch_assertionhandler.h +// start catch_message.h + +#include + +namespace Catch { + + struct MessageInfo { + MessageInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ); + + std::string macroName; + std::string message; + SourceLineInfo lineInfo; + ResultWas::OfType type; + unsigned int sequence; + + bool operator == ( MessageInfo const& other ) const; + bool operator < ( MessageInfo const& other ) const; + private: + static unsigned int globalCount; + }; + + struct MessageStream { + + template + MessageStream& operator << ( T const& value ) { + m_stream << value; + return *this; + } + + ReusableStringStream m_stream; + }; + + struct MessageBuilder : MessageStream { + MessageBuilder( std::string const& macroName, + SourceLineInfo const& lineInfo, + ResultWas::OfType type ); + + template + MessageBuilder& operator << ( T const& value ) { + m_stream << value; + return *this; + } + + MessageInfo m_info; + }; + + class ScopedMessage { + public: + explicit ScopedMessage( MessageBuilder const& builder ); + ~ScopedMessage(); + + MessageInfo m_info; + }; + +} // end namespace Catch + +// end catch_message.h +#if !defined(CATCH_CONFIG_DISABLE) + +#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION) + #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__ +#else + #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION" +#endif + +#if defined(CATCH_CONFIG_FAST_COMPILE) + +/////////////////////////////////////////////////////////////////////////////// +// Another way to speed-up compilation is to omit local try-catch for REQUIRE* +// macros. +#define INTERNAL_CATCH_TRY +#define INTERNAL_CATCH_CATCH( capturer ) + +#else // CATCH_CONFIG_FAST_COMPILE + +#define INTERNAL_CATCH_TRY try +#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); } + +#endif + +#define INTERNAL_CATCH_REACT( handler ) handler.complete(); + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ + INTERNAL_CATCH_TRY { \ + CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ + CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ + } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( (void)0, false && static_cast( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look + // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ + if( Catch::getResultCapture().lastAssertionPassed() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ + if( !Catch::getResultCapture().lastAssertionPassed() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ + try { \ + static_cast(__VA_ARGS__); \ + catchAssertionHandler.handleExceptionNotThrownAsExpected(); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleUnexpectedInflightException(); \ + } \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(__VA_ARGS__); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleExceptionThrownAsExpected(); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(expr); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( exceptionType const& ) { \ + catchAssertionHandler.handleExceptionThrownAsExpected(); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleUnexpectedInflightException(); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ + catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_INFO( macroName, log ) \ + Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ); + +/////////////////////////////////////////////////////////////////////////////// +// Although this is matcher-based, it can be used with just a string +#define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(__VA_ARGS__); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( ... ) { \ + Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +#endif // CATCH_CONFIG_DISABLE + +// end catch_capture.hpp +// start catch_section.h + +// start catch_section_info.h + +// start catch_totals.h + +#include + +namespace Catch { + + struct Counts { + Counts operator - ( Counts const& other ) const; + Counts& operator += ( Counts const& other ); + + std::size_t total() const; + bool allPassed() const; + bool allOk() const; + + std::size_t passed = 0; + std::size_t failed = 0; + std::size_t failedButOk = 0; + }; + + struct Totals { + + Totals operator - ( Totals const& other ) const; + Totals& operator += ( Totals const& other ); + + Totals delta( Totals const& prevTotals ) const; + + int error = 0; + Counts assertions; + Counts testCases; + }; +} + +// end catch_totals.h +#include + +namespace Catch { + + struct SectionInfo { + SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& _description = std::string() ); + + std::string name; + std::string description; + SourceLineInfo lineInfo; + }; + + struct SectionEndInfo { + SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ); + + SectionInfo sectionInfo; + Counts prevAssertions; + double durationInSeconds; + }; + +} // end namespace Catch + +// end catch_section_info.h +// start catch_timer.h + +#include + +namespace Catch { + + auto getCurrentNanosecondsSinceEpoch() -> uint64_t; + auto getEstimatedClockResolution() -> uint64_t; + + class Timer { + uint64_t m_nanoseconds = 0; + public: + void start(); + auto getElapsedNanoseconds() const -> uint64_t; + auto getElapsedMicroseconds() const -> uint64_t; + auto getElapsedMilliseconds() const -> unsigned int; + auto getElapsedSeconds() const -> double; + }; + +} // namespace Catch + +// end catch_timer.h +#include + +namespace Catch { + + class Section : NonCopyable { + public: + Section( SectionInfo const& info ); + ~Section(); + + // This indicates whether the section should be executed or not + explicit operator bool() const; + + private: + SectionInfo m_info; + + std::string m_name; + Counts m_assertions; + bool m_sectionIncluded; + Timer m_timer; + }; + +} // end namespace Catch + + #define INTERNAL_CATCH_SECTION( ... ) \ + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) + +// end catch_section.h +// start catch_benchmark.h + +#include +#include + +namespace Catch { + + class BenchmarkLooper { + + std::string m_name; + std::size_t m_count = 0; + std::size_t m_iterationsToRun = 1; + uint64_t m_resolution; + Timer m_timer; + + static auto getResolution() -> uint64_t; + public: + // Keep most of this inline as it's on the code path that is being timed + BenchmarkLooper( StringRef name ) + : m_name( name ), + m_resolution( getResolution() ) + { + reportStart(); + m_timer.start(); + } + + explicit operator bool() { + if( m_count < m_iterationsToRun ) + return true; + return needsMoreIterations(); + } + + void increment() { + ++m_count; + } + + void reportStart(); + auto needsMoreIterations() -> bool; + }; + +} // end namespace Catch + +#define BENCHMARK( name ) \ + for( Catch::BenchmarkLooper looper( name ); looper; looper.increment() ) + +// end catch_benchmark.h +// start catch_interfaces_exception.h + +// start catch_interfaces_registry_hub.h + +#include +#include + +namespace Catch { + + class TestCase; + struct ITestCaseRegistry; + struct IExceptionTranslatorRegistry; + struct IExceptionTranslator; + struct IReporterRegistry; + struct IReporterFactory; + struct ITagAliasRegistry; + class StartupExceptionRegistry; + + using IReporterFactoryPtr = std::shared_ptr; + + struct IRegistryHub { + virtual ~IRegistryHub(); + + virtual IReporterRegistry const& getReporterRegistry() const = 0; + virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; + virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0; + + virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; + + virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0; + }; + + struct IMutableRegistryHub { + virtual ~IMutableRegistryHub(); + virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0; + virtual void registerListener( IReporterFactoryPtr const& factory ) = 0; + virtual void registerTest( TestCase const& testInfo ) = 0; + virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; + virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0; + virtual void registerStartupException() noexcept = 0; + }; + + IRegistryHub& getRegistryHub(); + IMutableRegistryHub& getMutableRegistryHub(); + void cleanUp(); + std::string translateActiveException(); + +} + +// end catch_interfaces_registry_hub.h +#if defined(CATCH_CONFIG_DISABLE) + #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \ + static std::string translatorName( signature ) +#endif + +#include +#include +#include + +namespace Catch { + using exceptionTranslateFunction = std::string(*)(); + + struct IExceptionTranslator; + using ExceptionTranslators = std::vector>; + + struct IExceptionTranslator { + virtual ~IExceptionTranslator(); + virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; + }; + + struct IExceptionTranslatorRegistry { + virtual ~IExceptionTranslatorRegistry(); + + virtual std::string translateActiveException() const = 0; + }; + + class ExceptionTranslatorRegistrar { + template + class ExceptionTranslator : public IExceptionTranslator { + public: + + ExceptionTranslator( std::string(*translateFunction)( T& ) ) + : m_translateFunction( translateFunction ) + {} + + std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { + try { + if( it == itEnd ) + std::rethrow_exception(std::current_exception()); + else + return (*it)->translate( it+1, itEnd ); + } + catch( T& ex ) { + return m_translateFunction( ex ); + } + } + + protected: + std::string(*m_translateFunction)( T& ); + }; + + public: + template + ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { + getMutableRegistryHub().registerTranslator + ( new ExceptionTranslator( translateFunction ) ); + } + }; +} + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \ + static std::string translatorName( signature ); \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ + static std::string translatorName( signature ) + +#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) + +// end catch_interfaces_exception.h +// start catch_approx.h + +#include +#include + +namespace Catch { +namespace Detail { + + class Approx { + private: + bool equalityComparisonImpl(double other) const; + + public: + explicit Approx ( double value ); + + static Approx custom(); + + template ::value>::type> + Approx operator()( T const& value ) { + Approx approx( static_cast(value) ); + approx.epsilon( m_epsilon ); + approx.margin( m_margin ); + approx.scale( m_scale ); + return approx; + } + + template ::value>::type> + explicit Approx( T const& value ): Approx(static_cast(value)) + {} + + template ::value>::type> + friend bool operator == ( const T& lhs, Approx const& rhs ) { + auto lhs_v = static_cast(lhs); + return rhs.equalityComparisonImpl(lhs_v); + } + + template ::value>::type> + friend bool operator == ( Approx const& lhs, const T& rhs ) { + return operator==( rhs, lhs ); + } + + template ::value>::type> + friend bool operator != ( T const& lhs, Approx const& rhs ) { + return !operator==( lhs, rhs ); + } + + template ::value>::type> + friend bool operator != ( Approx const& lhs, T const& rhs ) { + return !operator==( rhs, lhs ); + } + + template ::value>::type> + friend bool operator <= ( T const& lhs, Approx const& rhs ) { + return static_cast(lhs) < rhs.m_value || lhs == rhs; + } + + template ::value>::type> + friend bool operator <= ( Approx const& lhs, T const& rhs ) { + return lhs.m_value < static_cast(rhs) || lhs == rhs; + } + + template ::value>::type> + friend bool operator >= ( T const& lhs, Approx const& rhs ) { + return static_cast(lhs) > rhs.m_value || lhs == rhs; + } + + template ::value>::type> + friend bool operator >= ( Approx const& lhs, T const& rhs ) { + return lhs.m_value > static_cast(rhs) || lhs == rhs; + } + + template ::value>::type> + Approx& epsilon( T const& newEpsilon ) { + double epsilonAsDouble = static_cast(newEpsilon); + if( epsilonAsDouble < 0 || epsilonAsDouble > 1.0 ) { + throw std::domain_error + ( "Invalid Approx::epsilon: " + + Catch::Detail::stringify( epsilonAsDouble ) + + ", Approx::epsilon has to be between 0 and 1" ); + } + m_epsilon = epsilonAsDouble; + return *this; + } + + template ::value>::type> + Approx& margin( T const& newMargin ) { + double marginAsDouble = static_cast(newMargin); + if( marginAsDouble < 0 ) { + throw std::domain_error + ( "Invalid Approx::margin: " + + Catch::Detail::stringify( marginAsDouble ) + + ", Approx::Margin has to be non-negative." ); + + } + m_margin = marginAsDouble; + return *this; + } + + template ::value>::type> + Approx& scale( T const& newScale ) { + m_scale = static_cast(newScale); + return *this; + } + + std::string toString() const; + + private: + double m_epsilon; + double m_margin; + double m_scale; + double m_value; + }; +} + +template<> +struct StringMaker { + static std::string convert(Catch::Detail::Approx const& value); +}; + +} // end namespace Catch + +// end catch_approx.h +// start catch_string_manip.h + +#include +#include + +namespace Catch { + + bool startsWith( std::string const& s, std::string const& prefix ); + bool startsWith( std::string const& s, char prefix ); + bool endsWith( std::string const& s, std::string const& suffix ); + bool endsWith( std::string const& s, char suffix ); + bool contains( std::string const& s, std::string const& infix ); + void toLowerInPlace( std::string& s ); + std::string toLower( std::string const& s ); + std::string trim( std::string const& str ); + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); + + struct pluralise { + pluralise( std::size_t count, std::string const& label ); + + friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); + + std::size_t m_count; + std::string m_label; + }; +} + +// end catch_string_manip.h +#ifndef CATCH_CONFIG_DISABLE_MATCHERS +// start catch_capture_matchers.h + +// start catch_matchers.h + +#include +#include + +namespace Catch { +namespace Matchers { + namespace Impl { + + template struct MatchAllOf; + template struct MatchAnyOf; + template struct MatchNotOf; + + class MatcherUntypedBase { + public: + MatcherUntypedBase() = default; + MatcherUntypedBase ( MatcherUntypedBase const& ) = default; + MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete; + std::string toString() const; + + protected: + virtual ~MatcherUntypedBase(); + virtual std::string describe() const = 0; + mutable std::string m_cachedToString; + }; + + template + struct MatcherMethod { + virtual bool match( ObjectT const& arg ) const = 0; + }; + template + struct MatcherMethod { + virtual bool match( PtrT* arg ) const = 0; + }; + + template + struct MatcherBase : MatcherUntypedBase, MatcherMethod { + + MatchAllOf operator && ( MatcherBase const& other ) const; + MatchAnyOf operator || ( MatcherBase const& other ) const; + MatchNotOf operator ! () const; + }; + + template + struct MatchAllOf : MatcherBase { + bool match( ArgT const& arg ) const override { + for( auto matcher : m_matchers ) { + if (!matcher->match(arg)) + return false; + } + return true; + } + std::string describe() const override { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + bool first = true; + for( auto matcher : m_matchers ) { + if( first ) + first = false; + else + description += " and "; + description += matcher->toString(); + } + description += " )"; + return description; + } + + MatchAllOf& operator && ( MatcherBase const& other ) { + m_matchers.push_back( &other ); + return *this; + } + + std::vector const*> m_matchers; + }; + template + struct MatchAnyOf : MatcherBase { + + bool match( ArgT const& arg ) const override { + for( auto matcher : m_matchers ) { + if (matcher->match(arg)) + return true; + } + return false; + } + std::string describe() const override { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + bool first = true; + for( auto matcher : m_matchers ) { + if( first ) + first = false; + else + description += " or "; + description += matcher->toString(); + } + description += " )"; + return description; + } + + MatchAnyOf& operator || ( MatcherBase const& other ) { + m_matchers.push_back( &other ); + return *this; + } + + std::vector const*> m_matchers; + }; + + template + struct MatchNotOf : MatcherBase { + + MatchNotOf( MatcherBase const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {} + + bool match( ArgT const& arg ) const override { + return !m_underlyingMatcher.match( arg ); + } + + std::string describe() const override { + return "not " + m_underlyingMatcher.toString(); + } + MatcherBase const& m_underlyingMatcher; + }; + + template + MatchAllOf MatcherBase::operator && ( MatcherBase const& other ) const { + return MatchAllOf() && *this && other; + } + template + MatchAnyOf MatcherBase::operator || ( MatcherBase const& other ) const { + return MatchAnyOf() || *this || other; + } + template + MatchNotOf MatcherBase::operator ! () const { + return MatchNotOf( *this ); + } + + } // namespace Impl + +} // namespace Matchers + +using namespace Matchers; +using Matchers::Impl::MatcherBase; + +} // namespace Catch + +// end catch_matchers.h +// start catch_matchers_floating.h + +#include +#include + +namespace Catch { +namespace Matchers { + + namespace Floating { + + enum class FloatingPointKind : uint8_t; + + struct WithinAbsMatcher : MatcherBase { + WithinAbsMatcher(double target, double margin); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + double m_margin; + }; + + struct WithinUlpsMatcher : MatcherBase { + WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + int m_ulps; + FloatingPointKind m_type; + }; + + } // namespace Floating + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff); + Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff); + Floating::WithinAbsMatcher WithinAbs(double target, double margin); + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_floating.h +// start catch_matchers_generic.hpp + +#include +#include + +namespace Catch { +namespace Matchers { +namespace Generic { + +namespace Detail { + std::string finalizeDescription(const std::string& desc); +} + +template +class PredicateMatcher : public MatcherBase { + std::function m_predicate; + std::string m_description; +public: + + PredicateMatcher(std::function const& elem, std::string const& descr) + :m_predicate(std::move(elem)), + m_description(Detail::finalizeDescription(descr)) + {} + + bool match( T const& item ) const override { + return m_predicate(item); + } + + std::string describe() const override { + return m_description; + } +}; + +} // namespace Generic + + // The following functions create the actual matcher objects. + // The user has to explicitly specify type to the function, because + // infering std::function is hard (but possible) and + // requires a lot of TMP. + template + Generic::PredicateMatcher Predicate(std::function const& predicate, std::string const& description = "") { + return Generic::PredicateMatcher(predicate, description); + } + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_generic.hpp +// start catch_matchers_string.h + +#include + +namespace Catch { +namespace Matchers { + + namespace StdString { + + struct CasedString + { + CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ); + std::string adjustString( std::string const& str ) const; + std::string caseSensitivitySuffix() const; + + CaseSensitive::Choice m_caseSensitivity; + std::string m_str; + }; + + struct StringMatcherBase : MatcherBase { + StringMatcherBase( std::string const& operation, CasedString const& comparator ); + std::string describe() const override; + + CasedString m_comparator; + std::string m_operation; + }; + + struct EqualsMatcher : StringMatcherBase { + EqualsMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + struct ContainsMatcher : StringMatcherBase { + ContainsMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + struct StartsWithMatcher : StringMatcherBase { + StartsWithMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + struct EndsWithMatcher : StringMatcherBase { + EndsWithMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + + struct RegexMatcher : MatcherBase { + RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity ); + bool match( std::string const& matchee ) const override; + std::string describe() const override; + + private: + std::string m_regex; + CaseSensitive::Choice m_caseSensitivity; + }; + + } // namespace StdString + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + + StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_string.h +// start catch_matchers_vector.h + +#include + +namespace Catch { +namespace Matchers { + + namespace Vector { + namespace Detail { + template + size_t count(InputIterator first, InputIterator last, T const& item) { + size_t cnt = 0; + for (; first != last; ++first) { + if (*first == item) { + ++cnt; + } + } + return cnt; + } + template + bool contains(InputIterator first, InputIterator last, T const& item) { + for (; first != last; ++first) { + if (*first == item) { + return true; + } + } + return false; + } + } + + template + struct ContainsElementMatcher : MatcherBase> { + + ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} + + bool match(std::vector const &v) const override { + for (auto const& el : v) { + if (el == m_comparator) { + return true; + } + } + return false; + } + + std::string describe() const override { + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); + } + + T const& m_comparator; + }; + + template + struct ContainsMatcher : MatcherBase> { + + ContainsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + + bool match(std::vector const &v) const override { + // !TBD: see note in EqualsMatcher + if (m_comparator.size() > v.size()) + return false; + for (auto const& comparator : m_comparator) { + auto present = false; + for (const auto& el : v) { + if (el == comparator) { + present = true; + break; + } + } + if (!present) { + return false; + } + } + return true; + } + std::string describe() const override { + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); + } + + std::vector const& m_comparator; + }; + + template + struct EqualsMatcher : MatcherBase> { + + EqualsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + + bool match(std::vector const &v) const override { + // !TBD: This currently works if all elements can be compared using != + // - a more general approach would be via a compare template that defaults + // to using !=. but could be specialised for, e.g. std::vector etc + // - then just call that directly + if (m_comparator.size() != v.size()) + return false; + for (std::size_t i = 0; i < v.size(); ++i) + if (m_comparator[i] != v[i]) + return false; + return true; + } + std::string describe() const override { + return "Equals: " + ::Catch::Detail::stringify( m_comparator ); + } + std::vector const& m_comparator; + }; + + template + struct UnorderedEqualsMatcher : MatcherBase> { + UnorderedEqualsMatcher(std::vector const& target) : m_target(target) {} + bool match(std::vector const& vec) const override { + // Note: This is a reimplementation of std::is_permutation, + // because I don't want to include inside the common path + if (m_target.size() != vec.size()) { + return false; + } + auto lfirst = m_target.begin(), llast = m_target.end(); + auto rfirst = vec.begin(), rlast = vec.end(); + // Cut common prefix to optimize checking of permuted parts + while (lfirst != llast && *lfirst != *rfirst) { + ++lfirst; ++rfirst; + } + if (lfirst == llast) { + return true; + } + + for (auto mid = lfirst; mid != llast; ++mid) { + // Skip already counted items + if (Detail::contains(lfirst, mid, *mid)) { + continue; + } + size_t num_vec = Detail::count(rfirst, rlast, *mid); + if (num_vec == 0 || Detail::count(lfirst, llast, *mid) != num_vec) { + return false; + } + } + + return true; + } + + std::string describe() const override { + return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target); + } + private: + std::vector const& m_target; + }; + + } // namespace Vector + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + + template + Vector::ContainsMatcher Contains( std::vector const& comparator ) { + return Vector::ContainsMatcher( comparator ); + } + + template + Vector::ContainsElementMatcher VectorContains( T const& comparator ) { + return Vector::ContainsElementMatcher( comparator ); + } + + template + Vector::EqualsMatcher Equals( std::vector const& comparator ) { + return Vector::EqualsMatcher( comparator ); + } + + template + Vector::UnorderedEqualsMatcher UnorderedEquals(std::vector const& target) { + return Vector::UnorderedEqualsMatcher(target); + } + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_vector.h +namespace Catch { + + template + class MatchExpr : public ITransientExpression { + ArgT const& m_arg; + MatcherT m_matcher; + StringRef m_matcherString; + public: + MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString ) + : ITransientExpression{ true, matcher.match( arg ) }, + m_arg( arg ), + m_matcher( matcher ), + m_matcherString( matcherString ) + {} + + void streamReconstructedExpression( std::ostream &os ) const override { + auto matcherAsString = m_matcher.toString(); + os << Catch::Detail::stringify( m_arg ) << ' '; + if( matcherAsString == Detail::unprintableString ) + os << m_matcherString; + else + os << matcherAsString; + } + }; + + using StringMatcher = Matchers::Impl::MatcherBase; + + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ); + + template + auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString ) -> MatchExpr { + return MatchExpr( arg, matcher, matcherString ); + } + +} // namespace Catch + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ + INTERNAL_CATCH_TRY { \ + catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \ + } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(__VA_ARGS__ ); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( exceptionType const& ex ) { \ + catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleUnexpectedInflightException(); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +// end catch_capture_matchers.h +#endif + +// These files are included here so the single_include script doesn't put them +// in the conditionally compiled sections +// start catch_test_case_info.h + +#include +#include +#include + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +namespace Catch { + + struct ITestInvoker; + + struct TestCaseInfo { + enum SpecialProperties{ + None = 0, + IsHidden = 1 << 1, + ShouldFail = 1 << 2, + MayFail = 1 << 3, + Throws = 1 << 4, + NonPortable = 1 << 5, + Benchmark = 1 << 6 + }; + + TestCaseInfo( std::string const& _name, + std::string const& _className, + std::string const& _description, + std::vector const& _tags, + SourceLineInfo const& _lineInfo ); + + friend void setTags( TestCaseInfo& testCaseInfo, std::vector tags ); + + bool isHidden() const; + bool throws() const; + bool okToFail() const; + bool expectedToFail() const; + + std::string tagsAsString() const; + + std::string name; + std::string className; + std::string description; + std::vector tags; + std::vector lcaseTags; + SourceLineInfo lineInfo; + SpecialProperties properties; + }; + + class TestCase : public TestCaseInfo { + public: + + TestCase( ITestInvoker* testCase, TestCaseInfo&& info ); + + TestCase withName( std::string const& _newName ) const; + + void invoke() const; + + TestCaseInfo const& getTestCaseInfo() const; + + bool operator == ( TestCase const& other ) const; + bool operator < ( TestCase const& other ) const; + + private: + std::shared_ptr test; + }; + + TestCase makeTestCase( ITestInvoker* testCase, + std::string const& className, + NameAndTags const& nameAndTags, + SourceLineInfo const& lineInfo ); +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_test_case_info.h +// start catch_interfaces_runner.h + +namespace Catch { + + struct IRunner { + virtual ~IRunner(); + virtual bool aborting() const = 0; + }; +} + +// end catch_interfaces_runner.h + +#ifdef __OBJC__ +// start catch_objc.hpp + +#import + +#include + +// NB. Any general catch headers included here must be included +// in catch.hpp first to make sure they are included by the single +// header for non obj-usage + +/////////////////////////////////////////////////////////////////////////////// +// This protocol is really only here for (self) documenting purposes, since +// all its methods are optional. +@protocol OcFixture + +@optional + +-(void) setUp; +-(void) tearDown; + +@end + +namespace Catch { + + class OcMethod : public ITestInvoker { + + public: + OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} + + virtual void invoke() const { + id obj = [[m_cls alloc] init]; + + performOptionalSelector( obj, @selector(setUp) ); + performOptionalSelector( obj, m_sel ); + performOptionalSelector( obj, @selector(tearDown) ); + + arcSafeRelease( obj ); + } + private: + virtual ~OcMethod() {} + + Class m_cls; + SEL m_sel; + }; + + namespace Detail{ + + inline std::string getAnnotation( Class cls, + std::string const& annotationName, + std::string const& testCaseName ) { + NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; + SEL sel = NSSelectorFromString( selStr ); + arcSafeRelease( selStr ); + id value = performOptionalSelector( cls, sel ); + if( value ) + return [(NSString*)value UTF8String]; + return ""; + } + } + + inline std::size_t registerTestMethods() { + std::size_t noTestMethods = 0; + int noClasses = objc_getClassList( nullptr, 0 ); + + Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); + objc_getClassList( classes, noClasses ); + + for( int c = 0; c < noClasses; c++ ) { + Class cls = classes[c]; + { + u_int count; + Method* methods = class_copyMethodList( cls, &count ); + for( u_int m = 0; m < count ; m++ ) { + SEL selector = method_getName(methods[m]); + std::string methodName = sel_getName(selector); + if( startsWith( methodName, "Catch_TestCase_" ) ) { + std::string testCaseName = methodName.substr( 15 ); + std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); + std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); + const char* className = class_getName( cls ); + + getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo("",0) ) ); + noTestMethods++; + } + } + free(methods); + } + } + return noTestMethods; + } + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) + + namespace Matchers { + namespace Impl { + namespace NSStringMatchers { + + struct StringHolder : MatcherBase{ + StringHolder( NSString* substr ) : m_substr( [substr copy] ){} + StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} + StringHolder() { + arcSafeRelease( m_substr ); + } + + bool match( NSString* arg ) const override { + return false; + } + + NSString* CATCH_ARC_STRONG m_substr; + }; + + struct Equals : StringHolder { + Equals( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str isEqualToString:m_substr]; + } + + std::string describe() const override { + return "equals string: " + Catch::Detail::stringify( m_substr ); + } + }; + + struct Contains : StringHolder { + Contains( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location != NSNotFound; + } + + std::string describe() const override { + return "contains string: " + Catch::Detail::stringify( m_substr ); + } + }; + + struct StartsWith : StringHolder { + StartsWith( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location == 0; + } + + std::string describe() const override { + return "starts with: " + Catch::Detail::stringify( m_substr ); + } + }; + struct EndsWith : StringHolder { + EndsWith( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location == [str length] - [m_substr length]; + } + + std::string describe() const override { + return "ends with: " + Catch::Detail::stringify( m_substr ); + } + }; + + } // namespace NSStringMatchers + } // namespace Impl + + inline Impl::NSStringMatchers::Equals + Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } + + inline Impl::NSStringMatchers::Contains + Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } + + inline Impl::NSStringMatchers::StartsWith + StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } + + inline Impl::NSStringMatchers::EndsWith + EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } + + } // namespace Matchers + + using namespace Matchers; + +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +} // namespace Catch + +/////////////////////////////////////////////////////////////////////////////// +#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix +#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \ ++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \ +{ \ +return @ name; \ +} \ ++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \ +{ \ +return @ desc; \ +} \ +-(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix ) + +#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ ) + +// end catch_objc.hpp +#endif + +#ifdef CATCH_CONFIG_EXTERNAL_INTERFACES +// start catch_external_interfaces.h + +// start catch_reporter_bases.hpp + +// start catch_interfaces_reporter.h + +// start catch_config.hpp + +// start catch_test_spec_parser.h + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +// start catch_test_spec.h + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +// start catch_wildcard_pattern.h + +namespace Catch +{ + class WildcardPattern { + enum WildcardPosition { + NoWildcard = 0, + WildcardAtStart = 1, + WildcardAtEnd = 2, + WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd + }; + + public: + + WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity ); + virtual ~WildcardPattern() = default; + virtual bool matches( std::string const& str ) const; + + private: + std::string adjustCase( std::string const& str ) const; + CaseSensitive::Choice m_caseSensitivity; + WildcardPosition m_wildcard = NoWildcard; + std::string m_pattern; + }; +} + +// end catch_wildcard_pattern.h +#include +#include +#include + +namespace Catch { + + class TestSpec { + struct Pattern { + virtual ~Pattern(); + virtual bool matches( TestCaseInfo const& testCase ) const = 0; + }; + using PatternPtr = std::shared_ptr; + + class NamePattern : public Pattern { + public: + NamePattern( std::string const& name ); + virtual ~NamePattern(); + virtual bool matches( TestCaseInfo const& testCase ) const override; + private: + WildcardPattern m_wildcardPattern; + }; + + class TagPattern : public Pattern { + public: + TagPattern( std::string const& tag ); + virtual ~TagPattern(); + virtual bool matches( TestCaseInfo const& testCase ) const override; + private: + std::string m_tag; + }; + + class ExcludedPattern : public Pattern { + public: + ExcludedPattern( PatternPtr const& underlyingPattern ); + virtual ~ExcludedPattern(); + virtual bool matches( TestCaseInfo const& testCase ) const override; + private: + PatternPtr m_underlyingPattern; + }; + + struct Filter { + std::vector m_patterns; + + bool matches( TestCaseInfo const& testCase ) const; + }; + + public: + bool hasFilters() const; + bool matches( TestCaseInfo const& testCase ) const; + + private: + std::vector m_filters; + + friend class TestSpecParser; + }; +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_test_spec.h +// start catch_interfaces_tag_alias_registry.h + +#include + +namespace Catch { + + struct TagAlias; + + struct ITagAliasRegistry { + virtual ~ITagAliasRegistry(); + // Nullptr if not present + virtual TagAlias const* find( std::string const& alias ) const = 0; + virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; + + static ITagAliasRegistry const& get(); + }; + +} // end namespace Catch + +// end catch_interfaces_tag_alias_registry.h +namespace Catch { + + class TestSpecParser { + enum Mode{ None, Name, QuotedName, Tag, EscapedName }; + Mode m_mode = None; + bool m_exclusion = false; + std::size_t m_start = std::string::npos, m_pos = 0; + std::string m_arg; + std::vector m_escapeChars; + TestSpec::Filter m_currentFilter; + TestSpec m_testSpec; + ITagAliasRegistry const* m_tagAliases = nullptr; + + public: + TestSpecParser( ITagAliasRegistry const& tagAliases ); + + TestSpecParser& parse( std::string const& arg ); + TestSpec testSpec(); + + private: + void visitChar( char c ); + void startNewMode( Mode mode, std::size_t start ); + void escape(); + std::string subString() const; + + template + void addPattern() { + std::string token = subString(); + for( std::size_t i = 0; i < m_escapeChars.size(); ++i ) + token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 ); + m_escapeChars.clear(); + if( startsWith( token, "exclude:" ) ) { + m_exclusion = true; + token = token.substr( 8 ); + } + if( !token.empty() ) { + TestSpec::PatternPtr pattern = std::make_shared( token ); + if( m_exclusion ) + pattern = std::make_shared( pattern ); + m_currentFilter.m_patterns.push_back( pattern ); + } + m_exclusion = false; + m_mode = None; + } + + void addFilter(); + }; + TestSpec parseTestSpec( std::string const& arg ); + +} // namespace Catch + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_test_spec_parser.h +// start catch_interfaces_config.h + +#include +#include +#include +#include + +namespace Catch { + + enum class Verbosity { + Quiet = 0, + Normal, + High + }; + + struct WarnAbout { enum What { + Nothing = 0x00, + NoAssertions = 0x01, + NoTests = 0x02 + }; }; + + struct ShowDurations { enum OrNot { + DefaultForReporter, + Always, + Never + }; }; + struct RunTests { enum InWhatOrder { + InDeclarationOrder, + InLexicographicalOrder, + InRandomOrder + }; }; + struct UseColour { enum YesOrNo { + Auto, + Yes, + No + }; }; + struct WaitForKeypress { enum When { + Never, + BeforeStart = 1, + BeforeExit = 2, + BeforeStartAndExit = BeforeStart | BeforeExit + }; }; + + class TestSpec; + + struct IConfig : NonCopyable { + + virtual ~IConfig(); + + virtual bool allowThrows() const = 0; + virtual std::ostream& stream() const = 0; + virtual std::string name() const = 0; + virtual bool includeSuccessfulResults() const = 0; + virtual bool shouldDebugBreak() const = 0; + virtual bool warnAboutMissingAssertions() const = 0; + virtual bool warnAboutNoTests() const = 0; + virtual int abortAfter() const = 0; + virtual bool showInvisibles() const = 0; + virtual ShowDurations::OrNot showDurations() const = 0; + virtual TestSpec const& testSpec() const = 0; + virtual bool hasTestFilters() const = 0; + virtual RunTests::InWhatOrder runOrder() const = 0; + virtual unsigned int rngSeed() const = 0; + virtual int benchmarkResolutionMultiple() const = 0; + virtual UseColour::YesOrNo useColour() const = 0; + virtual std::vector const& getSectionsToRun() const = 0; + virtual Verbosity verbosity() const = 0; + }; + + using IConfigPtr = std::shared_ptr; +} + +// end catch_interfaces_config.h +// Libstdc++ doesn't like incomplete classes for unique_ptr + +#include +#include +#include + +#ifndef CATCH_CONFIG_CONSOLE_WIDTH +#define CATCH_CONFIG_CONSOLE_WIDTH 80 +#endif + +namespace Catch { + + struct IStream; + + struct ConfigData { + bool listTests = false; + bool listTags = false; + bool listReporters = false; + bool listTestNamesOnly = false; + + bool showSuccessfulTests = false; + bool shouldDebugBreak = false; + bool noThrow = false; + bool showHelp = false; + bool showInvisibles = false; + bool filenamesAsTags = false; + bool libIdentify = false; + + int abortAfter = -1; + unsigned int rngSeed = 0; + int benchmarkResolutionMultiple = 100; + + Verbosity verbosity = Verbosity::Normal; + WarnAbout::What warnings = WarnAbout::Nothing; + ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter; + RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder; + UseColour::YesOrNo useColour = UseColour::Auto; + WaitForKeypress::When waitForKeypress = WaitForKeypress::Never; + + std::string outputFilename; + std::string name; + std::string processName; + + std::vector reporterNames; + std::vector testsOrTags; + std::vector sectionsToRun; + }; + + class Config : public IConfig { + public: + + Config() = default; + Config( ConfigData const& data ); + virtual ~Config() = default; + + std::string const& getFilename() const; + + bool listTests() const; + bool listTestNamesOnly() const; + bool listTags() const; + bool listReporters() const; + + std::string getProcessName() const; + + std::vector const& getReporterNames() const; + std::vector const& getTestsOrTags() const; + std::vector const& getSectionsToRun() const override; + + virtual TestSpec const& testSpec() const override; + bool hasTestFilters() const override; + + bool showHelp() const; + + // IConfig interface + bool allowThrows() const override; + std::ostream& stream() const override; + std::string name() const override; + bool includeSuccessfulResults() const override; + bool warnAboutMissingAssertions() const override; + bool warnAboutNoTests() const override; + ShowDurations::OrNot showDurations() const override; + RunTests::InWhatOrder runOrder() const override; + unsigned int rngSeed() const override; + int benchmarkResolutionMultiple() const override; + UseColour::YesOrNo useColour() const override; + bool shouldDebugBreak() const override; + int abortAfter() const override; + bool showInvisibles() const override; + Verbosity verbosity() const override; + + private: + + IStream const* openStream(); + ConfigData m_data; + + std::unique_ptr m_stream; + TestSpec m_testSpec; + bool m_hasTestFilters = false; + }; + +} // end namespace Catch + +// end catch_config.hpp +// start catch_assertionresult.h + +#include + +namespace Catch { + + struct AssertionResultData + { + AssertionResultData() = delete; + + AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression ); + + std::string message; + mutable std::string reconstructedExpression; + LazyExpression lazyExpression; + ResultWas::OfType resultType; + + std::string reconstructExpression() const; + }; + + class AssertionResult { + public: + AssertionResult() = delete; + AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); + + bool isOk() const; + bool succeeded() const; + ResultWas::OfType getResultType() const; + bool hasExpression() const; + bool hasMessage() const; + std::string getExpression() const; + std::string getExpressionInMacro() const; + bool hasExpandedExpression() const; + std::string getExpandedExpression() const; + std::string getMessage() const; + SourceLineInfo getSourceInfo() const; + StringRef getTestMacroName() const; + + //protected: + AssertionInfo m_info; + AssertionResultData m_resultData; + }; + +} // end namespace Catch + +// end catch_assertionresult.h +// start catch_option.hpp + +namespace Catch { + + // An optional type + template + class Option { + public: + Option() : nullableValue( nullptr ) {} + Option( T const& _value ) + : nullableValue( new( storage ) T( _value ) ) + {} + Option( Option const& _other ) + : nullableValue( _other ? new( storage ) T( *_other ) : nullptr ) + {} + + ~Option() { + reset(); + } + + Option& operator= ( Option const& _other ) { + if( &_other != this ) { + reset(); + if( _other ) + nullableValue = new( storage ) T( *_other ); + } + return *this; + } + Option& operator = ( T const& _value ) { + reset(); + nullableValue = new( storage ) T( _value ); + return *this; + } + + void reset() { + if( nullableValue ) + nullableValue->~T(); + nullableValue = nullptr; + } + + T& operator*() { return *nullableValue; } + T const& operator*() const { return *nullableValue; } + T* operator->() { return nullableValue; } + const T* operator->() const { return nullableValue; } + + T valueOr( T const& defaultValue ) const { + return nullableValue ? *nullableValue : defaultValue; + } + + bool some() const { return nullableValue != nullptr; } + bool none() const { return nullableValue == nullptr; } + + bool operator !() const { return nullableValue == nullptr; } + explicit operator bool() const { + return some(); + } + + private: + T *nullableValue; + alignas(alignof(T)) char storage[sizeof(T)]; + }; + +} // end namespace Catch + +// end catch_option.hpp +#include +#include +#include +#include +#include + +namespace Catch { + + struct ReporterConfig { + explicit ReporterConfig( IConfigPtr const& _fullConfig ); + + ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ); + + std::ostream& stream() const; + IConfigPtr fullConfig() const; + + private: + std::ostream* m_stream; + IConfigPtr m_fullConfig; + }; + + struct ReporterPreferences { + bool shouldRedirectStdOut = false; + }; + + template + struct LazyStat : Option { + LazyStat& operator=( T const& _value ) { + Option::operator=( _value ); + used = false; + return *this; + } + void reset() { + Option::reset(); + used = false; + } + bool used = false; + }; + + struct TestRunInfo { + TestRunInfo( std::string const& _name ); + std::string name; + }; + struct GroupInfo { + GroupInfo( std::string const& _name, + std::size_t _groupIndex, + std::size_t _groupsCount ); + + std::string name; + std::size_t groupIndex; + std::size_t groupsCounts; + }; + + struct AssertionStats { + AssertionStats( AssertionResult const& _assertionResult, + std::vector const& _infoMessages, + Totals const& _totals ); + + AssertionStats( AssertionStats const& ) = default; + AssertionStats( AssertionStats && ) = default; + AssertionStats& operator = ( AssertionStats const& ) = default; + AssertionStats& operator = ( AssertionStats && ) = default; + virtual ~AssertionStats(); + + AssertionResult assertionResult; + std::vector infoMessages; + Totals totals; + }; + + struct SectionStats { + SectionStats( SectionInfo const& _sectionInfo, + Counts const& _assertions, + double _durationInSeconds, + bool _missingAssertions ); + SectionStats( SectionStats const& ) = default; + SectionStats( SectionStats && ) = default; + SectionStats& operator = ( SectionStats const& ) = default; + SectionStats& operator = ( SectionStats && ) = default; + virtual ~SectionStats(); + + SectionInfo sectionInfo; + Counts assertions; + double durationInSeconds; + bool missingAssertions; + }; + + struct TestCaseStats { + TestCaseStats( TestCaseInfo const& _testInfo, + Totals const& _totals, + std::string const& _stdOut, + std::string const& _stdErr, + bool _aborting ); + + TestCaseStats( TestCaseStats const& ) = default; + TestCaseStats( TestCaseStats && ) = default; + TestCaseStats& operator = ( TestCaseStats const& ) = default; + TestCaseStats& operator = ( TestCaseStats && ) = default; + virtual ~TestCaseStats(); + + TestCaseInfo testInfo; + Totals totals; + std::string stdOut; + std::string stdErr; + bool aborting; + }; + + struct TestGroupStats { + TestGroupStats( GroupInfo const& _groupInfo, + Totals const& _totals, + bool _aborting ); + TestGroupStats( GroupInfo const& _groupInfo ); + + TestGroupStats( TestGroupStats const& ) = default; + TestGroupStats( TestGroupStats && ) = default; + TestGroupStats& operator = ( TestGroupStats const& ) = default; + TestGroupStats& operator = ( TestGroupStats && ) = default; + virtual ~TestGroupStats(); + + GroupInfo groupInfo; + Totals totals; + bool aborting; + }; + + struct TestRunStats { + TestRunStats( TestRunInfo const& _runInfo, + Totals const& _totals, + bool _aborting ); + + TestRunStats( TestRunStats const& ) = default; + TestRunStats( TestRunStats && ) = default; + TestRunStats& operator = ( TestRunStats const& ) = default; + TestRunStats& operator = ( TestRunStats && ) = default; + virtual ~TestRunStats(); + + TestRunInfo runInfo; + Totals totals; + bool aborting; + }; + + struct BenchmarkInfo { + std::string name; + }; + struct BenchmarkStats { + BenchmarkInfo info; + std::size_t iterations; + uint64_t elapsedTimeInNanoseconds; + }; + + struct IStreamingReporter { + virtual ~IStreamingReporter() = default; + + // Implementing class must also provide the following static methods: + // static std::string getDescription(); + // static std::set getSupportedVerbosities() + + virtual ReporterPreferences getPreferences() const = 0; + + virtual void noMatchingTestCases( std::string const& spec ) = 0; + + virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; + virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0; + + virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; + virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; + + // *** experimental *** + virtual void benchmarkStarting( BenchmarkInfo const& ) {} + + virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; + + // The return value indicates if the messages buffer should be cleared: + virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0; + + // *** experimental *** + virtual void benchmarkEnded( BenchmarkStats const& ) {} + + virtual void sectionEnded( SectionStats const& sectionStats ) = 0; + virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; + virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; + virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; + + virtual void skipTest( TestCaseInfo const& testInfo ) = 0; + + // Default empty implementation provided + virtual void fatalErrorEncountered( StringRef name ); + + virtual bool isMulti() const; + }; + using IStreamingReporterPtr = std::unique_ptr; + + struct IReporterFactory { + virtual ~IReporterFactory(); + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0; + virtual std::string getDescription() const = 0; + }; + using IReporterFactoryPtr = std::shared_ptr; + + struct IReporterRegistry { + using FactoryMap = std::map; + using Listeners = std::vector; + + virtual ~IReporterRegistry(); + virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0; + virtual FactoryMap const& getFactories() const = 0; + virtual Listeners const& getListeners() const = 0; + }; + + void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ); + +} // end namespace Catch + +// end catch_interfaces_reporter.h +#include +#include +#include +#include +#include +#include +#include + +namespace Catch { + void prepareExpandedExpression(AssertionResult& result); + + // Returns double formatted as %.3f (format expected on output) + std::string getFormattedDuration( double duration ); + + template + struct StreamingReporterBase : IStreamingReporter { + + StreamingReporterBase( ReporterConfig const& _config ) + : m_config( _config.fullConfig() ), + stream( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = false; + if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) + throw std::domain_error( "Verbosity level not supported by this reporter" ); + } + + ReporterPreferences getPreferences() const override { + return m_reporterPrefs; + } + + static std::set getSupportedVerbosities() { + return { Verbosity::Normal }; + } + + ~StreamingReporterBase() override = default; + + void noMatchingTestCases(std::string const&) override {} + + void testRunStarting(TestRunInfo const& _testRunInfo) override { + currentTestRunInfo = _testRunInfo; + } + void testGroupStarting(GroupInfo const& _groupInfo) override { + currentGroupInfo = _groupInfo; + } + + void testCaseStarting(TestCaseInfo const& _testInfo) override { + currentTestCaseInfo = _testInfo; + } + void sectionStarting(SectionInfo const& _sectionInfo) override { + m_sectionStack.push_back(_sectionInfo); + } + + void sectionEnded(SectionStats const& /* _sectionStats */) override { + m_sectionStack.pop_back(); + } + void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override { + currentTestCaseInfo.reset(); + } + void testGroupEnded(TestGroupStats const& /* _testGroupStats */) override { + currentGroupInfo.reset(); + } + void testRunEnded(TestRunStats const& /* _testRunStats */) override { + currentTestCaseInfo.reset(); + currentGroupInfo.reset(); + currentTestRunInfo.reset(); + } + + void skipTest(TestCaseInfo const&) override { + // Don't do anything with this by default. + // It can optionally be overridden in the derived class. + } + + IConfigPtr m_config; + std::ostream& stream; + + LazyStat currentTestRunInfo; + LazyStat currentGroupInfo; + LazyStat currentTestCaseInfo; + + std::vector m_sectionStack; + ReporterPreferences m_reporterPrefs; + }; + + template + struct CumulativeReporterBase : IStreamingReporter { + template + struct Node { + explicit Node( T const& _value ) : value( _value ) {} + virtual ~Node() {} + + using ChildNodes = std::vector>; + T value; + ChildNodes children; + }; + struct SectionNode { + explicit SectionNode(SectionStats const& _stats) : stats(_stats) {} + virtual ~SectionNode() = default; + + bool operator == (SectionNode const& other) const { + return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; + } + bool operator == (std::shared_ptr const& other) const { + return operator==(*other); + } + + SectionStats stats; + using ChildSections = std::vector>; + using Assertions = std::vector; + ChildSections childSections; + Assertions assertions; + std::string stdOut; + std::string stdErr; + }; + + struct BySectionInfo { + BySectionInfo( SectionInfo const& other ) : m_other( other ) {} + BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} + bool operator() (std::shared_ptr const& node) const { + return ((node->stats.sectionInfo.name == m_other.name) && + (node->stats.sectionInfo.lineInfo == m_other.lineInfo)); + } + void operator=(BySectionInfo const&) = delete; + + private: + SectionInfo const& m_other; + }; + + using TestCaseNode = Node; + using TestGroupNode = Node; + using TestRunNode = Node; + + CumulativeReporterBase( ReporterConfig const& _config ) + : m_config( _config.fullConfig() ), + stream( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = false; + if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) + throw std::domain_error( "Verbosity level not supported by this reporter" ); + } + ~CumulativeReporterBase() override = default; + + ReporterPreferences getPreferences() const override { + return m_reporterPrefs; + } + + static std::set getSupportedVerbosities() { + return { Verbosity::Normal }; + } + + void testRunStarting( TestRunInfo const& ) override {} + void testGroupStarting( GroupInfo const& ) override {} + + void testCaseStarting( TestCaseInfo const& ) override {} + + void sectionStarting( SectionInfo const& sectionInfo ) override { + SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); + std::shared_ptr node; + if( m_sectionStack.empty() ) { + if( !m_rootSection ) + m_rootSection = std::make_shared( incompleteStats ); + node = m_rootSection; + } + else { + SectionNode& parentNode = *m_sectionStack.back(); + auto it = + std::find_if( parentNode.childSections.begin(), + parentNode.childSections.end(), + BySectionInfo( sectionInfo ) ); + if( it == parentNode.childSections.end() ) { + node = std::make_shared( incompleteStats ); + parentNode.childSections.push_back( node ); + } + else + node = *it; + } + m_sectionStack.push_back( node ); + m_deepestSection = std::move(node); + } + + void assertionStarting(AssertionInfo const&) override {} + + bool assertionEnded(AssertionStats const& assertionStats) override { + assert(!m_sectionStack.empty()); + // AssertionResult holds a pointer to a temporary DecomposedExpression, + // which getExpandedExpression() calls to build the expression string. + // Our section stack copy of the assertionResult will likely outlive the + // temporary, so it must be expanded or discarded now to avoid calling + // a destroyed object later. + prepareExpandedExpression(const_cast( assertionStats.assertionResult ) ); + SectionNode& sectionNode = *m_sectionStack.back(); + sectionNode.assertions.push_back(assertionStats); + return true; + } + void sectionEnded(SectionStats const& sectionStats) override { + assert(!m_sectionStack.empty()); + SectionNode& node = *m_sectionStack.back(); + node.stats = sectionStats; + m_sectionStack.pop_back(); + } + void testCaseEnded(TestCaseStats const& testCaseStats) override { + auto node = std::make_shared(testCaseStats); + assert(m_sectionStack.size() == 0); + node->children.push_back(m_rootSection); + m_testCases.push_back(node); + m_rootSection.reset(); + + assert(m_deepestSection); + m_deepestSection->stdOut = testCaseStats.stdOut; + m_deepestSection->stdErr = testCaseStats.stdErr; + } + void testGroupEnded(TestGroupStats const& testGroupStats) override { + auto node = std::make_shared(testGroupStats); + node->children.swap(m_testCases); + m_testGroups.push_back(node); + } + void testRunEnded(TestRunStats const& testRunStats) override { + auto node = std::make_shared(testRunStats); + node->children.swap(m_testGroups); + m_testRuns.push_back(node); + testRunEndedCumulative(); + } + virtual void testRunEndedCumulative() = 0; + + void skipTest(TestCaseInfo const&) override {} + + IConfigPtr m_config; + std::ostream& stream; + std::vector m_assertions; + std::vector>> m_sections; + std::vector> m_testCases; + std::vector> m_testGroups; + + std::vector> m_testRuns; + + std::shared_ptr m_rootSection; + std::shared_ptr m_deepestSection; + std::vector> m_sectionStack; + ReporterPreferences m_reporterPrefs; + }; + + template + char const* getLineOfChars() { + static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; + if( !*line ) { + std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); + line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; + } + return line; + } + + struct TestEventListenerBase : StreamingReporterBase { + TestEventListenerBase( ReporterConfig const& _config ); + + void assertionStarting(AssertionInfo const&) override; + bool assertionEnded(AssertionStats const&) override; + }; + +} // end namespace Catch + +// end catch_reporter_bases.hpp +// start catch_console_colour.h + +namespace Catch { + + struct Colour { + enum Code { + None = 0, + + White, + Red, + Green, + Blue, + Cyan, + Yellow, + Grey, + + Bright = 0x10, + + BrightRed = Bright | Red, + BrightGreen = Bright | Green, + LightGrey = Bright | Grey, + BrightWhite = Bright | White, + BrightYellow = Bright | Yellow, + + // By intention + FileName = LightGrey, + Warning = BrightYellow, + ResultError = BrightRed, + ResultSuccess = BrightGreen, + ResultExpectedFailure = Warning, + + Error = BrightRed, + Success = Green, + + OriginalExpression = Cyan, + ReconstructedExpression = BrightYellow, + + SecondaryText = LightGrey, + Headers = White + }; + + // Use constructed object for RAII guard + Colour( Code _colourCode ); + Colour( Colour&& other ) noexcept; + Colour& operator=( Colour&& other ) noexcept; + ~Colour(); + + // Use static method for one-shot changes + static void use( Code _colourCode ); + + private: + bool m_moved = false; + }; + + std::ostream& operator << ( std::ostream& os, Colour const& ); + +} // end namespace Catch + +// end catch_console_colour.h +// start catch_reporter_registrars.hpp + + +namespace Catch { + + template + class ReporterRegistrar { + + class ReporterFactory : public IReporterFactory { + + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { + return std::unique_ptr( new T( config ) ); + } + + virtual std::string getDescription() const override { + return T::getDescription(); + } + }; + + public: + + explicit ReporterRegistrar( std::string const& name ) { + getMutableRegistryHub().registerReporter( name, std::make_shared() ); + } + }; + + template + class ListenerRegistrar { + + class ListenerFactory : public IReporterFactory { + + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { + return std::unique_ptr( new T( config ) ); + } + virtual std::string getDescription() const override { + return std::string(); + } + }; + + public: + + ListenerRegistrar() { + getMutableRegistryHub().registerListener( std::make_shared() ); + } + }; +} + +#if !defined(CATCH_CONFIG_DISABLE) + +#define CATCH_REGISTER_REPORTER( name, reporterType ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS + +#define CATCH_REGISTER_LISTENER( listenerType ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ListenerRegistrar catch_internal_RegistrarFor##listenerType; } \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +#else // CATCH_CONFIG_DISABLE + +#define CATCH_REGISTER_REPORTER(name, reporterType) +#define CATCH_REGISTER_LISTENER(listenerType) + +#endif // CATCH_CONFIG_DISABLE + +// end catch_reporter_registrars.hpp +// Allow users to base their work off existing reporters +// start catch_reporter_compact.h + +namespace Catch { + + struct CompactReporter : StreamingReporterBase { + + using StreamingReporterBase::StreamingReporterBase; + + ~CompactReporter() override; + + static std::string getDescription(); + + ReporterPreferences getPreferences() const override; + + void noMatchingTestCases(std::string const& spec) override; + + void assertionStarting(AssertionInfo const&) override; + + bool assertionEnded(AssertionStats const& _assertionStats) override; + + void sectionEnded(SectionStats const& _sectionStats) override; + + void testRunEnded(TestRunStats const& _testRunStats) override; + + }; + +} // end namespace Catch + +// end catch_reporter_compact.h +// start catch_reporter_console.h + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch + // Note that 4062 (not all labels are handled + // and default is missing) is enabled +#endif + +namespace Catch { + // Fwd decls + struct SummaryColumn; + class TablePrinter; + + struct ConsoleReporter : StreamingReporterBase { + std::unique_ptr m_tablePrinter; + + ConsoleReporter(ReporterConfig const& config); + ~ConsoleReporter() override; + static std::string getDescription(); + + void noMatchingTestCases(std::string const& spec) override; + + void assertionStarting(AssertionInfo const&) override; + + bool assertionEnded(AssertionStats const& _assertionStats) override; + + void sectionStarting(SectionInfo const& _sectionInfo) override; + void sectionEnded(SectionStats const& _sectionStats) override; + + void benchmarkStarting(BenchmarkInfo const& info) override; + void benchmarkEnded(BenchmarkStats const& stats) override; + + void testCaseEnded(TestCaseStats const& _testCaseStats) override; + void testGroupEnded(TestGroupStats const& _testGroupStats) override; + void testRunEnded(TestRunStats const& _testRunStats) override; + + private: + + void lazyPrint(); + + void lazyPrintWithoutClosingBenchmarkTable(); + void lazyPrintRunInfo(); + void lazyPrintGroupInfo(); + void printTestCaseAndSectionHeader(); + + void printClosedHeader(std::string const& _name); + void printOpenHeader(std::string const& _name); + + // if string has a : in first line will set indent to follow it on + // subsequent lines + void printHeaderString(std::string const& _string, std::size_t indent = 0); + + void printTotals(Totals const& totals); + void printSummaryRow(std::string const& label, std::vector const& cols, std::size_t row); + + void printTotalsDivider(Totals const& totals); + void printSummaryDivider(); + + private: + bool m_headerPrinted = false; + }; + +} // end namespace Catch + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +// end catch_reporter_console.h +// start catch_reporter_junit.h + +// start catch_xmlwriter.h + +#include + +namespace Catch { + + class XmlEncode { + public: + enum ForWhat { ForTextNodes, ForAttributes }; + + XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes ); + + void encodeTo( std::ostream& os ) const; + + friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ); + + private: + std::string m_str; + ForWhat m_forWhat; + }; + + class XmlWriter { + public: + + class ScopedElement { + public: + ScopedElement( XmlWriter* writer ); + + ScopedElement( ScopedElement&& other ) noexcept; + ScopedElement& operator=( ScopedElement&& other ) noexcept; + + ~ScopedElement(); + + ScopedElement& writeText( std::string const& text, bool indent = true ); + + template + ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { + m_writer->writeAttribute( name, attribute ); + return *this; + } + + private: + mutable XmlWriter* m_writer = nullptr; + }; + + XmlWriter( std::ostream& os = Catch::cout() ); + ~XmlWriter(); + + XmlWriter( XmlWriter const& ) = delete; + XmlWriter& operator=( XmlWriter const& ) = delete; + + XmlWriter& startElement( std::string const& name ); + + ScopedElement scopedElement( std::string const& name ); + + XmlWriter& endElement(); + + XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ); + + XmlWriter& writeAttribute( std::string const& name, bool attribute ); + + template + XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { + ReusableStringStream rss; + rss << attribute; + return writeAttribute( name, rss.str() ); + } + + XmlWriter& writeText( std::string const& text, bool indent = true ); + + XmlWriter& writeComment( std::string const& text ); + + void writeStylesheetRef( std::string const& url ); + + XmlWriter& writeBlankLine(); + + void ensureTagClosed(); + + private: + + void writeDeclaration(); + + void newlineIfNecessary(); + + bool m_tagIsOpen = false; + bool m_needsNewline = false; + std::vector m_tags; + std::string m_indent; + std::ostream& m_os; + }; + +} + +// end catch_xmlwriter.h +namespace Catch { + + class JunitReporter : public CumulativeReporterBase { + public: + JunitReporter(ReporterConfig const& _config); + + ~JunitReporter() override; + + static std::string getDescription(); + + void noMatchingTestCases(std::string const& /*spec*/) override; + + void testRunStarting(TestRunInfo const& runInfo) override; + + void testGroupStarting(GroupInfo const& groupInfo) override; + + void testCaseStarting(TestCaseInfo const& testCaseInfo) override; + bool assertionEnded(AssertionStats const& assertionStats) override; + + void testCaseEnded(TestCaseStats const& testCaseStats) override; + + void testGroupEnded(TestGroupStats const& testGroupStats) override; + + void testRunEndedCumulative() override; + + void writeGroup(TestGroupNode const& groupNode, double suiteTime); + + void writeTestCase(TestCaseNode const& testCaseNode); + + void writeSection(std::string const& className, + std::string const& rootName, + SectionNode const& sectionNode); + + void writeAssertions(SectionNode const& sectionNode); + void writeAssertion(AssertionStats const& stats); + + XmlWriter xml; + Timer suiteTimer; + std::string stdOutForSuite; + std::string stdErrForSuite; + unsigned int unexpectedExceptions = 0; + bool m_okToFail = false; + }; + +} // end namespace Catch + +// end catch_reporter_junit.h +// start catch_reporter_xml.h + +namespace Catch { + class XmlReporter : public StreamingReporterBase { + public: + XmlReporter(ReporterConfig const& _config); + + ~XmlReporter() override; + + static std::string getDescription(); + + virtual std::string getStylesheetRef() const; + + void writeSourceInfo(SourceLineInfo const& sourceInfo); + + public: // StreamingReporterBase + + void noMatchingTestCases(std::string const& s) override; + + void testRunStarting(TestRunInfo const& testInfo) override; + + void testGroupStarting(GroupInfo const& groupInfo) override; + + void testCaseStarting(TestCaseInfo const& testInfo) override; + + void sectionStarting(SectionInfo const& sectionInfo) override; + + void assertionStarting(AssertionInfo const&) override; + + bool assertionEnded(AssertionStats const& assertionStats) override; + + void sectionEnded(SectionStats const& sectionStats) override; + + void testCaseEnded(TestCaseStats const& testCaseStats) override; + + void testGroupEnded(TestGroupStats const& testGroupStats) override; + + void testRunEnded(TestRunStats const& testRunStats) override; + + private: + Timer m_testCaseTimer; + XmlWriter m_xml; + int m_sectionDepth = 0; + }; + +} // end namespace Catch + +// end catch_reporter_xml.h + +// end catch_external_interfaces.h +#endif + +#endif // ! CATCH_CONFIG_IMPL_ONLY + +#ifdef CATCH_IMPL +// start catch_impl.hpp + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#endif + +// Keep these here for external reporters +// start catch_test_case_tracker.h + +#include +#include +#include + +namespace Catch { +namespace TestCaseTracking { + + struct NameAndLocation { + std::string name; + SourceLineInfo location; + + NameAndLocation( std::string const& _name, SourceLineInfo const& _location ); + }; + + struct ITracker; + + using ITrackerPtr = std::shared_ptr; + + struct ITracker { + virtual ~ITracker(); + + // static queries + virtual NameAndLocation const& nameAndLocation() const = 0; + + // dynamic queries + virtual bool isComplete() const = 0; // Successfully completed or failed + virtual bool isSuccessfullyCompleted() const = 0; + virtual bool isOpen() const = 0; // Started but not complete + virtual bool hasChildren() const = 0; + + virtual ITracker& parent() = 0; + + // actions + virtual void close() = 0; // Successfully complete + virtual void fail() = 0; + virtual void markAsNeedingAnotherRun() = 0; + + virtual void addChild( ITrackerPtr const& child ) = 0; + virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0; + virtual void openChild() = 0; + + // Debug/ checking + virtual bool isSectionTracker() const = 0; + virtual bool isIndexTracker() const = 0; + }; + + class TrackerContext { + + enum RunState { + NotStarted, + Executing, + CompletedCycle + }; + + ITrackerPtr m_rootTracker; + ITracker* m_currentTracker = nullptr; + RunState m_runState = NotStarted; + + public: + + static TrackerContext& instance(); + + ITracker& startRun(); + void endRun(); + + void startCycle(); + void completeCycle(); + + bool completedCycle() const; + ITracker& currentTracker(); + void setCurrentTracker( ITracker* tracker ); + }; + + class TrackerBase : public ITracker { + protected: + enum CycleState { + NotStarted, + Executing, + ExecutingChildren, + NeedsAnotherRun, + CompletedSuccessfully, + Failed + }; + + class TrackerHasName { + NameAndLocation m_nameAndLocation; + public: + TrackerHasName( NameAndLocation const& nameAndLocation ); + bool operator ()( ITrackerPtr const& tracker ) const; + }; + + using Children = std::vector; + NameAndLocation m_nameAndLocation; + TrackerContext& m_ctx; + ITracker* m_parent; + Children m_children; + CycleState m_runState = NotStarted; + + public: + TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); + + NameAndLocation const& nameAndLocation() const override; + bool isComplete() const override; + bool isSuccessfullyCompleted() const override; + bool isOpen() const override; + bool hasChildren() const override; + + void addChild( ITrackerPtr const& child ) override; + + ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override; + ITracker& parent() override; + + void openChild() override; + + bool isSectionTracker() const override; + bool isIndexTracker() const override; + + void open(); + + void close() override; + void fail() override; + void markAsNeedingAnotherRun() override; + + private: + void moveToParent(); + void moveToThis(); + }; + + class SectionTracker : public TrackerBase { + std::vector m_filters; + public: + SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); + + bool isSectionTracker() const override; + + static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ); + + void tryOpen(); + + void addInitialFilters( std::vector const& filters ); + void addNextFilters( std::vector const& filters ); + }; + + class IndexTracker : public TrackerBase { + int m_size; + int m_index = -1; + public: + IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ); + + bool isIndexTracker() const override; + void close() override; + + static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ); + + int index() const; + + void moveNext(); + }; + +} // namespace TestCaseTracking + +using TestCaseTracking::ITracker; +using TestCaseTracking::TrackerContext; +using TestCaseTracking::SectionTracker; +using TestCaseTracking::IndexTracker; + +} // namespace Catch + +// end catch_test_case_tracker.h + +// start catch_leak_detector.h + +namespace Catch { + + struct LeakDetector { + LeakDetector(); + }; + +} +// end catch_leak_detector.h +// Cpp files will be included in the single-header file here +// start catch_approx.cpp + +#include +#include + +namespace { + +// Performs equivalent check of std::fabs(lhs - rhs) <= margin +// But without the subtraction to allow for INFINITY in comparison +bool marginComparison(double lhs, double rhs, double margin) { + return (lhs + margin >= rhs) && (rhs + margin >= lhs); +} + +} + +namespace Catch { +namespace Detail { + + Approx::Approx ( double value ) + : m_epsilon( std::numeric_limits::epsilon()*100 ), + m_margin( 0.0 ), + m_scale( 0.0 ), + m_value( value ) + {} + + Approx Approx::custom() { + return Approx( 0 ); + } + + std::string Approx::toString() const { + ReusableStringStream rss; + rss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; + return rss.str(); + } + + bool Approx::equalityComparisonImpl(const double other) const { + // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value + // Thanks to Richard Harris for his help refining the scaled margin value + return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value))); + } + +} // end namespace Detail + +std::string StringMaker::convert(Catch::Detail::Approx const& value) { + return value.toString(); +} + +} // end namespace Catch +// end catch_approx.cpp +// start catch_assertionhandler.cpp + +// start catch_context.h + +#include + +namespace Catch { + + struct IResultCapture; + struct IRunner; + struct IConfig; + struct IMutableContext; + + using IConfigPtr = std::shared_ptr; + + struct IContext + { + virtual ~IContext(); + + virtual IResultCapture* getResultCapture() = 0; + virtual IRunner* getRunner() = 0; + virtual IConfigPtr const& getConfig() const = 0; + }; + + struct IMutableContext : IContext + { + virtual ~IMutableContext(); + virtual void setResultCapture( IResultCapture* resultCapture ) = 0; + virtual void setRunner( IRunner* runner ) = 0; + virtual void setConfig( IConfigPtr const& config ) = 0; + + private: + static IMutableContext *currentContext; + friend IMutableContext& getCurrentMutableContext(); + friend void cleanUpContext(); + static void createContext(); + }; + + inline IMutableContext& getCurrentMutableContext() + { + if( !IMutableContext::currentContext ) + IMutableContext::createContext(); + return *IMutableContext::currentContext; + } + + inline IContext& getCurrentContext() + { + return getCurrentMutableContext(); + } + + void cleanUpContext(); +} + +// end catch_context.h +// start catch_debugger.h + +namespace Catch { + bool isDebuggerActive(); +} + +#ifdef CATCH_PLATFORM_MAC + + #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ + +#elif defined(CATCH_PLATFORM_LINUX) + // If we can use inline assembler, do it because this allows us to break + // directly at the location of the failing check instead of breaking inside + // raise() called from it, i.e. one stack frame below. + #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) + #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */ + #else // Fall back to the generic way. + #include + + #define CATCH_TRAP() raise(SIGTRAP) + #endif +#elif defined(_MSC_VER) + #define CATCH_TRAP() __debugbreak() +#elif defined(__MINGW32__) + extern "C" __declspec(dllimport) void __stdcall DebugBreak(); + #define CATCH_TRAP() DebugBreak() +#endif + +#ifdef CATCH_TRAP + #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } +#else + namespace Catch { + inline void doNothing() {} + } + #define CATCH_BREAK_INTO_DEBUGGER() Catch::doNothing() +#endif + +// end catch_debugger.h +// start catch_run_context.h + +// start catch_fatal_condition.h + +// start catch_windows_h_proxy.h + + +#if defined(CATCH_PLATFORM_WINDOWS) + +#if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) +# define CATCH_DEFINED_NOMINMAX +# define NOMINMAX +#endif +#if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) +# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif + +#ifdef __AFXDLL +#include +#else +#include +#endif + +#ifdef CATCH_DEFINED_NOMINMAX +# undef NOMINMAX +#endif +#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN +# undef WIN32_LEAN_AND_MEAN +#endif + +#endif // defined(CATCH_PLATFORM_WINDOWS) + +// end catch_windows_h_proxy.h +#if defined( CATCH_CONFIG_WINDOWS_SEH ) + +namespace Catch { + + struct FatalConditionHandler { + + static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo); + FatalConditionHandler(); + static void reset(); + ~FatalConditionHandler(); + + private: + static bool isSet; + static ULONG guaranteeSize; + static PVOID exceptionHandlerHandle; + }; + +} // namespace Catch + +#elif defined ( CATCH_CONFIG_POSIX_SIGNALS ) + +#include + +namespace Catch { + + struct FatalConditionHandler { + + static bool isSet; + static struct sigaction oldSigActions[]; + static stack_t oldSigStack; + static char altStackMem[]; + + static void handleSignal( int sig ); + + FatalConditionHandler(); + ~FatalConditionHandler(); + static void reset(); + }; + +} // namespace Catch + +#else + +namespace Catch { + struct FatalConditionHandler { + void reset(); + }; +} + +#endif + +// end catch_fatal_condition.h +#include + +namespace Catch { + + struct IMutableContext; + + /////////////////////////////////////////////////////////////////////////// + + class RunContext : public IResultCapture, public IRunner { + + public: + RunContext( RunContext const& ) = delete; + RunContext& operator =( RunContext const& ) = delete; + + explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr&& reporter ); + + ~RunContext() override; + + void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ); + void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ); + + Totals runTest(TestCase const& testCase); + + IConfigPtr config() const; + IStreamingReporter& reporter() const; + + public: // IResultCapture + + // Assertion handlers + void handleExpr + ( AssertionInfo const& info, + ITransientExpression const& expr, + AssertionReaction& reaction ) override; + void handleMessage + ( AssertionInfo const& info, + ResultWas::OfType resultType, + StringRef const& message, + AssertionReaction& reaction ) override; + void handleUnexpectedExceptionNotThrown + ( AssertionInfo const& info, + AssertionReaction& reaction ) override; + void handleUnexpectedInflightException + ( AssertionInfo const& info, + std::string const& message, + AssertionReaction& reaction ) override; + void handleIncomplete + ( AssertionInfo const& info ) override; + void handleNonExpr + ( AssertionInfo const &info, + ResultWas::OfType resultType, + AssertionReaction &reaction ) override; + + bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override; + + void sectionEnded( SectionEndInfo const& endInfo ) override; + void sectionEndedEarly( SectionEndInfo const& endInfo ) override; + + void benchmarkStarting( BenchmarkInfo const& info ) override; + void benchmarkEnded( BenchmarkStats const& stats ) override; + + void pushScopedMessage( MessageInfo const& message ) override; + void popScopedMessage( MessageInfo const& message ) override; + + std::string getCurrentTestName() const override; + + const AssertionResult* getLastResult() const override; + + void exceptionEarlyReported() override; + + void handleFatalErrorCondition( StringRef message ) override; + + bool lastAssertionPassed() override; + + void assertionPassed() override; + + public: + // !TBD We need to do this another way! + bool aborting() const final; + + private: + + void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ); + void invokeActiveTestCase(); + + void resetAssertionInfo(); + bool testForMissingAssertions( Counts& assertions ); + + void assertionEnded( AssertionResult const& result ); + void reportExpr + ( AssertionInfo const &info, + ResultWas::OfType resultType, + ITransientExpression const *expr, + bool negated ); + + void populateReaction( AssertionReaction& reaction ); + + private: + + void handleUnfinishedSections(); + + TestRunInfo m_runInfo; + IMutableContext& m_context; + TestCase const* m_activeTestCase = nullptr; + ITracker* m_testCaseTracker; + Option m_lastResult; + + IConfigPtr m_config; + Totals m_totals; + IStreamingReporterPtr m_reporter; + std::vector m_messages; + AssertionInfo m_lastAssertionInfo; + std::vector m_unfinishedSections; + std::vector m_activeSections; + TrackerContext m_trackerContext; + bool m_lastAssertionPassed = false; + bool m_shouldReportUnexpected = true; + bool m_includeSuccessfulResults; + }; + +} // end namespace Catch + +// end catch_run_context.h +namespace Catch { + + auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& { + expr.streamReconstructedExpression( os ); + return os; + } + + LazyExpression::LazyExpression( bool isNegated ) + : m_isNegated( isNegated ) + {} + + LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {} + + LazyExpression::operator bool() const { + return m_transientExpression != nullptr; + } + + auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& { + if( lazyExpr.m_isNegated ) + os << "!"; + + if( lazyExpr ) { + if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() ) + os << "(" << *lazyExpr.m_transientExpression << ")"; + else + os << *lazyExpr.m_transientExpression; + } + else { + os << "{** error - unchecked empty expression requested **}"; + } + return os; + } + + AssertionHandler::AssertionHandler + ( StringRef macroName, + SourceLineInfo const& lineInfo, + StringRef capturedExpression, + ResultDisposition::Flags resultDisposition ) + : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition }, + m_resultCapture( getResultCapture() ) + {} + + void AssertionHandler::handleExpr( ITransientExpression const& expr ) { + m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction ); + } + void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) { + m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction ); + } + + auto AssertionHandler::allowThrows() const -> bool { + return getCurrentContext().getConfig()->allowThrows(); + } + + void AssertionHandler::complete() { + setCompleted(); + if( m_reaction.shouldDebugBreak ) { + + // If you find your debugger stopping you here then go one level up on the + // call-stack for the code that caused it (typically a failed assertion) + + // (To go back to the test and change execution, jump over the throw, next) + CATCH_BREAK_INTO_DEBUGGER(); + } + if( m_reaction.shouldThrow ) + throw Catch::TestFailureException(); + } + void AssertionHandler::setCompleted() { + m_completed = true; + } + + void AssertionHandler::handleUnexpectedInflightException() { + m_resultCapture.handleUnexpectedInflightException( m_assertionInfo, Catch::translateActiveException(), m_reaction ); + } + + void AssertionHandler::handleExceptionThrownAsExpected() { + m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); + } + void AssertionHandler::handleExceptionNotThrownAsExpected() { + m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); + } + + void AssertionHandler::handleUnexpectedExceptionNotThrown() { + m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction ); + } + + void AssertionHandler::handleThrowingCallSkipped() { + m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); + } + + // This is the overload that takes a string and infers the Equals matcher from it + // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { + handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); + } + +} // namespace Catch +// end catch_assertionhandler.cpp +// start catch_assertionresult.cpp + +namespace Catch { + AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): + lazyExpression(_lazyExpression), + resultType(_resultType) {} + + std::string AssertionResultData::reconstructExpression() const { + + if( reconstructedExpression.empty() ) { + if( lazyExpression ) { + ReusableStringStream rss; + rss << lazyExpression; + reconstructedExpression = rss.str(); + } + } + return reconstructedExpression; + } + + AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) + : m_info( info ), + m_resultData( data ) + {} + + // Result was a success + bool AssertionResult::succeeded() const { + return Catch::isOk( m_resultData.resultType ); + } + + // Result was a success, or failure is suppressed + bool AssertionResult::isOk() const { + return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); + } + + ResultWas::OfType AssertionResult::getResultType() const { + return m_resultData.resultType; + } + + bool AssertionResult::hasExpression() const { + return m_info.capturedExpression[0] != 0; + } + + bool AssertionResult::hasMessage() const { + return !m_resultData.message.empty(); + } + + std::string AssertionResult::getExpression() const { + if( isFalseTest( m_info.resultDisposition ) ) + return "!(" + m_info.capturedExpression + ")"; + else + return m_info.capturedExpression; + } + + std::string AssertionResult::getExpressionInMacro() const { + std::string expr; + if( m_info.macroName[0] == 0 ) + expr = m_info.capturedExpression; + else { + expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); + expr += m_info.macroName; + expr += "( "; + expr += m_info.capturedExpression; + expr += " )"; + } + return expr; + } + + bool AssertionResult::hasExpandedExpression() const { + return hasExpression() && getExpandedExpression() != getExpression(); + } + + std::string AssertionResult::getExpandedExpression() const { + std::string expr = m_resultData.reconstructExpression(); + return expr.empty() + ? getExpression() + : expr; + } + + std::string AssertionResult::getMessage() const { + return m_resultData.message; + } + SourceLineInfo AssertionResult::getSourceInfo() const { + return m_info.lineInfo; + } + + StringRef AssertionResult::getTestMacroName() const { + return m_info.macroName; + } + +} // end namespace Catch +// end catch_assertionresult.cpp +// start catch_benchmark.cpp + +namespace Catch { + + auto BenchmarkLooper::getResolution() -> uint64_t { + return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple(); + } + + void BenchmarkLooper::reportStart() { + getResultCapture().benchmarkStarting( { m_name } ); + } + auto BenchmarkLooper::needsMoreIterations() -> bool { + auto elapsed = m_timer.getElapsedNanoseconds(); + + // Exponentially increasing iterations until we're confident in our timer resolution + if( elapsed < m_resolution ) { + m_iterationsToRun *= 10; + return true; + } + + getResultCapture().benchmarkEnded( { { m_name }, m_count, elapsed } ); + return false; + } + +} // end namespace Catch +// end catch_benchmark.cpp +// start catch_capture_matchers.cpp + +namespace Catch { + + using StringMatcher = Matchers::Impl::MatcherBase; + + // This is the general overload that takes a any string matcher + // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers + // the Equals matcher (so the header does not mention matchers) + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) { + std::string exceptionMessage = Catch::translateActiveException(); + MatchExpr expr( exceptionMessage, matcher, matcherString ); + handler.handleExpr( expr ); + } + +} // namespace Catch +// end catch_capture_matchers.cpp +// start catch_commandline.cpp + +// start catch_commandline.h + +// start catch_clara.h + +// Use Catch's value for console width (store Clara's off to the side, if present) +#ifdef CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#endif +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1 + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#pragma clang diagnostic ignored "-Wexit-time-destructors" +#pragma clang diagnostic ignored "-Wshadow" +#endif + +// start clara.hpp +// Copyright 2017 Two Blue Cubes Ltd. All rights reserved. +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See https://github.com/philsquared/Clara for more details + +// Clara v1.1.4 + + +#ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80 +#endif + +#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH +#endif + +#ifndef CLARA_CONFIG_OPTIONAL_TYPE +#ifdef __has_include +#if __has_include() && __cplusplus >= 201703L +#include +#define CLARA_CONFIG_OPTIONAL_TYPE std::optional +#endif +#endif +#endif + +// ----------- #included from clara_textflow.hpp ----------- + +// TextFlowCpp +// +// A single-header library for wrapping and laying out basic text, by Phil Nash +// +// This work is licensed under the BSD 2-Clause license. +// See the accompanying LICENSE file, or the one at https://opensource.org/licenses/BSD-2-Clause +// +// This project is hosted at https://github.com/philsquared/textflowcpp + + +#include +#include +#include +#include + +#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80 +#endif + +namespace Catch { namespace clara { namespace TextFlow { + + inline auto isWhitespace( char c ) -> bool { + static std::string chars = " \t\n\r"; + return chars.find( c ) != std::string::npos; + } + inline auto isBreakableBefore( char c ) -> bool { + static std::string chars = "[({<|"; + return chars.find( c ) != std::string::npos; + } + inline auto isBreakableAfter( char c ) -> bool { + static std::string chars = "])}>.,:;*+-=&/\\"; + return chars.find( c ) != std::string::npos; + } + + class Columns; + + class Column { + std::vector m_strings; + size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; + size_t m_indent = 0; + size_t m_initialIndent = std::string::npos; + + public: + class iterator { + friend Column; + + Column const& m_column; + size_t m_stringIndex = 0; + size_t m_pos = 0; + + size_t m_len = 0; + size_t m_end = 0; + bool m_suffix = false; + + iterator( Column const& column, size_t stringIndex ) + : m_column( column ), + m_stringIndex( stringIndex ) + {} + + auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } + + auto isBoundary( size_t at ) const -> bool { + assert( at > 0 ); + assert( at <= line().size() ); + + return at == line().size() || + ( isWhitespace( line()[at] ) && !isWhitespace( line()[at-1] ) ) || + isBreakableBefore( line()[at] ) || + isBreakableAfter( line()[at-1] ); + } + + void calcLength() { + assert( m_stringIndex < m_column.m_strings.size() ); + + m_suffix = false; + auto width = m_column.m_width-indent(); + m_end = m_pos; + while( m_end < line().size() && line()[m_end] != '\n' ) + ++m_end; + + if( m_end < m_pos + width ) { + m_len = m_end - m_pos; + } + else { + size_t len = width; + while (len > 0 && !isBoundary(m_pos + len)) + --len; + while (len > 0 && isWhitespace( line()[m_pos + len - 1] )) + --len; + + if (len > 0) { + m_len = len; + } else { + m_suffix = true; + m_len = width - 1; + } + } + } + + auto indent() const -> size_t { + auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; + return initial == std::string::npos ? m_column.m_indent : initial; + } + + auto addIndentAndSuffix(std::string const &plain) const -> std::string { + return std::string( indent(), ' ' ) + (m_suffix ? plain + "-" : plain); + } + + public: + explicit iterator( Column const& column ) : m_column( column ) { + assert( m_column.m_width > m_column.m_indent ); + assert( m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent ); + calcLength(); + if( m_len == 0 ) + m_stringIndex++; // Empty string + } + + auto operator *() const -> std::string { + assert( m_stringIndex < m_column.m_strings.size() ); + assert( m_pos <= m_end ); + if( m_pos + m_column.m_width < m_end ) + return addIndentAndSuffix(line().substr(m_pos, m_len)); + else + return addIndentAndSuffix(line().substr(m_pos, m_end - m_pos)); + } + + auto operator ++() -> iterator& { + m_pos += m_len; + if( m_pos < line().size() && line()[m_pos] == '\n' ) + m_pos += 1; + else + while( m_pos < line().size() && isWhitespace( line()[m_pos] ) ) + ++m_pos; + + if( m_pos == line().size() ) { + m_pos = 0; + ++m_stringIndex; + } + if( m_stringIndex < m_column.m_strings.size() ) + calcLength(); + return *this; + } + auto operator ++(int) -> iterator { + iterator prev( *this ); + operator++(); + return prev; + } + + auto operator ==( iterator const& other ) const -> bool { + return + m_pos == other.m_pos && + m_stringIndex == other.m_stringIndex && + &m_column == &other.m_column; + } + auto operator !=( iterator const& other ) const -> bool { + return !operator==( other ); + } + }; + using const_iterator = iterator; + + explicit Column( std::string const& text ) { m_strings.push_back( text ); } + + auto width( size_t newWidth ) -> Column& { + assert( newWidth > 0 ); + m_width = newWidth; + return *this; + } + auto indent( size_t newIndent ) -> Column& { + m_indent = newIndent; + return *this; + } + auto initialIndent( size_t newIndent ) -> Column& { + m_initialIndent = newIndent; + return *this; + } + + auto width() const -> size_t { return m_width; } + auto begin() const -> iterator { return iterator( *this ); } + auto end() const -> iterator { return { *this, m_strings.size() }; } + + inline friend std::ostream& operator << ( std::ostream& os, Column const& col ) { + bool first = true; + for( auto line : col ) { + if( first ) + first = false; + else + os << "\n"; + os << line; + } + return os; + } + + auto operator + ( Column const& other ) -> Columns; + + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + }; + + class Spacer : public Column { + + public: + explicit Spacer( size_t spaceWidth ) : Column( "" ) { + width( spaceWidth ); + } + }; + + class Columns { + std::vector m_columns; + + public: + + class iterator { + friend Columns; + struct EndTag {}; + + std::vector const& m_columns; + std::vector m_iterators; + size_t m_activeIterators; + + iterator( Columns const& columns, EndTag ) + : m_columns( columns.m_columns ), + m_activeIterators( 0 ) + { + m_iterators.reserve( m_columns.size() ); + + for( auto const& col : m_columns ) + m_iterators.push_back( col.end() ); + } + + public: + explicit iterator( Columns const& columns ) + : m_columns( columns.m_columns ), + m_activeIterators( m_columns.size() ) + { + m_iterators.reserve( m_columns.size() ); + + for( auto const& col : m_columns ) + m_iterators.push_back( col.begin() ); + } + + auto operator ==( iterator const& other ) const -> bool { + return m_iterators == other.m_iterators; + } + auto operator !=( iterator const& other ) const -> bool { + return m_iterators != other.m_iterators; + } + auto operator *() const -> std::string { + std::string row, padding; + + for( size_t i = 0; i < m_columns.size(); ++i ) { + auto width = m_columns[i].width(); + if( m_iterators[i] != m_columns[i].end() ) { + std::string col = *m_iterators[i]; + row += padding + col; + if( col.size() < width ) + padding = std::string( width - col.size(), ' ' ); + else + padding = ""; + } + else { + padding += std::string( width, ' ' ); + } + } + return row; + } + auto operator ++() -> iterator& { + for( size_t i = 0; i < m_columns.size(); ++i ) { + if (m_iterators[i] != m_columns[i].end()) + ++m_iterators[i]; + } + return *this; + } + auto operator ++(int) -> iterator { + iterator prev( *this ); + operator++(); + return prev; + } + }; + using const_iterator = iterator; + + auto begin() const -> iterator { return iterator( *this ); } + auto end() const -> iterator { return { *this, iterator::EndTag() }; } + + auto operator += ( Column const& col ) -> Columns& { + m_columns.push_back( col ); + return *this; + } + auto operator + ( Column const& col ) -> Columns { + Columns combined = *this; + combined += col; + return combined; + } + + inline friend std::ostream& operator << ( std::ostream& os, Columns const& cols ) { + + bool first = true; + for( auto line : cols ) { + if( first ) + first = false; + else + os << "\n"; + os << line; + } + return os; + } + + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + }; + + inline auto Column::operator + ( Column const& other ) -> Columns { + Columns cols; + cols += *this; + cols += other; + return cols; + } +}}} // namespace Catch::clara::TextFlow + +// ----------- end of #include from clara_textflow.hpp ----------- +// ........... back in clara.hpp + +#include +#include +#include + +#if !defined(CATCH_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) ) +#define CATCH_PLATFORM_WINDOWS +#endif + +namespace Catch { namespace clara { +namespace detail { + + // Traits for extracting arg and return type of lambdas (for single argument lambdas) + template + struct UnaryLambdaTraits : UnaryLambdaTraits {}; + + template + struct UnaryLambdaTraits { + static const bool isValid = false; + }; + + template + struct UnaryLambdaTraits { + static const bool isValid = true; + using ArgType = typename std::remove_const::type>::type; + using ReturnType = ReturnT; + }; + + class TokenStream; + + // Transport for raw args (copied from main args, or supplied via init list for testing) + class Args { + friend TokenStream; + std::string m_exeName; + std::vector m_args; + + public: + Args( int argc, char const* const* argv ) + : m_exeName(argv[0]), + m_args(argv + 1, argv + argc) {} + + Args( std::initializer_list args ) + : m_exeName( *args.begin() ), + m_args( args.begin()+1, args.end() ) + {} + + auto exeName() const -> std::string { + return m_exeName; + } + }; + + // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string + // may encode an option + its argument if the : or = form is used + enum class TokenType { + Option, Argument + }; + struct Token { + TokenType type; + std::string token; + }; + + inline auto isOptPrefix( char c ) -> bool { + return c == '-' +#ifdef CATCH_PLATFORM_WINDOWS + || c == '/' +#endif + ; + } + + // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled + class TokenStream { + using Iterator = std::vector::const_iterator; + Iterator it; + Iterator itEnd; + std::vector m_tokenBuffer; + + void loadBuffer() { + m_tokenBuffer.resize( 0 ); + + // Skip any empty strings + while( it != itEnd && it->empty() ) + ++it; + + if( it != itEnd ) { + auto const &next = *it; + if( isOptPrefix( next[0] ) ) { + auto delimiterPos = next.find_first_of( " :=" ); + if( delimiterPos != std::string::npos ) { + m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } ); + m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } ); + } else { + if( next[1] != '-' && next.size() > 2 ) { + std::string opt = "- "; + for( size_t i = 1; i < next.size(); ++i ) { + opt[1] = next[i]; + m_tokenBuffer.push_back( { TokenType::Option, opt } ); + } + } else { + m_tokenBuffer.push_back( { TokenType::Option, next } ); + } + } + } else { + m_tokenBuffer.push_back( { TokenType::Argument, next } ); + } + } + } + + public: + explicit TokenStream( Args const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {} + + TokenStream( Iterator it, Iterator itEnd ) : it( it ), itEnd( itEnd ) { + loadBuffer(); + } + + explicit operator bool() const { + return !m_tokenBuffer.empty() || it != itEnd; + } + + auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } + + auto operator*() const -> Token { + assert( !m_tokenBuffer.empty() ); + return m_tokenBuffer.front(); + } + + auto operator->() const -> Token const * { + assert( !m_tokenBuffer.empty() ); + return &m_tokenBuffer.front(); + } + + auto operator++() -> TokenStream & { + if( m_tokenBuffer.size() >= 2 ) { + m_tokenBuffer.erase( m_tokenBuffer.begin() ); + } else { + if( it != itEnd ) + ++it; + loadBuffer(); + } + return *this; + } + }; + + class ResultBase { + public: + enum Type { + Ok, LogicError, RuntimeError + }; + + protected: + ResultBase( Type type ) : m_type( type ) {} + virtual ~ResultBase() = default; + + virtual void enforceOk() const = 0; + + Type m_type; + }; + + template + class ResultValueBase : public ResultBase { + public: + auto value() const -> T const & { + enforceOk(); + return m_value; + } + + protected: + ResultValueBase( Type type ) : ResultBase( type ) {} + + ResultValueBase( ResultValueBase const &other ) : ResultBase( other ) { + if( m_type == ResultBase::Ok ) + new( &m_value ) T( other.m_value ); + } + + ResultValueBase( Type, T const &value ) : ResultBase( Ok ) { + new( &m_value ) T( value ); + } + + auto operator=( ResultValueBase const &other ) -> ResultValueBase & { + if( m_type == ResultBase::Ok ) + m_value.~T(); + ResultBase::operator=(other); + if( m_type == ResultBase::Ok ) + new( &m_value ) T( other.m_value ); + return *this; + } + + ~ResultValueBase() override { + if( m_type == Ok ) + m_value.~T(); + } + + union { + T m_value; + }; + }; + + template<> + class ResultValueBase : public ResultBase { + protected: + using ResultBase::ResultBase; + }; + + template + class BasicResult : public ResultValueBase { + public: + template + explicit BasicResult( BasicResult const &other ) + : ResultValueBase( other.type() ), + m_errorMessage( other.errorMessage() ) + { + assert( type() != ResultBase::Ok ); + } + + template + static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; } + static auto ok() -> BasicResult { return { ResultBase::Ok }; } + static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; } + static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; } + + explicit operator bool() const { return m_type == ResultBase::Ok; } + auto type() const -> ResultBase::Type { return m_type; } + auto errorMessage() const -> std::string { return m_errorMessage; } + + protected: + void enforceOk() const override { + + // Errors shouldn't reach this point, but if they do + // the actual error message will be in m_errorMessage + assert( m_type != ResultBase::LogicError ); + assert( m_type != ResultBase::RuntimeError ); + if( m_type != ResultBase::Ok ) + std::abort(); + } + + std::string m_errorMessage; // Only populated if resultType is an error + + BasicResult( ResultBase::Type type, std::string const &message ) + : ResultValueBase(type), + m_errorMessage(message) + { + assert( m_type != ResultBase::Ok ); + } + + using ResultValueBase::ResultValueBase; + using ResultBase::m_type; + }; + + enum class ParseResultType { + Matched, NoMatch, ShortCircuitAll, ShortCircuitSame + }; + + class ParseState { + public: + + ParseState( ParseResultType type, TokenStream const &remainingTokens ) + : m_type(type), + m_remainingTokens( remainingTokens ) + {} + + auto type() const -> ParseResultType { return m_type; } + auto remainingTokens() const -> TokenStream { return m_remainingTokens; } + + private: + ParseResultType m_type; + TokenStream m_remainingTokens; + }; + + using Result = BasicResult; + using ParserResult = BasicResult; + using InternalParseResult = BasicResult; + + struct HelpColumns { + std::string left; + std::string right; + }; + + template + inline auto convertInto( std::string const &source, T& target ) -> ParserResult { + std::stringstream ss; + ss << source; + ss >> target; + if( ss.fail() ) + return ParserResult::runtimeError( "Unable to convert '" + source + "' to destination type" ); + else + return ParserResult::ok( ParseResultType::Matched ); + } + inline auto convertInto( std::string const &source, std::string& target ) -> ParserResult { + target = source; + return ParserResult::ok( ParseResultType::Matched ); + } + inline auto convertInto( std::string const &source, bool &target ) -> ParserResult { + std::string srcLC = source; + std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), []( char c ) { return static_cast( ::tolower(c) ); } ); + if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on") + target = true; + else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off") + target = false; + else + return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + } +#ifdef CLARA_CONFIG_OPTIONAL_TYPE + template + inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE& target ) -> ParserResult { + T temp; + auto result = convertInto( source, temp ); + if( result ) + target = std::move(temp); + return result; + } +#endif // CLARA_CONFIG_OPTIONAL_TYPE + + struct NonCopyable { + NonCopyable() = default; + NonCopyable( NonCopyable const & ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable &operator=( NonCopyable const & ) = delete; + NonCopyable &operator=( NonCopyable && ) = delete; + }; + + struct BoundRef : NonCopyable { + virtual ~BoundRef() = default; + virtual auto isContainer() const -> bool { return false; } + virtual auto isFlag() const -> bool { return false; } + }; + struct BoundValueRefBase : BoundRef { + virtual auto setValue( std::string const &arg ) -> ParserResult = 0; + }; + struct BoundFlagRefBase : BoundRef { + virtual auto setFlag( bool flag ) -> ParserResult = 0; + virtual auto isFlag() const -> bool { return true; } + }; + + template + struct BoundValueRef : BoundValueRefBase { + T &m_ref; + + explicit BoundValueRef( T &ref ) : m_ref( ref ) {} + + auto setValue( std::string const &arg ) -> ParserResult override { + return convertInto( arg, m_ref ); + } + }; + + template + struct BoundValueRef> : BoundValueRefBase { + std::vector &m_ref; + + explicit BoundValueRef( std::vector &ref ) : m_ref( ref ) {} + + auto isContainer() const -> bool override { return true; } + + auto setValue( std::string const &arg ) -> ParserResult override { + T temp; + auto result = convertInto( arg, temp ); + if( result ) + m_ref.push_back( temp ); + return result; + } + }; + + struct BoundFlagRef : BoundFlagRefBase { + bool &m_ref; + + explicit BoundFlagRef( bool &ref ) : m_ref( ref ) {} + + auto setFlag( bool flag ) -> ParserResult override { + m_ref = flag; + return ParserResult::ok( ParseResultType::Matched ); + } + }; + + template + struct LambdaInvoker { + static_assert( std::is_same::value, "Lambda must return void or clara::ParserResult" ); + + template + static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { + return lambda( arg ); + } + }; + + template<> + struct LambdaInvoker { + template + static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { + lambda( arg ); + return ParserResult::ok( ParseResultType::Matched ); + } + }; + + template + inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult { + ArgType temp{}; + auto result = convertInto( arg, temp ); + return !result + ? result + : LambdaInvoker::ReturnType>::invoke( lambda, temp ); + } + + template + struct BoundLambda : BoundValueRefBase { + L m_lambda; + + static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); + explicit BoundLambda( L const &lambda ) : m_lambda( lambda ) {} + + auto setValue( std::string const &arg ) -> ParserResult override { + return invokeLambda::ArgType>( m_lambda, arg ); + } + }; + + template + struct BoundFlagLambda : BoundFlagRefBase { + L m_lambda; + + static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); + static_assert( std::is_same::ArgType, bool>::value, "flags must be boolean" ); + + explicit BoundFlagLambda( L const &lambda ) : m_lambda( lambda ) {} + + auto setFlag( bool flag ) -> ParserResult override { + return LambdaInvoker::ReturnType>::invoke( m_lambda, flag ); + } + }; + + enum class Optionality { Optional, Required }; + + struct Parser; + + class ParserBase { + public: + virtual ~ParserBase() = default; + virtual auto validate() const -> Result { return Result::ok(); } + virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; + virtual auto cardinality() const -> size_t { return 1; } + + auto parse( Args const &args ) const -> InternalParseResult { + return parse( args.exeName(), TokenStream( args ) ); + } + }; + + template + class ComposableParserImpl : public ParserBase { + public: + template + auto operator|( T const &other ) const -> Parser; + + template + auto operator+( T const &other ) const -> Parser; + }; + + // Common code and state for Args and Opts + template + class ParserRefImpl : public ComposableParserImpl { + protected: + Optionality m_optionality = Optionality::Optional; + std::shared_ptr m_ref; + std::string m_hint; + std::string m_description; + + explicit ParserRefImpl( std::shared_ptr const &ref ) : m_ref( ref ) {} + + public: + template + ParserRefImpl( T &ref, std::string const &hint ) + : m_ref( std::make_shared>( ref ) ), + m_hint( hint ) + {} + + template + ParserRefImpl( LambdaT const &ref, std::string const &hint ) + : m_ref( std::make_shared>( ref ) ), + m_hint(hint) + {} + + auto operator()( std::string const &description ) -> DerivedT & { + m_description = description; + return static_cast( *this ); + } + + auto optional() -> DerivedT & { + m_optionality = Optionality::Optional; + return static_cast( *this ); + }; + + auto required() -> DerivedT & { + m_optionality = Optionality::Required; + return static_cast( *this ); + }; + + auto isOptional() const -> bool { + return m_optionality == Optionality::Optional; + } + + auto cardinality() const -> size_t override { + if( m_ref->isContainer() ) + return 0; + else + return 1; + } + + auto hint() const -> std::string { return m_hint; } + }; + + class ExeName : public ComposableParserImpl { + std::shared_ptr m_name; + std::shared_ptr m_ref; + + template + static auto makeRef(LambdaT const &lambda) -> std::shared_ptr { + return std::make_shared>( lambda) ; + } + + public: + ExeName() : m_name( std::make_shared( "" ) ) {} + + explicit ExeName( std::string &ref ) : ExeName() { + m_ref = std::make_shared>( ref ); + } + + template + explicit ExeName( LambdaT const& lambda ) : ExeName() { + m_ref = std::make_shared>( lambda ); + } + + // The exe name is not parsed out of the normal tokens, but is handled specially + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); + } + + auto name() const -> std::string { return *m_name; } + auto set( std::string const& newName ) -> ParserResult { + + auto lastSlash = newName.find_last_of( "\\/" ); + auto filename = ( lastSlash == std::string::npos ) + ? newName + : newName.substr( lastSlash+1 ); + + *m_name = filename; + if( m_ref ) + return m_ref->setValue( filename ); + else + return ParserResult::ok( ParseResultType::Matched ); + } + }; + + class Arg : public ParserRefImpl { + public: + using ParserRefImpl::ParserRefImpl; + + auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override { + auto validationResult = validate(); + if( !validationResult ) + return InternalParseResult( validationResult ); + + auto remainingTokens = tokens; + auto const &token = *remainingTokens; + if( token.type != TokenType::Argument ) + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); + + assert( !m_ref->isFlag() ); + auto valueRef = static_cast( m_ref.get() ); + + auto result = valueRef->setValue( remainingTokens->token ); + if( !result ) + return InternalParseResult( result ); + else + return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); + } + }; + + inline auto normaliseOpt( std::string const &optName ) -> std::string { +#ifdef CATCH_PLATFORM_WINDOWS + if( optName[0] == '/' ) + return "-" + optName.substr( 1 ); + else +#endif + return optName; + } + + class Opt : public ParserRefImpl { + protected: + std::vector m_optNames; + + public: + template + explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared>( ref ) ) {} + + explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared( ref ) ) {} + + template + Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} + + template + Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} + + auto operator[]( std::string const &optName ) -> Opt & { + m_optNames.push_back( optName ); + return *this; + } + + auto getHelpColumns() const -> std::vector { + std::ostringstream oss; + bool first = true; + for( auto const &opt : m_optNames ) { + if (first) + first = false; + else + oss << ", "; + oss << opt; + } + if( !m_hint.empty() ) + oss << " <" << m_hint << ">"; + return { { oss.str(), m_description } }; + } + + auto isMatch( std::string const &optToken ) const -> bool { + auto normalisedToken = normaliseOpt( optToken ); + for( auto const &name : m_optNames ) { + if( normaliseOpt( name ) == normalisedToken ) + return true; + } + return false; + } + + using ParserBase::parse; + + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + auto validationResult = validate(); + if( !validationResult ) + return InternalParseResult( validationResult ); + + auto remainingTokens = tokens; + if( remainingTokens && remainingTokens->type == TokenType::Option ) { + auto const &token = *remainingTokens; + if( isMatch(token.token ) ) { + if( m_ref->isFlag() ) { + auto flagRef = static_cast( m_ref.get() ); + auto result = flagRef->setFlag( true ); + if( !result ) + return InternalParseResult( result ); + if( result.value() == ParseResultType::ShortCircuitAll ) + return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); + } else { + auto valueRef = static_cast( m_ref.get() ); + ++remainingTokens; + if( !remainingTokens ) + return InternalParseResult::runtimeError( "Expected argument following " + token.token ); + auto const &argToken = *remainingTokens; + if( argToken.type != TokenType::Argument ) + return InternalParseResult::runtimeError( "Expected argument following " + token.token ); + auto result = valueRef->setValue( argToken.token ); + if( !result ) + return InternalParseResult( result ); + if( result.value() == ParseResultType::ShortCircuitAll ) + return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); + } + return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); + } + } + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); + } + + auto validate() const -> Result override { + if( m_optNames.empty() ) + return Result::logicError( "No options supplied to Opt" ); + for( auto const &name : m_optNames ) { + if( name.empty() ) + return Result::logicError( "Option name cannot be empty" ); +#ifdef CATCH_PLATFORM_WINDOWS + if( name[0] != '-' && name[0] != '/' ) + return Result::logicError( "Option name must begin with '-' or '/'" ); +#else + if( name[0] != '-' ) + return Result::logicError( "Option name must begin with '-'" ); +#endif + } + return ParserRefImpl::validate(); + } + }; + + struct Help : Opt { + Help( bool &showHelpFlag ) + : Opt([&]( bool flag ) { + showHelpFlag = flag; + return ParserResult::ok( ParseResultType::ShortCircuitAll ); + }) + { + static_cast( *this ) + ("display usage information") + ["-?"]["-h"]["--help"] + .optional(); + } + }; + + struct Parser : ParserBase { + + mutable ExeName m_exeName; + std::vector m_options; + std::vector m_args; + + auto operator|=( ExeName const &exeName ) -> Parser & { + m_exeName = exeName; + return *this; + } + + auto operator|=( Arg const &arg ) -> Parser & { + m_args.push_back(arg); + return *this; + } + + auto operator|=( Opt const &opt ) -> Parser & { + m_options.push_back(opt); + return *this; + } + + auto operator|=( Parser const &other ) -> Parser & { + m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); + m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); + return *this; + } + + template + auto operator|( T const &other ) const -> Parser { + return Parser( *this ) |= other; + } + + // Forward deprecated interface with '+' instead of '|' + template + auto operator+=( T const &other ) -> Parser & { return operator|=( other ); } + template + auto operator+( T const &other ) const -> Parser { return operator|( other ); } + + auto getHelpColumns() const -> std::vector { + std::vector cols; + for (auto const &o : m_options) { + auto childCols = o.getHelpColumns(); + cols.insert( cols.end(), childCols.begin(), childCols.end() ); + } + return cols; + } + + void writeToStream( std::ostream &os ) const { + if (!m_exeName.name().empty()) { + os << "usage:\n" << " " << m_exeName.name() << " "; + bool required = true, first = true; + for( auto const &arg : m_args ) { + if (first) + first = false; + else + os << " "; + if( arg.isOptional() && required ) { + os << "["; + required = false; + } + os << "<" << arg.hint() << ">"; + if( arg.cardinality() == 0 ) + os << " ... "; + } + if( !required ) + os << "]"; + if( !m_options.empty() ) + os << " options"; + os << "\n\nwhere options are:" << std::endl; + } + + auto rows = getHelpColumns(); + size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; + size_t optWidth = 0; + for( auto const &cols : rows ) + optWidth = (std::max)(optWidth, cols.left.size() + 2); + + optWidth = (std::min)(optWidth, consoleWidth/2); + + for( auto const &cols : rows ) { + auto row = + TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + + TextFlow::Spacer(4) + + TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); + os << row << std::endl; + } + } + + friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { + parser.writeToStream( os ); + return os; + } + + auto validate() const -> Result override { + for( auto const &opt : m_options ) { + auto result = opt.validate(); + if( !result ) + return result; + } + for( auto const &arg : m_args ) { + auto result = arg.validate(); + if( !result ) + return result; + } + return Result::ok(); + } + + using ParserBase::parse; + + auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override { + + struct ParserInfo { + ParserBase const* parser = nullptr; + size_t count = 0; + }; + const size_t totalParsers = m_options.size() + m_args.size(); + assert( totalParsers < 512 ); + // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do + ParserInfo parseInfos[512]; + + { + size_t i = 0; + for (auto const &opt : m_options) parseInfos[i++].parser = &opt; + for (auto const &arg : m_args) parseInfos[i++].parser = &arg; + } + + m_exeName.set( exeName ); + + auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); + while( result.value().remainingTokens() ) { + bool tokenParsed = false; + + for( size_t i = 0; i < totalParsers; ++i ) { + auto& parseInfo = parseInfos[i]; + if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) { + result = parseInfo.parser->parse(exeName, result.value().remainingTokens()); + if (!result) + return result; + if (result.value().type() != ParseResultType::NoMatch) { + tokenParsed = true; + ++parseInfo.count; + break; + } + } + } + + if( result.value().type() == ParseResultType::ShortCircuitAll ) + return result; + if( !tokenParsed ) + return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token ); + } + // !TBD Check missing required options + return result; + } + }; + + template + template + auto ComposableParserImpl::operator|( T const &other ) const -> Parser { + return Parser() | static_cast( *this ) | other; + } +} // namespace detail + +// A Combined parser +using detail::Parser; + +// A parser for options +using detail::Opt; + +// A parser for arguments +using detail::Arg; + +// Wrapper for argc, argv from main() +using detail::Args; + +// Specifies the name of the executable +using detail::ExeName; + +// Convenience wrapper for option parser that specifies the help option +using detail::Help; + +// enum of result types from a parse +using detail::ParseResultType; + +// Result type for parser operation +using detail::ParserResult; + +}} // namespace Catch::clara + +// end clara.hpp +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// Restore Clara's value for console width, if present +#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#endif + +// end catch_clara.h +namespace Catch { + + clara::Parser makeCommandLineParser( ConfigData& config ); + +} // end namespace Catch + +// end catch_commandline.h +#include +#include + +namespace Catch { + + clara::Parser makeCommandLineParser( ConfigData& config ) { + + using namespace clara; + + auto const setWarning = [&]( std::string const& warning ) { + auto warningSet = [&]() { + if( warning == "NoAssertions" ) + return WarnAbout::NoAssertions; + + if ( warning == "NoTests" ) + return WarnAbout::NoTests; + + return WarnAbout::Nothing; + }(); + + if (warningSet == WarnAbout::Nothing) + return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); + config.warnings = static_cast( config.warnings | warningSet ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const loadTestNamesFromFile = [&]( std::string const& filename ) { + std::ifstream f( filename.c_str() ); + if( !f.is_open() ) + return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); + + std::string line; + while( std::getline( f, line ) ) { + line = trim(line); + if( !line.empty() && !startsWith( line, '#' ) ) { + if( !startsWith( line, '"' ) ) + line = '"' + line + '"'; + config.testsOrTags.push_back( line + ',' ); + } + } + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setTestOrder = [&]( std::string const& order ) { + if( startsWith( "declared", order ) ) + config.runOrder = RunTests::InDeclarationOrder; + else if( startsWith( "lexical", order ) ) + config.runOrder = RunTests::InLexicographicalOrder; + else if( startsWith( "random", order ) ) + config.runOrder = RunTests::InRandomOrder; + else + return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setRngSeed = [&]( std::string const& seed ) { + if( seed != "time" ) + return clara::detail::convertInto( seed, config.rngSeed ); + config.rngSeed = static_cast( std::time(nullptr) ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setColourUsage = [&]( std::string const& useColour ) { + auto mode = toLower( useColour ); + + if( mode == "yes" ) + config.useColour = UseColour::Yes; + else if( mode == "no" ) + config.useColour = UseColour::No; + else if( mode == "auto" ) + config.useColour = UseColour::Auto; + else + return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setWaitForKeypress = [&]( std::string const& keypress ) { + auto keypressLc = toLower( keypress ); + if( keypressLc == "start" ) + config.waitForKeypress = WaitForKeypress::BeforeStart; + else if( keypressLc == "exit" ) + config.waitForKeypress = WaitForKeypress::BeforeExit; + else if( keypressLc == "both" ) + config.waitForKeypress = WaitForKeypress::BeforeStartAndExit; + else + return ParserResult::runtimeError( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setVerbosity = [&]( std::string const& verbosity ) { + auto lcVerbosity = toLower( verbosity ); + if( lcVerbosity == "quiet" ) + config.verbosity = Verbosity::Quiet; + else if( lcVerbosity == "normal" ) + config.verbosity = Verbosity::Normal; + else if( lcVerbosity == "high" ) + config.verbosity = Verbosity::High; + else + return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + + auto cli + = ExeName( config.processName ) + | Help( config.showHelp ) + | Opt( config.listTests ) + ["-l"]["--list-tests"] + ( "list all/matching test cases" ) + | Opt( config.listTags ) + ["-t"]["--list-tags"] + ( "list all/matching tags" ) + | Opt( config.showSuccessfulTests ) + ["-s"]["--success"] + ( "include successful tests in output" ) + | Opt( config.shouldDebugBreak ) + ["-b"]["--break"] + ( "break into debugger on failure" ) + | Opt( config.noThrow ) + ["-e"]["--nothrow"] + ( "skip exception tests" ) + | Opt( config.showInvisibles ) + ["-i"]["--invisibles"] + ( "show invisibles (tabs, newlines)" ) + | Opt( config.outputFilename, "filename" ) + ["-o"]["--out"] + ( "output filename" ) + | Opt( config.reporterNames, "name" ) + ["-r"]["--reporter"] + ( "reporter to use (defaults to console)" ) + | Opt( config.name, "name" ) + ["-n"]["--name"] + ( "suite name" ) + | Opt( [&]( bool ){ config.abortAfter = 1; } ) + ["-a"]["--abort"] + ( "abort at first failure" ) + | Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" ) + ["-x"]["--abortx"] + ( "abort after x failures" ) + | Opt( setWarning, "warning name" ) + ["-w"]["--warn"] + ( "enable warnings" ) + | Opt( [&]( bool flag ) { config.showDurations = flag ? ShowDurations::Always : ShowDurations::Never; }, "yes|no" ) + ["-d"]["--durations"] + ( "show test durations" ) + | Opt( loadTestNamesFromFile, "filename" ) + ["-f"]["--input-file"] + ( "load test names to run from a file" ) + | Opt( config.filenamesAsTags ) + ["-#"]["--filenames-as-tags"] + ( "adds a tag for the filename" ) + | Opt( config.sectionsToRun, "section name" ) + ["-c"]["--section"] + ( "specify section to run" ) + | Opt( setVerbosity, "quiet|normal|high" ) + ["-v"]["--verbosity"] + ( "set output verbosity" ) + | Opt( config.listTestNamesOnly ) + ["--list-test-names-only"] + ( "list all/matching test cases names only" ) + | Opt( config.listReporters ) + ["--list-reporters"] + ( "list all reporters" ) + | Opt( setTestOrder, "decl|lex|rand" ) + ["--order"] + ( "test case order (defaults to decl)" ) + | Opt( setRngSeed, "'time'|number" ) + ["--rng-seed"] + ( "set a specific seed for random numbers" ) + | Opt( setColourUsage, "yes|no" ) + ["--use-colour"] + ( "should output be colourised" ) + | Opt( config.libIdentify ) + ["--libidentify"] + ( "report name and version according to libidentify standard" ) + | Opt( setWaitForKeypress, "start|exit|both" ) + ["--wait-for-keypress"] + ( "waits for a keypress before exiting" ) + | Opt( config.benchmarkResolutionMultiple, "multiplier" ) + ["--benchmark-resolution-multiple"] + ( "multiple of clock resolution to run benchmarks" ) + + | Arg( config.testsOrTags, "test name|pattern|tags" ) + ( "which test or tests to use" ); + + return cli; + } + +} // end namespace Catch +// end catch_commandline.cpp +// start catch_common.cpp + +#include +#include + +namespace Catch { + + bool SourceLineInfo::empty() const noexcept { + return file[0] == '\0'; + } + bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept { + return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0); + } + bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept { + return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0)); + } + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { +#ifndef __GNUG__ + os << info.file << '(' << info.line << ')'; +#else + os << info.file << ':' << info.line; +#endif + return os; + } + + std::string StreamEndStop::operator+() const { + return std::string(); + } + + NonCopyable::NonCopyable() = default; + NonCopyable::~NonCopyable() = default; + +} +// end catch_common.cpp +// start catch_config.cpp + +// start catch_enforce.h + +#include + +#define CATCH_PREPARE_EXCEPTION( type, msg ) \ + type( ( Catch::ReusableStringStream() << msg ).str() ) +#define CATCH_INTERNAL_ERROR( msg ) \ + throw CATCH_PREPARE_EXCEPTION( std::logic_error, CATCH_INTERNAL_LINEINFO << ": Internal Catch error: " << msg); +#define CATCH_ERROR( msg ) \ + throw CATCH_PREPARE_EXCEPTION( std::domain_error, msg ) +#define CATCH_ENFORCE( condition, msg ) \ + do{ if( !(condition) ) CATCH_ERROR( msg ); } while(false) + +// end catch_enforce.h +namespace Catch { + + Config::Config( ConfigData const& data ) + : m_data( data ), + m_stream( openStream() ) + { + TestSpecParser parser(ITagAliasRegistry::get()); + if (data.testsOrTags.empty()) { + parser.parse("~[.]"); // All not hidden tests + } + else { + m_hasTestFilters = true; + for( auto const& testOrTags : data.testsOrTags ) + parser.parse( testOrTags ); + } + m_testSpec = parser.testSpec(); + } + + std::string const& Config::getFilename() const { + return m_data.outputFilename ; + } + + bool Config::listTests() const { return m_data.listTests; } + bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; } + bool Config::listTags() const { return m_data.listTags; } + bool Config::listReporters() const { return m_data.listReporters; } + + std::string Config::getProcessName() const { return m_data.processName; } + + std::vector const& Config::getReporterNames() const { return m_data.reporterNames; } + std::vector const& Config::getTestsOrTags() const { return m_data.testsOrTags; } + std::vector const& Config::getSectionsToRun() const { return m_data.sectionsToRun; } + + TestSpec const& Config::testSpec() const { return m_testSpec; } + bool Config::hasTestFilters() const { return m_hasTestFilters; } + + bool Config::showHelp() const { return m_data.showHelp; } + + // IConfig interface + bool Config::allowThrows() const { return !m_data.noThrow; } + std::ostream& Config::stream() const { return m_stream->stream(); } + std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } + bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; } + bool Config::warnAboutMissingAssertions() const { return !!(m_data.warnings & WarnAbout::NoAssertions); } + bool Config::warnAboutNoTests() const { return !!(m_data.warnings & WarnAbout::NoTests); } + ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; } + RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; } + unsigned int Config::rngSeed() const { return m_data.rngSeed; } + int Config::benchmarkResolutionMultiple() const { return m_data.benchmarkResolutionMultiple; } + UseColour::YesOrNo Config::useColour() const { return m_data.useColour; } + bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; } + int Config::abortAfter() const { return m_data.abortAfter; } + bool Config::showInvisibles() const { return m_data.showInvisibles; } + Verbosity Config::verbosity() const { return m_data.verbosity; } + + IStream const* Config::openStream() { + return Catch::makeStream(m_data.outputFilename); + } + +} // end namespace Catch +// end catch_config.cpp +// start catch_console_colour.cpp + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +// start catch_errno_guard.h + +namespace Catch { + + class ErrnoGuard { + public: + ErrnoGuard(); + ~ErrnoGuard(); + private: + int m_oldErrno; + }; + +} + +// end catch_errno_guard.h +#include + +namespace Catch { + namespace { + + struct IColourImpl { + virtual ~IColourImpl() = default; + virtual void use( Colour::Code _colourCode ) = 0; + }; + + struct NoColourImpl : IColourImpl { + void use( Colour::Code ) {} + + static IColourImpl* instance() { + static NoColourImpl s_instance; + return &s_instance; + } + }; + + } // anon namespace +} // namespace Catch + +#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI ) +# ifdef CATCH_PLATFORM_WINDOWS +# define CATCH_CONFIG_COLOUR_WINDOWS +# else +# define CATCH_CONFIG_COLOUR_ANSI +# endif +#endif + +#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// + +namespace Catch { +namespace { + + class Win32ColourImpl : public IColourImpl { + public: + Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) + { + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; + GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); + originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY ); + originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); + } + + virtual void use( Colour::Code _colourCode ) override { + switch( _colourCode ) { + case Colour::None: return setTextAttribute( originalForegroundAttributes ); + case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); + case Colour::Red: return setTextAttribute( FOREGROUND_RED ); + case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); + case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE ); + case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN ); + case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN ); + case Colour::Grey: return setTextAttribute( 0 ); + + case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY ); + case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); + case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); + case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); + case Colour::BrightYellow: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN ); + + case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); + + default: + CATCH_ERROR( "Unknown colour requested" ); + } + } + + private: + void setTextAttribute( WORD _textAttribute ) { + SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes ); + } + HANDLE stdoutHandle; + WORD originalForegroundAttributes; + WORD originalBackgroundAttributes; + }; + + IColourImpl* platformColourInstance() { + static Win32ColourImpl s_instance; + + IConfigPtr config = getCurrentContext().getConfig(); + UseColour::YesOrNo colourMode = config + ? config->useColour() + : UseColour::Auto; + if( colourMode == UseColour::Auto ) + colourMode = UseColour::Yes; + return colourMode == UseColour::Yes + ? &s_instance + : NoColourImpl::instance(); + } + +} // end anon namespace +} // end namespace Catch + +#elif defined( CATCH_CONFIG_COLOUR_ANSI ) ////////////////////////////////////// + +#include + +namespace Catch { +namespace { + + // use POSIX/ ANSI console terminal codes + // Thanks to Adam Strzelecki for original contribution + // (http://github.com/nanoant) + // https://github.com/philsquared/Catch/pull/131 + class PosixColourImpl : public IColourImpl { + public: + virtual void use( Colour::Code _colourCode ) override { + switch( _colourCode ) { + case Colour::None: + case Colour::White: return setColour( "[0m" ); + case Colour::Red: return setColour( "[0;31m" ); + case Colour::Green: return setColour( "[0;32m" ); + case Colour::Blue: return setColour( "[0;34m" ); + case Colour::Cyan: return setColour( "[0;36m" ); + case Colour::Yellow: return setColour( "[0;33m" ); + case Colour::Grey: return setColour( "[1;30m" ); + + case Colour::LightGrey: return setColour( "[0;37m" ); + case Colour::BrightRed: return setColour( "[1;31m" ); + case Colour::BrightGreen: return setColour( "[1;32m" ); + case Colour::BrightWhite: return setColour( "[1;37m" ); + case Colour::BrightYellow: return setColour( "[1;33m" ); + + case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); + default: CATCH_INTERNAL_ERROR( "Unknown colour requested" ); + } + } + static IColourImpl* instance() { + static PosixColourImpl s_instance; + return &s_instance; + } + + private: + void setColour( const char* _escapeCode ) { + Catch::cout() << '\033' << _escapeCode; + } + }; + + bool useColourOnPlatform() { + return +#ifdef CATCH_PLATFORM_MAC + !isDebuggerActive() && +#endif +#if !(defined(__DJGPP__) && defined(__STRICT_ANSI__)) + isatty(STDOUT_FILENO) +#else + false +#endif + ; + } + IColourImpl* platformColourInstance() { + ErrnoGuard guard; + IConfigPtr config = getCurrentContext().getConfig(); + UseColour::YesOrNo colourMode = config + ? config->useColour() + : UseColour::Auto; + if( colourMode == UseColour::Auto ) + colourMode = useColourOnPlatform() + ? UseColour::Yes + : UseColour::No; + return colourMode == UseColour::Yes + ? PosixColourImpl::instance() + : NoColourImpl::instance(); + } + +} // end anon namespace +} // end namespace Catch + +#else // not Windows or ANSI /////////////////////////////////////////////// + +namespace Catch { + + static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); } + +} // end namespace Catch + +#endif // Windows/ ANSI/ None + +namespace Catch { + + Colour::Colour( Code _colourCode ) { use( _colourCode ); } + Colour::Colour( Colour&& rhs ) noexcept { + m_moved = rhs.m_moved; + rhs.m_moved = true; + } + Colour& Colour::operator=( Colour&& rhs ) noexcept { + m_moved = rhs.m_moved; + rhs.m_moved = true; + return *this; + } + + Colour::~Colour(){ if( !m_moved ) use( None ); } + + void Colour::use( Code _colourCode ) { + static IColourImpl* impl = platformColourInstance(); + impl->use( _colourCode ); + } + + std::ostream& operator << ( std::ostream& os, Colour const& ) { + return os; + } + +} // end namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + +// end catch_console_colour.cpp +// start catch_context.cpp + +namespace Catch { + + class Context : public IMutableContext, NonCopyable { + + public: // IContext + virtual IResultCapture* getResultCapture() override { + return m_resultCapture; + } + virtual IRunner* getRunner() override { + return m_runner; + } + + virtual IConfigPtr const& getConfig() const override { + return m_config; + } + + virtual ~Context() override; + + public: // IMutableContext + virtual void setResultCapture( IResultCapture* resultCapture ) override { + m_resultCapture = resultCapture; + } + virtual void setRunner( IRunner* runner ) override { + m_runner = runner; + } + virtual void setConfig( IConfigPtr const& config ) override { + m_config = config; + } + + friend IMutableContext& getCurrentMutableContext(); + + private: + IConfigPtr m_config; + IRunner* m_runner = nullptr; + IResultCapture* m_resultCapture = nullptr; + }; + + IMutableContext *IMutableContext::currentContext = nullptr; + + void IMutableContext::createContext() + { + currentContext = new Context(); + } + + void cleanUpContext() { + delete IMutableContext::currentContext; + IMutableContext::currentContext = nullptr; + } + IContext::~IContext() = default; + IMutableContext::~IMutableContext() = default; + Context::~Context() = default; +} +// end catch_context.cpp +// start catch_debug_console.cpp + +// start catch_debug_console.h + +#include + +namespace Catch { + void writeToDebugConsole( std::string const& text ); +} + +// end catch_debug_console.h +#ifdef CATCH_PLATFORM_WINDOWS + + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + ::OutputDebugStringA( text.c_str() ); + } + } + +#else + + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + // !TBD: Need a version for Mac/ XCode and other IDEs + Catch::cout() << text; + } + } + +#endif // Platform +// end catch_debug_console.cpp +// start catch_debugger.cpp + +#ifdef CATCH_PLATFORM_MAC + +# include +# include +# include +# include +# include +# include +# include + +namespace Catch { + + // The following function is taken directly from the following technical note: + // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html + + // Returns true if the current process is being debugged (either + // running under the debugger or has a debugger attached post facto). + bool isDebuggerActive(){ + + int mib[4]; + struct kinfo_proc info; + std::size_t size; + + // Initialize the flags so that, if sysctl fails for some bizarre + // reason, we get a predictable result. + + info.kp_proc.p_flag = 0; + + // Initialize mib, which tells sysctl the info we want, in this case + // we're looking for information about a specific process ID. + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = getpid(); + + // Call sysctl. + + size = sizeof(info); + if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) { + Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; + return false; + } + + // We're being debugged if the P_TRACED flag is set. + + return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); + } + } // namespace Catch + +#elif defined(CATCH_PLATFORM_LINUX) + #include + #include + + namespace Catch{ + // The standard POSIX way of detecting a debugger is to attempt to + // ptrace() the process, but this needs to be done from a child and not + // this process itself to still allow attaching to this process later + // if wanted, so is rather heavy. Under Linux we have the PID of the + // "debugger" (which doesn't need to be gdb, of course, it could also + // be strace, for example) in /proc/$PID/status, so just get it from + // there instead. + bool isDebuggerActive(){ + // Libstdc++ has a bug, where std::ifstream sets errno to 0 + // This way our users can properly assert over errno values + ErrnoGuard guard; + std::ifstream in("/proc/self/status"); + for( std::string line; std::getline(in, line); ) { + static const int PREFIX_LEN = 11; + if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) { + // We're traced if the PID is not 0 and no other PID starts + // with 0 digit, so it's enough to check for just a single + // character. + return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0'; + } + } + + return false; + } + } // namespace Catch +#elif defined(_MSC_VER) + extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); + namespace Catch { + bool isDebuggerActive() { + return IsDebuggerPresent() != 0; + } + } +#elif defined(__MINGW32__) + extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); + namespace Catch { + bool isDebuggerActive() { + return IsDebuggerPresent() != 0; + } + } +#else + namespace Catch { + bool isDebuggerActive() { return false; } + } +#endif // Platform +// end catch_debugger.cpp +// start catch_decomposer.cpp + +namespace Catch { + + ITransientExpression::~ITransientExpression() = default; + + void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) { + if( lhs.size() + rhs.size() < 40 && + lhs.find('\n') == std::string::npos && + rhs.find('\n') == std::string::npos ) + os << lhs << " " << op << " " << rhs; + else + os << lhs << "\n" << op << "\n" << rhs; + } +} +// end catch_decomposer.cpp +// start catch_errno_guard.cpp + +#include + +namespace Catch { + ErrnoGuard::ErrnoGuard():m_oldErrno(errno){} + ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; } +} +// end catch_errno_guard.cpp +// start catch_exception_translator_registry.cpp + +// start catch_exception_translator_registry.h + +#include +#include +#include + +namespace Catch { + + class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { + public: + ~ExceptionTranslatorRegistry(); + virtual void registerTranslator( const IExceptionTranslator* translator ); + virtual std::string translateActiveException() const override; + std::string tryTranslators() const; + + private: + std::vector> m_translators; + }; +} + +// end catch_exception_translator_registry.h +#ifdef __OBJC__ +#import "Foundation/Foundation.h" +#endif + +namespace Catch { + + ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() { + } + + void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) { + m_translators.push_back( std::unique_ptr( translator ) ); + } + + std::string ExceptionTranslatorRegistry::translateActiveException() const { + try { +#ifdef __OBJC__ + // In Objective-C try objective-c exceptions first + @try { + return tryTranslators(); + } + @catch (NSException *exception) { + return Catch::Detail::stringify( [exception description] ); + } +#else + // Compiling a mixed mode project with MSVC means that CLR + // exceptions will be caught in (...) as well. However, these + // do not fill-in std::current_exception and thus lead to crash + // when attempting rethrow. + // /EHa switch also causes structured exceptions to be caught + // here, but they fill-in current_exception properly, so + // at worst the output should be a little weird, instead of + // causing a crash. + if (std::current_exception() == nullptr) { + return "Non C++ exception. Possibly a CLR exception."; + } + return tryTranslators(); +#endif + } + catch( TestFailureException& ) { + std::rethrow_exception(std::current_exception()); + } + catch( std::exception& ex ) { + return ex.what(); + } + catch( std::string& msg ) { + return msg; + } + catch( const char* msg ) { + return msg; + } + catch(...) { + return "Unknown exception"; + } + } + + std::string ExceptionTranslatorRegistry::tryTranslators() const { + if( m_translators.empty() ) + std::rethrow_exception(std::current_exception()); + else + return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() ); + } +} +// end catch_exception_translator_registry.cpp +// start catch_fatal_condition.cpp + +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +#if defined( CATCH_CONFIG_WINDOWS_SEH ) || defined( CATCH_CONFIG_POSIX_SIGNALS ) + +namespace { + // Report the error condition + void reportFatal( char const * const message ) { + Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message ); + } +} + +#endif // signals/SEH handling + +#if defined( CATCH_CONFIG_WINDOWS_SEH ) + +namespace Catch { + struct SignalDefs { DWORD id; const char* name; }; + + // There is no 1-1 mapping between signals and windows exceptions. + // Windows can easily distinguish between SO and SigSegV, + // but SigInt, SigTerm, etc are handled differently. + static SignalDefs signalDefs[] = { + { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" }, + { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" }, + { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" }, + { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" }, + }; + + LONG CALLBACK FatalConditionHandler::handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { + for (auto const& def : signalDefs) { + if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) { + reportFatal(def.name); + } + } + // If its not an exception we care about, pass it along. + // This stops us from eating debugger breaks etc. + return EXCEPTION_CONTINUE_SEARCH; + } + + FatalConditionHandler::FatalConditionHandler() { + isSet = true; + // 32k seems enough for Catch to handle stack overflow, + // but the value was found experimentally, so there is no strong guarantee + guaranteeSize = 32 * 1024; + exceptionHandlerHandle = nullptr; + // Register as first handler in current chain + exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException); + // Pass in guarantee size to be filled + SetThreadStackGuarantee(&guaranteeSize); + } + + void FatalConditionHandler::reset() { + if (isSet) { + RemoveVectoredExceptionHandler(exceptionHandlerHandle); + SetThreadStackGuarantee(&guaranteeSize); + exceptionHandlerHandle = nullptr; + isSet = false; + } + } + + FatalConditionHandler::~FatalConditionHandler() { + reset(); + } + +bool FatalConditionHandler::isSet = false; +ULONG FatalConditionHandler::guaranteeSize = 0; +PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr; + +} // namespace Catch + +#elif defined( CATCH_CONFIG_POSIX_SIGNALS ) + +namespace Catch { + + struct SignalDefs { + int id; + const char* name; + }; + static SignalDefs signalDefs[] = { + { SIGINT, "SIGINT - Terminal interrupt signal" }, + { SIGILL, "SIGILL - Illegal instruction signal" }, + { SIGFPE, "SIGFPE - Floating point error signal" }, + { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, + { SIGTERM, "SIGTERM - Termination request signal" }, + { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } + }; + + void FatalConditionHandler::handleSignal( int sig ) { + char const * name = ""; + for (auto const& def : signalDefs) { + if (sig == def.id) { + name = def.name; + break; + } + } + reset(); + reportFatal(name); + raise( sig ); + } + + FatalConditionHandler::FatalConditionHandler() { + isSet = true; + stack_t sigStack; + sigStack.ss_sp = altStackMem; + sigStack.ss_size = SIGSTKSZ; + sigStack.ss_flags = 0; + sigaltstack(&sigStack, &oldSigStack); + struct sigaction sa = { }; + + sa.sa_handler = handleSignal; + sa.sa_flags = SA_ONSTACK; + for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) { + sigaction(signalDefs[i].id, &sa, &oldSigActions[i]); + } + } + + FatalConditionHandler::~FatalConditionHandler() { + reset(); + } + + void FatalConditionHandler::reset() { + if( isSet ) { + // Set signals back to previous values -- hopefully nobody overwrote them in the meantime + for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) { + sigaction(signalDefs[i].id, &oldSigActions[i], nullptr); + } + // Return the old stack + sigaltstack(&oldSigStack, nullptr); + isSet = false; + } + } + + bool FatalConditionHandler::isSet = false; + struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {}; + stack_t FatalConditionHandler::oldSigStack = {}; + char FatalConditionHandler::altStackMem[SIGSTKSZ] = {}; + +} // namespace Catch + +#else + +namespace Catch { + void FatalConditionHandler::reset() {} +} + +#endif // signals/SEH handling + +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif +// end catch_fatal_condition.cpp +// start catch_interfaces_capture.cpp + +namespace Catch { + IResultCapture::~IResultCapture() = default; +} +// end catch_interfaces_capture.cpp +// start catch_interfaces_config.cpp + +namespace Catch { + IConfig::~IConfig() = default; +} +// end catch_interfaces_config.cpp +// start catch_interfaces_exception.cpp + +namespace Catch { + IExceptionTranslator::~IExceptionTranslator() = default; + IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default; +} +// end catch_interfaces_exception.cpp +// start catch_interfaces_registry_hub.cpp + +namespace Catch { + IRegistryHub::~IRegistryHub() = default; + IMutableRegistryHub::~IMutableRegistryHub() = default; +} +// end catch_interfaces_registry_hub.cpp +// start catch_interfaces_reporter.cpp + +// start catch_reporter_multi.h + +namespace Catch { + + class MultipleReporters : public IStreamingReporter { + using Reporters = std::vector; + Reporters m_reporters; + + public: + void add( IStreamingReporterPtr&& reporter ); + + public: // IStreamingReporter + + ReporterPreferences getPreferences() const override; + + void noMatchingTestCases( std::string const& spec ) override; + + static std::set getSupportedVerbosities(); + + void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override; + void benchmarkEnded( BenchmarkStats const& benchmarkStats ) override; + + void testRunStarting( TestRunInfo const& testRunInfo ) override; + void testGroupStarting( GroupInfo const& groupInfo ) override; + void testCaseStarting( TestCaseInfo const& testInfo ) override; + void sectionStarting( SectionInfo const& sectionInfo ) override; + void assertionStarting( AssertionInfo const& assertionInfo ) override; + + // The return value indicates if the messages buffer should be cleared: + bool assertionEnded( AssertionStats const& assertionStats ) override; + void sectionEnded( SectionStats const& sectionStats ) override; + void testCaseEnded( TestCaseStats const& testCaseStats ) override; + void testGroupEnded( TestGroupStats const& testGroupStats ) override; + void testRunEnded( TestRunStats const& testRunStats ) override; + + void skipTest( TestCaseInfo const& testInfo ) override; + bool isMulti() const override; + + }; + +} // end namespace Catch + +// end catch_reporter_multi.h +namespace Catch { + + ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig ) + : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} + + ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ) + : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} + + std::ostream& ReporterConfig::stream() const { return *m_stream; } + IConfigPtr ReporterConfig::fullConfig() const { return m_fullConfig; } + + TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {} + + GroupInfo::GroupInfo( std::string const& _name, + std::size_t _groupIndex, + std::size_t _groupsCount ) + : name( _name ), + groupIndex( _groupIndex ), + groupsCounts( _groupsCount ) + {} + + AssertionStats::AssertionStats( AssertionResult const& _assertionResult, + std::vector const& _infoMessages, + Totals const& _totals ) + : assertionResult( _assertionResult ), + infoMessages( _infoMessages ), + totals( _totals ) + { + assertionResult.m_resultData.lazyExpression.m_transientExpression = _assertionResult.m_resultData.lazyExpression.m_transientExpression; + + if( assertionResult.hasMessage() ) { + // Copy message into messages list. + // !TBD This should have been done earlier, somewhere + MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); + builder << assertionResult.getMessage(); + builder.m_info.message = builder.m_stream.str(); + + infoMessages.push_back( builder.m_info ); + } + } + + AssertionStats::~AssertionStats() = default; + + SectionStats::SectionStats( SectionInfo const& _sectionInfo, + Counts const& _assertions, + double _durationInSeconds, + bool _missingAssertions ) + : sectionInfo( _sectionInfo ), + assertions( _assertions ), + durationInSeconds( _durationInSeconds ), + missingAssertions( _missingAssertions ) + {} + + SectionStats::~SectionStats() = default; + + TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo, + Totals const& _totals, + std::string const& _stdOut, + std::string const& _stdErr, + bool _aborting ) + : testInfo( _testInfo ), + totals( _totals ), + stdOut( _stdOut ), + stdErr( _stdErr ), + aborting( _aborting ) + {} + + TestCaseStats::~TestCaseStats() = default; + + TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo, + Totals const& _totals, + bool _aborting ) + : groupInfo( _groupInfo ), + totals( _totals ), + aborting( _aborting ) + {} + + TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo ) + : groupInfo( _groupInfo ), + aborting( false ) + {} + + TestGroupStats::~TestGroupStats() = default; + + TestRunStats::TestRunStats( TestRunInfo const& _runInfo, + Totals const& _totals, + bool _aborting ) + : runInfo( _runInfo ), + totals( _totals ), + aborting( _aborting ) + {} + + TestRunStats::~TestRunStats() = default; + + void IStreamingReporter::fatalErrorEncountered( StringRef ) {} + bool IStreamingReporter::isMulti() const { return false; } + + IReporterFactory::~IReporterFactory() = default; + IReporterRegistry::~IReporterRegistry() = default; + + void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ) { + + if( !existingReporter ) { + existingReporter = std::move( additionalReporter ); + return; + } + + MultipleReporters* multi = nullptr; + + if( existingReporter->isMulti() ) { + multi = static_cast( existingReporter.get() ); + } + else { + auto newMulti = std::unique_ptr( new MultipleReporters ); + newMulti->add( std::move( existingReporter ) ); + multi = newMulti.get(); + existingReporter = std::move( newMulti ); + } + multi->add( std::move( additionalReporter ) ); + } + +} // end namespace Catch +// end catch_interfaces_reporter.cpp +// start catch_interfaces_runner.cpp + +namespace Catch { + IRunner::~IRunner() = default; +} +// end catch_interfaces_runner.cpp +// start catch_interfaces_testcase.cpp + +namespace Catch { + ITestInvoker::~ITestInvoker() = default; + ITestCaseRegistry::~ITestCaseRegistry() = default; +} +// end catch_interfaces_testcase.cpp +// start catch_leak_detector.cpp + +#ifdef CATCH_CONFIG_WINDOWS_CRTDBG +#include + +namespace Catch { + + LeakDetector::LeakDetector() { + int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + flag |= _CRTDBG_LEAK_CHECK_DF; + flag |= _CRTDBG_ALLOC_MEM_DF; + _CrtSetDbgFlag(flag); + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + // Change this to leaking allocation's number to break there + _CrtSetBreakAlloc(-1); + } +} + +#else + + Catch::LeakDetector::LeakDetector() {} + +#endif +// end catch_leak_detector.cpp +// start catch_list.cpp + +// start catch_list.h + +#include + +namespace Catch { + + std::size_t listTests( Config const& config ); + + std::size_t listTestsNamesOnly( Config const& config ); + + struct TagInfo { + void add( std::string const& spelling ); + std::string all() const; + + std::set spellings; + std::size_t count = 0; + }; + + std::size_t listTags( Config const& config ); + + std::size_t listReporters( Config const& /*config*/ ); + + Option list( Config const& config ); + +} // end namespace Catch + +// end catch_list.h +// start catch_text.h + +namespace Catch { + using namespace clara::TextFlow; +} + +// end catch_text.h +#include +#include +#include + +namespace Catch { + + std::size_t listTests( Config const& config ) { + TestSpec testSpec = config.testSpec(); + if( config.hasTestFilters() ) + Catch::cout() << "Matching test cases:\n"; + else { + Catch::cout() << "All available test cases:\n"; + } + + auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( auto const& testCaseInfo : matchedTestCases ) { + Colour::Code colour = testCaseInfo.isHidden() + ? Colour::SecondaryText + : Colour::None; + Colour colourGuard( colour ); + + Catch::cout() << Column( testCaseInfo.name ).initialIndent( 2 ).indent( 4 ) << "\n"; + if( config.verbosity() >= Verbosity::High ) { + Catch::cout() << Column( Catch::Detail::stringify( testCaseInfo.lineInfo ) ).indent(4) << std::endl; + std::string description = testCaseInfo.description; + if( description.empty() ) + description = "(NO DESCRIPTION)"; + Catch::cout() << Column( description ).indent(4) << std::endl; + } + if( !testCaseInfo.tags.empty() ) + Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n"; + } + + if( !config.hasTestFilters() ) + Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl; + else + Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl; + return matchedTestCases.size(); + } + + std::size_t listTestsNamesOnly( Config const& config ) { + TestSpec testSpec = config.testSpec(); + std::size_t matchedTests = 0; + std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( auto const& testCaseInfo : matchedTestCases ) { + matchedTests++; + if( startsWith( testCaseInfo.name, '#' ) ) + Catch::cout() << '"' << testCaseInfo.name << '"'; + else + Catch::cout() << testCaseInfo.name; + if ( config.verbosity() >= Verbosity::High ) + Catch::cout() << "\t@" << testCaseInfo.lineInfo; + Catch::cout() << std::endl; + } + return matchedTests; + } + + void TagInfo::add( std::string const& spelling ) { + ++count; + spellings.insert( spelling ); + } + + std::string TagInfo::all() const { + std::string out; + for( auto const& spelling : spellings ) + out += "[" + spelling + "]"; + return out; + } + + std::size_t listTags( Config const& config ) { + TestSpec testSpec = config.testSpec(); + if( config.hasTestFilters() ) + Catch::cout() << "Tags for matching test cases:\n"; + else { + Catch::cout() << "All available tags:\n"; + } + + std::map tagCounts; + + std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( auto const& testCase : matchedTestCases ) { + for( auto const& tagName : testCase.getTestCaseInfo().tags ) { + std::string lcaseTagName = toLower( tagName ); + auto countIt = tagCounts.find( lcaseTagName ); + if( countIt == tagCounts.end() ) + countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; + countIt->second.add( tagName ); + } + } + + for( auto const& tagCount : tagCounts ) { + ReusableStringStream rss; + rss << " " << std::setw(2) << tagCount.second.count << " "; + auto str = rss.str(); + auto wrapper = Column( tagCount.second.all() ) + .initialIndent( 0 ) + .indent( str.size() ) + .width( CATCH_CONFIG_CONSOLE_WIDTH-10 ); + Catch::cout() << str << wrapper << '\n'; + } + Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl; + return tagCounts.size(); + } + + std::size_t listReporters( Config const& /*config*/ ) { + Catch::cout() << "Available reporters:\n"; + IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); + std::size_t maxNameLen = 0; + for( auto const& factoryKvp : factories ) + maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() ); + + for( auto const& factoryKvp : factories ) { + Catch::cout() + << Column( factoryKvp.first + ":" ) + .indent(2) + .width( 5+maxNameLen ) + + Column( factoryKvp.second->getDescription() ) + .initialIndent(0) + .indent(2) + .width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) + << "\n"; + } + Catch::cout() << std::endl; + return factories.size(); + } + + Option list( Config const& config ) { + Option listedCount; + if( config.listTests() ) + listedCount = listedCount.valueOr(0) + listTests( config ); + if( config.listTestNamesOnly() ) + listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config ); + if( config.listTags() ) + listedCount = listedCount.valueOr(0) + listTags( config ); + if( config.listReporters() ) + listedCount = listedCount.valueOr(0) + listReporters( config ); + return listedCount; + } + +} // end namespace Catch +// end catch_list.cpp +// start catch_matchers.cpp + +namespace Catch { +namespace Matchers { + namespace Impl { + + std::string MatcherUntypedBase::toString() const { + if( m_cachedToString.empty() ) + m_cachedToString = describe(); + return m_cachedToString; + } + + MatcherUntypedBase::~MatcherUntypedBase() = default; + + } // namespace Impl +} // namespace Matchers + +using namespace Matchers; +using Matchers::Impl::MatcherBase; + +} // namespace Catch +// end catch_matchers.cpp +// start catch_matchers_floating.cpp + +#include +#include +#include +#include + +namespace Catch { +namespace Matchers { +namespace Floating { +enum class FloatingPointKind : uint8_t { + Float, + Double +}; +} +} +} + +namespace { + +template +struct Converter; + +template <> +struct Converter { + static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated"); + Converter(float f) { + std::memcpy(&i, &f, sizeof(f)); + } + int32_t i; +}; + +template <> +struct Converter { + static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated"); + Converter(double d) { + std::memcpy(&i, &d, sizeof(d)); + } + int64_t i; +}; + +template +auto convert(T t) -> Converter { + return Converter(t); +} + +template +bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) { + // Comparison with NaN should always be false. + // This way we can rule it out before getting into the ugly details + if (std::isnan(lhs) || std::isnan(rhs)) { + return false; + } + + auto lc = convert(lhs); + auto rc = convert(rhs); + + if ((lc.i < 0) != (rc.i < 0)) { + // Potentially we can have +0 and -0 + return lhs == rhs; + } + + auto ulpDiff = std::abs(lc.i - rc.i); + return ulpDiff <= maxUlpDiff; +} + +} + +namespace Catch { +namespace Matchers { +namespace Floating { + WithinAbsMatcher::WithinAbsMatcher(double target, double margin) + :m_target{ target }, m_margin{ margin } { + if (m_margin < 0) { + throw std::domain_error("Allowed margin difference has to be >= 0"); + } + } + + // Performs equivalent check of std::fabs(lhs - rhs) <= margin + // But without the subtraction to allow for INFINITY in comparison + bool WithinAbsMatcher::match(double const& matchee) const { + return (matchee + m_margin >= m_target) && (m_target + m_margin >= matchee); + } + + std::string WithinAbsMatcher::describe() const { + return "is within " + ::Catch::Detail::stringify(m_margin) + " of " + ::Catch::Detail::stringify(m_target); + } + + WithinUlpsMatcher::WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType) + :m_target{ target }, m_ulps{ ulps }, m_type{ baseType } { + if (m_ulps < 0) { + throw std::domain_error("Allowed ulp difference has to be >= 0"); + } + } + + bool WithinUlpsMatcher::match(double const& matchee) const { + switch (m_type) { + case FloatingPointKind::Float: + return almostEqualUlps(static_cast(matchee), static_cast(m_target), m_ulps); + case FloatingPointKind::Double: + return almostEqualUlps(matchee, m_target, m_ulps); + default: + throw std::domain_error("Unknown FloatingPointKind value"); + } + } + + std::string WithinUlpsMatcher::describe() const { + return "is within " + std::to_string(m_ulps) + " ULPs of " + ::Catch::Detail::stringify(m_target) + ((m_type == FloatingPointKind::Float)? "f" : ""); + } + +}// namespace Floating + +Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff) { + return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Double); +} + +Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff) { + return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Float); +} + +Floating::WithinAbsMatcher WithinAbs(double target, double margin) { + return Floating::WithinAbsMatcher(target, margin); +} + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_floating.cpp +// start catch_matchers_generic.cpp + +std::string Catch::Matchers::Generic::Detail::finalizeDescription(const std::string& desc) { + if (desc.empty()) { + return "matches undescribed predicate"; + } else { + return "matches predicate: \"" + desc + '"'; + } +} +// end catch_matchers_generic.cpp +// start catch_matchers_string.cpp + +#include + +namespace Catch { +namespace Matchers { + + namespace StdString { + + CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) + : m_caseSensitivity( caseSensitivity ), + m_str( adjustString( str ) ) + {} + std::string CasedString::adjustString( std::string const& str ) const { + return m_caseSensitivity == CaseSensitive::No + ? toLower( str ) + : str; + } + std::string CasedString::caseSensitivitySuffix() const { + return m_caseSensitivity == CaseSensitive::No + ? " (case insensitive)" + : std::string(); + } + + StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator ) + : m_comparator( comparator ), + m_operation( operation ) { + } + + std::string StringMatcherBase::describe() const { + std::string description; + description.reserve(5 + m_operation.size() + m_comparator.m_str.size() + + m_comparator.caseSensitivitySuffix().size()); + description += m_operation; + description += ": \""; + description += m_comparator.m_str; + description += "\""; + description += m_comparator.caseSensitivitySuffix(); + return description; + } + + EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {} + + bool EqualsMatcher::match( std::string const& source ) const { + return m_comparator.adjustString( source ) == m_comparator.m_str; + } + + ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {} + + bool ContainsMatcher::match( std::string const& source ) const { + return contains( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {} + + bool StartsWithMatcher::match( std::string const& source ) const { + return startsWith( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {} + + bool EndsWithMatcher::match( std::string const& source ) const { + return endsWith( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {} + + bool RegexMatcher::match(std::string const& matchee) const { + auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway + if (m_caseSensitivity == CaseSensitive::Choice::No) { + flags |= std::regex::icase; + } + auto reg = std::regex(m_regex, flags); + return std::regex_match(matchee, reg); + } + + std::string RegexMatcher::describe() const { + return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively"); + } + + } // namespace StdString + + StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) ); + } + + StdString::RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) { + return StdString::RegexMatcher(regex, caseSensitivity); + } + +} // namespace Matchers +} // namespace Catch +// end catch_matchers_string.cpp +// start catch_message.cpp + +// start catch_uncaught_exceptions.h + +namespace Catch { + bool uncaught_exceptions(); +} // end namespace Catch + +// end catch_uncaught_exceptions.h +namespace Catch { + + MessageInfo::MessageInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ) + : macroName( _macroName ), + lineInfo( _lineInfo ), + type( _type ), + sequence( ++globalCount ) + {} + + bool MessageInfo::operator==( MessageInfo const& other ) const { + return sequence == other.sequence; + } + + bool MessageInfo::operator<( MessageInfo const& other ) const { + return sequence < other.sequence; + } + + // This may need protecting if threading support is added + unsigned int MessageInfo::globalCount = 0; + + //////////////////////////////////////////////////////////////////////////// + + Catch::MessageBuilder::MessageBuilder( std::string const& macroName, + SourceLineInfo const& lineInfo, + ResultWas::OfType type ) + :m_info(macroName, lineInfo, type) {} + + //////////////////////////////////////////////////////////////////////////// + + ScopedMessage::ScopedMessage( MessageBuilder const& builder ) + : m_info( builder.m_info ) + { + m_info.message = builder.m_stream.str(); + getResultCapture().pushScopedMessage( m_info ); + } + + ScopedMessage::~ScopedMessage() { + if ( !uncaught_exceptions() ){ + getResultCapture().popScopedMessage(m_info); + } + } +} // end namespace Catch +// end catch_message.cpp +// start catch_random_number_generator.cpp + +// start catch_random_number_generator.h + +#include + +namespace Catch { + + struct IConfig; + + void seedRng( IConfig const& config ); + + unsigned int rngSeed(); + + struct RandomNumberGenerator { + using result_type = unsigned int; + + static constexpr result_type (min)() { return 0; } + static constexpr result_type (max)() { return 1000000; } + + result_type operator()( result_type n ) const; + result_type operator()() const; + + template + static void shuffle( V& vector ) { + RandomNumberGenerator rng; + std::shuffle( vector.begin(), vector.end(), rng ); + } + }; + +} + +// end catch_random_number_generator.h +#include + +namespace Catch { + + void seedRng( IConfig const& config ) { + if( config.rngSeed() != 0 ) + std::srand( config.rngSeed() ); + } + unsigned int rngSeed() { + return getCurrentContext().getConfig()->rngSeed(); + } + + RandomNumberGenerator::result_type RandomNumberGenerator::operator()( result_type n ) const { + return std::rand() % n; + } + RandomNumberGenerator::result_type RandomNumberGenerator::operator()() const { + return std::rand() % (max)(); + } + +} +// end catch_random_number_generator.cpp +// start catch_registry_hub.cpp + +// start catch_test_case_registry_impl.h + +#include +#include +#include +#include + +namespace Catch { + + class TestCase; + struct IConfig; + + std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + + void enforceNoDuplicateTestCases( std::vector const& functions ); + + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + + class TestRegistry : public ITestCaseRegistry { + public: + virtual ~TestRegistry() = default; + + virtual void registerTest( TestCase const& testCase ); + + std::vector const& getAllTests() const override; + std::vector const& getAllTestsSorted( IConfig const& config ) const override; + + private: + std::vector m_functions; + mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder; + mutable std::vector m_sortedFunctions; + std::size_t m_unnamedCount = 0; + std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised + }; + + /////////////////////////////////////////////////////////////////////////// + + class TestInvokerAsFunction : public ITestInvoker { + void(*m_testAsFunction)(); + public: + TestInvokerAsFunction( void(*testAsFunction)() ) noexcept; + + void invoke() const override; + }; + + std::string extractClassName( StringRef const& classOrQualifiedMethodName ); + + /////////////////////////////////////////////////////////////////////////// + +} // end namespace Catch + +// end catch_test_case_registry_impl.h +// start catch_reporter_registry.h + +#include + +namespace Catch { + + class ReporterRegistry : public IReporterRegistry { + + public: + + ~ReporterRegistry() override; + + IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override; + + void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ); + void registerListener( IReporterFactoryPtr const& factory ); + + FactoryMap const& getFactories() const override; + Listeners const& getListeners() const override; + + private: + FactoryMap m_factories; + Listeners m_listeners; + }; +} + +// end catch_reporter_registry.h +// start catch_tag_alias_registry.h + +// start catch_tag_alias.h + +#include + +namespace Catch { + + struct TagAlias { + TagAlias(std::string const& _tag, SourceLineInfo _lineInfo); + + std::string tag; + SourceLineInfo lineInfo; + }; + +} // end namespace Catch + +// end catch_tag_alias.h +#include + +namespace Catch { + + class TagAliasRegistry : public ITagAliasRegistry { + public: + ~TagAliasRegistry() override; + TagAlias const* find( std::string const& alias ) const override; + std::string expandAliases( std::string const& unexpandedTestSpec ) const override; + void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ); + + private: + std::map m_registry; + }; + +} // end namespace Catch + +// end catch_tag_alias_registry.h +// start catch_startup_exception_registry.h + +#include +#include + +namespace Catch { + + class StartupExceptionRegistry { + public: + void add(std::exception_ptr const& exception) noexcept; + std::vector const& getExceptions() const noexcept; + private: + std::vector m_exceptions; + }; + +} // end namespace Catch + +// end catch_startup_exception_registry.h +namespace Catch { + + namespace { + + class RegistryHub : public IRegistryHub, public IMutableRegistryHub, + private NonCopyable { + + public: // IRegistryHub + RegistryHub() = default; + IReporterRegistry const& getReporterRegistry() const override { + return m_reporterRegistry; + } + ITestCaseRegistry const& getTestCaseRegistry() const override { + return m_testCaseRegistry; + } + IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() override { + return m_exceptionTranslatorRegistry; + } + ITagAliasRegistry const& getTagAliasRegistry() const override { + return m_tagAliasRegistry; + } + StartupExceptionRegistry const& getStartupExceptionRegistry() const override { + return m_exceptionRegistry; + } + + public: // IMutableRegistryHub + void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override { + m_reporterRegistry.registerReporter( name, factory ); + } + void registerListener( IReporterFactoryPtr const& factory ) override { + m_reporterRegistry.registerListener( factory ); + } + void registerTest( TestCase const& testInfo ) override { + m_testCaseRegistry.registerTest( testInfo ); + } + void registerTranslator( const IExceptionTranslator* translator ) override { + m_exceptionTranslatorRegistry.registerTranslator( translator ); + } + void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { + m_tagAliasRegistry.add( alias, tag, lineInfo ); + } + void registerStartupException() noexcept override { + m_exceptionRegistry.add(std::current_exception()); + } + + private: + TestRegistry m_testCaseRegistry; + ReporterRegistry m_reporterRegistry; + ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; + TagAliasRegistry m_tagAliasRegistry; + StartupExceptionRegistry m_exceptionRegistry; + }; + + // Single, global, instance + RegistryHub*& getTheRegistryHub() { + static RegistryHub* theRegistryHub = nullptr; + if( !theRegistryHub ) + theRegistryHub = new RegistryHub(); + return theRegistryHub; + } + } + + IRegistryHub& getRegistryHub() { + return *getTheRegistryHub(); + } + IMutableRegistryHub& getMutableRegistryHub() { + return *getTheRegistryHub(); + } + void cleanUp() { + delete getTheRegistryHub(); + getTheRegistryHub() = nullptr; + cleanUpContext(); + ReusableStringStream::cleanup(); + } + std::string translateActiveException() { + return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); + } + +} // end namespace Catch +// end catch_registry_hub.cpp +// start catch_reporter_registry.cpp + +namespace Catch { + + ReporterRegistry::~ReporterRegistry() = default; + + IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const { + auto it = m_factories.find( name ); + if( it == m_factories.end() ) + return nullptr; + return it->second->create( ReporterConfig( config ) ); + } + + void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) { + m_factories.emplace(name, factory); + } + void ReporterRegistry::registerListener( IReporterFactoryPtr const& factory ) { + m_listeners.push_back( factory ); + } + + IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const { + return m_factories; + } + IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const { + return m_listeners; + } + +} +// end catch_reporter_registry.cpp +// start catch_result_type.cpp + +namespace Catch { + + bool isOk( ResultWas::OfType resultType ) { + return ( resultType & ResultWas::FailureBit ) == 0; + } + bool isJustInfo( int flags ) { + return flags == ResultWas::Info; + } + + ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { + return static_cast( static_cast( lhs ) | static_cast( rhs ) ); + } + + bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } + bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } + +} // end namespace Catch +// end catch_result_type.cpp +// start catch_run_context.cpp + +#include +#include +#include + +namespace Catch { + + class RedirectedStream { + std::ostream& m_originalStream; + std::ostream& m_redirectionStream; + std::streambuf* m_prevBuf; + + public: + RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream ) + : m_originalStream( originalStream ), + m_redirectionStream( redirectionStream ), + m_prevBuf( m_originalStream.rdbuf() ) + { + m_originalStream.rdbuf( m_redirectionStream.rdbuf() ); + } + ~RedirectedStream() { + m_originalStream.rdbuf( m_prevBuf ); + } + }; + + class RedirectedStdOut { + ReusableStringStream m_rss; + RedirectedStream m_cout; + public: + RedirectedStdOut() : m_cout( Catch::cout(), m_rss.get() ) {} + auto str() const -> std::string { return m_rss.str(); } + }; + + // StdErr has two constituent streams in C++, std::cerr and std::clog + // This means that we need to redirect 2 streams into 1 to keep proper + // order of writes + class RedirectedStdErr { + ReusableStringStream m_rss; + RedirectedStream m_cerr; + RedirectedStream m_clog; + public: + RedirectedStdErr() + : m_cerr( Catch::cerr(), m_rss.get() ), + m_clog( Catch::clog(), m_rss.get() ) + {} + auto str() const -> std::string { return m_rss.str(); } + }; + + RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter) + : m_runInfo(_config->name()), + m_context(getCurrentMutableContext()), + m_config(_config), + m_reporter(std::move(reporter)), + m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal }, + m_includeSuccessfulResults( m_config->includeSuccessfulResults() ) + { + m_context.setRunner(this); + m_context.setConfig(m_config); + m_context.setResultCapture(this); + m_reporter->testRunStarting(m_runInfo); + } + + RunContext::~RunContext() { + m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting())); + } + + void RunContext::testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount) { + m_reporter->testGroupStarting(GroupInfo(testSpec, groupIndex, groupsCount)); + } + + void RunContext::testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount) { + m_reporter->testGroupEnded(TestGroupStats(GroupInfo(testSpec, groupIndex, groupsCount), totals, aborting())); + } + + Totals RunContext::runTest(TestCase const& testCase) { + Totals prevTotals = m_totals; + + std::string redirectedCout; + std::string redirectedCerr; + + auto const& testInfo = testCase.getTestCaseInfo(); + + m_reporter->testCaseStarting(testInfo); + + m_activeTestCase = &testCase; + + ITracker& rootTracker = m_trackerContext.startRun(); + assert(rootTracker.isSectionTracker()); + static_cast(rootTracker).addInitialFilters(m_config->getSectionsToRun()); + do { + m_trackerContext.startCycle(); + m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo)); + runCurrentTest(redirectedCout, redirectedCerr); + } while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting()); + + Totals deltaTotals = m_totals.delta(prevTotals); + if (testInfo.expectedToFail() && deltaTotals.testCases.passed > 0) { + deltaTotals.assertions.failed++; + deltaTotals.testCases.passed--; + deltaTotals.testCases.failed++; + } + m_totals.testCases += deltaTotals.testCases; + m_reporter->testCaseEnded(TestCaseStats(testInfo, + deltaTotals, + redirectedCout, + redirectedCerr, + aborting())); + + m_activeTestCase = nullptr; + m_testCaseTracker = nullptr; + + return deltaTotals; + } + + IConfigPtr RunContext::config() const { + return m_config; + } + + IStreamingReporter& RunContext::reporter() const { + return *m_reporter; + } + + void RunContext::assertionEnded(AssertionResult const & result) { + if (result.getResultType() == ResultWas::Ok) { + m_totals.assertions.passed++; + m_lastAssertionPassed = true; + } else if (!result.isOk()) { + m_lastAssertionPassed = false; + if( m_activeTestCase->getTestCaseInfo().okToFail() ) + m_totals.assertions.failedButOk++; + else + m_totals.assertions.failed++; + } + else { + m_lastAssertionPassed = true; + } + + // We have no use for the return value (whether messages should be cleared), because messages were made scoped + // and should be let to clear themselves out. + static_cast(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals))); + + // Reset working state + resetAssertionInfo(); + m_lastResult = result; + } + void RunContext::resetAssertionInfo() { + m_lastAssertionInfo.macroName = StringRef(); + m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr; + } + + bool RunContext::sectionStarted(SectionInfo const & sectionInfo, Counts & assertions) { + ITracker& sectionTracker = SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(sectionInfo.name, sectionInfo.lineInfo)); + if (!sectionTracker.isOpen()) + return false; + m_activeSections.push_back(§ionTracker); + + m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; + + m_reporter->sectionStarting(sectionInfo); + + assertions = m_totals.assertions; + + return true; + } + + bool RunContext::testForMissingAssertions(Counts& assertions) { + if (assertions.total() != 0) + return false; + if (!m_config->warnAboutMissingAssertions()) + return false; + if (m_trackerContext.currentTracker().hasChildren()) + return false; + m_totals.assertions.failed++; + assertions.failed++; + return true; + } + + void RunContext::sectionEnded(SectionEndInfo const & endInfo) { + Counts assertions = m_totals.assertions - endInfo.prevAssertions; + bool missingAssertions = testForMissingAssertions(assertions); + + if (!m_activeSections.empty()) { + m_activeSections.back()->close(); + m_activeSections.pop_back(); + } + + m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions)); + m_messages.clear(); + } + + void RunContext::sectionEndedEarly(SectionEndInfo const & endInfo) { + if (m_unfinishedSections.empty()) + m_activeSections.back()->fail(); + else + m_activeSections.back()->close(); + m_activeSections.pop_back(); + + m_unfinishedSections.push_back(endInfo); + } + void RunContext::benchmarkStarting( BenchmarkInfo const& info ) { + m_reporter->benchmarkStarting( info ); + } + void RunContext::benchmarkEnded( BenchmarkStats const& stats ) { + m_reporter->benchmarkEnded( stats ); + } + + void RunContext::pushScopedMessage(MessageInfo const & message) { + m_messages.push_back(message); + } + + void RunContext::popScopedMessage(MessageInfo const & message) { + m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end()); + } + + std::string RunContext::getCurrentTestName() const { + return m_activeTestCase + ? m_activeTestCase->getTestCaseInfo().name + : std::string(); + } + + const AssertionResult * RunContext::getLastResult() const { + return &(*m_lastResult); + } + + void RunContext::exceptionEarlyReported() { + m_shouldReportUnexpected = false; + } + + void RunContext::handleFatalErrorCondition( StringRef message ) { + // First notify reporter that bad things happened + m_reporter->fatalErrorEncountered(message); + + // Don't rebuild the result -- the stringification itself can cause more fatal errors + // Instead, fake a result data. + AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } ); + tempResult.message = message; + AssertionResult result(m_lastAssertionInfo, tempResult); + + assertionEnded(result); + + handleUnfinishedSections(); + + // Recreate section for test case (as we will lose the one that was in scope) + auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); + + Counts assertions; + assertions.failed = 1; + SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false); + m_reporter->sectionEnded(testCaseSectionStats); + + auto const& testInfo = m_activeTestCase->getTestCaseInfo(); + + Totals deltaTotals; + deltaTotals.testCases.failed = 1; + deltaTotals.assertions.failed = 1; + m_reporter->testCaseEnded(TestCaseStats(testInfo, + deltaTotals, + std::string(), + std::string(), + false)); + m_totals.testCases.failed++; + testGroupEnded(std::string(), m_totals, 1, 1); + m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false)); + } + + bool RunContext::lastAssertionPassed() { + return m_lastAssertionPassed; + } + + void RunContext::assertionPassed() { + m_lastAssertionPassed = true; + ++m_totals.assertions.passed; + resetAssertionInfo(); + } + + bool RunContext::aborting() const { + return m_totals.assertions.failed == static_cast(m_config->abortAfter()); + } + + void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) { + auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); + m_reporter->sectionStarting(testCaseSection); + Counts prevAssertions = m_totals.assertions; + double duration = 0; + m_shouldReportUnexpected = true; + m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal }; + + seedRng(*m_config); + + Timer timer; + try { + if (m_reporter->getPreferences().shouldRedirectStdOut) { + RedirectedStdOut redirectedStdOut; + RedirectedStdErr redirectedStdErr; + timer.start(); + invokeActiveTestCase(); + redirectedCout += redirectedStdOut.str(); + redirectedCerr += redirectedStdErr.str(); + + } else { + timer.start(); + invokeActiveTestCase(); + } + duration = timer.getElapsedSeconds(); + } catch (TestFailureException&) { + // This just means the test was aborted due to failure + } catch (...) { + // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions + // are reported without translation at the point of origin. + if( m_shouldReportUnexpected ) { + AssertionReaction dummyReaction; + handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction ); + } + } + Counts assertions = m_totals.assertions - prevAssertions; + bool missingAssertions = testForMissingAssertions(assertions); + + m_testCaseTracker->close(); + handleUnfinishedSections(); + m_messages.clear(); + + SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions); + m_reporter->sectionEnded(testCaseSectionStats); + } + + void RunContext::invokeActiveTestCase() { + FatalConditionHandler fatalConditionHandler; // Handle signals + m_activeTestCase->invoke(); + fatalConditionHandler.reset(); + } + + void RunContext::handleUnfinishedSections() { + // If sections ended prematurely due to an exception we stored their + // infos here so we can tear them down outside the unwind process. + for (auto it = m_unfinishedSections.rbegin(), + itEnd = m_unfinishedSections.rend(); + it != itEnd; + ++it) + sectionEnded(*it); + m_unfinishedSections.clear(); + } + + void RunContext::handleExpr( + AssertionInfo const& info, + ITransientExpression const& expr, + AssertionReaction& reaction + ) { + m_reporter->assertionStarting( info ); + + bool negated = isFalseTest( info.resultDisposition ); + bool result = expr.getResult() != negated; + + if( result ) { + if (!m_includeSuccessfulResults) { + assertionPassed(); + } + else { + reportExpr(info, ResultWas::Ok, &expr, negated); + } + } + else { + reportExpr(info, ResultWas::ExpressionFailed, &expr, negated ); + populateReaction( reaction ); + } + } + void RunContext::reportExpr( + AssertionInfo const &info, + ResultWas::OfType resultType, + ITransientExpression const *expr, + bool negated ) { + + m_lastAssertionInfo = info; + AssertionResultData data( resultType, LazyExpression( negated ) ); + + AssertionResult assertionResult{ info, data }; + assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; + + assertionEnded( assertionResult ); + } + + void RunContext::handleMessage( + AssertionInfo const& info, + ResultWas::OfType resultType, + StringRef const& message, + AssertionReaction& reaction + ) { + m_reporter->assertionStarting( info ); + + m_lastAssertionInfo = info; + + AssertionResultData data( resultType, LazyExpression( false ) ); + data.message = message; + AssertionResult assertionResult{ m_lastAssertionInfo, data }; + assertionEnded( assertionResult ); + if( !assertionResult.isOk() ) + populateReaction( reaction ); + } + void RunContext::handleUnexpectedExceptionNotThrown( + AssertionInfo const& info, + AssertionReaction& reaction + ) { + handleNonExpr(info, Catch::ResultWas::DidntThrowException, reaction); + } + + void RunContext::handleUnexpectedInflightException( + AssertionInfo const& info, + std::string const& message, + AssertionReaction& reaction + ) { + m_lastAssertionInfo = info; + + AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); + data.message = message; + AssertionResult assertionResult{ info, data }; + assertionEnded( assertionResult ); + populateReaction( reaction ); + } + + void RunContext::populateReaction( AssertionReaction& reaction ) { + reaction.shouldDebugBreak = m_config->shouldDebugBreak(); + reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal); + } + + void RunContext::handleIncomplete( + AssertionInfo const& info + ) { + m_lastAssertionInfo = info; + + AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); + data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"; + AssertionResult assertionResult{ info, data }; + assertionEnded( assertionResult ); + } + void RunContext::handleNonExpr( + AssertionInfo const &info, + ResultWas::OfType resultType, + AssertionReaction &reaction + ) { + m_lastAssertionInfo = info; + + AssertionResultData data( resultType, LazyExpression( false ) ); + AssertionResult assertionResult{ info, data }; + assertionEnded( assertionResult ); + + if( !assertionResult.isOk() ) + populateReaction( reaction ); + } + + IResultCapture& getResultCapture() { + if (auto* capture = getCurrentContext().getResultCapture()) + return *capture; + else + CATCH_INTERNAL_ERROR("No result capture instance"); + } +} +// end catch_run_context.cpp +// start catch_section.cpp + +namespace Catch { + + Section::Section( SectionInfo const& info ) + : m_info( info ), + m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) + { + m_timer.start(); + } + + Section::~Section() { + if( m_sectionIncluded ) { + SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() ); + if( uncaught_exceptions() ) + getResultCapture().sectionEndedEarly( endInfo ); + else + getResultCapture().sectionEnded( endInfo ); + } + } + + // This indicates whether the section should be executed or not + Section::operator bool() const { + return m_sectionIncluded; + } + +} // end namespace Catch +// end catch_section.cpp +// start catch_section_info.cpp + +namespace Catch { + + SectionInfo::SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& _description ) + : name( _name ), + description( _description ), + lineInfo( _lineInfo ) + {} + + SectionEndInfo::SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ) + : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) + {} + +} // end namespace Catch +// end catch_section_info.cpp +// start catch_session.cpp + +// start catch_session.h + +#include + +namespace Catch { + + class Session : NonCopyable { + public: + + Session(); + ~Session() override; + + void showHelp() const; + void libIdentify(); + + int applyCommandLine( int argc, char const * const * argv ); + + void useConfigData( ConfigData const& configData ); + + int run( int argc, char* argv[] ); + #if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(UNICODE) + int run( int argc, wchar_t* const argv[] ); + #endif + int run(); + + clara::Parser const& cli() const; + void cli( clara::Parser const& newParser ); + ConfigData& configData(); + Config& config(); + private: + int runInternal(); + + clara::Parser m_cli; + ConfigData m_configData; + std::shared_ptr m_config; + bool m_startupExceptions = false; + }; + +} // end namespace Catch + +// end catch_session.h +// start catch_version.h + +#include + +namespace Catch { + + // Versioning information + struct Version { + Version( Version const& ) = delete; + Version& operator=( Version const& ) = delete; + Version( unsigned int _majorVersion, + unsigned int _minorVersion, + unsigned int _patchNumber, + char const * const _branchName, + unsigned int _buildNumber ); + + unsigned int const majorVersion; + unsigned int const minorVersion; + unsigned int const patchNumber; + + // buildNumber is only used if branchName is not null + char const * const branchName; + unsigned int const buildNumber; + + friend std::ostream& operator << ( std::ostream& os, Version const& version ); + }; + + Version const& libraryVersion(); +} + +// end catch_version.h +#include +#include + +namespace Catch { + + namespace { + const int MaxExitCode = 255; + + IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) { + auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config); + CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'"); + + return reporter; + } + +#ifndef CATCH_CONFIG_DEFAULT_REPORTER +#define CATCH_CONFIG_DEFAULT_REPORTER "console" +#endif + + IStreamingReporterPtr makeReporter(std::shared_ptr const& config) { + auto const& reporterNames = config->getReporterNames(); + if (reporterNames.empty()) + return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config); + + IStreamingReporterPtr reporter; + for (auto const& name : reporterNames) + addReporter(reporter, createReporter(name, config)); + return reporter; + } + +#undef CATCH_CONFIG_DEFAULT_REPORTER + + void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) { + auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); + for (auto const& listener : listeners) + addReporter(reporters, listener->create(Catch::ReporterConfig(config))); + } + + Catch::Totals runTests(std::shared_ptr const& config) { + IStreamingReporterPtr reporter = makeReporter(config); + addListeners(reporter, config); + + RunContext context(config, std::move(reporter)); + + Totals totals; + + context.testGroupStarting(config->name(), 1, 1); + + TestSpec testSpec = config->testSpec(); + + auto const& allTestCases = getAllTestCasesSorted(*config); + for (auto const& testCase : allTestCases) { + if (!context.aborting() && matchTest(testCase, testSpec, *config)) + totals += context.runTest(testCase); + else + context.reporter().skipTest(testCase); + } + + if (config->warnAboutNoTests() && totals.testCases.total() == 0) { + ReusableStringStream testConfig; + + bool first = true; + for (const auto& input : config->getTestsOrTags()) { + if (!first) { testConfig << ' '; } + first = false; + testConfig << input; + } + + context.reporter().noMatchingTestCases(testConfig.str()); + totals.error = -1; + } + + context.testGroupEnded(config->name(), totals, 1, 1); + return totals; + } + + void applyFilenamesAsTags(Catch::IConfig const& config) { + auto& tests = const_cast&>(getAllTestCasesSorted(config)); + for (auto& testCase : tests) { + auto tags = testCase.tags; + + std::string filename = testCase.lineInfo.file; + auto lastSlash = filename.find_last_of("\\/"); + if (lastSlash != std::string::npos) { + filename.erase(0, lastSlash); + filename[0] = '#'; + } + + auto lastDot = filename.find_last_of('.'); + if (lastDot != std::string::npos) { + filename.erase(lastDot); + } + + tags.push_back(std::move(filename)); + setTags(testCase, tags); + } + } + + } // anon namespace + + Session::Session() { + static bool alreadyInstantiated = false; + if( alreadyInstantiated ) { + try { CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); } + catch(...) { getMutableRegistryHub().registerStartupException(); } + } + + const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions(); + if ( !exceptions.empty() ) { + m_startupExceptions = true; + Colour colourGuard( Colour::Red ); + Catch::cerr() << "Errors occurred during startup!" << '\n'; + // iterate over all exceptions and notify user + for ( const auto& ex_ptr : exceptions ) { + try { + std::rethrow_exception(ex_ptr); + } catch ( std::exception const& ex ) { + Catch::cerr() << Column( ex.what() ).indent(2) << '\n'; + } + } + } + + alreadyInstantiated = true; + m_cli = makeCommandLineParser( m_configData ); + } + Session::~Session() { + Catch::cleanUp(); + } + + void Session::showHelp() const { + Catch::cout() + << "\nCatch v" << libraryVersion() << "\n" + << m_cli << std::endl + << "For more detailed usage please see the project docs\n" << std::endl; + } + void Session::libIdentify() { + Catch::cout() + << std::left << std::setw(16) << "description: " << "A Catch test executable\n" + << std::left << std::setw(16) << "category: " << "testframework\n" + << std::left << std::setw(16) << "framework: " << "Catch Test\n" + << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl; + } + + int Session::applyCommandLine( int argc, char const * const * argv ) { + if( m_startupExceptions ) + return 1; + + auto result = m_cli.parse( clara::Args( argc, argv ) ); + if( !result ) { + Catch::cerr() + << Colour( Colour::Red ) + << "\nError(s) in input:\n" + << Column( result.errorMessage() ).indent( 2 ) + << "\n\n"; + Catch::cerr() << "Run with -? for usage\n" << std::endl; + return MaxExitCode; + } + + if( m_configData.showHelp ) + showHelp(); + if( m_configData.libIdentify ) + libIdentify(); + m_config.reset(); + return 0; + } + + void Session::useConfigData( ConfigData const& configData ) { + m_configData = configData; + m_config.reset(); + } + + int Session::run( int argc, char* argv[] ) { + if( m_startupExceptions ) + return 1; + int returnCode = applyCommandLine( argc, argv ); + if( returnCode == 0 ) + returnCode = run(); + return returnCode; + } + +#if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(UNICODE) + int Session::run( int argc, wchar_t* const argv[] ) { + + char **utf8Argv = new char *[ argc ]; + + for ( int i = 0; i < argc; ++i ) { + int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL ); + + utf8Argv[ i ] = new char[ bufSize ]; + + WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL ); + } + + int returnCode = run( argc, utf8Argv ); + + for ( int i = 0; i < argc; ++i ) + delete [] utf8Argv[ i ]; + + delete [] utf8Argv; + + return returnCode; + } +#endif + int Session::run() { + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) { + Catch::cout() << "...waiting for enter/ return before starting" << std::endl; + static_cast(std::getchar()); + } + int exitCode = runInternal(); + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) { + Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl; + static_cast(std::getchar()); + } + return exitCode; + } + + clara::Parser const& Session::cli() const { + return m_cli; + } + void Session::cli( clara::Parser const& newParser ) { + m_cli = newParser; + } + ConfigData& Session::configData() { + return m_configData; + } + Config& Session::config() { + if( !m_config ) + m_config = std::make_shared( m_configData ); + return *m_config; + } + + int Session::runInternal() { + if( m_startupExceptions ) + return 1; + + if( m_configData.showHelp || m_configData.libIdentify ) + return 0; + + try + { + config(); // Force config to be constructed + + seedRng( *m_config ); + + if( m_configData.filenamesAsTags ) + applyFilenamesAsTags( *m_config ); + + // Handle list request + if( Option listed = list( config() ) ) + return static_cast( *listed ); + + auto totals = runTests( m_config ); + // Note that on unices only the lower 8 bits are usually used, clamping + // the return value to 255 prevents false negative when some multiple + // of 256 tests has failed + return (std::min) (MaxExitCode, (std::max) (totals.error, static_cast(totals.assertions.failed))); + } + catch( std::exception& ex ) { + Catch::cerr() << ex.what() << std::endl; + return MaxExitCode; + } + } + +} // end namespace Catch +// end catch_session.cpp +// start catch_startup_exception_registry.cpp + +namespace Catch { + void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept { + try { + m_exceptions.push_back(exception); + } + catch(...) { + // If we run out of memory during start-up there's really not a lot more we can do about it + std::terminate(); + } + } + + std::vector const& StartupExceptionRegistry::getExceptions() const noexcept { + return m_exceptions; + } + +} // end namespace Catch +// end catch_startup_exception_registry.cpp +// start catch_stream.cpp + +#include +#include +#include +#include +#include +#include + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +namespace Catch { + + Catch::IStream::~IStream() = default; + + namespace detail { namespace { + template + class StreamBufImpl : public std::streambuf { + char data[bufferSize]; + WriterF m_writer; + + public: + StreamBufImpl() { + setp( data, data + sizeof(data) ); + } + + ~StreamBufImpl() noexcept { + StreamBufImpl::sync(); + } + + private: + int overflow( int c ) override { + sync(); + + if( c != EOF ) { + if( pbase() == epptr() ) + m_writer( std::string( 1, static_cast( c ) ) ); + else + sputc( static_cast( c ) ); + } + return 0; + } + + int sync() override { + if( pbase() != pptr() ) { + m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); + setp( pbase(), epptr() ); + } + return 0; + } + }; + + /////////////////////////////////////////////////////////////////////////// + + struct OutputDebugWriter { + + void operator()( std::string const&str ) { + writeToDebugConsole( str ); + } + }; + + /////////////////////////////////////////////////////////////////////////// + + class FileStream : public IStream { + mutable std::ofstream m_ofs; + public: + FileStream( StringRef filename ) { + m_ofs.open( filename.c_str() ); + CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" ); + } + ~FileStream() override = default; + public: // IStream + std::ostream& stream() const override { + return m_ofs; + } + }; + + /////////////////////////////////////////////////////////////////////////// + + class CoutStream : public IStream { + mutable std::ostream m_os; + public: + // Store the streambuf from cout up-front because + // cout may get redirected when running tests + CoutStream() : m_os( Catch::cout().rdbuf() ) {} + ~CoutStream() override = default; + + public: // IStream + std::ostream& stream() const override { return m_os; } + }; + + /////////////////////////////////////////////////////////////////////////// + + class DebugOutStream : public IStream { + std::unique_ptr> m_streamBuf; + mutable std::ostream m_os; + public: + DebugOutStream() + : m_streamBuf( new StreamBufImpl() ), + m_os( m_streamBuf.get() ) + {} + + ~DebugOutStream() override = default; + + public: // IStream + std::ostream& stream() const override { return m_os; } + }; + + }} // namespace anon::detail + + /////////////////////////////////////////////////////////////////////////// + + auto makeStream( StringRef const &filename ) -> IStream const* { + if( filename.empty() ) + return new detail::CoutStream(); + else if( filename[0] == '%' ) { + if( filename == "%debug" ) + return new detail::DebugOutStream(); + else + CATCH_ERROR( "Unrecognised stream: '" << filename << "'" ); + } + else + return new detail::FileStream( filename ); + } + + // This class encapsulates the idea of a pool of ostringstreams that can be reused. + struct StringStreams { + std::vector> m_streams; + std::vector m_unused; + std::ostringstream m_referenceStream; // Used for copy state/ flags from + static StringStreams* s_instance; + + auto add() -> std::size_t { + if( m_unused.empty() ) { + m_streams.push_back( std::unique_ptr( new std::ostringstream ) ); + return m_streams.size()-1; + } + else { + auto index = m_unused.back(); + m_unused.pop_back(); + return index; + } + } + + void release( std::size_t index ) { + m_streams[index]->copyfmt( m_referenceStream ); // Restore initial flags and other state + m_unused.push_back(index); + } + + // !TBD: put in TLS + static auto instance() -> StringStreams& { + if( !s_instance ) + s_instance = new StringStreams(); + return *s_instance; + } + static void cleanup() { + delete s_instance; + s_instance = nullptr; + } + }; + + StringStreams* StringStreams::s_instance = nullptr; + + void ReusableStringStream::cleanup() { + StringStreams::cleanup(); + } + + ReusableStringStream::ReusableStringStream() + : m_index( StringStreams::instance().add() ), + m_oss( StringStreams::instance().m_streams[m_index].get() ) + {} + + ReusableStringStream::~ReusableStringStream() { + static_cast( m_oss )->str(""); + m_oss->clear(); + StringStreams::instance().release( m_index ); + } + + auto ReusableStringStream::str() const -> std::string { + return static_cast( m_oss )->str(); + } + + /////////////////////////////////////////////////////////////////////////// + +#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions + std::ostream& cout() { return std::cout; } + std::ostream& cerr() { return std::cerr; } + std::ostream& clog() { return std::clog; } +#endif +} + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +// end catch_stream.cpp +// start catch_string_manip.cpp + +#include +#include +#include +#include + +namespace Catch { + + bool startsWith( std::string const& s, std::string const& prefix ) { + return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); + } + bool startsWith( std::string const& s, char prefix ) { + return !s.empty() && s[0] == prefix; + } + bool endsWith( std::string const& s, std::string const& suffix ) { + return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); + } + bool endsWith( std::string const& s, char suffix ) { + return !s.empty() && s[s.size()-1] == suffix; + } + bool contains( std::string const& s, std::string const& infix ) { + return s.find( infix ) != std::string::npos; + } + char toLowerCh(char c) { + return static_cast( std::tolower( c ) ); + } + void toLowerInPlace( std::string& s ) { + std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); + } + std::string toLower( std::string const& s ) { + std::string lc = s; + toLowerInPlace( lc ); + return lc; + } + std::string trim( std::string const& str ) { + static char const* whitespaceChars = "\n\r\t "; + std::string::size_type start = str.find_first_not_of( whitespaceChars ); + std::string::size_type end = str.find_last_not_of( whitespaceChars ); + + return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); + } + + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { + bool replaced = false; + std::size_t i = str.find( replaceThis ); + while( i != std::string::npos ) { + replaced = true; + str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); + if( i < str.size()-withThis.size() ) + i = str.find( replaceThis, i+withThis.size() ); + else + i = std::string::npos; + } + return replaced; + } + + pluralise::pluralise( std::size_t count, std::string const& label ) + : m_count( count ), + m_label( label ) + {} + + std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { + os << pluraliser.m_count << ' ' << pluraliser.m_label; + if( pluraliser.m_count != 1 ) + os << 's'; + return os; + } + +} +// end catch_string_manip.cpp +// start catch_stringref.cpp + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +#include +#include +#include + +namespace { + const uint32_t byte_2_lead = 0xC0; + const uint32_t byte_3_lead = 0xE0; + const uint32_t byte_4_lead = 0xF0; +} + +namespace Catch { + StringRef::StringRef( char const* rawChars ) noexcept + : StringRef( rawChars, static_cast(std::strlen(rawChars) ) ) + {} + + StringRef::operator std::string() const { + return std::string( m_start, m_size ); + } + + void StringRef::swap( StringRef& other ) noexcept { + std::swap( m_start, other.m_start ); + std::swap( m_size, other.m_size ); + std::swap( m_data, other.m_data ); + } + + auto StringRef::c_str() const -> char const* { + if( isSubstring() ) + const_cast( this )->takeOwnership(); + return m_start; + } + auto StringRef::currentData() const noexcept -> char const* { + return m_start; + } + + auto StringRef::isOwned() const noexcept -> bool { + return m_data != nullptr; + } + auto StringRef::isSubstring() const noexcept -> bool { + return m_start[m_size] != '\0'; + } + + void StringRef::takeOwnership() { + if( !isOwned() ) { + m_data = new char[m_size+1]; + memcpy( m_data, m_start, m_size ); + m_data[m_size] = '\0'; + m_start = m_data; + } + } + auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef { + if( start < m_size ) + return StringRef( m_start+start, size ); + else + return StringRef(); + } + auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool { + return + size() == other.size() && + (std::strncmp( m_start, other.m_start, size() ) == 0); + } + auto StringRef::operator != ( StringRef const& other ) const noexcept -> bool { + return !operator==( other ); + } + + auto StringRef::operator[](size_type index) const noexcept -> char { + return m_start[index]; + } + + auto StringRef::numberOfCharacters() const noexcept -> size_type { + size_type noChars = m_size; + // Make adjustments for uft encodings + for( size_type i=0; i < m_size; ++i ) { + char c = m_start[i]; + if( ( c & byte_2_lead ) == byte_2_lead ) { + noChars--; + if (( c & byte_3_lead ) == byte_3_lead ) + noChars--; + if( ( c & byte_4_lead ) == byte_4_lead ) + noChars--; + } + } + return noChars; + } + + auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string { + std::string str; + str.reserve( lhs.size() + rhs.size() ); + str += lhs; + str += rhs; + return str; + } + auto operator + ( StringRef const& lhs, const char* rhs ) -> std::string { + return std::string( lhs ) + std::string( rhs ); + } + auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string { + return std::string( lhs ) + std::string( rhs ); + } + + auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& { + return os.write(str.currentData(), str.size()); + } + + auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& { + lhs.append(rhs.currentData(), rhs.size()); + return lhs; + } + +} // namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +// end catch_stringref.cpp +// start catch_tag_alias.cpp + +namespace Catch { + TagAlias::TagAlias(std::string const & _tag, SourceLineInfo _lineInfo): tag(_tag), lineInfo(_lineInfo) {} +} +// end catch_tag_alias.cpp +// start catch_tag_alias_autoregistrar.cpp + +namespace Catch { + + RegistrarForTagAliases::RegistrarForTagAliases(char const* alias, char const* tag, SourceLineInfo const& lineInfo) { + try { + getMutableRegistryHub().registerTagAlias(alias, tag, lineInfo); + } catch (...) { + // Do not throw when constructing global objects, instead register the exception to be processed later + getMutableRegistryHub().registerStartupException(); + } + } + +} +// end catch_tag_alias_autoregistrar.cpp +// start catch_tag_alias_registry.cpp + +#include + +namespace Catch { + + TagAliasRegistry::~TagAliasRegistry() {} + + TagAlias const* TagAliasRegistry::find( std::string const& alias ) const { + auto it = m_registry.find( alias ); + if( it != m_registry.end() ) + return &(it->second); + else + return nullptr; + } + + std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { + std::string expandedTestSpec = unexpandedTestSpec; + for( auto const& registryKvp : m_registry ) { + std::size_t pos = expandedTestSpec.find( registryKvp.first ); + if( pos != std::string::npos ) { + expandedTestSpec = expandedTestSpec.substr( 0, pos ) + + registryKvp.second.tag + + expandedTestSpec.substr( pos + registryKvp.first.size() ); + } + } + return expandedTestSpec; + } + + void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) { + CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'), + "error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo ); + + CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second, + "error: tag alias, '" << alias << "' already registered.\n" + << "\tFirst seen at: " << find(alias)->lineInfo << "\n" + << "\tRedefined at: " << lineInfo ); + } + + ITagAliasRegistry::~ITagAliasRegistry() {} + + ITagAliasRegistry const& ITagAliasRegistry::get() { + return getRegistryHub().getTagAliasRegistry(); + } + +} // end namespace Catch +// end catch_tag_alias_registry.cpp +// start catch_test_case_info.cpp + +#include +#include +#include +#include + +namespace Catch { + + TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { + if( startsWith( tag, '.' ) || + tag == "!hide" ) + return TestCaseInfo::IsHidden; + else if( tag == "!throws" ) + return TestCaseInfo::Throws; + else if( tag == "!shouldfail" ) + return TestCaseInfo::ShouldFail; + else if( tag == "!mayfail" ) + return TestCaseInfo::MayFail; + else if( tag == "!nonportable" ) + return TestCaseInfo::NonPortable; + else if( tag == "!benchmark" ) + return static_cast( TestCaseInfo::Benchmark | TestCaseInfo::IsHidden ); + else + return TestCaseInfo::None; + } + bool isReservedTag( std::string const& tag ) { + return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] ); + } + void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { + CATCH_ENFORCE( !isReservedTag(tag), + "Tag name: [" << tag << "] is not allowed.\n" + << "Tag names starting with non alpha-numeric characters are reserved\n" + << _lineInfo ); + } + + TestCase makeTestCase( ITestInvoker* _testCase, + std::string const& _className, + NameAndTags const& nameAndTags, + SourceLineInfo const& _lineInfo ) + { + bool isHidden = false; + + // Parse out tags + std::vector tags; + std::string desc, tag; + bool inTag = false; + std::string _descOrTags = nameAndTags.tags; + for (char c : _descOrTags) { + if( !inTag ) { + if( c == '[' ) + inTag = true; + else + desc += c; + } + else { + if( c == ']' ) { + TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag ); + if( ( prop & TestCaseInfo::IsHidden ) != 0 ) + isHidden = true; + else if( prop == TestCaseInfo::None ) + enforceNotReservedTag( tag, _lineInfo ); + + tags.push_back( tag ); + tag.clear(); + inTag = false; + } + else + tag += c; + } + } + if( isHidden ) { + tags.push_back( "." ); + } + + TestCaseInfo info( nameAndTags.name, _className, desc, tags, _lineInfo ); + return TestCase( _testCase, std::move(info) ); + } + + void setTags( TestCaseInfo& testCaseInfo, std::vector tags ) { + std::sort(begin(tags), end(tags)); + tags.erase(std::unique(begin(tags), end(tags)), end(tags)); + testCaseInfo.lcaseTags.clear(); + + for( auto const& tag : tags ) { + std::string lcaseTag = toLower( tag ); + testCaseInfo.properties = static_cast( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); + testCaseInfo.lcaseTags.push_back( lcaseTag ); + } + testCaseInfo.tags = std::move(tags); + } + + TestCaseInfo::TestCaseInfo( std::string const& _name, + std::string const& _className, + std::string const& _description, + std::vector const& _tags, + SourceLineInfo const& _lineInfo ) + : name( _name ), + className( _className ), + description( _description ), + lineInfo( _lineInfo ), + properties( None ) + { + setTags( *this, _tags ); + } + + bool TestCaseInfo::isHidden() const { + return ( properties & IsHidden ) != 0; + } + bool TestCaseInfo::throws() const { + return ( properties & Throws ) != 0; + } + bool TestCaseInfo::okToFail() const { + return ( properties & (ShouldFail | MayFail ) ) != 0; + } + bool TestCaseInfo::expectedToFail() const { + return ( properties & (ShouldFail ) ) != 0; + } + + std::string TestCaseInfo::tagsAsString() const { + std::string ret; + // '[' and ']' per tag + std::size_t full_size = 2 * tags.size(); + for (const auto& tag : tags) { + full_size += tag.size(); + } + ret.reserve(full_size); + for (const auto& tag : tags) { + ret.push_back('['); + ret.append(tag); + ret.push_back(']'); + } + + return ret; + } + + TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {} + + TestCase TestCase::withName( std::string const& _newName ) const { + TestCase other( *this ); + other.name = _newName; + return other; + } + + void TestCase::invoke() const { + test->invoke(); + } + + bool TestCase::operator == ( TestCase const& other ) const { + return test.get() == other.test.get() && + name == other.name && + className == other.className; + } + + bool TestCase::operator < ( TestCase const& other ) const { + return name < other.name; + } + + TestCaseInfo const& TestCase::getTestCaseInfo() const + { + return *this; + } + +} // end namespace Catch +// end catch_test_case_info.cpp +// start catch_test_case_registry_impl.cpp + +#include + +namespace Catch { + + std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ) { + + std::vector sorted = unsortedTestCases; + + switch( config.runOrder() ) { + case RunTests::InLexicographicalOrder: + std::sort( sorted.begin(), sorted.end() ); + break; + case RunTests::InRandomOrder: + seedRng( config ); + RandomNumberGenerator::shuffle( sorted ); + break; + case RunTests::InDeclarationOrder: + // already in declaration order + break; + } + return sorted; + } + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) { + return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() ); + } + + void enforceNoDuplicateTestCases( std::vector const& functions ) { + std::set seenFunctions; + for( auto const& function : functions ) { + auto prev = seenFunctions.insert( function ); + CATCH_ENFORCE( prev.second, + "error: TEST_CASE( \"" << function.name << "\" ) already defined.\n" + << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" + << "\tRedefined at " << function.getTestCaseInfo().lineInfo ); + } + } + + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ) { + std::vector filtered; + filtered.reserve( testCases.size() ); + for( auto const& testCase : testCases ) + if( matchTest( testCase, testSpec, config ) ) + filtered.push_back( testCase ); + return filtered; + } + std::vector const& getAllTestCasesSorted( IConfig const& config ) { + return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config ); + } + + void TestRegistry::registerTest( TestCase const& testCase ) { + std::string name = testCase.getTestCaseInfo().name; + if( name.empty() ) { + ReusableStringStream rss; + rss << "Anonymous test case " << ++m_unnamedCount; + return registerTest( testCase.withName( rss.str() ) ); + } + m_functions.push_back( testCase ); + } + + std::vector const& TestRegistry::getAllTests() const { + return m_functions; + } + std::vector const& TestRegistry::getAllTestsSorted( IConfig const& config ) const { + if( m_sortedFunctions.empty() ) + enforceNoDuplicateTestCases( m_functions ); + + if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) { + m_sortedFunctions = sortTests( config, m_functions ); + m_currentSortOrder = config.runOrder(); + } + return m_sortedFunctions; + } + + /////////////////////////////////////////////////////////////////////////// + TestInvokerAsFunction::TestInvokerAsFunction( void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {} + + void TestInvokerAsFunction::invoke() const { + m_testAsFunction(); + } + + std::string extractClassName( StringRef const& classOrQualifiedMethodName ) { + std::string className = classOrQualifiedMethodName; + if( startsWith( className, '&' ) ) + { + std::size_t lastColons = className.rfind( "::" ); + std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); + if( penultimateColons == std::string::npos ) + penultimateColons = 1; + className = className.substr( penultimateColons, lastColons-penultimateColons ); + } + return className; + } + +} // end namespace Catch +// end catch_test_case_registry_impl.cpp +// start catch_test_case_tracker.cpp + +#include +#include +#include +#include +#include + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +namespace Catch { +namespace TestCaseTracking { + + NameAndLocation::NameAndLocation( std::string const& _name, SourceLineInfo const& _location ) + : name( _name ), + location( _location ) + {} + + ITracker::~ITracker() = default; + + TrackerContext& TrackerContext::instance() { + static TrackerContext s_instance; + return s_instance; + } + + ITracker& TrackerContext::startRun() { + m_rootTracker = std::make_shared( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr ); + m_currentTracker = nullptr; + m_runState = Executing; + return *m_rootTracker; + } + + void TrackerContext::endRun() { + m_rootTracker.reset(); + m_currentTracker = nullptr; + m_runState = NotStarted; + } + + void TrackerContext::startCycle() { + m_currentTracker = m_rootTracker.get(); + m_runState = Executing; + } + void TrackerContext::completeCycle() { + m_runState = CompletedCycle; + } + + bool TrackerContext::completedCycle() const { + return m_runState == CompletedCycle; + } + ITracker& TrackerContext::currentTracker() { + return *m_currentTracker; + } + void TrackerContext::setCurrentTracker( ITracker* tracker ) { + m_currentTracker = tracker; + } + + TrackerBase::TrackerHasName::TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {} + bool TrackerBase::TrackerHasName::operator ()( ITrackerPtr const& tracker ) const { + return + tracker->nameAndLocation().name == m_nameAndLocation.name && + tracker->nameAndLocation().location == m_nameAndLocation.location; + } + + TrackerBase::TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : m_nameAndLocation( nameAndLocation ), + m_ctx( ctx ), + m_parent( parent ) + {} + + NameAndLocation const& TrackerBase::nameAndLocation() const { + return m_nameAndLocation; + } + bool TrackerBase::isComplete() const { + return m_runState == CompletedSuccessfully || m_runState == Failed; + } + bool TrackerBase::isSuccessfullyCompleted() const { + return m_runState == CompletedSuccessfully; + } + bool TrackerBase::isOpen() const { + return m_runState != NotStarted && !isComplete(); + } + bool TrackerBase::hasChildren() const { + return !m_children.empty(); + } + + void TrackerBase::addChild( ITrackerPtr const& child ) { + m_children.push_back( child ); + } + + ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) { + auto it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) ); + return( it != m_children.end() ) + ? *it + : nullptr; + } + ITracker& TrackerBase::parent() { + assert( m_parent ); // Should always be non-null except for root + return *m_parent; + } + + void TrackerBase::openChild() { + if( m_runState != ExecutingChildren ) { + m_runState = ExecutingChildren; + if( m_parent ) + m_parent->openChild(); + } + } + + bool TrackerBase::isSectionTracker() const { return false; } + bool TrackerBase::isIndexTracker() const { return false; } + + void TrackerBase::open() { + m_runState = Executing; + moveToThis(); + if( m_parent ) + m_parent->openChild(); + } + + void TrackerBase::close() { + + // Close any still open children (e.g. generators) + while( &m_ctx.currentTracker() != this ) + m_ctx.currentTracker().close(); + + switch( m_runState ) { + case NeedsAnotherRun: + break; + + case Executing: + m_runState = CompletedSuccessfully; + break; + case ExecutingChildren: + if( m_children.empty() || m_children.back()->isComplete() ) + m_runState = CompletedSuccessfully; + break; + + case NotStarted: + case CompletedSuccessfully: + case Failed: + CATCH_INTERNAL_ERROR( "Illogical state: " << m_runState ); + + default: + CATCH_INTERNAL_ERROR( "Unknown state: " << m_runState ); + } + moveToParent(); + m_ctx.completeCycle(); + } + void TrackerBase::fail() { + m_runState = Failed; + if( m_parent ) + m_parent->markAsNeedingAnotherRun(); + moveToParent(); + m_ctx.completeCycle(); + } + void TrackerBase::markAsNeedingAnotherRun() { + m_runState = NeedsAnotherRun; + } + + void TrackerBase::moveToParent() { + assert( m_parent ); + m_ctx.setCurrentTracker( m_parent ); + } + void TrackerBase::moveToThis() { + m_ctx.setCurrentTracker( this ); + } + + SectionTracker::SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : TrackerBase( nameAndLocation, ctx, parent ) + { + if( parent ) { + while( !parent->isSectionTracker() ) + parent = &parent->parent(); + + SectionTracker& parentSection = static_cast( *parent ); + addNextFilters( parentSection.m_filters ); + } + } + + bool SectionTracker::isSectionTracker() const { return true; } + + SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) { + std::shared_ptr section; + + ITracker& currentTracker = ctx.currentTracker(); + if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { + assert( childTracker ); + assert( childTracker->isSectionTracker() ); + section = std::static_pointer_cast( childTracker ); + } + else { + section = std::make_shared( nameAndLocation, ctx, ¤tTracker ); + currentTracker.addChild( section ); + } + if( !ctx.completedCycle() ) + section->tryOpen(); + return *section; + } + + void SectionTracker::tryOpen() { + if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) ) + open(); + } + + void SectionTracker::addInitialFilters( std::vector const& filters ) { + if( !filters.empty() ) { + m_filters.push_back(""); // Root - should never be consulted + m_filters.push_back(""); // Test Case - not a section filter + m_filters.insert( m_filters.end(), filters.begin(), filters.end() ); + } + } + void SectionTracker::addNextFilters( std::vector const& filters ) { + if( filters.size() > 1 ) + m_filters.insert( m_filters.end(), ++filters.begin(), filters.end() ); + } + + IndexTracker::IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ) + : TrackerBase( nameAndLocation, ctx, parent ), + m_size( size ) + {} + + bool IndexTracker::isIndexTracker() const { return true; } + + IndexTracker& IndexTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ) { + std::shared_ptr tracker; + + ITracker& currentTracker = ctx.currentTracker(); + if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { + assert( childTracker ); + assert( childTracker->isIndexTracker() ); + tracker = std::static_pointer_cast( childTracker ); + } + else { + tracker = std::make_shared( nameAndLocation, ctx, ¤tTracker, size ); + currentTracker.addChild( tracker ); + } + + if( !ctx.completedCycle() && !tracker->isComplete() ) { + if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun ) + tracker->moveNext(); + tracker->open(); + } + + return *tracker; + } + + int IndexTracker::index() const { return m_index; } + + void IndexTracker::moveNext() { + m_index++; + m_children.clear(); + } + + void IndexTracker::close() { + TrackerBase::close(); + if( m_runState == CompletedSuccessfully && m_index < m_size-1 ) + m_runState = Executing; + } + +} // namespace TestCaseTracking + +using TestCaseTracking::ITracker; +using TestCaseTracking::TrackerContext; +using TestCaseTracking::SectionTracker; +using TestCaseTracking::IndexTracker; + +} // namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +// end catch_test_case_tracker.cpp +// start catch_test_registry.cpp + +namespace Catch { + + auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker* { + return new(std::nothrow) TestInvokerAsFunction( testAsFunction ); + } + + NameAndTags::NameAndTags( StringRef const& name_ , StringRef const& tags_ ) noexcept : name( name_ ), tags( tags_ ) {} + + AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept { + try { + getMutableRegistryHub() + .registerTest( + makeTestCase( + invoker, + extractClassName( classOrMethod ), + nameAndTags, + lineInfo)); + } catch (...) { + // Do not throw when constructing global objects, instead register the exception to be processed later + getMutableRegistryHub().registerStartupException(); + } + } + + AutoReg::~AutoReg() = default; +} +// end catch_test_registry.cpp +// start catch_test_spec.cpp + +#include +#include +#include +#include + +namespace Catch { + + TestSpec::Pattern::~Pattern() = default; + TestSpec::NamePattern::~NamePattern() = default; + TestSpec::TagPattern::~TagPattern() = default; + TestSpec::ExcludedPattern::~ExcludedPattern() = default; + + TestSpec::NamePattern::NamePattern( std::string const& name ) + : m_wildcardPattern( toLower( name ), CaseSensitive::No ) + {} + bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const { + return m_wildcardPattern.matches( toLower( testCase.name ) ); + } + + TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} + bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const { + return std::find(begin(testCase.lcaseTags), + end(testCase.lcaseTags), + m_tag) != end(testCase.lcaseTags); + } + + TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} + bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } + + bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const { + // All patterns in a filter must match for the filter to be a match + for( auto const& pattern : m_patterns ) { + if( !pattern->matches( testCase ) ) + return false; + } + return true; + } + + bool TestSpec::hasFilters() const { + return !m_filters.empty(); + } + bool TestSpec::matches( TestCaseInfo const& testCase ) const { + // A TestSpec matches if any filter matches + for( auto const& filter : m_filters ) + if( filter.matches( testCase ) ) + return true; + return false; + } +} +// end catch_test_spec.cpp +// start catch_test_spec_parser.cpp + +namespace Catch { + + TestSpecParser::TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} + + TestSpecParser& TestSpecParser::parse( std::string const& arg ) { + m_mode = None; + m_exclusion = false; + m_start = std::string::npos; + m_arg = m_tagAliases->expandAliases( arg ); + m_escapeChars.clear(); + for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) + visitChar( m_arg[m_pos] ); + if( m_mode == Name ) + addPattern(); + return *this; + } + TestSpec TestSpecParser::testSpec() { + addFilter(); + return m_testSpec; + } + + void TestSpecParser::visitChar( char c ) { + if( m_mode == None ) { + switch( c ) { + case ' ': return; + case '~': m_exclusion = true; return; + case '[': return startNewMode( Tag, ++m_pos ); + case '"': return startNewMode( QuotedName, ++m_pos ); + case '\\': return escape(); + default: startNewMode( Name, m_pos ); break; + } + } + if( m_mode == Name ) { + if( c == ',' ) { + addPattern(); + addFilter(); + } + else if( c == '[' ) { + if( subString() == "exclude:" ) + m_exclusion = true; + else + addPattern(); + startNewMode( Tag, ++m_pos ); + } + else if( c == '\\' ) + escape(); + } + else if( m_mode == EscapedName ) + m_mode = Name; + else if( m_mode == QuotedName && c == '"' ) + addPattern(); + else if( m_mode == Tag && c == ']' ) + addPattern(); + } + void TestSpecParser::startNewMode( Mode mode, std::size_t start ) { + m_mode = mode; + m_start = start; + } + void TestSpecParser::escape() { + if( m_mode == None ) + m_start = m_pos; + m_mode = EscapedName; + m_escapeChars.push_back( m_pos ); + } + std::string TestSpecParser::subString() const { return m_arg.substr( m_start, m_pos - m_start ); } + + void TestSpecParser::addFilter() { + if( !m_currentFilter.m_patterns.empty() ) { + m_testSpec.m_filters.push_back( m_currentFilter ); + m_currentFilter = TestSpec::Filter(); + } + } + + TestSpec parseTestSpec( std::string const& arg ) { + return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); + } + +} // namespace Catch +// end catch_test_spec_parser.cpp +// start catch_timer.cpp + +#include + +static const uint64_t nanosecondsInSecond = 1000000000; + +namespace Catch { + + auto getCurrentNanosecondsSinceEpoch() -> uint64_t { + return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); + } + + auto estimateClockResolution() -> uint64_t { + uint64_t sum = 0; + static const uint64_t iterations = 1000000; + + auto startTime = getCurrentNanosecondsSinceEpoch(); + + for( std::size_t i = 0; i < iterations; ++i ) { + + uint64_t ticks; + uint64_t baseTicks = getCurrentNanosecondsSinceEpoch(); + do { + ticks = getCurrentNanosecondsSinceEpoch(); + } while( ticks == baseTicks ); + + auto delta = ticks - baseTicks; + sum += delta; + + // If we have been calibrating for over 3 seconds -- the clock + // is terrible and we should move on. + // TBD: How to signal that the measured resolution is probably wrong? + if (ticks > startTime + 3 * nanosecondsInSecond) { + return sum / i; + } + } + + // We're just taking the mean, here. To do better we could take the std. dev and exclude outliers + // - and potentially do more iterations if there's a high variance. + return sum/iterations; + } + auto getEstimatedClockResolution() -> uint64_t { + static auto s_resolution = estimateClockResolution(); + return s_resolution; + } + + void Timer::start() { + m_nanoseconds = getCurrentNanosecondsSinceEpoch(); + } + auto Timer::getElapsedNanoseconds() const -> uint64_t { + return getCurrentNanosecondsSinceEpoch() - m_nanoseconds; + } + auto Timer::getElapsedMicroseconds() const -> uint64_t { + return getElapsedNanoseconds()/1000; + } + auto Timer::getElapsedMilliseconds() const -> unsigned int { + return static_cast(getElapsedMicroseconds()/1000); + } + auto Timer::getElapsedSeconds() const -> double { + return getElapsedMicroseconds()/1000000.0; + } + +} // namespace Catch +// end catch_timer.cpp +// start catch_tostring.cpp + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +# pragma clang diagnostic ignored "-Wglobal-constructors" +#endif + +// Enable specific decls locally +#if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +#endif + +#include +#include + +namespace Catch { + +namespace Detail { + + const std::string unprintableString = "{?}"; + + namespace { + const int hexThreshold = 255; + + struct Endianness { + enum Arch { Big, Little }; + + static Arch which() { + union _{ + int asInt; + char asChar[sizeof (int)]; + } u; + + u.asInt = 1; + return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little; + } + }; + } + + std::string rawMemoryToString( const void *object, std::size_t size ) { + // Reverse order for little endian architectures + int i = 0, end = static_cast( size ), inc = 1; + if( Endianness::which() == Endianness::Little ) { + i = end-1; + end = inc = -1; + } + + unsigned char const *bytes = static_cast(object); + ReusableStringStream rss; + rss << "0x" << std::setfill('0') << std::hex; + for( ; i != end; i += inc ) + rss << std::setw(2) << static_cast(bytes[i]); + return rss.str(); + } +} + +template +std::string fpToString( T value, int precision ) { + if (std::isnan(value)) { + return "nan"; + } + + ReusableStringStream rss; + rss << std::setprecision( precision ) + << std::fixed + << value; + std::string d = rss.str(); + std::size_t i = d.find_last_not_of( '0' ); + if( i != std::string::npos && i != d.size()-1 ) { + if( d[i] == '.' ) + i++; + d = d.substr( 0, i+1 ); + } + return d; +} + +//// ======================================================= //// +// +// Out-of-line defs for full specialization of StringMaker +// +//// ======================================================= //// + +std::string StringMaker::convert(const std::string& str) { + if (!getCurrentContext().getConfig()->showInvisibles()) { + return '"' + str + '"'; + } + + std::string s("\""); + for (char c : str) { + switch (c) { + case '\n': + s.append("\\n"); + break; + case '\t': + s.append("\\t"); + break; + default: + s.push_back(c); + break; + } + } + s.append("\""); + return s; +} + +#ifdef CATCH_CONFIG_WCHAR +std::string StringMaker::convert(const std::wstring& wstr) { + std::string s; + s.reserve(wstr.size()); + for (auto c : wstr) { + s += (c <= 0xff) ? static_cast(c) : '?'; + } + return ::Catch::Detail::stringify(s); +} +#endif + +std::string StringMaker::convert(char const* str) { + if (str) { + return ::Catch::Detail::stringify(std::string{ str }); + } else { + return{ "{null string}" }; + } +} +std::string StringMaker::convert(char* str) { + if (str) { + return ::Catch::Detail::stringify(std::string{ str }); + } else { + return{ "{null string}" }; + } +} +#ifdef CATCH_CONFIG_WCHAR +std::string StringMaker::convert(wchar_t const * str) { + if (str) { + return ::Catch::Detail::stringify(std::wstring{ str }); + } else { + return{ "{null string}" }; + } +} +std::string StringMaker::convert(wchar_t * str) { + if (str) { + return ::Catch::Detail::stringify(std::wstring{ str }); + } else { + return{ "{null string}" }; + } +} +#endif + +std::string StringMaker::convert(int value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(long value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(long long value) { + ReusableStringStream rss; + rss << value; + if (value > Detail::hexThreshold) { + rss << " (0x" << std::hex << value << ')'; + } + return rss.str(); +} + +std::string StringMaker::convert(unsigned int value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(unsigned long value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(unsigned long long value) { + ReusableStringStream rss; + rss << value; + if (value > Detail::hexThreshold) { + rss << " (0x" << std::hex << value << ')'; + } + return rss.str(); +} + +std::string StringMaker::convert(bool b) { + return b ? "true" : "false"; +} + +std::string StringMaker::convert(char value) { + if (value == '\r') { + return "'\\r'"; + } else if (value == '\f') { + return "'\\f'"; + } else if (value == '\n') { + return "'\\n'"; + } else if (value == '\t') { + return "'\\t'"; + } else if ('\0' <= value && value < ' ') { + return ::Catch::Detail::stringify(static_cast(value)); + } else { + char chstr[] = "' '"; + chstr[1] = value; + return chstr; + } +} +std::string StringMaker::convert(signed char c) { + return ::Catch::Detail::stringify(static_cast(c)); +} +std::string StringMaker::convert(unsigned char c) { + return ::Catch::Detail::stringify(static_cast(c)); +} + +std::string StringMaker::convert(std::nullptr_t) { + return "nullptr"; +} + +std::string StringMaker::convert(float value) { + return fpToString(value, 5) + 'f'; +} +std::string StringMaker::convert(double value) { + return fpToString(value, 10); +} + +std::string ratio_string::symbol() { return "a"; } +std::string ratio_string::symbol() { return "f"; } +std::string ratio_string::symbol() { return "p"; } +std::string ratio_string::symbol() { return "n"; } +std::string ratio_string::symbol() { return "u"; } +std::string ratio_string::symbol() { return "m"; } + +} // end namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + +// end catch_tostring.cpp +// start catch_totals.cpp + +namespace Catch { + + Counts Counts::operator - ( Counts const& other ) const { + Counts diff; + diff.passed = passed - other.passed; + diff.failed = failed - other.failed; + diff.failedButOk = failedButOk - other.failedButOk; + return diff; + } + + Counts& Counts::operator += ( Counts const& other ) { + passed += other.passed; + failed += other.failed; + failedButOk += other.failedButOk; + return *this; + } + + std::size_t Counts::total() const { + return passed + failed + failedButOk; + } + bool Counts::allPassed() const { + return failed == 0 && failedButOk == 0; + } + bool Counts::allOk() const { + return failed == 0; + } + + Totals Totals::operator - ( Totals const& other ) const { + Totals diff; + diff.assertions = assertions - other.assertions; + diff.testCases = testCases - other.testCases; + return diff; + } + + Totals& Totals::operator += ( Totals const& other ) { + assertions += other.assertions; + testCases += other.testCases; + return *this; + } + + Totals Totals::delta( Totals const& prevTotals ) const { + Totals diff = *this - prevTotals; + if( diff.assertions.failed > 0 ) + ++diff.testCases.failed; + else if( diff.assertions.failedButOk > 0 ) + ++diff.testCases.failedButOk; + else + ++diff.testCases.passed; + return diff; + } + +} +// end catch_totals.cpp +// start catch_uncaught_exceptions.cpp + +#include + +namespace Catch { + bool uncaught_exceptions() { +#if defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) + return std::uncaught_exceptions() > 0; +#else + return std::uncaught_exception(); +#endif + } +} // end namespace Catch +// end catch_uncaught_exceptions.cpp +// start catch_version.cpp + +#include + +namespace Catch { + + Version::Version + ( unsigned int _majorVersion, + unsigned int _minorVersion, + unsigned int _patchNumber, + char const * const _branchName, + unsigned int _buildNumber ) + : majorVersion( _majorVersion ), + minorVersion( _minorVersion ), + patchNumber( _patchNumber ), + branchName( _branchName ), + buildNumber( _buildNumber ) + {} + + std::ostream& operator << ( std::ostream& os, Version const& version ) { + os << version.majorVersion << '.' + << version.minorVersion << '.' + << version.patchNumber; + // branchName is never null -> 0th char is \0 if it is empty + if (version.branchName[0]) { + os << '-' << version.branchName + << '.' << version.buildNumber; + } + return os; + } + + Version const& libraryVersion() { + static Version version( 2, 2, 2, "", 0 ); + return version; + } + +} +// end catch_version.cpp +// start catch_wildcard_pattern.cpp + +#include + +namespace Catch { + + WildcardPattern::WildcardPattern( std::string const& pattern, + CaseSensitive::Choice caseSensitivity ) + : m_caseSensitivity( caseSensitivity ), + m_pattern( adjustCase( pattern ) ) + { + if( startsWith( m_pattern, '*' ) ) { + m_pattern = m_pattern.substr( 1 ); + m_wildcard = WildcardAtStart; + } + if( endsWith( m_pattern, '*' ) ) { + m_pattern = m_pattern.substr( 0, m_pattern.size()-1 ); + m_wildcard = static_cast( m_wildcard | WildcardAtEnd ); + } + } + + bool WildcardPattern::matches( std::string const& str ) const { + switch( m_wildcard ) { + case NoWildcard: + return m_pattern == adjustCase( str ); + case WildcardAtStart: + return endsWith( adjustCase( str ), m_pattern ); + case WildcardAtEnd: + return startsWith( adjustCase( str ), m_pattern ); + case WildcardAtBothEnds: + return contains( adjustCase( str ), m_pattern ); + default: + CATCH_INTERNAL_ERROR( "Unknown enum" ); + } + } + + std::string WildcardPattern::adjustCase( std::string const& str ) const { + return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str; + } +} +// end catch_wildcard_pattern.cpp +// start catch_xmlwriter.cpp + +#include + +using uchar = unsigned char; + +namespace Catch { + +namespace { + + size_t trailingBytes(unsigned char c) { + if ((c & 0xE0) == 0xC0) { + return 2; + } + if ((c & 0xF0) == 0xE0) { + return 3; + } + if ((c & 0xF8) == 0xF0) { + return 4; + } + CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered"); + } + + uint32_t headerValue(unsigned char c) { + if ((c & 0xE0) == 0xC0) { + return c & 0x1F; + } + if ((c & 0xF0) == 0xE0) { + return c & 0x0F; + } + if ((c & 0xF8) == 0xF0) { + return c & 0x07; + } + CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered"); + } + + void hexEscapeChar(std::ostream& os, unsigned char c) { + os << "\\x" + << std::uppercase << std::hex << std::setfill('0') << std::setw(2) + << static_cast(c); + } + +} // anonymous namespace + + XmlEncode::XmlEncode( std::string const& str, ForWhat forWhat ) + : m_str( str ), + m_forWhat( forWhat ) + {} + + void XmlEncode::encodeTo( std::ostream& os ) const { + // Apostrophe escaping not necessary if we always use " to write attributes + // (see: http://www.w3.org/TR/xml/#syntax) + + for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) { + uchar c = m_str[idx]; + switch (c) { + case '<': os << "<"; break; + case '&': os << "&"; break; + + case '>': + // See: http://www.w3.org/TR/xml/#syntax + if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']') + os << ">"; + else + os << c; + break; + + case '\"': + if (m_forWhat == ForAttributes) + os << """; + else + os << c; + break; + + default: + // Check for control characters and invalid utf-8 + + // Escape control characters in standard ascii + // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 + if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) { + hexEscapeChar(os, c); + break; + } + + // Plain ASCII: Write it to stream + if (c < 0x7F) { + os << c; + break; + } + + // UTF-8 territory + // Check if the encoding is valid and if it is not, hex escape bytes. + // Important: We do not check the exact decoded values for validity, only the encoding format + // First check that this bytes is a valid lead byte: + // This means that it is not encoded as 1111 1XXX + // Or as 10XX XXXX + if (c < 0xC0 || + c >= 0xF8) { + hexEscapeChar(os, c); + break; + } + + auto encBytes = trailingBytes(c); + // Are there enough bytes left to avoid accessing out-of-bounds memory? + if (idx + encBytes - 1 >= m_str.size()) { + hexEscapeChar(os, c); + break; + } + // The header is valid, check data + // The next encBytes bytes must together be a valid utf-8 + // This means: bitpattern 10XX XXXX and the extracted value is sane (ish) + bool valid = true; + uint32_t value = headerValue(c); + for (std::size_t n = 1; n < encBytes; ++n) { + uchar nc = m_str[idx + n]; + valid &= ((nc & 0xC0) == 0x80); + value = (value << 6) | (nc & 0x3F); + } + + if ( + // Wrong bit pattern of following bytes + (!valid) || + // Overlong encodings + (value < 0x80) || + (0x80 <= value && value < 0x800 && encBytes > 2) || + (0x800 < value && value < 0x10000 && encBytes > 3) || + // Encoded value out of range + (value >= 0x110000) + ) { + hexEscapeChar(os, c); + break; + } + + // If we got here, this is in fact a valid(ish) utf-8 sequence + for (std::size_t n = 0; n < encBytes; ++n) { + os << m_str[idx + n]; + } + idx += encBytes - 1; + break; + } + } + } + + std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { + xmlEncode.encodeTo( os ); + return os; + } + + XmlWriter::ScopedElement::ScopedElement( XmlWriter* writer ) + : m_writer( writer ) + {} + + XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept + : m_writer( other.m_writer ){ + other.m_writer = nullptr; + } + XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept { + if ( m_writer ) { + m_writer->endElement(); + } + m_writer = other.m_writer; + other.m_writer = nullptr; + return *this; + } + + XmlWriter::ScopedElement::~ScopedElement() { + if( m_writer ) + m_writer->endElement(); + } + + XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string const& text, bool indent ) { + m_writer->writeText( text, indent ); + return *this; + } + + XmlWriter::XmlWriter( std::ostream& os ) : m_os( os ) + { + writeDeclaration(); + } + + XmlWriter::~XmlWriter() { + while( !m_tags.empty() ) + endElement(); + } + + XmlWriter& XmlWriter::startElement( std::string const& name ) { + ensureTagClosed(); + newlineIfNecessary(); + m_os << m_indent << '<' << name; + m_tags.push_back( name ); + m_indent += " "; + m_tagIsOpen = true; + return *this; + } + + XmlWriter::ScopedElement XmlWriter::scopedElement( std::string const& name ) { + ScopedElement scoped( this ); + startElement( name ); + return scoped; + } + + XmlWriter& XmlWriter::endElement() { + newlineIfNecessary(); + m_indent = m_indent.substr( 0, m_indent.size()-2 ); + if( m_tagIsOpen ) { + m_os << "/>"; + m_tagIsOpen = false; + } + else { + m_os << m_indent << ""; + } + m_os << std::endl; + m_tags.pop_back(); + return *this; + } + + XmlWriter& XmlWriter::writeAttribute( std::string const& name, std::string const& attribute ) { + if( !name.empty() && !attribute.empty() ) + m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"'; + return *this; + } + + XmlWriter& XmlWriter::writeAttribute( std::string const& name, bool attribute ) { + m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"'; + return *this; + } + + XmlWriter& XmlWriter::writeText( std::string const& text, bool indent ) { + if( !text.empty() ){ + bool tagWasOpen = m_tagIsOpen; + ensureTagClosed(); + if( tagWasOpen && indent ) + m_os << m_indent; + m_os << XmlEncode( text ); + m_needsNewline = true; + } + return *this; + } + + XmlWriter& XmlWriter::writeComment( std::string const& text ) { + ensureTagClosed(); + m_os << m_indent << ""; + m_needsNewline = true; + return *this; + } + + void XmlWriter::writeStylesheetRef( std::string const& url ) { + m_os << "\n"; + } + + XmlWriter& XmlWriter::writeBlankLine() { + ensureTagClosed(); + m_os << '\n'; + return *this; + } + + void XmlWriter::ensureTagClosed() { + if( m_tagIsOpen ) { + m_os << ">" << std::endl; + m_tagIsOpen = false; + } + } + + void XmlWriter::writeDeclaration() { + m_os << "\n"; + } + + void XmlWriter::newlineIfNecessary() { + if( m_needsNewline ) { + m_os << std::endl; + m_needsNewline = false; + } + } +} +// end catch_xmlwriter.cpp +// start catch_reporter_bases.cpp + +#include +#include +#include +#include +#include + +namespace Catch { + void prepareExpandedExpression(AssertionResult& result) { + result.getExpandedExpression(); + } + + // Because formatting using c++ streams is stateful, drop down to C is required + // Alternatively we could use stringstream, but its performance is... not good. + std::string getFormattedDuration( double duration ) { + // Max exponent + 1 is required to represent the whole part + // + 1 for decimal point + // + 3 for the 3 decimal places + // + 1 for null terminator + const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; + char buffer[maxDoubleSize]; + + // Save previous errno, to prevent sprintf from overwriting it + ErrnoGuard guard; +#ifdef _MSC_VER + sprintf_s(buffer, "%.3f", duration); +#else + sprintf(buffer, "%.3f", duration); +#endif + return std::string(buffer); + } + + TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config) + :StreamingReporterBase(_config) {} + + void TestEventListenerBase::assertionStarting(AssertionInfo const &) {} + + bool TestEventListenerBase::assertionEnded(AssertionStats const &) { + return false; + } + +} // end namespace Catch +// end catch_reporter_bases.cpp +// start catch_reporter_compact.cpp + +namespace { + +#ifdef CATCH_PLATFORM_MAC + const char* failedString() { return "FAILED"; } + const char* passedString() { return "PASSED"; } +#else + const char* failedString() { return "failed"; } + const char* passedString() { return "passed"; } +#endif + + // Colour::LightGrey + Catch::Colour::Code dimColour() { return Catch::Colour::FileName; } + + std::string bothOrAll( std::size_t count ) { + return count == 1 ? std::string() : + count == 2 ? "both " : "all " ; + } + +} // anon namespace + +namespace Catch { +namespace { +// Colour, message variants: +// - white: No tests ran. +// - red: Failed [both/all] N test cases, failed [both/all] M assertions. +// - white: Passed [both/all] N test cases (no assertions). +// - red: Failed N tests cases, failed M assertions. +// - green: Passed [both/all] N tests cases with M assertions. +void printTotals(std::ostream& out, const Totals& totals) { + if (totals.testCases.total() == 0) { + out << "No tests ran."; + } else if (totals.testCases.failed == totals.testCases.total()) { + Colour colour(Colour::ResultError); + const std::string qualify_assertions_failed = + totals.assertions.failed == totals.assertions.total() ? + bothOrAll(totals.assertions.failed) : std::string(); + out << + "Failed " << bothOrAll(totals.testCases.failed) + << pluralise(totals.testCases.failed, "test case") << ", " + "failed " << qualify_assertions_failed << + pluralise(totals.assertions.failed, "assertion") << '.'; + } else if (totals.assertions.total() == 0) { + out << + "Passed " << bothOrAll(totals.testCases.total()) + << pluralise(totals.testCases.total(), "test case") + << " (no assertions)."; + } else if (totals.assertions.failed) { + Colour colour(Colour::ResultError); + out << + "Failed " << pluralise(totals.testCases.failed, "test case") << ", " + "failed " << pluralise(totals.assertions.failed, "assertion") << '.'; + } else { + Colour colour(Colour::ResultSuccess); + out << + "Passed " << bothOrAll(totals.testCases.passed) + << pluralise(totals.testCases.passed, "test case") << + " with " << pluralise(totals.assertions.passed, "assertion") << '.'; + } +} + +// Implementation of CompactReporter formatting +class AssertionPrinter { +public: + AssertionPrinter& operator= (AssertionPrinter const&) = delete; + AssertionPrinter(AssertionPrinter const&) = delete; + AssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) + : stream(_stream) + , result(_stats.assertionResult) + , messages(_stats.infoMessages) + , itMessage(_stats.infoMessages.begin()) + , printInfoMessages(_printInfoMessages) {} + + void print() { + printSourceInfo(); + + itMessage = messages.begin(); + + switch (result.getResultType()) { + case ResultWas::Ok: + printResultType(Colour::ResultSuccess, passedString()); + printOriginalExpression(); + printReconstructedExpression(); + if (!result.hasExpression()) + printRemainingMessages(Colour::None); + else + printRemainingMessages(); + break; + case ResultWas::ExpressionFailed: + if (result.isOk()) + printResultType(Colour::ResultSuccess, failedString() + std::string(" - but was ok")); + else + printResultType(Colour::Error, failedString()); + printOriginalExpression(); + printReconstructedExpression(); + printRemainingMessages(); + break; + case ResultWas::ThrewException: + printResultType(Colour::Error, failedString()); + printIssue("unexpected exception with message:"); + printMessage(); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::FatalErrorCondition: + printResultType(Colour::Error, failedString()); + printIssue("fatal error condition with message:"); + printMessage(); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::DidntThrowException: + printResultType(Colour::Error, failedString()); + printIssue("expected exception, got none"); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::Info: + printResultType(Colour::None, "info"); + printMessage(); + printRemainingMessages(); + break; + case ResultWas::Warning: + printResultType(Colour::None, "warning"); + printMessage(); + printRemainingMessages(); + break; + case ResultWas::ExplicitFailure: + printResultType(Colour::Error, failedString()); + printIssue("explicitly"); + printRemainingMessages(Colour::None); + break; + // These cases are here to prevent compiler warnings + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + printResultType(Colour::Error, "** internal error **"); + break; + } + } + +private: + void printSourceInfo() const { + Colour colourGuard(Colour::FileName); + stream << result.getSourceInfo() << ':'; + } + + void printResultType(Colour::Code colour, std::string const& passOrFail) const { + if (!passOrFail.empty()) { + { + Colour colourGuard(colour); + stream << ' ' << passOrFail; + } + stream << ':'; + } + } + + void printIssue(std::string const& issue) const { + stream << ' ' << issue; + } + + void printExpressionWas() { + if (result.hasExpression()) { + stream << ';'; + { + Colour colour(dimColour()); + stream << " expression was:"; + } + printOriginalExpression(); + } + } + + void printOriginalExpression() const { + if (result.hasExpression()) { + stream << ' ' << result.getExpression(); + } + } + + void printReconstructedExpression() const { + if (result.hasExpandedExpression()) { + { + Colour colour(dimColour()); + stream << " for: "; + } + stream << result.getExpandedExpression(); + } + } + + void printMessage() { + if (itMessage != messages.end()) { + stream << " '" << itMessage->message << '\''; + ++itMessage; + } + } + + void printRemainingMessages(Colour::Code colour = dimColour()) { + if (itMessage == messages.end()) + return; + + // using messages.end() directly yields (or auto) compilation error: + std::vector::const_iterator itEnd = messages.end(); + const std::size_t N = static_cast(std::distance(itMessage, itEnd)); + + { + Colour colourGuard(colour); + stream << " with " << pluralise(N, "message") << ':'; + } + + for (; itMessage != itEnd; ) { + // If this assertion is a warning ignore any INFO messages + if (printInfoMessages || itMessage->type != ResultWas::Info) { + stream << " '" << itMessage->message << '\''; + if (++itMessage != itEnd) { + Colour colourGuard(dimColour()); + stream << " and"; + } + } + } + } + +private: + std::ostream& stream; + AssertionResult const& result; + std::vector messages; + std::vector::const_iterator itMessage; + bool printInfoMessages; +}; + +} // anon namespace + + std::string CompactReporter::getDescription() { + return "Reports test results on a single line, suitable for IDEs"; + } + + ReporterPreferences CompactReporter::getPreferences() const { + ReporterPreferences prefs; + prefs.shouldRedirectStdOut = false; + return prefs; + } + + void CompactReporter::noMatchingTestCases( std::string const& spec ) { + stream << "No test cases matched '" << spec << '\'' << std::endl; + } + + void CompactReporter::assertionStarting( AssertionInfo const& ) {} + + bool CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) { + AssertionResult const& result = _assertionStats.assertionResult; + + bool printInfoMessages = true; + + // Drop out if result was successful and we're not printing those + if( !m_config->includeSuccessfulResults() && result.isOk() ) { + if( result.getResultType() != ResultWas::Warning ) + return false; + printInfoMessages = false; + } + + AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); + printer.print(); + + stream << std::endl; + return true; + } + + void CompactReporter::sectionEnded(SectionStats const& _sectionStats) { + if (m_config->showDurations() == ShowDurations::Always) { + stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; + } + } + + void CompactReporter::testRunEnded( TestRunStats const& _testRunStats ) { + printTotals( stream, _testRunStats.totals ); + stream << '\n' << std::endl; + StreamingReporterBase::testRunEnded( _testRunStats ); + } + + CompactReporter::~CompactReporter() {} + + CATCH_REGISTER_REPORTER( "compact", CompactReporter ) + +} // end namespace Catch +// end catch_reporter_compact.cpp +// start catch_reporter_console.cpp + +#include +#include + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch + // Note that 4062 (not all labels are handled + // and default is missing) is enabled +#endif + +namespace Catch { + +namespace { + +// Formatter impl for ConsoleReporter +class ConsoleAssertionPrinter { +public: + ConsoleAssertionPrinter& operator= (ConsoleAssertionPrinter const&) = delete; + ConsoleAssertionPrinter(ConsoleAssertionPrinter const&) = delete; + ConsoleAssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) + : stream(_stream), + stats(_stats), + result(_stats.assertionResult), + colour(Colour::None), + message(result.getMessage()), + messages(_stats.infoMessages), + printInfoMessages(_printInfoMessages) { + switch (result.getResultType()) { + case ResultWas::Ok: + colour = Colour::Success; + passOrFail = "PASSED"; + //if( result.hasMessage() ) + if (_stats.infoMessages.size() == 1) + messageLabel = "with message"; + if (_stats.infoMessages.size() > 1) + messageLabel = "with messages"; + break; + case ResultWas::ExpressionFailed: + if (result.isOk()) { + colour = Colour::Success; + passOrFail = "FAILED - but was ok"; + } else { + colour = Colour::Error; + passOrFail = "FAILED"; + } + if (_stats.infoMessages.size() == 1) + messageLabel = "with message"; + if (_stats.infoMessages.size() > 1) + messageLabel = "with messages"; + break; + case ResultWas::ThrewException: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "due to unexpected exception with "; + if (_stats.infoMessages.size() == 1) + messageLabel += "message"; + if (_stats.infoMessages.size() > 1) + messageLabel += "messages"; + break; + case ResultWas::FatalErrorCondition: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "due to a fatal error condition"; + break; + case ResultWas::DidntThrowException: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "because no exception was thrown where one was expected"; + break; + case ResultWas::Info: + messageLabel = "info"; + break; + case ResultWas::Warning: + messageLabel = "warning"; + break; + case ResultWas::ExplicitFailure: + passOrFail = "FAILED"; + colour = Colour::Error; + if (_stats.infoMessages.size() == 1) + messageLabel = "explicitly with message"; + if (_stats.infoMessages.size() > 1) + messageLabel = "explicitly with messages"; + break; + // These cases are here to prevent compiler warnings + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + passOrFail = "** internal error **"; + colour = Colour::Error; + break; + } + } + + void print() const { + printSourceInfo(); + if (stats.totals.assertions.total() > 0) { + if (result.isOk()) + stream << '\n'; + printResultType(); + printOriginalExpression(); + printReconstructedExpression(); + } else { + stream << '\n'; + } + printMessage(); + } + +private: + void printResultType() const { + if (!passOrFail.empty()) { + Colour colourGuard(colour); + stream << passOrFail << ":\n"; + } + } + void printOriginalExpression() const { + if (result.hasExpression()) { + Colour colourGuard(Colour::OriginalExpression); + stream << " "; + stream << result.getExpressionInMacro(); + stream << '\n'; + } + } + void printReconstructedExpression() const { + if (result.hasExpandedExpression()) { + stream << "with expansion:\n"; + Colour colourGuard(Colour::ReconstructedExpression); + stream << Column(result.getExpandedExpression()).indent(2) << '\n'; + } + } + void printMessage() const { + if (!messageLabel.empty()) + stream << messageLabel << ':' << '\n'; + for (auto const& msg : messages) { + // If this assertion is a warning ignore any INFO messages + if (printInfoMessages || msg.type != ResultWas::Info) + stream << Column(msg.message).indent(2) << '\n'; + } + } + void printSourceInfo() const { + Colour colourGuard(Colour::FileName); + stream << result.getSourceInfo() << ": "; + } + + std::ostream& stream; + AssertionStats const& stats; + AssertionResult const& result; + Colour::Code colour; + std::string passOrFail; + std::string messageLabel; + std::string message; + std::vector messages; + bool printInfoMessages; +}; + +std::size_t makeRatio(std::size_t number, std::size_t total) { + std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0; + return (ratio == 0 && number > 0) ? 1 : ratio; +} + +std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) { + if (i > j && i > k) + return i; + else if (j > k) + return j; + else + return k; +} + +struct ColumnInfo { + enum Justification { Left, Right }; + std::string name; + int width; + Justification justification; +}; +struct ColumnBreak {}; +struct RowBreak {}; + +class Duration { + enum class Unit { + Auto, + Nanoseconds, + Microseconds, + Milliseconds, + Seconds, + Minutes + }; + static const uint64_t s_nanosecondsInAMicrosecond = 1000; + static const uint64_t s_nanosecondsInAMillisecond = 1000 * s_nanosecondsInAMicrosecond; + static const uint64_t s_nanosecondsInASecond = 1000 * s_nanosecondsInAMillisecond; + static const uint64_t s_nanosecondsInAMinute = 60 * s_nanosecondsInASecond; + + uint64_t m_inNanoseconds; + Unit m_units; + +public: + explicit Duration(uint64_t inNanoseconds, Unit units = Unit::Auto) + : m_inNanoseconds(inNanoseconds), + m_units(units) { + if (m_units == Unit::Auto) { + if (m_inNanoseconds < s_nanosecondsInAMicrosecond) + m_units = Unit::Nanoseconds; + else if (m_inNanoseconds < s_nanosecondsInAMillisecond) + m_units = Unit::Microseconds; + else if (m_inNanoseconds < s_nanosecondsInASecond) + m_units = Unit::Milliseconds; + else if (m_inNanoseconds < s_nanosecondsInAMinute) + m_units = Unit::Seconds; + else + m_units = Unit::Minutes; + } + + } + + auto value() const -> double { + switch (m_units) { + case Unit::Microseconds: + return m_inNanoseconds / static_cast(s_nanosecondsInAMicrosecond); + case Unit::Milliseconds: + return m_inNanoseconds / static_cast(s_nanosecondsInAMillisecond); + case Unit::Seconds: + return m_inNanoseconds / static_cast(s_nanosecondsInASecond); + case Unit::Minutes: + return m_inNanoseconds / static_cast(s_nanosecondsInAMinute); + default: + return static_cast(m_inNanoseconds); + } + } + auto unitsAsString() const -> std::string { + switch (m_units) { + case Unit::Nanoseconds: + return "ns"; + case Unit::Microseconds: + return "µs"; + case Unit::Milliseconds: + return "ms"; + case Unit::Seconds: + return "s"; + case Unit::Minutes: + return "m"; + default: + return "** internal error **"; + } + + } + friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& { + return os << duration.value() << " " << duration.unitsAsString(); + } +}; +} // end anon namespace + +class TablePrinter { + std::ostream& m_os; + std::vector m_columnInfos; + std::ostringstream m_oss; + int m_currentColumn = -1; + bool m_isOpen = false; + +public: + TablePrinter( std::ostream& os, std::vector columnInfos ) + : m_os( os ), + m_columnInfos( std::move( columnInfos ) ) {} + + auto columnInfos() const -> std::vector const& { + return m_columnInfos; + } + + void open() { + if (!m_isOpen) { + m_isOpen = true; + *this << RowBreak(); + for (auto const& info : m_columnInfos) + *this << info.name << ColumnBreak(); + *this << RowBreak(); + m_os << Catch::getLineOfChars<'-'>() << "\n"; + } + } + void close() { + if (m_isOpen) { + *this << RowBreak(); + m_os << std::endl; + m_isOpen = false; + } + } + + template + friend TablePrinter& operator << (TablePrinter& tp, T const& value) { + tp.m_oss << value; + return tp; + } + + friend TablePrinter& operator << (TablePrinter& tp, ColumnBreak) { + auto colStr = tp.m_oss.str(); + // This takes account of utf8 encodings + auto strSize = Catch::StringRef(colStr).numberOfCharacters(); + tp.m_oss.str(""); + tp.open(); + if (tp.m_currentColumn == static_cast(tp.m_columnInfos.size() - 1)) { + tp.m_currentColumn = -1; + tp.m_os << "\n"; + } + tp.m_currentColumn++; + + auto colInfo = tp.m_columnInfos[tp.m_currentColumn]; + auto padding = (strSize + 2 < static_cast(colInfo.width)) + ? std::string(colInfo.width - (strSize + 2), ' ') + : std::string(); + if (colInfo.justification == ColumnInfo::Left) + tp.m_os << colStr << padding << " "; + else + tp.m_os << padding << colStr << " "; + return tp; + } + + friend TablePrinter& operator << (TablePrinter& tp, RowBreak) { + if (tp.m_currentColumn > 0) { + tp.m_os << "\n"; + tp.m_currentColumn = -1; + } + return tp; + } +}; + +ConsoleReporter::ConsoleReporter(ReporterConfig const& config) + : StreamingReporterBase(config), + m_tablePrinter(new TablePrinter(config.stream(), + { + { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 32, ColumnInfo::Left }, + { "iters", 8, ColumnInfo::Right }, + { "elapsed ns", 14, ColumnInfo::Right }, + { "average", 14, ColumnInfo::Right } + })) {} +ConsoleReporter::~ConsoleReporter() = default; + +std::string ConsoleReporter::getDescription() { + return "Reports test results as plain lines of text"; +} + +void ConsoleReporter::noMatchingTestCases(std::string const& spec) { + stream << "No test cases matched '" << spec << '\'' << std::endl; +} + +void ConsoleReporter::assertionStarting(AssertionInfo const&) {} + +bool ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) { + AssertionResult const& result = _assertionStats.assertionResult; + + bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); + + // Drop out if result was successful but we're not printing them. + if (!includeResults && result.getResultType() != ResultWas::Warning) + return false; + + lazyPrint(); + + ConsoleAssertionPrinter printer(stream, _assertionStats, includeResults); + printer.print(); + stream << std::endl; + return true; +} + +void ConsoleReporter::sectionStarting(SectionInfo const& _sectionInfo) { + m_headerPrinted = false; + StreamingReporterBase::sectionStarting(_sectionInfo); +} +void ConsoleReporter::sectionEnded(SectionStats const& _sectionStats) { + m_tablePrinter->close(); + if (_sectionStats.missingAssertions) { + lazyPrint(); + Colour colour(Colour::ResultError); + if (m_sectionStack.size() > 1) + stream << "\nNo assertions in section"; + else + stream << "\nNo assertions in test case"; + stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl; + } + if (m_config->showDurations() == ShowDurations::Always) { + stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; + } + if (m_headerPrinted) { + m_headerPrinted = false; + } + StreamingReporterBase::sectionEnded(_sectionStats); +} + +void ConsoleReporter::benchmarkStarting(BenchmarkInfo const& info) { + lazyPrintWithoutClosingBenchmarkTable(); + + auto nameCol = Column( info.name ).width( static_cast( m_tablePrinter->columnInfos()[0].width - 2 ) ); + + bool firstLine = true; + for (auto line : nameCol) { + if (!firstLine) + (*m_tablePrinter) << ColumnBreak() << ColumnBreak() << ColumnBreak(); + else + firstLine = false; + + (*m_tablePrinter) << line << ColumnBreak(); + } +} +void ConsoleReporter::benchmarkEnded(BenchmarkStats const& stats) { + Duration average(stats.elapsedTimeInNanoseconds / stats.iterations); + (*m_tablePrinter) + << stats.iterations << ColumnBreak() + << stats.elapsedTimeInNanoseconds << ColumnBreak() + << average << ColumnBreak(); +} + +void ConsoleReporter::testCaseEnded(TestCaseStats const& _testCaseStats) { + m_tablePrinter->close(); + StreamingReporterBase::testCaseEnded(_testCaseStats); + m_headerPrinted = false; +} +void ConsoleReporter::testGroupEnded(TestGroupStats const& _testGroupStats) { + if (currentGroupInfo.used) { + printSummaryDivider(); + stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; + printTotals(_testGroupStats.totals); + stream << '\n' << std::endl; + } + StreamingReporterBase::testGroupEnded(_testGroupStats); +} +void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) { + printTotalsDivider(_testRunStats.totals); + printTotals(_testRunStats.totals); + stream << std::endl; + StreamingReporterBase::testRunEnded(_testRunStats); +} + +void ConsoleReporter::lazyPrint() { + + m_tablePrinter->close(); + lazyPrintWithoutClosingBenchmarkTable(); +} + +void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() { + + if (!currentTestRunInfo.used) + lazyPrintRunInfo(); + if (!currentGroupInfo.used) + lazyPrintGroupInfo(); + + if (!m_headerPrinted) { + printTestCaseAndSectionHeader(); + m_headerPrinted = true; + } +} +void ConsoleReporter::lazyPrintRunInfo() { + stream << '\n' << getLineOfChars<'~'>() << '\n'; + Colour colour(Colour::SecondaryText); + stream << currentTestRunInfo->name + << " is a Catch v" << libraryVersion() << " host application.\n" + << "Run with -? for options\n\n"; + + if (m_config->rngSeed() != 0) + stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n"; + + currentTestRunInfo.used = true; +} +void ConsoleReporter::lazyPrintGroupInfo() { + if (!currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1) { + printClosedHeader("Group: " + currentGroupInfo->name); + currentGroupInfo.used = true; + } +} +void ConsoleReporter::printTestCaseAndSectionHeader() { + assert(!m_sectionStack.empty()); + printOpenHeader(currentTestCaseInfo->name); + + if (m_sectionStack.size() > 1) { + Colour colourGuard(Colour::Headers); + + auto + it = m_sectionStack.begin() + 1, // Skip first section (test case) + itEnd = m_sectionStack.end(); + for (; it != itEnd; ++it) + printHeaderString(it->name, 2); + } + + SourceLineInfo lineInfo = m_sectionStack.back().lineInfo; + + if (!lineInfo.empty()) { + stream << getLineOfChars<'-'>() << '\n'; + Colour colourGuard(Colour::FileName); + stream << lineInfo << '\n'; + } + stream << getLineOfChars<'.'>() << '\n' << std::endl; +} + +void ConsoleReporter::printClosedHeader(std::string const& _name) { + printOpenHeader(_name); + stream << getLineOfChars<'.'>() << '\n'; +} +void ConsoleReporter::printOpenHeader(std::string const& _name) { + stream << getLineOfChars<'-'>() << '\n'; + { + Colour colourGuard(Colour::Headers); + printHeaderString(_name); + } +} + +// if string has a : in first line will set indent to follow it on +// subsequent lines +void ConsoleReporter::printHeaderString(std::string const& _string, std::size_t indent) { + std::size_t i = _string.find(": "); + if (i != std::string::npos) + i += 2; + else + i = 0; + stream << Column(_string).indent(indent + i).initialIndent(indent) << '\n'; +} + +struct SummaryColumn { + + SummaryColumn( std::string _label, Colour::Code _colour ) + : label( std::move( _label ) ), + colour( _colour ) {} + SummaryColumn addRow( std::size_t count ) { + ReusableStringStream rss; + rss << count; + std::string row = rss.str(); + for (auto& oldRow : rows) { + while (oldRow.size() < row.size()) + oldRow = ' ' + oldRow; + while (oldRow.size() > row.size()) + row = ' ' + row; + } + rows.push_back(row); + return *this; + } + + std::string label; + Colour::Code colour; + std::vector rows; + +}; + +void ConsoleReporter::printTotals( Totals const& totals ) { + if (totals.testCases.total() == 0) { + stream << Colour(Colour::Warning) << "No tests ran\n"; + } else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) { + stream << Colour(Colour::ResultSuccess) << "All tests passed"; + stream << " (" + << pluralise(totals.assertions.passed, "assertion") << " in " + << pluralise(totals.testCases.passed, "test case") << ')' + << '\n'; + } else { + + std::vector columns; + columns.push_back(SummaryColumn("", Colour::None) + .addRow(totals.testCases.total()) + .addRow(totals.assertions.total())); + columns.push_back(SummaryColumn("passed", Colour::Success) + .addRow(totals.testCases.passed) + .addRow(totals.assertions.passed)); + columns.push_back(SummaryColumn("failed", Colour::ResultError) + .addRow(totals.testCases.failed) + .addRow(totals.assertions.failed)); + columns.push_back(SummaryColumn("failed as expected", Colour::ResultExpectedFailure) + .addRow(totals.testCases.failedButOk) + .addRow(totals.assertions.failedButOk)); + + printSummaryRow("test cases", columns, 0); + printSummaryRow("assertions", columns, 1); + } +} +void ConsoleReporter::printSummaryRow(std::string const& label, std::vector const& cols, std::size_t row) { + for (auto col : cols) { + std::string value = col.rows[row]; + if (col.label.empty()) { + stream << label << ": "; + if (value != "0") + stream << value; + else + stream << Colour(Colour::Warning) << "- none -"; + } else if (value != "0") { + stream << Colour(Colour::LightGrey) << " | "; + stream << Colour(col.colour) + << value << ' ' << col.label; + } + } + stream << '\n'; +} + +void ConsoleReporter::printTotalsDivider(Totals const& totals) { + if (totals.testCases.total() > 0) { + std::size_t failedRatio = makeRatio(totals.testCases.failed, totals.testCases.total()); + std::size_t failedButOkRatio = makeRatio(totals.testCases.failedButOk, totals.testCases.total()); + std::size_t passedRatio = makeRatio(totals.testCases.passed, totals.testCases.total()); + while (failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH - 1) + findMax(failedRatio, failedButOkRatio, passedRatio)++; + while (failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH - 1) + findMax(failedRatio, failedButOkRatio, passedRatio)--; + + stream << Colour(Colour::Error) << std::string(failedRatio, '='); + stream << Colour(Colour::ResultExpectedFailure) << std::string(failedButOkRatio, '='); + if (totals.testCases.allPassed()) + stream << Colour(Colour::ResultSuccess) << std::string(passedRatio, '='); + else + stream << Colour(Colour::Success) << std::string(passedRatio, '='); + } else { + stream << Colour(Colour::Warning) << std::string(CATCH_CONFIG_CONSOLE_WIDTH - 1, '='); + } + stream << '\n'; +} +void ConsoleReporter::printSummaryDivider() { + stream << getLineOfChars<'-'>() << '\n'; +} + +CATCH_REGISTER_REPORTER("console", ConsoleReporter) + +} // end namespace Catch + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif +// end catch_reporter_console.cpp +// start catch_reporter_junit.cpp + +#include +#include +#include +#include + +namespace Catch { + + namespace { + std::string getCurrentTimestamp() { + // Beware, this is not reentrant because of backward compatibility issues + // Also, UTC only, again because of backward compatibility (%z is C++11) + time_t rawtime; + std::time(&rawtime); + auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); + +#ifdef _MSC_VER + std::tm timeInfo = {}; + gmtime_s(&timeInfo, &rawtime); +#else + std::tm* timeInfo; + timeInfo = std::gmtime(&rawtime); +#endif + + char timeStamp[timeStampSize]; + const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + +#ifdef _MSC_VER + std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); +#else + std::strftime(timeStamp, timeStampSize, fmt, timeInfo); +#endif + return std::string(timeStamp); + } + + std::string fileNameTag(const std::vector &tags) { + auto it = std::find_if(begin(tags), + end(tags), + [] (std::string const& tag) {return tag.front() == '#'; }); + if (it != tags.end()) + return it->substr(1); + return std::string(); + } + } // anonymous namespace + + JunitReporter::JunitReporter( ReporterConfig const& _config ) + : CumulativeReporterBase( _config ), + xml( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = true; + } + + JunitReporter::~JunitReporter() {} + + std::string JunitReporter::getDescription() { + return "Reports test results in an XML format that looks like Ant's junitreport target"; + } + + void JunitReporter::noMatchingTestCases( std::string const& /*spec*/ ) {} + + void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) { + CumulativeReporterBase::testRunStarting( runInfo ); + xml.startElement( "testsuites" ); + } + + void JunitReporter::testGroupStarting( GroupInfo const& groupInfo ) { + suiteTimer.start(); + stdOutForSuite.clear(); + stdErrForSuite.clear(); + unexpectedExceptions = 0; + CumulativeReporterBase::testGroupStarting( groupInfo ); + } + + void JunitReporter::testCaseStarting( TestCaseInfo const& testCaseInfo ) { + m_okToFail = testCaseInfo.okToFail(); + } + + bool JunitReporter::assertionEnded( AssertionStats const& assertionStats ) { + if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail ) + unexpectedExceptions++; + return CumulativeReporterBase::assertionEnded( assertionStats ); + } + + void JunitReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { + stdOutForSuite += testCaseStats.stdOut; + stdErrForSuite += testCaseStats.stdErr; + CumulativeReporterBase::testCaseEnded( testCaseStats ); + } + + void JunitReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { + double suiteTime = suiteTimer.getElapsedSeconds(); + CumulativeReporterBase::testGroupEnded( testGroupStats ); + writeGroup( *m_testGroups.back(), suiteTime ); + } + + void JunitReporter::testRunEndedCumulative() { + xml.endElement(); + } + + void JunitReporter::writeGroup( TestGroupNode const& groupNode, double suiteTime ) { + XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); + TestGroupStats const& stats = groupNode.value; + xml.writeAttribute( "name", stats.groupInfo.name ); + xml.writeAttribute( "errors", unexpectedExceptions ); + xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions ); + xml.writeAttribute( "tests", stats.totals.assertions.total() ); + xml.writeAttribute( "hostname", "tbd" ); // !TBD + if( m_config->showDurations() == ShowDurations::Never ) + xml.writeAttribute( "time", "" ); + else + xml.writeAttribute( "time", suiteTime ); + xml.writeAttribute( "timestamp", getCurrentTimestamp() ); + + // Write test cases + for( auto const& child : groupNode.children ) + writeTestCase( *child ); + + xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite ), false ); + xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite ), false ); + } + + void JunitReporter::writeTestCase( TestCaseNode const& testCaseNode ) { + TestCaseStats const& stats = testCaseNode.value; + + // All test cases have exactly one section - which represents the + // test case itself. That section may have 0-n nested sections + assert( testCaseNode.children.size() == 1 ); + SectionNode const& rootSection = *testCaseNode.children.front(); + + std::string className = stats.testInfo.className; + + if( className.empty() ) { + className = fileNameTag(stats.testInfo.tags); + if ( className.empty() ) + className = "global"; + } + + if ( !m_config->name().empty() ) + className = m_config->name() + "." + className; + + writeSection( className, "", rootSection ); + } + + void JunitReporter::writeSection( std::string const& className, + std::string const& rootName, + SectionNode const& sectionNode ) { + std::string name = trim( sectionNode.stats.sectionInfo.name ); + if( !rootName.empty() ) + name = rootName + '/' + name; + + if( !sectionNode.assertions.empty() || + !sectionNode.stdOut.empty() || + !sectionNode.stdErr.empty() ) { + XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); + if( className.empty() ) { + xml.writeAttribute( "classname", name ); + xml.writeAttribute( "name", "root" ); + } + else { + xml.writeAttribute( "classname", className ); + xml.writeAttribute( "name", name ); + } + xml.writeAttribute( "time", ::Catch::Detail::stringify( sectionNode.stats.durationInSeconds ) ); + + writeAssertions( sectionNode ); + + if( !sectionNode.stdOut.empty() ) + xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); + if( !sectionNode.stdErr.empty() ) + xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); + } + for( auto const& childNode : sectionNode.childSections ) + if( className.empty() ) + writeSection( name, "", *childNode ); + else + writeSection( className, name, *childNode ); + } + + void JunitReporter::writeAssertions( SectionNode const& sectionNode ) { + for( auto const& assertion : sectionNode.assertions ) + writeAssertion( assertion ); + } + + void JunitReporter::writeAssertion( AssertionStats const& stats ) { + AssertionResult const& result = stats.assertionResult; + if( !result.isOk() ) { + std::string elementName; + switch( result.getResultType() ) { + case ResultWas::ThrewException: + case ResultWas::FatalErrorCondition: + elementName = "error"; + break; + case ResultWas::ExplicitFailure: + elementName = "failure"; + break; + case ResultWas::ExpressionFailed: + elementName = "failure"; + break; + case ResultWas::DidntThrowException: + elementName = "failure"; + break; + + // We should never see these here: + case ResultWas::Info: + case ResultWas::Warning: + case ResultWas::Ok: + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + elementName = "internalError"; + break; + } + + XmlWriter::ScopedElement e = xml.scopedElement( elementName ); + + xml.writeAttribute( "message", result.getExpandedExpression() ); + xml.writeAttribute( "type", result.getTestMacroName() ); + + ReusableStringStream rss; + if( !result.getMessage().empty() ) + rss << result.getMessage() << '\n'; + for( auto const& msg : stats.infoMessages ) + if( msg.type == ResultWas::Info ) + rss << msg.message << '\n'; + + rss << "at " << result.getSourceInfo(); + xml.writeText( rss.str(), false ); + } + } + + CATCH_REGISTER_REPORTER( "junit", JunitReporter ) + +} // end namespace Catch +// end catch_reporter_junit.cpp +// start catch_reporter_multi.cpp + +namespace Catch { + + void MultipleReporters::add( IStreamingReporterPtr&& reporter ) { + m_reporters.push_back( std::move( reporter ) ); + } + + ReporterPreferences MultipleReporters::getPreferences() const { + return m_reporters[0]->getPreferences(); + } + + std::set MultipleReporters::getSupportedVerbosities() { + return std::set{ }; + } + + void MultipleReporters::noMatchingTestCases( std::string const& spec ) { + for( auto const& reporter : m_reporters ) + reporter->noMatchingTestCases( spec ); + } + + void MultipleReporters::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) { + for( auto const& reporter : m_reporters ) + reporter->benchmarkStarting( benchmarkInfo ); + } + void MultipleReporters::benchmarkEnded( BenchmarkStats const& benchmarkStats ) { + for( auto const& reporter : m_reporters ) + reporter->benchmarkEnded( benchmarkStats ); + } + + void MultipleReporters::testRunStarting( TestRunInfo const& testRunInfo ) { + for( auto const& reporter : m_reporters ) + reporter->testRunStarting( testRunInfo ); + } + + void MultipleReporters::testGroupStarting( GroupInfo const& groupInfo ) { + for( auto const& reporter : m_reporters ) + reporter->testGroupStarting( groupInfo ); + } + + void MultipleReporters::testCaseStarting( TestCaseInfo const& testInfo ) { + for( auto const& reporter : m_reporters ) + reporter->testCaseStarting( testInfo ); + } + + void MultipleReporters::sectionStarting( SectionInfo const& sectionInfo ) { + for( auto const& reporter : m_reporters ) + reporter->sectionStarting( sectionInfo ); + } + + void MultipleReporters::assertionStarting( AssertionInfo const& assertionInfo ) { + for( auto const& reporter : m_reporters ) + reporter->assertionStarting( assertionInfo ); + } + + // The return value indicates if the messages buffer should be cleared: + bool MultipleReporters::assertionEnded( AssertionStats const& assertionStats ) { + bool clearBuffer = false; + for( auto const& reporter : m_reporters ) + clearBuffer |= reporter->assertionEnded( assertionStats ); + return clearBuffer; + } + + void MultipleReporters::sectionEnded( SectionStats const& sectionStats ) { + for( auto const& reporter : m_reporters ) + reporter->sectionEnded( sectionStats ); + } + + void MultipleReporters::testCaseEnded( TestCaseStats const& testCaseStats ) { + for( auto const& reporter : m_reporters ) + reporter->testCaseEnded( testCaseStats ); + } + + void MultipleReporters::testGroupEnded( TestGroupStats const& testGroupStats ) { + for( auto const& reporter : m_reporters ) + reporter->testGroupEnded( testGroupStats ); + } + + void MultipleReporters::testRunEnded( TestRunStats const& testRunStats ) { + for( auto const& reporter : m_reporters ) + reporter->testRunEnded( testRunStats ); + } + + void MultipleReporters::skipTest( TestCaseInfo const& testInfo ) { + for( auto const& reporter : m_reporters ) + reporter->skipTest( testInfo ); + } + + bool MultipleReporters::isMulti() const { + return true; + } + +} // end namespace Catch +// end catch_reporter_multi.cpp +// start catch_reporter_xml.cpp + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch + // Note that 4062 (not all labels are handled + // and default is missing) is enabled +#endif + +namespace Catch { + XmlReporter::XmlReporter( ReporterConfig const& _config ) + : StreamingReporterBase( _config ), + m_xml(_config.stream()) + { + m_reporterPrefs.shouldRedirectStdOut = true; + } + + XmlReporter::~XmlReporter() = default; + + std::string XmlReporter::getDescription() { + return "Reports test results as an XML document"; + } + + std::string XmlReporter::getStylesheetRef() const { + return std::string(); + } + + void XmlReporter::writeSourceInfo( SourceLineInfo const& sourceInfo ) { + m_xml + .writeAttribute( "filename", sourceInfo.file ) + .writeAttribute( "line", sourceInfo.line ); + } + + void XmlReporter::noMatchingTestCases( std::string const& s ) { + StreamingReporterBase::noMatchingTestCases( s ); + } + + void XmlReporter::testRunStarting( TestRunInfo const& testInfo ) { + StreamingReporterBase::testRunStarting( testInfo ); + std::string stylesheetRef = getStylesheetRef(); + if( !stylesheetRef.empty() ) + m_xml.writeStylesheetRef( stylesheetRef ); + m_xml.startElement( "Catch" ); + if( !m_config->name().empty() ) + m_xml.writeAttribute( "name", m_config->name() ); + } + + void XmlReporter::testGroupStarting( GroupInfo const& groupInfo ) { + StreamingReporterBase::testGroupStarting( groupInfo ); + m_xml.startElement( "Group" ) + .writeAttribute( "name", groupInfo.name ); + } + + void XmlReporter::testCaseStarting( TestCaseInfo const& testInfo ) { + StreamingReporterBase::testCaseStarting(testInfo); + m_xml.startElement( "TestCase" ) + .writeAttribute( "name", trim( testInfo.name ) ) + .writeAttribute( "description", testInfo.description ) + .writeAttribute( "tags", testInfo.tagsAsString() ); + + writeSourceInfo( testInfo.lineInfo ); + + if ( m_config->showDurations() == ShowDurations::Always ) + m_testCaseTimer.start(); + m_xml.ensureTagClosed(); + } + + void XmlReporter::sectionStarting( SectionInfo const& sectionInfo ) { + StreamingReporterBase::sectionStarting( sectionInfo ); + if( m_sectionDepth++ > 0 ) { + m_xml.startElement( "Section" ) + .writeAttribute( "name", trim( sectionInfo.name ) ) + .writeAttribute( "description", sectionInfo.description ); + writeSourceInfo( sectionInfo.lineInfo ); + m_xml.ensureTagClosed(); + } + } + + void XmlReporter::assertionStarting( AssertionInfo const& ) { } + + bool XmlReporter::assertionEnded( AssertionStats const& assertionStats ) { + + AssertionResult const& result = assertionStats.assertionResult; + + bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); + + if( includeResults || result.getResultType() == ResultWas::Warning ) { + // Print any info messages in tags. + for( auto const& msg : assertionStats.infoMessages ) { + if( msg.type == ResultWas::Info && includeResults ) { + m_xml.scopedElement( "Info" ) + .writeText( msg.message ); + } else if ( msg.type == ResultWas::Warning ) { + m_xml.scopedElement( "Warning" ) + .writeText( msg.message ); + } + } + } + + // Drop out if result was successful but we're not printing them. + if( !includeResults && result.getResultType() != ResultWas::Warning ) + return true; + + // Print the expression if there is one. + if( result.hasExpression() ) { + m_xml.startElement( "Expression" ) + .writeAttribute( "success", result.succeeded() ) + .writeAttribute( "type", result.getTestMacroName() ); + + writeSourceInfo( result.getSourceInfo() ); + + m_xml.scopedElement( "Original" ) + .writeText( result.getExpression() ); + m_xml.scopedElement( "Expanded" ) + .writeText( result.getExpandedExpression() ); + } + + // And... Print a result applicable to each result type. + switch( result.getResultType() ) { + case ResultWas::ThrewException: + m_xml.startElement( "Exception" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + case ResultWas::FatalErrorCondition: + m_xml.startElement( "FatalErrorCondition" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + case ResultWas::Info: + m_xml.scopedElement( "Info" ) + .writeText( result.getMessage() ); + break; + case ResultWas::Warning: + // Warning will already have been written + break; + case ResultWas::ExplicitFailure: + m_xml.startElement( "Failure" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + default: + break; + } + + if( result.hasExpression() ) + m_xml.endElement(); + + return true; + } + + void XmlReporter::sectionEnded( SectionStats const& sectionStats ) { + StreamingReporterBase::sectionEnded( sectionStats ); + if( --m_sectionDepth > 0 ) { + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); + e.writeAttribute( "successes", sectionStats.assertions.passed ); + e.writeAttribute( "failures", sectionStats.assertions.failed ); + e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); + + m_xml.endElement(); + } + } + + void XmlReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { + StreamingReporterBase::testCaseEnded( testCaseStats ); + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); + e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); + + if( !testCaseStats.stdOut.empty() ) + m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false ); + if( !testCaseStats.stdErr.empty() ) + m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false ); + + m_xml.endElement(); + } + + void XmlReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { + StreamingReporterBase::testGroupEnded( testGroupStats ); + // TODO: Check testGroupStats.aborting and act accordingly. + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", testGroupStats.totals.assertions.passed ) + .writeAttribute( "failures", testGroupStats.totals.assertions.failed ) + .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); + m_xml.endElement(); + } + + void XmlReporter::testRunEnded( TestRunStats const& testRunStats ) { + StreamingReporterBase::testRunEnded( testRunStats ); + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", testRunStats.totals.assertions.passed ) + .writeAttribute( "failures", testRunStats.totals.assertions.failed ) + .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk ); + m_xml.endElement(); + } + + CATCH_REGISTER_REPORTER( "xml", XmlReporter ) + +} // end namespace Catch + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif +// end catch_reporter_xml.cpp + +namespace Catch { + LeakDetector leakDetector; +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_impl.hpp +#endif + +#ifdef CATCH_CONFIG_MAIN +// start catch_default_main.hpp + +#ifndef __OBJC__ + +#if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) +// Standard C/C++ Win32 Unicode wmain entry point +extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) { +#else +// Standard C/C++ main entry point +int main (int argc, char * argv[]) { +#endif + + return Catch::Session().run( argc, argv ); +} + +#else // __OBJC__ + +// Objective-C entry point +int main (int argc, char * const argv[]) { +#if !CATCH_ARC_ENABLED + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; +#endif + + Catch::registerTestMethods(); + int result = Catch::Session().run( argc, (char**)argv ); + +#if !CATCH_ARC_ENABLED + [pool drain]; +#endif + + return result; +} + +#endif // __OBJC__ + +// end catch_default_main.hpp +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) + +#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED +# undef CLARA_CONFIG_MAIN +#endif + +#if !defined(CATCH_CONFIG_DISABLE) +////// +// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ +#ifdef CATCH_CONFIG_PREFIX_ALL + +#define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) + +#define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", __VA_ARGS__ ) +#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) +#endif// CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) + +#define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) +#define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) + +#define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", __VA_ARGS__ ) +#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) + +#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) +#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) +#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) + +#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) +#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) +#define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) +#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() + +// "BDD-style" convenience wrappers +#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) +#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) +#define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc ) +#define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc ) +#define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc ) +#define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc ) +#define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc ) + +// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required +#else + +#define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) + +#define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) + +#define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) +#define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) + +#define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) + +#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) +#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) +#define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) + +#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) +#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) +#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) +#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() + +#endif + +#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) + +// "BDD-style" convenience wrappers +#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) +#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) + +#define GIVEN( desc ) SECTION( std::string(" Given: ") + desc ) +#define WHEN( desc ) SECTION( std::string(" When: ") + desc ) +#define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc ) +#define THEN( desc ) SECTION( std::string(" Then: ") + desc ) +#define AND_THEN( desc ) SECTION( std::string(" And: ") + desc ) + +using Catch::Detail::Approx; + +#else +////// +// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ +#ifdef CATCH_CONFIG_PREFIX_ALL + +#define CATCH_REQUIRE( ... ) (void)(0) +#define CATCH_REQUIRE_FALSE( ... ) (void)(0) + +#define CATCH_REQUIRE_THROWS( ... ) (void)(0) +#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) +#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif// CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_REQUIRE_NOTHROW( ... ) (void)(0) + +#define CATCH_CHECK( ... ) (void)(0) +#define CATCH_CHECK_FALSE( ... ) (void)(0) +#define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__) +#define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) +#define CATCH_CHECK_NOFAIL( ... ) (void)(0) + +#define CATCH_CHECK_THROWS( ... ) (void)(0) +#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0) +#define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_CHECK_NOTHROW( ... ) (void)(0) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THAT( arg, matcher ) (void)(0) + +#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define CATCH_INFO( msg ) (void)(0) +#define CATCH_WARN( msg ) (void)(0) +#define CATCH_CAPTURE( msg ) (void)(0) + +#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define CATCH_METHOD_AS_TEST_CASE( method, ... ) +#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0) +#define CATCH_SECTION( ... ) +#define CATCH_FAIL( ... ) (void)(0) +#define CATCH_FAIL_CHECK( ... ) (void)(0) +#define CATCH_SUCCEED( ... ) (void)(0) + +#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) + +// "BDD-style" convenience wrappers +#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className ) +#define CATCH_GIVEN( desc ) +#define CATCH_WHEN( desc ) +#define CATCH_AND_WHEN( desc ) +#define CATCH_THEN( desc ) +#define CATCH_AND_THEN( desc ) + +// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required +#else + +#define REQUIRE( ... ) (void)(0) +#define REQUIRE_FALSE( ... ) (void)(0) + +#define REQUIRE_THROWS( ... ) (void)(0) +#define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) +#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define REQUIRE_NOTHROW( ... ) (void)(0) + +#define CHECK( ... ) (void)(0) +#define CHECK_FALSE( ... ) (void)(0) +#define CHECKED_IF( ... ) if (__VA_ARGS__) +#define CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) +#define CHECK_NOFAIL( ... ) (void)(0) + +#define CHECK_THROWS( ... ) (void)(0) +#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0) +#define CHECK_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CHECK_NOTHROW( ... ) (void)(0) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THAT( arg, matcher ) (void)(0) + +#define REQUIRE_THAT( arg, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define INFO( msg ) (void)(0) +#define WARN( msg ) (void)(0) +#define CAPTURE( msg ) (void)(0) + +#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define METHOD_AS_TEST_CASE( method, ... ) +#define REGISTER_TEST_CASE( Function, ... ) (void)(0) +#define SECTION( ... ) +#define FAIL( ... ) (void)(0) +#define FAIL_CHECK( ... ) (void)(0) +#define SUCCEED( ... ) (void)(0) +#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) + +#endif + +#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) + +// "BDD-style" convenience wrappers +#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) ) +#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className ) + +#define GIVEN( desc ) +#define WHEN( desc ) +#define AND_WHEN( desc ) +#define THEN( desc ) +#define AND_THEN( desc ) + +using Catch::Detail::Approx; + +#endif + +#endif // ! CATCH_CONFIG_IMPL_ONLY + +// start catch_reenable_warnings.h + + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(pop) +# else +# pragma clang diagnostic pop +# endif +#elif defined __GNUC__ +# pragma GCC diagnostic pop +#endif + +// end catch_reenable_warnings.h +// end catch.hpp +#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED + diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/ConfigBase.cpp similarity index 100% rename from xs/src/libslic3r/Config.cpp rename to xs/src/libslic3r/ConfigBase.cpp diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/ConfigBase.hpp similarity index 100% rename from xs/src/libslic3r/Config.hpp rename to xs/src/libslic3r/ConfigBase.hpp From d145ee3465210be035f46ad43cc49bde1f799239 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 18:12:26 -0500 Subject: [PATCH 018/305] Finish renaming Config->ConfigBase in libSlic3r to make room for a Slic3r::Config that has an interface closer to the Perl version. --- src/CMakeLists.txt | 2 +- src/slic3r.cpp | 2 +- xs/src/libslic3r/ConfigBase.cpp | 2 +- xs/src/libslic3r/ConfigBase.hpp | 6 +++--- xs/src/libslic3r/Flow.hpp | 2 +- xs/src/libslic3r/PrintConfig.hpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 15382d8b8..9f1e0072f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,7 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/BoundingBox.cpp ${LIBDIR}/libslic3r/BridgeDetector.cpp ${LIBDIR}/libslic3r/ClipperUtils.cpp - ${LIBDIR}/libslic3r/Config.cpp + ${LIBDIR}/libslic3r/ConfigBase.cpp ${LIBDIR}/libslic3r/ExPolygon.cpp ${LIBDIR}/libslic3r/ExPolygonCollection.cpp ${LIBDIR}/libslic3r/Extruder.cpp diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 82a04a1f1..2e8aaf387 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -1,4 +1,4 @@ -#include "Config.hpp" +#include "ConfigBase.hpp" #include "Geometry.hpp" #include "IO.hpp" #include "Model.hpp" diff --git a/xs/src/libslic3r/ConfigBase.cpp b/xs/src/libslic3r/ConfigBase.cpp index ad11df720..161c96212 100644 --- a/xs/src/libslic3r/ConfigBase.cpp +++ b/xs/src/libslic3r/ConfigBase.cpp @@ -1,4 +1,4 @@ -#include "Config.hpp" +#include "ConfigBase.hpp" #include #include #include diff --git a/xs/src/libslic3r/ConfigBase.hpp b/xs/src/libslic3r/ConfigBase.hpp index d1ea39002..1db0f9a96 100644 --- a/xs/src/libslic3r/ConfigBase.hpp +++ b/xs/src/libslic3r/ConfigBase.hpp @@ -1,5 +1,5 @@ -#ifndef slic3r_Config_hpp_ -#define slic3r_Config_hpp_ +#ifndef slic3r_ConfigBase_hpp_ +#define slic3r_ConfigBase_hpp_ #include #include @@ -751,4 +751,4 @@ class UnknownOptionException : public std::exception {}; } -#endif +#endif diff --git a/xs/src/libslic3r/Flow.hpp b/xs/src/libslic3r/Flow.hpp index fb4d8e237..cc8f90723 100644 --- a/xs/src/libslic3r/Flow.hpp +++ b/xs/src/libslic3r/Flow.hpp @@ -2,7 +2,7 @@ #define slic3r_Flow_hpp_ #include "libslic3r.h" -#include "Config.hpp" +#include "ConfigBase.hpp" #include "ExtrusionEntity.hpp" namespace Slic3r { diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 0aa65ba28..6db11d275 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -19,7 +19,7 @@ #define slic3r_PrintConfig_hpp_ #include "libslic3r.h" -#include "Config.hpp" +#include "ConfigBase.hpp" #define OPT_PTR(KEY) if (opt_key == #KEY) return &this->KEY From ad46bc81060fe368688db61e123a8ecd17dbd011 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 18:13:51 -0500 Subject: [PATCH 019/305] Start a simple Slic3r::Log to collect all of the debugging prints to a single area. Upgrade backend to boost::log as needed. --- xs/src/libslic3r/Log.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 xs/src/libslic3r/Log.hpp diff --git a/xs/src/libslic3r/Log.hpp b/xs/src/libslic3r/Log.hpp new file mode 100644 index 000000000..554b560a2 --- /dev/null +++ b/xs/src/libslic3r/Log.hpp @@ -0,0 +1,24 @@ +#ifndef slic3r_LOG_HPP +#define slic3r_LOG_HPP + +#include + +namespace Slic3r { + +class Log { +public: + static void fatal_error(std::string topic, std::wstring message) { + std::cerr << topic << ": "; + std::wcerr << message << std::endl; + } + + static void info(std::string topic, std::wstring message) { + std::clog << topic << ": "; + std::wclog << message << std::endl; + } + +}; + +} + +#endif // slic3r_LOG_HPP From 399db5902c618d40159ddb5f122620ad5105ee1b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 18:15:16 -0500 Subject: [PATCH 020/305] More misc functions (used to live as static functions in Slic3r::GUI perl file). Passing -DVAR_ABS and -DVAR_ABS_PATH=/path/to/slic3r/var on compile redirects where Slic3r expects to find its var directory. --- src/GUI/misc_ui.cpp | 32 ++++++++++++++++++++++++++++---- src/GUI/misc_ui.hpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index ef00fa2d3..8183ec020 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -1,5 +1,8 @@ #include "misc_ui.hpp" #include +#include + +#include namespace Slic3r { namespace GUI { @@ -14,11 +17,18 @@ void check_version(bool manual) { #endif const wxString var(const wxString& in) { + // TODO replace center string with path to VAR in actual distribution later + if (VAR_ABS) { + return VAR_ABS_PATH + "/" + in; + } else { + return bin() + VAR_REL + "/" + in; + } +} + +const wxString bin() { wxFileName f(wxStandardPaths::Get().GetExecutablePath()); wxString appPath(f.GetPath()); - - // replace center string with path to VAR in actual distribution later - return appPath + "/../var/" + in; + return appPath; } /// Returns the path to Slic3r's default user data directory. @@ -28,7 +38,6 @@ const wxString home(const wxString& in) { return wxGetHomeDir() + "/." + in + "/"; } - wxString decode_path(const wxString& in) { // TODO Stub return in; @@ -38,6 +47,21 @@ wxString encode_path(const wxString& in) { // TODO Stub return in; } + +void show_error(wxWindow* parent, const wxString& message) { + wxMessageDialog(parent, message, _("Error"), wxOK | wxICON_ERROR).ShowModal(); +} + +void show_info(wxWindow* parent, const wxString& message, const wxString& title = _("Notice")) { + wxMessageDialog(parent, message, title, wxOK | wxICON_INFORMATION).ShowModal(); +} + +void fatal_error(wxWindow* parent, const wxString& message) { + show_error(parent, message); + throw std::runtime_error(message.ToStdString()); +} + + /* sub append_submenu { my ($self, $menu, $string, $description, $submenu, $id, $icon) = @_; diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index 5276a3f8c..d8586fec7 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -29,16 +29,47 @@ constexpr bool isDev = true; constexpr bool isDev = false; #endif + +/// Mostly useful for Linux distro maintainers, this will change where Slic3r assumes +/// its ./var directory lives (where its art assets are). +/// Define VAR_ABS and VAR_ABS_PATH +#ifndef VAR_ABS + #define VAR_ABS false +#else + #define VAR_ABS true +#endif +#ifndef VAR_ABS_PATH + #define VAR_ABS_PATH "/usr/share/Slic3r/var" +#endif + +#ifndef VAR_REL // Redefine on compile + #define VAR_REL L"/../var" +#endif + /// Performs a check via the Internet for a new version of Slic3r. /// If this version of Slic3r was compiled with -DSLIC3R_DEV, check the development /// space instead of release. void check_version(bool manual = false); +/// Provides a path to Slic3r's var dir. const wxString var(const wxString& in); +/// Provide a path to where Slic3r exec'd from. +const wxString bin(); + /// Always returns path to home directory. const wxString home(const wxString& in = "Slic3r"); +/// Shows an error messagebox +void show_error(wxWindow* parent, const wxString& message); + +/// Shows an info messagebox. +void show_info(wxWindow* parent, const wxString& message, const wxString& title); + +/// Show an error messagebox and then throw an exception. +void fatal_error(wxWindow* parent, const wxString& message); + + template void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxString& icon = "", const wxString& accel = "") { wxMenuItem* tmp = menu->Append(wxID_ANY, name, help); From d24001b92dae241a081838f61f602d8cd99f6a16 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 18:17:10 -0500 Subject: [PATCH 021/305] Check for datadir in OnInit(). --- src/GUI/GUI.cpp | 55 ++++++++++++++++++++++++++++++++++++------------- src/GUI/GUI.hpp | 2 ++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index 67d5485c1..690f07284 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -3,6 +3,8 @@ #include #endif #include +#include +#include #include "MainFrame.hpp" @@ -10,40 +12,65 @@ #include "misc_ui.hpp" #include "Preset.hpp" +// Logging mechanism +#include "Log.hpp" + namespace Slic3r { namespace GUI { -enum -{ - ID_Hello = 1 -}; +/// Primary initialization and point of entry into the GUI application. +/// Calls MainFrame and handles preset loading, etc. bool App::OnInit() { - - this->SetAppName("Slic3r"); // TODO: Call a logging function with channel GUI, severity info this->notifier = std::unique_ptr(); - wxString datadir {decode_path(wxStandardPaths::Get().GetUserDataDir())}; + datadir = decode_path(wxStandardPaths::Get().GetUserDataDir()); wxString enc_datadir = encode_path(datadir); - std::cerr << datadir << "\n"; + + const wxString& slic3r_ini {datadir + "/slic3r.ini"}; + const wxString& print_ini {datadir + "/print"}; + const wxString& printer_ini {datadir + "/printer"}; + const wxString& material_ini {datadir + "/filament"}; + + // if we don't have a datadir or a slic3r.ini, prompt for wizard. + bool run_wizard = (wxDirExists(datadir) && wxFileExists(slic3r_ini)); + + /* Check to make sure if datadir exists */ + for (auto& dir : std::vector { enc_datadir, print_ini, printer_ini, material_ini }) { + if (wxDirExists(dir)) continue; + if (!wxMkdir(dir)) { + Slic3r::Log::fatal_error(LogChannel, (_("Slic3r was unable to create its data directory at ")+ dir).ToStdWstring()); + } + } // TODO: Call a logging function with channel GUI, severity info for datadir path + Slic3r::Log::info(LogChannel, (_("Data dir: ") + datadir).ToStdWstring()); + + if (wxFileExists(slic3r_ini)) { + /* + my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") }; + if ($ini) { + $last_version = $ini->{_}{version}; + $ini->{_}{$_} = $Settings->{_}{$_} + for grep !exists $ini->{_}{$_}, keys %{$Settings->{_}}; + $Settings = $ini; + } + delete $Settings->{_}{mode}; # handle legacy + */ + } - /* Check to make sure if datadir exists - * - */ - // Load settings this->gui_config->save_settings(); + + // Load presets this->load_presets(); wxImage::AddHandler(new wxPNGHandler()); MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize, this->gui_config); this->SetTopWindow(frame); - frame->Show( true ); // Load init bundle // @@ -56,7 +83,7 @@ bool App::OnInit() && (!$Settings->{_}{last_version_check} || (time - $Settings->{_}{last_version_check}) >= 86400); */ - // run callback functions during idle + // run callback functions during idle on the main frame /* EVT_IDLE($frame, sub { while (my $cb = shift @cb) { diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index 219970806..82c4b2082 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -36,6 +36,8 @@ private: void load_presets(); + wxString datadir {""}; + const std::string LogChannel {"GUI"}; //< Which log these messages should go to. }; }} // namespace Slic3r::GUI From c0d8e68606b9fbda4c576fd4e3dbb0e4c900d12d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 18:18:10 -0500 Subject: [PATCH 022/305] working on higher-level cpp Slic3r::Config that has a similar interface to the old Perl one. --- src/GUI/Settings.hpp | 7 ++++++- xs/src/libslic3r/Config.hpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 xs/src/libslic3r/Config.hpp diff --git a/src/GUI/Settings.hpp b/src/GUI/Settings.hpp index 9c135cec3..bc391ae87 100644 --- a/src/GUI/Settings.hpp +++ b/src/GUI/Settings.hpp @@ -25,7 +25,7 @@ enum class ReloadBehavior { }; /// Stub class to hold onto GUI-specific settings options. -/// TODO: Incorporate a copy of Slic3r::Config +/// TODO: Incorporate the system from libslic3r class Settings { public: bool show_host {false}; @@ -50,9 +50,14 @@ class Settings { const wxString version { wxString(SLIC3R_VERSION) }; void save_settings(); + void load_settings(); /// Storage for window positions std::map > window_pos { std::map >() }; + + private: + const std::string LogChannel {"GUI_Settings"}; //< Which log these messages should go to. + }; }} //namespace Slic3r::GUI diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp new file mode 100644 index 000000000..265cc2201 --- /dev/null +++ b/xs/src/libslic3r/Config.hpp @@ -0,0 +1,21 @@ +#ifndef CONFIG_HPP +#define CONFIG_HPP + +#include "PrintConfig.hpp" + +namespace Slic3r { + +class Config : DynamicPrintConfig { +public: + static Config *new_from_defaults(); + static Config *new_from_cli(const &argc, const char* argv[]); + + void write_ini(const std::string& file) { save(file); } + void read_ini(const std::string& file) { load(file); } + + +}; + +} // namespace Slic3r + +#endif // CONFIG_HPP From 47354beacc7e6b8bab07a3564ece53f800e939c3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 18:53:14 -0500 Subject: [PATCH 023/305] Added stdexcept include, convert VAR_ABS_PATH and VAR_REL to wxStrings. --- src/GUI/misc_ui.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index 8183ec020..c585117b9 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -3,6 +3,7 @@ #include #include +#include namespace Slic3r { namespace GUI { @@ -19,9 +20,9 @@ void check_version(bool manual) { const wxString var(const wxString& in) { // TODO replace center string with path to VAR in actual distribution later if (VAR_ABS) { - return VAR_ABS_PATH + "/" + in; + return wxString(VAR_ABS_PATH) + "/" + in; } else { - return bin() + VAR_REL + "/" + in; + return bin() + wxString(VAR_REL) + "/" + in; } } From ac24ab827e9d7b3bbffcd9a578872af3a6d64309 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 20:53:49 -0500 Subject: [PATCH 024/305] Add AboutDialog to GUI and menu. --- src/CMakeLists.txt | 3 +- src/GUI/AboutDialog.cpp | 98 +++++++++++++++++++++++++++++++++++++++++ src/GUI/AboutDialog.hpp | 41 +++++++++++++++++ src/GUI/MainFrame.cpp | 5 +++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 src/GUI/AboutDialog.cpp create mode 100644 src/GUI/AboutDialog.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9f1e0072f..187811c48 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -147,7 +147,7 @@ include_directories(${Boost_INCLUDE_DIRS}) set(wxWidgets_USE_STATIC OFF) set(wxWidgets_USE_UNICODE ON) -find_package(wxWidgets COMPONENTS base aui core) +find_package(wxWidgets COMPONENTS base aui core html) IF(CMAKE_HOST_UNIX) #set(Boost_LIBRARIES bsystem bthread bfilesystem) @@ -165,6 +165,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/Settings.cpp + ${GUI_LIBDIR}/AboutDialog.cpp ${GUI_LIBDIR}/misc_ui.cpp ) #only build GUI lib if building with wx diff --git a/src/GUI/AboutDialog.cpp b/src/GUI/AboutDialog.cpp new file mode 100644 index 000000000..91a7b224a --- /dev/null +++ b/src/GUI/AboutDialog.cpp @@ -0,0 +1,98 @@ +#include "AboutDialog.hpp" + +namespace Slic3r { namespace GUI { + +static void link_clicked(wxHtmlLinkEvent& e) +{ + wxLaunchDefaultBrowser(e.GetLinkInfo().GetHref()); + e.Skip(0); +} + +AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3r"), wxDefaultPosition, wxSize(600, 460), wxCAPTION) +{ + auto hsizer { new wxBoxSizer(wxHORIZONTAL) } ; + + auto vsizer { new wxBoxSizer(wxVERTICAL) } ; + + // logo + auto logo { new AboutDialogLogo(this) }; + hsizer->Add(logo, 0, wxEXPAND | wxLEFT | wxRIGHT, 30); + + // title + auto title { new wxStaticText(this, -1, "Slic3r", wxDefaultPosition, wxDefaultSize) }; + auto title_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; + + title_font.SetWeight(wxFONTWEIGHT_BOLD); + title_font.SetFamily(wxFONTFAMILY_ROMAN); + title_font.SetPointSize(24); + title->SetFont(title_font); + + vsizer->Add(title, 0, wxALIGN_LEFT | wxTOP, 30); + + // version + + auto version {new wxStaticText(this, -1, wxString("Version ") + wxString(SLIC3R_VERSION), wxDefaultPosition, wxDefaultSize) }; + auto version_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; + version_font.SetPointSize((the_os == OS::Windows ? 9 : 11)); + version->SetFont(version_font); + vsizer->Add(version, 0, wxALIGN_LEFT | wxBOTTOM, 10); + + // text + + wxString text {""}; + text << "" + << "" + << "Copyright © 2011-2017 Alessandro Ranellucci.
" + << "Slic3r is licensed under the " + << "GNU Affero General Public License, version 3." + << "


" + << "Contributions by Henrik Brix Andersen, Vojtech Bubnik, Nicolas Dandrimont, Mark Hindess, " + << "Petr Ledvina, Joseph Lenox, Y. Sapir, Mike Sheldrake, Kliment Yanev and numerous others. " + << "Manual by Gary Hodgson. Inspired by the RepRap community.
" + << "Slic3r logo designed by Corey Daniels, Silk Icon Set designed by Mark James. " + << "

" + << "Built on " << build_date << " at git version " << git_version << "." + << "" + << ""; + auto html {new wxHtmlWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_NEVER)}; + html->SetBorders(2); + html->SetPage(text); + + html->Bind(wxEVT_HTML_LINK_CLICKED, [=](wxHtmlLinkEvent& e){ link_clicked(e); }); + + vsizer->Add(html, 1, wxEXPAND | wxALIGN_LEFT | wxRIGHT | wxBOTTOM, 20); + // buttons + auto buttons = this->CreateStdDialogButtonSizer(wxOK); + this->SetEscapeId(wxID_CLOSE); + + vsizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3); + + hsizer->Add(vsizer, 1, wxEXPAND, 0); + this->SetSizer(hsizer); + + }; + +AboutDialogLogo::AboutDialogLogo(wxWindow* parent) : + wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize) +{ + this->logo = wxBitmap(var("Slic3r_192px.png"), wxBITMAP_TYPE_PNG); + this->SetMinSize(wxSize(this->logo.GetWidth(), this->logo.GetHeight())); + + this->Bind(wxEVT_PAINT, [=](wxPaintEvent& e) { this->repaint(e);}); +} + +void AboutDialogLogo::repaint(wxPaintEvent& event) +{ + auto dc { new wxPaintDC(this) }; + + dc->SetBackgroundMode(wxPENSTYLE_TRANSPARENT); + + const auto size {this->GetSize()}; + const auto logo_w {this->logo.GetWidth()}; + const auto logo_h {this->logo.GetHeight()}; + + dc->DrawBitmap(this->logo, (size.GetWidth() - logo_w) / 2, (size.GetHeight() - logo_h) / 2, 1); + event.Skip(); +} + +}} // namespace Slic3r::GUI diff --git a/src/GUI/AboutDialog.hpp b/src/GUI/AboutDialog.hpp new file mode 100644 index 000000000..40637a091 --- /dev/null +++ b/src/GUI/AboutDialog.hpp @@ -0,0 +1,41 @@ +#ifndef ABOUTDIALOG_HPP +#define ABOUTDIALOG_HPP +#include +#include +#include +#include +#include +#include +#include + +#include "libslic3r.h" +#include "misc_ui.hpp" + +#ifndef SLIC3R_BUILD_COMMIT +#define SLIC3R_BUILD_COMMIT "(Unknown revision)" +#endif + +namespace Slic3r { namespace GUI { + +const wxString build_date {__DATE__}; +const wxString git_version {SLIC3R_BUILD_COMMIT}; + +class AboutDialogLogo : public wxPanel { +private: + wxBitmap logo; +public: + AboutDialogLogo(wxWindow* parent); + void repaint(wxPaintEvent& event); +}; + +class AboutDialog : public wxDialog { +public: + /// Build and show the About popup. + AboutDialog(wxWindow* parent); +}; + + + +}} // namespace Slic3r::GUI + +#endif // ABOUTDIALOG_HPP diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index f006423b1..6c0221687 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -3,6 +3,8 @@ #include #include +#include "AboutDialog.hpp" + namespace Slic3r { namespace GUI { wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) @@ -151,6 +153,9 @@ void MainFrame::init_menubar() }); append_menu_item(menuHelp, _("&About Slic3r"), _("Show about dialog"), [=](wxCommandEvent& e) { + auto about = new AboutDialog(nullptr); + about->ShowModal(); + about->Destroy(); }, wxID_ABOUT); } From 8fb78ca5d7c229e2f210ee75d62dd5b08eaa0182 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 21:40:37 -0500 Subject: [PATCH 025/305] Spit out the result of git rev-parse --short HEAD in AboutDialog. --- src/CMakeLists.txt | 15 +++++++++++++++ src/GUI/AboutDialog.hpp | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 187811c48..db8ccfb80 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,12 @@ cmake_minimum_required (VERSION 3.9) project (slic3r) + # only on newer GCCs: -ftemplate-backtrace-limit=0 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") + +execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_VERSION) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -DSLIC3R_DEBUG") if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) @@ -158,6 +162,17 @@ target_link_libraries (slic3r libslic3r admesh BSpline clipper expat polypartiti IF(wxWidgets_FOUND) MESSAGE("wx found!") INCLUDE("${wxWidgets_USE_FILE}") + + if (NOT GIT_VERSION STREQUAL "") + if (MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DSLIC3R_BUILD_COMMIT=${GIT_VERSION} ") + else(MSVC) + execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_VERSION) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSLIC3R_BUILD_COMMIT=${GIT_VERSION}") + string(REGEX REPLACE "\n$" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + endif(MSVC) + endif(NOT GIT_VERSION STREQUAL "") + include_directories(${GUI_LIBDIR}) include_directories(${wxWidgets_INCLUDE}) diff --git a/src/GUI/AboutDialog.hpp b/src/GUI/AboutDialog.hpp index 40637a091..fea496b4a 100644 --- a/src/GUI/AboutDialog.hpp +++ b/src/GUI/AboutDialog.hpp @@ -11,14 +11,19 @@ #include "libslic3r.h" #include "misc_ui.hpp" + #ifndef SLIC3R_BUILD_COMMIT #define SLIC3R_BUILD_COMMIT "(Unknown revision)" #endif +#define VER1_(x) #x +#define VER_(x) VER1_(x) +#define BUILD_COMMIT VER_(SLIC3R_BUILD_COMMIT) + namespace Slic3r { namespace GUI { const wxString build_date {__DATE__}; -const wxString git_version {SLIC3R_BUILD_COMMIT}; +const wxString git_version {BUILD_COMMIT}; class AboutDialogLogo : public wxPanel { private: From 87b3f9582e38ab0de2d5bb1bbc210e98edb66f5e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 23:13:12 -0500 Subject: [PATCH 026/305] Ensure unknown revision still works. --- src/CMakeLists.txt | 2 +- src/GUI/AboutDialog.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index db8ccfb80..50e6870dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,7 @@ project (slic3r) # only on newer GCCs: -ftemplate-backtrace-limit=0 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") -execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_VERSION) +execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_VERSION ERROR_QUIET) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -DSLIC3R_DEBUG") diff --git a/src/GUI/AboutDialog.hpp b/src/GUI/AboutDialog.hpp index fea496b4a..f506cdfdd 100644 --- a/src/GUI/AboutDialog.hpp +++ b/src/GUI/AboutDialog.hpp @@ -13,7 +13,7 @@ #ifndef SLIC3R_BUILD_COMMIT -#define SLIC3R_BUILD_COMMIT "(Unknown revision)" +#define SLIC3R_BUILD_COMMIT (Unknown revision) #endif #define VER1_(x) #x From c2d10aeeedde22cb14d9e83360188ef74775ad41 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 23:37:27 -0500 Subject: [PATCH 027/305] Moved plater stubs to its own cpp --- src/CMakeLists.txt | 7 ++++--- src/GUI/Plater.cpp | 13 +++++++++++++ src/GUI/Plater.hpp | 9 ++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 src/GUI/Plater.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50e6870dc..1c4759fa1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -177,10 +177,11 @@ IF(wxWidgets_FOUND) include_directories(${wxWidgets_INCLUDE}) add_library(slic3r_gui STATIC - ${GUI_LIBDIR}/MainFrame.cpp - ${GUI_LIBDIR}/GUI.cpp - ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/AboutDialog.cpp + ${GUI_LIBDIR}/GUI.cpp + ${GUI_LIBDIR}/MainFrame.cpp + ${GUI_LIBDIR}/Plater.cpp + ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp ) #only build GUI lib if building with wx diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp new file mode 100644 index 000000000..57b4d1120 --- /dev/null +++ b/src/GUI/Plater.cpp @@ -0,0 +1,13 @@ +#include "Plater.hpp" + +namespace Slic3r { namespace GUI { + +Plater::Plater(wxWindow* parent, const wxString& title) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title) { } +void Plater::add() { + +} + + +}} // Namespace Slic3r::GUI + diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index bf7aa917a..7b0031519 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -1,14 +1,17 @@ #ifndef PLATER_HPP #define PLATER_HPP +#include +#ifndef WX_PRECOMP + #include +#endif namespace Slic3r { namespace GUI { class Plater : public wxPanel { public: - Plater(wxWindow* parent, const wxString& title) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title) - { } + Plater(wxWindow* parent, const wxString& title); + void add(); }; From ce77ade904f1e87a3fbe0dfe3fbee6f377ddf5d7 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 23:38:27 -0500 Subject: [PATCH 028/305] Added handling to deal with if the lambda function passed in is a nullptr type. --- src/GUI/misc_ui.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index d8586fec7..d40ab729c 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -9,6 +9,8 @@ #include #include +#include "Log.hpp" + /// Common static (that is, free-standing) functions, not part of an object hierarchy. namespace Slic3r { namespace GUI { @@ -82,7 +84,8 @@ void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T if (!icon.IsEmpty()) tmp->SetBitmap(wxBitmap(var(icon))); - menu->Bind(wxEVT_MENU, lambda, tmp->GetId(), tmp->GetId()); + if (typeid(lambda) != typeid(nullptr)) + menu->Bind(wxEVT_MENU, lambda, tmp->GetId(), tmp->GetId()); } /* From 72703ca0e83c583b97bd6a40ffeedfee26f371b3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 23:39:00 -0500 Subject: [PATCH 029/305] Added menu mechanism to load 3d models. --- src/GUI/MainFrame.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 6c0221687..83eb2a65a 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -118,6 +118,7 @@ void MainFrame::init_menubar() wxMenu* menuFile = new wxMenu(); { + append_menu_item(menuFile, _(L"Open STL/OBJ/AMF/3MF…"), _("Open a model"), [=](wxCommandEvent& e) { if (this->plater != nullptr) this->plater->add();}, wxID_ANY, "brick_add.png", "Ctrl+O"); } wxMenu* menuPlater = new wxMenu(); From 44944a9b7db7aadb5a7e9fed0428835eb1f257f5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 10:07:41 -0500 Subject: [PATCH 030/305] Move ZipArchive to its own library. --- src/CMakeLists.txt | 6 +++++- xs/src/{libslic3r => }/Zip/ZipArchive.cpp | 0 xs/src/{libslic3r => }/Zip/ZipArchive.hpp | 0 3 files changed, 5 insertions(+), 1 deletion(-) rename xs/src/{libslic3r => }/Zip/ZipArchive.cpp (100%) rename xs/src/{libslic3r => }/Zip/ZipArchive.hpp (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1c4759fa1..c5bea65c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,6 +44,11 @@ include_directories(${LIBDIR}/poly2tri/) include_directories(${LIBDIR}/poly2tri/sweep) include_directories(${LIBDIR}/poly2tri/common) +add_library(ZipArchive STATIC + ${LIBDIR}/Zip/ZipArchive.cpp +) + + add_library(libslic3r STATIC ${LIBDIR}/libslic3r/BoundingBox.cpp ${LIBDIR}/libslic3r/BridgeDetector.cpp @@ -97,7 +102,6 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/SurfaceCollection.cpp ${LIBDIR}/libslic3r/SVG.cpp ${LIBDIR}/libslic3r/TriangleMesh.cpp - ${LIBDIR}/libslic3r/Zip/ZipArchive.cpp ) add_library(BSpline STATIC diff --git a/xs/src/libslic3r/Zip/ZipArchive.cpp b/xs/src/Zip/ZipArchive.cpp similarity index 100% rename from xs/src/libslic3r/Zip/ZipArchive.cpp rename to xs/src/Zip/ZipArchive.cpp diff --git a/xs/src/libslic3r/Zip/ZipArchive.hpp b/xs/src/Zip/ZipArchive.hpp similarity index 100% rename from xs/src/libslic3r/Zip/ZipArchive.hpp rename to xs/src/Zip/ZipArchive.hpp From bd6fe7114a1c71a5bea09807cecae10669b236c0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 10:08:10 -0500 Subject: [PATCH 031/305] Be more selective in what is compiled with C++11. --- src/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c5bea65c1..a28bb833f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,7 @@ project (slic3r) # only on newer GCCs: -ftemplate-backtrace-limit=0 -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_VERSION ERROR_QUIET) @@ -103,6 +103,7 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/SVG.cpp ${LIBDIR}/libslic3r/TriangleMesh.cpp ) +target_compile_features(libslic3r PUBLIC cxx_std_11) add_library(BSpline STATIC ${LIBDIR}/BSpline/BSpline.cpp @@ -188,6 +189,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp ) + target_compile_features(slic3r_gui PUBLIC cxx_std_11) #only build GUI lib if building with wx target_link_libraries (slic3r slic3r_gui ${wxWidgets_LIBRARIES}) ELSE(wxWidgets_FOUND) From 3fda71e5ddc114f94fa0d7cc63fea723f6bd071d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 10:08:38 -0500 Subject: [PATCH 032/305] Move slic3r_gui link higher in the chain (as it relies on libslic3r). --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a28bb833f..e1190ee54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -162,7 +162,6 @@ IF(CMAKE_HOST_UNIX) #set(Boost_LIBRARIES bsystem bthread bfilesystem) ENDIF(CMAKE_HOST_UNIX) -target_link_libraries (slic3r libslic3r admesh BSpline clipper expat polypartition poly2tri ${Boost_LIBRARIES}) IF(wxWidgets_FOUND) MESSAGE("wx found!") @@ -198,6 +197,8 @@ ELSE(wxWidgets_FOUND) #skip gui when no wx included ENDIF(wxWidgets_FOUND) +target_link_libraries (slic3r libslic3r admesh BSpline clipper expat polypartition poly2tri ZipArchive ${Boost_LIBRARIES}) + # Windows needs a compiled component for Boost.nowide IF (WIN32) add_library(boost-nowide STATIC From 31ed51de00505dddec98a2c3762f341cfd135818 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 10:13:00 -0500 Subject: [PATCH 033/305] added descriptive comment to GUI --- src/GUI/GUI.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index 690f07284..9370e4afe 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -48,6 +48,7 @@ bool App::OnInit() // TODO: Call a logging function with channel GUI, severity info for datadir path Slic3r::Log::info(LogChannel, (_("Data dir: ") + datadir).ToStdWstring()); + // Load gui settings from slic3r.ini if (wxFileExists(slic3r_ini)) { /* my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") }; From 48b13aa1c78928d775c8773753fa46a6fbcbaf3b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 10:13:39 -0500 Subject: [PATCH 034/305] Stubbed Plater constructor. --- src/GUI/Plater.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++- src/GUI/Plater.hpp | 34 +++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 57b4d1120..ad887cf41 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -3,7 +3,96 @@ namespace Slic3r { namespace GUI { Plater::Plater(wxWindow* parent, const wxString& title) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title) { } + wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title), + print(Slic3r::Print()) +{ + + auto on_select_object { [=](uint32_t& obj_idx) { + // this->select_object(obj_idx); + } }; + /* + # Initialize handlers for canvases + my $on_select_object = sub { + my ($obj_idx) = @_; + $self->select_object($obj_idx); + }; + my $on_double_click = sub { + $self->object_settings_dialog if $self->selected_object; + }; + my $on_right_click = sub { + my ($canvas, $click_pos) = @_; + + my ($obj_idx, $object) = $self->selected_object; + return if !defined $obj_idx; + + my $menu = $self->object_menu; + $canvas->PopupMenu($menu, $click_pos); + $menu->Destroy; + }; + my $on_instances_moved = sub { + $self->on_model_change; + }; + # Initialize 3D plater + if ($Slic3r::GUI::have_OpenGL) { + $self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{config}); + $self->{preview_notebook}->AddPage($self->{canvas3D}, '3D'); + $self->{canvas3D}->set_on_select_object($on_select_object); + $self->{canvas3D}->set_on_double_click($on_double_click); + $self->{canvas3D}->set_on_right_click(sub { $on_right_click->($self->{canvas3D}, @_); }); + $self->{canvas3D}->set_on_instances_moved($on_instances_moved); + $self->{canvas3D}->on_viewport_changed(sub { + $self->{preview3D}->canvas->set_viewport_from_scene($self->{canvas3D}); + }); + } + # Initialize 2D preview canvas + $self->{canvas} = Slic3r::GUI::Plater::2D->new($self->{preview_notebook}, wxDefaultSize, $self->{objects}, $self->{model}, $self->{config}); + $self->{preview_notebook}->AddPage($self->{canvas}, '2D'); + $self->{canvas}->on_select_object($on_select_object); + $self->{canvas}->on_double_click($on_double_click); + $self->{canvas}->on_right_click(sub { $on_right_click->($self->{canvas}, @_); }); + $self->{canvas}->on_instances_moved($on_instances_moved); + + # Initialize 3D toolpaths preview + $self->{preview3D_page_idx} = -1; + if ($Slic3r::GUI::have_OpenGL) { + $self->{preview3D} = Slic3r::GUI::Plater::3DPreview->new($self->{preview_notebook}, $self->{print}); + $self->{preview3D}->canvas->on_viewport_changed(sub { + $self->{canvas3D}->set_viewport_from_scene($self->{preview3D}->canvas); + }); + $self->{preview_notebook}->AddPage($self->{preview3D}, 'Preview'); + $self->{preview3D_page_idx} = $self->{preview_notebook}->GetPageCount-1; + } + + # Initialize toolpaths preview + $self->{toolpaths2D_page_idx} = -1; + if ($Slic3r::GUI::have_OpenGL) { + $self->{toolpaths2D} = Slic3r::GUI::Plater::2DToolpaths->new($self->{preview_notebook}, $self->{print}); + $self->{preview_notebook}->AddPage($self->{toolpaths2D}, 'Layers'); + $self->{toolpaths2D_page_idx} = $self->{preview_notebook}->GetPageCount-1; + } + + EVT_NOTEBOOK_PAGE_CHANGED($self, $self->{preview_notebook}, sub { + wxTheApp->CallAfter(sub { + my $sel = $self->{preview_notebook}->GetSelection; + if ($sel == $self->{preview3D_page_idx} || $sel == $self->{toolpaths2D_page_idx}) { + if (!$Slic3r::GUI::Settings->{_}{background_processing} && !$self->{processed}) { + $self->statusbar->SetCancelCallback(sub { + $self->stop_background_process; + $self->statusbar->SetStatusText("Slicing cancelled"); + $self->{preview_notebook}->SetSelection(0); + + }); + $self->start_background_process; + } else { + $self->{preview3D}->load_print + if $sel == $self->{preview3D_page_idx}; + } + } + }); + }); + */ + +} void Plater::add() { } diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 7b0031519..a22d7acf6 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -5,14 +5,48 @@ #include #endif +#include + +#include + +#include "libslic3r.h" +#include "Model.hpp" +#include "Print.hpp" + namespace Slic3r { namespace GUI { +using UndoOperation = int; + +class Plater2DObject; + class Plater : public wxPanel { public: Plater(wxWindow* parent, const wxString& title); void add(); +private: + Print print; + Model model; + + bool processed {false}; + + std::vector objects; + + std::stack undo {}; + std::stack redo {}; + + wxNotebook* preview_notebook {new wxNotebook(this, -1, wxDefaultPosition, wxSize(335,335), wxNB_BOTTOM)}; + +}; + + +// 2D Preview of an object +class Plater2DObject { +public: + std::string name {""}; + std::string identifier {""}; + bool selected {false}; }; } } // Namespace Slic3r::GUI From d02516d8fed66b357e57d5f10120ed2669cfc771 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 12:14:03 -0500 Subject: [PATCH 035/305] Added factory function for new_from_defaults. Stubbed out new_from_cli. --- src/CMakeLists.txt | 1 + xs/src/libslic3r/Config.cpp | 31 +++++++++++++++++++++++++++++++ xs/src/libslic3r/Config.hpp | 10 ++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 xs/src/libslic3r/Config.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e1190ee54..12ac4a3b3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/BridgeDetector.cpp ${LIBDIR}/libslic3r/ClipperUtils.cpp ${LIBDIR}/libslic3r/ConfigBase.cpp + ${LIBDIR}/libslic3r/Config.cpp ${LIBDIR}/libslic3r/ExPolygon.cpp ${LIBDIR}/libslic3r/ExPolygonCollection.cpp ${LIBDIR}/libslic3r/Extruder.cpp diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp new file mode 100644 index 000000000..d9f99cbbc --- /dev/null +++ b/xs/src/libslic3r/Config.cpp @@ -0,0 +1,31 @@ +#include "Config.hpp" +#include "Log.hpp" + +namespace Slic3r { + +std::shared_ptr +Config::new_from_defaults() +{ + return std::make_shared(); +} +std::shared_ptr +Config::new_from_defaults(std::initializer_list init) +{ + auto my_config(std::make_shared()); + for (auto& opt_key : init) { + if (print_config_def.has(opt_key)) { + const std::string value { print_config_def.get(opt_key)->default_value->serialize() }; + my_config->set_deserialize(opt_key, value); + } + } + + return my_config; +} + +std::shared_ptr +new_from_cli(const int& argc, const char* argv[]) +{ + return std::make_shared(); +} + +} // namespace Slic3r diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 265cc2201..118309033 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -1,19 +1,21 @@ #ifndef CONFIG_HPP #define CONFIG_HPP +#include +#include + #include "PrintConfig.hpp" namespace Slic3r { class Config : DynamicPrintConfig { public: - static Config *new_from_defaults(); - static Config *new_from_cli(const &argc, const char* argv[]); + static std::shared_ptr new_from_defaults(); + static std::shared_ptr new_from_defaults(std::initializer_list init); + static std::shared_ptr new_from_cli(const int& argc, const char* argv[]); void write_ini(const std::string& file) { save(file); } void read_ini(const std::string& file) { load(file); } - - }; } // namespace Slic3r From d07aaa87fdd9579c49292081f7175733c566371b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 12:16:31 -0500 Subject: [PATCH 036/305] Further implementation of Plater and Plater2D. --- src/CMakeLists.txt | 1 + src/GUI/Plater.cpp | 19 +++++++++++++++---- src/GUI/Plater.hpp | 24 ++++++++++++++---------- src/GUI/Plater/Plate2D.cpp | 0 src/GUI/Plater/Plate2D.hpp | 25 +++++++++++++++++++++++++ src/GUI/Plater/Plater2DObject.hpp | 13 +++++++++++++ 6 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 src/GUI/Plater/Plate2D.cpp create mode 100644 src/GUI/Plater/Plate2D.hpp create mode 100644 src/GUI/Plater/Plater2DObject.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12ac4a3b3..361074ea3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -186,6 +186,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/Plater.cpp + ${GUI_LIBDIR}/Plater/Plate2D.cpp ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp ) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index ad887cf41..75d6fee1d 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -1,12 +1,20 @@ #include "Plater.hpp" +#include "Log.hpp" namespace Slic3r { namespace GUI { +const auto PROGRESS_BAR_EVENT = wxNewEventType(); + Plater::Plater(wxWindow* parent, const wxString& title) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title), - print(Slic3r::Print()) + wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title) { + // Set callback for status event for worker threads + /* + this->print->set_status_cb([=](std::string percent percent, std::wstring message) { + wxPostEvent(this, new wxPlThreadEvent(-1, PROGRESS_BAR_EVENT, + }); + */ auto on_select_object { [=](uint32_t& obj_idx) { // this->select_object(obj_idx); } }; @@ -44,6 +52,10 @@ Plater::Plater(wxWindow* parent, const wxString& title) : $self->{preview3D}->canvas->set_viewport_from_scene($self->{canvas3D}); }); } + */ + canvas2D = new Plate2D(preview_notebook, wxDefaultSize, objects, model, config); + + /* # Initialize 2D preview canvas $self->{canvas} = Slic3r::GUI::Plater::2D->new($self->{preview_notebook}, wxDefaultSize, $self->{objects}, $self->{model}, $self->{config}); $self->{preview_notebook}->AddPage($self->{canvas}, '2D'); @@ -51,7 +63,6 @@ Plater::Plater(wxWindow* parent, const wxString& title) : $self->{canvas}->on_double_click($on_double_click); $self->{canvas}->on_right_click(sub { $on_right_click->($self->{canvas}, @_); }); $self->{canvas}->on_instances_moved($on_instances_moved); - # Initialize 3D toolpaths preview $self->{preview3D_page_idx} = -1; if ($Slic3r::GUI::have_OpenGL) { @@ -94,7 +105,7 @@ Plater::Plater(wxWindow* parent, const wxString& title) : } void Plater::add() { - + Log::info("GUI", L"Called Add function"); } diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index a22d7acf6..f0c4569f3 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -12,6 +12,10 @@ #include "libslic3r.h" #include "Model.hpp" #include "Print.hpp" +#include "Config.hpp" + +#include "Plater/Plater2DObject.hpp" +#include "Plater/Plate2D.hpp" namespace Slic3r { namespace GUI { @@ -26,28 +30,28 @@ public: void add(); private: - Print print; - Model model; + std::shared_ptr print {std::make_shared(Slic3r::Print())}; + std::shared_ptr model {std::make_shared(Slic3r::Model())}; + + std::shared_ptr config { Slic3r::Config::new_from_defaults( + {"bed_shape", "complete_objects", "extruder_clearance_radius", "skirts", "skirt_distance", + "brim_width", "serial_port", "serial_speed", "host_type", "print_host", "octoprint_apikey", + "shortcuts", "filament_colour"})}; bool processed {false}; - std::vector objects; + std::vector objects {}; std::stack undo {}; std::stack redo {}; wxNotebook* preview_notebook {new wxNotebook(this, -1, wxDefaultPosition, wxSize(335,335), wxNB_BOTTOM)}; + Plate2D* canvas2D {}; + }; -// 2D Preview of an object -class Plater2DObject { -public: - std::string name {""}; - std::string identifier {""}; - bool selected {false}; -}; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp new file mode 100644 index 000000000..306d5cba1 --- /dev/null +++ b/src/GUI/Plater/Plate2D.hpp @@ -0,0 +1,25 @@ +#ifndef PLATE2D_HPP +#define PLATE2D_HPP +#include +#ifndef WX_PRECOMP + #include +#endif +#include +#include "Plater.hpp" +#include "Plater/Plater2DObject.hpp" + + +namespace Slic3r { namespace GUI { + +class Plate2D : public wxPanel { +public: + Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) { } +private: + std::vector& objects; + std::shared_ptr model; + std::shared_ptr config; +}; + +} } // Namespace Slic3r::GUI +#endif // PLATE2D_HPP diff --git a/src/GUI/Plater/Plater2DObject.hpp b/src/GUI/Plater/Plater2DObject.hpp new file mode 100644 index 000000000..3a1772cfb --- /dev/null +++ b/src/GUI/Plater/Plater2DObject.hpp @@ -0,0 +1,13 @@ +#ifndef PLATER2DOBJECT_HPP +#define PLATER2DOBJECT_HPP + +namespace Slic3r { namespace GUI { +// 2D Preview of an object +class Plater2DObject { +public: + std::string name {""}; + std::string identifier {""}; + bool selected {false}; +}; +} } // Namespace Slic3r::GUI +#endif From 1d1d9ba6a8acdd1b506b5853141ad4dead39c51e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 12:46:58 -0500 Subject: [PATCH 037/305] Trying to use gcc 7 for slic3r --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 738368ffc..6947794f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,8 @@ addons: sources: - ubuntu-toolchain-r-test packages: - - g++-4.9 - - gcc-4.9 + - g++-7.3.0 + - gcc-7.3.0 - libgtk2.0-0 - libgtk2.0-dev - freeglut3 From 1cbc72f1263715cce9994d94fafd564616850eb9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 12:48:07 -0500 Subject: [PATCH 038/305] Trying to use gcc 7 for slic3r --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6947794f3..6c4649418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,8 @@ addons: sources: - ubuntu-toolchain-r-test packages: - - g++-7.3.0 - - gcc-7.3.0 + - g++-7.3 + - gcc-7.3 - libgtk2.0-0 - libgtk2.0-dev - freeglut3 From d01c5f93e0ae0d3b558e074ba82fdbc0fccb27d6 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 12:49:42 -0500 Subject: [PATCH 039/305] Trying to use gcc 7 for slic3r --- .travis.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c4649418..8196536c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -language: perl +language: c++ before_install: - sh package/linux/travis-decrypt-key install: @@ -6,14 +6,11 @@ install: - export SLIC3R_STATIC=1 - export CXX=g++-4.9 - export CC=gcc-4.9 -- source $HOME/perl5/perlbrew/etc/bashrc script: - bash package/linux/travis-setup.sh -- perlbrew switch slic3r-perl - cmake -DBOOST_ROOT=$BOOST_DIR src/ - make after_success: -- eval $(perl -Mlocal::lib=$TRAVIS_BUILD_DIR/local-lib) - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 - package/linux/appimage.sh x86_64 - package/deploy/sftp.sh linux ~/slic3r-upload.rsa *.bz2 Slic3r*.AppImage @@ -33,8 +30,8 @@ addons: sources: - ubuntu-toolchain-r-test packages: - - g++-7.3 - - gcc-7.3 + - g++-6.3 + - gcc-6.3 - libgtk2.0-0 - libgtk2.0-dev - freeglut3 From d33ad951757cf9e485c71a6d2f413ce897063527 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 12:50:44 -0500 Subject: [PATCH 040/305] Trying to use gcc 7 for slic3r --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8196536c3..c861f7e9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,8 +30,8 @@ addons: sources: - ubuntu-toolchain-r-test packages: - - g++-6.3 - - gcc-6.3 + - g++-7 + - gcc-7 - libgtk2.0-0 - libgtk2.0-dev - freeglut3 From 108fc93fce48f9ae93f4cf4574f94f7e9aed1b33 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 12:56:17 -0500 Subject: [PATCH 041/305] Tweaks; removing perl deps from travis. --- .travis.yml | 4 ++-- package/linux/travis-setup.sh | 12 ------------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index c861f7e9e..34940401f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ before_install: install: - export BOOST_DIR=$HOME/boost_1_63_0 - export SLIC3R_STATIC=1 -- export CXX=g++-4.9 -- export CC=gcc-4.9 +- export CXX=g++-7 +- export CC=gcc-7 script: - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR src/ diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index 3c9f55ecf..3a0493606 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -4,27 +4,15 @@ WXVERSION=302 CACHE=$HOME/cache mkdir -p $CACHE -if [ ! -e $CACHE/slic3r-perlbrew-5.24.tar.bz2 ]; then - echo "Downloading http://www.siusgs.com/slic3r/buildserver/slic3r-perl.524.travis.tar.bz2 => $CACHE/slic3r-perlbrew-5.24.tar.bz2" - curl -L "http://www.siusgs.com/slic3r/buildserver/slic3r-perl.524.travis.tar.bz2" -o $CACHE/slic3r-perlbrew-5.24.tar.bz2; -fi - if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 fi -if [ ! -e $CACHE/local-lib-wx${WXVERSION}.tar.bz2 ]; then - echo "Downloading http://www.siusgs.com/slic3r/buildserver/slic3r-dependencies.travis-wx${WXVERSION}.tar.bz2 => $CACHE/local-lib-wx${WXVERSION}.tar.bz2" - curl -L "http://www.siusgs.com/slic3r/buildserver/slic3r-dependencies.travis-wx${WXVERSION}.tar.bz2" -o $CACHE/local-lib-wx${WXVERSION}.tar.bz2 -fi - if [ ! -e $CACHE/wx${WXVERSION}.tar.bz2 ]; then echo "Downloading http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2 => $CACHE/wx${WXVERSION}.tar.bz2" curl -L "http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2" -o $CACHE/wx${WXVERSION}.tar.bz2 fi -tar -C$TRAVIS_BUILD_DIR -xjf $CACHE/local-lib-wx${WXVERSION}.tar.bz2 -tar -C$HOME/perl5/perlbrew/perls -xjf $CACHE/slic3r-perlbrew-5.24.tar.bz2 tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 From 197b4f265f821c4d045de18a53092576b80d07e1 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 14:38:56 -0500 Subject: [PATCH 042/305] Stubbed out Solarized, added ColorScheme for default (needed for plater) --- src/GUI/ColorScheme.hpp | 11 ++++++ src/GUI/ColorScheme/ColorSchemeBase.hpp | 47 +++++++++++++++++++++++++ src/GUI/ColorScheme/Default.hpp | 47 +++++++++++++++++++++++++ src/GUI/ColorScheme/Solarized.hpp | 44 +++++++++++++++++++++++ src/GUI/Settings.hpp | 7 ++-- 5 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 src/GUI/ColorScheme.hpp create mode 100644 src/GUI/ColorScheme/ColorSchemeBase.hpp create mode 100644 src/GUI/ColorScheme/Default.hpp create mode 100644 src/GUI/ColorScheme/Solarized.hpp diff --git a/src/GUI/ColorScheme.hpp b/src/GUI/ColorScheme.hpp new file mode 100644 index 000000000..b0410a501 --- /dev/null +++ b/src/GUI/ColorScheme.hpp @@ -0,0 +1,11 @@ +#ifndef COLORSCHEME_HPP +#define COLORSCHEME_HPP + +/// Wrapper file to make the color schemes available to using applications +/// without the circular include headaches. + +#include "ColorScheme/ColorSchemeBase.hpp" +#include "ColorScheme/Default.hpp" +#include "ColorScheme/Solarized.hpp" + +#endif diff --git a/src/GUI/ColorScheme/ColorSchemeBase.hpp b/src/GUI/ColorScheme/ColorSchemeBase.hpp new file mode 100644 index 000000000..decac8d5d --- /dev/null +++ b/src/GUI/ColorScheme/ColorSchemeBase.hpp @@ -0,0 +1,47 @@ +#ifndef COLOR_SLIC3R_HPP +#define COLOR_SLIC3R_HPP + +namespace Slic3r { namespace GUI { + +class ColorScheme { +public: + virtual const std::string name() const = 0; + virtual const bool SOLID_BACKGROUNDCOLOR() const = 0; + virtual const wxColour SELECTED_COLOR() const = 0; + virtual const wxColour HOVER_COLOR() const = 0; + virtual const wxColour TOP_COLOR() const = 0; + virtual const wxColour BOTTOM_COLOR() const = 0; + virtual const wxColour BACKGROUND_COLOR() const = 0; + virtual const wxColour GRID_COLOR() const = 0; + virtual const wxColour GROUND_COLOR() const = 0; + virtual const wxColour COLOR_CUTPLANE() const = 0; + virtual const wxColour COLOR_PARTS() const = 0; + virtual const wxColour COLOR_INFILL() const = 0; + virtual const wxColour COLOR_SUPPORT() const = 0; + virtual const wxColour COLOR_UNKNOWN() const = 0; + virtual const wxColour BED_COLOR() const = 0; + virtual const wxColour BED_GRID() const = 0; + virtual const wxColour BED_SELECTED() const = 0; + virtual const wxColour BED_OBJECTS() const = 0; + virtual const wxColour BED_INSTANCE() const = 0; + virtual const wxColour BED_DRAGGED() const = 0; + virtual const wxColour BED_CENTER() const = 0; + virtual const wxColour BED_SKIRT() const = 0; + virtual const wxColour BED_CLEARANCE() const = 0; + virtual const wxColour BACKGROUND255() const = 0; + virtual const wxColour TOOL_DARK() const = 0; + virtual const wxColour TOOL_SUPPORT() const = 0; + virtual const wxColour TOOL_INFILL() const = 0; + virtual const wxColour TOOL_STEPPERIM() const = 0; + virtual const wxColour TOOL_SHADE() const = 0; + virtual const wxColour TOOL_COLOR() const = 0; + virtual const wxColour SPLINE_L_PEN() const = 0; + virtual const wxColour SPLINE_O_PEN() const = 0; + virtual const wxColour SPLINE_I_PEN() const = 0; + virtual const wxColour SPLINE_R_PEN() const = 0; + virtual const wxColour BED_DARK() const = 0; +}; + +}} // namespace Slic3r::GUI + +#endif diff --git a/src/GUI/ColorScheme/Default.hpp b/src/GUI/ColorScheme/Default.hpp new file mode 100644 index 000000000..47fd951e6 --- /dev/null +++ b/src/GUI/ColorScheme/Default.hpp @@ -0,0 +1,47 @@ +#ifndef COLOR_DEFAULT_HPP +#define COLOR_DEFAULT_HPP + +namespace Slic3r { namespace GUI { + +class DefaultColor : public ColorScheme { +public: + const std::string name() const { return "Default"; } + const bool SOLID_BACKGROUNDCOLOR() const { return false; }; + const wxColour SELECTED_COLOR() const { return wxColour(0, 1, 0); }; + const wxColour HOVER_COLOR() const { return wxColour(0.4, 0.9, 0); }; // + +#include "ColorScheme/ColorSchemeBase.hpp" + +namespace Slic3r { namespace GUI { + +/// S O L A R I Z E +/// http://ethanschoonover.com/solarized +/// +/// Implements a colorscheme lookup of wxColors +class Solarized : public ColorScheme { +public: + const wxColour SELECTED_COLOR() { return COLOR_MAGENTA; } + const wxColour HOVER_COLOR() { return COLOR_VIOLET; } + const wxColour SUPPORT_COLOR() { return COLOR_VIOLET; } + + const wxColour BACKGROUND_COLOR() { return COLOR_BASE3; } + + +private: + const wxColour COLOR_BASE0 {wxColour(0.51373,0.58039,0.58824)}; + const wxColour COLOR_BASE00 {wxColour(0.39608,0.48235,0.51373)}; + const wxColour COLOR_BASE01 {wxColour(0.34510,0.43137,0.45882)}; + const wxColour COLOR_BASE02 {wxColour(0.02745,0.21176,0.25882)}; + const wxColour COLOR_BASE03 {wxColour(0.00000,0.16863,0.21176)}; + const wxColour COLOR_BASE1 {wxColour(0.57647,0.63137,0.63137)}; + const wxColour COLOR_BASE2 {wxColour(0.93333,0.90980,0.83529)}; + const wxColour COLOR_BASE3 {wxColour(0.99216,0.96471,0.89020)}; + const wxColour COLOR_BLUE {wxColour(0.14902,0.54510,0.82353)}; + const wxColour COLOR_CYAN {wxColour(0.16471,0.63137,0.59608)}; + const wxColour COLOR_GREEN {wxColour(0.52157,0.60000,0.00000)}; + const wxColour COLOR_MAGENTA {wxColour(0.82745,0.21176,0.50980)}; + const wxColour COLOR_ORANGE {wxColour(0.79608,0.29412,0.08627)}; + const wxColour COLOR_RED {wxColour(0.86275,0.19608,0.18431)}; + const wxColour COLOR_VIOLET {wxColour(0.42353,0.44314,0.76863)}; + const wxColour COLOR_YELLOW {wxColour(0.70980,0.53725,0.00000)}; + +}; +}} // namespace Slic3r::GUI + + +#endif // SOLARIZED_HPP diff --git a/src/GUI/Settings.hpp b/src/GUI/Settings.hpp index bc391ae87..c74383084 100644 --- a/src/GUI/Settings.hpp +++ b/src/GUI/Settings.hpp @@ -9,6 +9,7 @@ #include #include "libslic3r.h" +#include "ColorScheme.hpp" namespace Slic3r { namespace GUI { @@ -16,10 +17,6 @@ enum class PathColor { role }; -enum class ColorScheme { - solarized, slic3r -}; - enum class ReloadBehavior { all, copy, discard }; @@ -40,7 +37,7 @@ class Settings { bool hide_reload_dialog {false}; ReloadBehavior reload {ReloadBehavior::all}; - ColorScheme color {ColorScheme::slic3r}; + std::unique_ptr color {new Slic3r::GUI::DefaultColor}; PathColor color_toolpaths_by {PathColor::role}; float nudge {1.0}; //< 2D plater nudge amount in mm From 7126d13850bd55f4b4d457466cb7434640d669ad Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 14:40:15 -0500 Subject: [PATCH 043/305] Push Settings down so it's available to the plater (for color choices, etc). --- src/GUI/MainFrame.cpp | 6 +++--- src/GUI/MainFrame.hpp | 2 +- src/GUI/Plater.cpp | 8 +++++--- src/GUI/Plater.hpp | 5 ++++- src/GUI/Plater/Plate2D.cpp | 12 ++++++++++++ src/GUI/Plater/Plate2D.hpp | 8 ++++++-- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 83eb2a65a..8c1d3c0e4 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -12,9 +12,9 @@ wxEND_EVENT_TABLE() MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : MainFrame(title, pos, size, nullptr) {} -MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr config) +MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr _gui_config) : wxFrame(NULL, wxID_ANY, title, pos, size), loaded(false), - tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(config), preset_editor_tabs(std::map()) + tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(_gui_config), preset_editor_tabs(std::map()) { // Set icon to either the .ico if windows or png for everything else. if (the_os == OS::Windows) @@ -105,7 +105,7 @@ void MainFrame::init_tabpanel() wxTheApp->CallAfter([=] { this->tabpanel->SetSelection(0); }); }), panel->GetId()); - this->plater = new Slic3r::GUI::Plater(panel, _("Plater")); + this->plater = new Slic3r::GUI::Plater(panel, _("Plater"), gui_config); this->controller = new Slic3r::GUI::Controller(panel, _("Controller")); panel->AddPage(this->plater, this->plater->GetName()); diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index 085cc3922..b067c6f9b 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -28,7 +28,7 @@ class MainFrame: public wxFrame { public: MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size); - MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr gui_config); + MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr _gui_config); private: wxDECLARE_EVENT_TABLE(); diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 75d6fee1d..2fb6d323d 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -1,3 +1,5 @@ +#include + #include "Plater.hpp" #include "Log.hpp" @@ -5,8 +7,8 @@ namespace Slic3r { namespace GUI { const auto PROGRESS_BAR_EVENT = wxNewEventType(); -Plater::Plater(wxWindow* parent, const wxString& title) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title) +Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title), settings(_settings) { // Set callback for status event for worker threads @@ -53,7 +55,7 @@ Plater::Plater(wxWindow* parent, const wxString& title) : }); } */ - canvas2D = new Plate2D(preview_notebook, wxDefaultSize, objects, model, config); + canvas2D = new Plate2D(preview_notebook, wxDefaultSize, objects, model, config, settings); /* # Initialize 2D preview canvas diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index f0c4569f3..e37448fdd 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -16,22 +16,25 @@ #include "Plater/Plater2DObject.hpp" #include "Plater/Plate2D.hpp" +#include "Settings.hpp" namespace Slic3r { namespace GUI { using UndoOperation = int; class Plater2DObject; +class Plate2D; class Plater : public wxPanel { public: - Plater(wxWindow* parent, const wxString& title); + Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings); void add(); private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; + std::shared_ptr settings {}; std::shared_ptr config { Slic3r::Config::new_from_defaults( {"bed_shape", "complete_objects", "extruder_clearance_radius", "skirts", "skirt_distance", diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index e69de29bb..c5015b5d2 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -0,0 +1,12 @@ +#include "Plater/Plate2D.hpp" + +#include + +namespace Slic3r { namespace GUI { + +Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) +{ +} + +} } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 306d5cba1..3c82f1a10 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -6,6 +6,8 @@ #endif #include #include "Plater.hpp" +#include "ColorScheme.hpp" +#include "Settings.hpp" #include "Plater/Plater2DObject.hpp" @@ -13,12 +15,14 @@ namespace Slic3r { namespace GUI { class Plate2D : public wxPanel { public: - Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) { } + Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); private: std::vector& objects; std::shared_ptr model; std::shared_ptr config; + std::shared_ptr settings; + + wxBrush objects_brush {}; }; } } // Namespace Slic3r::GUI From 1548066318e52c86c832d168a3e3398f8d2a7766 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 18:02:48 -0500 Subject: [PATCH 044/305] Staged the 2D plater on its tab. --- src/GUI/Plater.cpp | 1 + src/GUI/Plater/Plate2D.cpp | 58 ++++++++++++++++++++++++++++++++++++++ src/GUI/Plater/Plate2D.hpp | 31 ++++++++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 2fb6d323d..fa8b596c1 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -56,6 +56,7 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrAddPage(canvas2D, _("2D")); /* # Initialize 2D preview canvas diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index c5015b5d2..13ebb43f6 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -1,4 +1,5 @@ #include "Plater/Plate2D.hpp" +#include "Log.hpp" #include @@ -7,6 +8,63 @@ namespace Slic3r { namespace GUI { Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) { + + this->Bind(wxEVT_PAINT, [=](wxPaintEvent &e) { this->repaint(e); }); + this->Bind(wxEVT_MOTION, [=](wxMouseEvent &e) { this->mouse_drag(e); }); + if (user_drawn_background) { + this->Bind(wxEVT_ERASE_BACKGROUND, [=](wxEraseEvent& e){ }); + } + + // Bind the varying mouse events + + // Set the brushes + set_colors(); +} + +void Plate2D::repaint(wxPaintEvent& e) { +} + +void Plate2D::mouse_drag(wxMouseEvent& e) { + if (e.Dragging()) { + Slic3r::Log::info(LogChannel, L"Mouse dragging"); + } else { + Slic3r::Log::info(LogChannel, L"Mouse moving"); + } +} + +void Plate2D::set_colors() { + + this->SetBackgroundColour(settings->color->BACKGROUND255()); + + this->objects_brush.SetColour(settings->color->BED_OBJECTS()); + this->objects_brush.SetStyle(wxBRUSHSTYLE_SOLID); + this->instance_brush.SetColour(settings->color->BED_INSTANCE()); + this->instance_brush.SetStyle(wxBRUSHSTYLE_SOLID); + this->selected_brush.SetColour(settings->color->BED_SELECTED()); + this->selected_brush.SetStyle(wxBRUSHSTYLE_SOLID); + this->dragged_brush.SetColour(settings->color->BED_DRAGGED()); + this->dragged_brush.SetStyle(wxBRUSHSTYLE_SOLID); + this->bed_brush.SetColour(settings->color->BED_COLOR()); + this->bed_brush.SetStyle(wxBRUSHSTYLE_SOLID); + this->transparent_brush.SetColour(wxColour(0,0,0)); + this->transparent_brush.SetStyle(wxBRUSHSTYLE_TRANSPARENT); + + this->grid_pen.SetColour(settings->color->BED_GRID()); + this->grid_pen.SetWidth(1); + this->grid_pen.SetStyle(wxPENSTYLE_SOLID); + this->print_center_pen.SetColour(settings->color->BED_CENTER()); + this->print_center_pen.SetWidth(1); + this->print_center_pen.SetStyle(wxPENSTYLE_SOLID); + this->clearance_pen.SetColour(settings->color->BED_CLEARANCE()); + this->clearance_pen.SetWidth(1); + this->clearance_pen.SetStyle(wxPENSTYLE_SOLID); + this->skirt_pen.SetColour(settings->color->BED_SKIRT()); + this->skirt_pen.SetWidth(1); + this->skirt_pen.SetStyle(wxPENSTYLE_SOLID); + this->dark_pen.SetColour(settings->color->BED_DARK()); + this->dark_pen.SetWidth(1); + this->dark_pen.SetStyle(wxPENSTYLE_SOLID); + } } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 3c82f1a10..07ae3451a 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -4,11 +4,16 @@ #ifndef WX_PRECOMP #include #endif + #include #include "Plater.hpp" #include "ColorScheme.hpp" #include "Settings.hpp" #include "Plater/Plater2DObject.hpp" +#include "misc_ui.hpp" + + +#include "Log.hpp" namespace Slic3r { namespace GUI { @@ -22,7 +27,33 @@ private: std::shared_ptr config; std::shared_ptr settings; + // Different brushes to draw with wxBrush objects_brush {}; + wxBrush instance_brush {}; + wxBrush selected_brush {}; + wxBrush bed_brush {}; + wxBrush dragged_brush {}; + wxBrush transparent_brush {}; + + wxPen grid_pen {}; + wxPen print_center_pen {}; + wxPen clearance_pen {}; + wxPen skirt_pen {}; + wxPen dark_pen {}; + + bool user_drawn_background {(the_os == OS::Mac ? false : true)}; + Plater2DObject selected_instance; + + /// Handle mouse-move events + void mouse_drag(wxMouseEvent& e); + + /// Handle repaint events + void repaint(wxPaintEvent& e); + + /// Set/Update all of the colors used by the various brushes in the panel. + void set_colors(); + + const std::string LogChannel {"GUI_2D"}; }; } } // Namespace Slic3r::GUI From 0a963ea0df61bd97ac2c3b95392e261acd572055 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 18:03:13 -0500 Subject: [PATCH 045/305] Set LogChannel for Slic3r::GUI::Plater --- src/GUI/Plater.cpp | 2 +- src/GUI/Plater.hpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index fa8b596c1..678edfca5 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -108,7 +108,7 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptr Date: Sun, 29 Apr 2018 22:49:49 -0500 Subject: [PATCH 046/305] added warn() to log --- xs/src/libslic3r/Log.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xs/src/libslic3r/Log.hpp b/xs/src/libslic3r/Log.hpp index 554b560a2..419448a88 100644 --- a/xs/src/libslic3r/Log.hpp +++ b/xs/src/libslic3r/Log.hpp @@ -17,6 +17,11 @@ public: std::wclog << message << std::endl; } + static void warn(std::string topic, std::wstring message) { + std::cerr << topic << ": "; + std::wcerr << message << std::endl; + } + }; } From 4eec78e1bf906055d0a42cce75982c52160d418b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 29 Apr 2018 22:50:06 -0500 Subject: [PATCH 047/305] further fleshing out of 2d plater --- src/GUI/Plater/Plate2D.cpp | 92 ++++++++++++++++++++++++++++++++++++++ src/GUI/Plater/Plate2D.hpp | 38 +++++++++++++++- 2 files changed, 128 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 13ebb43f6..e9a906c22 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -1,7 +1,12 @@ #include "Plater/Plate2D.hpp" + +// libslic3r includes +#include "Geometry.hpp" #include "Log.hpp" +// wx includes #include +#include namespace Slic3r { namespace GUI { @@ -15,6 +20,8 @@ Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vectorBind(wxEVT_ERASE_BACKGROUND, [=](wxEraseEvent& e){ }); } + this->Bind(wxEVT_SIZE, [=](wxSizeEvent &e) { this->update_bed_size(); this->Refresh(); }); + // Bind the varying mouse events // Set the brushes @@ -22,6 +29,36 @@ Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vectorSetFocus(); + + auto dc {new wxAutoBufferedPaintDC(this)}; + const auto& size = this->GetSize(); + + + if (this->user_drawn_background) { + // On all systems the AutoBufferedPaintDC() achieves double buffering. + // On MacOS the background is erased, on Windows the background is not erased + // and on Linux/GTK the background is erased to gray color. + // Fill DC with the background on Windows & Linux/GTK. + const auto& brush_background {wxBrush(this->settings->color->BACKGROUND255(), wxBRUSHSTYLE_SOLID)}; + const auto& pen_background {wxPen(this->settings->color->BACKGROUND255(), 1, wxPENSTYLE_SOLID)}; + dc->SetPen(pen_background); + dc->SetBrush(brush_background); + const auto& rect {this->GetUpdateRegion().GetBox()}; + dc->DrawRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight()); + } + + // Draw bed + { + dc->SetPen(this->print_center_pen); + dc->SetBrush(this->bed_brush); + + dc->DrawPolygon(scaled_points_to_pixel(this->bed_polygon, true), 0, 0); + } + + } void Plate2D::mouse_drag(wxMouseEvent& e) { @@ -67,4 +104,59 @@ void Plate2D::set_colors() { } +void Plate2D::nudge_key(wxKeyEvent& e) { + const auto key = e.GetKeyCode(); + + switch( key ) { + case WXK_LEFT: + this->nudge(MoveDirection::Left); + case WXK_RIGHT: + this->nudge(MoveDirection::Right); + case WXK_DOWN: + this->nudge(MoveDirection::Down); + case WXK_UP: + this->nudge(MoveDirection::Up); + default: + break; // do nothing + } + +} + +void Plate2D::nudge(MoveDirection dir) { + if (this->selected_instance < this->objects.size()) { + auto i = 0U; + for (auto& obj : this->objects) { + if (obj.selected()) { + if (obj.selected_instance != -1) { + } + } + i++; + } + } + if (selected_instance >= this->objects.size()) { + Slic3r::Log::warn(LogChannel, L"Nudge failed because there is no selected instance."); + return; // Abort + } +} + +void Plate2D::update_bed_size() { + const auto& canvas_size {this->GetSize()}; + const auto& canvas_w {canvas_size.GetWidth()}; + const auto& canvas_h {canvas_size.GetHeight()}; + if (canvas_w == 0) return; // Abort early if we haven't drawn canvas yet. + + this->bed_polygon = Slic3r::Polygon(); + const auto& polygon = bed_polygon; + + const auto& bb = bed_polygon.bounding_box(); + const auto& size = bb.size(); + + this->scaling_factor = std::min(static_cast(canvas_w) / unscale(size.x), + static_cast(canvas_h) / unscale(size.y)); + + assert(this->scaling_factor != 0); + + +} + } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 07ae3451a..553400a44 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -6,6 +6,7 @@ #endif #include +#include #include "Plater.hpp" #include "ColorScheme.hpp" #include "Settings.hpp" @@ -18,9 +19,16 @@ namespace Slic3r { namespace GUI { +enum class MoveDirection { + Up, Down, Left, Right +}; + class Plate2D : public wxPanel { public: Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); + + +// std::function<> on_select_object {}; private: std::vector& objects; std::shared_ptr model; @@ -42,7 +50,7 @@ private: wxPen dark_pen {}; bool user_drawn_background {(the_os == OS::Mac ? false : true)}; - Plater2DObject selected_instance; + size_t selected_instance; /// Handle mouse-move events void mouse_drag(wxMouseEvent& e); @@ -50,10 +58,36 @@ private: /// Handle repaint events void repaint(wxPaintEvent& e); + void nudge_key(wxKeyEvent& e); + + void nudge(MoveDirection dir); + /// Set/Update all of the colors used by the various brushes in the panel. void set_colors(); - + + /// Convert a scale point array to a pixel polygon suitable for DrawPolygon + std::vector scaled_points_to_pixel(std::vector points, bool unscale); + + // For a specific point, unscaled it + wxPoint unscaled_point_to_pixel(const wxPoint& in) { + const auto& canvas_height {this->GetSize().GetHeight()}; + const auto& zero = this->bed_origin; + return wxPoint(in.x * this->scaling_factor + zero.x, + in.x * this->scaling_factor + (zero.y - canvas_height)); + } + + /// Read print bed size from config. + void update_bed_size(); + const std::string LogChannel {"GUI_2D"}; + + wxPoint bed_origin {}; + Slic3r::Polygon bed_polygon {}; + + /// How much to scale the points to fit in the draw bounding box area. + /// Expressed as pixel / mm + double scaling_factor {1.0}; + }; } } // Namespace Slic3r::GUI From cc4477eb3f61a87921e23ede41c85b848d50951e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:15:32 -0500 Subject: [PATCH 048/305] Used correct inheritance for Config. --- xs/src/libslic3r/Config.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 118309033..a4c7fa470 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -8,7 +8,7 @@ namespace Slic3r { -class Config : DynamicPrintConfig { +class Config : public DynamicPrintConfig { public: static std::shared_ptr new_from_defaults(); static std::shared_ptr new_from_defaults(std::initializer_list init); From 77ae0df2ad2d2f4a1b798a9ca909d381b2c5ba87 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:15:56 -0500 Subject: [PATCH 049/305] scale Pointf array into Points array. --- xs/src/libslic3r/Point.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index 048e6c227..57a9ef7e8 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -152,6 +152,15 @@ to_points(const std::vector &items) return pp; } +inline Points +scale(const std::vector&in ) { + Points out; + for (const auto& p : in) {out.push_back(Point(scale_(p.x), scale_(p.y))); } + return out; +} + + + } // start Boost From 456212918f72954b681f6eca8ba4e8aff890975f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:16:50 -0500 Subject: [PATCH 050/305] Fixed unscale point->pixel rescale function. --- src/GUI/Plater/Plate2D.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 553400a44..5bd57e75f 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -73,7 +73,7 @@ private: const auto& canvas_height {this->GetSize().GetHeight()}; const auto& zero = this->bed_origin; return wxPoint(in.x * this->scaling_factor + zero.x, - in.x * this->scaling_factor + (zero.y - canvas_height)); + in.y * this->scaling_factor + (zero.y - canvas_height)); } /// Read print bed size from config. From aef1bf7f37c83343e941333d9c7e130e90a110ce Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:17:42 -0500 Subject: [PATCH 051/305] Ported scaled_points_to_pixel, made Polygon and Polylines versions. --- src/GUI/Plater/Plate2D.cpp | 10 ++++++++++ src/GUI/Plater/Plate2D.hpp | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index e9a906c22..3791b10b8 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -157,6 +157,16 @@ void Plate2D::update_bed_size() { assert(this->scaling_factor != 0); +std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polygon& poly, bool unscale) { + return this->scaled_points_to_pixel(Polyline(poly), unscale); } +std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polyline& poly, bool unscale) { + std::vector result; + for (const auto& pt : poly.points) { + const auto tmp {wxPoint(pt.x, pt.y)}; + result.push_back( (unscale ? unscaled_point_to_pixel(tmp) : tmp) ); + } + return result; +} } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 5bd57e75f..6c7ab3dc8 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -66,7 +66,8 @@ private: void set_colors(); /// Convert a scale point array to a pixel polygon suitable for DrawPolygon - std::vector scaled_points_to_pixel(std::vector points, bool unscale); + std::vector scaled_points_to_pixel(const Slic3r::Polygon& poly, bool unscale); + std::vector scaled_points_to_pixel(const Slic3r::Polyline& poly, bool unscale); // For a specific point, unscaled it wxPoint unscaled_point_to_pixel(const wxPoint& in) { From 953977be4b3de9b56b48cead553bc56e917378c9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:18:17 -0500 Subject: [PATCH 052/305] Easter egg: Change Canvas text based on the current date (Sep 13). --- src/GUI/Plater/Plate2D.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 6c7ab3dc8..8c5313791 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -4,6 +4,7 @@ #ifndef WX_PRECOMP #include #endif +#include #include #include @@ -19,6 +20,12 @@ namespace Slic3r { namespace GUI { + +// Setup for an Easter Egg with the canvas text. +const wxDateTime today_date {wxDateTime().GetDateOnly()}; +const wxDateTime special_date {13, wxDateTime::Month::Sep, 2006, 0, 0, 0, 0}; +const bool today_is_special = {today_date.GetDay() == special_date.GetDay() && today_date.GetMonth() == special_date.GetMonth()}; + enum class MoveDirection { Up, Down, Left, Right }; @@ -84,6 +91,10 @@ private: wxPoint bed_origin {}; Slic3r::Polygon bed_polygon {}; + /// Set up the 2D canvas blank canvas text. + /// Easter egg: Sept. 13, 2006. The first part ever printed by a RepRap to make another RepRap. + const wxString CANVAS_TEXT { today_is_special ? _(L"What do you want to print today?™") : _("Drag your objects here") }; + /// How much to scale the points to fit in the draw bounding box area. /// Expressed as pixel / mm From fb3250997b47b094b3a944ab728824ca958e7b04 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:18:53 -0500 Subject: [PATCH 053/305] Set BackgroundStyle because wxWidgets wants us to. --- src/GUI/Plater/Plate2D.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 3791b10b8..b30f3b9e7 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -26,6 +26,7 @@ Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vectorSetBackgroundStyle(wxBG_STYLE_PAINT); } void Plate2D::repaint(wxPaintEvent& e) { From 2116dfa1788e6e984aefae7c1bfe92cfcf570543 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:20:00 -0500 Subject: [PATCH 054/305] more work on repaint() event handler. Now draws grid based on bed polygon in config. --- src/GUI/Plater/Plate2D.cpp | 36 +++++++++++++++++++++++++++++++++--- src/GUI/Plater/Plate2D.hpp | 3 +++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index b30f3b9e7..72d14e414 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -35,7 +35,7 @@ void Plate2D::repaint(wxPaintEvent& e) { this->SetFocus(); auto dc {new wxAutoBufferedPaintDC(this)}; - const auto& size = this->GetSize(); + const auto& size {wxSize(this->GetSize().GetWidth(), this->GetSize().GetHeight())}; if (this->user_drawn_background) { @@ -55,8 +55,38 @@ void Plate2D::repaint(wxPaintEvent& e) { { dc->SetPen(this->print_center_pen); dc->SetBrush(this->bed_brush); - - dc->DrawPolygon(scaled_points_to_pixel(this->bed_polygon, true), 0, 0); + auto tmp {scaled_points_to_pixel(this->bed_polygon, true)}; + dc->DrawPolygon(this->bed_polygon.points.size(), tmp.data(), 0, 0); + } + + // draw print center + { + if (this->objects.size() > 0 && settings->autocenter) { + const auto center = this->unscaled_point_to_pixel(this->print_center); + dc->SetPen(print_center_pen); + dc->DrawLine(center.x, 0, center.x, size.y); + dc->DrawLine(0, center.y, size.x, center.y); + dc->SetTextForeground(wxColor(0,0,0)); + dc->SetFont(wxFont(10, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); + + dc->DrawLabel("X = ", wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); + dc->DrawRotatedText("Y = ", 0, center.y + 15, 90); + } + } + + // draw text if plate is empty + if (this->objects.size() == 0) { + dc->SetTextForeground(settings->color->BED_OBJECTS()); + dc->SetFont(wxFont(14, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); + dc->DrawLabel(CANVAS_TEXT, wxRect(0,0, this->GetSize().GetWidth(), this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); + } else { + // draw grid + dc->SetPen(grid_pen); + // Assumption: grid of lines is arranged + // as adjacent pairs of wxPoints + for (auto i = 0U; i < grid.size(); i+=2) { + dc->DrawLine(grid[i], grid[i+1]); + } } diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 8c5313791..39457bc71 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -90,7 +90,10 @@ private: const std::string LogChannel {"GUI_2D"}; wxPoint bed_origin {}; + wxPoint print_center {}; Slic3r::Polygon bed_polygon {}; + std::vector grid {}; + /// Set up the 2D canvas blank canvas text. /// Easter egg: Sept. 13, 2006. The first part ever printed by a RepRap to make another RepRap. const wxString CANVAS_TEXT { today_is_special ? _(L"What do you want to print today?™") : _("Drag your objects here") }; From 352183131a797bbcaa871a69d72b2272b4fa38a5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:33:54 -0500 Subject: [PATCH 055/305] Finished update_bed_size, shuffled LogChannel position in the class. updated a few comments. --- src/GUI/Plater/Plate2D.cpp | 53 +++++++++++++++++++++++++++++++++----- src/GUI/Plater/Plate2D.hpp | 8 +++--- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 72d14e414..2f747f2a2 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -2,7 +2,9 @@ // libslic3r includes #include "Geometry.hpp" +#include "Point.hpp" #include "Log.hpp" +#include "ClipperUtils.hpp" // wx includes #include @@ -27,6 +29,7 @@ Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vectorSetBackgroundStyle(wxBG_STYLE_PAINT); + } void Plate2D::repaint(wxPaintEvent& e) { @@ -69,8 +72,11 @@ void Plate2D::repaint(wxPaintEvent& e) { dc->SetTextForeground(wxColor(0,0,0)); dc->SetFont(wxFont(10, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); - dc->DrawLabel("X = ", wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); - dc->DrawRotatedText("Y = ", 0, center.y + 15, 90); + wxString val {}; + val.Printf("X = %.0f", this->print_center.x); + dc->DrawLabel(val , wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); + val.Printf("Y = %.0f", this->print_center.y); + dc->DrawRotatedText(val, 0, center.y + 15, 90); } } @@ -157,7 +163,7 @@ void Plate2D::nudge(MoveDirection dir) { if (this->selected_instance < this->objects.size()) { auto i = 0U; for (auto& obj : this->objects) { - if (obj.selected()) { + if (obj.selected) { if (obj.selected_instance != -1) { } } @@ -176,17 +182,47 @@ void Plate2D::update_bed_size() { const auto& canvas_h {canvas_size.GetHeight()}; if (canvas_w == 0) return; // Abort early if we haven't drawn canvas yet. - this->bed_polygon = Slic3r::Polygon(); + this->bed_polygon = Slic3r::Polygon(scale(dynamic_cast(config->optptr("bed_shape"))->values)); + const auto& polygon = bed_polygon; const auto& bb = bed_polygon.bounding_box(); const auto& size = bb.size(); - this->scaling_factor = std::min(static_cast(canvas_w) / unscale(size.x), - static_cast(canvas_h) / unscale(size.y)); + this->scaling_factor = std::min(canvas_w / unscale(size.x), canvas_h / unscale(size.y)); - assert(this->scaling_factor != 0); + this->bed_origin = wxPoint( + canvas_w / 2 - (unscale(bb.max.x + bb.min.x)/2 * this->scaling_factor), + canvas_h - (canvas_h / 2 - (unscale(bb.max.y + bb.min.y)/2 * this->scaling_factor)) + ); + const auto& center = bb.center(); + this->print_center = wxPoint(unscale(center.x), unscale(center.y)); + + // Cache bed contours and grid + { + const auto& step { scale_(10) }; + auto grid {Polylines()}; + + for (coord_t x = (bb.min.x - (bb.min.x % step) + step); x < bb.max.x; x += step) { + grid.push_back(Polyline()); + grid.back().append(Point(x, bb.min.y)); + grid.back().append(Point(x, bb.max.y)); + }; + + for (coord_t y = (bb.min.y - (bb.min.y % step) + step); y < bb.max.y; y += step) { + grid.push_back(Polyline()); + grid.back().append(Point(bb.min.x, y)); + grid.back().append(Point(bb.max.x, y)); + }; + + grid = intersection_pl(grid, polygon); + for (auto& i : grid) { + const auto& tmpline { this->scaled_points_to_pixel(i, 1) }; + this->grid.insert(this->grid.end(), tmpline.begin(), tmpline.end()); + } + } +} std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polygon& poly, bool unscale) { return this->scaled_points_to_pixel(Polyline(poly), unscale); @@ -200,4 +236,7 @@ std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polyline& pol } return result; } + + + } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 39457bc71..9b33c80eb 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -84,11 +84,10 @@ private: in.y * this->scaling_factor + (zero.y - canvas_height)); } - /// Read print bed size from config. + /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. void update_bed_size(); - const std::string LogChannel {"GUI_2D"}; - + /// private class variables to stash bits for drawing the print bed area. wxPoint bed_origin {}; wxPoint print_center {}; Slic3r::Polygon bed_polygon {}; @@ -97,11 +96,12 @@ private: /// Set up the 2D canvas blank canvas text. /// Easter egg: Sept. 13, 2006. The first part ever printed by a RepRap to make another RepRap. const wxString CANVAS_TEXT { today_is_special ? _(L"What do you want to print today?™") : _("Drag your objects here") }; - /// How much to scale the points to fit in the draw bounding box area. /// Expressed as pixel / mm double scaling_factor {1.0}; + + const std::string LogChannel {"GUI_2D"}; }; From 7afbb6978ad6446422e9feb542db7ae7964767fd Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:34:30 -0500 Subject: [PATCH 056/305] added Selected_instance field to Plater2DObject, also added reference to object index to Plater. --- src/GUI/Plater.hpp | 1 + src/GUI/Plater/Plater2DObject.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 2d42295a5..c74f9d87f 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -21,6 +21,7 @@ namespace Slic3r { namespace GUI { using UndoOperation = int; +using obj_index = unsigned int; class Plater2DObject; class Plate2D; diff --git a/src/GUI/Plater/Plater2DObject.hpp b/src/GUI/Plater/Plater2DObject.hpp index 3a1772cfb..1bd5b97ba 100644 --- a/src/GUI/Plater/Plater2DObject.hpp +++ b/src/GUI/Plater/Plater2DObject.hpp @@ -8,6 +8,7 @@ public: std::string name {""}; std::string identifier {""}; bool selected {false}; + int selected_instance {-1}; }; } } // Namespace Slic3r::GUI #endif From 14097656e9c742ea963974b9ca4ce4c4d7974392 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 23:38:12 -0500 Subject: [PATCH 057/305] Added point_to_model_units() and clarified a couple comments. --- src/GUI/Plater/Plate2D.hpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 9b33c80eb..01eb01abe 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -14,7 +14,6 @@ #include "Plater/Plater2DObject.hpp" #include "misc_ui.hpp" - #include "Log.hpp" @@ -42,7 +41,7 @@ private: std::shared_ptr config; std::shared_ptr settings; - // Different brushes to draw with + // Different brushes to draw with, initialized from settings->Color during the constructor wxBrush objects_brush {}; wxBrush instance_brush {}; wxBrush selected_brush {}; @@ -76,7 +75,7 @@ private: std::vector scaled_points_to_pixel(const Slic3r::Polygon& poly, bool unscale); std::vector scaled_points_to_pixel(const Slic3r::Polyline& poly, bool unscale); - // For a specific point, unscaled it + /// For a specific point, unscale it relative to the origin wxPoint unscaled_point_to_pixel(const wxPoint& in) { const auto& canvas_height {this->GetSize().GetHeight()}; const auto& zero = this->bed_origin; @@ -103,6 +102,20 @@ private: const std::string LogChannel {"GUI_2D"}; + Slic3r::Point point_to_model_units(coordf_t x, coordf_t y) { + const auto& zero {this->bed_origin}; + return Slic3r::Point( + scale_(x - zero.x) / this->scaling_factor, + scale_(y - zero.y) / this->scaling_factor + ); + } + Slic3r::Point point_to_model_units(const wxPoint& pt) { + return this->point_to_model_units(pt.x, pt.y); + } + Slic3r::Point point_to_model_units(const Pointf& pt) { + return this->point_to_model_units(pt.x, pt.y); + } + }; } } // Namespace Slic3r::GUI From 5f405b60e91a22b02cee356aa1e123aa4bb84ef9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 1 May 2018 21:50:30 -0500 Subject: [PATCH 058/305] Plater2DObject->PlaterObject --- src/CMakeLists.txt | 1 + src/GUI/Plater.hpp | 6 ++-- src/GUI/Plater/Plate2D.cpp | 2 +- src/GUI/Plater/Plate2D.hpp | 6 ++-- src/GUI/Plater/Plater2DObject.hpp | 14 --------- src/GUI/Plater/PlaterObject.cpp | 50 +++++++++++++++++++++++++++++++ src/GUI/Plater/PlaterObject.hpp | 34 +++++++++++++++++++++ 7 files changed, 92 insertions(+), 21 deletions(-) delete mode 100644 src/GUI/Plater/Plater2DObject.hpp create mode 100644 src/GUI/Plater/PlaterObject.cpp create mode 100644 src/GUI/Plater/PlaterObject.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 361074ea3..6f81384a1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -187,6 +187,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/Plater.cpp ${GUI_LIBDIR}/Plater/Plate2D.cpp + ${GUI_LIBDIR}/Plater/PlaterObject.cpp ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp ) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index c74f9d87f..58a25d0a1 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -14,7 +14,7 @@ #include "Print.hpp" #include "Config.hpp" -#include "Plater/Plater2DObject.hpp" +#include "Plater/PlaterObject.hpp" #include "Plater/Plate2D.hpp" #include "Settings.hpp" @@ -23,7 +23,7 @@ namespace Slic3r { namespace GUI { using UndoOperation = int; using obj_index = unsigned int; -class Plater2DObject; +class PlaterObject; class Plate2D; class Plater : public wxPanel @@ -44,7 +44,7 @@ private: bool processed {false}; - std::vector objects {}; + std::vector objects {}; std::stack undo {}; std::stack redo {}; diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 2f747f2a2..11f863f93 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -12,7 +12,7 @@ namespace Slic3r { namespace GUI { -Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : +Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) { diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 01eb01abe..8bab87b7a 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -11,7 +11,7 @@ #include "Plater.hpp" #include "ColorScheme.hpp" #include "Settings.hpp" -#include "Plater/Plater2DObject.hpp" +#include "Plater/PlaterObject.hpp" #include "misc_ui.hpp" #include "Log.hpp" @@ -31,12 +31,12 @@ enum class MoveDirection { class Plate2D : public wxPanel { public: - Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); + Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); // std::function<> on_select_object {}; private: - std::vector& objects; + std::vector& objects; std::shared_ptr model; std::shared_ptr config; std::shared_ptr settings; diff --git a/src/GUI/Plater/Plater2DObject.hpp b/src/GUI/Plater/Plater2DObject.hpp deleted file mode 100644 index 1bd5b97ba..000000000 --- a/src/GUI/Plater/Plater2DObject.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef PLATER2DOBJECT_HPP -#define PLATER2DOBJECT_HPP - -namespace Slic3r { namespace GUI { -// 2D Preview of an object -class Plater2DObject { -public: - std::string name {""}; - std::string identifier {""}; - bool selected {false}; - int selected_instance {-1}; -}; -} } // Namespace Slic3r::GUI -#endif diff --git a/src/GUI/Plater/PlaterObject.cpp b/src/GUI/Plater/PlaterObject.cpp new file mode 100644 index 000000000..39b6bca3b --- /dev/null +++ b/src/GUI/Plater/PlaterObject.cpp @@ -0,0 +1,50 @@ +#include "Plater/PlaterObject.hpp" + +#include "Geometry.hpp" +#include "ExPolygon.hpp" + +namespace Slic3r { namespace GUI { + +Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& model, int obj_index) { + + // make method idempotent + this->thumbnail.clear(); + + auto mesh {model.objects[obj_index]->raw_mesh()}; + auto model_instance {model.objects[obj_idx]->instances[0]}; + + // Apply any x/y rotations and scaling vector if this came from a 3MF object. + mesh.rotate_x(model_instance.x_rotation); + mesh.rotate_y(model_instance.y_rotation); + mesh.scale_xyz(model_instance.scaling_vector); + + if (mesh.facets_count <= 5000) { + auto area_threshold {Slic3r::Geometry::scale(1)}; + ExPolygons tmp {}; + std::copy_if(tmp.end(), mesh.horizontal_projection().begin(), mesh.horizontal_projection().end(), [=](const ExPolygon& p) { return p.area() >= area_threshold; } ); // return all polys bigger than the area + this->thumbnail.append(tmp); + this->thumbnail.simplify(0.5); + } else { + auto convex_hull {Slic3r::ExPolygon(mesh.convex_hull)}; + this->thumbnail.append(convex_hull); + } + + return this->thumbnail; +} +Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(Slic3r::Model model, int obj_idx) { + if (this->thumbnail.expolygons.size() == 0) return this->thumbnail; + + const auto& model_object {model.objects[obj_idx] }; + const auto& model_instance {model_object.instances[0]}; + + // the order of these transformations MUST be the same everywhere, including + // in Slic3r::Print->add_model_object() + auto t {this->thumbnail}; + t.rotate(model_instance.rotation(), Slic3r::Point(0,0)); + t.scale(model_instance.scaling_factor()); + + this->transformed_thumbnail = t; + +} + +} } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp new file mode 100644 index 000000000..32709a30c --- /dev/null +++ b/src/GUI/Plater/PlaterObject.hpp @@ -0,0 +1,34 @@ +#ifndef PLATEROBJECT_HPP +#define PLATEROBJECT_HPP +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "ExPolygonCollection.hpp" + +namespace Slic3r { namespace GUI { + +class PlaterObject { +public: + wxString name {L""}; + wxString identifier {L""}; + wxString input_file {L""}; + int input_file_obj_idx {-1}; + + + Slic3r::ExPolygonCollection thumbnail; + Slic3r::ExPolygonCollection transformed_thumbnail; + + // read only + std::vector instance_thumbnails; + + bool selected {false}; + int selected_instance {-1}; + + Slic3r::ExPolygonCollection& make_thumbnail(Slic3r::Model model, int obj_index); + Slic3r::ExPolygonCollection& transform_thumbnail(Slic3r::Model model, int obj_index); +}; + +}} // Namespace Slic3r::GUI +#endif From 1074b04326424732d430abf29aa293203a558de2 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 1 May 2018 22:31:38 -0500 Subject: [PATCH 059/305] Overloaded append() to add single ExPolygons (avoids having to create a vector for no purpose) --- xs/src/libslic3r/ExPolygonCollection.cpp | 5 +++++ xs/src/libslic3r/ExPolygonCollection.hpp | 1 + 2 files changed, 6 insertions(+) diff --git a/xs/src/libslic3r/ExPolygonCollection.cpp b/xs/src/libslic3r/ExPolygonCollection.cpp index 90498a42d..9de1cb786 100644 --- a/xs/src/libslic3r/ExPolygonCollection.cpp +++ b/xs/src/libslic3r/ExPolygonCollection.cpp @@ -135,5 +135,10 @@ ExPolygonCollection::append(const ExPolygons &expp) { this->expolygons.insert(this->expolygons.end(), expp.begin(), expp.end()); } +void +ExPolygonCollection::append(const ExPolygon &expp) +{ + this->expolygons.push_back(expp); +} } diff --git a/xs/src/libslic3r/ExPolygonCollection.hpp b/xs/src/libslic3r/ExPolygonCollection.hpp index 89728c822..57f512336 100644 --- a/xs/src/libslic3r/ExPolygonCollection.hpp +++ b/xs/src/libslic3r/ExPolygonCollection.hpp @@ -33,6 +33,7 @@ class ExPolygonCollection Polygons contours() const; Polygons holes() const; void append(const ExPolygons &expolygons); + void append(const ExPolygon &expolygons); }; inline ExPolygonCollection& From 76b86c807bde33d724048636f9988786753774ce Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 1 May 2018 22:32:09 -0500 Subject: [PATCH 060/305] Implemented make_thumbnail and transform_thumbnail; neither is tested yet. --- src/GUI/Plater/PlaterObject.cpp | 29 +++++++++++++++-------------- src/GUI/Plater/PlaterObject.hpp | 5 +++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/GUI/Plater/PlaterObject.cpp b/src/GUI/Plater/PlaterObject.cpp index 39b6bca3b..b27ba821b 100644 --- a/src/GUI/Plater/PlaterObject.cpp +++ b/src/GUI/Plater/PlaterObject.cpp @@ -2,49 +2,50 @@ #include "Geometry.hpp" #include "ExPolygon.hpp" +#include "libslic3r.h" namespace Slic3r { namespace GUI { -Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& model, int obj_index) { +Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& model, int obj_idx) { // make method idempotent - this->thumbnail.clear(); + this->thumbnail.expolygons.clear(); - auto mesh {model.objects[obj_index]->raw_mesh()}; + auto mesh {model.objects[obj_idx]->raw_mesh()}; auto model_instance {model.objects[obj_idx]->instances[0]}; // Apply any x/y rotations and scaling vector if this came from a 3MF object. - mesh.rotate_x(model_instance.x_rotation); - mesh.rotate_y(model_instance.y_rotation); - mesh.scale_xyz(model_instance.scaling_vector); + mesh.rotate_x(model_instance->x_rotation); + mesh.rotate_y(model_instance->y_rotation); + mesh.scale(model_instance->scaling_vector); - if (mesh.facets_count <= 5000) { - auto area_threshold {Slic3r::Geometry::scale(1)}; + if (mesh.facets_count() <= 5000) { + auto area_threshold {scale_(1.0)}; ExPolygons tmp {}; std::copy_if(tmp.end(), mesh.horizontal_projection().begin(), mesh.horizontal_projection().end(), [=](const ExPolygon& p) { return p.area() >= area_threshold; } ); // return all polys bigger than the area this->thumbnail.append(tmp); this->thumbnail.simplify(0.5); } else { - auto convex_hull {Slic3r::ExPolygon(mesh.convex_hull)}; + auto convex_hull {Slic3r::ExPolygon(mesh.convex_hull())}; this->thumbnail.append(convex_hull); } return this->thumbnail; } -Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(Slic3r::Model model, int obj_idx) { +Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(const Slic3r::Model& model, int obj_idx) { if (this->thumbnail.expolygons.size() == 0) return this->thumbnail; const auto& model_object {model.objects[obj_idx] }; - const auto& model_instance {model_object.instances[0]}; + const auto& model_instance {model_object->instances[0]}; // the order of these transformations MUST be the same everywhere, including // in Slic3r::Print->add_model_object() auto t {this->thumbnail}; - t.rotate(model_instance.rotation(), Slic3r::Point(0,0)); - t.scale(model_instance.scaling_factor()); + t.rotate(model_instance->rotation, Slic3r::Point(0,0)); + t.scale(model_instance->scaling_factor); this->transformed_thumbnail = t; - + return this->transformed_thumbnail; } } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp index 32709a30c..72b71d88e 100644 --- a/src/GUI/Plater/PlaterObject.hpp +++ b/src/GUI/Plater/PlaterObject.hpp @@ -6,6 +6,7 @@ #endif #include "ExPolygonCollection.hpp" +#include "Model.hpp" namespace Slic3r { namespace GUI { @@ -26,8 +27,8 @@ public: bool selected {false}; int selected_instance {-1}; - Slic3r::ExPolygonCollection& make_thumbnail(Slic3r::Model model, int obj_index); - Slic3r::ExPolygonCollection& transform_thumbnail(Slic3r::Model model, int obj_index); + Slic3r::ExPolygonCollection& make_thumbnail(const Slic3r::Model& model, int obj_idx); + Slic3r::ExPolygonCollection& transform_thumbnail(const Slic3r::Model& model, int obj_idx); }; }} // Namespace Slic3r::GUI From a9983249622077a68380dd70f3a2f6e1e8992c67 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 1 May 2018 22:32:42 -0500 Subject: [PATCH 061/305] Stubbed out mouse events for left up/down/dclick. --- src/GUI/Plater/Plate2D.cpp | 21 ++++++++++++++++++++- src/GUI/Plater/Plate2D.hpp | 5 ++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 11f863f93..fb0b172a9 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -18,6 +18,10 @@ Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector this->Bind(wxEVT_PAINT, [=](wxPaintEvent &e) { this->repaint(e); }); this->Bind(wxEVT_MOTION, [=](wxMouseEvent &e) { this->mouse_drag(e); }); + this->Bind(wxEVT_LEFT_DOWN, [=](wxMouseEvent &e) { this->mouse_down(e); }); + this->Bind(wxEVT_LEFT_UP, [=](wxMouseEvent &e) { this->mouse_up(e); }); + this->Bind(wxEVT_LEFT_DCLICK, [=](wxMouseEvent &e) { this->mouse_dclick(e); }); + if (user_drawn_background) { this->Bind(wxEVT_ERASE_BACKGROUND, [=](wxEraseEvent& e){ }); } @@ -99,13 +103,28 @@ void Plate2D::repaint(wxPaintEvent& e) { } void Plate2D::mouse_drag(wxMouseEvent& e) { + const auto pos {e.GetPosition()}; + const auto& point {this->point_to_model_units(e.GetPosition())}; if (e.Dragging()) { Slic3r::Log::info(LogChannel, L"Mouse dragging"); } else { - Slic3r::Log::info(LogChannel, L"Mouse moving"); + auto cursor = wxSTANDARD_CURSOR; + /* + if (find_first_of(this->objects.begin(), this->objects.end(); [=](const PlaterObject& o) { return o.contour->contains_point(point);} ) == this->object.end()) { + cursor = wxCursor(wxCURSOR_HAND); + } + */ + this->SetCursor(*cursor); } } +void Plate2D::mouse_down(wxMouseEvent& e) { +} +void Plate2D::mouse_up(wxMouseEvent& e) { +} +void Plate2D::mouse_dclick(wxMouseEvent& e) { +} + void Plate2D::set_colors() { this->SetBackgroundColour(settings->color->BACKGROUND255()); diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 8bab87b7a..61c097422 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -36,7 +36,7 @@ public: // std::function<> on_select_object {}; private: - std::vector& objects; + std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; std::shared_ptr settings; @@ -60,6 +60,9 @@ private: /// Handle mouse-move events void mouse_drag(wxMouseEvent& e); + void mouse_down(wxMouseEvent& e); + void mouse_up(wxMouseEvent& e); + void mouse_dclick(wxMouseEvent& e); /// Handle repaint events void repaint(wxPaintEvent& e); From 3b17844fbaa91f47ad20c71e3072c3793855009d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 1 May 2018 22:50:10 -0500 Subject: [PATCH 062/305] partially implemented open_model as a free function in misc_ui. Initial dir and the file patterns are not implemented yet. --- src/GUI/misc_ui.cpp | 19 +++++++++++++++++++ src/GUI/misc_ui.hpp | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index c585117b9..ee1aaeb9d 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -1,10 +1,12 @@ #include "misc_ui.hpp" #include #include +#include #include #include + namespace Slic3r { namespace GUI { @@ -110,5 +112,22 @@ sub show_error { } */ +std::vector open_model(wxWindow* parent, const Settings& settings, wxWindow* top) { + auto dialog {new wxFileDialog((parent != nullptr ? parent : top), _("Choose one or more files") + wxString(" (STL/OBJ/AMF/3MF):"), ".", "", + "", wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST)}; + if (dialog->ShowModal() != wxID_OK) { + dialog->Destroy(); + return std::vector(); + } + std::vector tmp; + wxArrayString tmpout; + dialog->GetPaths(tmpout); + for (const auto& i : tmpout) { + tmp.push_back(i); + } + dialog->Destroy(); + return tmp; +} + }} // namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index d40ab729c..d56c52219 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -9,6 +9,8 @@ #include #include +#include "Settings.hpp" + #include "Log.hpp" /// Common static (that is, free-standing) functions, not part of an object hierarchy. @@ -98,6 +100,8 @@ sub CallAfter { wxString decode_path(const wxString& in); wxString encode_path(const wxString& in); +std::vector open_model(wxWindow* parent, const Settings& settings, wxWindow* top); + }} // namespace Slic3r::GUI #endif // MISC_UI_HPP From ff1fa38b3154362ad5707c46fe099992a3888b42 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 1 May 2018 22:51:07 -0500 Subject: [PATCH 063/305] Stubbed out load_file, some work on add to call load_file(). Added some comments for canvas2D. --- src/GUI/Plater.cpp | 19 +++++++++++++++++++ src/GUI/Plater.hpp | 9 +++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 678edfca5..c6eaf0421 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -109,8 +109,27 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrobject_identifier; + const auto& input_files{open_model(this, *(this->settings), wxTheApp->GetTopWindow())}; + for (const auto& f : input_files) { + Log::info(LogChannel, (wxString(L"Calling Load File for ") + f).ToStdWstring()); + this->load_file(f); + } + + // abort if no objects actually added. + if (start_object_id == this->object_identifier) return; + + // save the added objects + + // get newly added objects count + } +std::vector Plater::load_file(const wxString& file) { + return std::vector(); + +} }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 58a25d0a1..316c0b034 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -44,14 +44,19 @@ private: bool processed {false}; - std::vector objects {}; + std::vector objects {}; //< Main object vector. + + size_t object_identifier {0U}; //< Counter for adding objects to Slic3r std::stack undo {}; std::stack redo {}; wxNotebook* preview_notebook {new wxNotebook(this, -1, wxDefaultPosition, wxSize(335,335), wxNB_BOTTOM)}; - Plate2D* canvas2D {}; + Plate2D* canvas2D {}; //< 2D plater canvas + + /// Handles the actual load of the file from the dialog handoff. + std::vector load_file(const wxString& file); const std::string LogChannel {"GUI_Plater"}; //< Which log these messages should go to. From 4d9d2c88dc15104946f89f506561127115e45208 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 2 May 2018 16:16:19 -0500 Subject: [PATCH 064/305] added file filters to add dialog --- src/GUI/misc_ui.cpp | 2 +- src/GUI/misc_ui.hpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index ee1aaeb9d..f04adc8b7 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -114,7 +114,7 @@ sub show_error { std::vector open_model(wxWindow* parent, const Settings& settings, wxWindow* top) { auto dialog {new wxFileDialog((parent != nullptr ? parent : top), _("Choose one or more files") + wxString(" (STL/OBJ/AMF/3MF):"), ".", "", - "", wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST)}; + MODEL_WILDCARD, wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST)}; if (dialog->ShowModal() != wxID_OK) { dialog->Destroy(); return std::vector(); diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index d56c52219..e733fe565 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include "Settings.hpp" @@ -33,6 +35,23 @@ constexpr bool isDev = true; constexpr bool isDev = false; #endif +// hopefully the compiler is smart enough to figure this out +const std::map FILE_WILDCARDS { + std::make_pair("known", "Known files (*.stl, *.obj, *.amf, *.xml, *.3mf)|*.3mf;*.3MF;*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML"), + std::make_pair("stl", "STL files (*.stl)|*.stl;*.STL"), + std::make_pair("obj", "OBJ files (*.obj)|*.obj;*.OBJ"), + std::make_pair("amf", "AMF files (*.amf)|*.amf;*.AMF;*.xml;*.XML"), + std::make_pair("tmf", "3MF files (*.3mf)|*.3mf;*.3MF"), + std::make_pair("ini", "INI files *.ini|*.ini;*.INI"), + std::make_pair("gcode", "G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC"), + std::make_pair("svg", "SVG files *.svg|*.svg;*.SVG") + }; + +const std::string MODEL_WILDCARD { FILE_WILDCARDS.at("known") + std::string("|") + FILE_WILDCARDS.at("stl")+ std::string("|") + FILE_WILDCARDS.at("obj") + std::string("|") + FILE_WILDCARDS.at("amf")+ std::string("|") + FILE_WILDCARDS.at("tmf")}; +const std::string STL_MODEL_WILDCARD { FILE_WILDCARDS.at("stl") }; +const std::string AMF_MODEL_WILDCARD { FILE_WILDCARDS.at("amf") }; +const std::string TMF_MODEL_WILDCARD { FILE_WILDCARDS.at("tmf") }; + /// Mostly useful for Linux distro maintainers, this will change where Slic3r assumes /// its ./var directory lives (where its art assets are). From 434fc0aa2ec01e04d252c84c35201053b3d2043a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 2 May 2018 22:49:54 -0500 Subject: [PATCH 065/305] Define new event to post status text messages to a status bar; meant for child items to post information to the status bar that propagate up --- src/CMakeLists.txt | 1 + src/GUI/ProgressStatusBar.cpp | 10 ++++++++++ src/GUI/ProgressStatusBar.hpp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/GUI/ProgressStatusBar.cpp create mode 100644 src/GUI/ProgressStatusBar.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f81384a1..cf8958389 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -186,6 +186,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/Plater.cpp + ${GUI_LIBDIR}/ProgressStatusBar.cpp ${GUI_LIBDIR}/Plater/Plate2D.cpp ${GUI_LIBDIR}/Plater/PlaterObject.cpp ${GUI_LIBDIR}/Settings.cpp diff --git a/src/GUI/ProgressStatusBar.cpp b/src/GUI/ProgressStatusBar.cpp new file mode 100644 index 000000000..8684c2e35 --- /dev/null +++ b/src/GUI/ProgressStatusBar.cpp @@ -0,0 +1,10 @@ +#include "ProgressStatusBar.hpp" + +namespace Slic3r { namespace GUI { + +void ProgressStatusBar::SendStatusText(wxEvtHandler* dest, wxWindowID origin, const wxString& msg) { + wxQueueEvent(dest, new StatusTextEvent(EVT_STATUS_TEXT_POST, origin, msg)); + +} + +}} // Namespace Slic3r::GUI diff --git a/src/GUI/ProgressStatusBar.hpp b/src/GUI/ProgressStatusBar.hpp new file mode 100644 index 000000000..1b690f589 --- /dev/null +++ b/src/GUI/ProgressStatusBar.hpp @@ -0,0 +1,35 @@ +#ifndef PROGRESSSTATUSBAR_HPP +#define PROGRESSSTATUSBAR_HPP +#include +#include + +namespace Slic3r { namespace GUI { + +class StatusTextEvent : public wxEvent { +public: + StatusTextEvent(wxEventType eventType, int winid, const wxString& msg) + : wxEvent(winid, eventType), + message(msg) { } + + bool ShouldPropagate() const { return true; } // propagate this event + + /// One accessor + const wxString& GetMessage() const {return message;} + /// implement the base class pure virtual + virtual wxEvent *Clone() const { return new StatusTextEvent(*this); } + +private: + const wxString message; +}; + +wxDEFINE_EVENT(EVT_STATUS_TEXT_POST, StatusTextEvent); + +class ProgressStatusBar : public wxStatusBar { +public: + //< Post an event to owning box and let it percolate up to a window that sets the appropriate status text. + static void SendStatusText(wxEvtHandler* dest, wxWindowID origin, const wxString& msg); + ProgressStatusBar(wxWindow* parent, int id) : wxStatusBar(parent, id) { } +}; + +}} // Namespace Slic3r::GUI +#endif // PROGRESSSTATUSBAR_HPP From 131e6d8d8d7b873791bd07d99d2d684ab302c7d9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 2 May 2018 22:50:22 -0500 Subject: [PATCH 066/305] Initial load status bar, apparently layout broke for plater. --- src/GUI/MainFrame.cpp | 9 ++++----- src/GUI/MainFrame.hpp | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 8c1d3c0e4..029471f49 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -28,11 +28,10 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si wxToolTip::SetAutoPop(TOOLTIP_TIMER); - // STUB: Initialize status bar with text. - /* # initialize status bar - $self->{statusbar} = Slic3r::GUI::ProgressStatusBar->new($self, -1); - $self->{statusbar}->SetStatusText("Version $Slic3r::VERSION - Remember to check for updates at http://slic3r.org/"); - $self->SetStatusBar($self->{statusbar}); */ + // initialize status bar + this->statusbar = new ProgressStatusBar(this, -1); + this->statusbar->SetStatusText("Version $Slic3r::VERSION - Remember to check for updates at http://slic3r.org/"); + this->SetStatusBar(this->statusbar); this->loaded = 1; diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index b067c6f9b..b073d0c48 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -17,6 +17,7 @@ #include "PresetEditor.hpp" #include "Settings.hpp" #include "GUI.hpp" +#include "ProgressStatusBar.hpp" namespace Slic3r { namespace GUI { @@ -47,6 +48,8 @@ private: std::shared_ptr gui_config; std::map preset_editor_tabs; + ProgressStatusBar* statusbar {new ProgressStatusBar(this, -1)}; + }; }} // Namespace Slic3r::GUI From 33d2232f0987081f1fc7052bad8071742dca677a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 2 May 2018 22:51:08 -0500 Subject: [PATCH 067/305] stubbed in load_model_objects, load_file should be implemented now. --- src/GUI/Plater.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++-- src/GUI/Plater.hpp | 8 ++++- src/GUI/Settings.hpp | 2 ++ 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index c6eaf0421..51f684df9 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -1,6 +1,9 @@ #include +#include + #include "Plater.hpp" +#include "ProgressStatusBar.hpp" #include "Log.hpp" namespace Slic3r { namespace GUI { @@ -126,9 +129,82 @@ void Plater::add() { } -std::vector Plater::load_file(const wxString& file) { - return std::vector(); +std::vector Plater::load_file(const wxString& file, const int obj_idx_to_load) { + auto input_file {wxFileName(file)}; + settings->skein_directory = input_file.GetPath(); + settings->save_settings(); + + Slic3r::Model model; + bool valid_load {true}; + + auto obj_idx {std::vector()}; + auto progress_dialog {new wxProgressDialog(_(L"Loading…"), _(L"Processing input file…"), 100, this, 0)}; + progress_dialog->Pulse(); + //TODO: Add a std::wstring so we can handle non-roman characters as file names. + try { + auto model {Slic3r::Model::read_from_file(file.ToStdString())}; + } catch (std::runtime_error& e) { + show_error(this, e.what()); + valid_load = false; + } + + if (valid_load) { + if (model.looks_like_multipart_object()) { + auto dialog {new wxMessageDialog(this, + _("This file contains several objects positioned at multiple heights. Instead of considering them as multiple objects, should I consider\n them this file as a single object having multiple parts?\n"), _("Multi-part object detected"), wxICON_WARNING | wxYES | wxNO)}; + if (dialog->ShowModal() == wxID_YES) { + model.convert_multipart_object(); + } + } + + for (auto i = 0U; i < model.objects.size(); i++) { + auto object {model.objects[i]}; + object->input_file = file.ToStdString(); + for (auto j = 0U; j < object->volumes.size(); j++) { + auto volume {object->volumes.at(j)}; + volume->input_file = file.ToStdString(); + volume->input_file_obj_idx = i; + volume->input_file_vol_idx = j; + } + } + auto i {0U}; + if (obj_idx_to_load > 0) { + const size_t idx_load = obj_idx_to_load; + if (idx_load >= model.objects.size()) return std::vector(); + obj_idx = this->load_model_objects(model.objects.at(idx_load)); + i = idx_load; + } else { + obj_idx = this->load_model_objects(model.objects); + } + + for (const auto &j : obj_idx) { + this->objects[j].input_file = file; + this->objects[j].input_file_obj_idx = i++; + } + ProgressStatusBar::SendStatusText(this, this->GetId(), _("Loaded ") + input_file.GetName()); + + if (this->scaled_down) { + ProgressStatusBar::SendStatusText(this, this->GetId(), _("Your object appears to be too large, so it was automatically scaled down to fit your print bed.")); + } + if (this->outside_bounds) { + ProgressStatusBar::SendStatusText(this, this->GetId(), _("Some of your object(s) appear to be outside the print bed. Use the arrange button to correct this.")); + } + } + + progress_dialog->Destroy(); + this->redo = std::stack(); + return obj_idx; +} + + + +std::vector Plater::load_model_objects(ModelObject* model_object) { + ModelObjectPtrs tmp {model_object}; // wrap in a std::vector + return load_model_objects(tmp); +} +std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { + return std::vector(); } }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 316c0b034..9bc5165db 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -56,10 +56,16 @@ private: Plate2D* canvas2D {}; //< 2D plater canvas /// Handles the actual load of the file from the dialog handoff. - std::vector load_file(const wxString& file); + std::vector load_file(const wxString& file, const int obj_idx_to_load = -1); const std::string LogChannel {"GUI_Plater"}; //< Which log these messages should go to. + std::vector load_model_objects(ModelObject* model_object); + std::vector load_model_objects(ModelObjectPtrs model_objects); + + bool scaled_down {false}; + bool outside_bounds {false}; + }; diff --git a/src/GUI/Settings.hpp b/src/GUI/Settings.hpp index c74383084..854a88683 100644 --- a/src/GUI/Settings.hpp +++ b/src/GUI/Settings.hpp @@ -46,6 +46,8 @@ class Settings { const wxString version { wxString(SLIC3R_VERSION) }; + wxString skein_directory {}; //< Recently-opened skien directory. + void save_settings(); void load_settings(); From 2bab9f27e12cc27faff7b6728e5dbcfb4325ae7d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 3 May 2018 07:55:41 -0500 Subject: [PATCH 068/305] Moved statusbar up to public (allow children to manipulate the statusbar) --- src/GUI/MainFrame.hpp | 4 ++-- src/GUI/Plater.cpp | 11 ++++++++--- src/GUI/Plater.hpp | 4 ++++ src/GUI/ProgressStatusBar.cpp | 5 ----- src/GUI/ProgressStatusBar.hpp | 22 +--------------------- 5 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index b073d0c48..1838114bb 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -21,7 +21,7 @@ namespace Slic3r { namespace GUI { - +class Plater; constexpr unsigned int TOOLTIP_TIMER = 32767; @@ -30,6 +30,7 @@ class MainFrame: public wxFrame public: MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size); MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr _gui_config); + ProgressStatusBar* statusbar {new ProgressStatusBar(this, -1)}; private: wxDECLARE_EVENT_TABLE(); @@ -48,7 +49,6 @@ private: std::shared_ptr gui_config; std::map preset_editor_tabs; - ProgressStatusBar* statusbar {new ProgressStatusBar(this, -1)}; }; diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 51f684df9..623299215 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -1,10 +1,12 @@ #include #include +#include #include "Plater.hpp" #include "ProgressStatusBar.hpp" #include "Log.hpp" +#include "MainFrame.hpp" namespace Slic3r { namespace GUI { @@ -182,13 +184,13 @@ std::vector Plater::load_file(const wxString& file, const int obj_idx_to_lo this->objects[j].input_file = file; this->objects[j].input_file_obj_idx = i++; } - ProgressStatusBar::SendStatusText(this, this->GetId(), _("Loaded ") + input_file.GetName()); + GetFrame()->statusbar->SetStatusText(_("Loaded ") + input_file.GetName()); if (this->scaled_down) { - ProgressStatusBar::SendStatusText(this, this->GetId(), _("Your object appears to be too large, so it was automatically scaled down to fit your print bed.")); + GetFrame()->statusbar->SetStatusText(_("Your object appears to be too large, so it was automatically scaled down to fit your print bed.")); } if (this->outside_bounds) { - ProgressStatusBar::SendStatusText(this, this->GetId(), _("Some of your object(s) appear to be outside the print bed. Use the arrange button to correct this.")); + GetFrame()->statusbar->SetStatusText(_("Some of your object(s) appear to be outside the print bed. Use the arrange button to correct this.")); } } @@ -207,5 +209,8 @@ std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { return std::vector(); } +MainFrame* Plater::GetFrame() { return dynamic_cast(wxGetTopLevelParent(this)); } + + }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 9bc5165db..5068e788e 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -18,6 +18,8 @@ #include "Plater/Plate2D.hpp" #include "Settings.hpp" +#include "MainFrame.hpp" + namespace Slic3r { namespace GUI { using UndoOperation = int; @@ -25,6 +27,7 @@ using obj_index = unsigned int; class PlaterObject; class Plate2D; +class MainFrame; class Plater : public wxPanel { @@ -65,6 +68,7 @@ private: bool scaled_down {false}; bool outside_bounds {false}; + MainFrame* GetFrame(); }; diff --git a/src/GUI/ProgressStatusBar.cpp b/src/GUI/ProgressStatusBar.cpp index 8684c2e35..24822748b 100644 --- a/src/GUI/ProgressStatusBar.cpp +++ b/src/GUI/ProgressStatusBar.cpp @@ -2,9 +2,4 @@ namespace Slic3r { namespace GUI { -void ProgressStatusBar::SendStatusText(wxEvtHandler* dest, wxWindowID origin, const wxString& msg) { - wxQueueEvent(dest, new StatusTextEvent(EVT_STATUS_TEXT_POST, origin, msg)); - -} - }} // Namespace Slic3r::GUI diff --git a/src/GUI/ProgressStatusBar.hpp b/src/GUI/ProgressStatusBar.hpp index 1b690f589..f2984691b 100644 --- a/src/GUI/ProgressStatusBar.hpp +++ b/src/GUI/ProgressStatusBar.hpp @@ -5,29 +5,9 @@ namespace Slic3r { namespace GUI { -class StatusTextEvent : public wxEvent { -public: - StatusTextEvent(wxEventType eventType, int winid, const wxString& msg) - : wxEvent(winid, eventType), - message(msg) { } - - bool ShouldPropagate() const { return true; } // propagate this event - - /// One accessor - const wxString& GetMessage() const {return message;} - /// implement the base class pure virtual - virtual wxEvent *Clone() const { return new StatusTextEvent(*this); } - -private: - const wxString message; -}; - -wxDEFINE_EVENT(EVT_STATUS_TEXT_POST, StatusTextEvent); - class ProgressStatusBar : public wxStatusBar { public: - //< Post an event to owning box and let it percolate up to a window that sets the appropriate status text. - static void SendStatusText(wxEvtHandler* dest, wxWindowID origin, const wxString& msg); + /// Constructor stub from parent ProgressStatusBar(wxWindow* parent, int id) : wxStatusBar(parent, id) { } }; From e263ca2b3862d5a55e8bdad120fb41d37f1244be Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 4 May 2018 22:35:20 -0500 Subject: [PATCH 069/305] Stubbed out save_window_pos --- src/GUI/Settings.cpp | 3 +++ src/GUI/Settings.hpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/GUI/Settings.cpp b/src/GUI/Settings.cpp index 8affa6886..8354c54d4 100644 --- a/src/GUI/Settings.cpp +++ b/src/GUI/Settings.cpp @@ -10,6 +10,9 @@ sub save_settings { } */ + } +void Settings::save_window_pos(wxWindow* ref, wxString name) { +} }} // namespace Slic3r::GUI diff --git a/src/GUI/Settings.hpp b/src/GUI/Settings.hpp index 854a88683..0b35f62e7 100644 --- a/src/GUI/Settings.hpp +++ b/src/GUI/Settings.hpp @@ -54,6 +54,8 @@ class Settings { /// Storage for window positions std::map > window_pos { std::map >() }; + void save_window_pos(wxWindow* ref, wxString name); + private: const std::string LogChannel {"GUI_Settings"}; //< Which log these messages should go to. From c68cadbefa3e2eefd89c6b71e8313c34d7110c79 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 4 May 2018 22:35:47 -0500 Subject: [PATCH 070/305] Properly pull slic3r version string from libslic3r --- src/GUI/MainFrame.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 029471f49..fe7fba502 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -4,6 +4,7 @@ #include #include "AboutDialog.hpp" +#include "libslic3r.h" namespace Slic3r { namespace GUI { @@ -29,8 +30,11 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si wxToolTip::SetAutoPop(TOOLTIP_TIMER); // initialize status bar + // we call SetStatusBar() here because MainFrame is the direct owner. this->statusbar = new ProgressStatusBar(this, -1); - this->statusbar->SetStatusText("Version $Slic3r::VERSION - Remember to check for updates at http://slic3r.org/"); + wxString welcome_text {_("Version SLIC3R_VERSION_REPLACE - Remember to check for updates at http://slic3r.org/")}; + welcome_text.Replace("SLIC3R_VERSION_REPLACE", wxString(SLIC3R_VERSION)); + this->statusbar->SetStatusText(welcome_text); this->SetStatusBar(this->statusbar); this->loaded = 1; From 85bfd86bb3f8cdefa8f6e6a5bf91b2310dfa4329 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 4 May 2018 22:39:28 -0500 Subject: [PATCH 071/305] Handle wxEVT_WINDOW_CLOSE --- src/GUI/MainFrame.cpp | 30 +++++++++++++++++++----------- src/GUI/Plater.hpp | 2 ++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index fe7fba502..0c95505c9 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -51,17 +51,14 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si this->Show(); this->Layout(); } -/* - # declare events - EVT_CLOSE($self, sub { - my (undef, $event) = @_; - - if ($event->CanVeto) { - if (!$self->{plater}->prompt_unsaved_changes) { - $event->Veto; + // Set up event handlers. + this->Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent& e) { + if (e.CanVeto()) { + if (!this->plater->prompt_unsaved_changes()) { + e.Veto(); return; } - + /* if ($self->{controller} && $self->{controller}->printing) { my $confirm = Wx::MessageDialog->new($self, "You are currently printing. Do you want to stop printing and continue anyway?", 'Unfinished Print', wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT); @@ -70,10 +67,21 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si return; } } + + */ + // save window size + gui_config->save_window_pos(this, "main_frame"); + + // Propagate event + e.Skip(); } + }); +/* + # declare events + EVT_CLOSE($self, sub { + my (undef, $event) = @_; + - # save window size - wxTheApp->save_window_pos($self, "main_frame"); # propagate event $event->Skip; diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 5068e788e..ecbec1048 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -35,6 +35,8 @@ public: Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings); void add(); + /// Ask if there are any unsaved changes. + bool prompt_unsaved_changes() { return true; } private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; From c012ea6a00d3c036ada8f1385802a3d64af2b854 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 4 May 2018 22:46:50 -0500 Subject: [PATCH 072/305] Implemented ProgressStatusBar --- src/GUI/ProgressStatusBar.cpp | 59 ++++++++++++++++++++++++++++++++++- src/GUI/ProgressStatusBar.hpp | 45 +++++++++++++++++++++++++- src/GUI/misc_ui.hpp | 5 +++ 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/src/GUI/ProgressStatusBar.cpp b/src/GUI/ProgressStatusBar.cpp index 24822748b..ceb909af8 100644 --- a/src/GUI/ProgressStatusBar.cpp +++ b/src/GUI/ProgressStatusBar.cpp @@ -1,5 +1,62 @@ #include "ProgressStatusBar.hpp" - +#include "misc_ui.hpp" namespace Slic3r { namespace GUI { +ProgressStatusBar::ProgressStatusBar(wxWindow* parent, int id) : wxStatusBar(parent, id) { + this->prog->Hide(); + this->cancelbutton->Hide(); + + this->SetFieldsCount(3); + const int tmpWidths[] {-1, 150, 155}; // need to make the array ahead of time in C++ + this->SetStatusWidths(3, tmpWidths); + + // Assign events. + this->Bind(wxEVT_TIMER, [=](wxTimerEvent& e){this->OnTimer(e);}); + this->Bind(wxEVT_SIZE, [=](wxSizeEvent& e){this->OnSize(e);}); + this->Bind(wxEVT_BUTTON, [=](wxCommandEvent& e) { this->cancel_cb(); this->cancelbutton->Hide();}); +} + +ProgressStatusBar::~ProgressStatusBar() { + if (this->timer != nullptr) { + if (this->timer->IsRunning()) + this->timer->Stop(); + } +} + +/// wxPerl version of this used a impromptu hashmap and a loop +/// which more impractical here. +/// Opportunity to refactor here. +void ProgressStatusBar::OnSize(wxSizeEvent &e) { + + // position 0 is reserved for status text + // position 1 is cancel button + // position 2 is prog + + { + wxRect rect; + this->GetFieldRect(1, rect); + const auto& offset = ( wxGTK ? 1 : 0); // cosmetic 1px offset on wxgtk + const auto& pos {wxPoint(rect.x + offset, rect.y + offset)}; + this->cancelbutton->Move(pos); + this->cancelbutton->SetSize(rect.GetWidth() - offset, rect.GetHeight()); + } + + { + wxRect rect; + this->GetFieldRect(2, rect); + const auto& offset = ( wxGTK ? 1 : 0); // cosmetic 1px offset on wxgtk + const auto& pos {wxPoint(rect.x + offset, rect.y + offset)}; + this->prog->Move(pos); + this->prog->SetSize(rect.GetWidth() - offset, rect.GetHeight()); + } + e.Skip(); +} + +void ProgressStatusBar::OnTimer(wxTimerEvent& e) { + if (this->prog->IsShown()) + this->timer->Stop(); + if (this->busy) + this->prog->Pulse(); +} + }} // Namespace Slic3r::GUI diff --git a/src/GUI/ProgressStatusBar.hpp b/src/GUI/ProgressStatusBar.hpp index f2984691b..44e6dd60c 100644 --- a/src/GUI/ProgressStatusBar.hpp +++ b/src/GUI/ProgressStatusBar.hpp @@ -2,13 +2,56 @@ #define PROGRESSSTATUSBAR_HPP #include #include +#include +#include +#include namespace Slic3r { namespace GUI { class ProgressStatusBar : public wxStatusBar { public: /// Constructor stub from parent - ProgressStatusBar(wxWindow* parent, int id) : wxStatusBar(parent, id) { } + ProgressStatusBar(wxWindow* parent, int id); + + /// Stop any running timers before destruction. + ~ProgressStatusBar(); + + /// + wxTimer* timer {new wxTimer(this)}; + + /// Progress bar + wxGauge* prog {new wxGauge(this, wxGA_HORIZONTAL, 100, wxDefaultPosition, wxDefaultSize)}; + + /// General cancel button. Using applications can assign functions to it. + wxButton* cancelbutton {new wxButton(this, -1, _("Cancel"), wxDefaultPosition, wxDefaultSize)}; + + /// Set callback function for cancel button press. + void SetCancelCallback(std::function cb) { + this->cancel_cb = cb; + cb == nullptr ? this->cancelbutton->Hide() : this->cancelbutton->Show(); + } + + /// Accessor function for the current value of the progress bar + size_t GetProgress() {return this->prog->GetValue();} + + /// Accessor function for busy state + bool IsBusy() {return this->busy;} + + /// Show the progress bar. + void ShowProgress(bool show = true) { this->prog->Show(show); this->prog->Pulse(); } + + void SetRange(int range) { if (range != this->prog->GetRange() ) this->prog->SetRange(range);} + +private: + void OnSize(wxSizeEvent& e); + void OnTimer(wxTimerEvent& e); + void Run(int rate = 100) { if (this->timer->IsRunning()) this->timer->Start(rate);}; + + // Cancel callback function + std::function cancel_cb {[](){;}}; + + bool busy {false}; + }; }} // Namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index e733fe565..90ad19070 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -27,6 +27,11 @@ constexpr OS the_os = OS::Windows; constexpr OS the_os = OS::Mac; #elif __linux__ constexpr OS the_os = OS::Linux; + #ifdef __WXGTK__ + constexpr bool wxGTK {true}; + #else + constexpr bool wxGTK {false}; + #endif #endif #ifdef SLIC3R_DEV From e2fdb00bb0f8379bdf5a3554f696925897b653f4 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 4 May 2018 22:47:06 -0500 Subject: [PATCH 073/305] removed commented Perl code from MainFrame --- src/GUI/MainFrame.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 0c95505c9..82e2b0f09 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -76,17 +76,6 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si e.Skip(); } }); -/* - # declare events - EVT_CLOSE($self, sub { - my (undef, $event) = @_; - - - - # propagate event - $event->Skip; - }); -*/ } /// Private initialization function for the main frame tab panel. From 9235a52dceca4f285f207700ee24f69ea0c49125 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 4 May 2018 22:47:49 -0500 Subject: [PATCH 074/305] stubbed out Plater::select_object() and uncommented its use in a lambda being assigned to on_select_object. --- src/GUI/Plater.cpp | 4 ++-- src/GUI/Plater.hpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 623299215..3ac360799 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -22,8 +22,8 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrselect_object(obj_idx); + auto on_select_object { [=](size_t& obj_idx) { + this->select_object(obj_idx); } }; /* # Initialize handlers for canvases diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index ecbec1048..726040892 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -72,6 +72,8 @@ private: bool outside_bounds {false}; MainFrame* GetFrame(); + void select_object(size_t& obj_idx) { }; + }; From ea94cb750682bad0bf457f188fc2378c9b208756 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 4 May 2018 23:20:03 -0500 Subject: [PATCH 075/305] Fleshed out a StartBusy() function and moved Run to be public. Also added functional as a header. --- src/GUI/ProgressStatusBar.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/GUI/ProgressStatusBar.hpp b/src/GUI/ProgressStatusBar.hpp index 44e6dd60c..dfb792e8b 100644 --- a/src/GUI/ProgressStatusBar.hpp +++ b/src/GUI/ProgressStatusBar.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace Slic3r { namespace GUI { @@ -42,10 +43,14 @@ public: void SetRange(int range) { if (range != this->prog->GetRange() ) this->prog->SetRange(range);} + /// Start the timer. + void Run(int rate = 100) { if (this->timer->IsRunning()) this->timer->Start(rate);}; + + void StartBusy(int rate = 100) { this->busy = true; this->ShowProgress(true); if (!this->timer->IsRunning()) this->timer->Start(rate); } + private: void OnSize(wxSizeEvent& e); void OnTimer(wxTimerEvent& e); - void Run(int rate = 100) { if (this->timer->IsRunning()) this->timer->Start(rate);}; // Cancel callback function std::function cancel_cb {[](){;}}; From 25d9c110a6b025736bd2856e69e084f297340b32 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 4 May 2018 23:39:38 -0500 Subject: [PATCH 076/305] ripped out most of the perl-dependent stuff from Slic3r's archive build script on Linux (do less useless stuff on Travis). --- package/linux/appimage.sh | 4 +--- package/linux/libpaths.txt | 5 ----- package/linux/make_archive.sh | 42 +++-------------------------------- 3 files changed, 4 insertions(+), 47 deletions(-) diff --git a/package/linux/appimage.sh b/package/linux/appimage.sh index 3a68b5e17..05e61f909 100755 --- a/package/linux/appimage.sh +++ b/package/linux/appimage.sh @@ -32,7 +32,7 @@ cd $WD/${APP}.AppDir mkdir -p $WD/${APP}.AppDir/usr/bin # Copy primary Slic3r script here and perl-local, as well as var -for i in {var,slic3r.pl,perl-local}; do +for i in {var,Slic3r}; do cp -R $srcfolder/$i $WD/${APP}.AppDir/usr/bin/ done @@ -48,8 +48,6 @@ for i in $(cat $WD/libpaths.appimage.txt | grep -v "^#" | awk -F# '{print $1}'); done -cp -R $srcfolder/local-lib ${WD}/${APP}.AppDir/usr/lib/local-lib - cat > $WD/${APP}.AppDir/AppRun << 'EOF' #!/usr/bin/env bash # some magic to find out the real location of this script dealing with symlinks diff --git a/package/linux/libpaths.txt b/package/linux/libpaths.txt index ef876a13a..3c64c9758 100644 --- a/package/linux/libpaths.txt +++ b/package/linux/libpaths.txt @@ -1,8 +1,3 @@ -/home/travis/builds/alexrj/Slic3r/local-lib/lib/perl5/x86_64-linux-thread-multi/Alien/wxWidgets/gtk_3_0_2_uni/lib/libwx_baseu-3.0.so.0 -/home/travis/builds/alexrj/Slic3r/local-lib/lib/perl5/x86_64-linux-thread-multi/Alien/wxWidgets/gtk_3_0_2_uni/lib/libwx_gtk2u_adv-3.0.so.0 -/home/travis/builds/alexrj/Slic3r/local-lib/lib/perl5/x86_64-linux-thread-multi/Alien/wxWidgets/gtk_3_0_2_uni/lib/libwx_gtk2u_core-3.0.so.0 -/home/travis/builds/alexrj/Slic3r/local-lib/lib/perl5/x86_64-linux-thread-multi/Alien/wxWidgets/gtk_3_0_2_uni/lib/libwx_gtk2u_gl-3.0.so.0 -/home/travis/builds/alexrj/Slic3r/local-lib/lib/perl5/x86_64-linux-thread-multi/Alien/wxWidgets/gtk_3_0_2_uni/lib/libwx_gtk2u_html-3.0.so.0 /lib/x86_64-linux-gnu/liblzma.so.5 /lib/x86_64-linux-gnu/libpng12.so.0 /usr/lib/x86_64-linux-gnu/libjpeg.so.8 diff --git a/package/linux/make_archive.sh b/package/linux/make_archive.sh index ad87b2a06..3eaf8b601 100755 --- a/package/linux/make_archive.sh +++ b/package/linux/make_archive.sh @@ -10,7 +10,6 @@ if [ "$#" -ne 1 ]; then echo "Usage: $(basename $0) arch_name" exit 1; fi -libdirs=$(find ./local-lib -iname *.so -exec dirname {} \; | sort -u | paste -sd ";" -) WD=./$(dirname $0) source $(dirname $0)/../common/util.sh # Determine if this is a tagged (release) commit. @@ -22,7 +21,6 @@ set_build_id set_branch set_app_name set_pr_id -install_par # If we're on a branch, add the branch name to the app name. if [ "$current_branch" == "master" ]; then @@ -35,8 +33,7 @@ else dmgfile=slic3r-${SLIC3R_BUILD_ID}-${1}-${current_branch}.tar.bz2 fi -rm -rf $WD/_tmp -mkdir -p $WD/_tmp +mkdir -p $WD # Set the application folder infomation. appfolder="$WD/${appname}" @@ -46,8 +43,6 @@ resourcefolder=$appfolder echo "Appfolder: $appfolder, archivefolder: $archivefolder" # Our slic3r dir and location of perl -PERL_BIN=$(which perl) -PP_BIN=$(which pp) SLIC3R_DIR="./" if [[ -d "${appfolder}" ]]; then @@ -67,14 +62,12 @@ echo "Copying resources..." cp -rf $SLIC3R_DIR/var $resourcefolder/ echo "Copying Slic3r..." -cp $SLIC3R_DIR/slic3r.pl $archivefolder/slic3r.pl -cp -fRP $SLIC3R_DIR/local-lib $archivefolder/local-lib -cp -fRP $SLIC3R_DIR/lib/* $archivefolder/local-lib/lib/perl5/ +cp $SLIC3R_DIR/slic3r $archivefolder/Slic3r mkdir $archivefolder/bin echo "Installing libraries to $archivefolder/bin ..." if [ -z ${WXDIR+x} ]; then - for bundle in $(find $archivefolder/local-lib/lib/perl5 -name '*.so' | grep "Wx") $(find $archivefolder/local-lib/lib/perl5 -name '*.so' -type f | grep "wxWidgets"); do + for bundle in $archivefolder/Slic3r; do echo "$(LD_LIBRARY_PATH=$libdirs ldd $bundle | grep .so | grep local-lib | awk '{print $3}')" for dylib in $(LD_LIBRARY_PATH=$libdirs ldd $bundle | grep .so | grep local-lib | awk '{print $3}'); do install -v $dylib $archivefolder/bin @@ -91,37 +84,8 @@ echo "Copying startup script..." cp -f $WD/startup_script.sh $archivefolder/$appname chmod +x $archivefolder/$appname -echo "Copying perl from $PERL_BIN" -# Edit package/common/coreperl to add/remove core Perl modules added to this package, one per line. -cp -f $PERL_BIN $archivefolder/perl-local -${PP_BIN} wxextension .0 \ - -M $(grep -v "^#" ${WD}/../common/coreperl | xargs | awk 'BEGIN { OFS=" -M "}; {$1=$1; print $0}') \ - -B -p -e "print 123" -o $WD/_tmp/test.par -unzip -qq -o $WD/_tmp/test.par -d $WD/_tmp/ -cp -rf $WD/_tmp/lib/* $archivefolder/local-lib/lib/perl5/ -cp -rf $WD/_tmp/shlib $archivefolder/ -rm -rf $WD/_tmp for i in $(cat $WD/libpaths.txt | grep -v "^#" | awk -F# '{print $1}'); do install -v $i $archivefolder/bin done -echo "Cleaning local-lib" -rm -rf $archivefolder/local-lib/bin -rm -rf $archivefolder/local-lib/man -rm -f $archivefolder/local-lib/lib/perl5/Algorithm/*.pl -rm -rf $archivefolder/local-lib/lib/perl5/unicore -rm -rf $archivefolder/local-lib/lib/perl5/App -rm -rf $archivefolder/local-lib/lib/perl5/Devel/CheckLib.pm -rm -rf $archivefolder/local-lib/lib/perl5/ExtUtils -rm -rf $archivefolder/local-lib/lib/perl5/Module/Build* -rm -rf $(pwd)$archivefolder/local-lib/lib/perl5/TAP -rm -rf $(pwd)/$archivefolder/local-lib/lib/perl5/Test* -find $(pwd)/$archivefolder/local-lib -type d -path '*/Wx/*' \( -name WebView \ - -or -name DocView -or -name STC -or -name IPC \ - -or -name Calendar -or -name DataView \ - -or -name DateTime -or -name Media -or -name PerlTest \ - -or -name Ribbon \) -exec rm -rf "{}" \; -rm -rf $archivefolder/local-lib/lib/perl5/*/Alien/wxWidgets/*/include -find $archivefolder/local-lib -depth -type d -empty -exec rmdir "{}" \; - tar -C$(pwd)/$(dirname $appfolder) -cjf $(pwd)/$dmgfile "$appname" From 46edadb0cd271e514bbaa585a7ecdc070b5789a4 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 4 May 2018 23:52:25 -0500 Subject: [PATCH 077/305] Look for static wxwidgets and static boost if SLIC3R_STATIC is defined. --- src/CMakeLists.txt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cf8958389..86753350d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,8 +24,14 @@ ELSE(CMAKE_HOST_APPLE) # set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -L.") ENDIF(CMAKE_HOST_APPLE) -set(Boost_USE_STATIC_LIBS OFF) -set(Boost_USE_STATIC_RUNTIME OFF) +if(DEFINED ENV{SLIC3R_STATIC}) + set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_STATIC_RUNTIME ON) +else(DEFINED ENV{SLIC3R_STATIC}) + set(Boost_USE_STATIC_LIBS OFF) + set(Boost_USE_STATIC_RUNTIME OFF) +endif(DEFINED ENV{SLIC3R_STATIC}) + find_package(Threads REQUIRED) find_package(Boost COMPONENTS system thread filesystem) @@ -154,7 +160,12 @@ add_library(bthread SHARED IMPORTED) set_target_properties(bthread PROPERTIES IMPORTED_LOCATION ${bthread_l}) include_directories(${Boost_INCLUDE_DIRS}) -set(wxWidgets_USE_STATIC OFF) +if(DEFINED ENV{SLIC3R_STATIC}) + set(wxWidgets_USE_STATIC ON) +ELSE(DEFINED ENV{SLIC3R_STATIC}) + set(wxWidgets_USE_STATIC OFF) +ENDIF(DEFINED ENV{SLIC3R_STATIC}) + set(wxWidgets_USE_UNICODE ON) find_package(wxWidgets COMPONENTS base aui core html) From a73366b00ed16be652cce9b4780eeac5d3046e55 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 00:16:44 -0500 Subject: [PATCH 078/305] fix the startup script to point at the binary. --- package/linux/startup_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/linux/startup_script.sh b/package/linux/startup_script.sh index 30f0e2c69..dbe4d7981 100644 --- a/package/linux/startup_script.sh +++ b/package/linux/startup_script.sh @@ -3,4 +3,4 @@ BIN=$(readlink "$0") DIR=$(dirname "$BIN") export LD_LIBRARY_PATH="$DIR/bin" -exec "$DIR/perl-local" -I"$DIR/local-lib/lib/perl5" "$DIR/slic3r.pl" $@ +exec "$DIR/Slic3r" From 897b595db856883a6ce77c6c893ddb7b92f69d7c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 00:17:32 -0500 Subject: [PATCH 079/305] Set compile configuration variables if they are in the environment for the path to slic3r var dir --- .travis.yml | 1 + src/CMakeLists.txt | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 34940401f..c5d7c00a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ install: - export SLIC3R_STATIC=1 - export CXX=g++-7 - export CC=gcc-7 +- export SLIC3R_VAR_REL=./var script: - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR src/ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 86753350d..0a8b9f9b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,20 @@ project (slic3r) # only on newer GCCs: -ftemplate-backtrace-limit=0 -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") +set(CMAKE_CXX_FLAGS "-g ${CMAKE_CXX_FLAGS} -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") + +if(DEFINED ENV{SLIC3R_VAR_REL}) + set(CMAKE_CXX_FLAGS "-DVAR_REL=$ENV{SLIC3R_VAR_REL}") +endif(DEFINED ENV{SLIC3R_VAR_REL}) + +if(DEFINED ENV{SLIC3R_VAR_ABS}) + set(CMAKE_CXX_FLAGS "-DVAR_ABS") +endif(DEFINED ENV{SLIC3R_VAR_ABS}) + +if(DEFINED ENV{SLIC3R_VAR_ABS_PATH}) + set(CMAKE_CXX_FLAGS "-DVAR_ABS_PATH=$ENV{SLIC3R_VAR_ABS_PATH}") +endif(DEFINED ENV{SLIC3R_VAR_ABS_PATH}) + execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_VERSION ERROR_QUIET) From 9c154a6b2d8e65f4c48fb3e9e5cf7598528831c7 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 00:30:46 -0500 Subject: [PATCH 080/305] not using var rel because its expansion needs to be fixed in misc_ui.hpp --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c5d7c00a1..34940401f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ install: - export SLIC3R_STATIC=1 - export CXX=g++-7 - export CC=gcc-7 -- export SLIC3R_VAR_REL=./var script: - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR src/ From 0af528845c66136ab39262e58fab554229bfed86 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 12:48:24 -0500 Subject: [PATCH 081/305] Finished implementing ProgressStatusBar class --- src/GUI/ProgressStatusBar.cpp | 12 ++++++++++++ src/GUI/ProgressStatusBar.hpp | 16 ++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/GUI/ProgressStatusBar.cpp b/src/GUI/ProgressStatusBar.cpp index ceb909af8..b3f47f1ed 100644 --- a/src/GUI/ProgressStatusBar.cpp +++ b/src/GUI/ProgressStatusBar.cpp @@ -52,6 +52,18 @@ void ProgressStatusBar::OnSize(wxSizeEvent &e) { e.Skip(); } +void ProgressStatusBar::SetProgress(size_t val) { + if (!this->prog->IsShown()) { + this->ShowProgress(true); + } + if (val == this->prog->GetRange()) { + this->prog->SetValue(0); + this->ShowProgress(false); + } else { + this->prog->SetValue(val); + } +} + void ProgressStatusBar::OnTimer(wxTimerEvent& e) { if (this->prog->IsShown()) this->timer->Stop(); diff --git a/src/GUI/ProgressStatusBar.hpp b/src/GUI/ProgressStatusBar.hpp index dfb792e8b..e295dbd6a 100644 --- a/src/GUI/ProgressStatusBar.hpp +++ b/src/GUI/ProgressStatusBar.hpp @@ -32,21 +32,25 @@ public: cb == nullptr ? this->cancelbutton->Hide() : this->cancelbutton->Show(); } - /// Accessor function for the current value of the progress bar - size_t GetProgress() {return this->prog->GetValue();} - - /// Accessor function for busy state - bool IsBusy() {return this->busy;} - /// Show the progress bar. void ShowProgress(bool show = true) { this->prog->Show(show); this->prog->Pulse(); } + /// Accessor function for the current value of the progress bar + inline size_t GetProgress() {return this->prog->GetValue();} + + /// Accessor set function for the current value of the progress bar + void SetProgress(size_t val); + void SetRange(int range) { if (range != this->prog->GetRange() ) this->prog->SetRange(range);} /// Start the timer. void Run(int rate = 100) { if (this->timer->IsRunning()) this->timer->Start(rate);}; void StartBusy(int rate = 100) { this->busy = true; this->ShowProgress(true); if (!this->timer->IsRunning()) this->timer->Start(rate); } + void StopBusy() { this->timer->Stop(); this->ShowProgress(false); this->prog->SetValue(0); this->busy = false;} + + /// Accessor function for busy state + bool IsBusy() {return this->busy;} private: void OnSize(wxSizeEvent& e); From e32be5a2244271f5a7df00e230e4bde98e76dfb5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 12:48:36 -0500 Subject: [PATCH 082/305] sorted GUI files --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a8b9f9b0..6db5c038e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -210,9 +210,9 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/Plater.cpp - ${GUI_LIBDIR}/ProgressStatusBar.cpp ${GUI_LIBDIR}/Plater/Plate2D.cpp ${GUI_LIBDIR}/Plater/PlaterObject.cpp + ${GUI_LIBDIR}/ProgressStatusBar.cpp ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp ) From 91edf908f286bb0a6b0749edb82a35cc71ba30c0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 12:56:24 -0500 Subject: [PATCH 083/305] Stubbed restore_window_pos --- src/GUI/MainFrame.cpp | 1 + src/GUI/Settings.cpp | 3 +++ src/GUI/Settings.hpp | 1 + 3 files changed, 5 insertions(+) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 82e2b0f09..d39d0b363 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -48,6 +48,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si this->SetMinSize(wxSize(760, 490)); this->SetSize(this->GetMinSize()); wxTheApp->SetTopWindow(this); + gui_config->restore_window_pos(this, "main_frame"); this->Show(); this->Layout(); } diff --git a/src/GUI/Settings.cpp b/src/GUI/Settings.cpp index 8354c54d4..23d5808d5 100644 --- a/src/GUI/Settings.cpp +++ b/src/GUI/Settings.cpp @@ -15,4 +15,7 @@ sub save_settings { void Settings::save_window_pos(wxWindow* ref, wxString name) { } + +void Settings::restore_window_pos(wxWindow* ref, wxString name) { +} }} // namespace Slic3r::GUI diff --git a/src/GUI/Settings.hpp b/src/GUI/Settings.hpp index 0b35f62e7..aaa9bd72b 100644 --- a/src/GUI/Settings.hpp +++ b/src/GUI/Settings.hpp @@ -55,6 +55,7 @@ class Settings { std::map > window_pos { std::map >() }; void save_window_pos(wxWindow* ref, wxString name); + void restore_window_pos(wxWindow* ref, wxString name); private: const std::string LogChannel {"GUI_Settings"}; //< Which log these messages should go to. From 2b91524619ad2406e43c347dccb03e55dddbe5d9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 12:57:31 -0500 Subject: [PATCH 084/305] Remember to actually set the sizer. --- src/GUI/MainFrame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index d39d0b363..1452d0cc3 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -30,7 +30,6 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si wxToolTip::SetAutoPop(TOOLTIP_TIMER); // initialize status bar - // we call SetStatusBar() here because MainFrame is the direct owner. this->statusbar = new ProgressStatusBar(this, -1); wxString welcome_text {_("Version SLIC3R_VERSION_REPLACE - Remember to check for updates at http://slic3r.org/")}; welcome_text.Replace("SLIC3R_VERSION_REPLACE", wxString(SLIC3R_VERSION)); @@ -44,6 +43,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si wxSizer* sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(this->tabpanel, 1, wxEXPAND); sizer->SetSizeHints(this); + this->SetSizer(sizer); this->Fit(); this->SetMinSize(wxSize(760, 490)); this->SetSize(this->GetMinSize()); From 4860d63b01aa2dea64fba63ef15d353a1e82c7bf Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 16:10:43 -0500 Subject: [PATCH 085/305] Add static method to create scaled Polygons from Pointf arrays. --- xs/src/libslic3r/Polygon.cpp | 11 +++++++++++ xs/src/libslic3r/Polygon.hpp | 2 ++ 2 files changed, 13 insertions(+) diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index b14b7d0fa..d809294f1 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -293,4 +293,15 @@ Polygon::convex_points(double angle) const return convex; } +Polygon Polygon::new_scale(const Pointfs& p) { + Points scaled_p; + for (auto i : p) { + // scale each individual point and append to a new array + scaled_p.push_back(scale_(i.x), scale_(i.y)); + } + return Slic3r::Polygon(scaled_p); +}; + + + } diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index b1576ad27..1534de40c 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -48,6 +48,8 @@ class Polygon : public MultiPoint { std::string wkt() const; Points concave_points(double angle = PI) const; Points convex_points(double angle = PI) const; + + static Polygon new_scale(const Pointfs& p); }; inline Polygons From dc08bcafaeba8b6abc816bab7c6468b7c601732a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 16:13:34 -0500 Subject: [PATCH 086/305] Added template function to make getting references to ConfigOptions easier to write. --- xs/src/libslic3r/Config.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index a4c7fa470..e2049cd32 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -16,6 +16,13 @@ public: void write_ini(const std::string& file) { save(file); } void read_ini(const std::string& file) { load(file); } + + /// Template function to retrieve and cast in hopefully a slightly nicer + /// format than longwinded dynamic_cast<> + template + T& get(const t_config_option_key& opt_key, bool create=false) { + return *(dynamic_cast(this->optptr(opt_key, create))); + } }; } // namespace Slic3r From 2c2ad2c992625b38f15eee2a9614fdd4f27e8381 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 16:13:58 -0500 Subject: [PATCH 087/305] Changed identifier type to size_t (needs to be numerical to do math on it) --- src/GUI/Plater/PlaterObject.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp index 72b71d88e..7fb6602cb 100644 --- a/src/GUI/Plater/PlaterObject.hpp +++ b/src/GUI/Plater/PlaterObject.hpp @@ -13,7 +13,7 @@ namespace Slic3r { namespace GUI { class PlaterObject { public: wxString name {L""}; - wxString identifier {L""}; + size_t identifier {0U}; wxString input_file {L""}; int input_file_obj_idx {-1}; From b0d552ce4e735a7e977f946b2764600d5912b7af Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 17:35:28 -0500 Subject: [PATCH 088/305] Add macro to take advantage of wxString << --- src/GUI/misc_ui.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index 90ad19070..eebefd015 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -15,6 +15,11 @@ #include "Log.hpp" + +/// Macro to build std::wstring that slic3r::log expects using << syntax of wxString +/// Avoids wx pollution of libslic3r +#define LOG_WSTRING(...) ((wxString("") << __VA_ARGS__).ToStdWstring()) + /// Common static (that is, free-standing) functions, not part of an object hierarchy. namespace Slic3r { namespace GUI { From a620e2ee133bba53aeb130dd6f386ee213d57e47 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 17:35:53 -0500 Subject: [PATCH 089/305] Fixed arguments for Polygon::new_scale --- xs/src/libslic3r/Polygon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index d809294f1..a3bebb034 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -297,7 +297,7 @@ Polygon Polygon::new_scale(const Pointfs& p) { Points scaled_p; for (auto i : p) { // scale each individual point and append to a new array - scaled_p.push_back(scale_(i.x), scale_(i.y)); + scaled_p.push_back(Slic3r::Point(scale_(i.x), scale_(i.y))); } return Slic3r::Polygon(scaled_p); }; From 574f77ec165273f66d8c4be7fcedf0131bfe2b04 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 17:36:20 -0500 Subject: [PATCH 090/305] Added generic error message to Log; print error type to console. --- xs/src/libslic3r/Log.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xs/src/libslic3r/Log.hpp b/xs/src/libslic3r/Log.hpp index 419448a88..5eddac995 100644 --- a/xs/src/libslic3r/Log.hpp +++ b/xs/src/libslic3r/Log.hpp @@ -8,17 +8,21 @@ namespace Slic3r { class Log { public: static void fatal_error(std::string topic, std::wstring message) { - std::cerr << topic << ": "; + std::cerr << topic << " FERR" << ": "; + std::wcerr << message << std::endl; + } + static void error(std::string topic, std::wstring message) { + std::cerr << topic << " ERR" << ": "; std::wcerr << message << std::endl; } static void info(std::string topic, std::wstring message) { - std::clog << topic << ": "; + std::clog << topic << " INFO" << ": "; std::wclog << message << std::endl; } static void warn(std::string topic, std::wstring message) { - std::cerr << topic << ": "; + std::cerr << topic << " WARN" << ": "; std::wcerr << message << std::endl; } From 904e7d749ee66910c1ab03cfd8c66fd38640e110 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 5 May 2018 17:37:13 -0500 Subject: [PATCH 091/305] Implemented load_model_objects, fleshed out add() more. Implemented bed_centerf(). --- src/GUI/Plater.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++-- src/GUI/Plater.hpp | 5 +++ 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 3ac360799..16a74a828 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -126,8 +126,21 @@ void Plater::add() { if (start_object_id == this->object_identifier) return; // save the added objects - + auto new_model {this->model}; + // get newly added objects count + auto new_objects_count = this->object_identifier - start_object_id; + + Slic3r::Log::info(LogChannel, (wxString("Obj id:") << object_identifier).ToStdWstring()); + for (auto i = start_object_id; i < new_objects_count + start_object_id; i++) { + const auto& obj_idx {this->get_object_index(i)}; + new_model->add_object(*(this->model->objects.at(obj_idx))); + } + Slic3r::Log::info(LogChannel, (wxString("Obj id:") << object_identifier).ToStdWstring()); + + // Prepare for undo + //this->add_undo_operation("ADD", nullptr, new_model, start_object_id); + } @@ -145,11 +158,13 @@ std::vector Plater::load_file(const wxString& file, const int obj_idx_to_lo progress_dialog->Pulse(); //TODO: Add a std::wstring so we can handle non-roman characters as file names. try { - auto model {Slic3r::Model::read_from_file(file.ToStdString())}; + model = Slic3r::Model::read_from_file(file.ToStdString()); } catch (std::runtime_error& e) { show_error(this, e.what()); + Slic3r::Log::error(LogChannel, LOG_WSTRING(file << " failed to load: " << e.what())); valid_load = false; } + Slic3r::Log::info(LogChannel, LOG_WSTRING("load_valid is " << valid_load)); if (valid_load) { if (model.looks_like_multipart_object()) { @@ -172,12 +187,15 @@ std::vector Plater::load_file(const wxString& file, const int obj_idx_to_lo } auto i {0U}; if (obj_idx_to_load > 0) { + Slic3r::Log::info(LogChannel, L"Loading model objects, obj_idx_to_load > 0"); const size_t idx_load = obj_idx_to_load; if (idx_load >= model.objects.size()) return std::vector(); obj_idx = this->load_model_objects(model.objects.at(idx_load)); i = idx_load; } else { + Slic3r::Log::info(LogChannel, L"Loading model objects, obj_idx_to_load = 0"); obj_idx = this->load_model_objects(model.objects); + Slic3r::Log::info(LogChannel, LOG_WSTRING("obj_idx size: " << obj_idx.size())); } for (const auto &j : obj_idx) { @@ -206,11 +224,77 @@ std::vector Plater::load_model_objects(ModelObject* model_object) { return load_model_objects(tmp); } std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { - return std::vector(); + auto bed_center {this->bed_centerf()}; + + auto bed_shape {Slic3r::Polygon::new_scale(this->config->get("bed_shape").values)}; + auto bed_size {bed_shape.bounding_box().size()}; + + bool need_arrange {false}; + + auto obj_idx {std::vector()}; + Slic3r::Log::info(LogChannel, LOG_WSTRING("Objects: " << model_objects.size())); + + for (auto& obj : model_objects) { + auto o {this->model->add_object(*obj)}; + o->repair(); + + auto tmpobj {PlaterObject()}; + const auto objfile {wxFileName::FileName( obj->input_file )}; + tmpobj.name = wxString(std::string() == obj->name ? obj->name : objfile.GetName()); + tmpobj.identifier = (this->object_identifier)++; + + this->objects.push_back(tmpobj); + obj_idx.push_back(this->objects.size()); + Slic3r::Log::info(LogChannel, LOG_WSTRING("Object array new size: " << this->objects.size())); + Slic3r::Log::info(LogChannel, LOG_WSTRING("Instances: " << obj->instances.size())); + + if (obj->instances.size() == 0) { + if (settings->autocenter) { + need_arrange = true; + o->center_around_origin(); + + o->add_instance(); + o->instances.back()->offset = this->bed_centerf(); + } else { + need_arrange = false; + if (settings->autoalignz) { + o->align_to_ground(); + } + o->add_instance(); + } + } else { + if (settings->autoalignz) { + o->align_to_ground(); + } + } + { + // If the object is too large (more than 5x the bed) scale it down. + auto size {o->bounding_box().size()}; + double ratio {0.0f}; + if (ratio > 5) { + for (auto& instance : o->instances) { + instance->scaling_factor = (1.0f/ratio); + this->scaled_down = true; + } + } + } + + { + // Provide a warning if downscaling by 5x still puts it over the bed size. + + } + } + return obj_idx; } MainFrame* Plater::GetFrame() { return dynamic_cast(wxGetTopLevelParent(this)); } +int Plater::get_object_index(size_t object_id) { + for (size_t i = 0U; i < this->objects.size(); i++) { + if (this->objects.at(i).identifier == object_id) return static_cast(i); + } + return -1; +} }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 726040892..7f84f0ca1 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -73,7 +73,12 @@ private: MainFrame* GetFrame(); void select_object(size_t& obj_idx) { }; + int get_object_index(size_t object_id); + Slic3r::Pointf bed_centerf() { + auto bed_shape { Slic3r::Polygon::new_scale(this->config->get("bed_shape").values) }; + return Slic3r::Pointf(); + } }; From b541bc208f75547acf63cef4b87bf209dfb90e66 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 17:55:59 -0500 Subject: [PATCH 092/305] Avoid using wxString Printf, instead use Format() and use wxRealPoint (floating point) instead of wxPoint (integer) --- src/GUI/Plater/Plate2D.cpp | 7 ++----- src/GUI/Plater/Plate2D.hpp | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index fb0b172a9..e2a4162bf 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -76,11 +76,8 @@ void Plate2D::repaint(wxPaintEvent& e) { dc->SetTextForeground(wxColor(0,0,0)); dc->SetFont(wxFont(10, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); - wxString val {}; - val.Printf("X = %.0f", this->print_center.x); - dc->DrawLabel(val , wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); - val.Printf("Y = %.0f", this->print_center.y); - dc->DrawRotatedText(val, 0, center.y + 15, 90); + dc->DrawLabel(wxString::Format("X = %.0f", this->print_center.x), wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); + dc->DrawRotatedText(wxString::Format("Y = %.0f", this->print_center.y), 0, center.y + 15, 90); } } diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 61c097422..1db726a11 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -90,8 +90,8 @@ private: void update_bed_size(); /// private class variables to stash bits for drawing the print bed area. - wxPoint bed_origin {}; - wxPoint print_center {}; + wxRealPoint bed_origin {}; + wxRealPoint print_center {}; Slic3r::Polygon bed_polygon {}; std::vector grid {}; From 10f4bf9be9e5ecd99b04a3ce126ef048808493a0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 19:36:28 -0500 Subject: [PATCH 093/305] add log function to build strings for vectors --- xs/src/libslic3r/Log.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xs/src/libslic3r/Log.hpp b/xs/src/libslic3r/Log.hpp index 5eddac995..255b2e7a6 100644 --- a/xs/src/libslic3r/Log.hpp +++ b/xs/src/libslic3r/Log.hpp @@ -2,6 +2,8 @@ #define slic3r_LOG_HPP #include +#include +#include namespace Slic3r { @@ -28,6 +30,28 @@ public: }; +/// Utility debug function to transform a std::vector of anything that +/// supports ostream& operator<<() into a std::string. +template +std::string +log_string(const std::vector& in) +{ + std::stringstream ss; + bool first {true}; + ss << "[ "; + for (auto& c : in) { + if (!first) { + ss << ", "; + } + ss << c; + first = false; + } + + ss << " ]"; + + return ss.str(); +} + } #endif // slic3r_LOG_HPP From 2e74c9f3ada5390d8acaf431c0177f557158f85e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 19:37:25 -0500 Subject: [PATCH 094/305] Remember that std::vector<>.size() needs to be offset by 1 if it's being used to find the last index. --- src/GUI/Plater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 16a74a828..d94e51005 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -244,7 +244,7 @@ std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { tmpobj.identifier = (this->object_identifier)++; this->objects.push_back(tmpobj); - obj_idx.push_back(this->objects.size()); + obj_idx.push_back(this->objects.size() - 1); Slic3r::Log::info(LogChannel, LOG_WSTRING("Object array new size: " << this->objects.size())); Slic3r::Log::info(LogChannel, LOG_WSTRING("Instances: " << obj->instances.size())); From ad2295639189a53ef3de3922c7ffff7a06f35155 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 19:38:11 -0500 Subject: [PATCH 095/305] Use .at() instead of [] because that'll throw an exception if out of bounds instead of a hard-to-find memory crash. --- src/GUI/Plater.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index d94e51005..994adbe44 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -199,8 +199,8 @@ std::vector Plater::load_file(const wxString& file, const int obj_idx_to_lo } for (const auto &j : obj_idx) { - this->objects[j].input_file = file; - this->objects[j].input_file_obj_idx = i++; + this->objects.at(j).input_file = file; + this->objects.at(j).input_file_obj_idx = i++; } GetFrame()->statusbar->SetStatusText(_("Loaded ") + input_file.GetName()); From 08611ffc8ca282df39a3ee47d0fefa67cd205df8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 19:39:34 -0500 Subject: [PATCH 096/305] Use std::string internally instead of wxString. --- src/GUI/Plater.cpp | 10 +++++----- src/GUI/Plater.hpp | 2 +- src/GUI/Plater/PlaterObject.hpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 994adbe44..02cfae165 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -119,7 +119,7 @@ void Plater::add() { const auto& input_files{open_model(this, *(this->settings), wxTheApp->GetTopWindow())}; for (const auto& f : input_files) { Log::info(LogChannel, (wxString(L"Calling Load File for ") + f).ToStdWstring()); - this->load_file(f); + this->load_file(f.ToStdString()); } // abort if no objects actually added. @@ -144,7 +144,7 @@ void Plater::add() { } -std::vector Plater::load_file(const wxString& file, const int obj_idx_to_load) { +std::vector Plater::load_file(const std::string file, const int obj_idx_to_load) { auto input_file {wxFileName(file)}; settings->skein_directory = input_file.GetPath(); @@ -158,7 +158,7 @@ std::vector Plater::load_file(const wxString& file, const int obj_idx_to_lo progress_dialog->Pulse(); //TODO: Add a std::wstring so we can handle non-roman characters as file names. try { - model = Slic3r::Model::read_from_file(file.ToStdString()); + model = Slic3r::Model::read_from_file(file); } catch (std::runtime_error& e) { show_error(this, e.what()); Slic3r::Log::error(LogChannel, LOG_WSTRING(file << " failed to load: " << e.what())); @@ -177,10 +177,10 @@ std::vector Plater::load_file(const wxString& file, const int obj_idx_to_lo for (auto i = 0U; i < model.objects.size(); i++) { auto object {model.objects[i]}; - object->input_file = file.ToStdString(); + object->input_file = file; for (auto j = 0U; j < object->volumes.size(); j++) { auto volume {object->volumes.at(j)}; - volume->input_file = file.ToStdString(); + volume->input_file = file; volume->input_file_obj_idx = i; volume->input_file_vol_idx = j; } diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 7f84f0ca1..d4eb41abf 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -61,7 +61,7 @@ private: Plate2D* canvas2D {}; //< 2D plater canvas /// Handles the actual load of the file from the dialog handoff. - std::vector load_file(const wxString& file, const int obj_idx_to_load = -1); + std::vector load_file(const std::string file, const int obj_idx_to_load = -1); const std::string LogChannel {"GUI_Plater"}; //< Which log these messages should go to. diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp index 7fb6602cb..a99b20ca6 100644 --- a/src/GUI/Plater/PlaterObject.hpp +++ b/src/GUI/Plater/PlaterObject.hpp @@ -12,9 +12,9 @@ namespace Slic3r { namespace GUI { class PlaterObject { public: - wxString name {L""}; + std::string name {""}; size_t identifier {0U}; - wxString input_file {L""}; + std::string input_file {""}; int input_file_obj_idx {-1}; From 9cbc2810b44c3881fcc36345f1dd8fc9869979c0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 20:36:40 -0500 Subject: [PATCH 097/305] Add additional translate() functions to accept a Point or Pointf for convenience. --- xs/src/libslic3r/ExPolygonCollection.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xs/src/libslic3r/ExPolygonCollection.hpp b/xs/src/libslic3r/ExPolygonCollection.hpp index 57f512336..b11e41ecd 100644 --- a/xs/src/libslic3r/ExPolygonCollection.hpp +++ b/xs/src/libslic3r/ExPolygonCollection.hpp @@ -24,6 +24,8 @@ class ExPolygonCollection operator ExPolygons&(); void scale(double factor); void translate(double x, double y); + void translate(const Point offset) { translate(static_cast(offset.x), static_cast(offset.y)); } + void translate(const Pointf offset) { translate(offset.x, offset.y); } void rotate(double angle, const Point ¢er); template bool contains(const T &item) const; bool contains_b(const Point &point) const; From 00fd19331efdbb83a93100bac105891c2572737c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 20:37:18 -0500 Subject: [PATCH 098/305] Added convenience function to build a Point from a Pointf that is scaled. --- xs/src/libslic3r/Point.cpp | 5 +++++ xs/src/libslic3r/Point.hpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/xs/src/libslic3r/Point.cpp b/xs/src/libslic3r/Point.cpp index 9a4a71ac2..465f78db8 100644 --- a/xs/src/libslic3r/Point.cpp +++ b/xs/src/libslic3r/Point.cpp @@ -18,6 +18,11 @@ Point::operator==(const Point& rhs) const return this->coincides_with(rhs); } +Point +Point::new_scale(Pointf p) { + return Point(scale_(p.x), scale_(p.y)); +} + std::string Point::wkt() const { diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index 57a9ef7e8..3c0b5f299 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -36,6 +36,9 @@ class Point static Point new_scale(coordf_t x, coordf_t y) { return Point(scale_(x), scale_(y)); }; + + /// Scale and create a Point from a Pointf. + static Point new_scale(Pointf p); bool operator==(const Point& rhs) const; std::string wkt() const; std::string dump_perl() const; From b1c6d28411fc2b6a564d756296ddedd2c910fac7 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 20:37:49 -0500 Subject: [PATCH 099/305] Ported clean_instance_thumbnails --- src/GUI/Plater/Plate2D.cpp | 4 ++++ src/GUI/Plater/Plate2D.hpp | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index e2a4162bf..36997560e 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -97,6 +97,10 @@ void Plate2D::repaint(wxPaintEvent& e) { } +void Plate2D::clean_instance_thumbnails() { + for (auto& obj : this->objects) { + obj.instance_thumbnails.clear(); + } } void Plate2D::mouse_drag(wxMouseEvent& e) { diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 1db726a11..42ec6f786 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -119,6 +119,9 @@ private: return this->point_to_model_units(pt.x, pt.y); } + /// Remove all instance thumbnails. + void clean_instance_thumbnails(); + }; } } // Namespace Slic3r::GUI From e6caa8aa618955c984047ad1bc60466b7bd796e1 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 20:39:29 -0500 Subject: [PATCH 100/305] Started work on component to draw thumbnails from repaint() method. --- src/GUI/Plater/Plate2D.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 36997560e..c235debb4 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -96,6 +96,32 @@ void Plate2D::repaint(wxPaintEvent& e) { } } + // Draw thumbnails + + dc->SetPen(dark_pen); + this->clean_instance_thumbnails(); + for (auto& obj : this->objects) { + auto model_object {this->model->objects.at(obj.identifier)}; + if (obj.thumbnail.expolygons.size() == 0) + continue; // if there's no thumbnail move on + for (size_t instance_idx = 0U; instance_idx < model_object->instances.size(); instance_idx++) { + auto& instance {model_object->instances.at(instance_idx)}; + if (obj.transformed_thumbnail.expolygons.size()) continue; + auto thumbnail {obj.transformed_thumbnail}; // starts in unscaled model coords + + thumbnail.translate(Point::new_scale(instance->offset)); + + obj.instance_thumbnails.emplace_back(thumbnail); + + for (auto& poly : obj.instance_thumbnails) { + for (const auto& points : poly.expolygons) { + auto poly { this->scaled_points_to_pixel(Polygon(points), 1) }; + dc->DrawPolygon(poly.size(), poly.data(), 0, 0); + } + } + } + } +} void Plate2D::clean_instance_thumbnails() { for (auto& obj : this->objects) { From 17074c14b89b5a5742261d9c164b0803ede7ffd5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 20:39:50 -0500 Subject: [PATCH 101/305] Remember to put the event skip in during repaint. --- src/GUI/Plater/Plate2D.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index c235debb4..04250c7ae 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -121,6 +121,7 @@ void Plate2D::repaint(wxPaintEvent& e) { } } } + e.Skip(); } void Plate2D::clean_instance_thumbnails() { From 7c96e56e0746916fa014d66d938bea20f492da6c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 21:39:31 -0500 Subject: [PATCH 102/305] Stubbed out the different draw brushes being set; flattened loops slightly and posted a note --- src/GUI/Plater/Plate2D.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 04250c7ae..82d5fbf03 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -113,11 +113,22 @@ void Plate2D::repaint(wxPaintEvent& e) { obj.instance_thumbnails.emplace_back(thumbnail); - for (auto& poly : obj.instance_thumbnails) { - for (const auto& points : poly.expolygons) { - auto poly { this->scaled_points_to_pixel(Polygon(points), 1) }; - dc->DrawPolygon(poly.size(), poly.data(), 0, 0); - } + if (0) { // object is dragged + dc->SetBrush(dragged_brush); + } else if (0) { + dc->SetBrush(instance_brush); + } else if (0) { + dc->SetBrush(selected_brush); + } else { + dc->SetBrush(objects_brush); + } + // porting notes: perl here seems to be making a single-item array of the + // thumbnail set. + // no idea why. It doesn't look necessary, so skip the outer layer + // and draw the contained expolygons + for (const auto& points : obj.instance_thumbnails.back().expolygons) { + auto poly { this->scaled_points_to_pixel(Polygon(points), 1) }; + dc->DrawPolygon(poly.size(), poly.data(), 0, 0); } } } From 19c1811823b9fdded9f41b4f0fa49af0025e8b1b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 22:43:02 -0500 Subject: [PATCH 103/305] Added bare-bones stubs for 3D plater and 3D preview. --- src/GUI/Plater.hpp | 7 ++++++- src/GUI/Plater/Plate3D.hpp | 16 ++++++++++++++++ src/GUI/Plater/Preview3D.hpp | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/GUI/Plater/Plate3D.hpp create mode 100644 src/GUI/Plater/Preview3D.hpp diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index d4eb41abf..47d61a693 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -16,6 +16,8 @@ #include "Plater/PlaterObject.hpp" #include "Plater/Plate2D.hpp" +#include "Plater/Plate3D.hpp" +#include "Plater/Preview3D.hpp" #include "Settings.hpp" #include "MainFrame.hpp" @@ -58,7 +60,10 @@ private: wxNotebook* preview_notebook {new wxNotebook(this, -1, wxDefaultPosition, wxSize(335,335), wxNB_BOTTOM)}; - Plate2D* canvas2D {}; //< 2D plater canvas + Plate2D* canvas2D {nullptr}; //< 2D plater canvas + Plate3D* canvas3D {nullptr}; //< 3D plater canvas + + Preview3D* preview3D {nullptr}; //< 3D Preview /// Handles the actual load of the file from the dialog handoff. std::vector load_file(const std::string file, const int obj_idx_to_load = -1); diff --git a/src/GUI/Plater/Plate3D.hpp b/src/GUI/Plater/Plate3D.hpp new file mode 100644 index 000000000..488e35019 --- /dev/null +++ b/src/GUI/Plater/Plate3D.hpp @@ -0,0 +1,16 @@ +#ifndef PLATE3D_HPP +#define PLATE3D_HPP +#include +#ifndef WX_PRECOMP + #include +#endif + +namespace Slic3r { namespace GUI { + +class Plate3D : public wxPanel { +public: + void update() {}; +}; + +} } // Namespace Slic3r::GUI +#endif diff --git a/src/GUI/Plater/Preview3D.hpp b/src/GUI/Plater/Preview3D.hpp new file mode 100644 index 000000000..cd4e0a283 --- /dev/null +++ b/src/GUI/Plater/Preview3D.hpp @@ -0,0 +1,16 @@ +#ifndef PREVIEW3D_HPP +#define PREVIEW3D_HPP +#include +#ifndef WX_PRECOMP + #include +#endif + +namespace Slic3r { namespace GUI { + +class Preview3D : public wxPanel { +public: + void reload_print() {}; +}; + +} } // Namespace Slic3r::GUI +#endif From bc311474a2d1a43205c2f5db7a3338207a26e471 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 22:43:02 -0500 Subject: [PATCH 104/305] stubbed in constant for turning on/off threading (mostly to reduce complexity when testing feature code) --- src/GUI/misc_ui.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index eebefd015..28c28377d 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -45,6 +45,8 @@ constexpr bool isDev = true; constexpr bool isDev = false; #endif +constexpr bool threaded = false; + // hopefully the compiler is smart enough to figure this out const std::map FILE_WILDCARDS { std::make_pair("known", "Known files (*.stl, *.obj, *.amf, *.xml, *.3mf)|*.3mf;*.3MF;*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML"), From 98d4e9a6c569ea5983f33228114d8e56efdbd984 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 22:43:02 -0500 Subject: [PATCH 105/305] Added canvas refresh utility function. Additional previews/canvases should update here. --- src/GUI/Plater.cpp | 9 +++++++++ src/GUI/Plater.hpp | 1 + 2 files changed, 10 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 02cfae165..95c4dff9d 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -296,5 +296,14 @@ int Plater::get_object_index(size_t object_id) { return -1; } +void Plater::refresh_canvases() { + if (this->canvas2D != nullptr) + this->canvas2D->Refresh(); + if (this->canvas3D != nullptr) + this->canvas3D->update(); + if (this->preview3D != nullptr) + this->preview3D->reload_print(); + +} }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 47d61a693..7bfd8cbf2 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -84,6 +84,7 @@ private: auto bed_shape { Slic3r::Polygon::new_scale(this->config->get("bed_shape").values) }; return Slic3r::Pointf(); } + void refresh_canvases(); }; From 6276e0d7ce2b76e17549c24b32cb96da05372ea2 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 22:43:02 -0500 Subject: [PATCH 106/305] Added make_thumbnail and on_thumbnail_made --- src/GUI/Plater.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/GUI/Plater.hpp | 3 +++ 2 files changed, 41 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 95c4dff9d..ecee4435a 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -284,6 +284,7 @@ std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { } } + for (const auto& i : obj_idx) { this->make_thumbnail(i); } return obj_idx; } @@ -296,6 +297,42 @@ int Plater::get_object_index(size_t object_id) { return -1; } +void Plater::make_thumbnail(size_t idx) { + auto& plater_object {this->objects.at(idx)}; + if (threaded) { + // spin off a thread to create the thumbnail and post an event when it is done. + } else { + plater_object.make_thumbnail(this->model, idx); + this->on_thumbnail_made(idx); + } +/* + my $plater_object = $self->{objects}[$obj_idx]; + $plater_object->thumbnail(Slic3r::ExPolygon::Collection->new); + my $cb = sub { + $plater_object->make_thumbnail($self->{model}, $obj_idx); + + if ($Slic3r::have_threads) { + Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $THUMBNAIL_DONE_EVENT, shared_clone([ $obj_idx ]))); + Slic3r::thread_cleanup(); + threads->exit; + } else { + $self->on_thumbnail_made($obj_idx); + } + }; + + @_ = (); + $Slic3r::have_threads + ? threads->create(sub { $cb->(); Slic3r::thread_cleanup(); })->detach + : $cb->(); +} +*/ +} + +void Plater::on_thumbnail_made(size_t idx) { + this->objects.at(idx).transform_thumbnail(this->model, idx); + this->refresh_canvases(); +} + void Plater::refresh_canvases() { if (this->canvas2D != nullptr) this->canvas2D->Refresh(); @@ -305,5 +342,6 @@ void Plater::refresh_canvases() { this->preview3D->reload_print(); } + }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 7bfd8cbf2..8e47b0a7d 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -84,6 +84,9 @@ private: auto bed_shape { Slic3r::Polygon::new_scale(this->config->get("bed_shape").values) }; return Slic3r::Pointf(); } + + /// Complete thumbnail transformation and refresh canvases + void on_thumbnail_made(size_t idx); void refresh_canvases(); }; From b3b003ce3535c51de410b5f25c7fa6f497f5659e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 6 May 2018 22:54:04 -0500 Subject: [PATCH 107/305] Updated gitignore to ignore windows executables. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8cac56759..1ceeccf14 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ CMakeFiles core CMakeCache.txt *.cmake +*.exe From 962239cf61afe470212632876c2dbff97f183885 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:23:33 -0500 Subject: [PATCH 108/305] avoid magic numbers --- src/GUI/MainFrame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 1452d0cc3..b28f38cf1 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -82,7 +82,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si /// Private initialization function for the main frame tab panel. void MainFrame::init_tabpanel() { - this->tabpanel = new wxAuiNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP); + this->tabpanel = new wxAuiNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP); auto panel = this->tabpanel; panel->Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, ([=](wxAuiNotebookEvent& e) From d6d3c755825e9bdb7e811a4d264287f1a33fe944 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:24:08 -0500 Subject: [PATCH 109/305] Stub out more of the sizers so people implementing can see their work immediately. --- src/GUI/Plater.cpp | 25 +++++++++++++++++++++++++ src/GUI/Plater.hpp | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index ecee4435a..70c6b7010 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -111,6 +111,31 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrright_sizer; +// $right_sizer->Add($presets, 0, wxEXPAND | wxTOP, 10) if defined $presets; +// $right_sizer->Add($buttons_sizer, 0, wxEXPAND | wxBOTTOM, 5); +// $right_sizer->Add($self->{settings_override_panel}, 1, wxEXPAND, 5); +// $right_sizer->Add($object_info_sizer, 0, wxEXPAND, 0); +// $right_sizer->Add($print_info_sizer, 0, wxEXPAND, 0); +// $right_sizer->Hide($print_info_sizer); + + auto hsizer {new wxBoxSizer(wxHORIZONTAL)}; + hsizer->Add(this->preview_notebook, 1, wxEXPAND | wxTOP, 1); + hsizer->Add(right_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, 3); + + auto sizer {new wxBoxSizer(wxVERTICAL)}; + if (this->htoolbar != nullptr) sizer->Add(this->htoolbar, 0, wxEXPAND, 0); + if (this->btoolbar != nullptr) sizer->Add(this->btoolbar, 0, wxEXPAND, 0); + sizer->Add(hsizer, 1, wxEXPAND,0); + + sizer->SetSizeHints(this); + this->SetSizer(sizer); + } void Plater::add() { Log::info(LogChannel, L"Called Add function"); diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 8e47b0a7d..9e86eb265 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -59,6 +59,10 @@ private: std::stack redo {}; wxNotebook* preview_notebook {new wxNotebook(this, -1, wxDefaultPosition, wxSize(335,335), wxNB_BOTTOM)}; + wxBoxSizer* right_sizer {new wxBoxSizer(wxVERTICAL)}; + + wxToolBar* htoolbar {nullptr}; //< toolbar for non-MSW platforms. + wxBoxSizer* btoolbar {nullptr}; //< button-based toolbar for Windows Plate2D* canvas2D {nullptr}; //< 2D plater canvas Plate3D* canvas3D {nullptr}; //< 3D plater canvas From def5d565b690820408391c96efa0764228f39bd2 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:24:27 -0500 Subject: [PATCH 110/305] call update_bed_size during instantiation --- src/GUI/Plater.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 70c6b7010..291da269d 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -111,6 +111,8 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrcanvas2D->update_bed_size(); + // Finally assemble the sizers into the display. // export/print/send/export buttons From ae10bc70b5a873013f2668d3d08504661d1981ca Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:26:07 -0500 Subject: [PATCH 111/305] Actually unscale instead of doing silly things. --- src/GUI/Plater/Plate2D.cpp | 13 ++++++++++--- src/GUI/Plater/Plate2D.hpp | 7 +------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 82d5fbf03..f79aff616 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -286,15 +286,22 @@ std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polygon& poly return this->scaled_points_to_pixel(Polyline(poly), unscale); } -std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polyline& poly, bool unscale) { +std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polyline& poly, bool _unscale) { std::vector result; for (const auto& pt : poly.points) { - const auto tmp {wxPoint(pt.x, pt.y)}; - result.push_back( (unscale ? unscaled_point_to_pixel(tmp) : tmp) ); + const auto x {_unscale ? Slic3r::unscale(pt.x) : pt.x}; + const auto y {_unscale ? Slic3r::unscale(pt.y) : pt.y}; + result.push_back(wxPoint(x, y)); } return result; } +wxPoint Plate2D::unscaled_point_to_pixel(const wxPoint& in) { + const auto& canvas_height {this->GetSize().GetHeight()}; + const auto& zero = this->bed_origin; + return wxPoint(in.x * this->scaling_factor + zero.x, + in.y * this->scaling_factor + (zero.y - canvas_height)); +} } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 42ec6f786..2d5752d14 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -79,12 +79,7 @@ private: std::vector scaled_points_to_pixel(const Slic3r::Polyline& poly, bool unscale); /// For a specific point, unscale it relative to the origin - wxPoint unscaled_point_to_pixel(const wxPoint& in) { - const auto& canvas_height {this->GetSize().GetHeight()}; - const auto& zero = this->bed_origin; - return wxPoint(in.x * this->scaling_factor + zero.x, - in.y * this->scaling_factor + (zero.y - canvas_height)); - } + wxPoint unscaled_point_to_pixel(const wxPoint& in); /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. void update_bed_size(); From 62f7760198e7f8b4bbb08c07c0445b3b00d153fc Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:27:02 -0500 Subject: [PATCH 112/305] Make update_bed_size() public. --- src/GUI/Plater/Plate2D.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 2d5752d14..07d9e53da 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -34,6 +34,8 @@ public: Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); + /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. + void update_bed_size(); // std::function<> on_select_object {}; private: std::vector& objects; //< reference to parent vector @@ -81,8 +83,6 @@ private: /// For a specific point, unscale it relative to the origin wxPoint unscaled_point_to_pixel(const wxPoint& in); - /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. - void update_bed_size(); /// private class variables to stash bits for drawing the print bed area. wxRealPoint bed_origin {}; From eca8fea2b4518664deba6e65b4c5e43157c52c7c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:27:56 -0500 Subject: [PATCH 113/305] Work on shared::ptr of Model instead of trying to be clever. --- src/GUI/Plater/PlaterObject.cpp | 19 +++++++++++++------ src/GUI/Plater/PlaterObject.hpp | 13 +++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/GUI/Plater/PlaterObject.cpp b/src/GUI/Plater/PlaterObject.cpp index b27ba821b..442c5d412 100644 --- a/src/GUI/Plater/PlaterObject.cpp +++ b/src/GUI/Plater/PlaterObject.cpp @@ -3,16 +3,18 @@ #include "Geometry.hpp" #include "ExPolygon.hpp" #include "libslic3r.h" +#include "Log.hpp" +#include "misc_ui.hpp" namespace Slic3r { namespace GUI { -Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& model, int obj_idx) { +Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(std::shared_ptr model, int obj_idx) { // make method idempotent this->thumbnail.expolygons.clear(); - auto mesh {model.objects[obj_idx]->raw_mesh()}; - auto model_instance {model.objects[obj_idx]->instances[0]}; + auto mesh {model->objects[obj_idx]->raw_mesh()}; + auto model_instance {model->objects[obj_idx]->instances[0]}; // Apply any x/y rotations and scaling vector if this came from a 3MF object. mesh.rotate_x(model_instance->x_rotation); @@ -22,7 +24,10 @@ Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& m if (mesh.facets_count() <= 5000) { auto area_threshold {scale_(1.0)}; ExPolygons tmp {}; - std::copy_if(tmp.end(), mesh.horizontal_projection().begin(), mesh.horizontal_projection().end(), [=](const ExPolygon& p) { return p.area() >= area_threshold; } ); // return all polys bigger than the area + for (auto p : mesh.horizontal_projection()) { + if (p.area() >= area_threshold) tmp.push_back(p); + } + // return all polys bigger than the area this->thumbnail.append(tmp); this->thumbnail.simplify(0.5); } else { @@ -32,10 +37,12 @@ Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& m return this->thumbnail; } -Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(const Slic3r::Model& model, int obj_idx) { + + +Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(std::shared_ptr model, int obj_idx) { if (this->thumbnail.expolygons.size() == 0) return this->thumbnail; - const auto& model_object {model.objects[obj_idx] }; + const auto& model_object {model->objects[obj_idx] }; const auto& model_instance {model_object->instances[0]}; // the order of these transformations MUST be the same everywhere, including diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp index a99b20ca6..ae53ec0fd 100644 --- a/src/GUI/Plater/PlaterObject.hpp +++ b/src/GUI/Plater/PlaterObject.hpp @@ -17,6 +17,9 @@ public: std::string input_file {""}; int input_file_obj_idx {-1}; + bool selected {false}; + int selected_instance {-1}; + Slic3r::ExPolygonCollection thumbnail; Slic3r::ExPolygonCollection transformed_thumbnail; @@ -24,11 +27,13 @@ public: // read only std::vector instance_thumbnails; - bool selected {false}; - int selected_instance {-1}; + Slic3r::ExPolygonCollection& make_thumbnail(const Slic3r::Model model, int obj_idx); + Slic3r::ExPolygonCollection& make_thumbnail(const std::shared_ptr model, int obj_idx); + + Slic3r::ExPolygonCollection& transform_thumbnail(const Slic3r::Model model, int obj_idx); + Slic3r::ExPolygonCollection& transform_thumbnail(const std::shared_ptr model, int obj_idx); + - Slic3r::ExPolygonCollection& make_thumbnail(const Slic3r::Model& model, int obj_idx); - Slic3r::ExPolygonCollection& transform_thumbnail(const Slic3r::Model& model, int obj_idx); }; }} // Namespace Slic3r::GUI From ad7460655b8f164b0cfb890bc9c27a3a8f77c66a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:29:36 -0500 Subject: [PATCH 114/305] Being more specific about units. --- src/GUI/Plater/Plate2D.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index f79aff616..89f047f7a 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -247,11 +247,11 @@ void Plate2D::update_bed_size() { const auto& bb = bed_polygon.bounding_box(); const auto& size = bb.size(); - this->scaling_factor = std::min(canvas_w / unscale(size.x), canvas_h / unscale(size.y)); + this->scaling_factor = std::min(static_cast(canvas_w) / unscale(size.x), static_cast(canvas_h) / unscale(size.y)); this->bed_origin = wxPoint( - canvas_w / 2 - (unscale(bb.max.x + bb.min.x)/2 * this->scaling_factor), - canvas_h - (canvas_h / 2 - (unscale(bb.max.y + bb.min.y)/2 * this->scaling_factor)) + canvas_w / 2.0 - (unscale(bb.max.x + bb.min.x)/2.0 * this->scaling_factor), + canvas_h - (canvas_h / 2.0 - (unscale(bb.max.y + bb.min.y)/2.0 * this->scaling_factor)) ); const auto& center = bb.center(); @@ -259,7 +259,7 @@ void Plate2D::update_bed_size() { // Cache bed contours and grid { - const auto& step { scale_(10) }; + const auto& step { scale_(10.0) }; // want a 10mm step for the lines auto grid {Polylines()}; for (coord_t x = (bb.min.x - (bb.min.x % step) + step); x < bb.max.x; x += step) { From eb4df9965f587866b05c5aa6a7aad8f2594a6538 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:30:05 -0500 Subject: [PATCH 115/305] Pass bool when we mean bool, not int. --- src/GUI/Plater/Plate2D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 89f047f7a..bd3cf10fb 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -127,7 +127,7 @@ void Plate2D::repaint(wxPaintEvent& e) { // no idea why. It doesn't look necessary, so skip the outer layer // and draw the contained expolygons for (const auto& points : obj.instance_thumbnails.back().expolygons) { - auto poly { this->scaled_points_to_pixel(Polygon(points), 1) }; + auto poly { this->scaled_points_to_pixel(Polygon(points), true) }; dc->DrawPolygon(poly.size(), poly.data(), 0, 0); } } From 787ac4a0e3bfac360ee5763e51420a23533a6a3d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:30:28 -0500 Subject: [PATCH 116/305] Add LogChannel designation as a protected member. --- src/GUI/Plater/PlaterObject.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp index ae53ec0fd..3d06601c3 100644 --- a/src/GUI/Plater/PlaterObject.hpp +++ b/src/GUI/Plater/PlaterObject.hpp @@ -33,6 +33,8 @@ public: Slic3r::ExPolygonCollection& transform_thumbnail(const Slic3r::Model model, int obj_idx); Slic3r::ExPolygonCollection& transform_thumbnail(const std::shared_ptr model, int obj_idx); +protected: + const std::string LogChannel {"PlaterObject"}; }; From b0404fca34430e506b520d1f9c738be521956af9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:31:19 -0500 Subject: [PATCH 117/305] Fixed inverted logic; abort if there aren't any transformed thumbnails. --- src/GUI/Plater/Plate2D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index bd3cf10fb..54f8fd8c3 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -106,7 +106,7 @@ void Plate2D::repaint(wxPaintEvent& e) { continue; // if there's no thumbnail move on for (size_t instance_idx = 0U; instance_idx < model_object->instances.size(); instance_idx++) { auto& instance {model_object->instances.at(instance_idx)}; - if (obj.transformed_thumbnail.expolygons.size()) continue; + if (obj.transformed_thumbnail.expolygons.size() == 0) continue; auto thumbnail {obj.transformed_thumbnail}; // starts in unscaled model coords thumbnail.translate(Point::new_scale(instance->offset)); From fee6aef5c4c34862a37b8b1d664b32afc359ce25 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:31:42 -0500 Subject: [PATCH 118/305] Get access to LOG_WSTRING. --- src/GUI/Plater/Plate2D.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 54f8fd8c3..a80a9b3ca 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -5,6 +5,7 @@ #include "Point.hpp" #include "Log.hpp" #include "ClipperUtils.hpp" +#include "misc_ui.hpp" // wx includes #include From 90ddda9ce14a8a1e625380a6d075537f86a4c763 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:32:20 -0500 Subject: [PATCH 119/305] be more specific about what is getting used. --- src/GUI/Plater/Plate2D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index a80a9b3ca..8fec15502 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -64,7 +64,7 @@ void Plate2D::repaint(wxPaintEvent& e) { dc->SetPen(this->print_center_pen); dc->SetBrush(this->bed_brush); auto tmp {scaled_points_to_pixel(this->bed_polygon, true)}; - dc->DrawPolygon(this->bed_polygon.points.size(), tmp.data(), 0, 0); + dc->DrawPolygon(tmp.size(), tmp.data(), 0, 0); } // draw print center From ccb7333b82f6b209a504b915cee50a81f7d597da Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 21:33:15 -0500 Subject: [PATCH 120/305] remember to add the prototype for make_thumbnail --- src/GUI/Plater.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 9e86eb265..c180ca843 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -89,6 +89,9 @@ private: return Slic3r::Pointf(); } + /// Build thumbnails for the models + void make_thumbnail(size_t idx); + /// Complete thumbnail transformation and refresh canvases void on_thumbnail_made(size_t idx); void refresh_canvases(); From 168e7913de2ebacff42364f8ad2a582d60f1a70a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 22:15:12 -0500 Subject: [PATCH 121/305] Stubbed out Plater::arrange() and on_model_change() --- src/GUI/Plater.cpp | 17 ++++++++++++++++- src/GUI/Plater.hpp | 9 ++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 291da269d..0af673ff3 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -7,6 +7,7 @@ #include "ProgressStatusBar.hpp" #include "Log.hpp" #include "MainFrame.hpp" +#include "BoundingBox.hpp" namespace Slic3r { namespace GUI { @@ -311,7 +312,8 @@ std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { } } - for (const auto& i : obj_idx) { this->make_thumbnail(i); } + for (const auto& i : obj_idx) { this->make_thumbnail(i); } + if (need_arrange) this->arrange(); return obj_idx; } @@ -370,5 +372,18 @@ void Plater::refresh_canvases() { } +void Plater::arrange() { + // pause background process + auto bb {Slic3r::BoundingBoxf(this->config->get("bed_shape").values)}; + bool success {this->model->arrange_objects(this->config->min_object_distance(), &bb)}; + + GetFrame()->statusbar->SetStatusText(_("Objects were arranged.")); + this->on_model_change(true); +} + +void Plater::on_model_change(bool force_autocenter) { + this->refresh_canvases(); +} + }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index c180ca843..5d052891f 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -47,7 +47,7 @@ private: std::shared_ptr config { Slic3r::Config::new_from_defaults( {"bed_shape", "complete_objects", "extruder_clearance_radius", "skirts", "skirt_distance", "brim_width", "serial_port", "serial_speed", "host_type", "print_host", "octoprint_apikey", - "shortcuts", "filament_colour"})}; + "shortcuts", "filament_colour", "duplicate_distance"})}; bool processed {false}; @@ -95,6 +95,13 @@ private: /// Complete thumbnail transformation and refresh canvases void on_thumbnail_made(size_t idx); void refresh_canvases(); + + /// Arrange models + void arrange(); + + /// Run everything that needs to happen when models change. + /// Includes updating canvases, reloading menus, etc. + void on_model_change(bool force_autocenter = false); }; From 2fb6b8103ed5394477783727d5fd94892a016738 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 22:15:28 -0500 Subject: [PATCH 122/305] Actually do the unscaled point conversion -.-; --- src/GUI/Plater/Plate2D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 8fec15502..e9f50c5c4 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -292,7 +292,7 @@ std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polyline& pol for (const auto& pt : poly.points) { const auto x {_unscale ? Slic3r::unscale(pt.x) : pt.x}; const auto y {_unscale ? Slic3r::unscale(pt.y) : pt.y}; - result.push_back(wxPoint(x, y)); + result.push_back(unscaled_point_to_pixel(wxPoint(x, y))); } return result; } From babedbe7d6d48a35f119974fa5699ce79fbbc3b5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 22:15:47 -0500 Subject: [PATCH 123/305] Code beautification --- src/GUI/Plater/Plate2D.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index e9f50c5c4..1ec395db9 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -300,7 +300,8 @@ std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polyline& pol wxPoint Plate2D::unscaled_point_to_pixel(const wxPoint& in) { const auto& canvas_height {this->GetSize().GetHeight()}; const auto& zero = this->bed_origin; - return wxPoint(in.x * this->scaling_factor + zero.x, + return wxPoint( + in.x * this->scaling_factor + zero.x, in.y * this->scaling_factor + (zero.y - canvas_height)); } From a7db378b8ae271447f802216dc2faf40c472ba5e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 22:16:20 -0500 Subject: [PATCH 124/305] Remember to clean up old grid array before filling it up again. --- src/GUI/Plater/Plate2D.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 1ec395db9..194aaa467 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -258,6 +258,7 @@ void Plate2D::update_bed_size() { const auto& center = bb.center(); this->print_center = wxPoint(unscale(center.x), unscale(center.y)); + this->grid.clear(); // clear out the old grid // Cache bed contours and grid { const auto& step { scale_(10.0) }; // want a 10mm step for the lines From 8bca31ff2ef6cb2bea4829f11053a651453e79ad Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 22:16:52 -0500 Subject: [PATCH 125/305] It's all integer points anyway. --- src/GUI/Plater/Plate2D.cpp | 4 ++-- src/GUI/Plater/Plate2D.hpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 194aaa467..037c86b40 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -251,8 +251,8 @@ void Plate2D::update_bed_size() { this->scaling_factor = std::min(static_cast(canvas_w) / unscale(size.x), static_cast(canvas_h) / unscale(size.y)); this->bed_origin = wxPoint( - canvas_w / 2.0 - (unscale(bb.max.x + bb.min.x)/2.0 * this->scaling_factor), - canvas_h - (canvas_h / 2.0 - (unscale(bb.max.y + bb.min.y)/2.0 * this->scaling_factor)) + canvas_w / 2 - (unscale(bb.max.x + bb.min.x)/2 * this->scaling_factor), + canvas_h - (canvas_h / 2 - (unscale(bb.max.y + bb.min.y)/2 * this->scaling_factor)) ); const auto& center = bb.center(); diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 07d9e53da..126163158 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -84,8 +84,10 @@ private: wxPoint unscaled_point_to_pixel(const wxPoint& in); + /// Displacement needed to center bed. + wxPoint bed_origin {}; + /// private class variables to stash bits for drawing the print bed area. - wxRealPoint bed_origin {}; wxRealPoint print_center {}; Slic3r::Polygon bed_polygon {}; std::vector grid {}; From eadac30476506c81890ccd0d5635b5fafefcb6aa Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 22:36:12 -0500 Subject: [PATCH 126/305] added one-off menu option to call arrange, currently crashes if no models loaded. --- src/GUI/MainFrame.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index b28f38cf1..7a99f5f25 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -124,6 +124,7 @@ void MainFrame::init_menubar() wxMenu* menuPlater = new wxMenu(); { + append_menu_item(menuPlater, _(L"Arrange…"), _("Arrange models on plater"), [=](wxCommandEvent& e) { if (this->plater != nullptr) this->plater->arrange();}, wxID_ANY, "bricks.png", "Ctrl+G"); } wxMenu* menuObject = new wxMenu(); { From b16e2570f3f3b760159f9365bac792bb145f9ebe Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 7 May 2018 22:36:40 -0500 Subject: [PATCH 127/305] more work on arrange() --- src/GUI/Plater.cpp | 6 +++++- src/GUI/Plater.hpp | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 0af673ff3..6336fc3f1 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -374,14 +374,18 @@ void Plater::refresh_canvases() { void Plater::arrange() { // pause background process + Slic3r::Log::info(LogChannel, L"Called arrange()"); auto bb {Slic3r::BoundingBoxf(this->config->get("bed_shape").values)}; - bool success {this->model->arrange_objects(this->config->min_object_distance(), &bb)}; + bool success {this->model->arrange_objects(5, &bb)}; GetFrame()->statusbar->SetStatusText(_("Objects were arranged.")); this->on_model_change(true); } void Plater::on_model_change(bool force_autocenter) { + if (force_autocenter || settings->autocenter) { + this->model->center_instances_around_point(this->bed_centerf()); + } this->refresh_canvases(); } diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 5d052891f..74d892f1c 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -36,6 +36,9 @@ class Plater : public wxPanel public: Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings); void add(); + + /// Arrange models + void arrange(); /// Ask if there are any unsaved changes. bool prompt_unsaved_changes() { return true; } @@ -96,8 +99,6 @@ private: void on_thumbnail_made(size_t idx); void refresh_canvases(); - /// Arrange models - void arrange(); /// Run everything that needs to happen when models change. /// Includes updating canvases, reloading menus, etc. From f00249ffe02d0211d6b59d7338c4c85980579dc9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 8 May 2018 23:10:13 -0500 Subject: [PATCH 128/305] added additional documentation for Plater --- src/GUI/Plater.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 74d892f1c..8898ea037 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -31,6 +31,8 @@ class PlaterObject; class Plate2D; class MainFrame; +/// Extension of wxPanel class to handle the main plater. +/// 2D, 3D, preview, etc tabs. class Plater : public wxPanel { public: From e7ab533da6dfc70e048c4f13a6cbe5104d428c47 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 8 May 2018 23:11:02 -0500 Subject: [PATCH 129/305] Pushed a contains() method up to ExPolygonCollection that returns if any of its expolygons contain the point. --- xs/src/libslic3r/ExPolygonCollection.cpp | 7 +++++++ xs/src/libslic3r/ExPolygonCollection.hpp | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/xs/src/libslic3r/ExPolygonCollection.cpp b/xs/src/libslic3r/ExPolygonCollection.cpp index 9de1cb786..ec27505a5 100644 --- a/xs/src/libslic3r/ExPolygonCollection.cpp +++ b/xs/src/libslic3r/ExPolygonCollection.cpp @@ -140,5 +140,12 @@ ExPolygonCollection::append(const ExPolygon &expp) { this->expolygons.push_back(expp); } +bool +ExPolygonCollection::contains(const Point &point) const { + for (const auto& poly : this->expolygons) { + if (poly.contour.contains(point)) return true; + } + return false; +} } diff --git a/xs/src/libslic3r/ExPolygonCollection.hpp b/xs/src/libslic3r/ExPolygonCollection.hpp index b11e41ecd..1acd080a2 100644 --- a/xs/src/libslic3r/ExPolygonCollection.hpp +++ b/xs/src/libslic3r/ExPolygonCollection.hpp @@ -36,6 +36,11 @@ class ExPolygonCollection Polygons holes() const; void append(const ExPolygons &expolygons); void append(const ExPolygon &expolygons); + + /// Convenience function to iterate through all of the owned + /// ExPolygons and check if at least one contains the point. + bool contains(const Point &point) const; + }; inline ExPolygonCollection& From 70b81db7f944427336c0c44a4cdfd040bf1b2f53 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 8 May 2018 23:11:37 -0500 Subject: [PATCH 130/305] Staged more of mouse_down() --- src/GUI/Plater/Plate2D.cpp | 45 ++++++++++++++++++++++++++++++++++++++ src/GUI/Plater/Plate2D.hpp | 17 +++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 037c86b40..7ab85fc69 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -159,7 +159,52 @@ void Plate2D::mouse_drag(wxMouseEvent& e) { } void Plate2D::mouse_down(wxMouseEvent& e) { + this->SetFocus(); // Focus needed to move selected instance with keyboard arrows + + const auto& pos = e.GetPosition(); + const auto point = this->point_to_model_units(pos); + this->on_select_object(-1); + this->selected_instance = {-1, -1}; + + Slic3r::Log::info(LogChannel, LOG_WSTRING("Mouse down at scaled point " << point.x << ", " << point.y)); + + // Iterate through the list backwards to catch the highest object (last placed/drawn), which + // is usually what the user wants. + for (auto obj = this->objects.rbegin(); obj != this->objects.rend(); obj++) { + const auto& obj_idx {obj->identifier}; + for (auto thumbnail = obj->instance_thumbnails.crbegin(); thumbnail != obj->instance_thumbnails.crend(); thumbnail++) { + Slic3r::Log::info(LogChannel, LOG_WSTRING("First point: " << thumbnail->contours()[0].points[0].x << "," << thumbnail->contours()[0].points[0].y)); + if (thumbnail->contains(point)) { + const auto& instance_idx {std::distance(thumbnail, obj->instance_thumbnails.crend()) - 1}; + Slic3r::Log::info(LogChannel, LOG_WSTRING(instance_idx << " contains this point")); + this->on_select_object(obj_idx); + if (e.LeftDown()) { + // start dragging + auto& instance {this->model->objects.at(obj_idx)->instances.at(instance_idx)}; + auto instance_origin { Point::new_scale(instance->offset) }; + + this->drag_start_pos { Slic3r::Point( + point.x - instance_origin.x, + point.y - instance_origin.y, + )}; + + this->drag_object = { obj_idx, instance_idx }; + this->selected_instance = this->drag_object; + + obj->selected_instance = instance_idx; + + } else if(e.RightDown()) { + this->on_right_click(pos); + } + } + } + + } + } +void Plate2D::on_select_object(int i) { +} + void Plate2D::mouse_up(wxMouseEvent& e) { } void Plate2D::mouse_dclick(wxMouseEvent& e) { diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 126163158..51f63943d 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -29,6 +29,12 @@ enum class MoveDirection { Up, Down, Left, Right }; +/// simple POD to make referencing this pair of identifiers easy +struct InstanceIdx { + long obj; + long inst; +}; + class Plate2D : public wxPanel { public: Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); @@ -58,7 +64,10 @@ private: wxPen dark_pen {}; bool user_drawn_background {(the_os == OS::Mac ? false : true)}; - size_t selected_instance; + + /// The object id and selected + InstanceIdx selected_instance; + InstanceIdx drag_object; /// Handle mouse-move events void mouse_drag(wxMouseEvent& e); @@ -66,6 +75,11 @@ private: void mouse_up(wxMouseEvent& e); void mouse_dclick(wxMouseEvent& e); + wxPoint drag_start_pos {}; + + /// Do something on right-clicks. + void on_right_click(const wxPoint& pos) { } + /// Handle repaint events void repaint(wxPaintEvent& e); @@ -119,6 +133,7 @@ private: /// Remove all instance thumbnails. void clean_instance_thumbnails(); + void on_select_object(int); }; } } // Namespace Slic3r::GUI From daece6e4c0589174dc552a80e6d2f97d168b7792 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 8 May 2018 23:12:15 -0500 Subject: [PATCH 131/305] Fix maths used for converting between model coordinates and pixels (and vice-versa) --- src/GUI/Plater/Plate2D.cpp | 2 +- src/GUI/Plater/Plate2D.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 7ab85fc69..17b51638a 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -348,7 +348,7 @@ wxPoint Plate2D::unscaled_point_to_pixel(const wxPoint& in) { const auto& zero = this->bed_origin; return wxPoint( in.x * this->scaling_factor + zero.x, - in.y * this->scaling_factor + (zero.y - canvas_height)); + canvas_height - in.y * this->scaling_factor + (zero.y - canvas_height)); } diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 51f63943d..57212a613 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -120,7 +120,7 @@ private: const auto& zero {this->bed_origin}; return Slic3r::Point( scale_(x - zero.x) / this->scaling_factor, - scale_(y - zero.y) / this->scaling_factor + scale_(zero.y - y) / this->scaling_factor ); } Slic3r::Point point_to_model_units(const wxPoint& pt) { From 179c3969a659e142922a8c3f55c24cf4221a7f6c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 8 May 2018 23:13:47 -0500 Subject: [PATCH 132/305] use integers instead of size_t for object identifiers. Need a better solution for semantics (perl used undef, python would have used None). --- src/GUI/Plater/PlaterObject.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp index 3d06601c3..d1d2f7056 100644 --- a/src/GUI/Plater/PlaterObject.hpp +++ b/src/GUI/Plater/PlaterObject.hpp @@ -13,7 +13,7 @@ namespace Slic3r { namespace GUI { class PlaterObject { public: std::string name {""}; - size_t identifier {0U}; + int identifier {0}; std::string input_file {""}; int input_file_obj_idx {-1}; From a16673c306f542e3834a6b19d432da382ea0ccc0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 8 May 2018 23:14:39 -0500 Subject: [PATCH 133/305] finished pushing through changes from InstanceIdx. --- src/GUI/Plater/Plate2D.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 17b51638a..7ef0dd1b6 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -264,7 +264,7 @@ void Plate2D::nudge_key(wxKeyEvent& e) { } void Plate2D::nudge(MoveDirection dir) { - if (this->selected_instance < this->objects.size()) { + if (this->selected_instance.obj < this->objects.size()) { auto i = 0U; for (auto& obj : this->objects) { if (obj.selected) { @@ -274,7 +274,7 @@ void Plate2D::nudge(MoveDirection dir) { i++; } } - if (selected_instance >= this->objects.size()) { + if (selected_instance.obj >= this->objects.size()) { Slic3r::Log::warn(LogChannel, L"Nudge failed because there is no selected instance."); return; // Abort } @@ -294,6 +294,7 @@ void Plate2D::update_bed_size() { const auto& size = bb.size(); + // calculate the scaling factor needed for constraining print bed area inside preview this->scaling_factor = std::min(static_cast(canvas_w) / unscale(size.x), static_cast(canvas_h) / unscale(size.y)); this->bed_origin = wxPoint( canvas_w / 2 - (unscale(bb.max.x + bb.min.x)/2 * this->scaling_factor), From 4a0d2b228f621aaa9209b5e19e6d9194be05634c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 9 May 2018 20:59:27 -0500 Subject: [PATCH 134/305] Updating README.md a bit. --- README.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d0404855a..5cb7d0c9b 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ See the [project homepage](http://slic3r.org/) at slic3r.org for more informatio ### What language is it written in? -The core parts of Slic3r are written in C++11, with multithreading. The graphical interface is still mostly written in Perl, but we're gradually porting it to C++ (want to help?). The goal is to port everything to C++. +The core parts of Slic3r are written in C++11, with multithreading. The graphical interface is in the process of being ported to C++11. ### How to install? @@ -66,23 +66,20 @@ Sure! You can do the following to find things that are available to help with: ### Directory structure -* `Build.PL`: this script installs dependencies into `local-lib/`, compiles the C++ part and runs tests -* `lib/`: the Perl code * `package/`: the scripts used for packaging the executables -* `slic3r.pl`: the main executable script, launching the GUI and providing the CLI -* `src/`: the C++ source of the `slic3r` executable the and CMake definition file for compiling it (note that this C++ `slic3r` executable can do many things but can't generate G-code yet because the porting isn't finished yet - the main executable is `slic3r.pl`) +* `src/`: the C++ source of the `slic3r` executable the and CMake definition file for compiling it +* `src/GUI`: The C++ GUI. * `t/`: the test suite * `utils/`: various useful scripts * `xs/src/libslic3r/`: C++ sources for libslic3r -* `xs/src/slic3r/`: C++ sources for the Slic3r GUI application * `xs/t/`: test suite for libslic3r * `xs/xsp/`: bindings for calling libslic3r from Perl (XS) ### Acknowledgements -The main author of Slic3r is Alessandro Ranellucci (@alexrj, *Sound* in IRC, [@alranel](http://twitter.com/alranel) on Twitter), who started the project in 2011 and still leads development. +The main author of Slic3r is Alessandro Ranellucci (@alexrj, *Sound* in IRC, [@alranel](http://twitter.com/alranel) on Twitter), who started the project in 2011. -Joseph Lenox (@lordofhyphens, *Loh* in IRC) is the current co-maintainer. +Joseph Lenox (@lordofhyphens, *LoH* in IRC, [@LenoxPlay](http://twitter.com/LenoxPlay) on Twitter) is the current co-maintainer. Contributions by Henrik Brix Andersen, Vojtech Bubnik, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Y. Sapir, Mike Sheldrake, Kliment Yanev and numerous others. Original manual by Gary Hodgson. Slic3r logo designed by Corey Daniels, Silk Icon Set designed by Mark James, stl and gcode file icons designed by Akira Yasuda. From 588bb456ae981f8918cbe214619ff46a50b745c3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 9 May 2018 21:48:16 -0500 Subject: [PATCH 135/305] Made Plater::arrange a little less noisy, noted TODO for the background process pause. Also finished implemented bed_centerf() --- src/GUI/Plater.cpp | 13 ++++++++----- src/GUI/Plater.hpp | 7 ++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 6336fc3f1..25b99ec16 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -373,12 +373,15 @@ void Plater::refresh_canvases() { } void Plater::arrange() { - // pause background process - Slic3r::Log::info(LogChannel, L"Called arrange()"); - auto bb {Slic3r::BoundingBoxf(this->config->get("bed_shape").values)}; - bool success {this->model->arrange_objects(5, &bb)}; + // TODO pause background process + const Slic3r::BoundingBoxf bb {Slic3r::BoundingBoxf(this->config->get("bed_shape").values)}; + bool success {this->model->arrange_objects(this->config->min_object_distance(), &bb)}; - GetFrame()->statusbar->SetStatusText(_("Objects were arranged.")); + if (success) { + GetFrame()->statusbar->SetStatusText(_("Objects were arranged.")); + } else { + GetFrame()->statusbar->SetStatusText(_("Arrange failed.")); + } this->on_model_change(true); } diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 8898ea037..394cd2843 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -39,7 +39,7 @@ public: Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings); void add(); - /// Arrange models + /// Arrange models via a simple packing mechanism based on bounding boxes. void arrange(); /// Ask if there are any unsaved changes. @@ -90,8 +90,9 @@ private: int get_object_index(size_t object_id); Slic3r::Pointf bed_centerf() { - auto bed_shape { Slic3r::Polygon::new_scale(this->config->get("bed_shape").values) }; - return Slic3r::Pointf(); + const auto& bed_shape { Slic3r::Polygon::new_scale(this->config->get("bed_shape").values) }; + const auto& bed_center {BoundingBox(bed_shape).center()}; + return Slic3r::Pointf::new_unscale(bed_center); } /// Build thumbnails for the models From d44f63059ccf639c8ac2e75dd18aff6821de0a84 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 9 May 2018 21:48:35 -0500 Subject: [PATCH 136/305] More documentation of Plater methods. --- src/GUI/Plater.hpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 394cd2843..977066f19 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -37,6 +37,9 @@ class Plater : public wxPanel { public: Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings); + + /// User-level function called through external interface. + /// Pops file dialog. void add(); /// Arrange models via a simple packing mechanism based on bounding boxes. @@ -58,7 +61,7 @@ private: std::vector objects {}; //< Main object vector. - size_t object_identifier {0U}; //< Counter for adding objects to Slic3r + size_t object_identifier {0U}; //< Counter for adding objects to Slic3r. Increment after adding each object. std::stack undo {}; std::stack redo {}; @@ -79,16 +82,20 @@ private: const std::string LogChannel {"GUI_Plater"}; //< Which log these messages should go to. + /// Populate the PlaterObject vector. std::vector load_model_objects(ModelObject* model_object); std::vector load_model_objects(ModelObjectPtrs model_objects); bool scaled_down {false}; bool outside_bounds {false}; + + /// Method to get the top-level window and cast it as a MainFrame. MainFrame* GetFrame(); void select_object(size_t& obj_idx) { }; int get_object_index(size_t object_id); + /// Get the center of the configured bed's bounding box. Slic3r::Pointf bed_centerf() { const auto& bed_shape { Slic3r::Polygon::new_scale(this->config->get("bed_shape").values) }; const auto& bed_center {BoundingBox(bed_shape).center()}; @@ -100,6 +107,9 @@ private: /// Complete thumbnail transformation and refresh canvases void on_thumbnail_made(size_t idx); + + + /// Issue a repaint event to all of the canvasses. void refresh_canvases(); From dc626de8b34eb96884751f704e48e0c1b4565114 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 9 May 2018 21:49:04 -0500 Subject: [PATCH 137/305] use wxID_ANY instead of -1 for calling preview notebook --- src/GUI/Plater.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 977066f19..8e90937b9 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -66,7 +66,7 @@ private: std::stack undo {}; std::stack redo {}; - wxNotebook* preview_notebook {new wxNotebook(this, -1, wxDefaultPosition, wxSize(335,335), wxNB_BOTTOM)}; + wxNotebook* preview_notebook {new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(335,335), wxNB_BOTTOM)}; wxBoxSizer* right_sizer {new wxBoxSizer(wxVERTICAL)}; wxToolBar* htoolbar {nullptr}; //< toolbar for non-MSW platforms. From e835184cef45ff88c634a68f57bf3af6bb2aa881 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 9 May 2018 21:55:20 -0500 Subject: [PATCH 138/305] added a little bit of whitespace to Plater.hpp --- src/GUI/Plater.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 8e90937b9..9ad6df3a3 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -47,6 +47,7 @@ public: /// Ask if there are any unsaved changes. bool prompt_unsaved_changes() { return true; } + private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; From 014d134823163137fe32afc4821d2b19649f950c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 9 May 2018 21:56:15 -0500 Subject: [PATCH 139/305] Utility function for generating scaled points from wxPoints. --- src/GUI/misc_ui.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index 28c28377d..b22c73b3a 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -14,6 +14,7 @@ #include "Settings.hpp" #include "Log.hpp" +#include "Point.hpp" /// Macro to build std::wstring that slic3r::log expects using << syntax of wxString @@ -133,6 +134,8 @@ wxString encode_path(const wxString& in); std::vector open_model(wxWindow* parent, const Settings& settings, wxWindow* top); +inline Slic3r::Point new_scale(const wxPoint& p) { return Slic3r::Point::new_scale(p.x, p.y); } + }} // namespace Slic3r::GUI #endif // MISC_UI_HPP From b8a9761b6c371ff2c607d736abeb49268baa17da Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 9 May 2018 21:57:04 -0500 Subject: [PATCH 140/305] Fix typo in drag_start_pos assignment. --- src/GUI/Plater/Plate2D.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 7ef0dd1b6..27849366e 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -183,10 +183,10 @@ void Plate2D::mouse_down(wxMouseEvent& e) { auto& instance {this->model->objects.at(obj_idx)->instances.at(instance_idx)}; auto instance_origin { Point::new_scale(instance->offset) }; - this->drag_start_pos { Slic3r::Point( + this->drag_start_pos = wxPoint( point.x - instance_origin.x, - point.y - instance_origin.y, - )}; + point.y - instance_origin.y + ); this->drag_object = { obj_idx, instance_idx }; this->selected_instance = this->drag_object; From d48166ae929e278e64adc3f1c2390b0ab2c235ee Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 9 May 2018 23:03:06 -0500 Subject: [PATCH 141/305] Stubbed out classes for 3D plater/preview, 2D preview (toolpaths), and DLP/SLA preview tabs. --- src/GUI/Plater.cpp | 17 +++++++++++++++++ src/GUI/Plater.hpp | 6 ++++++ src/GUI/Plater/Plate3D.hpp | 11 +++++++++++ src/GUI/Plater/Preview2D.hpp | 28 ++++++++++++++++++++++++++++ src/GUI/Plater/Preview3D.hpp | 12 ++++++++++++ src/GUI/Plater/PreviewDLP.hpp | 28 ++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+) create mode 100644 src/GUI/Plater/Preview2D.hpp create mode 100644 src/GUI/Plater/PreviewDLP.hpp diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 25b99ec16..d743cd37d 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -63,6 +63,18 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrAddPage(canvas2D, _("2D")); + + canvas3D = new Plate3D(preview_notebook, wxDefaultSize, objects, model, config, settings); + preview_notebook->AddPage(canvas3D, _("3D")); + + preview3D = new Preview3D(preview_notebook, wxDefaultSize, objects, model, config, settings); + preview_notebook->AddPage(preview3D, _("Preview")); + + preview2D = new Preview2D(preview_notebook, wxDefaultSize, objects, model, config, settings); + preview_notebook->AddPage(preview2D, _("Toolpaths")); + + previewDLP = new PreviewDLP(preview_notebook, wxDefaultSize, objects, model, config, settings); + preview_notebook->AddPage(previewDLP, _("DLP/SLA")); /* # Initialize 2D preview canvas @@ -369,6 +381,11 @@ void Plater::refresh_canvases() { this->canvas3D->update(); if (this->preview3D != nullptr) this->preview3D->reload_print(); + if (this->preview2D != nullptr) + this->preview2D->reload_print(); + + if (this->previewDLP != nullptr) + this->previewDLP->reload_print(); } diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 9ad6df3a3..a306217ce 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -17,7 +17,10 @@ #include "Plater/PlaterObject.hpp" #include "Plater/Plate2D.hpp" #include "Plater/Plate3D.hpp" +#include "Plater/Preview2D.hpp" #include "Plater/Preview3D.hpp" +#include "Plater/PreviewDLP.hpp" + #include "Settings.hpp" #include "MainFrame.hpp" @@ -76,8 +79,11 @@ private: Plate2D* canvas2D {nullptr}; //< 2D plater canvas Plate3D* canvas3D {nullptr}; //< 3D plater canvas + Preview2D* preview2D {nullptr}; //< 2D Preview Preview3D* preview3D {nullptr}; //< 3D Preview + PreviewDLP* previewDLP {nullptr}; //< DLP/SLA Preview canvas + /// Handles the actual load of the file from the dialog handoff. std::vector load_file(const std::string file, const int obj_idx_to_load = -1); diff --git a/src/GUI/Plater/Plate3D.hpp b/src/GUI/Plater/Plate3D.hpp index 488e35019..7df04abcb 100644 --- a/src/GUI/Plater/Plate3D.hpp +++ b/src/GUI/Plater/Plate3D.hpp @@ -4,12 +4,23 @@ #ifndef WX_PRECOMP #include #endif +#include "Settings.hpp" +#include "Model.hpp" +#include "Config.hpp" namespace Slic3r { namespace GUI { class Plate3D : public wxPanel { public: void update() {}; + Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) + {} +private: + std::vector& objects; //< reference to parent vector + std::shared_ptr model; + std::shared_ptr config; + std::shared_ptr settings; }; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Preview2D.hpp b/src/GUI/Plater/Preview2D.hpp new file mode 100644 index 000000000..9aa4c37f7 --- /dev/null +++ b/src/GUI/Plater/Preview2D.hpp @@ -0,0 +1,28 @@ +#ifndef PREVIEW2D_HPP +#define PREVIEW2D_HPP +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "Settings.hpp" +#include "Model.hpp" +#include "Config.hpp" + +namespace Slic3r { namespace GUI { + +class Preview2D : public wxPanel { +public: + void reload_print() {}; + Preview2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) + {} +private: + std::vector& objects; //< reference to parent vector + std::shared_ptr model; + std::shared_ptr config; + std::shared_ptr settings; +}; + +} } // Namespace Slic3r::GUI +#endif diff --git a/src/GUI/Plater/Preview3D.hpp b/src/GUI/Plater/Preview3D.hpp index cd4e0a283..2baa63900 100644 --- a/src/GUI/Plater/Preview3D.hpp +++ b/src/GUI/Plater/Preview3D.hpp @@ -5,11 +5,23 @@ #include #endif +#include "Settings.hpp" +#include "Model.hpp" +#include "Config.hpp" + namespace Slic3r { namespace GUI { class Preview3D : public wxPanel { public: void reload_print() {}; + Preview3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) + {} +private: + std::vector& objects; //< reference to parent vector + std::shared_ptr model; + std::shared_ptr config; + std::shared_ptr settings; }; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/PreviewDLP.hpp b/src/GUI/Plater/PreviewDLP.hpp new file mode 100644 index 000000000..090483cc1 --- /dev/null +++ b/src/GUI/Plater/PreviewDLP.hpp @@ -0,0 +1,28 @@ +#ifndef PREVIEWDLP_HPP +#define PREVIEWDLP_HPP +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "Settings.hpp" +#include "Model.hpp" +#include "Config.hpp" + +namespace Slic3r { namespace GUI { + +class PreviewDLP : public wxPanel { +public: + void reload_print() {}; + PreviewDLP(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) + {} +private: + std::vector& objects; //< reference to parent vector + std::shared_ptr model; + std::shared_ptr config; + std::shared_ptr settings; +}; + +} } // Namespace Slic3r::GUI +#endif From 10c538c683992bd7f881322c801b2666335c5077 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 10 May 2018 18:48:04 -0500 Subject: [PATCH 142/305] made SLIC3R_STATIC a -D option instead of environment var --- src/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6db5c038e..d99259a0b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -173,15 +173,15 @@ add_library(bthread SHARED IMPORTED) set_target_properties(bthread PROPERTIES IMPORTED_LOCATION ${bthread_l}) include_directories(${Boost_INCLUDE_DIRS}) -if(DEFINED ENV{SLIC3R_STATIC}) +if(${SLIC3R_STATIC}) set(wxWidgets_USE_STATIC ON) -ELSE(DEFINED ENV{SLIC3R_STATIC}) +else(${SLIC3R_STATIC}) set(wxWidgets_USE_STATIC OFF) -ENDIF(DEFINED ENV{SLIC3R_STATIC}) +endif(${SLIC3R_STATIC}) set(wxWidgets_USE_UNICODE ON) -find_package(wxWidgets COMPONENTS base aui core html) +find_package(wxWidgets COMPONENTS net gl html aui core base) IF(CMAKE_HOST_UNIX) #set(Boost_LIBRARIES bsystem bthread bfilesystem) From aba90c705afafd99469bb6d322b69d51f976e6cf Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 10 May 2018 18:48:24 -0500 Subject: [PATCH 143/305] Fix some linking under MinGW. --- src/CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d99259a0b..e9a911c6d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -232,8 +232,15 @@ IF (WIN32) add_library(boost-nowide STATIC ${LIBDIR}/boost/nowide/iostream.cpp ) + target_link_libraries(slic3r boost-nowide) - target_link_libraries(slic3r STATIC boost-nowide) + # Windows findwxwidgets doesn't get everything needed for wxMSW + target_link_libraries(slic3r uxtheme) + # MinGW apparently has some multiple definitions of UUID-related items + # deal with it. + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_EXE_LINKER_FLAGS "-Wl,--allow-multiple-definition") + endif() # target_link_libraries(extrude-tin boost-nowide) ENDIF(WIN32) From a57a9dc700d66614f57d18b321d8db0db93033ca Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 10 May 2018 19:08:58 -0500 Subject: [PATCH 144/305] Set the bitmap type (needed for wxMSW) and check that the load happens before trying to use it. --- src/GUI/MainFrame.cpp | 7 +------ src/GUI/misc_ui.hpp | 9 +++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 7a99f5f25..2ee7bba9e 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -17,12 +17,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si : wxFrame(NULL, wxID_ANY, title, pos, size), loaded(false), tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(_gui_config), preset_editor_tabs(std::map()) { - // Set icon to either the .ico if windows or png for everything else. - if (the_os == OS::Windows) - this->SetIcon(wxIcon(var("Slic3r.ico"), wxBITMAP_TYPE_ICO)); - else - this->SetIcon(wxIcon(var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG)); - + this->SetIcon(wxIcon(var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG)); this->init_tabpanel(); this->init_menubar(); diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index b22c73b3a..51a677504 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -115,8 +115,13 @@ void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T tmp->SetAccel(a); // set the accelerator if and only if the accelerator is fine } tmp->SetHelp(help); - if (!icon.IsEmpty()) - tmp->SetBitmap(wxBitmap(var(icon))); + if (!icon.IsEmpty()) { + wxBitmap ico; + if(ico.LoadFile(var(icon), wxBITMAP_TYPE_PNG)) + tmp->SetBitmap(ico); + else + std::cerr<< var(icon) << " failed to load \n"; + } if (typeid(lambda) != typeid(nullptr)) menu->Bind(wxEVT_MENU, lambda, tmp->GetId(), tmp->GetId()); From ce21077c617d51bace69b844ecbd20574149909a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 10 May 2018 19:09:39 -0500 Subject: [PATCH 145/305] Define wxGTK as false under win32 or osx --- src/GUI/misc_ui.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index 51a677504..fb3930325 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -29,8 +29,10 @@ enum class OS { Linux, Mac, Windows } ; // constants to reduce the proliferation of macros in the rest of the code #ifdef __WIN32 constexpr OS the_os = OS::Windows; +constexpr bool wxGTK {false}; #elif __APPLE__ constexpr OS the_os = OS::Mac; +constexpr bool wxGTK {false}; #elif __linux__ constexpr OS the_os = OS::Linux; #ifdef __WXGTK__ From cbede041d25c84d0afc1d9eb1b592c7ada10bc0b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 10 May 2018 19:10:33 -0500 Subject: [PATCH 146/305] be a little smarter about converting things (avoids confusing mingw 7.3) --- src/GUI/Plater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index d743cd37d..56a93f09d 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -280,7 +280,7 @@ std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { auto tmpobj {PlaterObject()}; const auto objfile {wxFileName::FileName( obj->input_file )}; - tmpobj.name = wxString(std::string() == obj->name ? obj->name : objfile.GetName()); + tmpobj.name = (std::string() == obj->name ? wxString(obj->name) : objfile.GetName()); tmpobj.identifier = (this->object_identifier)++; this->objects.push_back(tmpobj); From dfe4f54d080a9e02edb688a83593d1b6265f46fc Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 11 May 2018 22:34:40 -0500 Subject: [PATCH 147/305] stubbed methods to fire object_settings_dialog, retrieve the current selected object, etc. --- src/GUI/Plater.cpp | 116 +++++++++++++++++++++++++++++++++++++++++++++ src/GUI/Plater.hpp | 14 ++++++ 2 files changed, 130 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 56a93f09d..4a4174dc5 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -409,5 +409,121 @@ void Plater::on_model_change(bool force_autocenter) { this->refresh_canvases(); } +ObjRef Plater::selected_object() { + Slic3r::Log::info(LogChannel, L"Calling selected_object()"); + auto it {this->objects.begin()}; + for (it; it != this->objects.end(); it++) + if (it->selected) return it; + Slic3r::Log::info(LogChannel, L"No object selected."); + return this->objects.end(); +} + +void Plater::object_settings_dialog() { object_settings_dialog(this->selected_object()); } +void Plater::object_settings_dialog(ObjIdx obj_idx) { object_settings_dialog(this->objects.begin() + obj_idx); } +void Plater::object_settings_dialog(ObjRef obj) { + +} + +wxMenu* Plater::object_menu() { + return new wxMenu(); +} + + +void Plater::select_object(ObjRef obj) { + for (auto& o : this->objects) { + o.selected = false; + o.selected_instance = -1; + } + if (obj >= this->objects.end() && obj < this->objects.begin()) { + obj->selected = true; + obj->selected_instance = 0; + } + this->selection_changed(); // selection_changed(1) in perl +} + +void Plater::select_object(ObjIdx obj_idx) { + this->select_object(this->objects.begin() + obj_idx); +} + +void Plater::select_object() { + this->select_object(this->objects.end()); +} + +void Plater::selection_changed() { + // Remove selection in 2D plater + this->canvas2D->set_selected(-1, -1); + + auto obj = this->selected_object(); + bool have_sel {obj != this->objects.end()}; + /* + if (my $menu = $self->GetFrame->{plater_select_menu}) { + $_->Check(0) for $menu->GetMenuItems; + if ($have_sel) { + $menu->FindItemByPosition($obj_idx)->Check(1); + } + } + + my $method = $have_sel ? 'Enable' : 'Disable'; + $self->{"btn_$_"}->$method + for grep $self->{"btn_$_"}, qw(remove increase decrease rotate45cw rotate45ccw changescale split cut layers settings); + + if ($self->{htoolbar}) { + $self->{htoolbar}->EnableTool($_, $have_sel) + for (TB_REMOVE, TB_MORE, TB_FEWER, TB_45CW, TB_45CCW, TB_SCALE, TB_SPLIT, TB_CUT, TB_LAYERS, TB_SETTINGS); + } + + if ($self->{object_info_size}) { # have we already loaded the info pane? + + if ($have_sel) { + my $model_object = $self->{model}->objects->[$obj_idx]; + $self->{object_info_choice}->SetSelection($obj_idx); + $self->{object_info_copies}->SetLabel($model_object->instances_count); + my $model_instance = $model_object->instances->[0]; + { + my $size_string = sprintf "%.2f x %.2f x %.2f", @{$model_object->instance_bounding_box(0)->size}; + if ($model_instance->scaling_factor != 1) { + $size_string .= sprintf " (%s%%)", $model_instance->scaling_factor * 100; + } + $self->{object_info_size}->SetLabel($size_string); + } + $self->{object_info_materials}->SetLabel($model_object->materials_count); + + my $raw_mesh = $model_object->raw_mesh; + $raw_mesh->repair; # this calculates number_of_parts + if (my $stats = $raw_mesh->stats) { + $self->{object_info_volume}->SetLabel(sprintf('%.2f', $raw_mesh->volume * ($model_instance->scaling_factor**3))); + $self->{object_info_facets}->SetLabel(sprintf('%d (%d shells)', $model_object->facets_count, $stats->{number_of_parts})); + if (my $errors = sum(@$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)})) { + $self->{object_info_manifold}->SetLabel(sprintf("Auto-repaired (%d errors)", $errors)); + $self->{object_info_manifold_warning_icon}->Show; + + # we don't show normals_fixed because we never provide normals + # to admesh, so it generates normals for all facets + my $message = sprintf '%d degenerate facets, %d edges fixed, %d facets removed, %d facets added, %d facets reversed, %d backwards edges', + @$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)}; + $self->{object_info_manifold}->SetToolTipString($message); + $self->{object_info_manifold_warning_icon}->SetToolTipString($message); + } else { + $self->{object_info_manifold}->SetLabel("Yes"); + } + } else { + $self->{object_info_facets}->SetLabel($object->facets); + } + } else { + $self->{object_info_choice}->SetSelection(-1); + $self->{"object_info_$_"}->SetLabel("") for qw(copies size volume facets materials manifold); + $self->{object_info_manifold_warning_icon}->Hide; + $self->{object_info_manifold}->SetToolTipString(""); + } + $self->Layout; + } + # prepagate the event to the frame (a custom Wx event would be cleaner) + $self->GetFrame->on_plater_selection_changed($have_sel); +*/ + + +} + + }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index a306217ce..a91053a8b 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -119,10 +119,24 @@ private: /// Issue a repaint event to all of the canvasses. void refresh_canvases(); + /// Action to take when selection changes. Update platers, etc. + void selection_changed(); /// Run everything that needs to happen when models change. /// Includes updating canvases, reloading menus, etc. void on_model_change(bool force_autocenter = false); + + /// Searches the object vector for the first selected object and returns an iterator to it. + ObjRef selected_object(); + + /// Create and launch dialog for object settings. + void object_settings_dialog(); + void object_settings_dialog(ObjIdx obj_idx); + void object_settings_dialog(ObjRef obj); + + /// Create and launch menu for object. + wxMenu* object_menu(); + }; From 872fd617066ab6880b2f4a7ca2c7787e67bac666 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 11 May 2018 22:36:37 -0500 Subject: [PATCH 148/305] Moved assignable methods to std::function objects. --- src/GUI/Plater.cpp | 47 ++++++++++++++++++-------------------- src/GUI/Plater/Plate2D.cpp | 2 -- src/GUI/Plater/Plate2D.hpp | 16 +++++++++---- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 4a4174dc5..68ad6b5ed 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -23,31 +23,22 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrselect_object(obj_idx); - } }; + + // Initialize handlers for canvases + auto on_select_object {[this](ObjIdx obj_idx) { this->select_object(obj_idx); }}; + auto on_double_click {[this]() { if (this->selected_object() != this->objects.end()) this->object_settings_dialog(); }}; + auto on_right_click {[this](wxPanel* canvas, const wxPoint& pos) + { + auto obj = this->selected_object(); + if (obj == this->objects.end()) return; + + auto menu = this->object_menu(); + canvas->PopupMenu(menu, pos); + delete menu; + }}; + auto on_instances_moved {[this]() { this->on_model_change(); }}; + /* - # Initialize handlers for canvases - my $on_select_object = sub { - my ($obj_idx) = @_; - $self->select_object($obj_idx); - }; - my $on_double_click = sub { - $self->object_settings_dialog if $self->selected_object; - }; - my $on_right_click = sub { - my ($canvas, $click_pos) = @_; - - my ($obj_idx, $object) = $self->selected_object; - return if !defined $obj_idx; - - my $menu = $self->object_menu; - $canvas->PopupMenu($menu, $click_pos); - $menu->Destroy; - }; - my $on_instances_moved = sub { - $self->on_model_change; - }; # Initialize 3D plater if ($Slic3r::GUI::have_OpenGL) { $self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{config}); @@ -61,9 +52,15 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrAddPage(canvas2D, _("2D")); - + + canvas2D->on_select_object = std::function(on_select_object); + canvas2D->on_double_click = std::function(on_double_click); + canvas2D->on_right_click = std::function([=](const wxPoint& pos){ on_right_click(canvas2D, pos); }); + canvas3D = new Plate3D(preview_notebook, wxDefaultSize, objects, model, config, settings); preview_notebook->AddPage(canvas3D, _("3D")); diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 27849366e..bb5738701 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -202,8 +202,6 @@ void Plate2D::mouse_down(wxMouseEvent& e) { } } -void Plate2D::on_select_object(int i) { -} void Plate2D::mouse_up(wxMouseEvent& e) { } diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 57212a613..22f663cb7 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -42,7 +42,17 @@ public: /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. void update_bed_size(); -// std::function<> on_select_object {}; + + std::function on_select_object {}; + std::function on_double_click {}; + + /// Do something on right-clicks. + std::function on_right_click {}; + std::function on_instances_moved {}; + + + void set_selected (long obj, long inst) { this->selected_instance = {obj, inst}; } + private: std::vector& objects; //< reference to parent vector std::shared_ptr model; @@ -77,8 +87,6 @@ private: wxPoint drag_start_pos {}; - /// Do something on right-clicks. - void on_right_click(const wxPoint& pos) { } /// Handle repaint events void repaint(wxPaintEvent& e); @@ -132,8 +140,6 @@ private: /// Remove all instance thumbnails. void clean_instance_thumbnails(); - - void on_select_object(int); }; } } // Namespace Slic3r::GUI From 1d4e5775ae412434398706e17c376eb09d9746e3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 11 May 2018 22:38:00 -0500 Subject: [PATCH 149/305] Set typedef (via using directive) for object references (iterators) and object indices. --- src/GUI/Plater.cpp | 2 +- src/GUI/Plater.hpp | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 68ad6b5ed..499267e98 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -328,7 +328,7 @@ std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { MainFrame* Plater::GetFrame() { return dynamic_cast(wxGetTopLevelParent(this)); } -int Plater::get_object_index(size_t object_id) { +int Plater::get_object_index(ObjIdx object_id) { for (size_t i = 0U; i < this->objects.size(); i++) { if (this->objects.at(i).identifier == object_id) return static_cast(i); } diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index a91053a8b..c73899b13 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -28,7 +28,8 @@ namespace Slic3r { namespace GUI { using UndoOperation = int; -using obj_index = unsigned int; +using ObjIdx = unsigned int; +using ObjRef = std::vector::iterator; class PlaterObject; class Plate2D; @@ -99,8 +100,13 @@ private: /// Method to get the top-level window and cast it as a MainFrame. MainFrame* GetFrame(); - void select_object(size_t& obj_idx) { }; - int get_object_index(size_t object_id); + void select_object(ObjRef obj_idx); + void select_object(ObjIdx obj_idx); + + /// Overload to unselect objects + void select_object(); + + int get_object_index(ObjIdx object_id); /// Get the center of the configured bed's bounding box. Slic3r::Pointf bed_centerf() { From 13e8a1ea1af5111f3df3c848c0b91511ec675de8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 11 May 2018 23:07:07 -0500 Subject: [PATCH 150/305] Use correct range for range check on iterator. --- src/GUI/Plater.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 499267e98..1b0a58db4 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -431,7 +431,8 @@ void Plater::select_object(ObjRef obj) { o.selected = false; o.selected_instance = -1; } - if (obj >= this->objects.end() && obj < this->objects.begin()) { + // range check the iterator + if (obj < this->objects.end() && obj >= this->objects.begin()) { obj->selected = true; obj->selected_instance = 0; } From 74570f822ce25f4090e286ced7cad176ecb1fd76 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 11 May 2018 23:09:15 -0500 Subject: [PATCH 151/305] Object selection now functions on 2D plater. --- src/GUI/Plater/Plate2D.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index bb5738701..598061be0 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -116,9 +116,9 @@ void Plate2D::repaint(wxPaintEvent& e) { if (0) { // object is dragged dc->SetBrush(dragged_brush); - } else if (0) { + } else if (obj.selected && obj.selected_instance >= 0 && obj.selected_instance == static_cast(instance_idx)) { dc->SetBrush(instance_brush); - } else if (0) { + } else if (obj.selected) { dc->SetBrush(selected_brush); } else { dc->SetBrush(objects_brush); @@ -147,6 +147,7 @@ void Plate2D::mouse_drag(wxMouseEvent& e) { const auto& point {this->point_to_model_units(e.GetPosition())}; if (e.Dragging()) { Slic3r::Log::info(LogChannel, L"Mouse dragging"); + this->Refresh(); } else { auto cursor = wxSTANDARD_CURSOR; /* @@ -198,9 +199,8 @@ void Plate2D::mouse_down(wxMouseEvent& e) { } } } - } - + this->Refresh(); } void Plate2D::mouse_up(wxMouseEvent& e) { From a49ab1549d8de7d0a7b8444585753e53d260511d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 13:38:09 -0500 Subject: [PATCH 152/305] Cleaned up a pointless statement warning. --- src/GUI/Plater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 1b0a58db4..a33fa713e 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -409,7 +409,7 @@ void Plater::on_model_change(bool force_autocenter) { ObjRef Plater::selected_object() { Slic3r::Log::info(LogChannel, L"Calling selected_object()"); auto it {this->objects.begin()}; - for (it; it != this->objects.end(); it++) + for (; it != this->objects.end(); it++) if (it->selected) return it; Slic3r::Log::info(LogChannel, L"No object selected."); return this->objects.end(); From b88d36c391a42d9d44655f482129add0ab577bf0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 13:38:41 -0500 Subject: [PATCH 153/305] Removed dead code and a spammy log message. --- src/GUI/Plater/Plate2D.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 598061be0..8bb97a1ba 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -143,10 +143,8 @@ void Plate2D::clean_instance_thumbnails() { } void Plate2D::mouse_drag(wxMouseEvent& e) { - const auto pos {e.GetPosition()}; const auto& point {this->point_to_model_units(e.GetPosition())}; if (e.Dragging()) { - Slic3r::Log::info(LogChannel, L"Mouse dragging"); this->Refresh(); } else { auto cursor = wxSTANDARD_CURSOR; From ef0f7bf7bb41b42b47a55b72e23ae206daee6abd Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 13:39:20 -0500 Subject: [PATCH 154/305] 2D click and drag functions now like in perl side. --- src/GUI/Plater/Plate2D.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 8bb97a1ba..46b8ae586 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -145,6 +145,14 @@ void Plate2D::clean_instance_thumbnails() { void Plate2D::mouse_drag(wxMouseEvent& e) { const auto& point {this->point_to_model_units(e.GetPosition())}; if (e.Dragging()) { + if (!this->drag_start_pos.IsFullySpecified()) return; // possible concurrency problems? + auto model_object = this->model->objects.at(this->drag_object.obj); + model_object->instances.at(this->drag_object.inst)->offset = + Slic3r::Pointf( + unscale(point.x - this->drag_start_pos.x), + unscale(point.y - this->drag_start_pos.y) + ); + model_object->update_bounding_box(); this->Refresh(); } else { auto cursor = wxSTANDARD_CURSOR; From 539e83e74f2b276f8d921c34c49fc06b1c501572 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 13:39:45 -0500 Subject: [PATCH 155/305] Set some default values. --- src/GUI/Plater/Plate2D.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 22f663cb7..064749757 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -76,8 +76,8 @@ private: bool user_drawn_background {(the_os == OS::Mac ? false : true)}; /// The object id and selected - InstanceIdx selected_instance; - InstanceIdx drag_object; + InstanceIdx selected_instance {-1, -1}; + InstanceIdx drag_object {-1, -1}; /// Handle mouse-move events void mouse_drag(wxMouseEvent& e); @@ -85,7 +85,7 @@ private: void mouse_up(wxMouseEvent& e); void mouse_dclick(wxMouseEvent& e); - wxPoint drag_start_pos {}; + wxPoint drag_start_pos {wxPoint(-1, -1)}; /// Handle repaint events From c08d0de7d0c5d0e1465a5b9c24fe5b8ab6824c87 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 13:40:51 -0500 Subject: [PATCH 156/305] Mostly implemented mouseup on 2D player. Someting through on_instances_moved causes an uncaught exception. --- src/GUI/Plater/Plate2D.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 46b8ae586..8dd729c52 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -210,6 +210,12 @@ void Plate2D::mouse_down(wxMouseEvent& e) { } void Plate2D::mouse_up(wxMouseEvent& e) { + if (e.LeftUp()) { + //if (this->drag_object.obj != -1 && this->drag_object.inst != -1) this->on_instances_moved(); + this->drag_start_pos = wxPoint(-1, -1); + this->drag_object = {-1, -1}; + this->SetCursor(*wxSTANDARD_CURSOR); + } } void Plate2D::mouse_dclick(wxMouseEvent& e) { } From f1ec1f068f56ec6dfc4c4985f323da9a756eff39 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 16:05:02 -0500 Subject: [PATCH 157/305] 2D Plater: Change cursor to hand cursor when over selectable items. Includes function to check if any instance in a PlaterObject includes a point (makes logic much more readable). --- src/GUI/Plater/Plate2D.cpp | 16 +++++++++------- src/GUI/Plater/PlaterObject.cpp | 7 +++++++ src/GUI/Plater/PlaterObject.hpp | 2 ++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 8dd729c52..b25c256eb 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -154,14 +154,16 @@ void Plate2D::mouse_drag(wxMouseEvent& e) { ); model_object->update_bounding_box(); this->Refresh(); - } else { - auto cursor = wxSTANDARD_CURSOR; - /* - if (find_first_of(this->objects.begin(), this->objects.end(); [=](const PlaterObject& o) { return o.contour->contains_point(point);} ) == this->object.end()) { - cursor = wxCursor(wxCURSOR_HAND); + } else { // moving + + if (std::any_of(this->objects.cbegin(), this->objects.cend(), + [=](const Slic3r::GUI::PlaterObject o) { return o.instance_contains(point); }) + ) + { + this->SetCursor(wxCURSOR_HAND); + } else { + this->SetCursor(*wxSTANDARD_CURSOR); } - */ - this->SetCursor(*cursor); } } diff --git a/src/GUI/Plater/PlaterObject.cpp b/src/GUI/Plater/PlaterObject.cpp index 442c5d412..1ecee7b49 100644 --- a/src/GUI/Plater/PlaterObject.cpp +++ b/src/GUI/Plater/PlaterObject.cpp @@ -55,4 +55,11 @@ Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(std::shared_ptrtransformed_thumbnail; } +bool PlaterObject::instance_contains(Slic3r::Point point) const { + return std::any_of(this->instance_thumbnails.cbegin(), this->instance_thumbnails.cend(), + [point](const ExPolygonCollection ep) { + return ep.contains(point); + }); +} + } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp index d1d2f7056..d5f857583 100644 --- a/src/GUI/Plater/PlaterObject.hpp +++ b/src/GUI/Plater/PlaterObject.hpp @@ -33,6 +33,8 @@ public: Slic3r::ExPolygonCollection& transform_thumbnail(const Slic3r::Model model, int obj_idx); Slic3r::ExPolygonCollection& transform_thumbnail(const std::shared_ptr model, int obj_idx); + bool instance_contains(Slic3r::Point point) const; + protected: const std::string LogChannel {"PlaterObject"}; From ca0e39d7e78a7007c909f2145da660e2cc3397f3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 16:05:22 -0500 Subject: [PATCH 158/305] 2D Plater: Added double-click handler. --- src/GUI/Plater/Plate2D.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index b25c256eb..e53eec7d9 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -220,6 +220,9 @@ void Plate2D::mouse_up(wxMouseEvent& e) { } } void Plate2D::mouse_dclick(wxMouseEvent& e) { + if (e.LeftDClick()) { + this->on_double_click(); + } } void Plate2D::set_colors() { From 2bb1c1ab39918656ca2c1852f65ec31ff1a2d82f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 16:41:56 -0500 Subject: [PATCH 159/305] Use wxDateTime::Now() to initialze current date instead of default constructor (avoid runtime errors) --- src/GUI/Plater/Plate2D.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 064749757..68e140f04 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -21,7 +21,7 @@ namespace Slic3r { namespace GUI { // Setup for an Easter Egg with the canvas text. -const wxDateTime today_date {wxDateTime().GetDateOnly()}; +const wxDateTime today_date {wxDateTime::Now()}; const wxDateTime special_date {13, wxDateTime::Month::Sep, 2006, 0, 0, 0, 0}; const bool today_is_special = {today_date.GetDay() == special_date.GetDay() && today_date.GetMonth() == special_date.GetMonth()}; From 9a4ab21bb825cf7d34295fa28cbd303c49114b05 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 16:56:32 -0500 Subject: [PATCH 160/305] Comment update to be more clear as to what is going on --- src/GUI/Plater/Plate2D.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index e53eec7d9..3e865086b 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -154,8 +154,7 @@ void Plate2D::mouse_drag(wxMouseEvent& e) { ); model_object->update_bounding_box(); this->Refresh(); - } else { // moving - + } else { // moving, set the cursor to the hand cursor. if (std::any_of(this->objects.cbegin(), this->objects.cend(), [=](const Slic3r::GUI::PlaterObject o) { return o.instance_contains(point); }) ) From 4e5ed9cdb072dc4b73eb442cefc5207d3ae4b737 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 16:58:29 -0500 Subject: [PATCH 161/305] Assign on_instances_moved and put a try/catch to not crash if it accidentally gets called while uninitialzed. --- src/GUI/Plater.cpp | 2 ++ src/GUI/Plater/Plate2D.cpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index a33fa713e..4e299aaa6 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -60,6 +60,8 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptron_select_object = std::function(on_select_object); canvas2D->on_double_click = std::function(on_double_click); canvas2D->on_right_click = std::function([=](const wxPoint& pos){ on_right_click(canvas2D, pos); }); + canvas2D->on_instances_moved = std::function(on_instances_moved); + canvas3D = new Plate3D(preview_notebook, wxDefaultSize, objects, model, config, settings); preview_notebook->AddPage(canvas3D, _("3D")); diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 3e865086b..10f9122e5 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -212,7 +212,11 @@ void Plate2D::mouse_down(wxMouseEvent& e) { void Plate2D::mouse_up(wxMouseEvent& e) { if (e.LeftUp()) { - //if (this->drag_object.obj != -1 && this->drag_object.inst != -1) this->on_instances_moved(); + try { + if (this->drag_object.obj != -1 && this->drag_object.inst != -1) this->on_instances_moved(); + } catch (std::bad_function_call &ex) { + Slic3r::Log::error(LogChannel, L"On_instances_moved was not intialized to a function."); + } this->drag_start_pos = wxPoint(-1, -1); this->drag_object = {-1, -1}; this->SetCursor(*wxSTANDARD_CURSOR); From cd9ba6932860dd3014351fae2d0b05cb474b4b60 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 17:32:30 -0500 Subject: [PATCH 162/305] Remembered to bind the right click mouse events, moved the associated comment. capture [this] instead of [=] for lambdas. --- src/GUI/Plater/Plate2D.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 10f9122e5..703615a7b 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -17,19 +17,22 @@ Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) { - this->Bind(wxEVT_PAINT, [=](wxPaintEvent &e) { this->repaint(e); }); - this->Bind(wxEVT_MOTION, [=](wxMouseEvent &e) { this->mouse_drag(e); }); - this->Bind(wxEVT_LEFT_DOWN, [=](wxMouseEvent &e) { this->mouse_down(e); }); - this->Bind(wxEVT_LEFT_UP, [=](wxMouseEvent &e) { this->mouse_up(e); }); - this->Bind(wxEVT_LEFT_DCLICK, [=](wxMouseEvent &e) { this->mouse_dclick(e); }); - - if (user_drawn_background) { - this->Bind(wxEVT_ERASE_BACKGROUND, [=](wxEraseEvent& e){ }); - } - - this->Bind(wxEVT_SIZE, [=](wxSizeEvent &e) { this->update_bed_size(); this->Refresh(); }); + this->Bind(wxEVT_PAINT, [this](wxPaintEvent &e) { this->repaint(e); }); + this->Bind(wxEVT_MOTION, [this](wxMouseEvent &e) { this->mouse_drag(e); }); // Bind the varying mouse events + this->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { this->mouse_down(e); }); + this->Bind(wxEVT_RIGHT_DOWN, [this](wxMouseEvent &e) { this->mouse_down(e); }); + this->Bind(wxEVT_LEFT_UP, [this](wxMouseEvent &e) { this->mouse_up(e); }); + this->Bind(wxEVT_LEFT_DCLICK, [this](wxMouseEvent &e) { this->mouse_dclick(e); }); + + if (user_drawn_background) { + this->Bind(wxEVT_ERASE_BACKGROUND, [this](wxEraseEvent& e){ }); + } + + this->Bind(wxEVT_SIZE, [this](wxSizeEvent &e) { this->update_bed_size(); this->Refresh(); }); + + // Set the brushes set_colors(); From 3e65cf843d4e1d6aefa77ed67a0a8830ba33ed48 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 17:33:01 -0500 Subject: [PATCH 163/305] Implemented keyboard nudge in 2D plater. --- src/GUI/Plater/Plate2D.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 703615a7b..e694b3680 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -32,6 +32,7 @@ Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector this->Bind(wxEVT_SIZE, [this](wxSizeEvent &e) { this->update_bed_size(); this->Refresh(); }); + this->Bind(wxEVT_CHAR, [this](wxKeyEvent &e) { this->nudge_key(e);}); // Set the brushes @@ -272,12 +273,16 @@ void Plate2D::nudge_key(wxKeyEvent& e) { switch( key ) { case WXK_LEFT: this->nudge(MoveDirection::Left); + break; case WXK_RIGHT: this->nudge(MoveDirection::Right); + break; case WXK_DOWN: this->nudge(MoveDirection::Down); + break; case WXK_UP: this->nudge(MoveDirection::Up); + break; default: break; // do nothing } @@ -299,6 +304,37 @@ void Plate2D::nudge(MoveDirection dir) { Slic3r::Log::warn(LogChannel, L"Nudge failed because there is no selected instance."); return; // Abort } + auto selected {this->selected_instance}; + auto obj {this->model->objects.at(selected.obj)}; + auto instance {obj->instances.at(selected.inst)}; + + Slic3r::Point shift(0,0); + + auto nudge_value {settings->nudge < 0.1 ? 0.1 : scale_(settings->nudge) }; + + switch (dir) { + case MoveDirection::Up: + shift.y = nudge_value; + break; + case MoveDirection::Down: + shift.y = -1.0f * nudge_value; + break; + case MoveDirection::Left: + shift.x = -1.0f * nudge_value; + break; + case MoveDirection::Right: + shift.x = nudge_value; + break; + default: + Slic3r::Log::error(LogChannel, L"Invalid direction supplied to nudge."); + } + Slic3r::Point instance_origin {Slic3r::Point::new_scale(instance->offset)}; + instance->offset = Slic3r::Pointf::new_unscale(shift + instance_origin); + + obj->update_bounding_box(); + this->Refresh(); + this->on_instances_moved(); + } void Plate2D::update_bed_size() { From 996a8e355a4d1b7f58a197b9357d7d275ea975b5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 18:38:55 -0500 Subject: [PATCH 164/305] Draw clearance area if necessary. --- src/GUI/Plater/Plate2D.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index e694b3680..15f449c03 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -134,6 +134,16 @@ void Plate2D::repaint(wxPaintEvent& e) { for (const auto& points : obj.instance_thumbnails.back().expolygons) { auto poly { this->scaled_points_to_pixel(Polygon(points), true) }; dc->DrawPolygon(poly.size(), poly.data(), 0, 0); + // TODO draw bounding box if that debug option is turned on. + + // if sequential printing is enabled and more than one object, draw clearance area + if (this->config->get("complete_objects") && + std::count_if(this->model->objects.cbegin(), this->model->objects.cend(), [](const ModelObject* o){ return o->instances.size() > 0; }) > 1) { + auto clearance {offset(thumbnail.convex_hull(), (scale_(this->config->get("extruder_clearance_radius")) / 2.0), 1.0, ClipperLib::jtRound, scale_(0.1))}; + dc->SetPen(this->clearance_pen); + dc->SetBrush(this->transparent_brush); + auto poly { this->scaled_points_to_pixel(Polygon(clearance.front()), true) }; + dc->DrawPolygon(poly.size(), poly.data(), 0, 0); } } } From 850e546c92fec348210fbaa1dadf2dc7c1e8d504 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 18:57:12 -0500 Subject: [PATCH 165/305] Draw skirt on 2D plater. --- src/GUI/Plater/Plate2D.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 15f449c03..685a95495 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -147,6 +147,29 @@ void Plate2D::repaint(wxPaintEvent& e) { } } } + + // Draw skirt + if (this->objects.size() > 0 && this->config->get("skirts") > 0) + { + // get all of the contours of the instances + Slic3r::Polygons tmp_cont {}; + for (auto obj : this->objects) { + for (auto inst : obj.instance_thumbnails) { + tmp_cont.push_back(inst.convex_hull()); + } + } + + // Calculate the offset hull and draw the points. + if (tmp_cont.size() > 0) { + dc->SetPen(this->skirt_pen); + dc->SetBrush(this->transparent_brush); + auto skirt {offset(Slic3r::Geometry::convex_hull(tmp_cont), + scale_(this->config->get("brim_width") + this->config->get("skirt_distance")), 1.0, ClipperLib::jtRound, scale_(0.1))}; + auto poly { this->scaled_points_to_pixel(skirt.front(), true) }; + dc->DrawPolygon(poly.size(), poly.data(), 0, 0); + } + } + e.Skip(); } From 2d386053f6bb97c77f5f8fcf817fafab366736e0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 19:21:22 -0500 Subject: [PATCH 166/305] Forgot to check in a } --- src/GUI/Plater/Plate2D.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 685a95495..10bdc0ec2 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -134,6 +134,7 @@ void Plate2D::repaint(wxPaintEvent& e) { for (const auto& points : obj.instance_thumbnails.back().expolygons) { auto poly { this->scaled_points_to_pixel(Polygon(points), true) }; dc->DrawPolygon(poly.size(), poly.data(), 0, 0); + } // TODO draw bounding box if that debug option is turned on. // if sequential printing is enabled and more than one object, draw clearance area From 1006abc5b841d06793f35cb4435f0fb6bbebc686 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 19:43:43 -0500 Subject: [PATCH 167/305] Cleaned up header for Plate2D.hpp; added comments. --- src/GUI/Plater/Plate2D.hpp | 58 +++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 68e140f04..67bbd4a57 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -8,23 +8,23 @@ #include #include -#include "Plater.hpp" + #include "ColorScheme.hpp" -#include "Settings.hpp" +#include "Plater.hpp" #include "Plater/PlaterObject.hpp" +#include "Settings.hpp" #include "misc_ui.hpp" #include "Log.hpp" - namespace Slic3r { namespace GUI { - // Setup for an Easter Egg with the canvas text. const wxDateTime today_date {wxDateTime::Now()}; const wxDateTime special_date {13, wxDateTime::Month::Sep, 2006, 0, 0, 0, 0}; const bool today_is_special = {today_date.GetDay() == special_date.GetDay() && today_date.GetMonth() == special_date.GetMonth()}; +/// Enumeration for object nudges. enum class MoveDirection { Up, Down, Left, Right }; @@ -37,20 +37,26 @@ struct InstanceIdx { class Plate2D : public wxPanel { public: - Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); + /// Constructor. Keeps a reference to the main configuration, the model, and the gui settings. + Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. void update_bed_size(); - std::function on_select_object {}; - std::function on_double_click {}; - /// Do something on right-clicks. std::function on_right_click {}; + + /// Do something when right-clicks occur. + std::function on_double_click {}; + + /// Registered function to fire when an instance is moved. std::function on_instances_moved {}; + /// Registered function to fire when objects are selected. + std::function on_select_object {}; + /// Set the selected object instance. void set_selected (long obj, long inst) { this->selected_instance = {obj, inst}; } private: @@ -59,7 +65,7 @@ private: std::shared_ptr config; std::shared_ptr settings; - // Different brushes to draw with, initialized from settings->Color during the constructor + /// Different brushes to draw with, initialized from settings->Color during the constructor wxBrush objects_brush {}; wxBrush instance_brush {}; wxBrush selected_brush {}; @@ -75,8 +81,10 @@ private: bool user_drawn_background {(the_os == OS::Mac ? false : true)}; - /// The object id and selected + /// Object and instance currently selected. InstanceIdx selected_instance {-1, -1}; + + /// Currently dragged object. InstanceIdx drag_object {-1, -1}; /// Handle mouse-move events @@ -85,15 +93,13 @@ private: void mouse_up(wxMouseEvent& e); void mouse_dclick(wxMouseEvent& e); - wxPoint drag_start_pos {wxPoint(-1, -1)}; + wxPoint drag_start_pos {wxPoint(-1, -1)}; //< Start coordinate for object drags + void repaint(wxPaintEvent& e); //< Handle repaint events - /// Handle repaint events - void repaint(wxPaintEvent& e); + void nudge_key(wxKeyEvent& e); //< Handler for wxKeyEvents. - void nudge_key(wxKeyEvent& e); - - void nudge(MoveDirection dir); + void nudge(MoveDirection dir); //< Perform object nudge on plater. /// Set/Update all of the colors used by the various brushes in the panel. void set_colors(); @@ -105,14 +111,13 @@ private: /// For a specific point, unscale it relative to the origin wxPoint unscaled_point_to_pixel(const wxPoint& in); - - /// Displacement needed to center bed. - wxPoint bed_origin {}; - - /// private class variables to stash bits for drawing the print bed area. - wxRealPoint print_center {}; + /// private class variables for drawing the print bed area. Slic3r::Polygon bed_polygon {}; std::vector grid {}; + wxRealPoint print_center {}; + + /// Displacement needed to center bed. + wxPoint bed_origin {}; /// Set up the 2D canvas blank canvas text. /// Easter egg: Sept. 13, 2006. The first part ever printed by a RepRap to make another RepRap. @@ -121,9 +126,12 @@ private: /// How much to scale the points to fit in the draw bounding box area. /// Expressed as pixel / mm double scaling_factor {1.0}; + - const std::string LogChannel {"GUI_2D"}; + const std::string LogChannel {"GUI_2D"}; //< Which logging channel to use for this object. + /// Transform a (X,Y) pair relative to the GUI position of the bed + /// and scale. Returns a Slic3r::Point in scaled units. Slic3r::Point point_to_model_units(coordf_t x, coordf_t y) { const auto& zero {this->bed_origin}; return Slic3r::Point( @@ -131,9 +139,13 @@ private: scale_(zero.y - y) / this->scaling_factor ); } + + /// Overloaded function to accept wxPoint and return scaled and offset Slic3r::Point Slic3r::Point point_to_model_units(const wxPoint& pt) { return this->point_to_model_units(pt.x, pt.y); } + + /// Overloaded function to accept Slic3r::Pointf and return scaled and offset Slic3r::Point Slic3r::Point point_to_model_units(const Pointf& pt) { return this->point_to_model_units(pt.x, pt.y); } From 9108e1b13dfba2c56150f061f69d256d3ad72058 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 12 May 2018 20:11:14 -0500 Subject: [PATCH 168/305] Stubbed out toolbar button graphics. --- src/GUI/Plater.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 4e299aaa6..2f6c2b0b6 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -520,6 +520,27 @@ void Plater::selection_changed() { # prepagate the event to the frame (a custom Wx event would be cleaner) $self->GetFrame->on_plater_selection_changed($have_sel); */ +} + +void Plater::build_toolbar() { + wxToolTip::Enable(true); + auto* toolbar = this->htoolbar = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL | wxTB_TEXT | wxBORDER_SIMPLE | wxTAB_TRAVERSAL); + toolbar->AddTool(TB_ADD, _(L"Add…"), wxBitmap(var("brick_add.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_REMOVE, _("Delete"), wxBitmap(var("brick_delete.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_RESET, _("Delete All"), wxBitmap(var("cross.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_ARRANGE, _("Arrange"), wxBitmap(var("bricks.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddSeparator(); + toolbar->AddTool(TB_MORE, _("More"), wxBitmap(var("add.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_FEWER, _("Fewer"), wxBitmap(var("delete.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddSeparator(); + toolbar->AddTool(TB_45CCW, _(L"45° ccw"), wxBitmap(var("arrow_rotate_anticlockwise.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_45CW, _(L"45° cw"), wxBitmap(var("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_SCALE, _(L"Scale…"), wxBitmap(var("arrow_out.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_SPLIT, _("Split"), wxBitmap(var("shape_ungroup.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_CUT, _(L"Cut…"), wxBitmap(var("package.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddSeparator(); + toolbar->AddTool(TB_SETTINGS, _(L"Settings…"), wxBitmap(var("cog.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_LAYERS, _(L"Layer heights…"), wxBitmap(var("variable_layer_height.png"), wxBITMAP_TYPE_PNG), ""); } From 163572e53773659d7b3f06775ce0bf5ac6fb7080 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 00:05:31 -0500 Subject: [PATCH 169/305] Stubbed out toolbar with calling functions; Add, Delete, and Delete All work. Plater object got a move constructor. --- src/GUI/Plater.cpp | 174 +++++++++++++++++++++++++++++++- src/GUI/Plater.hpp | 45 +++++++++ src/GUI/Plater/PlaterObject.cpp | 31 ++++++ src/GUI/Plater/PlaterObject.hpp | 7 +- src/GUI/Plater/Preview2D.hpp | 2 + src/GUI/Plater/Preview3D.hpp | 2 + src/GUI/Plater/PreviewDLP.hpp | 2 + 7 files changed, 261 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 2f6c2b0b6..acedd69ae 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -11,6 +11,22 @@ namespace Slic3r { namespace GUI { +const auto TB_ADD {wxNewId()}; +const auto TB_REMOVE {wxNewId()}; +const auto TB_RESET {wxNewId()}; +const auto TB_ARRANGE {wxNewId()}; +const auto TB_EXPORT_GCODE {wxNewId()}; +const auto TB_EXPORT_STL {wxNewId()}; +const auto TB_MORE {wxNewId()}; +const auto TB_FEWER {wxNewId()}; +const auto TB_45CW {wxNewId()}; +const auto TB_45CCW {wxNewId()}; +const auto TB_SCALE {wxNewId()}; +const auto TB_SPLIT {wxNewId()}; +const auto TB_CUT {wxNewId()}; +const auto TB_LAYERS {wxNewId()}; +const auto TB_SETTINGS {wxNewId()}; + const auto PROGRESS_BAR_EVENT = wxNewEventType(); Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings) : @@ -123,8 +139,12 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrcanvas2D->update_bed_size(); + // Toolbar + this->build_toolbar(); + // Finally assemble the sizers into the display. // export/print/send/export buttons @@ -541,10 +561,162 @@ void Plater::build_toolbar() { toolbar->AddSeparator(); toolbar->AddTool(TB_SETTINGS, _(L"Settings…"), wxBitmap(var("cog.png"), wxBITMAP_TYPE_PNG), ""); toolbar->AddTool(TB_LAYERS, _(L"Layer heights…"), wxBitmap(var("variable_layer_height.png"), wxBITMAP_TYPE_PNG), ""); - + + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->add(); }, TB_ADD); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->remove(); }, TB_REMOVE); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->reset(); }, TB_RESET); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->arrange(); }, TB_ARRANGE); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->increase(); }, TB_MORE); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->decrease(); }, TB_FEWER); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->rotate(-45); }, TB_45CW); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->rotate(45); }, TB_45CCW); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->changescale(); }, TB_SCALE); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->split_object(); }, TB_SPLIT); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->object_cut_dialog(); }, TB_CUT); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->object_layers_dialog(); }, TB_LAYERS); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->object_settings_dialog(); }, TB_SETTINGS); } +void Plater::remove() { + this->remove(-1, false); +} + +void Plater::remove(int obj_idx, bool dont_push) { + + // TODO: $self->stop_background_process; + + // Prevent toolpaths preview from rendering while we modify the Print object + if (this->preview2D != nullptr) + this->preview2D->enabled(false); + + if (this->preview3D != nullptr) + this->preview3D->enabled(false); + + if (this->previewDLP != nullptr) + this->previewDLP->enabled(false); + + ObjRef obj_ref; + // if no object index is supplied or an invalid one is supplied, remove the selected one + if (obj_idx < 0 || obj_idx >= this->objects.size()) { + obj_ref = this->selected_object(); + } else { // otherwise + obj_ref = this->objects.begin() + obj_idx; + } + std::vector::const_iterator const_ref = obj_ref; + + if (obj_ref >= this->objects.end()) return; // do nothing, nothing was selected. + + Slic3r::Log::info(LogChannel, "Assigned obj_ref"); + // Save the object identifier and copy the object for undo/redo operations. + auto object_id { obj_ref->identifier }; + auto new_model { Slic3r::Model() }; + new_model.add_object(*(this->model->objects.at(obj_ref->identifier))); + + Slic3r::Log::info(LogChannel, "Assigned obj_ref"); + try { + this->model->delete_object(obj_ref->identifier); + } catch (InvalidObjectException& ex) { + Slic3r::Log::error(LogChannel, LOG_WSTRING("Failed to delete object " << obj_ref->identifier << " from Model.")); + } + try { + this->print->delete_object(obj_ref->identifier); + } catch (InvalidObjectException& ex) { + Slic3r::Log::error(LogChannel, LOG_WSTRING("Failed to delete object " << obj_ref->identifier << " from Print.")); + } + + this->objects.erase(const_ref); + int i = 0; + for (auto o : this->objects) { o.identifier = i++; } // fix identifiers + this->object_identifier = this->objects.size(); + + this->object_list_changed(); + + this->select_object(); + + this->on_model_change(); + + if (!dont_push) { + Slic3r::Log::info(LogChannel, "Push to undo stack."); + this->add_undo_operation(UndoCmd::Remove, object_id, new_model); + Slic3r::Log::info(LogChannel, "Pushed to undo stack."); + } +} + +void Plater::reset(bool dont_push) { + // TODO: $self->stop_background_process; + + // Prevent toolpaths preview from rendering while we modify the Print object + if (this->preview2D != nullptr) + this->preview2D->enabled(false); + + if (this->preview3D != nullptr) + this->preview3D->enabled(false); + + if (this->previewDLP != nullptr) + this->previewDLP->enabled(false); + + if (!dont_push) { + Slic3r::Model current_model {*(this->model)}; + std::vector tmp_ids; + for (const auto& obj : this->objects) { + tmp_ids.push_back(obj.identifier); + } + this->add_undo_operation(UndoCmd::Reset, tmp_ids, current_model); + } + + this->objects.clear(); + this->object_identifier = this->objects.size(); + + this->model->clear_objects(); + this->print->clear_objects(); + + this->object_list_changed(); + this->select_object(); + + this->on_model_change(); +} + +void Plater::increase() { + //TODO +} + +void Plater::decrease() { + //TODO +} + +void Plater::rotate(double angle) { + //TODO +} + +void Plater::split_object() { + //TODO +} + +void Plater::changescale() { + //TODO +} + +void Plater::object_cut_dialog() { + //TODO +} + +void Plater::object_layers_dialog() { + //TODO +} + +void Plater::add_undo_operation(UndoCmd cmd, std::vector& obj_ids, Slic3r::Model& model) { + //TODO +} + +void Plater::add_undo_operation(UndoCmd cmd, int obj_id, Slic3r::Model& model) { + std::vector tmp {obj_id}; + add_undo_operation(cmd, tmp, model); +} + +void Plater::object_list_changed() { + //TODO +} }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index c73899b13..5170bc553 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -6,6 +6,7 @@ #endif #include +#include #include @@ -28,6 +29,11 @@ namespace Slic3r { namespace GUI { using UndoOperation = int; + +enum class UndoCmd { + Remove, Add, Reset +}; + using ObjIdx = unsigned int; using ObjRef = std::vector::iterator; @@ -45,6 +51,10 @@ public: /// User-level function called through external interface. /// Pops file dialog. void add(); + + /// Remove a selected model from the plater. + void remove(int obj_idx, bool dont_push = false); + void remove(); /// Arrange models via a simple packing mechanism based on bounding boxes. void arrange(); @@ -52,6 +62,11 @@ public: /// Ask if there are any unsaved changes. bool prompt_unsaved_changes() { return true; } + void add_undo_operation(UndoCmd cmd, int obj_id, Slic3r::Model& model); + + /// Push an undo op onto the stack. + void add_undo_operation(UndoCmd cmd, std::vector& obj_ids, Slic3r::Model& model); + private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; @@ -143,6 +158,36 @@ private: /// Create and launch menu for object. wxMenu* object_menu(); + /// Instantiate the toolbar + void build_toolbar(); + + /// Clear plate. + void reset(bool dont_push = false); + + /// Make instances of the currently selected model. + void increase(); + + /// Remove instances of the currently selected model. + void decrease(); + + /// Rotate the currently selected model. + void rotate(double angle); + + /// Separate a multipart model to its component interfaces. + void split_object(); + + /// Prompt a change of scaling. + void changescale(); + + /// Open the dialog to perform a cut on the current model. + void object_cut_dialog(); + + /// Open a menu to configure the layer heights. + void object_layers_dialog(); + + /// Process a change in the object list. + void object_list_changed(); + }; diff --git a/src/GUI/Plater/PlaterObject.cpp b/src/GUI/Plater/PlaterObject.cpp index 1ecee7b49..e0d9f598a 100644 --- a/src/GUI/Plater/PlaterObject.cpp +++ b/src/GUI/Plater/PlaterObject.cpp @@ -61,5 +61,36 @@ bool PlaterObject::instance_contains(Slic3r::Point point) const { return ep.contains(point); }); } +PlaterObject& PlaterObject::operator=(const PlaterObject& other) { + if (&other == this) return *this; + this->name = std::string(other.name); + this->identifier = other.identifier; + this->input_file = std::string(other.input_file); + this->input_file_obj_idx = other.input_file_obj_idx; + this->selected = false; + this->selected_instance = -1; + + this->thumbnail = Slic3r::ExPolygonCollection(other.thumbnail); + this->transformed_thumbnail = Slic3r::ExPolygonCollection(other.transformed_thumbnail); + + this->instance_thumbnails = std::vector(other.instance_thumbnails); + return *this; +} + +PlaterObject& PlaterObject::operator=(PlaterObject&& other) { + this->name = std::string(other.name); + this->identifier = other.identifier; + this->input_file = std::string(other.input_file); + this->input_file_obj_idx = other.input_file_obj_idx; + + this->selected = std::move(other.selected); + this->selected_instance = std::move(other.selected); + + this->thumbnail = Slic3r::ExPolygonCollection(other.thumbnail); + this->transformed_thumbnail = Slic3r::ExPolygonCollection(other.transformed_thumbnail); + + this->instance_thumbnails = std::vector(other.instance_thumbnails); + return *this; +} } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp index d5f857583..2134d14b5 100644 --- a/src/GUI/Plater/PlaterObject.hpp +++ b/src/GUI/Plater/PlaterObject.hpp @@ -20,7 +20,6 @@ public: bool selected {false}; int selected_instance {-1}; - Slic3r::ExPolygonCollection thumbnail; Slic3r::ExPolygonCollection transformed_thumbnail; @@ -35,6 +34,12 @@ public: bool instance_contains(Slic3r::Point point) const; + PlaterObject& operator=(const PlaterObject& other); + PlaterObject& operator=(PlaterObject&& other); + + PlaterObject(const PlaterObject& other) = default; + PlaterObject() = default; + protected: const std::string LogChannel {"PlaterObject"}; diff --git a/src/GUI/Plater/Preview2D.hpp b/src/GUI/Plater/Preview2D.hpp index 9aa4c37f7..2a17b68da 100644 --- a/src/GUI/Plater/Preview2D.hpp +++ b/src/GUI/Plater/Preview2D.hpp @@ -17,6 +17,8 @@ public: Preview2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) {} + + void enabled(bool enable = true) {} private: std::vector& objects; //< reference to parent vector std::shared_ptr model; diff --git a/src/GUI/Plater/Preview3D.hpp b/src/GUI/Plater/Preview3D.hpp index 2baa63900..49aa98c2d 100644 --- a/src/GUI/Plater/Preview3D.hpp +++ b/src/GUI/Plater/Preview3D.hpp @@ -17,6 +17,8 @@ public: Preview3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) {} + + void enabled(bool enable = true) {} private: std::vector& objects; //< reference to parent vector std::shared_ptr model; diff --git a/src/GUI/Plater/PreviewDLP.hpp b/src/GUI/Plater/PreviewDLP.hpp index 090483cc1..17b52cae5 100644 --- a/src/GUI/Plater/PreviewDLP.hpp +++ b/src/GUI/Plater/PreviewDLP.hpp @@ -17,6 +17,8 @@ public: PreviewDLP(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) {} + + void enabled(bool enable = true) {} private: std::vector& objects; //< reference to parent vector std::shared_ptr model; From 22e24d92e2e3c0e60c6c4cf1bd6ee19fafa9f181 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 00:06:34 -0500 Subject: [PATCH 170/305] Throw a custom exception if Print::delete_object() gets an out-of-range identifier. --- xs/src/libslic3r/Print.cpp | 2 ++ xs/src/libslic3r/Print.hpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index d413806f9..1ffc35c51 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -77,6 +77,8 @@ void Print::delete_object(size_t idx) { PrintObjectPtrs::iterator i = this->objects.begin() + idx; + if (i >= this->objects.end()) + throw InvalidObjectException(); // before deleting object, invalidate all of its steps in order to // invalidate all of the dependent ones in Print diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 7f83c684f..f0c9dfd5c 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -16,8 +16,12 @@ #include "SlicingAdaptive.hpp" #include "LayerHeightSpline.hpp" +#include + namespace Slic3r { +class InvalidObjectException : public std::exception {}; + class Print; class PrintObject; class ModelObject; From 5cba03da98023668f2c9c863c4ff312362c95657 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 00:07:11 -0500 Subject: [PATCH 171/305] Added std::string versions of error and info to Slic3r::Log --- xs/src/libslic3r/Log.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xs/src/libslic3r/Log.hpp b/xs/src/libslic3r/Log.hpp index 255b2e7a6..f105dac0d 100644 --- a/xs/src/libslic3r/Log.hpp +++ b/xs/src/libslic3r/Log.hpp @@ -18,10 +18,19 @@ public: std::wcerr << message << std::endl; } + static void error(std::string topic, std::string message) { + std::cerr << topic << " ERR" << ": "; + std::cerr << message << std::endl; + } + static void info(std::string topic, std::wstring message) { std::clog << topic << " INFO" << ": "; std::wclog << message << std::endl; } + static void info(std::string topic, std::string message) { + std::clog << topic << " INFO" << ": "; + std::clog << message << std::endl; + } static void warn(std::string topic, std::wstring message) { std::cerr << topic << " WARN" << ": "; From ffa1b3ba2c2ec0b8eea9c69f9af4cae5559614e7 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 00:22:34 -0500 Subject: [PATCH 172/305] Removed useless tooltip id --- src/GUI/Plater.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index acedd69ae..120e42640 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -545,22 +545,22 @@ void Plater::selection_changed() { void Plater::build_toolbar() { wxToolTip::Enable(true); auto* toolbar = this->htoolbar = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL | wxTB_TEXT | wxBORDER_SIMPLE | wxTAB_TRAVERSAL); - toolbar->AddTool(TB_ADD, _(L"Add…"), wxBitmap(var("brick_add.png"), wxBITMAP_TYPE_PNG), ""); - toolbar->AddTool(TB_REMOVE, _("Delete"), wxBitmap(var("brick_delete.png"), wxBITMAP_TYPE_PNG), ""); - toolbar->AddTool(TB_RESET, _("Delete All"), wxBitmap(var("cross.png"), wxBITMAP_TYPE_PNG), ""); - toolbar->AddTool(TB_ARRANGE, _("Arrange"), wxBitmap(var("bricks.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_ADD, _(L"Add…"), wxBitmap(var("brick_add.png"), wxBITMAP_TYPE_PNG)); + toolbar->AddTool(TB_REMOVE, _("Delete"), wxBitmap(var("brick_delete.png"), wxBITMAP_TYPE_PNG)); + toolbar->AddTool(TB_RESET, _("Delete All"), wxBitmap(var("cross.png"), wxBITMAP_TYPE_PNG)); + toolbar->AddTool(TB_ARRANGE, _("Arrange"), wxBitmap(var("bricks.png"), wxBITMAP_TYPE_PNG)); toolbar->AddSeparator(); - toolbar->AddTool(TB_MORE, _("More"), wxBitmap(var("add.png"), wxBITMAP_TYPE_PNG), ""); - toolbar->AddTool(TB_FEWER, _("Fewer"), wxBitmap(var("delete.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_MORE, _("More"), wxBitmap(var("add.png"), wxBITMAP_TYPE_PNG)); + toolbar->AddTool(TB_FEWER, _("Fewer"), wxBitmap(var("delete.png"), wxBITMAP_TYPE_PNG)); toolbar->AddSeparator(); - toolbar->AddTool(TB_45CCW, _(L"45° ccw"), wxBitmap(var("arrow_rotate_anticlockwise.png"), wxBITMAP_TYPE_PNG), ""); - toolbar->AddTool(TB_45CW, _(L"45° cw"), wxBitmap(var("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG), ""); - toolbar->AddTool(TB_SCALE, _(L"Scale…"), wxBitmap(var("arrow_out.png"), wxBITMAP_TYPE_PNG), ""); - toolbar->AddTool(TB_SPLIT, _("Split"), wxBitmap(var("shape_ungroup.png"), wxBITMAP_TYPE_PNG), ""); - toolbar->AddTool(TB_CUT, _(L"Cut…"), wxBitmap(var("package.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_45CCW, _(L"45° ccw"), wxBitmap(var("arrow_rotate_anticlockwise.png"), wxBITMAP_TYPE_PNG)); + toolbar->AddTool(TB_45CW, _(L"45° cw"), wxBitmap(var("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG)); + toolbar->AddTool(TB_SCALE, _(L"Scale…"), wxBitmap(var("arrow_out.png"), wxBITMAP_TYPE_PNG)); + toolbar->AddTool(TB_SPLIT, _("Split"), wxBitmap(var("shape_ungroup.png"), wxBITMAP_TYPE_PNG)); + toolbar->AddTool(TB_CUT, _(L"Cut…"), wxBitmap(var("package.png"), wxBITMAP_TYPE_PNG)); toolbar->AddSeparator(); - toolbar->AddTool(TB_SETTINGS, _(L"Settings…"), wxBitmap(var("cog.png"), wxBITMAP_TYPE_PNG), ""); - toolbar->AddTool(TB_LAYERS, _(L"Layer heights…"), wxBitmap(var("variable_layer_height.png"), wxBITMAP_TYPE_PNG), ""); + toolbar->AddTool(TB_SETTINGS, _(L"Settings…"), wxBitmap(var("cog.png"), wxBITMAP_TYPE_PNG)); + toolbar->AddTool(TB_LAYERS, _(L"Layer heights…"), wxBitmap(var("variable_layer_height.png"), wxBITMAP_TYPE_PNG)); toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->add(); }, TB_ADD); From 9b81e7ad95650625f297db82665fdab864268345 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 09:19:12 -0500 Subject: [PATCH 173/305] Implemented increase/decrease for instances. --- src/GUI/Plater.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++--- src/GUI/Plater.hpp | 11 ++++++-- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 120e42640..0c04b4750 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -677,12 +677,51 @@ void Plater::reset(bool dont_push) { this->on_model_change(); } -void Plater::increase() { - //TODO +void Plater::increase(size_t copies, bool dont_push) { + auto obj {this->selected_object()}; + if (obj == this->objects.end()) return; // do nothing; nothing is selected. + + this->stop_background_process(); + + auto* model_object {this->model->objects.at(obj->identifier)}; + ModelInstance* instance {model_object->instances.back()}; + + for (size_t i = 1; i <= copies; i++) { + instance = model_object->add_instance(*instance); + instance->offset.x += 10; + instance->offset.y += 10; + this->print->objects.at(obj->identifier)->add_copy(instance->offset); + } + + if (!dont_push) { + this->add_undo_operation(UndoCmd::Increase, obj->identifier, copies); + } + + if(settings->autocenter) { + this->arrange(); + } else { + this->on_model_change(); + } } -void Plater::decrease() { - //TODO +void Plater::decrease(size_t copies, bool dont_push) { + auto obj {this->selected_object()}; + if (obj == this->objects.end()) return; // do nothing; nothing is selected. + + this->stop_background_process(); + auto* model_object {this->model->objects.at(obj->identifier)}; + if (model_object->instances.size() > copies) { + for (size_t i = 1; i <= copies; i++) { + model_object->delete_last_instance(); + this->print->objects.at(obj->identifier)->delete_last_copy(); + } + if (!dont_push) { + this->add_undo_operation(UndoCmd::Decrease, obj->identifier, copies); + } + } else { + this->remove(); + } + this->on_model_change(); } void Plater::rotate(double angle) { @@ -714,9 +753,27 @@ void Plater::add_undo_operation(UndoCmd cmd, int obj_id, Slic3r::Model& model) { add_undo_operation(cmd, tmp, model); } +void Plater::add_undo_operation(UndoCmd cmd, int obj_id, size_t copies) { +} + void Plater::object_list_changed() { //TODO } +void Plater::stop_background_process() { + //TODO +} + +void Plater::start_background_process() { + //TODO +} + +void Plater::pause_background_process() { + //TODO +} +void Plater::resume_background_process() { + //TODO +} + }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 5170bc553..c0c69fdeb 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -165,10 +165,10 @@ private: void reset(bool dont_push = false); /// Make instances of the currently selected model. - void increase(); + void increase(size_t copies = 1, bool dont_push = false); /// Remove instances of the currently selected model. - void decrease(); + void decrease(size_t copies = 1, bool dont_push = false); /// Rotate the currently selected model. void rotate(double angle); @@ -188,6 +188,13 @@ private: /// Process a change in the object list. void object_list_changed(); + /// Halt ongoing background processes. + void stop_background_process(); + + void start_background_process(); + + void pause_background_process(); + void resume_background_process(); }; From fa2ee0b8a13a99705f9802e37660c30ec99d8cc8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 09:19:44 -0500 Subject: [PATCH 174/305] Add loaded objects to the Slic3r::Print reference. --- src/GUI/Plater.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 0c04b4750..7e52540b5 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -342,6 +342,8 @@ std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { // Provide a warning if downscaling by 5x still puts it over the bed size. } + this->print->auto_assign_extruders(o); + this->print->add_model_object(o); } for (const auto& i : obj_idx) { this->make_thumbnail(i); } if (need_arrange) this->arrange(); From e0ff9411ba71fca4d1acf4d9946eceb0b6e516a3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 09:20:05 -0500 Subject: [PATCH 175/305] Stubbed undo ops for increase/decrease. --- src/GUI/Plater.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index c0c69fdeb..be6b27051 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -31,7 +31,7 @@ namespace Slic3r { namespace GUI { using UndoOperation = int; enum class UndoCmd { - Remove, Add, Reset + Remove, Add, Reset, Increase, Decrease }; using ObjIdx = unsigned int; @@ -66,6 +66,9 @@ public: /// Push an undo op onto the stack. void add_undo_operation(UndoCmd cmd, std::vector& obj_ids, Slic3r::Model& model); + + /// Undo for increase/decrease + void add_undo_operation(UndoCmd cmd, int obj_id, size_t copies); private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; From cdcccfc87c44e2460dcb88bf1901eb7cedb31f34 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 11:00:14 -0500 Subject: [PATCH 176/305] Abort arrange if no objects in plater. --- src/GUI/Plater.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 7e52540b5..a85af6bd5 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -413,6 +413,10 @@ void Plater::refresh_canvases() { void Plater::arrange() { // TODO pause background process const Slic3r::BoundingBoxf bb {Slic3r::BoundingBoxf(this->config->get("bed_shape").values)}; + if (this->objects.size() == 0U) { // abort + GetFrame()->statusbar->SetStatusText(_("Nothing to arrange.")); + return; + } bool success {this->model->arrange_objects(this->config->min_object_distance(), &bb)}; if (success) { From 294c9aaa1827411738d108b250cbdc9c8011d883 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 11:00:29 -0500 Subject: [PATCH 177/305] call Realize() function on toolbar. --- src/GUI/Plater.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index a85af6bd5..839394fe1 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -568,6 +568,8 @@ void Plater::build_toolbar() { toolbar->AddTool(TB_SETTINGS, _(L"Settings…"), wxBitmap(var("cog.png"), wxBITMAP_TYPE_PNG)); toolbar->AddTool(TB_LAYERS, _(L"Layer heights…"), wxBitmap(var("variable_layer_height.png"), wxBITMAP_TYPE_PNG)); + toolbar->Realize(); + toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->add(); }, TB_ADD); toolbar->Bind(wxEVT_TOOL, [this](wxCommandEvent &e) { this->remove(); }, TB_REMOVE); From cad975038474017ce249a83c0cd508ffacdd94a0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 11:01:17 -0500 Subject: [PATCH 178/305] put the dc on the stack so it gets destroyed instead of on the heap. --- src/GUI/Plater/Plate2D.cpp | 71 +++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 10bdc0ec2..05573b750 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -46,7 +46,8 @@ void Plate2D::repaint(wxPaintEvent& e) { // Need focus to catch keyboard events. this->SetFocus(); - auto dc {new wxAutoBufferedPaintDC(this)}; + // create the device context. + wxAutoBufferedPaintDC dc(this); const auto& size {wxSize(this->GetSize().GetWidth(), this->GetSize().GetHeight())}; @@ -57,60 +58,63 @@ void Plate2D::repaint(wxPaintEvent& e) { // Fill DC with the background on Windows & Linux/GTK. const auto& brush_background {wxBrush(this->settings->color->BACKGROUND255(), wxBRUSHSTYLE_SOLID)}; const auto& pen_background {wxPen(this->settings->color->BACKGROUND255(), 1, wxPENSTYLE_SOLID)}; - dc->SetPen(pen_background); - dc->SetBrush(brush_background); + dc.SetPen(pen_background); + dc.SetBrush(brush_background); const auto& rect {this->GetUpdateRegion().GetBox()}; - dc->DrawRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight()); + dc.DrawRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight()); } // Draw bed { - dc->SetPen(this->print_center_pen); - dc->SetBrush(this->bed_brush); + dc.SetPen(this->print_center_pen); + dc.SetBrush(this->bed_brush); auto tmp {scaled_points_to_pixel(this->bed_polygon, true)}; - dc->DrawPolygon(tmp.size(), tmp.data(), 0, 0); + dc.DrawPolygon(tmp.size(), tmp.data(), 0, 0); } // draw print center { if (this->objects.size() > 0 && settings->autocenter) { const auto center = this->unscaled_point_to_pixel(this->print_center); - dc->SetPen(print_center_pen); - dc->DrawLine(center.x, 0, center.x, size.y); - dc->DrawLine(0, center.y, size.x, center.y); - dc->SetTextForeground(wxColor(0,0,0)); - dc->SetFont(wxFont(10, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); + dc.SetPen(print_center_pen); + dc.DrawLine(center.x, 0, center.x, size.y); + dc.DrawLine(0, center.y, size.x, center.y); + dc.SetTextForeground(wxColor(0,0,0)); + dc.SetFont(wxFont(10, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); - dc->DrawLabel(wxString::Format("X = %.0f", this->print_center.x), wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); - dc->DrawRotatedText(wxString::Format("Y = %.0f", this->print_center.y), 0, center.y + 15, 90); + dc.DrawLabel(wxString::Format("X = %.0f", this->print_center.x), wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); + dc.DrawRotatedText(wxString::Format("Y = %.0f", this->print_center.y), 0, center.y + 15, 90); } } // draw text if plate is empty if (this->objects.size() == 0) { - dc->SetTextForeground(settings->color->BED_OBJECTS()); - dc->SetFont(wxFont(14, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); - dc->DrawLabel(CANVAS_TEXT, wxRect(0,0, this->GetSize().GetWidth(), this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); + dc.SetTextForeground(settings->color->BED_OBJECTS()); + dc.SetFont(wxFont(14, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); + dc.DrawLabel(CANVAS_TEXT, wxRect(0,0, this->GetSize().GetWidth(), this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); } else { // draw grid - dc->SetPen(grid_pen); + dc.SetPen(grid_pen); // Assumption: grid of lines is arranged // as adjacent pairs of wxPoints for (auto i = 0U; i < grid.size(); i+=2) { - dc->DrawLine(grid[i], grid[i+1]); + dc.DrawLine(grid[i], grid[i+1]); } } // Draw thumbnails - dc->SetPen(dark_pen); + dc.SetPen(dark_pen); this->clean_instance_thumbnails(); for (auto& obj : this->objects) { + Slic3r::Log::info(LogChannel, LOG_WSTRING("Iterating over object " << obj.identifier)); auto model_object {this->model->objects.at(obj.identifier)}; + Slic3r::Log::info(LogChannel, "at() didn't crash"); if (obj.thumbnail.expolygons.size() == 0) continue; // if there's no thumbnail move on for (size_t instance_idx = 0U; instance_idx < model_object->instances.size(); instance_idx++) { auto& instance {model_object->instances.at(instance_idx)}; + Slic3r::Log::info(LogChannel, LOG_WSTRING("Drawing polygon for " << obj.input_file)); if (obj.transformed_thumbnail.expolygons.size() == 0) continue; auto thumbnail {obj.transformed_thumbnail}; // starts in unscaled model coords @@ -119,13 +123,16 @@ void Plate2D::repaint(wxPaintEvent& e) { obj.instance_thumbnails.emplace_back(thumbnail); if (0) { // object is dragged - dc->SetBrush(dragged_brush); + dc.SetBrush(dragged_brush); } else if (obj.selected && obj.selected_instance >= 0 && obj.selected_instance == static_cast(instance_idx)) { - dc->SetBrush(instance_brush); + Slic3r::Log::info(LogChannel, L"Using instance brush."); + dc.SetBrush(instance_brush); } else if (obj.selected) { - dc->SetBrush(selected_brush); + Slic3r::Log::info(LogChannel, L"Using selection brush."); + dc.SetBrush(selected_brush); } else { - dc->SetBrush(objects_brush); + Slic3r::Log::info(LogChannel, L"Using default objects brush."); + dc.SetBrush(objects_brush); } // porting notes: perl here seems to be making a single-item array of the // thumbnail set. @@ -133,18 +140,20 @@ void Plate2D::repaint(wxPaintEvent& e) { // and draw the contained expolygons for (const auto& points : obj.instance_thumbnails.back().expolygons) { auto poly { this->scaled_points_to_pixel(Polygon(points), true) }; - dc->DrawPolygon(poly.size(), poly.data(), 0, 0); + dc.DrawPolygon(poly.size(), poly.data(), 0, 0); + Slic3r::Log::info(LogChannel, LOG_WSTRING("Drawing polygon for " << obj.input_file)); } + // TODO draw bounding box if that debug option is turned on. // if sequential printing is enabled and more than one object, draw clearance area if (this->config->get("complete_objects") && std::count_if(this->model->objects.cbegin(), this->model->objects.cend(), [](const ModelObject* o){ return o->instances.size() > 0; }) > 1) { auto clearance {offset(thumbnail.convex_hull(), (scale_(this->config->get("extruder_clearance_radius")) / 2.0), 1.0, ClipperLib::jtRound, scale_(0.1))}; - dc->SetPen(this->clearance_pen); - dc->SetBrush(this->transparent_brush); + dc.SetPen(this->clearance_pen); + dc.SetBrush(this->transparent_brush); auto poly { this->scaled_points_to_pixel(Polygon(clearance.front()), true) }; - dc->DrawPolygon(poly.size(), poly.data(), 0, 0); + dc.DrawPolygon(poly.size(), poly.data(), 0, 0); } } } @@ -162,12 +171,12 @@ void Plate2D::repaint(wxPaintEvent& e) { // Calculate the offset hull and draw the points. if (tmp_cont.size() > 0) { - dc->SetPen(this->skirt_pen); - dc->SetBrush(this->transparent_brush); + dc.SetPen(this->skirt_pen); + dc.SetBrush(this->transparent_brush); auto skirt {offset(Slic3r::Geometry::convex_hull(tmp_cont), scale_(this->config->get("brim_width") + this->config->get("skirt_distance")), 1.0, ClipperLib::jtRound, scale_(0.1))}; auto poly { this->scaled_points_to_pixel(skirt.front(), true) }; - dc->DrawPolygon(poly.size(), poly.data(), 0, 0); + dc.DrawPolygon(poly.size(), poly.data(), 0, 0); } } From 8558050979d9338e4b4c6916a61990c2cabf467e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 11:14:58 -0500 Subject: [PATCH 179/305] try to build on both linux and osx with travis --- .travis.yml | 7 ++++++- package/linux/travis-setup.sh | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34940401f..4a1de9e77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: c++ +os: + - linux + - osx before_install: - sh package/linux/travis-decrypt-key install: @@ -49,7 +52,9 @@ notifications: use_notice: true dist: trusty env: - matrix: + matrix: global: - secure: eEVRZNMv7FM6jrOU9iAFkDhWxFQ1WtHBEaObImcvtFUxy6vWSt3ehFFeTRouj3uHQAnbvUzziDyvPPm8/95alv5g/du8ML6YzzqKBKfazM0xQ7SF6R2DQL8lfFIp+RSV7T02byEP1f1g7Zva7xH9szIlDcSfU0pXW4KWbkBFMd8= - secure: gj338h+qHGccTD/VQFmEJkqdg2McIe2pO0iZ4Ae9BvY5vxkIML4BpoYZQXQTqiAOETnUjlcknY9lx0hI/PfkDD9MSJc5BC/3fMYRCu3SgAclEwklWf9vvtodUeT69mtnZuw1zze1nTbExuOw2mepbqFjxKKMl+9l5oCz4O54fXU= + allow_failures: + - os: osx diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index 3a0493606..cea536aeb 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -3,16 +3,16 @@ WXVERSION=302 CACHE=$HOME/cache mkdir -p $CACHE +if [ $TRAVIS_OS_NAME == "linux"; then + if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then + echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" + curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 + fi -if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then - echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" - curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 -fi - -if [ ! -e $CACHE/wx${WXVERSION}.tar.bz2 ]; then - echo "Downloading http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2 => $CACHE/wx${WXVERSION}.tar.bz2" - curl -L "http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2" -o $CACHE/wx${WXVERSION}.tar.bz2 -fi - + if [ ! -e $CACHE/wx${WXVERSION}.tar.bz2 ]; then + echo "Downloading http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2 => $CACHE/wx${WXVERSION}.tar.bz2" + curl -L "http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2" -o $CACHE/wx${WXVERSION}.tar.bz2 + fi tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 +fi From 9474e2bbc0a6d3abd0ee80044b26f96dfff68fba Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 11:20:09 -0500 Subject: [PATCH 180/305] Oops, forgot a ] --- package/linux/travis-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index cea536aeb..f0e1b0906 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -3,7 +3,7 @@ WXVERSION=302 CACHE=$HOME/cache mkdir -p $CACHE -if [ $TRAVIS_OS_NAME == "linux"; then +if [ $TRAVIS_OS_NAME == "linux" ]; then if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 From 86b620d8a07eba8beac747c24e0b1a265e3d2007 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 11:25:50 -0500 Subject: [PATCH 181/305] push CXX and CC to a subscript. --- .travis.yml | 2 -- package/linux/travis-setup.sh | 9 +++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a1de9e77..4cd1f75f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,6 @@ before_install: install: - export BOOST_DIR=$HOME/boost_1_63_0 - export SLIC3R_STATIC=1 -- export CXX=g++-7 -- export CC=gcc-7 script: - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR src/ diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index f0e1b0906..fc8b83756 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -13,6 +13,11 @@ if [ $TRAVIS_OS_NAME == "linux" ]; then echo "Downloading http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2 => $CACHE/wx${WXVERSION}.tar.bz2" curl -L "http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2" -o $CACHE/wx${WXVERSION}.tar.bz2 fi -tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 -tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 + + tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 + tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 + + # Set some env variables specific to Travis Linux + export CXX=g++-7 + export CC=gcc-7 fi From ebe37cd27d8511ab421164719edbe94983972f52 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 11:30:46 -0500 Subject: [PATCH 182/305] Playing around with compiler setups --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e9a911c6d..07da56259 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,7 +31,7 @@ endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) set(CMAKE_INCLUDE_CURRENT_DIR ON) IF(CMAKE_HOST_APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE") set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework CoreFoundation -lc++") ELSE(CMAKE_HOST_APPLE) # set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -L.") From 437c4f8cf37e2517e281a5959ccf0c4eb55cab20 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 11:55:55 -0500 Subject: [PATCH 183/305] Build wxwidgets on osx if it's not cached. --- .travis.yml | 2 +- package/linux/travis-setup.sh | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4cd1f75f2..aa55095e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: - export SLIC3R_STATIC=1 script: - bash package/linux/travis-setup.sh -- cmake -DBOOST_ROOT=$BOOST_DIR src/ +- cmake -DBOOST_ROOT=$BOOST_DIR -DwxWidgets_ROOT_DIR=$WXDIR src/ - make after_success: - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index fc8b83756..0edff8fae 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -4,6 +4,7 @@ WXVERSION=302 CACHE=$HOME/cache mkdir -p $CACHE if [ $TRAVIS_OS_NAME == "linux" ]; then + export WXDIR=$HOME/wx${WXVERSION} if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 @@ -20,4 +21,17 @@ if [ $TRAVIS_OS_NAME == "linux" ]; then # Set some env variables specific to Travis Linux export CXX=g++-7 export CC=gcc-7 +elif [ $TRAVIS_OS_NAME == "osx" ]; then + WXVERSION=311 + export WXDIR=$HOME/wx${WXVERSION} + if [ ! -e $CACHE/wx${WXVERSION}.tar.bz2 ]; then + curl -L "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2" -o $HOME/wx311-src.tar.bz2 + tar -C$HOME -xjr $HOME/wx311-src.tar.bz2 + mkdir $HOME/wxbuild-${WXVERSION} + cd $HOME/wxbuild-${WXVERSION} && cmake $HOME/wxWidgets-3.1.1 -DwxBUILD_SHARED=off -DCMAKE_INSTALL_PREFIX=${WXDIR} + cmake --build . --target install + tar -C$HOME -cjf $CACHE/wx${WXVERSION}.tar.bz2 $(basename ${WXDIR}) + else + tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 + fi fi From 685ed01ac6cd46132d434ba9e283a45631dd7e5f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 11:58:24 -0500 Subject: [PATCH 184/305] wrong argument to tar --- package/linux/travis-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index 0edff8fae..43600f89d 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -26,7 +26,7 @@ elif [ $TRAVIS_OS_NAME == "osx" ]; then export WXDIR=$HOME/wx${WXVERSION} if [ ! -e $CACHE/wx${WXVERSION}.tar.bz2 ]; then curl -L "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2" -o $HOME/wx311-src.tar.bz2 - tar -C$HOME -xjr $HOME/wx311-src.tar.bz2 + tar -C$HOME -xjf $HOME/wx311-src.tar.bz2 mkdir $HOME/wxbuild-${WXVERSION} cd $HOME/wxbuild-${WXVERSION} && cmake $HOME/wxWidgets-3.1.1 -DwxBUILD_SHARED=off -DCMAKE_INSTALL_PREFIX=${WXDIR} cmake --build . --target install From 3f77c838b86ca72a630a54402d7568c8ad1698c0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 12:33:22 -0500 Subject: [PATCH 185/305] Build wx and cache the build dir instead of the installdir. Also add it to PATH so that wx-config will be found. --- package/linux/travis-setup.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index 43600f89d..41d7ab38c 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -24,14 +24,16 @@ if [ $TRAVIS_OS_NAME == "linux" ]; then elif [ $TRAVIS_OS_NAME == "osx" ]; then WXVERSION=311 export WXDIR=$HOME/wx${WXVERSION} - if [ ! -e $CACHE/wx${WXVERSION}.tar.bz2 ]; then + if [ ! -e $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 ]; then curl -L "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2" -o $HOME/wx311-src.tar.bz2 tar -C$HOME -xjf $HOME/wx311-src.tar.bz2 - mkdir $HOME/wxbuild-${WXVERSION} - cd $HOME/wxbuild-${WXVERSION} && cmake $HOME/wxWidgets-3.1.1 -DwxBUILD_SHARED=off -DCMAKE_INSTALL_PREFIX=${WXDIR} - cmake --build . --target install - tar -C$HOME -cjf $CACHE/wx${WXVERSION}.tar.bz2 $(basename ${WXDIR}) + mkdir $WXDIR + cd $HOME/$WXDIR && cmake $HOME/wxWidgets-3.1.1 -DwxBUILD_SHARED=OFF + cmake --build . --target -- -j4 + tar -C$HOME -cjf $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 $(basename ${WXDIR}) else - tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 + tar -C$HOME -xjf $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 fi + export PATH=${PATH}:${WXDIR} + cd $TRAVIS_BUILD_DIR # go back to the build dir fi From dd9092457863aa2783a38e341fcd10239ab447ed Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 12:41:42 -0500 Subject: [PATCH 186/305] made download more flexible. --- package/linux/travis-setup.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index 41d7ab38c..e05f55534 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -23,12 +23,13 @@ if [ $TRAVIS_OS_NAME == "linux" ]; then export CC=gcc-7 elif [ $TRAVIS_OS_NAME == "osx" ]; then WXVERSION=311 + WXVER_EXPANDED=${WXVERSION:0:1}.${WXVERSION:1:1}.${WXVERSION:2:1} export WXDIR=$HOME/wx${WXVERSION} if [ ! -e $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 ]; then - curl -L "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2" -o $HOME/wx311-src.tar.bz2 - tar -C$HOME -xjf $HOME/wx311-src.tar.bz2 + curl -L "https://github.com/wxWidgets/wxWidgets/releases/download/v${WXVER_EXPANDED}/wxWidgets-${WXVER_EXPANDED}.tar.bz2" -o $HOME/wx${WXVERSION}-src.tar.bz2 + tar -C$HOME -xjf $HOME/wx${WXVERSION}-src.tar.bz2 mkdir $WXDIR - cd $HOME/$WXDIR && cmake $HOME/wxWidgets-3.1.1 -DwxBUILD_SHARED=OFF + cd $HOME/$WXDIR && cmake $HOME/wxWidgets-${WXVER_EXPANDED} -DwxBUILD_SHARED=OFF cmake --build . --target -- -j4 tar -C$HOME -cjf $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 $(basename ${WXDIR}) else From 422ca4f8bbfd0ae9e529b6f73dadf1fd254b75e0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 12:47:31 -0500 Subject: [PATCH 187/305] Avoid gcc interpreting things as initializer lists. --- src/GUI/AboutDialog.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GUI/AboutDialog.cpp b/src/GUI/AboutDialog.cpp index 91a7b224a..52f831de7 100644 --- a/src/GUI/AboutDialog.cpp +++ b/src/GUI/AboutDialog.cpp @@ -10,16 +10,16 @@ static void link_clicked(wxHtmlLinkEvent& e) AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3r"), wxDefaultPosition, wxSize(600, 460), wxCAPTION) { - auto hsizer { new wxBoxSizer(wxHORIZONTAL) } ; + auto hsizer = new wxBoxSizer(wxHORIZONTAL) ; - auto vsizer { new wxBoxSizer(wxVERTICAL) } ; + auto vsizer = new wxBoxSizer(wxVERTICAL) ; // logo - auto logo { new AboutDialogLogo(this) }; + auto logo = new AboutDialogLogo(this); hsizer->Add(logo, 0, wxEXPAND | wxLEFT | wxRIGHT, 30); // title - auto title { new wxStaticText(this, -1, "Slic3r", wxDefaultPosition, wxDefaultSize) }; + auto title = new wxStaticText(this, -1, "Slic3r", wxDefaultPosition, wxDefaultSize); auto title_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; title_font.SetWeight(wxFONTWEIGHT_BOLD); @@ -31,7 +31,7 @@ AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3 // version - auto version {new wxStaticText(this, -1, wxString("Version ") + wxString(SLIC3R_VERSION), wxDefaultPosition, wxDefaultSize) }; + auto version = new wxStaticText(this, -1, wxString("Version ") + wxString(SLIC3R_VERSION), wxDefaultPosition, wxDefaultSize); auto version_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; version_font.SetPointSize((the_os == OS::Windows ? 9 : 11)); version->SetFont(version_font); @@ -54,7 +54,7 @@ AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3 << "Built on " << build_date << " at git version " << git_version << "." << "" << ""; - auto html {new wxHtmlWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_NEVER)}; + auto html = new wxHtmlWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_NEVER); html->SetBorders(2); html->SetPage(text); From 2b43cdfa98dab23e3c827b9e0e1e0117bcadd644 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 12:50:11 -0500 Subject: [PATCH 188/305] playing around with findwxwidgets --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aa55095e3..1572eca05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: - export SLIC3R_STATIC=1 script: - bash package/linux/travis-setup.sh -- cmake -DBOOST_ROOT=$BOOST_DIR -DwxWidgets_ROOT_DIR=$WXDIR src/ +- cmake -DBOOST_ROOT=$BOOST_DIR -DwxWidgets_CONFIG_OPTIONS=--prefix=$WXDIR -DwxWIDGETS_LIB_DIR=$WXDIR/lib -DwxWidgets_ROOT_DIR=$WXDIR src/ - make after_success: - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 From 1d64d9ae1716614e2ba89805e1527dc39b85dd95 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 12:56:16 -0500 Subject: [PATCH 189/305] Less fancy. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1572eca05..aa55095e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: - export SLIC3R_STATIC=1 script: - bash package/linux/travis-setup.sh -- cmake -DBOOST_ROOT=$BOOST_DIR -DwxWidgets_CONFIG_OPTIONS=--prefix=$WXDIR -DwxWIDGETS_LIB_DIR=$WXDIR/lib -DwxWidgets_ROOT_DIR=$WXDIR src/ +- cmake -DBOOST_ROOT=$BOOST_DIR -DwxWidgets_ROOT_DIR=$WXDIR src/ - make after_success: - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 From dc0bc0bbdb13699e26590fb134da0a7f1764a94e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 13:20:52 -0500 Subject: [PATCH 190/305] compiler misinterprets as initializer list -.- --- src/GUI/AboutDialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GUI/AboutDialog.cpp b/src/GUI/AboutDialog.cpp index 52f831de7..daad5218b 100644 --- a/src/GUI/AboutDialog.cpp +++ b/src/GUI/AboutDialog.cpp @@ -20,7 +20,7 @@ AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3 // title auto title = new wxStaticText(this, -1, "Slic3r", wxDefaultPosition, wxDefaultSize); - auto title_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; + auto title_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); title_font.SetWeight(wxFONTWEIGHT_BOLD); title_font.SetFamily(wxFONTFAMILY_ROMAN); @@ -32,7 +32,7 @@ AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3 // version auto version = new wxStaticText(this, -1, wxString("Version ") + wxString(SLIC3R_VERSION), wxDefaultPosition, wxDefaultSize); - auto version_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; + auto version_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); version_font.SetPointSize((the_os == OS::Windows ? 9 : 11)); version->SetFont(version_font); vsizer->Add(version, 0, wxALIGN_LEFT | wxBOTTOM, 10); From e82238266c302fbf20573d3b1ab1bd865df281ee Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 13:32:33 -0500 Subject: [PATCH 191/305] Don't leak memory on the dc --- src/GUI/AboutDialog.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GUI/AboutDialog.cpp b/src/GUI/AboutDialog.cpp index daad5218b..23e893588 100644 --- a/src/GUI/AboutDialog.cpp +++ b/src/GUI/AboutDialog.cpp @@ -83,15 +83,15 @@ AboutDialogLogo::AboutDialogLogo(wxWindow* parent) : void AboutDialogLogo::repaint(wxPaintEvent& event) { - auto dc { new wxPaintDC(this) }; + auto dc = wxPaintDC(this); - dc->SetBackgroundMode(wxPENSTYLE_TRANSPARENT); + dc.SetBackgroundMode(wxPENSTYLE_TRANSPARENT); const auto size {this->GetSize()}; const auto logo_w {this->logo.GetWidth()}; const auto logo_h {this->logo.GetHeight()}; - dc->DrawBitmap(this->logo, (size.GetWidth() - logo_w) / 2, (size.GetHeight() - logo_h) / 2, 1); + dc.DrawBitmap(this->logo, (size.GetWidth() - logo_w) / 2, (size.GetHeight() - logo_h) / 2, 1); event.Skip(); } From 8e5056dee45e35141613618b26361f3596c4deda Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 13:37:04 -0500 Subject: [PATCH 192/305] don't build WX if it can't be found --- src/CMakeLists.txt | 1 + src/slic3r.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 07da56259..d423ed8b5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -219,6 +219,7 @@ IF(wxWidgets_FOUND) target_compile_features(slic3r_gui PUBLIC cxx_std_11) #only build GUI lib if building with wx target_link_libraries (slic3r slic3r_gui ${wxWidgets_LIBRARIES}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_WX") ELSE(wxWidgets_FOUND) # For convenience. When we cannot continue, inform the user MESSAGE("wx not found!") diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 2e8aaf387..6d3470c83 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -13,7 +13,11 @@ #include #include #include -#include "GUI/GUI.hpp" + + +#ifdef USE_WX + #include "GUI/GUI.hpp" +#endif using namespace Slic3r; @@ -41,6 +45,7 @@ main(int argc, char **argv) DynamicPrintConfig print_config; +#ifdef USE_WX std::shared_ptr gui_config = std::make_shared(); GUI::App *gui = new GUI::App(gui_config); @@ -49,7 +54,7 @@ main(int argc, char **argv) GUI::App::SetInstance(gui); wxEntry(argc, argv); - +#endif // load config files supplied via --load for (const std::string &file : cli_config.load.values) { if (!boost::filesystem::exists(file)) { From 86b0d18a2ef003e4b6f8e3276c83f14a5aa06eb4 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 13:43:03 -0500 Subject: [PATCH 193/305] try homebrew --- package/linux/travis-setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index e05f55534..19f206c37 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -37,4 +37,5 @@ elif [ $TRAVIS_OS_NAME == "osx" ]; then fi export PATH=${PATH}:${WXDIR} cd $TRAVIS_BUILD_DIR # go back to the build dir + brew install wxmac # install via homebrew fi From 54220204ddb6f948a96deee796fbc8d92d800792 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 13:48:40 -0500 Subject: [PATCH 194/305] Fix assignment to not use copy constructor --- src/GUI/AboutDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/AboutDialog.cpp b/src/GUI/AboutDialog.cpp index 23e893588..52d8897a9 100644 --- a/src/GUI/AboutDialog.cpp +++ b/src/GUI/AboutDialog.cpp @@ -83,7 +83,7 @@ AboutDialogLogo::AboutDialogLogo(wxWindow* parent) : void AboutDialogLogo::repaint(wxPaintEvent& event) { - auto dc = wxPaintDC(this); + wxPaintDC dc(this); dc.SetBackgroundMode(wxPENSTYLE_TRANSPARENT); From bfb8f8f3d83503008754ed7e53c86d4f4e58a0e4 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 13:55:53 -0500 Subject: [PATCH 195/305] Convert colors to base-255 --- src/GUI/ColorScheme/Default.hpp | 26 ++++++++++++------------- src/GUI/ColorScheme/Solarized.hpp | 32 +++++++++++++++---------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/GUI/ColorScheme/Default.hpp b/src/GUI/ColorScheme/Default.hpp index 47fd951e6..69b7e0a98 100644 --- a/src/GUI/ColorScheme/Default.hpp +++ b/src/GUI/ColorScheme/Default.hpp @@ -8,17 +8,17 @@ public: const std::string name() const { return "Default"; } const bool SOLID_BACKGROUNDCOLOR() const { return false; }; const wxColour SELECTED_COLOR() const { return wxColour(0, 1, 0); }; - const wxColour HOVER_COLOR() const { return wxColour(0.4, 0.9, 0); }; // Date: Sun, 13 May 2018 14:01:48 -0500 Subject: [PATCH 196/305] fix signature --- src/GUI/ColorScheme/Solarized.hpp | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/GUI/ColorScheme/Solarized.hpp b/src/GUI/ColorScheme/Solarized.hpp index 1cc224ce4..e1aaf456a 100644 --- a/src/GUI/ColorScheme/Solarized.hpp +++ b/src/GUI/ColorScheme/Solarized.hpp @@ -12,30 +12,30 @@ namespace Slic3r { namespace GUI { /// Implements a colorscheme lookup of wxColors class Solarized : public ColorScheme { public: - const wxColour SELECTED_COLOR() { return COLOR_MAGENTA; } - const wxColour HOVER_COLOR() { return COLOR_VIOLET; } - const wxColour SUPPORT_COLOR() { return COLOR_VIOLET; } + const wxColour SELECTED_COLOR() const { return COLOR_MAGENTA; } + const wxColour HOVER_COLOR() const { return COLOR_VIOLET; } + const wxColour SUPPORT_COLOR() const { return COLOR_VIOLET; } - const wxColour BACKGROUND_COLOR() { return COLOR_BASE3; } + const wxColour BACKGROUND_COLOR() const { return COLOR_BASE3; } private: - const wxColour COLOR_BASE0 {wxColour(255*0.51373,255*0.58039,255*0.58824)}; - const wxColour COLOR_BASE00 {wxColour(255*0.39608,255*0.48235,255*0.51373)}; - const wxColour COLOR_BASE01 {wxColour(255*0.34510,255*0.43137,255*0.45882)}; - const wxColour COLOR_BASE02 {wxColour(255*0.02745,255*0.21176,255*0.25882)}; - const wxColour COLOR_BASE03 {wxColour(255*0.00000,255*0.16863,255*0.21176)}; - const wxColour COLOR_BASE1 {wxColour(255*0.57647,255*0.63137,255*0.63137)}; - const wxColour COLOR_BASE2 {wxColour(255*0.93333,255*0.90980,255*0.83529)}; - const wxColour COLOR_BASE3 {wxColour(255*0.99216,255*0.96471,255*0.89020)}; - const wxColour COLOR_BLUE {wxColour(255*0.14902,255*0.54510,255*0.82353)}; - const wxColour COLOR_CYAN {wxColour(255*0.16471,255*0.63137,255*0.59608)}; - const wxColour COLOR_GREEN {wxColour(255*0.52157,255*0.60000,255*0.00000)}; - const wxColour COLOR_MAGENTA {wxColour(255*0.82745,255*0.21176,255*0.50980)}; - const wxColour COLOR_ORANGE {wxColour(255*0.79608,255*0.29412,255*0.08627)}; - const wxColour COLOR_RED {wxColour(255*0.86275,255*0.19608,255*0.18431)}; - const wxColour COLOR_VIOLET {wxColour(255*0.42353,255*0.44314,255*0.76863)}; - const wxColour COLOR_YELLOW {wxColour(255*0.70980,255*0.53725,255*0.00000)}; + const wxColour COLOR_BASE0 const {wxColour(255*0.51373,255*0.58039,255*0.58824)}; + const wxColour COLOR_BASE00 const {wxColour(255*0.39608,255*0.48235,255*0.51373)}; + const wxColour COLOR_BASE01 const {wxColour(255*0.34510,255*0.43137,255*0.45882)}; + const wxColour COLOR_BASE02 const {wxColour(255*0.02745,255*0.21176,255*0.25882)}; + const wxColour COLOR_BASE03 const {wxColour(255*0.00000,255*0.16863,255*0.21176)}; + const wxColour COLOR_BASE1 const {wxColour(255*0.57647,255*0.63137,255*0.63137)}; + const wxColour COLOR_BASE2 const {wxColour(255*0.93333,255*0.90980,255*0.83529)}; + const wxColour COLOR_BASE3 const {wxColour(255*0.99216,255*0.96471,255*0.89020)}; + const wxColour COLOR_BLUE const {wxColour(255*0.14902,255*0.54510,255*0.82353)}; + const wxColour COLOR_CYAN const {wxColour(255*0.16471,255*0.63137,255*0.59608)}; + const wxColour COLOR_GREEN const {wxColour(255*0.52157,255*0.60000,255*0.00000)}; + const wxColour COLOR_MAGENTA const {wxColour(255*0.82745,255*0.21176,255*0.50980)}; + const wxColour COLOR_ORANGE const {wxColour(255*0.79608,255*0.29412,255*0.08627)}; + const wxColour COLOR_RED const {wxColour(255*0.86275,255*0.19608,255*0.18431)}; + const wxColour COLOR_VIOLET const {wxColour(255*0.42353,255*0.44314,255*0.76863)}; + const wxColour COLOR_YELLOW const {wxColour(255*0.70980,255*0.53725,255*0.00000)}; }; }} // namespace Slic3r::GUI From 8acc2157597b9513772dc88956bb0f55351d5b43 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 14:15:48 -0500 Subject: [PATCH 197/305] okay, you win this time clang --- src/GUI/ColorScheme/Solarized.hpp | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/GUI/ColorScheme/Solarized.hpp b/src/GUI/ColorScheme/Solarized.hpp index e1aaf456a..1c983d088 100644 --- a/src/GUI/ColorScheme/Solarized.hpp +++ b/src/GUI/ColorScheme/Solarized.hpp @@ -20,22 +20,22 @@ public: private: - const wxColour COLOR_BASE0 const {wxColour(255*0.51373,255*0.58039,255*0.58824)}; - const wxColour COLOR_BASE00 const {wxColour(255*0.39608,255*0.48235,255*0.51373)}; - const wxColour COLOR_BASE01 const {wxColour(255*0.34510,255*0.43137,255*0.45882)}; - const wxColour COLOR_BASE02 const {wxColour(255*0.02745,255*0.21176,255*0.25882)}; - const wxColour COLOR_BASE03 const {wxColour(255*0.00000,255*0.16863,255*0.21176)}; - const wxColour COLOR_BASE1 const {wxColour(255*0.57647,255*0.63137,255*0.63137)}; - const wxColour COLOR_BASE2 const {wxColour(255*0.93333,255*0.90980,255*0.83529)}; - const wxColour COLOR_BASE3 const {wxColour(255*0.99216,255*0.96471,255*0.89020)}; - const wxColour COLOR_BLUE const {wxColour(255*0.14902,255*0.54510,255*0.82353)}; - const wxColour COLOR_CYAN const {wxColour(255*0.16471,255*0.63137,255*0.59608)}; - const wxColour COLOR_GREEN const {wxColour(255*0.52157,255*0.60000,255*0.00000)}; - const wxColour COLOR_MAGENTA const {wxColour(255*0.82745,255*0.21176,255*0.50980)}; - const wxColour COLOR_ORANGE const {wxColour(255*0.79608,255*0.29412,255*0.08627)}; - const wxColour COLOR_RED const {wxColour(255*0.86275,255*0.19608,255*0.18431)}; - const wxColour COLOR_VIOLET const {wxColour(255*0.42353,255*0.44314,255*0.76863)}; - const wxColour COLOR_YELLOW const {wxColour(255*0.70980,255*0.53725,255*0.00000)}; + const wxColour COLOR_BASE0() const {wxColour(255*0.51373,255*0.58039,255*0.58824)}; + const wxColour COLOR_BASE00() const {wxColour(255*0.39608,255*0.48235,255*0.51373)}; + const wxColour COLOR_BASE01() const {wxColour(255*0.34510,255*0.43137,255*0.45882)}; + const wxColour COLOR_BASE02() const {wxColour(255*0.02745,255*0.21176,255*0.25882)}; + const wxColour COLOR_BASE03() const {wxColour(255*0.00000,255*0.16863,255*0.21176)}; + const wxColour COLOR_BASE1() const {wxColour(255*0.57647,255*0.63137,255*0.63137)}; + const wxColour COLOR_BASE2() const {wxColour(255*0.93333,255*0.90980,255*0.83529)}; + const wxColour COLOR_BASE3() const {wxColour(255*0.99216,255*0.96471,255*0.89020)}; + const wxColour COLOR_BLUE() const {wxColour(255*0.14902,255*0.54510,255*0.82353)}; + const wxColour COLOR_CYAN() const {wxColour(255*0.16471,255*0.63137,255*0.59608)}; + const wxColour COLOR_GREEN() const {wxColour(255*0.52157,255*0.60000,255*0.00000)}; + const wxColour COLOR_MAGENTA() const {wxColour(255*0.82745,255*0.21176,255*0.50980)}; + const wxColour COLOR_ORANGE() const {wxColour(255*0.79608,255*0.29412,255*0.08627)}; + const wxColour COLOR_RED() const {wxColour(255*0.86275,255*0.19608,255*0.18431)}; + const wxColour COLOR_VIOLET() const {wxColour(255*0.42353,255*0.44314,255*0.76863)}; + const wxColour COLOR_YELLOW() const {wxColour(255*0.70980,255*0.53725,255*0.00000)}; }; }} // namespace Slic3r::GUI From 94c4813dc5630e0449a891a4e898673234e2627a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 14:27:10 -0500 Subject: [PATCH 198/305] actually do functions right --- src/GUI/ColorScheme/Solarized.hpp | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/GUI/ColorScheme/Solarized.hpp b/src/GUI/ColorScheme/Solarized.hpp index 1c983d088..b02f0849d 100644 --- a/src/GUI/ColorScheme/Solarized.hpp +++ b/src/GUI/ColorScheme/Solarized.hpp @@ -12,30 +12,30 @@ namespace Slic3r { namespace GUI { /// Implements a colorscheme lookup of wxColors class Solarized : public ColorScheme { public: - const wxColour SELECTED_COLOR() const { return COLOR_MAGENTA; } - const wxColour HOVER_COLOR() const { return COLOR_VIOLET; } - const wxColour SUPPORT_COLOR() const { return COLOR_VIOLET; } + const wxColour SELECTED_COLOR() const { return COLOR_MAGENTA(); } + const wxColour HOVER_COLOR() const { return COLOR_VIOLET(); } + const wxColour SUPPORT_COLOR() const { return COLOR_VIOLET(); } - const wxColour BACKGROUND_COLOR() const { return COLOR_BASE3; } + const wxColour BACKGROUND_COLOR() const { return COLOR_BASE3(); } private: - const wxColour COLOR_BASE0() const {wxColour(255*0.51373,255*0.58039,255*0.58824)}; - const wxColour COLOR_BASE00() const {wxColour(255*0.39608,255*0.48235,255*0.51373)}; - const wxColour COLOR_BASE01() const {wxColour(255*0.34510,255*0.43137,255*0.45882)}; - const wxColour COLOR_BASE02() const {wxColour(255*0.02745,255*0.21176,255*0.25882)}; - const wxColour COLOR_BASE03() const {wxColour(255*0.00000,255*0.16863,255*0.21176)}; - const wxColour COLOR_BASE1() const {wxColour(255*0.57647,255*0.63137,255*0.63137)}; - const wxColour COLOR_BASE2() const {wxColour(255*0.93333,255*0.90980,255*0.83529)}; - const wxColour COLOR_BASE3() const {wxColour(255*0.99216,255*0.96471,255*0.89020)}; - const wxColour COLOR_BLUE() const {wxColour(255*0.14902,255*0.54510,255*0.82353)}; - const wxColour COLOR_CYAN() const {wxColour(255*0.16471,255*0.63137,255*0.59608)}; - const wxColour COLOR_GREEN() const {wxColour(255*0.52157,255*0.60000,255*0.00000)}; - const wxColour COLOR_MAGENTA() const {wxColour(255*0.82745,255*0.21176,255*0.50980)}; - const wxColour COLOR_ORANGE() const {wxColour(255*0.79608,255*0.29412,255*0.08627)}; - const wxColour COLOR_RED() const {wxColour(255*0.86275,255*0.19608,255*0.18431)}; - const wxColour COLOR_VIOLET() const {wxColour(255*0.42353,255*0.44314,255*0.76863)}; - const wxColour COLOR_YELLOW() const {wxColour(255*0.70980,255*0.53725,255*0.00000)}; + const wxColour COLOR_BASE0() const {return wxColour(255*0.51373,255*0.58039,255*0.58824);} + const wxColour COLOR_BASE00() const {return wxColour(255*0.39608,255*0.48235,255*0.51373);} + const wxColour COLOR_BASE01() const {return wxColour(255*0.34510,255*0.43137,255*0.45882);} + const wxColour COLOR_BASE02() const {return wxColour(255*0.02745,255*0.21176,255*0.25882);} + const wxColour COLOR_BASE03() const {return wxColour(255*0.00000,255*0.16863,255*0.21176);} + const wxColour COLOR_BASE1() const {return wxColour(255*0.57647,255*0.63137,255*0.63137);} + const wxColour COLOR_BASE2() const {return wxColour(255*0.93333,255*0.90980,255*0.83529);} + const wxColour COLOR_BASE3() const {return wxColour(255*0.99216,255*0.96471,255*0.89020);} + const wxColour COLOR_BLUE() const {return wxColour(255*0.14902,255*0.54510,255*0.82353);} + const wxColour COLOR_CYAN() const {return wxColour(255*0.16471,255*0.63137,255*0.59608);} + const wxColour COLOR_GREEN() const {return wxColour(255*0.52157,255*0.60000,255*0.00000);} + const wxColour COLOR_MAGENTA() const {return wxColour(255*0.82745,255*0.21176,255*0.50980);} + const wxColour COLOR_ORANGE() const {return wxColour(255*0.79608,255*0.29412,255*0.08627);} + const wxColour COLOR_RED() const {return wxColour(255*0.86275,255*0.19608,255*0.18431);} + const wxColour COLOR_VIOLET() const {return wxColour(255*0.42353,255*0.44314,255*0.76863);} + const wxColour COLOR_YELLOW() const {return wxColour(255*0.70980,255*0.53725,255*0.00000);} }; }} // namespace Slic3r::GUI From 371aa85162851dbf112ff86e6bf13ea94e8a82ee Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 14:42:03 -0500 Subject: [PATCH 199/305] make verbose to see output and move the language specifier a little further down --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index aa55095e3..cda043d13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ -language: c++ os: - linux - osx +language: c++ before_install: - sh package/linux/travis-decrypt-key install: @@ -10,7 +10,7 @@ install: script: - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR -DwxWidgets_ROOT_DIR=$WXDIR src/ -- make +- make VERBOSE=1 after_success: - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 - package/linux/appimage.sh x86_64 From 5f49ee8913c5b779a9ae4742e608a276efc50b01 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 18:02:03 -0500 Subject: [PATCH 200/305] Moved AboutDialog into Dialogs subdir. --- src/CMakeLists.txt | 2 +- src/GUI/{ => Dialogs}/AboutDialog.cpp | 4 ++-- src/GUI/{ => Dialogs}/AboutDialog.hpp | 0 src/GUI/MainFrame.cpp | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) rename src/GUI/{ => Dialogs}/AboutDialog.cpp (97%) rename src/GUI/{ => Dialogs}/AboutDialog.hpp (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d423ed8b5..5ccbc4335 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -206,7 +206,7 @@ IF(wxWidgets_FOUND) include_directories(${wxWidgets_INCLUDE}) add_library(slic3r_gui STATIC - ${GUI_LIBDIR}/AboutDialog.cpp + ${GUI_LIBDIR}/Dialogs/AboutDialog.cpp ${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/Plater.cpp diff --git a/src/GUI/AboutDialog.cpp b/src/GUI/Dialogs/AboutDialog.cpp similarity index 97% rename from src/GUI/AboutDialog.cpp rename to src/GUI/Dialogs/AboutDialog.cpp index 52d8897a9..fb6d2798e 100644 --- a/src/GUI/AboutDialog.cpp +++ b/src/GUI/Dialogs/AboutDialog.cpp @@ -1,4 +1,4 @@ -#include "AboutDialog.hpp" +#include "Dialogs/AboutDialog.hpp" namespace Slic3r { namespace GUI { @@ -87,7 +87,7 @@ void AboutDialogLogo::repaint(wxPaintEvent& event) dc.SetBackgroundMode(wxPENSTYLE_TRANSPARENT); - const auto size {this->GetSize()}; + const wxSize size {this->GetSize()}; const auto logo_w {this->logo.GetWidth()}; const auto logo_h {this->logo.GetHeight()}; diff --git a/src/GUI/AboutDialog.hpp b/src/GUI/Dialogs/AboutDialog.hpp similarity index 100% rename from src/GUI/AboutDialog.hpp rename to src/GUI/Dialogs/AboutDialog.hpp diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 2ee7bba9e..54ed0b6ae 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -3,9 +3,10 @@ #include #include -#include "AboutDialog.hpp" #include "libslic3r.h" +#include "Dialogs/AboutDialog.hpp" + namespace Slic3r { namespace GUI { wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) From be71ede08b4e3824413d4b79195792a3ea5a52ef Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 18:12:14 -0500 Subject: [PATCH 201/305] Reorganize includes --- src/GUI/MainFrame.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 54ed0b6ae..2eb0d2ec3 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -1,10 +1,10 @@ -#include "MainFrame.hpp" -#include "misc_ui.hpp" #include #include #include "libslic3r.h" +#include "MainFrame.hpp" +#include "misc_ui.hpp" #include "Dialogs/AboutDialog.hpp" namespace Slic3r { namespace GUI { From f3c652e322663960d12abd562b14232d55c8b408 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 19:32:15 -0500 Subject: [PATCH 202/305] Implemented general rotate function for supplied function. --- src/GUI/Plater.cpp | 35 ++++++++++++++++++++++++++++++++++- src/GUI/Plater.hpp | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 839394fe1..7532f6160 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -8,6 +8,7 @@ #include "Log.hpp" #include "MainFrame.hpp" #include "BoundingBox.hpp" +#include "Geometry.hpp" namespace Slic3r { namespace GUI { @@ -732,8 +733,40 @@ void Plater::decrease(size_t copies, bool dont_push) { this->on_model_change(); } -void Plater::rotate(double angle) { +void Plater::rotate(double angle, Axis axis, bool dont_push) { //TODO + ObjRef obj {this->selected_object()}; + if (obj == this->objects.end()) return; + + auto* model_object {this->model->objects.at(obj->identifier)}; + auto* model_instance {model_object->instances.front()}; + + if(obj->thumbnail.expolygons.size() == 0) { return; } + + if (axis == Z) { + for (auto* instance : model_object->instances) + instance->rotation += Geometry::deg2rad(angle); + obj->transform_thumbnail(this->model, obj->identifier); + } else { + model_object->transform_by_instance(*model_instance, true); + model_object->rotate(Geometry::deg2rad(angle), axis); + + // realign object to Z=0 + model_object->center_around_origin(); + this->make_thumbnail(obj->identifier); + } + + model_object->update_bounding_box(); + + this->print->add_model_object(model_object, obj->identifier); + + if (!dont_push) { + // TODO + } + + this->selection_changed(); + this->on_model_change(); + } void Plater::split_object() { diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index be6b27051..518931834 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -174,7 +174,7 @@ private: void decrease(size_t copies = 1, bool dont_push = false); /// Rotate the currently selected model. - void rotate(double angle); + void rotate(double angle, Axis axis = Z, bool dont_push = false); /// Separate a multipart model to its component interfaces. void split_object(); From ada744d7182a48dbf70e0f770d00c7e9a8e2cda2 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 21:18:50 -0500 Subject: [PATCH 203/305] Implement generic object rotation in all 3 axes with a slider and box. --- src/GUI/Dialogs/AnglePicker.hpp | 89 ++++++++++++++++++ src/GUI/MainFrame.cpp | 6 +- src/GUI/Plater.cpp | 154 ++++++++++++++++++++++++++++++-- src/GUI/Plater.hpp | 12 ++- src/GUI/misc_ui.cpp | 18 ++++ src/GUI/misc_ui.hpp | 12 ++- 6 files changed, 270 insertions(+), 21 deletions(-) create mode 100644 src/GUI/Dialogs/AnglePicker.hpp diff --git a/src/GUI/Dialogs/AnglePicker.hpp b/src/GUI/Dialogs/AnglePicker.hpp new file mode 100644 index 000000000..7b6bc6d3e --- /dev/null +++ b/src/GUI/Dialogs/AnglePicker.hpp @@ -0,0 +1,89 @@ +#ifndef ANGLEPICKER_HPP +#define ANGLEPICKER_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace Slic3r { namespace GUI { + +/// Dialog to produce a special dialog with both a slider for +/- 360 degree rotation and a text box. +/// Supports decimal numbers via integer scaling. +template +class AnglePicker : public wxDialog { +public: + AnglePicker(wxWindow* parent, const wxString& title, double initial_angle) : + wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, wxString("AnglePicker")), _angle(scaling * initial_angle) { + + auto* lbl_min = new wxStaticText(this, wxID_ANY, wxString(L"-360°"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); + auto* lbl_max = new wxStaticText(this, wxID_ANY, wxString(L"360°"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + auto* lbl_txt = new wxStaticText(this, wxID_ANY, wxString("Angle "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); + + auto btn_sizer = new wxBoxSizer(wxHORIZONTAL); + btn_sizer->Add( + new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize), + 0, + wxALL, + 10); + btn_sizer->Add( + new wxButton(this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize), + 0, + wxALL, + 10); + + + this->slider = new wxSlider(this, wxID_ANY, _angle, -360*scaling, 360*scaling, wxDefaultPosition, wxSize(255, wxDefaultSize.y)); + this->manual_entry = new wxTextCtrl(this, wxID_ANY, wxString("") << angle(), wxDefaultPosition, wxDefaultSize); + + + this->hsizer = new wxBoxSizer(wxHORIZONTAL); + this->hsizer->Add(lbl_min, wxALIGN_LEFT); + this->hsizer->Add(this->slider, wxALIGN_CENTER); + this->hsizer->Add(lbl_max, wxALIGN_RIGHT); + + auto text_sizer {new wxBoxSizer(wxHORIZONTAL)}; + text_sizer->Add(lbl_txt, 0); + text_sizer->Add(this->manual_entry, 0); + + this->vsizer = new wxBoxSizer(wxVERTICAL); + + this->vsizer->Add(this->hsizer, 0); + this->vsizer->Add(text_sizer, 0); + this->vsizer->Add(btn_sizer, 0, wxALIGN_CENTER); + + this->SetSizerAndFit(vsizer); + + this->Bind(wxEVT_SLIDER, [this](wxCommandEvent &e){ + wxString str; + _angle = this->slider->GetValue(); + str.Printf("%f", this->angle()); + this->manual_entry->SetValue(str); + }); + this->Bind(wxEVT_TEXT, [this](wxCommandEvent &e){ + wxString str {this->manual_entry->GetValue()}; + double value {0.0}; + if (str.ToDouble(&value)) + if (value <= 360.0 && value >= -360.0) + this->slider->SetValue(value * scaling); + }); + } + double angle() { return double(_angle) / double(scaling) ; } + +private: + /// Scaled integer + int _angle {0}; + + wxSlider* slider {nullptr}; + wxTextCtrl* manual_entry {nullptr}; + wxSizer* hsizer {nullptr}; + wxSizer* vsizer {nullptr}; + +}; + +}} + +#endif// ANGLEPICKER_HPP diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 2eb0d2ec3..e1facce0f 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -120,11 +120,9 @@ void MainFrame::init_menubar() wxMenu* menuPlater = new wxMenu(); { - append_menu_item(menuPlater, _(L"Arrange…"), _("Arrange models on plater"), [=](wxCommandEvent& e) { if (this->plater != nullptr) this->plater->arrange();}, wxID_ANY, "bricks.png", "Ctrl+G"); - } - wxMenu* menuObject = new wxMenu(); - { + append_menu_item(menuPlater, _(L"Arrange…"), _("Arrange models on plater"), [this](wxCommandEvent& e) { if (this->plater != nullptr) this->plater->arrange();}, wxID_ANY, "bricks.png", "Ctrl+G"); } + wxMenu* menuObject = this->plater->object_menu(); wxMenu* menuSettings = new wxMenu(); { } diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 7532f6160..898bb945c 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -9,6 +9,8 @@ #include "MainFrame.hpp" #include "BoundingBox.hpp" #include "Geometry.hpp" +#include "Dialogs/AnglePicker.hpp" + namespace Slic3r { namespace GUI { @@ -450,11 +452,6 @@ void Plater::object_settings_dialog(ObjRef obj) { } -wxMenu* Plater::object_menu() { - return new wxMenu(); -} - - void Plater::select_object(ObjRef obj) { for (auto& o : this->objects) { o.selected = false; @@ -733,8 +730,26 @@ void Plater::decrease(size_t copies, bool dont_push) { this->on_model_change(); } +void Plater::rotate(Axis axis, bool dont_push) { + ObjRef obj {this->selected_object()}; + if (obj == this->objects.end()) return; + double angle {0.0}; + + auto* model_object {this->model->objects.at(obj->identifier)}; + auto model_instance {model_object->instances.begin()}; + + // pop a menu to get the angle + auto* pick = new AnglePicker<1000>(this, "Set Angle", angle); + if (pick->ShowModal() == wxID_OK) { + angle = pick->angle(); + pick->Destroy(); // cleanup afterwards. + this->rotate(angle, axis, dont_push); + } else { + pick->Destroy(); // cleanup afterwards. + } +} + void Plater::rotate(double angle, Axis axis, bool dont_push) { - //TODO ObjRef obj {this->selected_object()}; if (obj == this->objects.end()) return; @@ -761,7 +776,7 @@ void Plater::rotate(double angle, Axis axis, bool dont_push) { this->print->add_model_object(model_object, obj->identifier); if (!dont_push) { - // TODO + add_undo_operation(UndoCmd::Rotate, obj->identifier, angle, axis); } this->selection_changed(); @@ -797,6 +812,9 @@ void Plater::add_undo_operation(UndoCmd cmd, int obj_id, Slic3r::Model& model) { void Plater::add_undo_operation(UndoCmd cmd, int obj_id, size_t copies) { } +void Plater::add_undo_operation(UndoCmd cmd, int obj_id, double angle, Axis axis) { +} + void Plater::object_list_changed() { //TODO } @@ -816,5 +834,127 @@ void Plater::resume_background_process() { //TODO } +wxMenu* Plater::object_menu() { + auto* frame {this->GetFrame()}; + auto* menu {new wxMenu()}; + + append_menu_item(menu, _("Delete"), _("Remove the selected object."), [=](wxCommandEvent& e) { this->remove();}, wxID_ANY, "brick_delete.png", "Ctrl+Del"); +/* + wxTheApp->append_menu_item($menu, "Delete\tCtrl+Del", 'Remove the selected object', sub { + $self->remove; + }, undef, 'brick_delete.png'); + wxTheApp->append_menu_item($menu, "Increase copies\tCtrl++", 'Place one more copy of the selected object', sub { + $self->increase; + }, undef, 'add.png'); + wxTheApp->append_menu_item($menu, "Decrease copies\tCtrl+-", 'Remove one copy of the selected object', sub { + $self->decrease; + }, undef, 'delete.png'); + wxTheApp->append_menu_item($menu, "Set number of copies…", 'Change the number of copies of the selected object', sub { + $self->set_number_of_copies; + }, undef, 'textfield.png'); + $menu->AppendSeparator(); + wxTheApp->append_menu_item($menu, "Move to bed center", 'Center object around bed center', sub { + $self->center_selected_object_on_bed; + }, undef, 'arrow_in.png'); + wxTheApp->append_menu_item($menu, "Rotate 45° clockwise", 'Rotate the selected object by 45° clockwise', sub { + $self->rotate(-45); + }, undef, 'arrow_rotate_clockwise.png'); + wxTheApp->append_menu_item($menu, "Rotate 45° counter-clockwise", 'Rotate the selected object by 45° counter-clockwise', sub { + $self->rotate(+45); + }, undef, 'arrow_rotate_anticlockwise.png'); + */ + { + auto* rotateMenu {new wxMenu}; + append_menu_item(rotateMenu, _(L"Around X axis…"), _("Rotate the selected object by an arbitrary angle around X axis."), [this](wxCommandEvent& e) { this->rotate(X); }, wxID_ANY, "bullet_red.png"); + + append_menu_item(rotateMenu, _(L"Around Y axis…"), _("Rotate the selected object by an arbitrary angle around Y axis."), [this](wxCommandEvent& e) { this->rotate(Y); }, wxID_ANY, "bullet_green.png"); + + append_menu_item(rotateMenu, _(L"Around Z axis…"), _("Rotate the selected object by an arbitrary angle around Z axis."), [this](wxCommandEvent& e) { this->rotate(Z); }, wxID_ANY, "bullet_blue.png"); + + append_submenu(menu, _("Rotate"), _("Rotate the selected object by an arbitrary angle"), rotateMenu, wxID_ANY, "textfield.png"); + } + /* + + { + my $mirrorMenu = Wx::Menu->new; + wxTheApp->append_menu_item($mirrorMenu, "Along X axis…", 'Mirror the selected object along the X axis', sub { + $self->mirror(X); + }, undef, 'bullet_red.png'); + wxTheApp->append_menu_item($mirrorMenu, "Along Y axis…", 'Mirror the selected object along the Y axis', sub { + $self->mirror(Y); + }, undef, 'bullet_green.png'); + wxTheApp->append_menu_item($mirrorMenu, "Along Z axis…", 'Mirror the selected object along the Z axis', sub { + $self->mirror(Z); + }, undef, 'bullet_blue.png'); + wxTheApp->append_submenu($menu, "Mirror", 'Mirror the selected object', $mirrorMenu, undef, 'shape_flip_horizontal.png'); + } + + { + my $scaleMenu = Wx::Menu->new; + wxTheApp->append_menu_item($scaleMenu, "Uniformly…", 'Scale the selected object along the XYZ axes', sub { + $self->changescale(undef); + }); + wxTheApp->append_menu_item($scaleMenu, "Along X axis…", 'Scale the selected object along the X axis', sub { + $self->changescale(X); + }, undef, 'bullet_red.png'); + wxTheApp->append_menu_item($scaleMenu, "Along Y axis…", 'Scale the selected object along the Y axis', sub { + $self->changescale(Y); + }, undef, 'bullet_green.png'); + wxTheApp->append_menu_item($scaleMenu, "Along Z axis…", 'Scale the selected object along the Z axis', sub { + $self->changescale(Z); + }, undef, 'bullet_blue.png'); + wxTheApp->append_submenu($menu, "Scale", 'Scale the selected object by a given factor', $scaleMenu, undef, 'arrow_out.png'); + } + + { + my $scaleToSizeMenu = Wx::Menu->new; + wxTheApp->append_menu_item($scaleToSizeMenu, "Uniformly…", 'Scale the selected object along the XYZ axes', sub { + $self->changescale(undef, 1); + }); + wxTheApp->append_menu_item($scaleToSizeMenu, "Along X axis…", 'Scale the selected object along the X axis', sub { + $self->changescale(X, 1); + }, undef, 'bullet_red.png'); + wxTheApp->append_menu_item($scaleToSizeMenu, "Along Y axis…", 'Scale the selected object along the Y axis', sub { + $self->changescale(Y, 1); + }, undef, 'bullet_green.png'); + wxTheApp->append_menu_item($scaleToSizeMenu, "Along Z axis…", 'Scale the selected object along the Z axis', sub { + $self->changescale(Z, 1); + }, undef, 'bullet_blue.png'); + wxTheApp->append_submenu($menu, "Scale to size", 'Scale the selected object to match a given size', $scaleToSizeMenu, undef, 'arrow_out.png'); + } + + wxTheApp->append_menu_item($menu, "Split", 'Split the selected object into individual parts', sub { + $self->split_object; + }, undef, 'shape_ungroup.png'); + wxTheApp->append_menu_item($menu, "Cut…", 'Open the 3D cutting tool', sub { + $self->object_cut_dialog; + }, undef, 'package.png'); + wxTheApp->append_menu_item($menu, "Layer heights…", 'Open the dynamic layer height control', sub { + $self->object_layers_dialog; + }, undef, 'variable_layer_height.png'); + $menu->AppendSeparator(); + wxTheApp->append_menu_item($menu, "Settings…", 'Open the object editor dialog', sub { + $self->object_settings_dialog; + }, undef, 'cog.png'); + $menu->AppendSeparator(); + wxTheApp->append_menu_item($menu, "Reload from Disk", 'Reload the selected file from Disk', sub { + $self->reload_from_disk; + }, undef, 'arrow_refresh.png'); + wxTheApp->append_menu_item($menu, "Export object as STL…", 'Export this single object as STL file', sub { + $self->export_object_stl; + }, undef, 'brick_go.png'); + wxTheApp->append_menu_item($menu, "Export object and modifiers as AMF…", 'Export this single object and all associated modifiers as AMF file', sub { + $self->export_object_amf; + }, undef, 'brick_go.png'); + wxTheApp->append_menu_item($menu, "Export object and modifiers as 3MF…", 'Export this single object and all associated modifiers as 3MF file', sub { + $self->export_object_tmf; + }, undef, 'brick_go.png'); + + return $menu; +} +*/ + return menu; +} + }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 518931834..a1c81e60b 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -31,7 +31,7 @@ namespace Slic3r { namespace GUI { using UndoOperation = int; enum class UndoCmd { - Remove, Add, Reset, Increase, Decrease + Remove, Add, Reset, Increase, Decrease, Rotate }; using ObjIdx = unsigned int; @@ -70,6 +70,12 @@ public: /// Undo for increase/decrease void add_undo_operation(UndoCmd cmd, int obj_id, size_t copies); + /// Undo for increase/decrease + void add_undo_operation(UndoCmd cmd, int obj_id, double angle, Axis axis); + + /// Create menu for object. + wxMenu* object_menu(); + private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; @@ -158,8 +164,6 @@ private: void object_settings_dialog(ObjIdx obj_idx); void object_settings_dialog(ObjRef obj); - /// Create and launch menu for object. - wxMenu* object_menu(); /// Instantiate the toolbar void build_toolbar(); @@ -173,6 +177,8 @@ private: /// Remove instances of the currently selected model. void decrease(size_t copies = 1, bool dont_push = false); + /// Rotate the currently selected model, triggering a user prompt. + void rotate(Axis axis = Z, bool dont_push = false); /// Rotate the currently selected model. void rotate(double angle, Axis axis = Z, bool dont_push = false); diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index f04adc8b7..41c1f17f0 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -64,6 +64,24 @@ void fatal_error(wxWindow* parent, const wxString& message) { throw std::runtime_error(message.ToStdString()); } +wxMenuItem* append_submenu(wxMenu* menu, const wxString& name, const wxString& help, wxMenu* submenu, int id, const wxString& icon) { + auto* item {new wxMenuItem(menu, id, name, help)}; + + set_menu_item_icon(item,icon); + item->SetSubMenu(submenu); + menu->Append(item); + return item; +} + +void set_menu_item_icon(wxMenuItem* item, const wxString& icon) { + if (!icon.IsEmpty()) { + wxBitmap ico; + if(ico.LoadFile(var(icon), wxBITMAP_TYPE_PNG)) + item->SetBitmap(ico); + else + std::cerr<< var(icon) << " failed to load \n"; + } +} /* sub append_submenu { diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index fb3930325..e592618ea 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -107,6 +107,8 @@ void show_info(wxWindow* parent, const wxString& message, const wxString& title) /// Show an error messagebox and then throw an exception. void fatal_error(wxWindow* parent, const wxString& message); +/// Assign a menu item icon +void set_menu_item_icon(wxMenuItem* item, const wxString& icon); template void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxString& icon = "", const wxString& accel = "") { @@ -117,18 +119,14 @@ void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T tmp->SetAccel(a); // set the accelerator if and only if the accelerator is fine } tmp->SetHelp(help); - if (!icon.IsEmpty()) { - wxBitmap ico; - if(ico.LoadFile(var(icon), wxBITMAP_TYPE_PNG)) - tmp->SetBitmap(ico); - else - std::cerr<< var(icon) << " failed to load \n"; - } + set_menu_item_icon(tmp, icon); if (typeid(lambda) != typeid(nullptr)) menu->Bind(wxEVT_MENU, lambda, tmp->GetId(), tmp->GetId()); } +wxMenuItem* append_submenu(wxMenu* menu, const wxString& name, const wxString& help, wxMenu* submenu, int id = wxID_ANY, const wxString& icon = ""); + /* sub CallAfter { my ($self, $cb) = @_; From ab97539a1dd76c516ab51ac32ee75261b492e917 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 21:30:04 -0500 Subject: [PATCH 204/305] gcc please don't treat that as an initializer list. :( --- src/GUI/Dialogs/AboutDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Dialogs/AboutDialog.cpp b/src/GUI/Dialogs/AboutDialog.cpp index fb6d2798e..84211d62d 100644 --- a/src/GUI/Dialogs/AboutDialog.cpp +++ b/src/GUI/Dialogs/AboutDialog.cpp @@ -87,7 +87,7 @@ void AboutDialogLogo::repaint(wxPaintEvent& event) dc.SetBackgroundMode(wxPENSTYLE_TRANSPARENT); - const wxSize size {this->GetSize()}; + const wxSize size = this->GetSize() ; const auto logo_w {this->logo.GetWidth()}; const auto logo_h {this->logo.GetHeight()}; From a8ae789c1b6c222d24db9e970d81292b6a0d79f0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 21:30:35 -0500 Subject: [PATCH 205/305] Implement more of Object menu --- src/GUI/Plater.cpp | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 898bb945c..ef43fc18a 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -839,36 +839,19 @@ wxMenu* Plater::object_menu() { auto* menu {new wxMenu()}; append_menu_item(menu, _("Delete"), _("Remove the selected object."), [=](wxCommandEvent& e) { this->remove();}, wxID_ANY, "brick_delete.png", "Ctrl+Del"); -/* - wxTheApp->append_menu_item($menu, "Delete\tCtrl+Del", 'Remove the selected object', sub { - $self->remove; - }, undef, 'brick_delete.png'); - wxTheApp->append_menu_item($menu, "Increase copies\tCtrl++", 'Place one more copy of the selected object', sub { - $self->increase; - }, undef, 'add.png'); - wxTheApp->append_menu_item($menu, "Decrease copies\tCtrl+-", 'Remove one copy of the selected object', sub { - $self->decrease; - }, undef, 'delete.png'); - wxTheApp->append_menu_item($menu, "Set number of copies…", 'Change the number of copies of the selected object', sub { - $self->set_number_of_copies; - }, undef, 'textfield.png'); - $menu->AppendSeparator(); - wxTheApp->append_menu_item($menu, "Move to bed center", 'Center object around bed center', sub { - $self->center_selected_object_on_bed; - }, undef, 'arrow_in.png'); - wxTheApp->append_menu_item($menu, "Rotate 45° clockwise", 'Rotate the selected object by 45° clockwise', sub { - $self->rotate(-45); - }, undef, 'arrow_rotate_clockwise.png'); - wxTheApp->append_menu_item($menu, "Rotate 45° counter-clockwise", 'Rotate the selected object by 45° counter-clockwise', sub { - $self->rotate(+45); - }, undef, 'arrow_rotate_anticlockwise.png'); - */ + append_menu_item(menu, _("Increase copies"), _("Place one more copy of the selected object."), [=](wxCommandEvent& e) { this->increase();}, wxID_ANY, "add.png", "Ctrl++"); + append_menu_item(menu, _("Decrease copies"), _("Remove one copy of the selected object."), [=](wxCommandEvent& e) { this->decrease();}, wxID_ANY, "delete.png", "Ctrl+-"); + append_menu_item(menu, _(L"Set number of copies…"), _("Change the number of copies of the selected object."), [=](wxCommandEvent& e) { this->decrease();}, wxID_ANY, "textfield.png"); + menu->AppendSeparator(); + append_menu_item(menu, _(L"Move to bed center"), _(L"Center object around bed center."), [=](wxCommandEvent& e) { this->center_selected_object_on_bed();}, wxID_ANY, "arrow_in.png"); + append_menu_item(menu, _(L"Rotate 45° clockwise"), _(L"Rotate the selected object by 45° clockwise."), [=](wxCommandEvent& e) { this->rotate(45);}, wxID_ANY, "arrow_rotate_clockwise.png"); + append_menu_item(menu, _(L"Rotate 45° counter-clockwise"), _(L"Rotate the selected object by 45° counter-clockwise."), [=](wxCommandEvent& e) { this->rotate(-45);}, wxID_ANY, "arrow_rotate_anticlockwise.png"); + { auto* rotateMenu {new wxMenu}; + append_menu_item(rotateMenu, _(L"Around X axis…"), _("Rotate the selected object by an arbitrary angle around X axis."), [this](wxCommandEvent& e) { this->rotate(X); }, wxID_ANY, "bullet_red.png"); - append_menu_item(rotateMenu, _(L"Around Y axis…"), _("Rotate the selected object by an arbitrary angle around Y axis."), [this](wxCommandEvent& e) { this->rotate(Y); }, wxID_ANY, "bullet_green.png"); - append_menu_item(rotateMenu, _(L"Around Z axis…"), _("Rotate the selected object by an arbitrary angle around Z axis."), [this](wxCommandEvent& e) { this->rotate(Z); }, wxID_ANY, "bullet_blue.png"); append_submenu(menu, _("Rotate"), _("Rotate the selected object by an arbitrary angle"), rotateMenu, wxID_ANY, "textfield.png"); From a8e2c860ae2136d712e2d1fdcd98355a8243b2ad Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 21:50:36 -0500 Subject: [PATCH 206/305] Implemented center_selected_object_on_bed and set_number_of_copies --- src/GUI/Plater.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/GUI/Plater.hpp | 7 +++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index ef43fc18a..7eb51d9a8 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "Plater.hpp" @@ -841,7 +842,7 @@ wxMenu* Plater::object_menu() { append_menu_item(menu, _("Delete"), _("Remove the selected object."), [=](wxCommandEvent& e) { this->remove();}, wxID_ANY, "brick_delete.png", "Ctrl+Del"); append_menu_item(menu, _("Increase copies"), _("Place one more copy of the selected object."), [=](wxCommandEvent& e) { this->increase();}, wxID_ANY, "add.png", "Ctrl++"); append_menu_item(menu, _("Decrease copies"), _("Remove one copy of the selected object."), [=](wxCommandEvent& e) { this->decrease();}, wxID_ANY, "delete.png", "Ctrl+-"); - append_menu_item(menu, _(L"Set number of copies…"), _("Change the number of copies of the selected object."), [=](wxCommandEvent& e) { this->decrease();}, wxID_ANY, "textfield.png"); + append_menu_item(menu, _(L"Set number of copies…"), _("Change the number of copies of the selected object."), [=](wxCommandEvent& e) { this->set_number_of_copies();}, wxID_ANY, "textfield.png"); menu->AppendSeparator(); append_menu_item(menu, _(L"Move to bed center"), _(L"Center object around bed center."), [=](wxCommandEvent& e) { this->center_selected_object_on_bed();}, wxID_ANY, "arrow_in.png"); append_menu_item(menu, _(L"Rotate 45° clockwise"), _(L"Rotate the selected object by 45° clockwise."), [=](wxCommandEvent& e) { this->rotate(45);}, wxID_ANY, "arrow_rotate_clockwise.png"); @@ -939,5 +940,40 @@ wxMenu* Plater::object_menu() { return menu; } +void Plater::set_number_of_copies() { + this->pause_background_process(); + + ObjRef obj {this->selected_object()}; + if (obj == this->objects.end()) return; + auto* model_object { this->model->objects.at(obj->identifier) }; + + long copies = -1; + copies = wxGetNumberFromUser("", _("Enter the number of copies of the selected object:"), _("Copies"), model_object->instances.size(), 0, 1000, this); + if (copies < 0) return; + long diff {copies - model_object->instances.size() }; + + if (diff == 0) { this->resume_background_process(); } + else if (diff > 0) { this->increase(diff); } + else if (diff < 0) { this->decrease(-diff); } +} +void Plater::center_selected_object_on_bed() { + ObjRef obj {this->selected_object()}; + + if (obj == this->objects.end()) return; + auto* model_object { this->model->objects.at(obj->identifier) }; + auto bb {model_object->bounding_box()}; + auto size {bb.size()}; + + auto vector { Slic3r::Pointf( + this->bed_centerf().x - bb.min.x - size.x/2.0, + this->bed_centerf().y - bb.min.y - size.y/2.0)}; + for (auto* inst : model_object->instances) { + inst->offset.translate(vector); + } + + this->refresh_canvases(); + +} + }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index a1c81e60b..d6d5977f6 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -145,7 +145,6 @@ private: /// Complete thumbnail transformation and refresh canvases void on_thumbnail_made(size_t idx); - /// Issue a repaint event to all of the canvasses. void refresh_canvases(); @@ -164,7 +163,6 @@ private: void object_settings_dialog(ObjIdx obj_idx); void object_settings_dialog(ObjRef obj); - /// Instantiate the toolbar void build_toolbar(); @@ -204,6 +202,11 @@ private: void pause_background_process(); void resume_background_process(); + + /// Move the selected object to the center of bed. + void center_selected_object_on_bed(); + + void set_number_of_copies(); }; From 23a0f417d1becef2598a371691df9b085b2a5e32 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 21:57:21 -0500 Subject: [PATCH 207/305] Still playing with solarized, better setup (private constants with public functions) --- src/GUI/ColorScheme/Solarized.hpp | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/GUI/ColorScheme/Solarized.hpp b/src/GUI/ColorScheme/Solarized.hpp index b02f0849d..228257f97 100644 --- a/src/GUI/ColorScheme/Solarized.hpp +++ b/src/GUI/ColorScheme/Solarized.hpp @@ -12,30 +12,30 @@ namespace Slic3r { namespace GUI { /// Implements a colorscheme lookup of wxColors class Solarized : public ColorScheme { public: - const wxColour SELECTED_COLOR() const { return COLOR_MAGENTA(); } - const wxColour HOVER_COLOR() const { return COLOR_VIOLET(); } - const wxColour SUPPORT_COLOR() const { return COLOR_VIOLET(); } + const wxColour SELECTED_COLOR() const { return COLOR_SOLAR_MAGENTA; } + const wxColour HOVER_COLOR() const { return COLOR_SOLAR_VIOLET; } + const wxColour SUPPORT_COLOR() const { return COLOR_SOLAR_VIOLET; } - const wxColour BACKGROUND_COLOR() const { return COLOR_BASE3(); } + const wxColour BACKGROUND_COLOR() const { return COLOR_SOLAR_BASE3; } private: - const wxColour COLOR_BASE0() const {return wxColour(255*0.51373,255*0.58039,255*0.58824);} - const wxColour COLOR_BASE00() const {return wxColour(255*0.39608,255*0.48235,255*0.51373);} - const wxColour COLOR_BASE01() const {return wxColour(255*0.34510,255*0.43137,255*0.45882);} - const wxColour COLOR_BASE02() const {return wxColour(255*0.02745,255*0.21176,255*0.25882);} - const wxColour COLOR_BASE03() const {return wxColour(255*0.00000,255*0.16863,255*0.21176);} - const wxColour COLOR_BASE1() const {return wxColour(255*0.57647,255*0.63137,255*0.63137);} - const wxColour COLOR_BASE2() const {return wxColour(255*0.93333,255*0.90980,255*0.83529);} - const wxColour COLOR_BASE3() const {return wxColour(255*0.99216,255*0.96471,255*0.89020);} - const wxColour COLOR_BLUE() const {return wxColour(255*0.14902,255*0.54510,255*0.82353);} - const wxColour COLOR_CYAN() const {return wxColour(255*0.16471,255*0.63137,255*0.59608);} - const wxColour COLOR_GREEN() const {return wxColour(255*0.52157,255*0.60000,255*0.00000);} - const wxColour COLOR_MAGENTA() const {return wxColour(255*0.82745,255*0.21176,255*0.50980);} - const wxColour COLOR_ORANGE() const {return wxColour(255*0.79608,255*0.29412,255*0.08627);} - const wxColour COLOR_RED() const {return wxColour(255*0.86275,255*0.19608,255*0.18431);} - const wxColour COLOR_VIOLET() const {return wxColour(255*0.42353,255*0.44314,255*0.76863);} - const wxColour COLOR_YELLOW() const {return wxColour(255*0.70980,255*0.53725,255*0.00000);} + const wxColour COLOR_SOLAR_BASE0 { wxColour(255*0.51373,255*0.58039,255*0.58824)}; + const wxColour COLOR_SOLAR_BASE00 { wxColour(255*0.39608,255*0.48235,255*0.51373)}; + const wxColour COLOR_SOLAR_BASE01 { wxColour(255*0.34510,255*0.43137,255*0.45882)}; + const wxColour COLOR_SOLAR_BASE02 { wxColour(255*0.02745,255*0.21176,255*0.25882)}; + const wxColour COLOR_SOLAR_BASE03 { wxColour(255*0.00000,255*0.16863,255*0.21176)}; + const wxColour COLOR_SOLAR_BASE1 { wxColour(255*0.57647,255*0.63137,255*0.63137)}; + const wxColour COLOR_SOLAR_BASE2 { wxColour(255*0.93333,255*0.90980,255*0.83529)}; + const wxColour COLOR_SOLAR_BASE3 { wxColour(255*0.99216,255*0.96471,255*0.89020)}; + const wxColour COLOR_SOLAR_BLUE { wxColour(255*0.14902,255*0.54510,255*0.82353)}; + const wxColour COLOR_SOLAR_CYAN { wxColour(255*0.16471,255*0.63137,255*0.59608)}; + const wxColour COLOR_SOLAR_GREEN { wxColour(255*0.52157,255*0.60000,255*0.00000)}; + const wxColour COLOR_SOLAR_MAGENTA { wxColour(255*0.82745,255*0.21176,255*0.50980)}; + const wxColour COLOR_SOLAR_ORANGE { wxColour(255*0.79608,255*0.29412,255*0.08627)}; + const wxColour COLOR_SOLAR_RED { wxColour(255*0.86275,255*0.19608,255*0.18431)}; + const wxColour COLOR_SOLAR_VIOLET { wxColour(255*0.42353,255*0.44314,255*0.76863)}; + const wxColour COLOR_SOLAR_YELLOW { wxColour(255*0.70980,255*0.53725,255*0.00000)}; }; }} // namespace Slic3r::GUI From 121dd6636224380d5e5ca5286d627d9137c48312 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:08:36 -0500 Subject: [PATCH 208/305] Handle possible narrowing of data type between unsigned long and signed long --- src/GUI/Plater.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 7eb51d9a8..24cce1573 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -950,7 +950,13 @@ void Plater::set_number_of_copies() { long copies = -1; copies = wxGetNumberFromUser("", _("Enter the number of copies of the selected object:"), _("Copies"), model_object->instances.size(), 0, 1000, this); if (copies < 0) return; - long diff {copies - model_object->instances.size() }; + long instance_count = 0; + if (model_object->instances.size() <= LONG_MAX) { + instance_count = static_cast(model_object->instances.size()); + } else { + instance_count = LONG_MAX; + } + long diff {copies - instance_count }; if (diff == 0) { this->resume_background_process(); } else if (diff > 0) { this->increase(diff); } From a98dad496d4a2b8f628d2f48874e38b08fa7f476 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:10:43 -0500 Subject: [PATCH 209/305] gcc, pls --- src/GUI/Dialogs/AboutDialog.cpp | 4 ++-- src/GUI/Plater.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GUI/Dialogs/AboutDialog.cpp b/src/GUI/Dialogs/AboutDialog.cpp index 84211d62d..745d53a7d 100644 --- a/src/GUI/Dialogs/AboutDialog.cpp +++ b/src/GUI/Dialogs/AboutDialog.cpp @@ -88,8 +88,8 @@ void AboutDialogLogo::repaint(wxPaintEvent& event) dc.SetBackgroundMode(wxPENSTYLE_TRANSPARENT); const wxSize size = this->GetSize() ; - const auto logo_w {this->logo.GetWidth()}; - const auto logo_h {this->logo.GetHeight()}; + const auto logo_w = this->logo.GetWidth(); + const auto logo_h = this->logo.GetHeight(); dc.DrawBitmap(this->logo, (size.GetWidth() - logo_w) / 2, (size.GetHeight() - logo_h) / 2, 1); event.Skip(); diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 24cce1573..051949ca2 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -1,4 +1,6 @@ #include +#include + #include #include #include From e07dfdf54fe135c2b77c370e7bd0c9a9c5c380f4 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:26:10 -0500 Subject: [PATCH 210/305] setting envionment variables via matrix --- .travis.yml | 13 ++++--- package/linux/travis-setup.sh | 66 +++++++++++++++++------------------ 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/.travis.yml b/.travis.yml index cda043d13..f4e778b7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,3 @@ -os: - - linux - - osx -language: c++ before_install: - sh package/linux/travis-decrypt-key install: @@ -51,6 +47,15 @@ notifications: dist: trusty env: matrix: + include: + - os: linux + language: c++ + env: CXX=g++-7 + env: CX=gcc-7 + env: WXVERSION=pkg + - os: osx + language: c++ + env: WXVERSION=pkg global: - secure: eEVRZNMv7FM6jrOU9iAFkDhWxFQ1WtHBEaObImcvtFUxy6vWSt3ehFFeTRouj3uHQAnbvUzziDyvPPm8/95alv5g/du8ML6YzzqKBKfazM0xQ7SF6R2DQL8lfFIp+RSV7T02byEP1f1g7Zva7xH9szIlDcSfU0pXW4KWbkBFMd8= - secure: gj338h+qHGccTD/VQFmEJkqdg2McIe2pO0iZ4Ae9BvY5vxkIML4BpoYZQXQTqiAOETnUjlcknY9lx0hI/PfkDD9MSJc5BC/3fMYRCu3SgAclEwklWf9vvtodUeT69mtnZuw1zze1nTbExuOw2mepbqFjxKKMl+9l5oCz4O54fXU= diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index 19f206c37..e6ac70440 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -1,41 +1,41 @@ #!/bin/bash # Script to configure travis environment prior to build -WXVERSION=302 CACHE=$HOME/cache mkdir -p $CACHE -if [ $TRAVIS_OS_NAME == "linux" ]; then - export WXDIR=$HOME/wx${WXVERSION} - if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then - echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" - curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 +if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then + if [[ "$WXVERSION" -neq "pkg" ]]; then + export WXDIR=$HOME/wx${WXVERSION} + if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then + echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" + curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 + fi + + if [ ! -e $CACHE/wx${WXVERSION}.tar.bz2 ]; then + echo "Downloading http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2 => $CACHE/wx${WXVERSION}.tar.bz2" + curl -L "http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2" -o $CACHE/wx${WXVERSION}.tar.bz2 + fi + + tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 + tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 fi - if [ ! -e $CACHE/wx${WXVERSION}.tar.bz2 ]; then - echo "Downloading http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2 => $CACHE/wx${WXVERSION}.tar.bz2" - curl -L "http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2" -o $CACHE/wx${WXVERSION}.tar.bz2 +elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + if [[ "$WXVERSION" -neq "pkg" ]]; then + WXVER_EXPANDED=${WXVERSION:0:1}.${WXVERSION:1:1}.${WXVERSION:2:1} + export WXDIR=$HOME/wx${WXVERSION} + if [ ! -e $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 ]; then + curl -L "https://github.com/wxWidgets/wxWidgets/releases/download/v${WXVER_EXPANDED}/wxWidgets-${WXVER_EXPANDED}.tar.bz2" -o $HOME/wx${WXVERSION}-src.tar.bz2 + tar -C$HOME -xjf $HOME/wx${WXVERSION}-src.tar.bz2 + mkdir $WXDIR + cd $HOME/$WXDIR && cmake $HOME/wxWidgets-${WXVER_EXPANDED} -DwxBUILD_SHARED=OFF + cmake --build . --target -- -j4 + tar -C$HOME -cjf $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 $(basename ${WXDIR}) + else + tar -C$HOME -xjf $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 + fi + export PATH=${PATH}:${WXDIR} + cd $TRAVIS_BUILD_DIR # go back to the build dir + else + brew install wxmac # install via homebrew fi - - tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 - tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 - - # Set some env variables specific to Travis Linux - export CXX=g++-7 - export CC=gcc-7 -elif [ $TRAVIS_OS_NAME == "osx" ]; then - WXVERSION=311 - WXVER_EXPANDED=${WXVERSION:0:1}.${WXVERSION:1:1}.${WXVERSION:2:1} - export WXDIR=$HOME/wx${WXVERSION} - if [ ! -e $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 ]; then - curl -L "https://github.com/wxWidgets/wxWidgets/releases/download/v${WXVER_EXPANDED}/wxWidgets-${WXVER_EXPANDED}.tar.bz2" -o $HOME/wx${WXVERSION}-src.tar.bz2 - tar -C$HOME -xjf $HOME/wx${WXVERSION}-src.tar.bz2 - mkdir $WXDIR - cd $HOME/$WXDIR && cmake $HOME/wxWidgets-${WXVER_EXPANDED} -DwxBUILD_SHARED=OFF - cmake --build . --target -- -j4 - tar -C$HOME -cjf $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 $(basename ${WXDIR}) - else - tar -C$HOME -xjf $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 - fi - export PATH=${PATH}:${WXDIR} - cd $TRAVIS_BUILD_DIR # go back to the build dir - brew install wxmac # install via homebrew fi From 331584f72810f69b66d0063311d261c9c8a826a3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:28:50 -0500 Subject: [PATCH 211/305] fixing travis? --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4e778b7b..9a9815aeb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,8 +45,7 @@ notifications: on_failure: always use_notice: true dist: trusty -env: - matrix: +matrix: include: - os: linux language: c++ @@ -56,6 +55,7 @@ env: - os: osx language: c++ env: WXVERSION=pkg +env: global: - secure: eEVRZNMv7FM6jrOU9iAFkDhWxFQ1WtHBEaObImcvtFUxy6vWSt3ehFFeTRouj3uHQAnbvUzziDyvPPm8/95alv5g/du8ML6YzzqKBKfazM0xQ7SF6R2DQL8lfFIp+RSV7T02byEP1f1g7Zva7xH9szIlDcSfU0pXW4KWbkBFMd8= - secure: gj338h+qHGccTD/VQFmEJkqdg2McIe2pO0iZ4Ae9BvY5vxkIML4BpoYZQXQTqiAOETnUjlcknY9lx0hI/PfkDD9MSJc5BC/3fMYRCu3SgAclEwklWf9vvtodUeT69mtnZuw1zze1nTbExuOw2mepbqFjxKKMl+9l5oCz4O54fXU= From e829d05cc0f270705285d84a20e538d77ce0eec5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:29:41 -0500 Subject: [PATCH 212/305] fixing travis? --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9a9815aeb..2a7a8c840 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,9 +49,10 @@ matrix: include: - os: linux language: c++ - env: CXX=g++-7 - env: CX=gcc-7 - env: WXVERSION=pkg + env: + - CXX=g++-7 + - CX=gcc-7 + - WXVERSION=pkg - os: osx language: c++ env: WXVERSION=pkg From 18d3ccf581231b9dd1480baec5459b9c20e60041 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:36:03 -0500 Subject: [PATCH 213/305] broke script out, trying to avoid gcc-4 getting used on linux for whatever reason --- .travis.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2a7a8c840..886311368 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,9 @@ before_install: - sh package/linux/travis-decrypt-key +- bash package/linux/travis-setup.sh install: - export BOOST_DIR=$HOME/boost_1_63_0 - export SLIC3R_STATIC=1 -script: -- bash package/linux/travis-setup.sh -- cmake -DBOOST_ROOT=$BOOST_DIR -DwxWidgets_ROOT_DIR=$WXDIR src/ -- make VERBOSE=1 after_success: - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 - package/linux/appimage.sh x86_64 @@ -50,12 +47,16 @@ matrix: - os: linux language: c++ env: - - CXX=g++-7 - - CX=gcc-7 - WXVERSION=pkg + script: + - CXX=g++-7 CC=gcc-7 cmake -DBOOST_ROOT=$BOOST_DIR src/ + - make - os: osx language: c++ env: WXVERSION=pkg + script: + - cmake -DBOOST_ROOT=$BOOST_DIR src/ + - make env: global: - secure: eEVRZNMv7FM6jrOU9iAFkDhWxFQ1WtHBEaObImcvtFUxy6vWSt3ehFFeTRouj3uHQAnbvUzziDyvPPm8/95alv5g/du8ML6YzzqKBKfazM0xQ7SF6R2DQL8lfFIp+RSV7T02byEP1f1g7Zva7xH9szIlDcSfU0pXW4KWbkBFMd8= From cb6264afde3ca384f3fccacf2f7fc94096f8bd5a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:39:06 -0500 Subject: [PATCH 214/305] fix bash --- package/linux/travis-setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index e6ac70440..dfa4277e3 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -3,7 +3,7 @@ CACHE=$HOME/cache mkdir -p $CACHE if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then - if [[ "$WXVERSION" -neq "pkg" ]]; then + if [[ "$WXVERSION" != "pkg" ]]; then export WXDIR=$HOME/wx${WXVERSION} if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" @@ -20,7 +20,7 @@ if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then fi elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - if [[ "$WXVERSION" -neq "pkg" ]]; then + if [[ "$WXVERSION" != "pkg" ]]; then WXVER_EXPANDED=${WXVERSION:0:1}.${WXVERSION:1:1}.${WXVERSION:2:1} export WXDIR=$HOME/wx${WXVERSION} if [ ! -e $CACHE/wx${WXVERSION}-${TRAVIS_OS_NAME}.tar.bz2 ]; then From 35f468523ef9de091033c942fdda1b419b684ac3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:43:41 -0500 Subject: [PATCH 215/305] set an eval to force correct --- .travis.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 886311368..e464bb21a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,19 @@ before_install: -- sh package/linux/travis-decrypt-key -- bash package/linux/travis-setup.sh -install: -- export BOOST_DIR=$HOME/boost_1_63_0 -- export SLIC3R_STATIC=1 + - sh package/linux/travis-decrypt-key + - bash package/linux/travis-setup.sh + - eval "${MATRIX_EVAL}" +env: + - BOOST_DIR=$HOME/boost_1_63_0 + - SLIC3R_STATIC=1 +script: + - cmake -DBOOST_ROOT=$BOOST_DIR src/ + - make after_success: -- LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 -- package/linux/appimage.sh x86_64 -- package/deploy/sftp.sh linux ~/slic3r-upload.rsa *.bz2 Slic3r*.AppImage -- package/deploy/sftp-symlink.sh linux ~/slic3r-upload.rsa AppImage Slic3r*.AppImage -- package/deploy/sftp-symlink.sh linux ~/slic3r-upload.rsa tar.bz2 *.bz2 + - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 + - package/linux/appimage.sh x86_64 + - package/deploy/sftp.sh linux ~/slic3r-upload.rsa *.bz2 Slic3r*.AppImage + - package/deploy/sftp-symlink.sh linux ~/slic3r-upload.rsa AppImage Slic3r*.AppImage + - package/deploy/sftp-symlink.sh linux ~/slic3r-upload.rsa tar.bz2 *.bz2 branches: only: - master @@ -48,15 +52,11 @@ matrix: language: c++ env: - WXVERSION=pkg - script: - - CXX=g++-7 CC=gcc-7 cmake -DBOOST_ROOT=$BOOST_DIR src/ - - make + - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" - os: osx language: c++ - env: WXVERSION=pkg - script: - - cmake -DBOOST_ROOT=$BOOST_DIR src/ - - make + env: + - WXVERSION=pkg env: global: - secure: eEVRZNMv7FM6jrOU9iAFkDhWxFQ1WtHBEaObImcvtFUxy6vWSt3ehFFeTRouj3uHQAnbvUzziDyvPPm8/95alv5g/du8ML6YzzqKBKfazM0xQ7SF6R2DQL8lfFIp+RSV7T02byEP1f1g7Zva7xH9szIlDcSfU0pXW4KWbkBFMd8= From 1430180b242ff73b01f8eb6b56884b049cff097a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:46:10 -0500 Subject: [PATCH 216/305] remove language preconfig --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e464bb21a..d96d09dcf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,12 +49,10 @@ dist: trusty matrix: include: - os: linux - language: c++ env: - WXVERSION=pkg - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" - os: osx - language: c++ env: - WXVERSION=pkg env: From 86b98c4eb6356b17d4801b8bd026d89b23f0f1c2 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:52:01 -0500 Subject: [PATCH 217/305] Fix boost download and travis --- .travis.yml | 6 +++--- package/linux/travis-setup.sh | 13 ++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index d96d09dcf..a2ecfeb86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,10 @@ before_install: - sh package/linux/travis-decrypt-key - - bash package/linux/travis-setup.sh - - eval "${MATRIX_EVAL}" env: - BOOST_DIR=$HOME/boost_1_63_0 - SLIC3R_STATIC=1 script: + - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR src/ - make after_success: @@ -51,7 +50,8 @@ matrix: - os: linux env: - WXVERSION=pkg - - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" + - CC=gcc-7 + - CXX-g++-7 - os: osx env: - WXVERSION=pkg diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index dfa4277e3..79780609e 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -5,19 +5,18 @@ mkdir -p $CACHE if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then if [[ "$WXVERSION" != "pkg" ]]; then export WXDIR=$HOME/wx${WXVERSION} - if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then - echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" - curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 - fi - if [ ! -e $CACHE/wx${WXVERSION}.tar.bz2 ]; then echo "Downloading http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2 => $CACHE/wx${WXVERSION}.tar.bz2" curl -L "http://www.siusgs.com/slic3r/buildserver/wx${WXVERSION}-libs.tar.bz2" -o $CACHE/wx${WXVERSION}.tar.bz2 fi - - tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 fi + if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then + echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" + curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 + fi + + tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then if [[ "$WXVERSION" != "pkg" ]]; then From f44a2a17e29e4c21f03c4848ee36d77717faa117 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:53:01 -0500 Subject: [PATCH 218/305] re-add language to cpp --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a2ecfeb86..e4bb75a9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +language: cpp before_install: - sh package/linux/travis-decrypt-key env: From a05791e90d311f07f8585d3e2f7df5ba67e59f3f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:54:56 -0500 Subject: [PATCH 219/305] oops, typo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e4bb75a9d..ebc509c37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,7 +52,7 @@ matrix: env: - WXVERSION=pkg - CC=gcc-7 - - CXX-g++-7 + - CXX=g++-7 - os: osx env: - WXVERSION=pkg From cac7d911649acc041ae81ea53adea4f1e8e5147b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 22:58:40 -0500 Subject: [PATCH 220/305] travis, pls --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ebc509c37..f8d052928 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ env: - BOOST_DIR=$HOME/boost_1_63_0 - SLIC3R_STATIC=1 script: + - if [ -z ${CXX7+x} ]; then export CXX=$CXX7; fi + - if [ -z ${CC7+x} ]; then export CC=$CC7; fi - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR src/ - make @@ -51,8 +53,8 @@ matrix: - os: linux env: - WXVERSION=pkg - - CC=gcc-7 - - CXX=g++-7 + - CC7=gcc-7 + - CXX7=g++-7 - os: osx env: - WXVERSION=pkg From dbec4e571cd179fd1cb70183b5547bc30781a8b8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 23:02:33 -0500 Subject: [PATCH 221/305] travis... --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f8d052928..0771c5bca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,9 +52,9 @@ matrix: include: - os: linux env: - - WXVERSION=pkg - - CC7=gcc-7 - - CXX7=g++-7 + - export WXVERSION=pkg + - export CC7=gcc-7 + - export CXX7=g++-7 - os: osx env: - WXVERSION=pkg From a38b215952b9f81ff5dd0c78b8950e95d5c521ce Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 23:03:50 -0500 Subject: [PATCH 222/305] don't trust travis to do anything intelligent with the language. --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0771c5bca..4974682db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -language: cpp +language: before_install: - sh package/linux/travis-decrypt-key env: @@ -53,8 +53,8 @@ matrix: - os: linux env: - export WXVERSION=pkg - - export CC7=gcc-7 - - export CXX7=g++-7 + - export CC=gcc-7 + - export CXX=g++-7 - os: osx env: - WXVERSION=pkg From 99dd8d0dd93980b1ffd3994907439c6d4e4a4ab4 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 23:05:06 -0500 Subject: [PATCH 223/305] generic build language. Can't trust anything Travis does w/r/t environment variables on its own --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4974682db..376639363 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -language: +language: generic before_install: - sh package/linux/travis-decrypt-key env: From 51bb96eb21e5ffefe040e2804ca10db19da55d62 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 23:10:13 -0500 Subject: [PATCH 224/305] ... --- .travis.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 376639363..9641aede6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ env: - BOOST_DIR=$HOME/boost_1_63_0 - SLIC3R_STATIC=1 script: - - if [ -z ${CXX7+x} ]; then export CXX=$CXX7; fi - - if [ -z ${CC7+x} ]; then export CC=$CC7; fi - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR src/ - make @@ -52,9 +50,9 @@ matrix: include: - os: linux env: - - export WXVERSION=pkg - - export CC=gcc-7 - - export CXX=g++-7 + - WXVERSION=pkg + - CC=gcc-7 + - CXX=g++-7 - os: osx env: - WXVERSION=pkg From 708c6d0b74b34915b53650bf0a0fc4cad2ba013f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 23:14:28 -0500 Subject: [PATCH 225/305] ... --- .travis.yml | 7 ++++--- package/linux/travis-setup.sh | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9641aede6..068843f22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: generic before_install: - sh package/linux/travis-decrypt-key -env: - - BOOST_DIR=$HOME/boost_1_63_0 - - SLIC3R_STATIC=1 script: - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR src/ @@ -53,9 +50,13 @@ matrix: - WXVERSION=pkg - CC=gcc-7 - CXX=g++-7 + - BOOST_DIR=$HOME/boost_1_63_0 + - SLIC3R_STATIC=1 - os: osx env: - WXVERSION=pkg + - BOOST_DIR=$HOME/boost_1_63_0 + - SLIC3R_STATIC=1 env: global: - secure: eEVRZNMv7FM6jrOU9iAFkDhWxFQ1WtHBEaObImcvtFUxy6vWSt3ehFFeTRouj3uHQAnbvUzziDyvPPm8/95alv5g/du8ML6YzzqKBKfazM0xQ7SF6R2DQL8lfFIp+RSV7T02byEP1f1g7Zva7xH9szIlDcSfU0pXW4KWbkBFMd8= diff --git a/package/linux/travis-setup.sh b/package/linux/travis-setup.sh index 79780609e..b8f4b28a9 100755 --- a/package/linux/travis-setup.sh +++ b/package/linux/travis-setup.sh @@ -11,12 +11,13 @@ if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then fi tar -C$HOME -xjf $CACHE/wx${WXVERSION}.tar.bz2 fi - if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then - echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" - curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 - fi + + if [ ! -e $CACHE/boost-compiled.tar.bz2 ]; then + echo "Downloading http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2 => $CACHE/boost-compiled.tar.bz2" + curl -L "http://www.siusgs.com/slic3r/buildserver/boost_1_63_0.built.gcc-4.9.4-buildserver.tar.bz2" -o $CACHE/boost-compiled.tar.bz2 + fi - tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 + tar -C$HOME -xjf $CACHE/boost-compiled.tar.bz2 elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then if [[ "$WXVERSION" != "pkg" ]]; then From b799516d00c9bdd9d8052d4ff374a61d28364425 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 23:24:16 -0500 Subject: [PATCH 226/305] squawk on osx failures now, as it should work. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 068843f22..5c5893b30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,5 +61,3 @@ env: global: - secure: eEVRZNMv7FM6jrOU9iAFkDhWxFQ1WtHBEaObImcvtFUxy6vWSt3ehFFeTRouj3uHQAnbvUzziDyvPPm8/95alv5g/du8ML6YzzqKBKfazM0xQ7SF6R2DQL8lfFIp+RSV7T02byEP1f1g7Zva7xH9szIlDcSfU0pXW4KWbkBFMd8= - secure: gj338h+qHGccTD/VQFmEJkqdg2McIe2pO0iZ4Ae9BvY5vxkIML4BpoYZQXQTqiAOETnUjlcknY9lx0hI/PfkDD9MSJc5BC/3fMYRCu3SgAclEwklWf9vvtodUeT69mtnZuw1zze1nTbExuOw2mepbqFjxKKMl+9l5oCz4O54fXU= - allow_failures: - - os: osx From ac80e2da7f1d50ed2f4e4cb4afc8c005ffa99baf Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 23:24:33 -0500 Subject: [PATCH 227/305] back to c++11 semantics for initialization. --- src/GUI/Dialogs/AboutDialog.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/GUI/Dialogs/AboutDialog.cpp b/src/GUI/Dialogs/AboutDialog.cpp index 745d53a7d..6cafde4ad 100644 --- a/src/GUI/Dialogs/AboutDialog.cpp +++ b/src/GUI/Dialogs/AboutDialog.cpp @@ -10,17 +10,17 @@ static void link_clicked(wxHtmlLinkEvent& e) AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3r"), wxDefaultPosition, wxSize(600, 460), wxCAPTION) { - auto hsizer = new wxBoxSizer(wxHORIZONTAL) ; + auto* hsizer {new wxBoxSizer(wxHORIZONTAL)} ; - auto vsizer = new wxBoxSizer(wxVERTICAL) ; + auto* vsizer {new wxBoxSizer(wxVERTICAL)} ; // logo - auto logo = new AboutDialogLogo(this); + auto* logo {new AboutDialogLogo(this)}; hsizer->Add(logo, 0, wxEXPAND | wxLEFT | wxRIGHT, 30); // title - auto title = new wxStaticText(this, -1, "Slic3r", wxDefaultPosition, wxDefaultSize); - auto title_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + auto* title { new wxStaticText(this, -1, "Slic3r", wxDefaultPosition, wxDefaultSize)}; + auto title_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)}; title_font.SetWeight(wxFONTWEIGHT_BOLD); title_font.SetFamily(wxFONTFAMILY_ROMAN); @@ -31,8 +31,8 @@ AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3 // version - auto version = new wxStaticText(this, -1, wxString("Version ") + wxString(SLIC3R_VERSION), wxDefaultPosition, wxDefaultSize); - auto version_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + auto* version {new wxStaticText(this, -1, wxString("Version ") + wxString(SLIC3R_VERSION), wxDefaultPosition, wxDefaultSize)}; + auto version_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; version_font.SetPointSize((the_os == OS::Windows ? 9 : 11)); version->SetFont(version_font); vsizer->Add(version, 0, wxALIGN_LEFT | wxBOTTOM, 10); @@ -54,7 +54,7 @@ AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3 << "Built on " << build_date << " at git version " << git_version << "." << "" << ""; - auto html = new wxHtmlWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_NEVER); + auto* html {new wxHtmlWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_NEVER)}; html->SetBorders(2); html->SetPage(text); @@ -83,13 +83,13 @@ AboutDialogLogo::AboutDialogLogo(wxWindow* parent) : void AboutDialogLogo::repaint(wxPaintEvent& event) { - wxPaintDC dc(this); + wxPaintDC dc {this}; dc.SetBackgroundMode(wxPENSTYLE_TRANSPARENT); - const wxSize size = this->GetSize() ; - const auto logo_w = this->logo.GetWidth(); - const auto logo_h = this->logo.GetHeight(); + const wxSize size {this->GetSize()} ; + const auto logo_w {this->logo.GetWidth()}; + const auto logo_h {this->logo.GetHeight()}; dc.DrawBitmap(this->logo, (size.GetWidth() - logo_w) / 2, (size.GetHeight() - logo_h) / 2, 1); event.Skip(); From 2348ff357994a175c9f1a807e31bc0411dcd368d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 14 May 2018 11:07:45 -0500 Subject: [PATCH 228/305] Only make linux distributables on linux. --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5c5893b30..6ec13380a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,12 +5,6 @@ script: - bash package/linux/travis-setup.sh - cmake -DBOOST_ROOT=$BOOST_DIR src/ - make -after_success: - - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 - - package/linux/appimage.sh x86_64 - - package/deploy/sftp.sh linux ~/slic3r-upload.rsa *.bz2 Slic3r*.AppImage - - package/deploy/sftp-symlink.sh linux ~/slic3r-upload.rsa AppImage Slic3r*.AppImage - - package/deploy/sftp-symlink.sh linux ~/slic3r-upload.rsa tar.bz2 *.bz2 branches: only: - master @@ -52,6 +46,12 @@ matrix: - CXX=g++-7 - BOOST_DIR=$HOME/boost_1_63_0 - SLIC3R_STATIC=1 + after_success: + - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 + - package/linux/appimage.sh x86_64 + - package/deploy/sftp.sh linux ~/slic3r-upload.rsa *.bz2 Slic3r*.AppImage + - package/deploy/sftp-symlink.sh linux ~/slic3r-upload.rsa AppImage Slic3r*.AppImage + - package/deploy/sftp-symlink.sh linux ~/slic3r-upload.rsa tar.bz2 *.bz2 - os: osx env: - WXVERSION=pkg From 4b3986a4ee0d1cfd8a3181d21d0ef63f83794ec3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 14 May 2018 11:08:09 -0500 Subject: [PATCH 229/305] Don't build xsgui --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6ec13380a..796eb151f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ script: branches: only: - master - - xsgui - cppgui cache: apt: true From 86fc28a7833fe119062038cac24400cdacfa99c5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 15 May 2018 14:15:43 -0500 Subject: [PATCH 230/305] Require boost. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5ccbc4335..6809eb6d3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,7 +47,7 @@ endif(DEFINED ENV{SLIC3R_STATIC}) find_package(Threads REQUIRED) -find_package(Boost COMPONENTS system thread filesystem) +find_package(Boost REQUIRED COMPONENTS system thread filesystem) set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/../xs/src/) set(GUI_LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/GUI/) From 3a0f5297a1b856b46ad3cf08ceef909050098cbe Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 15 May 2018 20:17:12 -0500 Subject: [PATCH 231/305] Stubbed in Plater menu. --- src/GUI/MainFrame.cpp | 30 ++++++++++++++++++++++++++++-- src/GUI/MainFrame.hpp | 8 ++++++++ src/GUI/Plater.cpp | 14 ++++++++------ src/GUI/Plater.hpp | 20 ++++++++++++++++++-- 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index e1facce0f..28fecd971 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -118,11 +118,37 @@ void MainFrame::init_menubar() append_menu_item(menuFile, _(L"Open STL/OBJ/AMF/3MF…"), _("Open a model"), [=](wxCommandEvent& e) { if (this->plater != nullptr) this->plater->add();}, wxID_ANY, "brick_add.png", "Ctrl+O"); } - wxMenu* menuPlater = new wxMenu(); + wxMenu* menuPlater = this->plater_menu = new wxMenu(); { - append_menu_item(menuPlater, _(L"Arrange…"), _("Arrange models on plater"), [this](wxCommandEvent& e) { if (this->plater != nullptr) this->plater->arrange();}, wxID_ANY, "bricks.png", "Ctrl+G"); + wxMenu* selectMenu = this->plater_select_menu = new wxMenu(); + append_submenu(menuPlater, _("Select"), _("Select an object in the plater"), selectMenu, wxID_ANY, "brick.png"); + append_menu_item(menuPlater, _("Undo"), _("Undo"), [this](wxCommandEvent& e) { this->plater->undo(); }, wxID_ANY, "arrow_undo.png", "Ctrl+Z"); + append_menu_item(menuPlater, _("Redo"), _("Redo"), [this](wxCommandEvent& e) { this->plater->redo(); }, wxID_ANY, "arrow_redo.png", "Ctrl+Shift+Z"); + append_menu_item(menuPlater, _("Select Next Object"), _("Select Next Object in the plater"), + [this](wxCommandEvent& e) { this->plater->select_next(); }, wxID_ANY, "arrow_right.png", "Ctrl+Right"); + append_menu_item(menuPlater, _("Select Prev Object"), _("Select Previous Object in the plater"), + [this](wxCommandEvent& e) { this->plater->select_prev(); }, wxID_ANY, "arrow_left.png", "Ctrl+Left"); + append_menu_item(menuPlater, _("Zoom In"), _("Zoom In"), + [this](wxCommandEvent& e) { this->plater->zoom(Zoom::In); }, wxID_ANY, "zoom_in.png", "Ctrl+Up"); + append_menu_item(menuPlater, _("Zoom Out"), _("Zoom Out"), + [this](wxCommandEvent& e) { this->plater->zoom(Zoom::In); }, wxID_ANY, "zoom_out.png", "Ctrl+Down"); + menuPlater->AppendSeparator(); + append_menu_item(menuPlater, _("Export G-code..."), _("Export current plate as G-code"), + [this](wxCommandEvent& e) { this->plater->export_gcode(); }, wxID_ANY, "cog_go.png"); + append_menu_item(menuPlater, _("Export plate as STL..."), _("Export current plate as STL"), + [this](wxCommandEvent& e) { this->plater->export_stl(); }, wxID_ANY, "brick_go.png"); + append_menu_item(menuPlater, _("Export plate with modifiers as AMF..."), _("Export current plate as AMF, including all modifier meshes"), + [this](wxCommandEvent& e) { this->plater->export_amf(); }, wxID_ANY, "brick_go.png"); + append_menu_item(menuPlater, _("Export plate with modifiers as 3MF..."), _("Export current plate as 3MF, including all modifier meshes"), + [this](wxCommandEvent& e) { this->plater->export_tmf(); }, wxID_ANY, "brick_go.png"); + + + } wxMenu* menuObject = this->plater->object_menu(); + this->on_plater_object_list_changed(false); + this->on_plater_selection_changed(false); + wxMenu* menuSettings = new wxMenu(); { } diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index 1838114bb..65b66649e 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -31,6 +31,9 @@ public: MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size); MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr _gui_config); ProgressStatusBar* statusbar {new ProgressStatusBar(this, -1)}; + + bool has_plater_menu() { return this->plater_menu != nullptr; } + wxMenu* plater_select_menu {nullptr}; private: wxDECLARE_EVENT_TABLE(); @@ -45,10 +48,15 @@ private: Controller* controller; Plater* plater; + wxMenu* plater_menu {nullptr}; + std::shared_ptr gui_config; std::map preset_editor_tabs; + void on_plater_object_list_changed(bool force) {}; + void on_plater_selection_changed(bool force) {}; + }; diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 051949ca2..a87c11177 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -278,7 +278,7 @@ std::vector Plater::load_file(const std::string file, const int obj_idx_to_ } progress_dialog->Destroy(); - this->redo = std::stack(); + this->_redo = std::stack(); return obj_idx; } @@ -482,13 +482,15 @@ void Plater::selection_changed() { auto obj = this->selected_object(); bool have_sel {obj != this->objects.end()}; - /* - if (my $menu = $self->GetFrame->{plater_select_menu}) { - $_->Check(0) for $menu->GetMenuItems; - if ($have_sel) { - $menu->FindItemByPosition($obj_idx)->Check(1); + auto* menu {this->GetFrame()->plater_select_menu}; + if (menu != nullptr) { + for (auto* item : menu->GetMenuItems()) { + item->Check(false); } + if (have_sel) + menu->FindItemByPosition(obj->identifier)->Check(true); } + /* my $method = $have_sel ? 'Enable' : 'Disable'; $self->{"btn_$_"}->$method diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index d6d5977f6..aafad916e 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -7,6 +7,7 @@ #include #include +#include #include @@ -34,6 +35,10 @@ enum class UndoCmd { Remove, Add, Reset, Increase, Decrease, Rotate }; +enum class Zoom { + In, Out +}; + using ObjIdx = unsigned int; using ObjRef = std::vector::iterator; @@ -76,6 +81,17 @@ public: /// Create menu for object. wxMenu* object_menu(); + void undo() {}; + void redo() {}; + + void select_next() {}; + void select_prev() {}; + void zoom(Zoom dir) {}; + + void export_gcode() {}; + void export_amf() {}; + void export_tmf() {}; + void export_stl() {}; private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; @@ -92,8 +108,8 @@ private: size_t object_identifier {0U}; //< Counter for adding objects to Slic3r. Increment after adding each object. - std::stack undo {}; - std::stack redo {}; + std::stack _undo {}; + std::stack _redo {}; wxNotebook* preview_notebook {new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(335,335), wxNB_BOTTOM)}; wxBoxSizer* right_sizer {new wxBoxSizer(wxVERTICAL)}; From 5f252f1848e871ae8f7499e2c2e115137519dffe Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 15 May 2018 20:59:46 -0500 Subject: [PATCH 232/305] Return the wxMenuItem* from append_menu_item, we do need it for some methods. --- src/GUI/misc_ui.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index e592618ea..79f6fd2dc 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -111,8 +111,8 @@ void fatal_error(wxWindow* parent, const wxString& message); void set_menu_item_icon(wxMenuItem* item, const wxString& icon); template -void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxString& icon = "", const wxString& accel = "") { - wxMenuItem* tmp = menu->Append(wxID_ANY, name, help); +wxMenuItem* append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxString& icon = "", const wxString& accel = "", const wxItemKind kind = wxITEM_NORMAL) { + wxMenuItem* tmp = menu->Append(wxID_ANY, name, help, kind); wxAcceleratorEntry* a = new wxAcceleratorEntry(); if (!accel.IsEmpty()) { a->FromString(accel); @@ -123,6 +123,8 @@ void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T if (typeid(lambda) != typeid(nullptr)) menu->Bind(wxEVT_MENU, lambda, tmp->GetId(), tmp->GetId()); + + return tmp; } wxMenuItem* append_submenu(wxMenu* menu, const wxString& name, const wxString& help, wxMenu* submenu, int id = wxID_ANY, const wxString& icon = ""); From a418521a604caf65133f9b82203049ae190a71cd Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 15 May 2018 21:00:34 -0500 Subject: [PATCH 233/305] Populate and set/unset select menu. --- src/GUI/Plater.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index a87c11177..eda744715 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -434,6 +434,28 @@ void Plater::arrange() { } void Plater::on_model_change(bool force_autocenter) { + + // reload the select submenu (if already initialized) + { + auto* menu = this->GetFrame()->plater_select_menu; + + if (menu != nullptr) { + for (auto* item : menu->GetMenuItems() ) { menu->Delete(item); } + for (const auto& obj : this->objects) { + const auto idx {obj.identifier}; + auto name {wxString(obj.name)}; + auto inst_count = this->model->objects.at(idx)->instances.size(); + if (inst_count > 1) { + name << " (" << inst_count << "x)"; + } + wxMenuItem* item {append_menu_item(menu, name, _("Select object."), + [this,idx](wxCommandEvent& e) { this->select_object(idx); this->refresh_canvases(); }, + wxID_ANY, "", "", wxITEM_CHECK)}; + if (obj.selected) item->Check(true); + } + } + } + if (force_autocenter || settings->autocenter) { this->model->center_instances_around_point(this->bed_centerf()); } @@ -484,8 +506,8 @@ void Plater::selection_changed() { bool have_sel {obj != this->objects.end()}; auto* menu {this->GetFrame()->plater_select_menu}; if (menu != nullptr) { - for (auto* item : menu->GetMenuItems()) { - item->Check(false); + for (auto item = menu->GetMenuItems().begin(); item != menu->GetMenuItems().end(); item++) { + (*item)->Check(false); } if (have_sel) menu->FindItemByPosition(obj->identifier)->Check(true); From 3d67cf03b8b388dd6d9ae8f602861231351f3c91 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 15 May 2018 21:01:04 -0500 Subject: [PATCH 234/305] Enable/disable toolbar on selection --- src/GUI/Plater.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index eda744715..ce68fdfde 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -512,6 +512,12 @@ void Plater::selection_changed() { if (have_sel) menu->FindItemByPosition(obj->identifier)->Check(true); } + + if (this->htoolbar != nullptr) { + for (auto tb : {TB_REMOVE, TB_MORE, TB_FEWER, TB_45CW, TB_45CCW, TB_SCALE, TB_SPLIT, TB_CUT, TB_LAYERS, TB_SETTINGS}) { + this->htoolbar->EnableTool(tb, have_sel); + } + } /* my $method = $have_sel ? 'Enable' : 'Disable'; From af041564fa2895321fafe48fe3feaf2d2dfa0da8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 15 May 2018 21:07:48 -0500 Subject: [PATCH 235/305] added comment to append_menu_item and append_submenu. --- src/GUI/misc_ui.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index 79f6fd2dc..dedfa8e4f 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -110,6 +110,10 @@ void fatal_error(wxWindow* parent, const wxString& message); /// Assign a menu item icon void set_menu_item_icon(wxMenuItem* item, const wxString& icon); +/// Construct a menu item for Slic3r, append it to a menu, and return it. +/// Automatically binds the lambda method to the event handler of the menu for this menu item's id. +/// Assign the accelerator separately if one is desired (instead of the \t interface in the name) +/// to permit translation. template wxMenuItem* append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxString& icon = "", const wxString& accel = "", const wxItemKind kind = wxITEM_NORMAL) { wxMenuItem* tmp = menu->Append(wxID_ANY, name, help, kind); @@ -127,6 +131,7 @@ wxMenuItem* append_menu_item(wxMenu* menu, const wxString& name,const wxString& return tmp; } +/// Construct and return a submenu to the menu, optionally with an icon. wxMenuItem* append_submenu(wxMenu* menu, const wxString& name, const wxString& help, wxMenu* submenu, int id = wxID_ANY, const wxString& icon = ""); /* From 910f95f01a66635045f3e781d90fcea39249a5fe Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 15 May 2018 22:26:39 -0500 Subject: [PATCH 236/305] added info box --- src/GUI/Plater.cpp | 63 ++++++++++++++++++++++++++++++++++++++++----- src/GUI/Plater.hpp | 29 +++++++++++++++++++++ src/GUI/misc_ui.hpp | 4 +++ 3 files changed, 90 insertions(+), 6 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index ce68fdfde..bb0898532 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -144,8 +144,63 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrSetMinSize(wxSize(350, -1)); + { + auto* sizer {new wxBoxSizer(wxHORIZONTAL)}; + object_info_sizer->Add(sizer, 0, wxEXPAND | wxBOTTOM, 5); + auto* text {new wxStaticText(this, wxID_ANY, _("Object:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT)}; + text->SetFont(small_font); + sizer->Add(text, 0, wxALIGN_CENTER_VERTICAL); + /* We supply a bogus width to wxChoice (sizer will override it and stretch + * the control anyway), because if we leave the default (-1) it will stretch + * too much according to the contents, and this is bad with long file names. + */ + this->object_info.choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(100, -1)); + this->object_info.choice->SetFont(small_font); + sizer->Add(this->object_info.choice, 1, wxALIGN_CENTER_VERTICAL); + // Select object on change. + this->Bind(wxEVT_CHOICE, [this](wxCommandEvent& e) { this->select_object(this->object_info.choice->GetSelection()); this->refresh_canvases();}); + + } + + auto* grid_sizer { new wxFlexGridSizer(3, 4, 5, 5)}; + grid_sizer->SetFlexibleDirection(wxHORIZONTAL); + grid_sizer->AddGrowableCol(1, 1); + grid_sizer->AddGrowableCol(3, 1); + + add_info_field(this, this->object_info.copies, _("Copies"), grid_sizer); + add_info_field(this, this->object_info.size, _("Size"), grid_sizer); + add_info_field(this, this->object_info.volume, _("Volume"), grid_sizer); + add_info_field(this, this->object_info.facets, _("Facets"), grid_sizer); + add_info_field(this, this->object_info.materials, _("Materials"), grid_sizer); + { + wxString name {"Manifold:"}; + auto* text {new wxStaticText(parent, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT)}; + text->SetFont(small_font); + grid_sizer->Add(text, 0); + + this->object_info.manifold = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + this->object_info.manifold->SetFont(small_font); + + this->object_info.manifold_warning_icon = new wxStaticBitmap(this, wxID_ANY, wxBitmap(var("error.png"), wxBITMAP_TYPE_PNG)); + this->object_info.manifold_warning_icon->Hide(); + + auto* h_sizer {new wxBoxSizer(wxHORIZONTAL)}; + h_sizer->Add(this->object_info.manifold_warning_icon, 0); + h_sizer->Add(this->object_info.manifold, 0); + + grid_sizer->Add(h_sizer, 0, wxEXPAND); + } + + object_info_sizer->Add(grid_sizer, 0, wxEXPAND); + } + this->selection_changed(); this->canvas2D->update_bed_size(); // Toolbar @@ -156,10 +211,11 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrright_sizer; + auto* right_sizer {this->right_sizer}; // $right_sizer->Add($presets, 0, wxEXPAND | wxTOP, 10) if defined $presets; // $right_sizer->Add($buttons_sizer, 0, wxEXPAND | wxBOTTOM, 5); // $right_sizer->Add($self->{settings_override_panel}, 1, wxEXPAND, 5); + right_sizer->Add(object_info_sizer, 0, wxEXPAND, 0); // $right_sizer->Add($object_info_sizer, 0, wxEXPAND, 0); // $right_sizer->Add($print_info_sizer, 0, wxEXPAND, 0); // $right_sizer->Hide($print_info_sizer); @@ -524,11 +580,6 @@ void Plater::selection_changed() { $self->{"btn_$_"}->$method for grep $self->{"btn_$_"}, qw(remove increase decrease rotate45cw rotate45ccw changescale split cut layers settings); - if ($self->{htoolbar}) { - $self->{htoolbar}->EnableTool($_, $have_sel) - for (TB_REMOVE, TB_MORE, TB_FEWER, TB_45CW, TB_45CCW, TB_SCALE, TB_SPLIT, TB_CUT, TB_LAYERS, TB_SETTINGS); - } - if ($self->{object_info_size}) { # have we already loaded the info pane? if ($have_sel) { diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index aafad916e..288764702 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -15,6 +15,7 @@ #include "Model.hpp" #include "Print.hpp" #include "Config.hpp" +#include "misc_ui.hpp" #include "Plater/PlaterObject.hpp" #include "Plater/Plate2D.hpp" @@ -46,6 +47,18 @@ class PlaterObject; class Plate2D; class MainFrame; +/// Struct to group object info text fields together +struct info_fields { + wxChoice* choice {nullptr}; + wxStaticText* copies {nullptr}; + wxStaticText* size {nullptr}; + wxStaticText* volume {nullptr}; + wxStaticText* facets {nullptr}; + wxStaticText* materials {nullptr}; + wxStaticText* manifold {nullptr}; + wxStaticBitmap* manifold_warning_icon {nullptr}; +}; + /// Extension of wxPanel class to handle the main plater. /// 2D, 3D, preview, etc tabs. class Plater : public wxPanel @@ -125,6 +138,8 @@ private: PreviewDLP* previewDLP {nullptr}; //< DLP/SLA Preview canvas + wxStaticBoxSizer* object_info_size {nullptr}; + /// Handles the actual load of the file from the dialog handoff. std::vector load_file(const std::string file, const int obj_idx_to_load = -1); @@ -223,9 +238,23 @@ private: void center_selected_object_on_bed(); void set_number_of_copies(); + + /// Struct containing various object info fields. + info_fields object_info; }; +template +static void add_info_field(wxWindow* parent, T*& field, wxString name, wxGridSizer* sizer) { + name << ":"; + auto* text {new wxStaticText(parent, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT)}; + text->SetFont(small_font); + sizer->Add(text, 0); + + field = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + field->SetFont(small_font); + sizer->Add(field, 0); +} } } // Namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index dedfa8e4f..40b3b4b81 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -6,6 +6,7 @@ #include #endif +#include #include #include #include @@ -50,6 +51,9 @@ constexpr bool isDev = false; constexpr bool threaded = false; +const wxFont small_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; + + // hopefully the compiler is smart enough to figure this out const std::map FILE_WILDCARDS { std::make_pair("known", "Known files (*.stl, *.obj, *.amf, *.xml, *.3mf)|*.3mf;*.3MF;*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML"), From 5f2fa5b5fbd828f0e39c123bb8d3c3da06e6ed92 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 17 May 2018 21:14:51 -0500 Subject: [PATCH 237/305] Add adv to build (support wxbitmapcombobox) --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6809eb6d3..9b096683b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -181,7 +181,7 @@ endif(${SLIC3R_STATIC}) set(wxWidgets_USE_UNICODE ON) -find_package(wxWidgets COMPONENTS net gl html aui core base) +find_package(wxWidgets COMPONENTS net gl html aui adv core base) IF(CMAKE_HOST_UNIX) #set(Boost_LIBRARIES bsystem bthread bfilesystem) From 7f485cd094602feb74d45d707e57114570a10ec3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 17 May 2018 21:19:20 -0500 Subject: [PATCH 238/305] Implemented callback system with a registration function that manipulates a stack. Stack access is protected by a mutex. Writes block until mutex is gotten, reads will try again later in event handler. --- src/GUI/GUI.cpp | 27 ++++++++++++++++++++++++++- src/GUI/GUI.hpp | 17 ++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index 9370e4afe..b72e7b84a 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -83,8 +83,24 @@ bool App::OnInit() && ($Settings->{_}{version_check} // 1) && (!$Settings->{_}{last_version_check} || (time - $Settings->{_}{last_version_check}) >= 86400); */ - + // run callback functions during idle on the main frame + this->Bind(wxEVT_IDLE, + [this](wxIdleEvent& e) { + std::function func {nullptr}; // + // try to get the mutex. If we can't, just skip this idle event and get the next one. + if (!this->callback_register.try_lock()) return; + // pop callback + if (cb.size() >= 1) { + func = cb.top(); + cb.pop(); + } + // unlock mutex + this->callback_register.unlock(); + try { // call the function if it's not nullptr; + if (func != nullptr) func(); + } catch (std::exception& e) { Slic3r::Log::error(LogChannel, LOG_WSTRING("Exception thrown: " << e.what())); } + }); /* EVT_IDLE($frame, sub { while (my $cb = shift @cb) { @@ -184,4 +200,13 @@ void App::load_presets() { */ } +void App::CallAfter(std::function cb_function) { + // set mutex + this->callback_register.lock(); + // push function onto stack + this->cb.emplace(cb_function); + // unset mutex + this->callback_register.unlock(); +} + }} // namespace Slic3r::GUI diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index 82c4b2082..83389bbf2 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -5,10 +5,13 @@ #include "Notifier.hpp" #include #include +#include +#include namespace Slic3r { namespace GUI { + // Friendly indices for the preset lists. enum class PresetID { PRINT = 0, @@ -29,6 +32,11 @@ public: /// Move/resize a named TopLevelWindow (includes Frames) from Settings void restore_window_pos(wxTopLevelWindow* window, const wxString& name ); + /// Function to add callback functions to the idle loop stack. + void CallAfter(std::function cb_function); + + + private: std::shared_ptr gui_config; // GUI-specific configuration options std::unique_ptr notifier {nullptr}; @@ -37,8 +45,15 @@ private: void load_presets(); wxString datadir {""}; - const std::string LogChannel {"GUI"}; //< Which log these messages should go to. + const std::string LogChannel {"APP"}; //< Which log these messages should go to. + + /// Lock to guard the callback stack + std::mutex callback_register; + + /// callbacks registered to run during idle event. + std::stack > cb {}; }; + }} // namespace Slic3r::GUI #endif // GUI_HPP From 43c4721c26b1cf750782620a09c118a2f15e2b2a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 17 May 2018 22:00:59 -0500 Subject: [PATCH 239/305] Added preset type enumeration --- src/GUI/Plater.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 288764702..8f52ce239 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -36,6 +36,14 @@ enum class UndoCmd { Remove, Add, Reset, Increase, Decrease, Rotate }; +/// Preset tab list +enum class preset_t : uint8_t { + Print = 0, Material, Printer, + Last // This MUST be the last enumeration. Don't use it for anything. +}; +/// Convenience counter to determine how many preset tabs exist. +constexpr size_t preset_count = static_cast(preset_t::Last); + enum class Zoom { In, Out }; From 27dc6870e4b59b3ecb986a4a31874468efc85aff Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 17 May 2018 22:01:48 -0500 Subject: [PATCH 240/305] working through UI for preset selector. --- src/GUI/Plater.cpp | 131 ++++++++++++++++++++++++++++++++++++++++++++- src/GUI/Plater.hpp | 15 ++++++ 2 files changed, 145 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index bb0898532..b6ae9efcf 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -144,6 +144,7 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrright_sizer}; -// $right_sizer->Add($presets, 0, wxEXPAND | wxTOP, 10) if defined $presets; + if (this->presets_sizer != nullptr) right_sizer->Add(this->presets_sizer, 0, wxEXPAND | wxTOP, 10); // $right_sizer->Add($buttons_sizer, 0, wxEXPAND | wxBOTTOM, 5); // $right_sizer->Add($self->{settings_override_panel}, 1, wxEXPAND, 5); right_sizer->Add(object_info_sizer, 0, wxEXPAND, 0); @@ -1063,6 +1064,134 @@ void Plater::center_selected_object_on_bed() { this->refresh_canvases(); } +void Plater::build_preset_chooser() { + this->presets_sizer = new wxFlexGridSizer(3,3,1,2); + auto& presets {this->presets_sizer}; // reference for local use + + presets->AddGrowableCol(1,1); + presets->SetFlexibleDirection(wxHORIZONTAL); + + this->preset_choosers.clear(); + for (auto group : { preset_t::Print, preset_t::Material, preset_t::Printer }) { + wxString name = ""; + switch(group) { + case preset_t::Print: + name << _("Print settings:"); + break; + case preset_t::Material: + name << _("Material:"); + break; + case preset_t::Printer: + name << _("Printer:"); + break; + default: + break; + } + auto* text {new wxStaticText(this, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT)}; + text->SetFont(small_font); + + auto* choice {new wxBitmapComboBox(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY)}; + this->preset_choosers[static_cast(group)] = choice; + + // setup listener. + // On a combobox event, puts a call to _on_change_combobox() on the evt_idle stack. + choice->Bind(wxEVT_COMBOBOX, + [=](wxCommandEvent& e) { + wxTheApp->CallAfter([=]() { this->_on_change_combobox(group, choice);} ); + }); + + // Settings button + auto* settings_btn {new wxBitmapButton(this, wxID_ANY, wxBitmap(var("cog.png"), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxDefaultSize, wxBORDER_NONE)}; + + settings_btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent& e) { + this->show_preset_editor(group, 0); + }); + + presets->Add(text, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxRIGHT, 4); + presets->Add(choice, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxBOTTOM, 0); + presets->Add(settings_btn, 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxLEFT, 3); + + } +/* + my %group_labels = ( + print => 'Print settings', + filament => 'Filament', + printer => 'Printer', + ); + $self->{preset_choosers} = {}; + $self->{preset_choosers_names} = {}; # wxChoice* => [] + for my $group (qw(print filament printer)) { + # label + my $text = Wx::StaticText->new($self, -1, "$group_labels{$group}:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); + $text->SetFont($Slic3r::GUI::small_font); + + # dropdown control + my $choice = Wx::BitmapComboBox->new($self, -1, "", wxDefaultPosition, wxDefaultSize, [], wxCB_READONLY); + $self->{preset_choosers}{$group} = [$choice]; + # setup the listener + EVT_COMBOBOX($choice, $choice, sub { + my ($choice) = @_; + wxTheApp->CallAfter(sub { + $self->_on_change_combobox($group, $choice); + }); + }); + + # settings button + my $settings_btn = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG), + wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); + EVT_BUTTON($self, $settings_btn, sub { + $self->show_preset_editor($group, 0); + }); + + $presets->Add($text, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxRIGHT, 4); + $presets->Add($choice, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxBOTTOM, 0); + $presets->Add($settings_btn, 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxLEFT, 3); + */ +} + +void Plater::_on_change_combobox(preset_t preset, wxBitmapComboBox* choice) { + + // Prompt for unsaved changes and undo selections if cancelled and return early + // Callback to close preset editor tab, close editor tabs, reload presets. + wxTheApp->CallAfter([=](){ + + this->_on_select_preset(preset); + // reload presets; removes the modified mark + this->load_presets(); + }); + /* + sub _on_change_combobox { + my ($self, $group, $choice) = @_; + + if (0) { + # This code is disabled because wxPerl doesn't provide GetCurrentSelection + my $current_name = $self->{preset_choosers_names}{$choice}[$choice->GetCurrentSelection]; + my $current = first { $_->name eq $current_name } @{wxTheApp->presets->{$group}}; + if (!$current->prompt_unsaved_changes($self)) { + # Restore the previous one + $choice->SetSelection($choice->GetCurrentSelection); + return; + } + } else { + return 0 if !$self->prompt_unsaved_changes; + } + wxTheApp->CallAfter(sub { + # Close the preset editor tab if any + if (exists $self->GetFrame->{preset_editor_tabs}{$group}) { + my $tabpanel = $self->GetFrame->{tabpanel}; + $tabpanel->DeletePage($tabpanel->GetPageIndex($self->GetFrame->{preset_editor_tabs}{$group})); + delete $self->GetFrame->{preset_editor_tabs}{$group}; + $tabpanel->SetSelection(0); # without this, a newly created tab will not be selected by wx + } + + $self->_on_select_preset($group); + + # This will remove the "(modified)" mark from any dirty preset handled here. + $self->load_presets; + }); +} +*/ +} }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 8f52ce239..712277975 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -249,6 +250,20 @@ private: /// Struct containing various object info fields. info_fields object_info; + + /// Build the preset chooser + void build_preset_chooser(); + + wxFlexGridSizer* presets_sizer {}; + + std::vector preset_choosers {preset_count, nullptr}; + void _on_change_combobox(preset_t preset, wxBitmapComboBox* choice); + + void show_preset_editor(preset_t preset, unsigned int idx) { }; + + void _on_select_preset(preset_t preset) {}; + void load_presets() {}; + }; From c5653a14352ed68608bbef303d84efc1ab723049 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 17 May 2018 22:36:43 -0500 Subject: [PATCH 241/305] Log otherwise uncaught exceptions so we have an idea where it came from. --- src/GUI/GUI.cpp | 7 +++++++ src/GUI/GUI.hpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index b72e7b84a..d31344810 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -209,4 +209,11 @@ void App::CallAfter(std::function cb_function) { this->callback_register.unlock(); } +void App::OnUnhandledException() { + try { throw; } + catch (std::exception &e) { + Slic3r::Log::fatal_error(LogChannel, LOG_WSTRING("Exception Caught: " << e.what())); + } +} + }} // namespace Slic3r::GUI diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index 83389bbf2..054acd001 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -36,6 +36,7 @@ public: void CallAfter(std::function cb_function); + void OnUnhandledException() override; private: std::shared_ptr gui_config; // GUI-specific configuration options From d74712ef7de0e651121151087daf8ce93bb56f22 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 21 May 2018 16:28:08 -0500 Subject: [PATCH 242/305] Moved Preset to its own header. --- src/GUI/GUI.hpp | 12 +++--------- src/GUI/Plater.cpp | 7 +++++++ src/GUI/Plater.hpp | 11 +++-------- src/GUI/Preset.hpp | 23 ++++++++++++++++++++++- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index 054acd001..96f18ca3b 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -9,17 +9,11 @@ #include +#include "Preset.hpp" + namespace Slic3r { namespace GUI { -// Friendly indices for the preset lists. -enum class PresetID { - PRINT = 0, - FILAMENT = 1, - PRINTER = 2 -}; -using preset_list = std::vector; - class App: public wxApp { public: @@ -41,7 +35,7 @@ public: private: std::shared_ptr gui_config; // GUI-specific configuration options std::unique_ptr notifier {nullptr}; - std::vector presets { preset_list(), preset_list(), preset_list() }; + std::vector presets { preset_types, Presets() }; void load_presets(); diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index b6ae9efcf..40d80fa99 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -1193,5 +1193,12 @@ void Plater::_on_change_combobox(preset_t preset, wxBitmapComboBox* choice) { */ } +void Plater::load_presets() { + + for (auto group : {preset_t::Printer, preset_t::Material, preset_t::Print}) { + // skip presets not compatible with selected printer + } +} + }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 712277975..11b8c9dfa 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -18,6 +18,8 @@ #include "Config.hpp" #include "misc_ui.hpp" +#include "Preset.hpp" + #include "Plater/PlaterObject.hpp" #include "Plater/Plate2D.hpp" #include "Plater/Plate3D.hpp" @@ -37,13 +39,6 @@ enum class UndoCmd { Remove, Add, Reset, Increase, Decrease, Rotate }; -/// Preset tab list -enum class preset_t : uint8_t { - Print = 0, Material, Printer, - Last // This MUST be the last enumeration. Don't use it for anything. -}; -/// Convenience counter to determine how many preset tabs exist. -constexpr size_t preset_count = static_cast(preset_t::Last); enum class Zoom { In, Out @@ -262,7 +257,7 @@ private: void show_preset_editor(preset_t preset, unsigned int idx) { }; void _on_select_preset(preset_t preset) {}; - void load_presets() {}; + void load_presets(); }; diff --git a/src/GUI/Preset.hpp b/src/GUI/Preset.hpp index e169c4827..826e6c05c 100644 --- a/src/GUI/Preset.hpp +++ b/src/GUI/Preset.hpp @@ -5,9 +5,30 @@ namespace Slic3r { namespace GUI { -class Preset { +/// Preset types list. We assign numbers to permit static_casts and use as preset tab indices +enum class preset_t : uint8_t { + Print = 0, Material, Printer, + Last // This MUST be the last enumeration. Don't use it for anything. +}; +/// Convenience counter to determine how many preset tabs exist. +constexpr size_t preset_types = static_cast(preset_t::Last); + +class Preset; + +using Presets = std::vector; + +class Preset { + preset_t type; + std::string name {""}; + + + /// Search the compatible_printers config option list for this preset name. + /// Assume that Printer configs are compatible with other Printer configs + bool compatible(std::string printer_name) { return true; } + bool compatible(const Preset& other) {return (this->type == preset_t::Printer || (compatible(other.name) && other.type == preset_t::Printer));} private: + /// store to keep config options for this preset Slic3r::DynamicPrintConfig config { Slic3r::DynamicPrintConfig() }; }; From e329a3ea88ecf443ba546bf3ca3d2bb4666b00c5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 21 May 2018 20:47:01 -0500 Subject: [PATCH 243/305] Require C++14 support for gui compile (because string literals are really really useful). --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b096683b..f7edd8b93 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,7 +31,7 @@ endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) set(CMAKE_INCLUDE_CURRENT_DIR ON) IF(CMAKE_HOST_APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++ -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE") set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework CoreFoundation -lc++") ELSE(CMAKE_HOST_APPLE) # set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -L.") @@ -216,7 +216,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp ) - target_compile_features(slic3r_gui PUBLIC cxx_std_11) + target_compile_features(slic3r_gui PUBLIC cxx_std_14) #only build GUI lib if building with wx target_link_libraries (slic3r slic3r_gui ${wxWidgets_LIBRARIES}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_WX") From 7cb17d4fb26d6994ca5152797bbe67cbdf3ddd82 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 21 May 2018 20:56:55 -0500 Subject: [PATCH 244/305] Stubbed out more of PresetEditor and Preset --- src/GUI/Plater.hpp | 2 +- src/GUI/Preset.hpp | 54 +++++++++++++++++++++++-- src/GUI/PresetEditor.hpp | 86 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 5 deletions(-) diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 11b8c9dfa..5c14f5f3a 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -251,7 +251,7 @@ private: wxFlexGridSizer* presets_sizer {}; - std::vector preset_choosers {preset_count, nullptr}; + std::vector preset_choosers {preset_types, nullptr}; void _on_change_combobox(preset_t preset, wxBitmapComboBox* choice); void show_preset_editor(preset_t preset, unsigned int idx) { }; diff --git a/src/GUI/Preset.hpp b/src/GUI/Preset.hpp index 826e6c05c..0aee6e6ef 100644 --- a/src/GUI/Preset.hpp +++ b/src/GUI/Preset.hpp @@ -2,6 +2,7 @@ #define PRESET_HPP #include "PrintConfig.hpp" +#include "Config.hpp" namespace Slic3r { namespace GUI { @@ -12,24 +13,69 @@ enum class preset_t : uint8_t { }; /// Convenience counter to determine how many preset tabs exist. -constexpr size_t preset_types = static_cast(preset_t::Last); +constexpr uint8_t preset(preset_t preset) { return static_cast(preset); } +constexpr size_t preset_types = preset(preset_t::Last); class Preset; using Presets = std::vector; class Preset { - preset_t type; + preset_t group; std::string name {""}; + /// Preset + bool default_preset {false}; /// Search the compatible_printers config option list for this preset name. /// Assume that Printer configs are compatible with other Printer configs bool compatible(std::string printer_name) { return true; } - bool compatible(const Preset& other) {return (this->type == preset_t::Printer || (compatible(other.name) && other.type == preset_t::Printer));} + bool compatible(const Preset& other) {return (this->group == preset_t::Printer || (compatible(other.name) && other.group == preset_t::Printer));} + + /// Format the name appropriately. + wxString dropdown_name() { return (this->dirty() ? wxString(this->name) << " " << _("(modified)") : this->name); } + + bool file_exists(wxString name); + + bool prompt_unsaved_changes(wxWindow* parent); + + /// Apply dirty config to config and save. + bool save(t_config_option_keys opt_keys); + + /// Apply dirty config to config and save with an alternate name. + bool save_as(wxString name, t_config_option_keys opt_keys); + + /// Delete this preset from the system. + void delete_preset(); + + /// Returns list of options that have been modified from the config. + t_config_option_keys dirty_options(); + + /// Returns whether or not this config is different from its modified state. + bool dirty(); + + /// Loads the selected config from file and return a reference. + Slic3r::Config& load_config(); + + /// Pass-through to Slic3r::Config, returns whether or not a config was loaded. + bool loaded() { return !this->config.empty(); } + + /// Clear the dirty config. + void dismiss_changes(); private: + bool external {false}; + /// store to keep config options for this preset - Slic3r::DynamicPrintConfig config { Slic3r::DynamicPrintConfig() }; + Slic3r::Config config { Slic3r::Config() }; + + /// Alternative config store for a modified configuration. + Slic3r::Config dirty_config {Slic3r::Config()}; + + std::string file {""}; + + /// reach through to the appropriate material type + t_config_option_keys _group_class(); + }; diff --git a/src/GUI/PresetEditor.hpp b/src/GUI/PresetEditor.hpp index 8d6359eab..6f7bfcc4d 100644 --- a/src/GUI/PresetEditor.hpp +++ b/src/GUI/PresetEditor.hpp @@ -1,11 +1,97 @@ #ifndef PRESETEDITOR_HPP #define PRESETEDITOR_HPP +#include + + namespace Slic3r { namespace GUI { +using namespace std::string_literals; class PresetEditor : public wxPanel { + /// Member function to retrieve a list of options + /// that this preset governs. Subclasses should + /// call their own static method. + virtual t_config_option_keys my_options() = 0; + static t_config_option_keys options() { return t_config_option_keys {}; } }; +class PrintEditor : public PresetEditor { +public: + + /// Static method to retrieve list of options that this preset governs. + static t_config_option_keys options() { + return t_config_option_keys + { + "layer_height"s, "first_layer_height"s, + "adaptive_slicing"s, "adaptive_slicing_quality"s, "match_horizontal_surfaces"s, + "perimeters"s, "spiral_vase"s, + "top_solid_layers"s, "bottom_solid_layers"s, + "extra_perimeters"s, "avoid_crossing_perimeters"s, "thin_walls"s, "overhangs"s, + "seam_position"s, "external_perimeters_first"s, + "fill_density"s, "fill_pattern"s, "top_infill_pattern"s, "bottom_infill_pattern"s, "fill_gaps"s, + "infill_every_layers"s, "infill_only_where_needed"s, + "solid_infill_every_layers"s, "fill_angle"s, "solid_infill_below_area"s, ""s, + "only_retract_when_crossing_perimeters"s, "infill_first"s, + "max_print_speed"s, "max_volumetric_speed"s, + "perimeter_speed"s, "small_perimeter_speed"s, "external_perimeter_speed"s, "infill_speed"s, ""s, + "solid_infill_speed"s, "top_solid_infill_speed"s, "support_material_speed"s, ""s, + "support_material_interface_speed"s, "bridge_speed"s, "gap_fill_speed"s, + "travel_speed"s, + "first_layer_speed"s, + "perimeter_acceleration"s, "infill_acceleration"s, "bridge_acceleration"s, ""s, + "first_layer_acceleration"s, "default_acceleration"s, + "skirts"s, "skirt_distance"s, "skirt_height"s, "min_skirt_length"s, + "brim_connections_width"s, "brim_width"s, "interior_brim_width"s, + "support_material"s, "support_material_threshold"s, "support_material_max_layers"s, "support_material_enforce_layers"s, + "raft_layers"s, + "support_material_pattern"s, "support_material_spacing"s, "support_material_angle"s, ""s, + "support_material_interface_layers"s, "support_material_interface_spacing"s, + "support_material_contact_distance"s, "support_material_buildplate_only"s, "dont_support_bridges"s, + "notes"s, + "complete_objects"s, "extruder_clearance_radius"s, "extruder_clearance_height"s, + "gcode_comments"s, "output_filename_format"s, + "post_process"s, + "perimeter_extruder"s, "infill_extruder"s, "solid_infill_extruder"s, + "support_material_extruder"s, "support_material_interface_extruder"s, + "ooze_prevention"s, "standby_temperature_delta"s, + "interface_shells"s, "regions_overlap"s, + "extrusion_width"s, "first_layer_extrusion_width"s, "perimeter_extrusion_width"s, ""s, + "external_perimeter_extrusion_width"s, "infill_extrusion_width"s, "solid_infill_extrusion_width"s, + "top_infill_extrusion_width"s, "support_material_extrusion_width"s, + "support_material_interface_extrusion_width"s, "infill_overlap"s, "bridge_flow_ratio"s, + "xy_size_compensation"s, "resolution"s, "shortcuts"s, "compatible_printers"s, + "print_settings_id"s + }; + } + + t_config_option_keys my_options() override { return PrintEditor::options(); } +}; + +class PrinterEditor : public PresetEditor { + + static t_config_option_keys options() { + return t_config_option_keys + { + "bed_shape"s, "z_offset"s, "z_steps_per_mm"s, "has_heatbed"s, + "gcode_flavor"s, "use_relative_e_distances"s, + "serial_port"s, "serial_speed"s, + "host_type"s, "print_host"s, "octoprint_apikey"s, + "use_firmware_retraction"s, "pressure_advance"s, "vibration_limit"s, + "use_volumetric_e"s, + "start_gcode"s, "end_gcode"s, "before_layer_gcode"s, "layer_gcode"s, "toolchange_gcode"s, "between_objects_gcode"s, + "nozzle_diameter"s, "extruder_offset"s, "min_layer_height"s, "max_layer_height"s, + "retract_length"s, "retract_lift"s, "retract_speed"s, "retract_restart_extra"s, "retract_before_travel"s, "retract_layer_change"s, "wipe"s, + "retract_length_toolchange"s, "retract_restart_extra_toolchange"s, "retract_lift_above"s, "retract_lift_below"s, + "printer_settings_id"s, + "printer_notes"s, + "use_set_and_wait_bed"s, "use_set_and_wait_extruder"s + }; + } + + t_config_option_keys my_options() override { return PrinterEditor::options(); } +}; + + }} // namespace Slic3r::GUI #endif // PRESETEDITOR_HPP From d20c0f48ca843d841a9675d04ef75a9939b366d9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 21 May 2018 22:01:35 -0500 Subject: [PATCH 245/305] workaround: avoid requiring c++14 just yet. --- src/CMakeLists.txt | 4 +- src/GUI/PresetEditor.hpp | 131 +++++++++++++++++++++++---------------- 2 files changed, 80 insertions(+), 55 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f7edd8b93..9b096683b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,7 +31,7 @@ endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) set(CMAKE_INCLUDE_CURRENT_DIR ON) IF(CMAKE_HOST_APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++ -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE") set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework CoreFoundation -lc++") ELSE(CMAKE_HOST_APPLE) # set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -L.") @@ -216,7 +216,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp ) - target_compile_features(slic3r_gui PUBLIC cxx_std_14) + target_compile_features(slic3r_gui PUBLIC cxx_std_11) #only build GUI lib if building with wx target_link_libraries (slic3r slic3r_gui ${wxWidgets_LIBRARIES}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_WX") diff --git a/src/GUI/PresetEditor.hpp b/src/GUI/PresetEditor.hpp index 6f7bfcc4d..03cb86d6d 100644 --- a/src/GUI/PresetEditor.hpp +++ b/src/GUI/PresetEditor.hpp @@ -2,10 +2,17 @@ #define PRESETEDITOR_HPP #include +#include "libslic3r.h" +#if SLIC3R_CPPVER==11 + #define st(A) (std::string(#A)) +#elif SLIC3R_CPPVER==14 + #define st(A) ((#A)s) +#endif + +// TODO for C++14 find/replace st([A-z_]*) with "\1"s namespace Slic3r { namespace GUI { -using namespace std::string_literals; class PresetEditor : public wxPanel { @@ -23,69 +30,87 @@ public: static t_config_option_keys options() { return t_config_option_keys { - "layer_height"s, "first_layer_height"s, - "adaptive_slicing"s, "adaptive_slicing_quality"s, "match_horizontal_surfaces"s, - "perimeters"s, "spiral_vase"s, - "top_solid_layers"s, "bottom_solid_layers"s, - "extra_perimeters"s, "avoid_crossing_perimeters"s, "thin_walls"s, "overhangs"s, - "seam_position"s, "external_perimeters_first"s, - "fill_density"s, "fill_pattern"s, "top_infill_pattern"s, "bottom_infill_pattern"s, "fill_gaps"s, - "infill_every_layers"s, "infill_only_where_needed"s, - "solid_infill_every_layers"s, "fill_angle"s, "solid_infill_below_area"s, ""s, - "only_retract_when_crossing_perimeters"s, "infill_first"s, - "max_print_speed"s, "max_volumetric_speed"s, - "perimeter_speed"s, "small_perimeter_speed"s, "external_perimeter_speed"s, "infill_speed"s, ""s, - "solid_infill_speed"s, "top_solid_infill_speed"s, "support_material_speed"s, ""s, - "support_material_interface_speed"s, "bridge_speed"s, "gap_fill_speed"s, - "travel_speed"s, - "first_layer_speed"s, - "perimeter_acceleration"s, "infill_acceleration"s, "bridge_acceleration"s, ""s, - "first_layer_acceleration"s, "default_acceleration"s, - "skirts"s, "skirt_distance"s, "skirt_height"s, "min_skirt_length"s, - "brim_connections_width"s, "brim_width"s, "interior_brim_width"s, - "support_material"s, "support_material_threshold"s, "support_material_max_layers"s, "support_material_enforce_layers"s, - "raft_layers"s, - "support_material_pattern"s, "support_material_spacing"s, "support_material_angle"s, ""s, - "support_material_interface_layers"s, "support_material_interface_spacing"s, - "support_material_contact_distance"s, "support_material_buildplate_only"s, "dont_support_bridges"s, - "notes"s, - "complete_objects"s, "extruder_clearance_radius"s, "extruder_clearance_height"s, - "gcode_comments"s, "output_filename_format"s, - "post_process"s, - "perimeter_extruder"s, "infill_extruder"s, "solid_infill_extruder"s, - "support_material_extruder"s, "support_material_interface_extruder"s, - "ooze_prevention"s, "standby_temperature_delta"s, - "interface_shells"s, "regions_overlap"s, - "extrusion_width"s, "first_layer_extrusion_width"s, "perimeter_extrusion_width"s, ""s, - "external_perimeter_extrusion_width"s, "infill_extrusion_width"s, "solid_infill_extrusion_width"s, - "top_infill_extrusion_width"s, "support_material_extrusion_width"s, - "support_material_interface_extrusion_width"s, "infill_overlap"s, "bridge_flow_ratio"s, - "xy_size_compensation"s, "resolution"s, "shortcuts"s, "compatible_printers"s, - "print_settings_id"s + st(layer_height), st(first_layer_height), + st(adaptive_slicing), st(adaptive_slicing_quality), st(match_horizontal_surfaces), + st(perimeters), st(spiral_vase), + st(top_solid_layers), st(bottom_solid_layers), + st(extra_perimeters), st(avoid_crossing_perimeters), st(thin_walls), st(overhangs), + st(seam_position), st(external_perimeters_first), + st(fill_density), st(fill_pattern), st(top_infill_pattern), st(bottom_infill_pattern), st(fill_gaps), + st(infill_every_layers), st(infill_only_where_needed), + st(solid_infill_every_layers), st(fill_angle), st(solid_infill_below_area), st(), + st(only_retract_when_crossing_perimeters), st(infill_first), + st(max_print_speed), st(max_volumetric_speed), + st(perimeter_speed), st(small_perimeter_speed), st(external_perimeter_speed), st(infill_speed), st(), + st(solid_infill_speed), st(top_solid_infill_speed), st(support_material_speed), + st(support_material_interface_speed), st(bridge_speed), st(gap_fill_speed), + st(travel_speed), + st(first_layer_speed), + st(perimeter_acceleration), st(infill_acceleration), st(bridge_acceleration), + st(first_layer_acceleration), st(default_acceleration), + st(skirts), st(skirt_distance), st(skirt_height), st(min_skirt_length), + st(brim_connections_width), st(brim_width), st(interior_brim_width), + st(support_material), st(support_material_threshold), st(support_material_max_layers), st(support_material_enforce_layers), + st(raft_layers), + st(support_material_pattern), st(support_material_spacing), st(support_material_angle), st(), + st(support_material_interface_layers), st(support_material_interface_spacing), + st(support_material_contact_distance), st(support_material_buildplate_only), st(dont_support_bridges), + st(notes), + st(complete_objects), st(extruder_clearance_radius), st(extruder_clearance_height), + st(gcode_comments), st(output_filename_format), + st(post_process), + st(perimeter_extruder), st(infill_extruder), st(solid_infill_extruder), + st(support_material_extruder), st(support_material_interface_extruder), + st(ooze_prevention), st(standby_temperature_delta), + st(interface_shells), st(regions_overlap), + st(extrusion_width), st(first_layer_extrusion_width), st(perimeter_extrusion_width), st(), + st(external_perimeter_extrusion_width), st(infill_extrusion_width), st(solid_infill_extrusion_width), + st(top_infill_extrusion_width), st(support_material_extrusion_width), + st(support_material_interface_extrusion_width), st(infill_overlap), st(bridge_flow_ratio), + st(xy_size_compensation), st(resolution), st(shortcuts), st(compatible_printers), + st(print_settings_id) }; } t_config_option_keys my_options() override { return PrintEditor::options(); } }; +class MaterialEditor : public PresetEditor { + + static t_config_option_keys options() { + return t_config_option_keys + { + st(filament_colour), st(filament_diameter), st(filament_notes), st(filament_max_volumetric_speed), st(extrusion_multiplier), st(filament_density), st(filament_cost), + st(temperature), st(first_layer_temperature), st(bed_temperature), st(first_layer_bed_temperature), + st(fan_always_on), st(cooling), st(compatible_printers), + st(min_fan_speed), st(max_fan_speed), st(bridge_fan_speed), st(disable_fan_first_layers), + st(fan_below_layer_time), st(slowdown_below_layer_time), st(min_print_speed), + st(start_filament_gcode), st(end_filament_gcode), + st(filament_settings_id) + }; + } + + t_config_option_keys my_options() override { return MaterialEditor::options(); } +}; + class PrinterEditor : public PresetEditor { static t_config_option_keys options() { return t_config_option_keys { - "bed_shape"s, "z_offset"s, "z_steps_per_mm"s, "has_heatbed"s, - "gcode_flavor"s, "use_relative_e_distances"s, - "serial_port"s, "serial_speed"s, - "host_type"s, "print_host"s, "octoprint_apikey"s, - "use_firmware_retraction"s, "pressure_advance"s, "vibration_limit"s, - "use_volumetric_e"s, - "start_gcode"s, "end_gcode"s, "before_layer_gcode"s, "layer_gcode"s, "toolchange_gcode"s, "between_objects_gcode"s, - "nozzle_diameter"s, "extruder_offset"s, "min_layer_height"s, "max_layer_height"s, - "retract_length"s, "retract_lift"s, "retract_speed"s, "retract_restart_extra"s, "retract_before_travel"s, "retract_layer_change"s, "wipe"s, - "retract_length_toolchange"s, "retract_restart_extra_toolchange"s, "retract_lift_above"s, "retract_lift_below"s, - "printer_settings_id"s, - "printer_notes"s, - "use_set_and_wait_bed"s, "use_set_and_wait_extruder"s + st(bed_shape), st(z_offset), st(z_steps_per_mm), st(has_heatbed), + st(gcode_flavor), st(use_relative_e_distances), + st(serial_port), st(serial_speed), + st(host_type), st(print_host), st(octoprint_apikey), + st(use_firmware_retraction), st(pressure_advance), st(vibration_limit), + st(use_volumetric_e), + st(start_gcode), st(end_gcode), st(before_layer_gcode), st(layer_gcode), st(toolchange_gcode), st(between_objects_gcode), + st(nozzle_diameter), st(extruder_offset), st(min_layer_height), st(max_layer_height), + st(retract_length), st(retract_lift), st(retract_speed), st(retract_restart_extra), st(retract_before_travel), st(retract_layer_change), st(wipe), + st(retract_length_toolchange), st(retract_restart_extra_toolchange), st(retract_lift_above), st(retract_lift_below), + st(printer_settings_id), + st(printer_notes), + st(use_set_and_wait_bed), st(use_set_and_wait_extruder) }; } From e83a6c47798aedb660c00805e2c047d6b3463992 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 4 Jun 2018 16:19:17 -0500 Subject: [PATCH 246/305] Changed small_font to be a function; avoids initialization segfault (calling wxSystemSettings before wx is initialized). --- src/GUI/Plater.cpp | 10 +++++----- src/GUI/Plater.hpp | 4 ++-- src/GUI/misc_ui.cpp | 2 ++ src/GUI/misc_ui.hpp | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 40d80fa99..83d937d41 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -154,7 +154,7 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrAdd(sizer, 0, wxEXPAND | wxBOTTOM, 5); auto* text {new wxStaticText(this, wxID_ANY, _("Object:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT)}; - text->SetFont(small_font); + text->SetFont(small_font()); sizer->Add(text, 0, wxALIGN_CENTER_VERTICAL); /* We supply a bogus width to wxChoice (sizer will override it and stretch @@ -162,7 +162,7 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrobject_info.choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(100, -1)); - this->object_info.choice->SetFont(small_font); + this->object_info.choice->SetFont(small_font()); sizer->Add(this->object_info.choice, 1, wxALIGN_CENTER_VERTICAL); // Select object on change. @@ -183,11 +183,11 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrSetFont(small_font); + text->SetFont(small_font()); grid_sizer->Add(text, 0); this->object_info.manifold = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); - this->object_info.manifold->SetFont(small_font); + this->object_info.manifold->SetFont(small_font()); this->object_info.manifold_warning_icon = new wxStaticBitmap(this, wxID_ANY, wxBitmap(var("error.png"), wxBITMAP_TYPE_PNG)); this->object_info.manifold_warning_icon->Hide(); @@ -1088,7 +1088,7 @@ void Plater::build_preset_chooser() { break; } auto* text {new wxStaticText(this, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT)}; - text->SetFont(small_font); + text->SetFont(small_font()); auto* choice {new wxBitmapComboBox(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY)}; this->preset_choosers[static_cast(group)] = choice; diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 5c14f5f3a..7dd226d89 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -266,11 +266,11 @@ template static void add_info_field(wxWindow* parent, T*& field, wxString name, wxGridSizer* sizer) { name << ":"; auto* text {new wxStaticText(parent, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT)}; - text->SetFont(small_font); + text->SetFont(small_font()); sizer->Add(text, 0); field = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); - field->SetFont(small_font); + field->SetFont(small_font()); sizer->Add(field, 0); } diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index 41c1f17f0..95febae57 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -147,5 +147,7 @@ std::vector open_model(wxWindow* parent, const Settings& settings, wxW return tmp; } +wxFont small_font() { return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); } + }} // namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index 40b3b4b81..cbf1e5134 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -51,8 +51,8 @@ constexpr bool isDev = false; constexpr bool threaded = false; -const wxFont small_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; - +/// Font definition +wxFont small_font(); // hopefully the compiler is smart enough to figure this out const std::map FILE_WILDCARDS { From 451d202be590c15b66085fc1abe6dc93c8164689 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 4 Jun 2018 16:25:06 -0500 Subject: [PATCH 247/305] Properly initialize the toolbar state on start --- src/GUI/Plater.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 83d937d41..77a213680 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -233,6 +233,9 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrSetSizeHints(this); this->SetSizer(sizer); + // Initialize the toolbar + this->selection_changed(); + } void Plater::add() { Log::info(LogChannel, L"Called Add function"); From 8eb7f952ea62713932a2b27358b3ba50d5fe7e99 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 4 Jun 2018 16:26:55 -0500 Subject: [PATCH 248/305] Moved PresetEditor into Dialogs subdir --- src/GUI/{ => Dialogs}/PresetEditor.hpp | 0 src/GUI/MainFrame.hpp | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/GUI/{ => Dialogs}/PresetEditor.hpp (100%) diff --git a/src/GUI/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp similarity index 100% rename from src/GUI/PresetEditor.hpp rename to src/GUI/Dialogs/PresetEditor.hpp diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index 65b66649e..d5a8ca61c 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -14,7 +14,7 @@ #include "Controller.hpp" #include "Plater.hpp" -#include "PresetEditor.hpp" +#include "Dialogs/PresetEditor.hpp" #include "Settings.hpp" #include "GUI.hpp" #include "ProgressStatusBar.hpp" From 832c0eb101ada04381fd261b9fbeeb1b57ba4bfa Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 5 Jun 2018 22:39:12 -0500 Subject: [PATCH 249/305] Stubbing out the various editors for print/material/printer --- src/CMakeLists.txt | 4 ++ src/GUI/Dialogs/MaterialEditor.cpp | 19 +++++++ src/GUI/Dialogs/PresetEditor.hpp | 88 +++++++++++++++++++++++++++++- src/GUI/Dialogs/PrintEditor.cpp | 19 +++++++ src/GUI/Dialogs/PrinterEditor.cpp | 19 +++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 src/GUI/Dialogs/MaterialEditor.cpp create mode 100644 src/GUI/Dialogs/PrintEditor.cpp create mode 100644 src/GUI/Dialogs/PrinterEditor.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b096683b..686cc3c2f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -207,6 +207,10 @@ IF(wxWidgets_FOUND) add_library(slic3r_gui STATIC ${GUI_LIBDIR}/Dialogs/AboutDialog.cpp + ${GUI_LIBDIR}/Dialogs/PresetEditor.cpp + ${GUI_LIBDIR}/Dialogs/PrintEditor.cpp + ${GUI_LIBDIR}/Dialogs/PrinterEditor.cpp + ${GUI_LIBDIR}/Dialogs/MaterialEditor.cpp ${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/Plater.cpp diff --git a/src/GUI/Dialogs/MaterialEditor.cpp b/src/GUI/Dialogs/MaterialEditor.cpp new file mode 100644 index 000000000..9ec877753 --- /dev/null +++ b/src/GUI/Dialogs/MaterialEditor.cpp @@ -0,0 +1,19 @@ +#include "Dialogs/PresetEditor.hpp" +namespace Slic3r { namespace GUI { + +MaterialEditor::MaterialEditor(wxWindow* parent, t_config_option_keys options) : + PresetEditor(parent, options) { + + this->config = Slic3r::Config::new_from_defaults(this->my_options()); + this->_update_tree(); + this->load_presets(); + this->_update(); + this->_build(); + } + +void MaterialEditor::_update() { +} + +void MaterialEditor::_build() { +} +}} // namespace Slic3r::GUI diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index 03cb86d6d..2c6544d92 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -1,8 +1,22 @@ #ifndef PRESETEDITOR_HPP #define PRESETEDITOR_HPP +// stdlib #include +#include + +// Libslic3r #include "libslic3r.h" +#include "ConfigBase.hpp" +#include "Config.hpp" + +// GUI +#include "misc_ui.hpp" + +// Wx +#include +#include +#include #if SLIC3R_CPPVER==11 #define st(A) (std::string(#A)) @@ -16,16 +30,66 @@ namespace Slic3r { namespace GUI { class PresetEditor : public wxPanel { +public: /// Member function to retrieve a list of options /// that this preset governs. Subclasses should /// call their own static method. virtual t_config_option_keys my_options() = 0; static t_config_option_keys options() { return t_config_option_keys {}; } + + wxSizer* sizer() { return _sizer; }; + PresetEditor(wxWindow* parent, t_config_option_keys options = {}); + PresetEditor() : PresetEditor(nullptr, {}) {}; + + bool prompt_unsaved_changes(); + void select_preset_by_name(const wxString& name, bool force = false); + + /// suppress the callback when the tree selection is changed. + bool disable_tree_sel_changed_event {false}; + + void save_preset(); + std::function on_save_preset {}; + std::function on_value_change {}; + + config_ptr config; + + virtual wxString title() = 0; + virtual std::string name() = 0; +protected: + // Main sizer + wxSizer* _sizer {nullptr}; + wxString presets; + wxImageList* _icons {nullptr}; + wxTreeCtrl* _treectrl {nullptr}; + wxBitmapButton* _btn_save_preset {nullptr}; + wxBitmapButton* _btn_delete_preset {nullptr}; + wxChoice* _presets_choice {nullptr}; + int _iconcount {-1}; + + std::vector _pages {}; + + const unsigned int left_col_width {150}; + void _update_tree(); + void load_presets(); + + virtual void _build() = 0; + virtual void _update() = 0; + virtual void _on_preset_loaded() = 0; + void set_tooltips() { + this->_btn_save_preset->SetToolTip(wxString(_("Save current ")) + this->title()); + this->_btn_delete_preset->SetToolTip(_("Delete this preset.")); + } }; class PrintEditor : public PresetEditor { public: + PrintEditor(wxWindow* parent, t_config_option_keys options = {}); + PrintEditor() : PrintEditor(nullptr, {}) {}; + + wxString title() override { return _("Print Settings"); } + std::string name() override { return st("print"); } + /// Static method to retrieve list of options that this preset governs. static t_config_option_keys options() { return t_config_option_keys @@ -73,10 +137,20 @@ public: } t_config_option_keys my_options() override { return PrintEditor::options(); } + +protected: + void _update() override; + void _build() override; }; class MaterialEditor : public PresetEditor { - +public: + + wxString title() override { return _("Material Settings"); } + std::string name() override { return st("material"); } + MaterialEditor(wxWindow* parent, t_config_option_keys options = {}); + MaterialEditor() : MaterialEditor(nullptr, {}) {}; + static t_config_option_keys options() { return t_config_option_keys { @@ -91,9 +165,18 @@ class MaterialEditor : public PresetEditor { } t_config_option_keys my_options() override { return MaterialEditor::options(); } +protected: + void _update() override; + void _build() override; }; class PrinterEditor : public PresetEditor { +public: + PrinterEditor(wxWindow* parent, t_config_option_keys options = {}); + PrinterEditor() : PrinterEditor(nullptr, {}) {}; + + wxString title() override { return _("Printer Settings"); } + std::string name() override { return st("printer"); } static t_config_option_keys options() { return t_config_option_keys @@ -115,6 +198,9 @@ class PrinterEditor : public PresetEditor { } t_config_option_keys my_options() override { return PrinterEditor::options(); } +protected: + void _update() override; + void _build() override; }; diff --git a/src/GUI/Dialogs/PrintEditor.cpp b/src/GUI/Dialogs/PrintEditor.cpp new file mode 100644 index 000000000..7a121c9fb --- /dev/null +++ b/src/GUI/Dialogs/PrintEditor.cpp @@ -0,0 +1,19 @@ +#include "Dialogs/PresetEditor.hpp" +namespace Slic3r { namespace GUI { + +PrintEditor::PrintEditor(wxWindow* parent, t_config_option_keys options) : + PresetEditor(parent, options) { + + this->config = Slic3r::Config::new_from_defaults(this->my_options()); + this->_update_tree(); + this->load_presets(); + this->_update(); + this->_build(); + } + +void PrintEditor::_update() { +} + +void PrintEditor::_build() { +} +}} // namespace Slic3r::GUI diff --git a/src/GUI/Dialogs/PrinterEditor.cpp b/src/GUI/Dialogs/PrinterEditor.cpp new file mode 100644 index 000000000..8143e9b26 --- /dev/null +++ b/src/GUI/Dialogs/PrinterEditor.cpp @@ -0,0 +1,19 @@ +#include "Dialogs/PresetEditor.hpp" +namespace Slic3r { namespace GUI { + +PrinterEditor::PrinterEditor(wxWindow* parent, t_config_option_keys options) : + PresetEditor(parent, options) { + + this->config = Slic3r::Config::new_from_defaults(this->my_options()); + this->_update_tree(); + this->load_presets(); + this->_update(); + this->_build(); + } + +void PrinterEditor::_update() { +} + +void PrinterEditor::_build() { +} +}} // namespace Slic3r::GUI From 109fdce8c8268da417ae158d20d2bc1d1418818f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 5 Jun 2018 22:39:48 -0500 Subject: [PATCH 250/305] refactored to accept a t_config_option_keys for initializer. --- xs/src/libslic3r/Config.cpp | 6 ++++++ xs/src/libslic3r/Config.hpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index d9f99cbbc..91e68cc40 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -10,6 +10,12 @@ Config::new_from_defaults() } std::shared_ptr Config::new_from_defaults(std::initializer_list init) +{ + return Config::new_from_defaults(t_config_option_keys(init)); +} + +std::shared_ptr +Config::new_from_defaults(t_config_option_keys init) { auto my_config(std::make_shared()); for (auto& opt_key : init) { diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index e2049cd32..f8c5e05a4 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -5,13 +5,18 @@ #include #include "PrintConfig.hpp" +#include "ConfigBase.hpp" namespace Slic3r { +class Config; +using config_ptr = std::shared_ptr; + class Config : public DynamicPrintConfig { public: static std::shared_ptr new_from_defaults(); static std::shared_ptr new_from_defaults(std::initializer_list init); + static std::shared_ptr new_from_defaults(t_config_option_keys init); static std::shared_ptr new_from_cli(const int& argc, const char* argv[]); void write_ini(const std::string& file) { save(file); } From f59b6bea42a5b507d95648e3277ae9e020776d38 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 6 Jun 2018 18:22:50 -0500 Subject: [PATCH 251/305] Committing PresetEditor.cpp --- src/GUI/Dialogs/PresetEditor.cpp | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/GUI/Dialogs/PresetEditor.cpp diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp new file mode 100644 index 000000000..0533fc911 --- /dev/null +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -0,0 +1,61 @@ +#include "Dialogs/PresetEditor.hpp" +#include "misc_ui.hpp" +#include + +namespace Slic3r { namespace GUI { + +PresetEditor::PresetEditor(wxWindow* parent, t_config_option_keys options) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL) { + + this->_sizer = new wxBoxSizer(wxHORIZONTAL); + this->SetSizer(this->_sizer); + + wxSizer* left_sizer { new wxBoxSizer(wxVERTICAL) }; + + { + // choice menu + this->_presets_choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(left_col_width, -1)); + this->_presets_choice->SetFont(small_font()); + + + // buttons + this->_btn_save_preset = new wxBitmapButton(this, wxID_ANY, wxBitmap(var("disk.png"), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); + this->_btn_delete_preset = new wxBitmapButton(this, wxID_ANY, wxBitmap(var("delete.png"), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); + + this->set_tooltips(); + this->_btn_delete_preset->Disable(); + + wxBoxSizer* hsizer {new wxBoxSizer(wxHORIZONTAL)}; + left_sizer->Add(hsizer, 0, wxEXPAND | wxBOTTOM, 5); + hsizer->Add(this->_presets_choice, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, 3); + hsizer->Add(this->_btn_save_preset, 0, wxALIGN_CENTER_VERTICAL); + hsizer->Add(this->_btn_delete_preset, 0, wxALIGN_CENTER_VERTICAL); + + } + + // tree + this->_treectrl = new wxTreeCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(left_col_width, -1), wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS); + + left_sizer->Add(this->_treectrl, 1, wxEXPAND); + this->_icons = new wxImageList(16, 16, 1); + this->_treectrl->AssignImageList(this->_icons); + this->_iconcount = - 1; + + this->_treectrl->AddRoot("root"); + this->_treectrl->SetIndent(0); + this->disable_tree_sel_changed_event = false; + + /// bind a lambda for the event EVT_TREE_SEL_CHANGED + + /// bind a lambda for the event EVT_KEY_DOWN + + /// bind a lambda for the event EVT_CHOICE + + /// bind a lambda for the event EVT_KEY_DOWN + + /// bind a lambda for the event EVT_BUTTON from btn_save_preset + + /// bind a lambda for the event EVT_BUTTON from btn_delete_preset + +} +}} // namespace Slic3r::GUI From ba4a3138974a948dd74085d6c7dffdaf288eaefe Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 6 Jun 2018 18:24:47 -0500 Subject: [PATCH 252/305] Build statically and build in a subdirectory. --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 796eb151f..e7cf20a43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,9 @@ before_install: - sh package/linux/travis-decrypt-key script: - bash package/linux/travis-setup.sh - - cmake -DBOOST_ROOT=$BOOST_DIR src/ - - make + - mkdir build && cd build + - cmake -DBOOST_ROOT=$BOOST_DIR -DSLIC3R_STATIC=1 ../src + - cmake --build . branches: only: - master @@ -44,8 +45,8 @@ matrix: - CC=gcc-7 - CXX=g++-7 - BOOST_DIR=$HOME/boost_1_63_0 - - SLIC3R_STATIC=1 after_success: + - cp slic3r ../ - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 - package/linux/appimage.sh x86_64 - package/deploy/sftp.sh linux ~/slic3r-upload.rsa *.bz2 Slic3r*.AppImage @@ -55,7 +56,6 @@ matrix: env: - WXVERSION=pkg - BOOST_DIR=$HOME/boost_1_63_0 - - SLIC3R_STATIC=1 env: global: - secure: eEVRZNMv7FM6jrOU9iAFkDhWxFQ1WtHBEaObImcvtFUxy6vWSt3ehFFeTRouj3uHQAnbvUzziDyvPPm8/95alv5g/du8ML6YzzqKBKfazM0xQ7SF6R2DQL8lfFIp+RSV7T02byEP1f1g7Zva7xH9szIlDcSfU0pXW4KWbkBFMd8= From 7cdeb7b45447aa9b4207518b17a6c8a81d82bdc6 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 20:48:45 -0500 Subject: [PATCH 253/305] Require C++14 for GUI --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 686cc3c2f..e252e72d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -220,7 +220,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp ) - target_compile_features(slic3r_gui PUBLIC cxx_std_11) + target_compile_features(slic3r_gui PUBLIC cxx_std_14) #only build GUI lib if building with wx target_link_libraries (slic3r slic3r_gui ${wxWidgets_LIBRARIES}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_WX") From bd359198044ea743118717b5f4b1ba4f8ce2522c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 21:00:17 -0500 Subject: [PATCH 254/305] Push GUI config/settings store out to a singleton unique_ptr that is instantiated during OnInit. --- src/GUI/Dialogs/PresetEditor.cpp | 2 +- src/GUI/GUI.cpp | 14 ++++++++------ src/GUI/GUI.hpp | 3 +-- src/GUI/MainFrame.cpp | 14 ++++++-------- src/GUI/MainFrame.hpp | 3 --- src/GUI/Plater.cpp | 14 +++++++------- src/GUI/Plater.hpp | 7 +++---- src/GUI/Plater/Plate2D.cpp | 8 ++++---- src/GUI/Plater/Plate2D.hpp | 4 +--- src/GUI/Plater/Preview2D.hpp | 4 +--- src/GUI/Plater/Preview3D.hpp | 4 +--- src/GUI/Plater/PreviewDLP.hpp | 4 +--- src/GUI/Settings.cpp | 13 +++++++++++++ src/GUI/Settings.hpp | 29 ++++++++++++++++++++++++++--- src/GUI/misc_ui.cpp | 2 -- src/GUI/misc_ui.hpp | 7 +++++-- 16 files changed, 78 insertions(+), 54 deletions(-) diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp index 0533fc911..b91f18935 100644 --- a/src/GUI/Dialogs/PresetEditor.cpp +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -15,7 +15,7 @@ PresetEditor::PresetEditor(wxWindow* parent, t_config_option_keys options) : { // choice menu this->_presets_choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(left_col_width, -1)); - this->_presets_choice->SetFont(small_font()); + this->_presets_choice->SetFont(ui_settings->small_font()); // buttons diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index d31344810..3a2bb3c11 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -10,6 +10,7 @@ #include "MainFrame.hpp" #include "GUI.hpp" #include "misc_ui.hpp" +#include "Settings.hpp" #include "Preset.hpp" // Logging mechanism @@ -48,6 +49,8 @@ bool App::OnInit() // TODO: Call a logging function with channel GUI, severity info for datadir path Slic3r::Log::info(LogChannel, (_("Data dir: ") + datadir).ToStdWstring()); + ui_settings = Settings::init_settings(); + // Load gui settings from slic3r.ini if (wxFileExists(slic3r_ini)) { /* @@ -62,15 +65,14 @@ bool App::OnInit() */ } - - this->gui_config->save_settings(); + ui_settings->save_settings(); // Load presets this->load_presets(); wxImage::AddHandler(new wxPNGHandler()); - MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize, this->gui_config); + MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize); this->SetTopWindow(frame); // Load init bundle @@ -135,18 +137,18 @@ bool App::OnInit() } void App::save_window_pos(const wxTopLevelWindow* window, const wxString& name ) { - this->gui_config->window_pos[name] = + ui_settings->window_pos[name] = std::make_tuple( window->GetScreenPosition(), window->GetSize(), window->IsMaximized()); - this->gui_config->save_settings(); + ui_settings->save_settings(); } void App::restore_window_pos(wxTopLevelWindow* window, const wxString& name ) { try { - auto tmp = gui_config->window_pos[name]; + auto tmp = ui_settings->window_pos[name]; const auto& size = std::get<1>(tmp); const auto& pos = std::get<0>(tmp); window->SetSize(size); diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index 96f18ca3b..d6e38f3b3 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -18,7 +18,7 @@ class App: public wxApp { public: virtual bool OnInit(); - App(std::shared_ptr config) : wxApp(), gui_config(config) {} + App() : wxApp() {} /// Save position, size, and maximize state for a TopLevelWindow (includes Frames) by name in Settings. void save_window_pos(const wxTopLevelWindow* window, const wxString& name ); @@ -33,7 +33,6 @@ public: void OnUnhandledException() override; private: - std::shared_ptr gui_config; // GUI-specific configuration options std::unique_ptr notifier {nullptr}; std::vector presets { preset_types, Presets() }; diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 28fecd971..dfad27820 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -13,10 +13,8 @@ wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) wxEND_EVENT_TABLE() MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) - : MainFrame(title, pos, size, nullptr) {} -MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr _gui_config) : wxFrame(NULL, wxID_ANY, title, pos, size), loaded(false), - tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(_gui_config), preset_editor_tabs(std::map()) + tabpanel(nullptr), controller(nullptr), plater(nullptr), preset_editor_tabs(std::map()) { this->SetIcon(wxIcon(var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG)); @@ -44,7 +42,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si this->SetMinSize(wxSize(760, 490)); this->SetSize(this->GetMinSize()); wxTheApp->SetTopWindow(this); - gui_config->restore_window_pos(this, "main_frame"); + ui_settings->restore_window_pos(this, "main_frame"); this->Show(); this->Layout(); } @@ -67,7 +65,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si */ // save window size - gui_config->save_window_pos(this, "main_frame"); + ui_settings->save_window_pos(this, "main_frame"); // Propagate event e.Skip(); @@ -87,7 +85,7 @@ void MainFrame::init_tabpanel() // TODO: trigger processing for activation event if (tabpanel->GetSelection() > 1) { tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); - } else if (this->gui_config->show_host == false && tabpanel->GetSelection() == 1) { + } else if (ui_settings->show_host == false && tabpanel->GetSelection() == 1) { tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); } else { tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | ~wxAUI_NB_CLOSE_ON_ACTIVE_TAB); @@ -102,11 +100,11 @@ void MainFrame::init_tabpanel() wxTheApp->CallAfter([=] { this->tabpanel->SetSelection(0); }); }), panel->GetId()); - this->plater = new Slic3r::GUI::Plater(panel, _("Plater"), gui_config); + this->plater = new Slic3r::GUI::Plater(panel, _("Plater")); this->controller = new Slic3r::GUI::Controller(panel, _("Controller")); panel->AddPage(this->plater, this->plater->GetName()); - if (this->gui_config->show_host) panel->AddPage(this->controller, this->controller->GetName()); + if (ui_settings->show_host) panel->AddPage(this->controller, this->controller->GetName()); } diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index d5a8ca61c..54f0bfdc9 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -29,7 +29,6 @@ class MainFrame: public wxFrame { public: MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size); - MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr _gui_config); ProgressStatusBar* statusbar {new ProgressStatusBar(this, -1)}; bool has_plater_menu() { return this->plater_menu != nullptr; } @@ -50,8 +49,6 @@ private: wxMenu* plater_menu {nullptr}; - - std::shared_ptr gui_config; std::map preset_editor_tabs; void on_plater_object_list_changed(bool force) {}; diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 77a213680..a5fe7de9a 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -35,8 +35,8 @@ const auto TB_SETTINGS {wxNewId()}; const auto PROGRESS_BAR_EVENT = wxNewEventType(); -Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title), settings(_settings) +Plater::Plater(wxWindow* parent, const wxString& title) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title) { // Set callback for status event for worker threads @@ -154,7 +154,7 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrAdd(sizer, 0, wxEXPAND | wxBOTTOM, 5); auto* text {new wxStaticText(this, wxID_ANY, _("Object:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT)}; - text->SetFont(small_font()); + text->SetFont(ui_settings->small_font()); sizer->Add(text, 0, wxALIGN_CENTER_VERTICAL); /* We supply a bogus width to wxChoice (sizer will override it and stretch @@ -162,7 +162,7 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrobject_info.choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(100, -1)); - this->object_info.choice->SetFont(small_font()); + this->object_info.choice->SetFont(ui_settings->small_font()); sizer->Add(this->object_info.choice, 1, wxALIGN_CENTER_VERTICAL); // Select object on change. @@ -183,11 +183,11 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrSetFont(small_font()); + text->SetFont(ui_settings->small_font()); grid_sizer->Add(text, 0); this->object_info.manifold = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); - this->object_info.manifold->SetFont(small_font()); + this->object_info.manifold->SetFont(ui_settings->small_font()); this->object_info.manifold_warning_icon = new wxStaticBitmap(this, wxID_ANY, wxBitmap(var("error.png"), wxBITMAP_TYPE_PNG)); this->object_info.manifold_warning_icon->Hide(); @@ -1091,7 +1091,7 @@ void Plater::build_preset_chooser() { break; } auto* text {new wxStaticText(this, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT)}; - text->SetFont(small_font()); + text->SetFont(ui_settings->small_font()); auto* choice {new wxBitmapComboBox(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY)}; this->preset_choosers[static_cast(group)] = choice; diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 7dd226d89..f4cd4dbdf 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -68,7 +68,7 @@ struct info_fields { class Plater : public wxPanel { public: - Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings); + Plater(wxWindow* parent, const wxString& title); /// User-level function called through external interface. /// Pops file dialog. @@ -112,7 +112,6 @@ public: private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; - std::shared_ptr settings {}; std::shared_ptr config { Slic3r::Config::new_from_defaults( {"bed_shape", "complete_objects", "extruder_clearance_radius", "skirts", "skirt_distance", @@ -266,11 +265,11 @@ template static void add_info_field(wxWindow* parent, T*& field, wxString name, wxGridSizer* sizer) { name << ":"; auto* text {new wxStaticText(parent, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT)}; - text->SetFont(small_font()); + text->SetFont(ui_settings->small_font()); sizer->Add(text, 0); field = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); - field->SetFont(small_font()); + field->SetFont(ui_settings->small_font()); sizer->Add(field, 0); } diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 05573b750..e83836adc 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -13,8 +13,8 @@ namespace Slic3r { namespace GUI { -Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) +Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) { this->Bind(wxEVT_PAINT, [this](wxPaintEvent &e) { this->repaint(e); }); @@ -56,8 +56,8 @@ void Plate2D::repaint(wxPaintEvent& e) { // On MacOS the background is erased, on Windows the background is not erased // and on Linux/GTK the background is erased to gray color. // Fill DC with the background on Windows & Linux/GTK. - const auto& brush_background {wxBrush(this->settings->color->BACKGROUND255(), wxBRUSHSTYLE_SOLID)}; - const auto& pen_background {wxPen(this->settings->color->BACKGROUND255(), 1, wxPENSTYLE_SOLID)}; + const auto& brush_background {wxBrush(ui_settings->color->BACKGROUND255(), wxBRUSHSTYLE_SOLID)}; + const auto& pen_background {wxPen(ui_settings->color->BACKGROUND255(), 1, wxPENSTYLE_SOLID)}; dc.SetPen(pen_background); dc.SetBrush(brush_background); const auto& rect {this->GetUpdateRegion().GetBox()}; diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 67bbd4a57..6cadf0b00 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -12,7 +12,6 @@ #include "ColorScheme.hpp" #include "Plater.hpp" #include "Plater/PlaterObject.hpp" -#include "Settings.hpp" #include "misc_ui.hpp" #include "Log.hpp" @@ -39,7 +38,7 @@ class Plate2D : public wxPanel { public: /// Constructor. Keeps a reference to the main configuration, the model, and the gui settings. - Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); + Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config); /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. void update_bed_size(); @@ -63,7 +62,6 @@ private: std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; - std::shared_ptr settings; /// Different brushes to draw with, initialized from settings->Color during the constructor wxBrush objects_brush {}; diff --git a/src/GUI/Plater/Preview2D.hpp b/src/GUI/Plater/Preview2D.hpp index 2a17b68da..a77239562 100644 --- a/src/GUI/Plater/Preview2D.hpp +++ b/src/GUI/Plater/Preview2D.hpp @@ -5,7 +5,6 @@ #include #endif -#include "Settings.hpp" #include "Model.hpp" #include "Config.hpp" @@ -14,7 +13,7 @@ namespace Slic3r { namespace GUI { class Preview2D : public wxPanel { public: void reload_print() {}; - Preview2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + Preview2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) {} @@ -23,7 +22,6 @@ private: std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; - std::shared_ptr settings; }; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Preview3D.hpp b/src/GUI/Plater/Preview3D.hpp index 49aa98c2d..3e2a66ab0 100644 --- a/src/GUI/Plater/Preview3D.hpp +++ b/src/GUI/Plater/Preview3D.hpp @@ -5,7 +5,6 @@ #include #endif -#include "Settings.hpp" #include "Model.hpp" #include "Config.hpp" @@ -14,7 +13,7 @@ namespace Slic3r { namespace GUI { class Preview3D : public wxPanel { public: void reload_print() {}; - Preview3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + Preview3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) {} @@ -23,7 +22,6 @@ private: std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; - std::shared_ptr settings; }; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/PreviewDLP.hpp b/src/GUI/Plater/PreviewDLP.hpp index 17b52cae5..c4d80b99c 100644 --- a/src/GUI/Plater/PreviewDLP.hpp +++ b/src/GUI/Plater/PreviewDLP.hpp @@ -5,7 +5,6 @@ #include #endif -#include "Settings.hpp" #include "Model.hpp" #include "Config.hpp" @@ -14,7 +13,7 @@ namespace Slic3r { namespace GUI { class PreviewDLP : public wxPanel { public: void reload_print() {}; - PreviewDLP(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + PreviewDLP(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) {} @@ -23,7 +22,6 @@ private: std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; - std::shared_ptr settings; }; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Settings.cpp b/src/GUI/Settings.cpp index 23d5808d5..a0e8fea55 100644 --- a/src/GUI/Settings.cpp +++ b/src/GUI/Settings.cpp @@ -1,7 +1,20 @@ #include "Settings.hpp" +#include "misc_ui.hpp" namespace Slic3r { namespace GUI { +void Settings::Settings() { + // Initialize fonts + _small_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + if (the_os == OS::Mac) _small_font.SetPointSize(11); + _small_bold_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + if (the_os == OS::Mac) _small_bold_font.SetPointSize(11); + _small_bold_font.MakeBold() + _medium_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + _medium_font.SetPointSize(12); + + _scroll_step = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)->GetPointSize(); +} void Settings::save_settings() { /* sub save_settings { diff --git a/src/GUI/Settings.hpp b/src/GUI/Settings.hpp index aaa9bd72b..d5b7b07be 100644 --- a/src/GUI/Settings.hpp +++ b/src/GUI/Settings.hpp @@ -6,6 +6,7 @@ #include #endif #include +#include #include #include "libslic3r.h" @@ -32,7 +33,7 @@ class Settings { bool invert_zoom {false}; bool background_processing {false}; - bool preset_editor_tabs {false}; + bool preset_editor_tabs {true}; bool hide_reload_dialog {false}; @@ -57,9 +58,31 @@ class Settings { void save_window_pos(wxWindow* ref, wxString name); void restore_window_pos(wxWindow* ref, wxString name); - private: - const std::string LogChannel {"GUI_Settings"}; //< Which log these messages should go to. + + const wxFont& small_font() { return _small_font;} + const wxFont& small_bold_font() { return _small_bold_font;} + const wxFont& medium_font() { return _medium_font;} + const int& scroll_step() { return _scroll_step; } + + static std::unique_ptr init_settings() { + return std::make_unique(); + } + Settings(Settings&&) = default; + Settings& operator=(Settings&&) = default; + Settings(); + private: + Settings& operator=(const Settings&) = default; + Settings(const Settings&) = default; + + const std::string LogChannel {"GUI_Settings"}; //< Which log these messages should go to. + + /// Fonts used by the UI. + wxFont _small_font; + wxFont _small_bold_font; + wxFont _medium_font; + + int _scroll_step {0}; }; }} //namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index 95febae57..41c1f17f0 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -147,7 +147,5 @@ std::vector open_model(wxWindow* parent, const Settings& settings, wxW return tmp; } -wxFont small_font() { return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); } - }} // namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index cbf1e5134..cc4d5e158 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "Settings.hpp" @@ -22,6 +23,7 @@ /// Avoids wx pollution of libslic3r #define LOG_WSTRING(...) ((wxString("") << __VA_ARGS__).ToStdWstring()) + /// Common static (that is, free-standing) functions, not part of an object hierarchy. namespace Slic3r { namespace GUI { @@ -51,8 +53,6 @@ constexpr bool isDev = false; constexpr bool threaded = false; -/// Font definition -wxFont small_font(); // hopefully the compiler is smart enough to figure this out const std::map FILE_WILDCARDS { @@ -152,6 +152,9 @@ std::vector open_model(wxWindow* parent, const Settings& settings, wxW inline Slic3r::Point new_scale(const wxPoint& p) { return Slic3r::Point::new_scale(p.x, p.y); } +/// Singleton for UI settings. +std::unique_ptr ui_settings {nullptr}; + }} // namespace Slic3r::GUI #endif // MISC_UI_HPP From 82836f1ec316007329423e50a1c250f6a619b742 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 21:31:42 -0500 Subject: [PATCH 255/305] Moved to C++14 syntax with string literals. --- src/GUI/Dialogs/PresetEditor.hpp | 183 ++++++++++++++++--------------- 1 file changed, 93 insertions(+), 90 deletions(-) diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index 2c6544d92..59051dd09 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -18,14 +18,7 @@ #include #include -#if SLIC3R_CPPVER==11 - #define st(A) (std::string(#A)) -#elif SLIC3R_CPPVER==14 - #define st(A) ((#A)s) -#endif - -// TODO for C++14 find/replace st([A-z_]*) with "\1"s - +using namespace std::string_literals; namespace Slic3r { namespace GUI { class PresetEditor : public wxPanel { @@ -88,51 +81,51 @@ public: PrintEditor() : PrintEditor(nullptr, {}) {}; wxString title() override { return _("Print Settings"); } - std::string name() override { return st("print"); } + std::string name() override { return "print"s; } /// Static method to retrieve list of options that this preset governs. static t_config_option_keys options() { return t_config_option_keys { - st(layer_height), st(first_layer_height), - st(adaptive_slicing), st(adaptive_slicing_quality), st(match_horizontal_surfaces), - st(perimeters), st(spiral_vase), - st(top_solid_layers), st(bottom_solid_layers), - st(extra_perimeters), st(avoid_crossing_perimeters), st(thin_walls), st(overhangs), - st(seam_position), st(external_perimeters_first), - st(fill_density), st(fill_pattern), st(top_infill_pattern), st(bottom_infill_pattern), st(fill_gaps), - st(infill_every_layers), st(infill_only_where_needed), - st(solid_infill_every_layers), st(fill_angle), st(solid_infill_below_area), st(), - st(only_retract_when_crossing_perimeters), st(infill_first), - st(max_print_speed), st(max_volumetric_speed), - st(perimeter_speed), st(small_perimeter_speed), st(external_perimeter_speed), st(infill_speed), st(), - st(solid_infill_speed), st(top_solid_infill_speed), st(support_material_speed), - st(support_material_interface_speed), st(bridge_speed), st(gap_fill_speed), - st(travel_speed), - st(first_layer_speed), - st(perimeter_acceleration), st(infill_acceleration), st(bridge_acceleration), - st(first_layer_acceleration), st(default_acceleration), - st(skirts), st(skirt_distance), st(skirt_height), st(min_skirt_length), - st(brim_connections_width), st(brim_width), st(interior_brim_width), - st(support_material), st(support_material_threshold), st(support_material_max_layers), st(support_material_enforce_layers), - st(raft_layers), - st(support_material_pattern), st(support_material_spacing), st(support_material_angle), st(), - st(support_material_interface_layers), st(support_material_interface_spacing), - st(support_material_contact_distance), st(support_material_buildplate_only), st(dont_support_bridges), - st(notes), - st(complete_objects), st(extruder_clearance_radius), st(extruder_clearance_height), - st(gcode_comments), st(output_filename_format), - st(post_process), - st(perimeter_extruder), st(infill_extruder), st(solid_infill_extruder), - st(support_material_extruder), st(support_material_interface_extruder), - st(ooze_prevention), st(standby_temperature_delta), - st(interface_shells), st(regions_overlap), - st(extrusion_width), st(first_layer_extrusion_width), st(perimeter_extrusion_width), st(), - st(external_perimeter_extrusion_width), st(infill_extrusion_width), st(solid_infill_extrusion_width), - st(top_infill_extrusion_width), st(support_material_extrusion_width), - st(support_material_interface_extrusion_width), st(infill_overlap), st(bridge_flow_ratio), - st(xy_size_compensation), st(resolution), st(shortcuts), st(compatible_printers), - st(print_settings_id) + "layer_height"s, "first_layer_height"s, + "adaptive_slicing"s, "adaptive_slicing_quality"s, "match_horizontal_surfaces"s, + "perimeters"s, "spiral_vase"s, + "top_solid_layers"s, "bottom_solid_layers"s, + "extra_perimeters"s, "avoid_crossing_perimeters"s, "thin_walls"s, "overhangs"s, + "seam_position"s, "external_perimeters_first"s, + "fill_density"s, "fill_pattern"s, "top_infill_pattern"s, "bottom_infill_pattern"s, "fill_gaps"s, + "infill_every_layers"s, "infill_only_where_needed"s, + "solid_infill_every_layers"s, "fill_angle"s, "solid_infill_below_area"s, ""s, + "only_retract_when_crossing_perimeters"s, "infill_first"s, + "max_print_speed"s, "max_volumetric_speed"s, + "perimeter_speed"s, "small_perimeter_speed"s, "external_perimeter_speed"s, "infill_speed"s, ""s, + "solid_infill_speed"s, "top_solid_infill_speed"s, "support_material_speed"s, + "support_material_interface_speed"s, "bridge_speed"s, "gap_fill_speed"s, + "travel_speed"s, + "first_layer_speed"s, + "perimeter_acceleration"s, "infill_acceleration"s, "bridge_acceleration"s, + "first_layer_acceleration"s, "default_acceleration"s, + "skirts"s, "skirt_distance"s, "skirt_height"s, "min_skirt_length"s, + "brim_connections_width"s, "brim_width"s, "interior_brim_width"s, + "support_material"s, "support_material_threshold"s, "support_material_max_layers"s, "support_material_enforce_layers"s, + "raft_layers"s, + "support_material_pattern"s, "support_material_spacing"s, "support_material_angle"s, ""s, + "support_material_interface_layers"s, "support_material_interface_spacing"s, + "support_material_contact_distance"s, "support_material_buildplate_only"s, "dont_support_bridges"s, + "notes"s, + "complete_objects"s, "extruder_clearance_radius"s, "extruder_clearance_height"s, + "gcode_comments"s, "output_filename_format"s, + "post_process"s, + "perimeter_extruder"s, "infill_extruder"s, "solid_infill_extruder"s, + "support_material_extruder"s, "support_material_interface_extruder"s, + "ooze_prevention"s, "standby_temperature_delta"s, + "interface_shells"s, "regions_overlap"s, + "extrusion_width"s, "first_layer_extrusion_width"s, "perimeter_extrusion_width"s, ""s, + "external_perimeter_extrusion_width"s, "infill_extrusion_width"s, "solid_infill_extrusion_width"s, + "top_infill_extrusion_width"s, "support_material_extrusion_width"s, + "support_material_interface_extrusion_width"s, "infill_overlap"s, "bridge_flow_ratio"s, + "xy_size_compensation"s, "resolution"s, "shortcuts"s, "compatible_printers"s, + "print_settings_id"s }; } @@ -143,57 +136,36 @@ protected: void _build() override; }; -class MaterialEditor : public PresetEditor { -public: - - wxString title() override { return _("Material Settings"); } - std::string name() override { return st("material"); } - MaterialEditor(wxWindow* parent, t_config_option_keys options = {}); - MaterialEditor() : MaterialEditor(nullptr, {}) {}; - - static t_config_option_keys options() { - return t_config_option_keys - { - st(filament_colour), st(filament_diameter), st(filament_notes), st(filament_max_volumetric_speed), st(extrusion_multiplier), st(filament_density), st(filament_cost), - st(temperature), st(first_layer_temperature), st(bed_temperature), st(first_layer_bed_temperature), - st(fan_always_on), st(cooling), st(compatible_printers), - st(min_fan_speed), st(max_fan_speed), st(bridge_fan_speed), st(disable_fan_first_layers), - st(fan_below_layer_time), st(slowdown_below_layer_time), st(min_print_speed), - st(start_filament_gcode), st(end_filament_gcode), - st(filament_settings_id) - }; - } - - t_config_option_keys my_options() override { return MaterialEditor::options(); } -protected: - void _update() override; - void _build() override; -}; - class PrinterEditor : public PresetEditor { public: PrinterEditor(wxWindow* parent, t_config_option_keys options = {}); PrinterEditor() : PrinterEditor(nullptr, {}) {}; wxString title() override { return _("Printer Settings"); } - std::string name() override { return st("printer"); } - + std::string name() override { return "printer"s; } + static t_config_option_keys overridable_options() { return t_config_option_keys + { + "pressure_advance"s, + "retract_length"s, "retract_lift"s, "retract_speed"s, "retract_restart_extra"s, + "retract_before_travel"s, "retract_layer_change"s, "wipe"s + }; }; + static t_config_option_keys options() { return t_config_option_keys { - st(bed_shape), st(z_offset), st(z_steps_per_mm), st(has_heatbed), - st(gcode_flavor), st(use_relative_e_distances), - st(serial_port), st(serial_speed), - st(host_type), st(print_host), st(octoprint_apikey), - st(use_firmware_retraction), st(pressure_advance), st(vibration_limit), - st(use_volumetric_e), - st(start_gcode), st(end_gcode), st(before_layer_gcode), st(layer_gcode), st(toolchange_gcode), st(between_objects_gcode), - st(nozzle_diameter), st(extruder_offset), st(min_layer_height), st(max_layer_height), - st(retract_length), st(retract_lift), st(retract_speed), st(retract_restart_extra), st(retract_before_travel), st(retract_layer_change), st(wipe), - st(retract_length_toolchange), st(retract_restart_extra_toolchange), st(retract_lift_above), st(retract_lift_below), - st(printer_settings_id), - st(printer_notes), - st(use_set_and_wait_bed), st(use_set_and_wait_extruder) + "bed_shape"s, "z_offset"s, "z_steps_per_mm"s, "has_heatbed"s, + "gcode_flavor"s, "use_relative_e_distances"s, + "serial_port"s, "serial_speed"s, + "host_type"s, "print_host"s, "octoprint_apikey"s, + "use_firmware_retraction"s, "pressure_advance"s, "vibration_limit"s, + "use_volumetric_e"s, + "start_gcode"s, "end_gcode"s, "before_layer_gcode"s, "layer_gcode"s, "toolchange_gcode"s, "between_objects_gcode"s, + "nozzle_diameter"s, "extruder_offset"s, "min_layer_height"s, "max_layer_height"s, + "retract_length"s, "retract_lift"s, "retract_speed"s, "retract_restart_extra"s, "retract_before_travel"s, "retract_layer_change"s, "wipe"s, + "retract_length_toolchange"s, "retract_restart_extra_toolchange"s, "retract_lift_above"s, "retract_lift_below"s, + "printer_settings_id"s, + "printer_notes"s, + "use_set_and_wait_bed"s, "use_set_and_wait_extruder"s }; } @@ -201,6 +173,37 @@ public: protected: void _update() override; void _build() override; + const std::string LogChannel() override {return "PrinterEditor"s;} //< Which log these messages should go to. +}; + +class MaterialEditor : public PresetEditor { +public: + + wxString title() override { return _("Material Settings"); } + std::string name() override { return "material"s; } + preset_t type() override { return preset_t::Material; }; + int typeId() override { return static_cast(preset_t::Material); }; + MaterialEditor(wxWindow* parent, t_config_option_keys options = {}); + MaterialEditor() : MaterialEditor(nullptr, {}) {}; + + static t_config_option_keys options() { + return t_config_option_keys + { + "filament_colour"s, "filament_diameter"s, "filament_notes"s, "filament_max_volumetric_speed"s, "extrusion_multiplier"s, "filament_density"s, "filament_cost"s, + "temperature"s, "first_layer_temperature"s, "bed_temperature"s, "first_layer_bed_temperature"s, + "fan_always_on"s, "cooling"s, "compatible_printers"s, + "min_fan_speed"s, "max_fan_speed"s, "bridge_fan_speed"s, "disable_fan_first_layers"s, + "fan_below_layer_time"s, "slowdown_below_layer_time"s, "min_print_speed"s, + "start_filament_gcode"s, "end_filament_gcode"s, + "filament_settings_id"s + }; + } + + t_config_option_keys my_options() override { return MaterialEditor::options(); } +protected: + void _update() override; + void _build() override; + const std::string LogChannel() override {return "MaterialEditor"s;} //< Which log these messages should go to. }; From a9b6946066e02902ba71b9fac5ac8109b96a54bf Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 21:32:22 -0500 Subject: [PATCH 256/305] Added overriding and overridable options. --- src/GUI/Dialogs/PresetEditor.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index 59051dd09..f39a5ad1f 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -30,6 +30,12 @@ public: virtual t_config_option_keys my_options() = 0; static t_config_option_keys options() { return t_config_option_keys {}; } + static t_config_option_keys overridable_options() { return t_config_option_keys {}; }; + static t_config_option_keys overriding_options() { return t_config_option_keys {}; }; + + virtual t_config_option_keys my_overridable_options() = 0; + virtual t_config_option_keys my_overriding_options() = 0; + wxSizer* sizer() { return _sizer; }; PresetEditor(wxWindow* parent, t_config_option_keys options = {}); PresetEditor() : PresetEditor(nullptr, {}) {}; @@ -83,6 +89,13 @@ public: wxString title() override { return _("Print Settings"); } std::string name() override { return "print"s; } + + t_config_option_keys my_overridable_options() override { return PresetEditor::overridable_options(); }; + static t_config_option_keys overridable_options() { return PresetEditor::overridable_options(); }; + + t_config_option_keys my_overriding_options() override { return PresetEditor::overriding_options(); }; + static t_config_option_keys overriding_options() { return PresetEditor::overriding_options(); }; + /// Static method to retrieve list of options that this preset governs. static t_config_option_keys options() { return t_config_option_keys @@ -149,7 +162,12 @@ public: "retract_length"s, "retract_lift"s, "retract_speed"s, "retract_restart_extra"s, "retract_before_travel"s, "retract_layer_change"s, "wipe"s }; }; + static t_config_option_keys overriding_options() { return PresetEditor::overriding_options(); }; + t_config_option_keys my_overridable_options() override { return PrinterEditor::overridable_options(); }; + t_config_option_keys my_overriding_options() override { return PrinterEditor::overriding_options(); }; + + static t_config_option_keys options() { return t_config_option_keys { @@ -186,6 +204,12 @@ public: MaterialEditor(wxWindow* parent, t_config_option_keys options = {}); MaterialEditor() : MaterialEditor(nullptr, {}) {}; + t_config_option_keys my_overridable_options() override { return PresetEditor::overridable_options(); }; + t_config_option_keys my_overriding_options() override { return PrinterEditor::overridable_options(); }; + + static t_config_option_keys overriding_options() { return PrinterEditor::overridable_options(); }; + static t_config_option_keys overridable_options() { return PresetEditor::overridable_options(); }; + static t_config_option_keys options() { return t_config_option_keys { From d8d7119f47356a3151c4c7b375a2a090d5cb96e6 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:06:49 -0500 Subject: [PATCH 257/305] pages is PresetPage, not wxString --- src/GUI/Dialogs/PresetEditor.hpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index f39a5ad1f..ec8ce6afc 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -21,6 +21,8 @@ using namespace std::string_literals; namespace Slic3r { namespace GUI { +class PresetPage; + class PresetEditor : public wxPanel { public: @@ -39,6 +41,7 @@ public: wxSizer* sizer() { return _sizer; }; PresetEditor(wxWindow* parent, t_config_option_keys options = {}); PresetEditor() : PresetEditor(nullptr, {}) {}; + std::shared_ptr current_preset; bool prompt_unsaved_changes(); void select_preset_by_name(const wxString& name, bool force = false); @@ -51,6 +54,7 @@ public: std::function on_value_change {}; config_ptr config; + PresetPage* add_options_page(const wxString& _title, const wxString& _icon = ""); virtual wxString title() = 0; virtual std::string name() = 0; @@ -65,8 +69,9 @@ protected: wxChoice* _presets_choice {nullptr}; int _iconcount {-1}; - std::vector _pages {}; - + /// Vector of PresetPage pointers; trust wxWidgets RTTI to avoid leaks + std::vector _pages {}; + const unsigned int left_col_width {150}; void _update_tree(); void load_presets(); @@ -231,5 +236,22 @@ protected: }; + + +class PresetPage : wxScrolledWindow { +public: + PresetPage(wxWindow* parent, wxString _title, int _iconID) : + wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + title(_title), iconID(_iconID) { + this->vsizer = new wxBoxSizer(wxVERTICAL); + this->SetSizer(this->vsizer); + this->SetScrollRate(ui_settings->scroll_step(), ui_settings->scroll_step()); + } +protected: + wxSizer* vsizer {nullptr}; + wxString title {""}; + int iconID {0}; +}; + }} // namespace Slic3r::GUI #endif // PRESETEDITOR_HPP From 97acd95341d10f6ececf37ebc025a65cdd26b763 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:07:16 -0500 Subject: [PATCH 258/305] Added comment for prompt_unsaved_changes --- src/GUI/Dialogs/PresetEditor.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index ec8ce6afc..bec6ed0a5 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -43,6 +43,7 @@ public: PresetEditor() : PresetEditor(nullptr, {}) {}; std::shared_ptr current_preset; + /// Check if there is a dirty config that is different than the loaded config. bool prompt_unsaved_changes(); void select_preset_by_name(const wxString& name, bool force = false); From 9d9781acd55533ce764fd6eb6eeb69822b2fb02b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:08:22 -0500 Subject: [PATCH 259/305] Made Preset methods public (as originally intended), added == for wxString and std::string to let std::find behave nicely. --- src/GUI/Preset.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/GUI/Preset.hpp b/src/GUI/Preset.hpp index 0aee6e6ef..fe28f430d 100644 --- a/src/GUI/Preset.hpp +++ b/src/GUI/Preset.hpp @@ -21,6 +21,7 @@ class Preset; using Presets = std::vector; class Preset { +public: preset_t group; std::string name {""}; @@ -62,6 +63,11 @@ class Preset { /// Clear the dirty config. void dismiss_changes(); + + void apply_dirty(const Slic3r::Config& other) { this->dirty_config.apply(other); } + void apply_dirty(const config_ptr& other) { this->apply_dirty(*other); } + bool operator==(const wxString& _name) const { return this->operator==(_name.ToStdString()); } + bool operator==(const std::string& _name) const { return _name.compare(this->name) == 0; } private: bool external {false}; From 2b6e64756e4ff78f792b146baa997dca590ffe2d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:17:25 -0500 Subject: [PATCH 260/305] finished removing local settings in favor of singleton ui_settings --- src/GUI/Plater/Plate3D.hpp | 6 ++---- src/GUI/Plater/Preview2D.hpp | 2 +- src/GUI/Plater/Preview3D.hpp | 2 +- src/GUI/Plater/PreviewDLP.hpp | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/GUI/Plater/Plate3D.hpp b/src/GUI/Plater/Plate3D.hpp index 7df04abcb..8e6814d25 100644 --- a/src/GUI/Plater/Plate3D.hpp +++ b/src/GUI/Plater/Plate3D.hpp @@ -4,7 +4,6 @@ #ifndef WX_PRECOMP #include #endif -#include "Settings.hpp" #include "Model.hpp" #include "Config.hpp" @@ -13,14 +12,13 @@ namespace Slic3r { namespace GUI { class Plate3D : public wxPanel { public: void update() {}; - Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) + Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) {} private: std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; - std::shared_ptr settings; }; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Preview2D.hpp b/src/GUI/Plater/Preview2D.hpp index a77239562..9ef459295 100644 --- a/src/GUI/Plater/Preview2D.hpp +++ b/src/GUI/Plater/Preview2D.hpp @@ -14,7 +14,7 @@ class Preview2D : public wxPanel { public: void reload_print() {}; Preview2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) {} void enabled(bool enable = true) {} diff --git a/src/GUI/Plater/Preview3D.hpp b/src/GUI/Plater/Preview3D.hpp index 3e2a66ab0..d2ec12b48 100644 --- a/src/GUI/Plater/Preview3D.hpp +++ b/src/GUI/Plater/Preview3D.hpp @@ -14,7 +14,7 @@ class Preview3D : public wxPanel { public: void reload_print() {}; Preview3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) {} void enabled(bool enable = true) {} diff --git a/src/GUI/Plater/PreviewDLP.hpp b/src/GUI/Plater/PreviewDLP.hpp index c4d80b99c..8de143174 100644 --- a/src/GUI/Plater/PreviewDLP.hpp +++ b/src/GUI/Plater/PreviewDLP.hpp @@ -14,7 +14,7 @@ class PreviewDLP : public wxPanel { public: void reload_print() {}; PreviewDLP(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) {} void enabled(bool enable = true) {} From d95d7f8d5500841b289caea1b8c58dc6f60dea38 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:19:36 -0500 Subject: [PATCH 261/305] Bring in Preset reference file --- src/GUI/Dialogs/PresetEditor.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index bec6ed0a5..9a05b0ce4 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -12,11 +12,13 @@ // GUI #include "misc_ui.hpp" +#include "Preset.hpp" // Wx #include #include #include +#include using namespace std::string_literals; namespace Slic3r { namespace GUI { From 93039e13fc3fecb07c83a75c54121d95e7631a96 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:20:57 -0500 Subject: [PATCH 262/305] Quick reference macro to GUI with the cast applied so access is available --- src/GUI/GUI.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index d6e38f3b3..30f913d14 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -49,5 +49,9 @@ private: }; +/// Quick reference to this app with its cast applied. +#define SLIC3RAPP dynamic_cast(wxTheApp) + + }} // namespace Slic3r::GUI #endif // GUI_HPP From 80bc61d833e687d4d9c75f49fc077217f435c1ff Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:24:06 -0500 Subject: [PATCH 263/305] Moved presets vector to public from private. --- src/GUI/GUI.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index 30f913d14..e18e073ff 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -32,9 +32,9 @@ public: void OnUnhandledException() override; + std::vector presets { preset_types, Presets() }; private: std::unique_ptr notifier {nullptr}; - std::vector presets { preset_types, Presets() }; void load_presets(); From 1b8e880c84426084ed3d6cde5f678cd775e87146 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:24:58 -0500 Subject: [PATCH 264/305] Added LogChannel interface function (pure virtual) to PresetEditor --- src/GUI/Dialogs/PresetEditor.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index 9a05b0ce4..6b26ab126 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -86,6 +86,9 @@ protected: this->_btn_save_preset->SetToolTip(wxString(_("Save current ")) + this->title()); this->_btn_delete_preset->SetToolTip(_("Delete this preset.")); } + virtual const std::string LogChannel() = 0; //< Which log these messages should go to. + + }; class PrintEditor : public PresetEditor { From f2d0dae35750a103d62cc13a42766905eca0705e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:25:44 -0500 Subject: [PATCH 265/305] Added more functions to PresetEditor interface --- src/GUI/Dialogs/PresetEditor.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index 6b26ab126..b40ed1fa0 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -57,10 +57,14 @@ public: std::function on_value_change {}; config_ptr config; + void reload_config(); + void reload_preset(); PresetPage* add_options_page(const wxString& _title, const wxString& _icon = ""); virtual wxString title() = 0; virtual std::string name() = 0; + virtual preset_t type() = 0; + virtual int typeId() = 0; protected: // Main sizer wxSizer* _sizer {nullptr}; @@ -86,6 +90,23 @@ protected: this->_btn_save_preset->SetToolTip(wxString(_("Save current ")) + this->title()); this->_btn_delete_preset->SetToolTip(_("Delete this preset.")); } + + + void reload_compatible_printers_widget(); + wxSizer* compatible_printers_widget(); + + /// This method is called: + /// - upon first initialization; + /// - whenever user selects a preset from the dropdown; + /// - whenever select_preset() or select_preset_by_name() are called. + void _on_select_preset(bool force = false); + + /// This method is supposed to be called whenever new values are loaded + /// or changed by the user (including when presets are loaded). + /// Pushes a callback onto the owning Slic3r app to be processed during + /// an idle event. + void _on_value_change(std::string opt_key); + virtual const std::string LogChannel() = 0; //< Which log these messages should go to. From 8e5d2595d6808ab0691ab49ac039b49b09a27954 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:26:21 -0500 Subject: [PATCH 266/305] Fixed signatures for on_save_preset and on_value_change function objects. --- src/GUI/Dialogs/PresetEditor.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index b40ed1fa0..a8ed24fc3 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -53,8 +53,8 @@ public: bool disable_tree_sel_changed_event {false}; void save_preset(); - std::function on_save_preset {}; - std::function on_value_change {}; + std::function on_save_preset {nullptr}; + std::function on_value_change {nullptr}; config_ptr config; void reload_config(); From 4fc9a09bc9185721b3e3422941b936b14c692536 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:26:51 -0500 Subject: [PATCH 267/305] Stubbed out more functions in PresetEditor --- src/GUI/Dialogs/PresetEditor.cpp | 61 ++++++++++++++++++++++++++++++++ src/GUI/Dialogs/PresetEditor.hpp | 4 +++ 2 files changed, 65 insertions(+) diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp index b91f18935..bc9dfcdf7 100644 --- a/src/GUI/Dialogs/PresetEditor.cpp +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -58,4 +58,65 @@ PresetEditor::PresetEditor(wxWindow* parent, t_config_option_keys options) : /// bind a lambda for the event EVT_BUTTON from btn_delete_preset } + +void PresetEditor::save_preset() { +} + + +/// TODO: Can this get deleted before the callback executes? +void PresetEditor::_on_value_change(std::string opt_key) { + SLIC3RAPP->CallAfter( + [this, opt_key]() { + this->current_preset->apply_dirty(this->config); + if (this->on_value_change != nullptr) this->on_value_change(opt_key); + this->load_presets(); + this->_update(opt_key); + } ); +} + +void PresetEditor::select_preset(int id, bool force) { + this->_presets_choice->SetSelection(id); + this->_on_select_preset(force); +} + +// TODO +void PresetEditor::delete_preset() { +} + +void PresetEditor::select_preset_by_name(const wxString& name, bool force) { + const auto presets {SLIC3RAPP->presets.at(this->typeId())}; + int id = -1; + auto result = std::find(presets.cbegin(), presets.cend(), name); + if (result != presets.cend()) id = std::distance(presets.cbegin(), result); + if (id == -1) { + Slic3r::Log::warn(this->LogChannel(), LOG_WSTRING("No preset named" + name)); + return; + } + this->_presets_choice->SetSelection(id); + this->_on_select_preset(force); +} + +PresetPage* PresetEditor::add_options_page(wxString _title, wxString _icon) { + + if (_icon.size() > 0) { + auto* bitmap { new wxBitmap(var(_icon), wxBITMAPT_TYPE_PNG); + this->_icons.Add(bitmap); + this->_iconcount += 1; + } + + PresetPage* page {new PresetPage(this, _title, this->_iconcount)}; + page->Hide(); + this->sizer->Add(page, 1, wxEXPAND | wxLEFT, 5); + _pages.push_back(page); + return page; +} + +// TODO +void PresetEditor::reload_config() { +} + +// TODO +void PresetEditor::reload_preset() { +} + }} // namespace Slic3r::GUI diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index a8ed24fc3..d17626fc0 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -47,6 +47,10 @@ public: /// Check if there is a dirty config that is different than the loaded config. bool prompt_unsaved_changes(); + + /// Perform a preset selection and possibly trigger the _on_select_preset + /// method. + void select_preset(int id, bool force = false); void select_preset_by_name(const wxString& name, bool force = false); /// suppress the callback when the tree selection is changed. From c70ecd68bafbf27258f63966fe70ff56a4c7d763 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:35:15 -0500 Subject: [PATCH 268/305] Add GUI.hpp to include list. --- src/GUI/Dialogs/PresetEditor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp index bc9dfcdf7..be32c47c3 100644 --- a/src/GUI/Dialogs/PresetEditor.cpp +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -1,5 +1,6 @@ #include "Dialogs/PresetEditor.hpp" #include "misc_ui.hpp" +#include "GUI.hpp" #include namespace Slic3r { namespace GUI { From 9e068d5d659b9c1526245f6d878cac722a676e6b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:36:58 -0500 Subject: [PATCH 269/305] Match prototype for add_options_page --- src/GUI/Dialogs/PresetEditor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp index be32c47c3..5639e3e8d 100644 --- a/src/GUI/Dialogs/PresetEditor.cpp +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -97,7 +97,7 @@ void PresetEditor::select_preset_by_name(const wxString& name, bool force) { this->_on_select_preset(force); } -PresetPage* PresetEditor::add_options_page(wxString _title, wxString _icon) { +PresetPage* PresetEditor::add_options_page(const wxString& _title, const wxString& _icon) { if (_icon.size() > 0) { auto* bitmap { new wxBitmap(var(_icon), wxBITMAPT_TYPE_PNG); From cbc026e4edb7f69a55d318ae361b44ec7ab92acb Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:46:12 -0500 Subject: [PATCH 270/305] Update now takes an argument, added accessor functions to get the type as both a preset enum and integer (index into vector) Stubbed in more functions. --- src/GUI/Dialogs/PresetEditor.hpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index d17626fc0..372582bae 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -88,8 +88,9 @@ protected: void load_presets(); virtual void _build() = 0; - virtual void _update() = 0; + virtual void _update(const std::string& opt_key = "") = 0; virtual void _on_preset_loaded() = 0; + void set_tooltips() { this->_btn_save_preset->SetToolTip(wxString(_("Save current ")) + this->title()); this->_btn_delete_preset->SetToolTip(_("Delete this preset.")); @@ -125,6 +126,8 @@ public: wxString title() override { return _("Print Settings"); } std::string name() override { return "print"s; } + preset_t type() override { return preset_t::Print; }; + int typeId() override { return static_cast(preset_t::Print); }; t_config_option_keys my_overridable_options() override { return PresetEditor::overridable_options(); }; static t_config_option_keys overridable_options() { return PresetEditor::overridable_options(); }; @@ -181,8 +184,11 @@ public: t_config_option_keys my_options() override { return PrintEditor::options(); } protected: - void _update() override; + void _update(const std::string& opt_key = "") override; void _build() override; + void _on_preset_loaded() override; + const std::string LogChannel() override {return "PrintEditor"s; } //< Which log these messages should go to. + }; class PrinterEditor : public PresetEditor { @@ -192,6 +198,9 @@ public: wxString title() override { return _("Printer Settings"); } std::string name() override { return "printer"s; } + preset_t type() override { return preset_t::Printer; }; + int typeId() override { return static_cast(preset_t::Printer); }; + static t_config_option_keys overridable_options() { return t_config_option_keys { "pressure_advance"s, @@ -225,8 +234,9 @@ public: t_config_option_keys my_options() override { return PrinterEditor::options(); } protected: - void _update() override; + void _update(const std::string& opt_key = "") override; void _build() override; + void _on_preset_loaded() override; const std::string LogChannel() override {return "PrinterEditor"s;} //< Which log these messages should go to. }; @@ -261,8 +271,9 @@ public: t_config_option_keys my_options() override { return MaterialEditor::options(); } protected: - void _update() override; + void _update(const std::string& opt_key = "") override; void _build() override; + void _on_preset_loaded() override; const std::string LogChannel() override {return "MaterialEditor"s;} //< Which log these messages should go to. }; From e9df376f9bb040072a351c615ebe8ab24e624ae7 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 22:50:52 -0500 Subject: [PATCH 271/305] Fixed some typos, working on getting code to build. --- src/GUI/Dialogs/PresetEditor.cpp | 13 +++++-------- src/GUI/Dialogs/PresetEditor.hpp | 2 +- src/GUI/Dialogs/PrintEditor.cpp | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp index 5639e3e8d..dfe7fe796 100644 --- a/src/GUI/Dialogs/PresetEditor.cpp +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -3,6 +3,7 @@ #include "GUI.hpp" #include + namespace Slic3r { namespace GUI { PresetEditor::PresetEditor(wxWindow* parent, t_config_option_keys options) : @@ -40,7 +41,7 @@ PresetEditor::PresetEditor(wxWindow* parent, t_config_option_keys options) : left_sizer->Add(this->_treectrl, 1, wxEXPAND); this->_icons = new wxImageList(16, 16, 1); this->_treectrl->AssignImageList(this->_icons); - this->_iconcount = - 1; + this->_iconcount = -1; this->_treectrl->AddRoot("root"); this->_treectrl->SetIndent(0); @@ -80,10 +81,6 @@ void PresetEditor::select_preset(int id, bool force) { this->_on_select_preset(force); } -// TODO -void PresetEditor::delete_preset() { -} - void PresetEditor::select_preset_by_name(const wxString& name, bool force) { const auto presets {SLIC3RAPP->presets.at(this->typeId())}; int id = -1; @@ -100,14 +97,14 @@ void PresetEditor::select_preset_by_name(const wxString& name, bool force) { PresetPage* PresetEditor::add_options_page(const wxString& _title, const wxString& _icon) { if (_icon.size() > 0) { - auto* bitmap { new wxBitmap(var(_icon), wxBITMAPT_TYPE_PNG); - this->_icons.Add(bitmap); + auto* bitmap { new wxBitmap(var(_icon), wxBITMAP_TYPE_PNG); + this->_icons->Add(bitmap); this->_iconcount += 1; } PresetPage* page {new PresetPage(this, _title, this->_iconcount)}; page->Hide(); - this->sizer->Add(page, 1, wxEXPAND | wxLEFT, 5); + this->_sizer->Add(page, 1, wxEXPAND | wxLEFT, 5); _pages.push_back(page); return page; } diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index 372582bae..a6046c10b 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -280,7 +280,7 @@ protected: -class PresetPage : wxScrolledWindow { +class PresetPage : public wxScrolledWindow { public: PresetPage(wxWindow* parent, wxString _title, int _iconID) : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), diff --git a/src/GUI/Dialogs/PrintEditor.cpp b/src/GUI/Dialogs/PrintEditor.cpp index 7a121c9fb..2ddb26c73 100644 --- a/src/GUI/Dialogs/PrintEditor.cpp +++ b/src/GUI/Dialogs/PrintEditor.cpp @@ -11,7 +11,7 @@ PrintEditor::PrintEditor(wxWindow* parent, t_config_option_keys options) : this->_build(); } -void PrintEditor::_update() { +void PrintEditor::_update(const std::string& opt_key) { } void PrintEditor::_build() { From 759428fef75346b1d48985162a6748e67b02449d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 23:00:34 -0500 Subject: [PATCH 272/305] Fixed how bitmap was instantiated, forgot a } --- src/GUI/Dialogs/PresetEditor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp index dfe7fe796..8fb363283 100644 --- a/src/GUI/Dialogs/PresetEditor.cpp +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -97,7 +97,7 @@ void PresetEditor::select_preset_by_name(const wxString& name, bool force) { PresetPage* PresetEditor::add_options_page(const wxString& _title, const wxString& _icon) { if (_icon.size() > 0) { - auto* bitmap { new wxBitmap(var(_icon), wxBITMAP_TYPE_PNG); + auto bitmap { wxBitmap(var(_icon), wxBITMAP_TYPE_PNG) }; this->_icons->Add(bitmap); this->_iconcount += 1; } From 32f440ea654bb34524a1da0b6e6aa4b8427175f6 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 13 Jun 2018 23:14:34 -0500 Subject: [PATCH 273/305] Fix _update() signature. --- src/GUI/Dialogs/MaterialEditor.cpp | 2 +- src/GUI/Dialogs/PrinterEditor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GUI/Dialogs/MaterialEditor.cpp b/src/GUI/Dialogs/MaterialEditor.cpp index 9ec877753..d077e3886 100644 --- a/src/GUI/Dialogs/MaterialEditor.cpp +++ b/src/GUI/Dialogs/MaterialEditor.cpp @@ -11,7 +11,7 @@ MaterialEditor::MaterialEditor(wxWindow* parent, t_config_option_keys options) : this->_build(); } -void MaterialEditor::_update() { +void MaterialEditor::_update(const std::string& opt_key) { } void MaterialEditor::_build() { diff --git a/src/GUI/Dialogs/PrinterEditor.cpp b/src/GUI/Dialogs/PrinterEditor.cpp index 8143e9b26..94c5c6167 100644 --- a/src/GUI/Dialogs/PrinterEditor.cpp +++ b/src/GUI/Dialogs/PrinterEditor.cpp @@ -11,7 +11,7 @@ PrinterEditor::PrinterEditor(wxWindow* parent, t_config_option_keys options) : this->_build(); } -void PrinterEditor::_update() { +void PrinterEditor::_update(const std::string& opt_key) { } void PrinterEditor::_build() { From c6639786b7ade6d437636d4d3b587e494af0d4ae Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 09:24:03 -0500 Subject: [PATCH 274/305] Cleaning up settings to ui_settings --- src/GUI/Plater.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index a5fe7de9a..3c1fa5d66 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -76,7 +76,7 @@ Plater::Plater(wxWindow* parent, const wxString& title) : */ // initialize 2D Preview Canvas - canvas2D = new Plate2D(preview_notebook, wxDefaultSize, objects, model, config, settings); + canvas2D = new Plate2D(preview_notebook, wxDefaultSize, objects, model, config); preview_notebook->AddPage(canvas2D, _("2D")); canvas2D->on_select_object = std::function(on_select_object); @@ -241,7 +241,7 @@ void Plater::add() { Log::info(LogChannel, L"Called Add function"); auto& start_object_id = this->object_identifier; - const auto& input_files{open_model(this, *(this->settings), wxTheApp->GetTopWindow())}; + const auto& input_files{open_model(this, wxTheApp->GetTopWindow())}; for (const auto& f : input_files) { Log::info(LogChannel, (wxString(L"Calling Load File for ") + f).ToStdWstring()); this->load_file(f.ToStdString()); @@ -272,8 +272,8 @@ void Plater::add() { std::vector Plater::load_file(const std::string file, const int obj_idx_to_load) { auto input_file {wxFileName(file)}; - settings->skein_directory = input_file.GetPath(); - settings->save_settings(); + ui_settings->skein_directory = input_file.GetPath(); + ui_settings->save_settings(); Slic3r::Model model; bool valid_load {true}; @@ -791,7 +791,7 @@ void Plater::increase(size_t copies, bool dont_push) { this->add_undo_operation(UndoCmd::Increase, obj->identifier, copies); } - if(settings->autocenter) { + if(ui_settings->autocenter) { this->arrange(); } else { this->on_model_change(); From cc0ee1931f2391aeea4b9c62e3e1a986b834c26b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 09:24:37 -0500 Subject: [PATCH 275/305] Refactoring Settings store. --- src/GUI/misc_ui.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index cc4d5e158..d4dccd057 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -148,7 +148,7 @@ sub CallAfter { wxString decode_path(const wxString& in); wxString encode_path(const wxString& in); -std::vector open_model(wxWindow* parent, const Settings& settings, wxWindow* top); +std::vector open_model(wxWindow* parent, wxWindow* top); inline Slic3r::Point new_scale(const wxPoint& p) { return Slic3r::Point::new_scale(p.x, p.y); } From b249b75be81aa54b3d7e9f04e568a5f2b2a9d456 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 09:25:22 -0500 Subject: [PATCH 276/305] Refactoring Settings store. --- src/GUI/misc_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index 41c1f17f0..ba850fbe4 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -130,7 +130,7 @@ sub show_error { } */ -std::vector open_model(wxWindow* parent, const Settings& settings, wxWindow* top) { +std::vector open_model(wxWindow* parent, wxWindow* top) { auto dialog {new wxFileDialog((parent != nullptr ? parent : top), _("Choose one or more files") + wxString(" (STL/OBJ/AMF/3MF):"), ".", "", MODEL_WILDCARD, wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST)}; if (dialog->ShowModal() != wxID_OK) { From 3ac6cbdbfd97c31367cb3f17f36816f8e9a08f87 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 11:07:19 -0500 Subject: [PATCH 277/305] Cleanup of Settings usage/propagation --- src/GUI/Plater.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 3c1fa5d66..bbf8d10a2 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -85,16 +85,16 @@ Plater::Plater(wxWindow* parent, const wxString& title) : canvas2D->on_instances_moved = std::function(on_instances_moved); - canvas3D = new Plate3D(preview_notebook, wxDefaultSize, objects, model, config, settings); + canvas3D = new Plate3D(preview_notebook, wxDefaultSize, objects, model, config); preview_notebook->AddPage(canvas3D, _("3D")); - preview3D = new Preview3D(preview_notebook, wxDefaultSize, objects, model, config, settings); + preview3D = new Preview3D(preview_notebook, wxDefaultSize, objects, model, config); preview_notebook->AddPage(preview3D, _("Preview")); - preview2D = new Preview2D(preview_notebook, wxDefaultSize, objects, model, config, settings); + preview2D = new Preview2D(preview_notebook, wxDefaultSize, objects, model, config); preview_notebook->AddPage(preview2D, _("Toolpaths")); - previewDLP = new PreviewDLP(preview_notebook, wxDefaultSize, objects, model, config, settings); + previewDLP = new PreviewDLP(preview_notebook, wxDefaultSize, objects, model, config); preview_notebook->AddPage(previewDLP, _("DLP/SLA")); /* @@ -374,7 +374,7 @@ std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { Slic3r::Log::info(LogChannel, LOG_WSTRING("Instances: " << obj->instances.size())); if (obj->instances.size() == 0) { - if (settings->autocenter) { + if (ui_settings->autocenter) { need_arrange = true; o->center_around_origin(); @@ -382,13 +382,13 @@ std::vector Plater::load_model_objects(ModelObjectPtrs model_objects) { o->instances.back()->offset = this->bed_centerf(); } else { need_arrange = false; - if (settings->autoalignz) { + if (ui_settings->autoalignz) { o->align_to_ground(); } o->add_instance(); } } else { - if (settings->autoalignz) { + if (ui_settings->autoalignz) { o->align_to_ground(); } } @@ -516,7 +516,7 @@ void Plater::on_model_change(bool force_autocenter) { } } - if (force_autocenter || settings->autocenter) { + if (force_autocenter || ui_settings->autocenter) { this->model->center_instances_around_point(this->bed_centerf()); } this->refresh_canvases(); From 33b5b7c00331ec2597ad9c0fe055da5a98723c54 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 11:29:23 -0500 Subject: [PATCH 278/305] settings to ui_settings --- src/GUI/Plater/Plate2D.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index e83836adc..e36f0d3c8 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -74,7 +74,7 @@ void Plate2D::repaint(wxPaintEvent& e) { // draw print center { - if (this->objects.size() > 0 && settings->autocenter) { + if (this->objects.size() > 0 && ui_settings->autocenter) { const auto center = this->unscaled_point_to_pixel(this->print_center); dc.SetPen(print_center_pen); dc.DrawLine(center.x, 0, center.x, size.y); @@ -89,7 +89,7 @@ void Plate2D::repaint(wxPaintEvent& e) { // draw text if plate is empty if (this->objects.size() == 0) { - dc.SetTextForeground(settings->color->BED_OBJECTS()); + dc.SetTextForeground(ui_settings->color->BED_OBJECTS()); dc.SetFont(wxFont(14, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); dc.DrawLabel(CANVAS_TEXT, wxRect(0,0, this->GetSize().GetWidth(), this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); } else { @@ -277,34 +277,34 @@ void Plate2D::mouse_dclick(wxMouseEvent& e) { void Plate2D::set_colors() { - this->SetBackgroundColour(settings->color->BACKGROUND255()); + this->SetBackgroundColour(ui_settings->color->BACKGROUND255()); - this->objects_brush.SetColour(settings->color->BED_OBJECTS()); + this->objects_brush.SetColour(ui_settings->color->BED_OBJECTS()); this->objects_brush.SetStyle(wxBRUSHSTYLE_SOLID); - this->instance_brush.SetColour(settings->color->BED_INSTANCE()); + this->instance_brush.SetColour(ui_settings->color->BED_INSTANCE()); this->instance_brush.SetStyle(wxBRUSHSTYLE_SOLID); - this->selected_brush.SetColour(settings->color->BED_SELECTED()); + this->selected_brush.SetColour(ui_settings->color->BED_SELECTED()); this->selected_brush.SetStyle(wxBRUSHSTYLE_SOLID); - this->dragged_brush.SetColour(settings->color->BED_DRAGGED()); + this->dragged_brush.SetColour(ui_settings->color->BED_DRAGGED()); this->dragged_brush.SetStyle(wxBRUSHSTYLE_SOLID); - this->bed_brush.SetColour(settings->color->BED_COLOR()); + this->bed_brush.SetColour(ui_settings->color->BED_COLOR()); this->bed_brush.SetStyle(wxBRUSHSTYLE_SOLID); this->transparent_brush.SetColour(wxColour(0,0,0)); this->transparent_brush.SetStyle(wxBRUSHSTYLE_TRANSPARENT); - this->grid_pen.SetColour(settings->color->BED_GRID()); + this->grid_pen.SetColour(ui_settings->color->BED_GRID()); this->grid_pen.SetWidth(1); this->grid_pen.SetStyle(wxPENSTYLE_SOLID); - this->print_center_pen.SetColour(settings->color->BED_CENTER()); + this->print_center_pen.SetColour(ui_settings->color->BED_CENTER()); this->print_center_pen.SetWidth(1); this->print_center_pen.SetStyle(wxPENSTYLE_SOLID); - this->clearance_pen.SetColour(settings->color->BED_CLEARANCE()); + this->clearance_pen.SetColour(ui_settings->color->BED_CLEARANCE()); this->clearance_pen.SetWidth(1); this->clearance_pen.SetStyle(wxPENSTYLE_SOLID); - this->skirt_pen.SetColour(settings->color->BED_SKIRT()); + this->skirt_pen.SetColour(ui_settings->color->BED_SKIRT()); this->skirt_pen.SetWidth(1); this->skirt_pen.SetStyle(wxPENSTYLE_SOLID); - this->dark_pen.SetColour(settings->color->BED_DARK()); + this->dark_pen.SetColour(ui_settings->color->BED_DARK()); this->dark_pen.SetWidth(1); this->dark_pen.SetStyle(wxPENSTYLE_SOLID); @@ -353,7 +353,7 @@ void Plate2D::nudge(MoveDirection dir) { Slic3r::Point shift(0,0); - auto nudge_value {settings->nudge < 0.1 ? 0.1 : scale_(settings->nudge) }; + auto nudge_value {ui_settings->nudge < 0.1 ? 0.1 : scale_(ui_settings->nudge) }; switch (dir) { case MoveDirection::Up: From b32f7132b9bdd33bfe43489ee0b910484087c2f6 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 11:41:12 -0500 Subject: [PATCH 279/305] What's that semicolon?!? --- src/GUI/Settings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GUI/Settings.cpp b/src/GUI/Settings.cpp index a0e8fea55..0e619a76f 100644 --- a/src/GUI/Settings.cpp +++ b/src/GUI/Settings.cpp @@ -9,11 +9,11 @@ void Settings::Settings() { if (the_os == OS::Mac) _small_font.SetPointSize(11); _small_bold_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); if (the_os == OS::Mac) _small_bold_font.SetPointSize(11); - _small_bold_font.MakeBold() + _small_bold_font.MakeBold(); _medium_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); _medium_font.SetPointSize(12); - _scroll_step = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)->GetPointSize(); + _scroll_step = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetPointSize(); } void Settings::save_settings() { /* From 5fb873c38105e5639202da6eba9980652966c3ad Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 12:02:52 -0500 Subject: [PATCH 280/305] Fix typo. --- src/GUI/Settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/Settings.cpp b/src/GUI/Settings.cpp index 0e619a76f..d91d9d119 100644 --- a/src/GUI/Settings.cpp +++ b/src/GUI/Settings.cpp @@ -3,7 +3,7 @@ namespace Slic3r { namespace GUI { -void Settings::Settings() { +Settings::Settings() { // Initialize fonts _small_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); if (the_os == OS::Mac) _small_font.SetPointSize(11); From e15e628645cb4d26724b3f33d1b4fdf13b828df8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 12:17:01 -0500 Subject: [PATCH 281/305] Last pieces of refactor --- src/slic3r.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 6d3470c83..70a9d7d29 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -46,12 +46,8 @@ main(int argc, char **argv) DynamicPrintConfig print_config; #ifdef USE_WX - std::shared_ptr gui_config = std::make_shared(); - - GUI::App *gui = new GUI::App(gui_config); + GUI::App *gui = new GUI::App(); - gui_config->show_host = true; - GUI::App::SetInstance(gui); wxEntry(argc, argv); #endif From ec2582c4e48f051186bf5d1764046d9d0b9785c2 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 17:10:44 -0500 Subject: [PATCH 282/305] Made ui_settings extern. --- src/GUI/Settings.cpp | 2 ++ src/GUI/misc_ui.hpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GUI/Settings.cpp b/src/GUI/Settings.cpp index d91d9d119..44aa321ea 100644 --- a/src/GUI/Settings.cpp +++ b/src/GUI/Settings.cpp @@ -3,6 +3,8 @@ namespace Slic3r { namespace GUI { +std::unique_ptr ui_settings {nullptr}; + Settings::Settings() { // Initialize fonts _small_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index d4dccd057..22033d6a4 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -153,7 +153,7 @@ std::vector open_model(wxWindow* parent, wxWindow* top); inline Slic3r::Point new_scale(const wxPoint& p) { return Slic3r::Point::new_scale(p.x, p.y); } /// Singleton for UI settings. -std::unique_ptr ui_settings {nullptr}; +extern std::unique_ptr ui_settings; }} // namespace Slic3r::GUI From 8340654183b0ed253413863b31770eb853ce2bc1 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 23:16:30 -0500 Subject: [PATCH 283/305] stubbed out preset editor changes. --- src/GUI/Dialogs/PresetEditor.cpp | 13 ++++++ src/GUI/Dialogs/PrintEditor.cpp | 5 +++ src/GUI/GUI.cpp | 3 -- src/GUI/GUI.hpp | 2 +- src/GUI/MainFrame.cpp | 4 +- src/GUI/MainFrame.hpp | 4 +- src/GUI/Plater.cpp | 74 ++++++++++++++++++++++++++++++++ src/GUI/Plater.hpp | 9 +++- src/GUI/Preset.hpp | 3 +- 9 files changed, 108 insertions(+), 9 deletions(-) diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp index 8fb363283..08f389f70 100644 --- a/src/GUI/Dialogs/PresetEditor.cpp +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -76,6 +76,11 @@ void PresetEditor::_on_value_change(std::string opt_key) { } ); } +// TODO +void PresetEditor::_on_select_preset(bool force) { +} + + void PresetEditor::select_preset(int id, bool force) { this->_presets_choice->SetSelection(id); this->_on_select_preset(force); @@ -117,4 +122,12 @@ void PresetEditor::reload_config() { void PresetEditor::reload_preset() { } +// TODO +void PresetEditor::_update_tree() { +} + +// TODO +void PresetEditor::load_presets() { +} + }} // namespace Slic3r::GUI diff --git a/src/GUI/Dialogs/PrintEditor.cpp b/src/GUI/Dialogs/PrintEditor.cpp index 2ddb26c73..e675cc74a 100644 --- a/src/GUI/Dialogs/PrintEditor.cpp +++ b/src/GUI/Dialogs/PrintEditor.cpp @@ -14,6 +14,11 @@ PrintEditor::PrintEditor(wxWindow* parent, t_config_option_keys options) : void PrintEditor::_update(const std::string& opt_key) { } + +// TODO +void PrintEditor::_on_preset_loaded() { +} + void PrintEditor::_build() { } }} // namespace Slic3r::GUI diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index 3a2bb3c11..bafcaeb83 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -23,8 +23,6 @@ namespace Slic3r { namespace GUI { bool App::OnInit() { this->SetAppName("Slic3r"); - // TODO: Call a logging function with channel GUI, severity info - this->notifier = std::unique_ptr(); datadir = decode_path(wxStandardPaths::Get().GetUserDataDir()); @@ -46,7 +44,6 @@ bool App::OnInit() } } - // TODO: Call a logging function with channel GUI, severity info for datadir path Slic3r::Log::info(LogChannel, (_("Data dir: ") + datadir).ToStdWstring()); ui_settings = Settings::init_settings(); diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index e18e073ff..11b497852 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -50,7 +50,7 @@ private: /// Quick reference to this app with its cast applied. -#define SLIC3RAPP dynamic_cast(wxTheApp) +#define SLIC3RAPP (dynamic_cast(wxTheApp)) }} // namespace Slic3r::GUI diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index dfad27820..80d949b85 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -14,7 +14,7 @@ wxEND_EVENT_TABLE() MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame(NULL, wxID_ANY, title, pos, size), loaded(false), - tabpanel(nullptr), controller(nullptr), plater(nullptr), preset_editor_tabs(std::map()) + tabpanel(nullptr), controller(nullptr), plater(nullptr), preset_editor_tabs(std::map()) { this->SetIcon(wxIcon(var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG)); @@ -95,7 +95,7 @@ void MainFrame::init_tabpanel() panel->Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, ([=](wxAuiNotebookEvent& e) { if (typeid(panel) == typeid(Slic3r::GUI::PresetEditor)) { - wxDELETE(this->preset_editor_tabs[panel->GetId()]); + wxDELETE(this->preset_editor_tabs[dynamic_cast(panel)->type()]); } wxTheApp->CallAfter([=] { this->tabpanel->SetSelection(0); }); }), panel->GetId()); diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index 54f0bfdc9..1d8272231 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -33,6 +33,9 @@ public: bool has_plater_menu() { return this->plater_menu != nullptr; } wxMenu* plater_select_menu {nullptr}; + wxAuiNotebook* tabs() { return tabpanel; } + + std::map preset_editor_tabs; private: wxDECLARE_EVENT_TABLE(); @@ -49,7 +52,6 @@ private: wxMenu* plater_menu {nullptr}; - std::map preset_editor_tabs; void on_plater_object_list_changed(bool force) {}; void on_plater_selection_changed(bool force) {}; diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index bbf8d10a2..301917f46 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -1196,6 +1196,80 @@ void Plater::_on_change_combobox(preset_t preset, wxBitmapComboBox* choice) { */ } +void Plater::show_preset_editor(preset_t preset, unsigned int idx) { + + std::function cbfunc { + [this, preset, idx]() { + auto presets { this->selected_presets(preset) }; + auto* mainframe {this->GetFrame()}; + auto* tabpanel {mainframe->tabs()}; + if (mainframe->preset_editor_tabs[preset] != nullptr) { + // editor is already open + tabpanel->SetSelection(tabpanel->GetPageIndex(mainframe->preset_editor_tabs[preset])); + return; + } else if (ui_settings->preset_editor_tabs) { + // open a tab + PresetEditor* tab {nullptr}; + switch (preset) { + case preset_t::Print: + tab = new PrintEditor(this); + break; + /* + case preset_t::Material: + tab = new MaterialEditor(this); + break; + case preset_t::Printer: + tab = new PrinterEditor(this); + break; + */ + default: // do nothing + return; + } + tabpanel->AddPage(tab, wxString(tab->name()) + wxString(" Settings")); + + } else { + // pop a dialog + switch (preset) { + case preset_t::Print: + break; + case preset_t::Material: + break; + case preset_t::Printer: + break; + default:; // do nothing + return; + } + } + + } + }; + SLIC3RAPP->CallAfter(cbfunc); + +} + +Preset* Plater::selected_presets(preset_t preset) { + auto& preset_list {SLIC3RAPP->presets.at(static_cast(preset))}; + auto sel = this->preset_choosers.at(static_cast(preset))->GetSelection(); + if (sel == -1) sel = 0; + + // Retrieve the string associated with this + auto preset_name {this->preset_choosers.at(static_cast(preset))->GetString(sel)}; + auto iter = std::find(preset_list.begin(), preset_list.end(), preset_name); + if (iter == preset_list.end()) { + Slic3r::Log::warn(LogChannel, LOG_WSTRING(preset_name + LOG_WSTRING(" not found in Presets list."))); + iter = preset_list.begin(); // get the first one if not found for some reason. + } + return &(*iter); +} + +std::vector Plater::selected_presets() { + std::vector tmp(static_cast(preset_t::Last)); // preallocate + for (uint8_t i = 0; i < static_cast(preset_t::Last); i++) { + tmp[i] = selected_presets(static_cast(i)); + } + return tmp; +} + void Plater::load_presets() { for (auto group : {preset_t::Printer, preset_t::Material, preset_t::Print}) { diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index f4cd4dbdf..a88c2999e 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -98,6 +98,8 @@ public: /// Create menu for object. wxMenu* object_menu(); + + /// Retrieve the identifier for the currently selected preset. void undo() {}; void redo() {}; @@ -109,6 +111,11 @@ public: void export_amf() {}; void export_tmf() {}; void export_stl() {}; + + /// Return a reference to the currently selected preset for a group. + Preset* selected_presets(preset_t preset); + /// Return a reference to all currently selected presets. + std::vector selected_presets(); private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; @@ -253,7 +260,7 @@ private: std::vector preset_choosers {preset_types, nullptr}; void _on_change_combobox(preset_t preset, wxBitmapComboBox* choice); - void show_preset_editor(preset_t preset, unsigned int idx) { }; + void show_preset_editor(preset_t preset, unsigned int idx); void _on_select_preset(preset_t preset) {}; void load_presets(); diff --git a/src/GUI/Preset.hpp b/src/GUI/Preset.hpp index fe28f430d..7d3ece2a4 100644 --- a/src/GUI/Preset.hpp +++ b/src/GUI/Preset.hpp @@ -6,7 +6,8 @@ namespace Slic3r { namespace GUI { -/// Preset types list. We assign numbers to permit static_casts and use as preset tab indices +/// Preset types list. We assign numbers to permit static_casts and use as preset tab indices. +/// Don't skip numbers in the enumeration, we use this as an index into vectors (instead of using std::map). enum class preset_t : uint8_t { Print = 0, Material, Printer, Last // This MUST be the last enumeration. Don't use it for anything. From 695bf7d29321ba24d2a783edd924dabb829a9c36 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 15 Jun 2018 10:42:00 -0500 Subject: [PATCH 284/305] Renaming xs/../GUI.hpp to xsGUI.hpp to avoid conflicts --- xs/src/slic3r/GUI/GUI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index fd5135f0a..0602221f7 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -1,4 +1,4 @@ -#include "GUI.hpp" +#include "xsGUI.hpp" #if __APPLE__ #import From b8a094e18f43f208d09cc26de0a04f073481d986 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 15 Jun 2018 10:42:21 -0500 Subject: [PATCH 285/305] Rename GUI.hpp to xsGUI.hpp --- xs/src/slic3r/GUI/{GUI.hpp => xsGUI.hpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename xs/src/slic3r/GUI/{GUI.hpp => xsGUI.hpp} (100%) diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/xsGUI.hpp similarity index 100% rename from xs/src/slic3r/GUI/GUI.hpp rename to xs/src/slic3r/GUI/xsGUI.hpp From 4e89f2f806b722b3e5a7beded23d47bb5a613caf Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 15 Jun 2018 10:58:32 -0500 Subject: [PATCH 286/305] Make xs/gui name correct/consistent --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e252e72d1..c3b3b4b35 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,7 +54,7 @@ set(GUI_LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/GUI/) include_directories(${LIBDIR}) include_directories(${LIBDIR}/libslic3r) -include_directories(${LIBDIR}/Slic3r/GUI/) +include_directories(${LIBDIR}/slic3r/GUI/) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/standalone/) include_directories(${LIBDIR}/admesh/) include_directories(${LIBDIR}/BSpline/) From 94736231d630c89679d42deeedfb7d7807a0b346 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 21:48:54 -0500 Subject: [PATCH 287/305] Start building tests with Catch; also use ON/OFF syntax for build options. testableframe borrowed from wxWidgets tests. --- .travis.yml | 2 +- src/CMakeLists.txt | 61 ++++++++++++++++++++++++++-- src/test/GUI/test_field_checkbox.cpp | 11 +++++ src/test/GUI/test_harness_gui.cpp | 2 + src/test/GUI/testableframe.cpp | 61 ++++++++++++++++++++++++++++ src/test/GUI/testableframe.h | 42 +++++++++++++++++++ 6 files changed, 175 insertions(+), 4 deletions(-) create mode 100644 src/test/GUI/test_field_checkbox.cpp create mode 100644 src/test/GUI/test_harness_gui.cpp create mode 100644 src/test/GUI/testableframe.cpp create mode 100644 src/test/GUI/testableframe.h diff --git a/.travis.yml b/.travis.yml index e7cf20a43..7ed9a0680 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: script: - bash package/linux/travis-setup.sh - mkdir build && cd build - - cmake -DBOOST_ROOT=$BOOST_DIR -DSLIC3R_STATIC=1 ../src + - cmake -DBOOST_ROOT=$BOOST_DIR -DSLIC3R_STATIC=ON ../src - cmake --build . branches: only: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c3b3b4b35..e9e1fae1d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_minimum_required (VERSION 3.9) project (slic3r) +option(GUI_BUILD_TESTS "Build tests for Slic3r GUI." ON) +option(SLIC3R_BUILD_TESTS "Build tests for libslic3r." ON) + # only on newer GCCs: -ftemplate-backtrace-limit=0 set(CMAKE_CXX_FLAGS "-g ${CMAKE_CXX_FLAGS} -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") @@ -37,13 +40,15 @@ ELSE(CMAKE_HOST_APPLE) # set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -L.") ENDIF(CMAKE_HOST_APPLE) -if(DEFINED ENV{SLIC3R_STATIC}) +option(SLIC3R_STATIC "Build and link Slic3r statically." ON) + +if(SLIC3R_STATIC) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME ON) -else(DEFINED ENV{SLIC3R_STATIC}) +else(SLIC3R_STATIC) set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_STATIC_RUNTIME OFF) -endif(DEFINED ENV{SLIC3R_STATIC}) +endif(SLIC3R_STATIC) find_package(Threads REQUIRED) @@ -51,6 +56,8 @@ find_package(Boost REQUIRED COMPONENTS system thread filesystem) set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/../xs/src/) set(GUI_LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/GUI/) +set(TESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/test) +set(GUI_TESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/test/GUI/) include_directories(${LIBDIR}) include_directories(${LIBDIR}/libslic3r) @@ -154,6 +161,12 @@ add_library(poly2tri STATIC ${LIBDIR}/poly2tri/sweep/sweep.cc ) +set(UI_TEST_SOURCES + ${GUI_TESTDIR}/testableframe.cpp + ${GUI_TESTDIR}/test_harness_gui.cpp + ${GUI_TESTDIR}/test_field_checkbox.cpp +) + add_executable(slic3r slic3r.cpp) #set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1) #set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1) @@ -224,6 +237,43 @@ IF(wxWidgets_FOUND) #only build GUI lib if building with wx target_link_libraries (slic3r slic3r_gui ${wxWidgets_LIBRARIES}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_WX") + + if (GUI_BUILD_TESTS) + enable_testing() + if (NOT TARGET Catch) + include (ExternalProject) + if(IS_TRAVIS_BUILD) # on travis, use git for fetching instead of wget + set(FETCH_EXTERNAL_CATCH + GIT_REPOSITORY https://github.com/philsquared/Catch.git + GIT_TAG 19ab2117c5bac2f376f8da4a4b25e183137bcec0) + elseif(WIN32) + set(FETCH_EXTERNAL_CATCH + URL https://github.com/catchorg/Catch2/archive/v2.0.1.zip + URL_HASH MD5=1abca1b324b99b1631e999119b172620) + else() + set(FETCH_EXTERNAL_CATCH + URL https://github.com/catchorg/Catch2/archive/v2.0.1.tar.gz + URL_HASH MD5=2080f4696579351d9323b3b5a8c3c71b) + endif() + ExternalProject_Add(Catch-External + PREFIX ${CMAKE_BINARY_DIR}/external/Catch + ${FETCH_EXTERNAL_CATCH} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/external/Catch/src/Catch-External/single_include/catch.hpp + ${CMAKE_BINARY_DIR}/external/Catch/include/catch.hpp + ) + add_library(Catch INTERFACE) + add_dependencies(Catch Catch-External) + + target_include_directories(Catch INTERFACE ${CMAKE_BINARY_DIR}/external/Catch/include) + target_compile_definitions(Catch INTERFACE $<$:_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING>) + endif() + add_executable(gui_test ${UI_TEST_SOURCES}) + add_test(NAME TestBase COMMAND gui_test) + target_link_libraries(gui_test PUBLIC libslic3r slic3r_gui Catch ${wxWidgets_LIBRARIES}) + + endif() ELSE(wxWidgets_FOUND) # For convenience. When we cannot continue, inform the user MESSAGE("wx not found!") @@ -249,4 +299,9 @@ IF (WIN32) # target_link_libraries(extrude-tin boost-nowide) ENDIF(WIN32) + + + + + #target_link_libraries (extrude-tin libslic3r admesh BSpline clipper expat polypartition poly2tri ${Boost_LIBRARIES}) diff --git a/src/test/GUI/test_field_checkbox.cpp b/src/test/GUI/test_field_checkbox.cpp new file mode 100644 index 000000000..23f275068 --- /dev/null +++ b/src/test/GUI/test_field_checkbox.cpp @@ -0,0 +1,11 @@ +#include "test/catch.hpp" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/checkbox.h" +#endif // WX_PRECOMP + +#include "testableframe.h" + +TEST_CASE( "Dummy" ) { +} diff --git a/src/test/GUI/test_harness_gui.cpp b/src/test/GUI/test_harness_gui.cpp new file mode 100644 index 000000000..fe8666f2d --- /dev/null +++ b/src/test/GUI/test_harness_gui.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#include "test/catch.hpp" diff --git a/src/test/GUI/testableframe.cpp b/src/test/GUI/testableframe.cpp new file mode 100644 index 000000000..fae750124 --- /dev/null +++ b/src/test/GUI/testableframe.cpp @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: testableframe.cpp +// Purpose: An improved wxFrame for unit-testing +// Author: Steven Lamerton +// Copyright: (c) 2010 Steven Lamerton +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/app.h" +#include "testableframe.h" + +wxTestableFrame::wxTestableFrame() : wxFrame(NULL, wxID_ANY, "Test Frame") +{ + // Use fixed position to facilitate debugging. + Move(200, 200); + + Show(); +} + +void wxTestableFrame::OnEvent(wxEvent& evt) +{ + m_count[evt.GetEventType()]++; + + if(! evt.IsCommandEvent() ) + evt.Skip(); +} + +int wxTestableFrame::GetEventCount(wxEventType type) +{ + return m_count[type]; +} + +void wxTestableFrame::ClearEventCount(wxEventType type) +{ + m_count[type] = 0; +} + +EventCounter::EventCounter(wxWindow* win, wxEventType type) : m_type(type), + m_win(win) + +{ + m_frame = wxStaticCast(wxTheApp->GetTopWindow(), wxTestableFrame); + + m_win->Connect(m_type, wxEventHandler(wxTestableFrame::OnEvent), + NULL, m_frame); +} + +EventCounter::~EventCounter() +{ + m_win->Disconnect(m_type, wxEventHandler(wxTestableFrame::OnEvent), + NULL, m_frame); + + //This stops spurious counts from previous tests + Clear(); + + m_frame = NULL; + m_win = NULL; +} diff --git a/src/test/GUI/testableframe.h b/src/test/GUI/testableframe.h new file mode 100644 index 000000000..a0465d829 --- /dev/null +++ b/src/test/GUI/testableframe.h @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: testableframe.h +// Purpose: An improved wxFrame for unit-testing +// Author: Steven Lamerton +// Copyright: (c) 2010 Steven Lamerton +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#include "wx/frame.h" +#include "wx/hashmap.h" +#include "wx/event.h" + +class wxTestableFrame : public wxFrame +{ +public: + wxTestableFrame(); + + void OnEvent(wxEvent& evt); + +private: + friend class EventCounter; + + int GetEventCount(wxEventType type); + void ClearEventCount(wxEventType type); + + wxLongToLongHashMap m_count; +}; + +class EventCounter +{ +public: + EventCounter(wxWindow* win, wxEventType type); + ~EventCounter(); + + int GetCount() { return m_frame->GetEventCount(m_type); } + void Clear() { m_frame->ClearEventCount(m_type); } + +private: + wxEventType m_type; + wxTestableFrame* m_frame; + wxWindow* m_win; +}; From 29b6aa23e8c39c75a5f2a893305b86c76e22a13d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 21:51:54 -0500 Subject: [PATCH 288/305] Fetch Catch via cmake instead of clone + own. --- src/test/catch.hpp | 13050 ------------------------------------------- 1 file changed, 13050 deletions(-) delete mode 100644 src/test/catch.hpp diff --git a/src/test/catch.hpp b/src/test/catch.hpp deleted file mode 100644 index ecd8907ea..000000000 --- a/src/test/catch.hpp +++ /dev/null @@ -1,13050 +0,0 @@ -/* - * Catch v2.2.2 - * Generated: 2018-04-06 12:05:03.186665 - * ---------------------------------------------------------- - * This file has been merged from multiple headers. Please don't edit it directly - * Copyright (c) 2018 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -// start catch.hpp - - -#define CATCH_VERSION_MAJOR 2 -#define CATCH_VERSION_MINOR 2 -#define CATCH_VERSION_PATCH 2 - -#ifdef __clang__ -# pragma clang system_header -#elif defined __GNUC__ -# pragma GCC system_header -#endif - -// start catch_suppress_warnings.h - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(push) -# pragma warning(disable: 161 1682) -# else // __ICC -# pragma clang diagnostic ignored "-Wunused-variable" -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wpadded" -# pragma clang diagnostic ignored "-Wswitch-enum" -# pragma clang diagnostic ignored "-Wcovered-switch-default" -# endif -#elif defined __GNUC__ -# pragma GCC diagnostic ignored "-Wparentheses" -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wunused-variable" -# pragma GCC diagnostic ignored "-Wpadded" -#endif -// end catch_suppress_warnings.h -#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) -# define CATCH_IMPL -# define CATCH_CONFIG_ALL_PARTS -#endif - -// In the impl file, we want to have access to all parts of the headers -// Can also be used to sanely support PCHs -#if defined(CATCH_CONFIG_ALL_PARTS) -# define CATCH_CONFIG_EXTERNAL_INTERFACES -# if defined(CATCH_CONFIG_DISABLE_MATCHERS) -# undef CATCH_CONFIG_DISABLE_MATCHERS -# endif -# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER -#endif - -#if !defined(CATCH_CONFIG_IMPL_ONLY) -// start catch_platform.h - -#ifdef __APPLE__ -# include -# if TARGET_OS_OSX == 1 -# define CATCH_PLATFORM_MAC -# elif TARGET_OS_IPHONE == 1 -# define CATCH_PLATFORM_IPHONE -# endif - -#elif defined(linux) || defined(__linux) || defined(__linux__) -# define CATCH_PLATFORM_LINUX - -#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) -# define CATCH_PLATFORM_WINDOWS -#endif - -// end catch_platform.h - -#ifdef CATCH_IMPL -# ifndef CLARA_CONFIG_MAIN -# define CLARA_CONFIG_MAIN_NOT_DEFINED -# define CLARA_CONFIG_MAIN -# endif -#endif - -// start catch_user_interfaces.h - -namespace Catch { - unsigned int rngSeed(); -} - -// end catch_user_interfaces.h -// start catch_tag_alias_autoregistrar.h - -// start catch_common.h - -// start catch_compiler_capabilities.h - -// Detect a number of compiler features - by compiler -// The following features are defined: -// -// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? -// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? -// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? -// **************** -// Note to maintainers: if new toggles are added please document them -// in configuration.md, too -// **************** - -// In general each macro has a _NO_ form -// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. -// Many features, at point of detection, define an _INTERNAL_ macro, so they -// can be combined, en-mass, with the _NO_ forms later. - -#ifdef __cplusplus - -# if __cplusplus >= 201402L -# define CATCH_CPP14_OR_GREATER -# endif - -# if __cplusplus >= 201703L -# define CATCH_CPP17_OR_GREATER -# endif - -#endif - -#if defined(CATCH_CPP17_OR_GREATER) -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -#endif - -#ifdef __clang__ - -# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ - _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") -# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ - _Pragma( "clang diagnostic pop" ) - -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) -# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic pop" ) - -#endif // __clang__ - -//////////////////////////////////////////////////////////////////////////////// -// Assume that non-Windows platforms support posix signals by default -#if !defined(CATCH_PLATFORM_WINDOWS) - #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS -#endif - -//////////////////////////////////////////////////////////////////////////////// -// We know some environments not to support full POSIX signals -#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) - #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -#endif - -#ifdef __OS400__ -# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -# define CATCH_CONFIG_COLOUR_NONE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Cygwin -#ifdef __CYGWIN__ - -// Required for some versions of Cygwin to declare gettimeofday -// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin -# define _BSD_SOURCE - -#endif // __CYGWIN__ - -//////////////////////////////////////////////////////////////////////////////// -// Visual C++ -#ifdef _MSC_VER - -# if _MSC_VER >= 1900 // Visual Studio 2015 or newer -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -# endif - -// Universal Windows platform does not support SEH -// Or console colours (or console at all...) -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) -# define CATCH_CONFIG_COLOUR_NONE -# else -# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH -# endif - -#endif // _MSC_VER - -//////////////////////////////////////////////////////////////////////////////// - -// DJGPP -#ifdef __DJGPP__ -# define CATCH_INTERNAL_CONFIG_NO_WCHAR -#endif // __DJGPP__ - -//////////////////////////////////////////////////////////////////////////////// - -// Use of __COUNTER__ is suppressed during code analysis in -// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly -// handled by it. -// Otherwise all supported compilers support COUNTER macro, -// but user still might want to turn it off -#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) - #define CATCH_INTERNAL_CONFIG_COUNTER -#endif - -#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) -# define CATCH_CONFIG_COUNTER -#endif -#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) -# define CATCH_CONFIG_WINDOWS_SEH -#endif -// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. -#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) -# define CATCH_CONFIG_POSIX_SIGNALS -#endif -// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. -#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) -# define CATCH_CONFIG_WCHAR -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) -# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -#endif - -#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS -#endif - -// end catch_compiler_capabilities.h -#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line -#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) -#ifdef CATCH_CONFIG_COUNTER -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) -#else -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) -#endif - -#include -#include -#include - -namespace Catch { - - struct CaseSensitive { enum Choice { - Yes, - No - }; }; - - class NonCopyable { - NonCopyable( NonCopyable const& ) = delete; - NonCopyable( NonCopyable && ) = delete; - NonCopyable& operator = ( NonCopyable const& ) = delete; - NonCopyable& operator = ( NonCopyable && ) = delete; - - protected: - NonCopyable(); - virtual ~NonCopyable(); - }; - - struct SourceLineInfo { - - SourceLineInfo() = delete; - SourceLineInfo( char const* _file, std::size_t _line ) noexcept - : file( _file ), - line( _line ) - {} - - SourceLineInfo( SourceLineInfo const& other ) = default; - SourceLineInfo( SourceLineInfo && ) = default; - SourceLineInfo& operator = ( SourceLineInfo const& ) = default; - SourceLineInfo& operator = ( SourceLineInfo && ) = default; - - bool empty() const noexcept; - bool operator == ( SourceLineInfo const& other ) const noexcept; - bool operator < ( SourceLineInfo const& other ) const noexcept; - - char const* file; - std::size_t line; - }; - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); - - // Use this in variadic streaming macros to allow - // >> +StreamEndStop - // as well as - // >> stuff +StreamEndStop - struct StreamEndStop { - std::string operator+() const; - }; - template - T const& operator + ( T const& value, StreamEndStop ) { - return value; - } -} - -#define CATCH_INTERNAL_LINEINFO \ - ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) - -// end catch_common.h -namespace Catch { - - struct RegistrarForTagAliases { - RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); - }; - -} // end namespace Catch - -#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ - CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS - -// end catch_tag_alias_autoregistrar.h -// start catch_test_registry.h - -// start catch_interfaces_testcase.h - -#include -#include - -namespace Catch { - - class TestSpec; - - struct ITestInvoker { - virtual void invoke () const = 0; - virtual ~ITestInvoker(); - }; - - using ITestCasePtr = std::shared_ptr; - - class TestCase; - struct IConfig; - - struct ITestCaseRegistry { - virtual ~ITestCaseRegistry(); - virtual std::vector const& getAllTests() const = 0; - virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; - }; - - bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); - std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); - std::vector const& getAllTestCasesSorted( IConfig const& config ); - -} - -// end catch_interfaces_testcase.h -// start catch_stringref.h - -#include -#include -#include - -namespace Catch { - - class StringData; - - /// A non-owning string class (similar to the forthcoming std::string_view) - /// Note that, because a StringRef may be a substring of another string, - /// it may not be null terminated. c_str() must return a null terminated - /// string, however, and so the StringRef will internally take ownership - /// (taking a copy), if necessary. In theory this ownership is not externally - /// visible - but it does mean (substring) StringRefs should not be shared between - /// threads. - class StringRef { - public: - using size_type = std::size_t; - - private: - friend struct StringRefTestAccess; - - char const* m_start; - size_type m_size; - - char* m_data = nullptr; - - void takeOwnership(); - - static constexpr char const* const s_empty = ""; - - public: // construction/ assignment - StringRef() noexcept - : StringRef( s_empty, 0 ) - {} - - StringRef( StringRef const& other ) noexcept - : m_start( other.m_start ), - m_size( other.m_size ) - {} - - StringRef( StringRef&& other ) noexcept - : m_start( other.m_start ), - m_size( other.m_size ), - m_data( other.m_data ) - { - other.m_data = nullptr; - } - - StringRef( char const* rawChars ) noexcept; - - StringRef( char const* rawChars, size_type size ) noexcept - : m_start( rawChars ), - m_size( size ) - {} - - StringRef( std::string const& stdString ) noexcept - : m_start( stdString.c_str() ), - m_size( stdString.size() ) - {} - - ~StringRef() noexcept { - delete[] m_data; - } - - auto operator = ( StringRef const &other ) noexcept -> StringRef& { - delete[] m_data; - m_data = nullptr; - m_start = other.m_start; - m_size = other.m_size; - return *this; - } - - operator std::string() const; - - void swap( StringRef& other ) noexcept; - - public: // operators - auto operator == ( StringRef const& other ) const noexcept -> bool; - auto operator != ( StringRef const& other ) const noexcept -> bool; - - auto operator[] ( size_type index ) const noexcept -> char; - - public: // named queries - auto empty() const noexcept -> bool { - return m_size == 0; - } - auto size() const noexcept -> size_type { - return m_size; - } - - auto numberOfCharacters() const noexcept -> size_type; - auto c_str() const -> char const*; - - public: // substrings and searches - auto substr( size_type start, size_type size ) const noexcept -> StringRef; - - // Returns the current start pointer. - // Note that the pointer can change when if the StringRef is a substring - auto currentData() const noexcept -> char const*; - - private: // ownership queries - may not be consistent between calls - auto isOwned() const noexcept -> bool; - auto isSubstring() const noexcept -> bool; - }; - - auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string; - auto operator + ( StringRef const& lhs, char const* rhs ) -> std::string; - auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string; - - auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; - auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; - - inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { - return StringRef( rawChars, size ); - } - -} // namespace Catch - -// end catch_stringref.h -namespace Catch { - -template -class TestInvokerAsMethod : public ITestInvoker { - void (C::*m_testAsMethod)(); -public: - TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {} - - void invoke() const override { - C obj; - (obj.*m_testAsMethod)(); - } -}; - -auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*; - -template -auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* { - return new(std::nothrow) TestInvokerAsMethod( testAsMethod ); -} - -struct NameAndTags { - NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept; - StringRef name; - StringRef tags; -}; - -struct AutoReg : NonCopyable { - AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept; - ~AutoReg(); -}; - -} // end namespace Catch - -#if defined(CATCH_CONFIG_DISABLE) - #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \ - static void TestName() - #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \ - namespace{ \ - struct TestName : ClassName { \ - void test(); \ - }; \ - } \ - void TestName::test() - -#endif - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \ - static void TestName(); \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ - CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ - static void TestName() - #define INTERNAL_CATCH_TESTCASE( ... ) \ - INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ ) - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ - CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ \ - struct TestName : ClassName{ \ - void test(); \ - }; \ - Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ - } \ - CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ - void TestName::test() - #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ - INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ ) - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ - CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS - -// end catch_test_registry.h -// start catch_capture.hpp - -// start catch_assertionhandler.h - -// start catch_assertioninfo.h - -// start catch_result_type.h - -namespace Catch { - - // ResultWas::OfType enum - struct ResultWas { enum OfType { - Unknown = -1, - Ok = 0, - Info = 1, - Warning = 2, - - FailureBit = 0x10, - - ExpressionFailed = FailureBit | 1, - ExplicitFailure = FailureBit | 2, - - Exception = 0x100 | FailureBit, - - ThrewException = Exception | 1, - DidntThrowException = Exception | 2, - - FatalErrorCondition = 0x200 | FailureBit - - }; }; - - bool isOk( ResultWas::OfType resultType ); - bool isJustInfo( int flags ); - - // ResultDisposition::Flags enum - struct ResultDisposition { enum Flags { - Normal = 0x01, - - ContinueOnFailure = 0x02, // Failures fail test, but execution continues - FalseTest = 0x04, // Prefix expression with ! - SuppressFail = 0x08 // Failures are reported but do not fail the test - }; }; - - ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ); - - bool shouldContinueOnFailure( int flags ); - inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } - bool shouldSuppressFailure( int flags ); - -} // end namespace Catch - -// end catch_result_type.h -namespace Catch { - - struct AssertionInfo - { - StringRef macroName; - SourceLineInfo lineInfo; - StringRef capturedExpression; - ResultDisposition::Flags resultDisposition; - - // We want to delete this constructor but a compiler bug in 4.8 means - // the struct is then treated as non-aggregate - //AssertionInfo() = delete; - }; - -} // end namespace Catch - -// end catch_assertioninfo.h -// start catch_decomposer.h - -// start catch_tostring.h - -#include -#include -#include -#include -// start catch_stream.h - -#include -#include -#include - -namespace Catch { - - std::ostream& cout(); - std::ostream& cerr(); - std::ostream& clog(); - - class StringRef; - - struct IStream { - virtual ~IStream(); - virtual std::ostream& stream() const = 0; - }; - - auto makeStream( StringRef const &filename ) -> IStream const*; - - class ReusableStringStream { - std::size_t m_index; - std::ostream* m_oss; - public: - ReusableStringStream(); - ~ReusableStringStream(); - - auto str() const -> std::string; - - template - auto operator << ( T const& value ) -> ReusableStringStream& { - *m_oss << value; - return *this; - } - auto get() -> std::ostream& { return *m_oss; } - - static void cleanup(); - }; -} - -// end catch_stream.h - -#ifdef __OBJC__ -// start catch_objc_arc.hpp - -#import - -#ifdef __has_feature -#define CATCH_ARC_ENABLED __has_feature(objc_arc) -#else -#define CATCH_ARC_ENABLED 0 -#endif - -void arcSafeRelease( NSObject* obj ); -id performOptionalSelector( id obj, SEL sel ); - -#if !CATCH_ARC_ENABLED -inline void arcSafeRelease( NSObject* obj ) { - [obj release]; -} -inline id performOptionalSelector( id obj, SEL sel ) { - if( [obj respondsToSelector: sel] ) - return [obj performSelector: sel]; - return nil; -} -#define CATCH_UNSAFE_UNRETAINED -#define CATCH_ARC_STRONG -#else -inline void arcSafeRelease( NSObject* ){} -inline id performOptionalSelector( id obj, SEL sel ) { -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Warc-performSelector-leaks" -#endif - if( [obj respondsToSelector: sel] ) - return [obj performSelector: sel]; -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - return nil; -} -#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained -#define CATCH_ARC_STRONG __strong -#endif - -// end catch_objc_arc.hpp -#endif - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless -#endif - -// We need a dummy global operator<< so we can bring it into Catch namespace later -struct Catch_global_namespace_dummy {}; -std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); - -namespace Catch { - // Bring in operator<< from global namespace into Catch namespace - using ::operator<<; - - namespace Detail { - - extern const std::string unprintableString; - - std::string rawMemoryToString( const void *object, std::size_t size ); - - template - std::string rawMemoryToString( const T& object ) { - return rawMemoryToString( &object, sizeof(object) ); - } - - template - class IsStreamInsertable { - template - static auto test(int) - -> decltype(std::declval() << std::declval(), std::true_type()); - - template - static auto test(...)->std::false_type; - - public: - static const bool value = decltype(test(0))::value; - }; - - template - std::string convertUnknownEnumToString( E e ); - - template - typename std::enable_if::value, std::string>::type convertUnstreamable( T const& value ) { -#if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER) - (void)value; - return Detail::unprintableString; -#else - return CATCH_CONFIG_FALLBACK_STRINGIFIER(value); -#endif - } - template - typename std::enable_if::value, std::string>::type convertUnstreamable( T const& value ) { - return convertUnknownEnumToString( value ); - } - -#if defined(_MANAGED) - //! Convert a CLR string to a utf8 std::string - template - std::string clrReferenceToString( T^ ref ) { - if (ref == nullptr) - return std::string("null"); - auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString()); - cli::pin_ptr p = &bytes[0]; - return std::string(reinterpret_cast(p), bytes->Length); - } -#endif - - } // namespace Detail - - // If we decide for C++14, change these to enable_if_ts - template - struct StringMaker { - template - static - typename std::enable_if<::Catch::Detail::IsStreamInsertable::value, std::string>::type - convert(const Fake& value) { - ReusableStringStream rss; - rss << value; - return rss.str(); - } - - template - static - typename std::enable_if::value, std::string>::type - convert( const Fake& value ) { - return Detail::convertUnstreamable( value ); - } - }; - - namespace Detail { - - // This function dispatches all stringification requests inside of Catch. - // Should be preferably called fully qualified, like ::Catch::Detail::stringify - template - std::string stringify(const T& e) { - return ::Catch::StringMaker::type>::type>::convert(e); - } - - template - std::string convertUnknownEnumToString( E e ) { - return ::Catch::Detail::stringify(static_cast::type>(e)); - } - -#if defined(_MANAGED) - template - std::string stringify( T^ e ) { - return ::Catch::StringMaker::convert(e); - } -#endif - - } // namespace Detail - - // Some predefined specializations - - template<> - struct StringMaker { - static std::string convert(const std::string& str); - }; -#ifdef CATCH_CONFIG_WCHAR - template<> - struct StringMaker { - static std::string convert(const std::wstring& wstr); - }; -#endif - - template<> - struct StringMaker { - static std::string convert(char const * str); - }; - template<> - struct StringMaker { - static std::string convert(char * str); - }; - -#ifdef CATCH_CONFIG_WCHAR - template<> - struct StringMaker { - static std::string convert(wchar_t const * str); - }; - template<> - struct StringMaker { - static std::string convert(wchar_t * str); - }; -#endif - - // TBD: Should we use `strnlen` to ensure that we don't go out of the buffer, - // while keeping string semantics? - template - struct StringMaker { - static std::string convert(char const* str) { - return ::Catch::Detail::stringify(std::string{ str }); - } - }; - template - struct StringMaker { - static std::string convert(signed char const* str) { - return ::Catch::Detail::stringify(std::string{ reinterpret_cast(str) }); - } - }; - template - struct StringMaker { - static std::string convert(unsigned char const* str) { - return ::Catch::Detail::stringify(std::string{ reinterpret_cast(str) }); - } - }; - - template<> - struct StringMaker { - static std::string convert(int value); - }; - template<> - struct StringMaker { - static std::string convert(long value); - }; - template<> - struct StringMaker { - static std::string convert(long long value); - }; - template<> - struct StringMaker { - static std::string convert(unsigned int value); - }; - template<> - struct StringMaker { - static std::string convert(unsigned long value); - }; - template<> - struct StringMaker { - static std::string convert(unsigned long long value); - }; - - template<> - struct StringMaker { - static std::string convert(bool b); - }; - - template<> - struct StringMaker { - static std::string convert(char c); - }; - template<> - struct StringMaker { - static std::string convert(signed char c); - }; - template<> - struct StringMaker { - static std::string convert(unsigned char c); - }; - - template<> - struct StringMaker { - static std::string convert(std::nullptr_t); - }; - - template<> - struct StringMaker { - static std::string convert(float value); - }; - template<> - struct StringMaker { - static std::string convert(double value); - }; - - template - struct StringMaker { - template - static std::string convert(U* p) { - if (p) { - return ::Catch::Detail::rawMemoryToString(p); - } else { - return "nullptr"; - } - } - }; - - template - struct StringMaker { - static std::string convert(R C::* p) { - if (p) { - return ::Catch::Detail::rawMemoryToString(p); - } else { - return "nullptr"; - } - } - }; - -#if defined(_MANAGED) - template - struct StringMaker { - static std::string convert( T^ ref ) { - return ::Catch::Detail::clrReferenceToString(ref); - } - }; -#endif - - namespace Detail { - template - std::string rangeToString(InputIterator first, InputIterator last) { - ReusableStringStream rss; - rss << "{ "; - if (first != last) { - rss << ::Catch::Detail::stringify(*first); - for (++first; first != last; ++first) - rss << ", " << ::Catch::Detail::stringify(*first); - } - rss << " }"; - return rss.str(); - } - } - -#ifdef __OBJC__ - template<> - struct StringMaker { - static std::string convert(NSString * nsstring) { - if (!nsstring) - return "nil"; - return std::string("@") + [nsstring UTF8String]; - } - }; - template<> - struct StringMaker { - static std::string convert(NSObject* nsObject) { - return ::Catch::Detail::stringify([nsObject description]); - } - - }; - namespace Detail { - inline std::string stringify( NSString* nsstring ) { - return StringMaker::convert( nsstring ); - } - - } // namespace Detail -#endif // __OBJC__ - -} // namespace Catch - -////////////////////////////////////////////////////// -// Separate std-lib types stringification, so it can be selectively enabled -// This means that we do not bring in - -#if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS) -# define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER -# define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER -# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER -#endif - -// Separate std::pair specialization -#if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER) -#include -namespace Catch { - template - struct StringMaker > { - static std::string convert(const std::pair& pair) { - ReusableStringStream rss; - rss << "{ " - << ::Catch::Detail::stringify(pair.first) - << ", " - << ::Catch::Detail::stringify(pair.second) - << " }"; - return rss.str(); - } - }; -} -#endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER - -// Separate std::tuple specialization -#if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER) -#include -namespace Catch { - namespace Detail { - template< - typename Tuple, - std::size_t N = 0, - bool = (N < std::tuple_size::value) - > - struct TupleElementPrinter { - static void print(const Tuple& tuple, std::ostream& os) { - os << (N ? ", " : " ") - << ::Catch::Detail::stringify(std::get(tuple)); - TupleElementPrinter::print(tuple, os); - } - }; - - template< - typename Tuple, - std::size_t N - > - struct TupleElementPrinter { - static void print(const Tuple&, std::ostream&) {} - }; - - } - - template - struct StringMaker> { - static std::string convert(const std::tuple& tuple) { - ReusableStringStream rss; - rss << '{'; - Detail::TupleElementPrinter>::print(tuple, rss.get()); - rss << " }"; - return rss.str(); - } - }; -} -#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER - -namespace Catch { - struct not_this_one {}; // Tag type for detecting which begin/ end are being selected - - // Import begin/ end from std here so they are considered alongside the fallback (...) overloads in this namespace - using std::begin; - using std::end; - - not_this_one begin( ... ); - not_this_one end( ... ); - - template - struct is_range { - static const bool value = - !std::is_same())), not_this_one>::value && - !std::is_same())), not_this_one>::value; - }; - -#if defined(_MANAGED) // Managed types are never ranges - template - struct is_range { - static const bool value = false; - }; -#endif - - template - std::string rangeToString( Range const& range ) { - return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); - } - - // Handle vector specially - template - std::string rangeToString( std::vector const& v ) { - ReusableStringStream rss; - rss << "{ "; - bool first = true; - for( bool b : v ) { - if( first ) - first = false; - else - rss << ", "; - rss << ::Catch::Detail::stringify( b ); - } - rss << " }"; - return rss.str(); - } - - template - struct StringMaker::value && !::Catch::Detail::IsStreamInsertable::value>::type> { - static std::string convert( R const& range ) { - return rangeToString( range ); - } - }; - - template - struct StringMaker { - static std::string convert(T const(&arr)[SZ]) { - return rangeToString(arr); - } - }; - -} // namespace Catch - -// Separate std::chrono::duration specialization -#if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) -#include -#include -#include - -namespace Catch { - -template -struct ratio_string { - static std::string symbol(); -}; - -template -std::string ratio_string::symbol() { - Catch::ReusableStringStream rss; - rss << '[' << Ratio::num << '/' - << Ratio::den << ']'; - return rss.str(); -} -template <> -struct ratio_string { - static std::string symbol(); -}; -template <> -struct ratio_string { - static std::string symbol(); -}; -template <> -struct ratio_string { - static std::string symbol(); -}; -template <> -struct ratio_string { - static std::string symbol(); -}; -template <> -struct ratio_string { - static std::string symbol(); -}; -template <> -struct ratio_string { - static std::string symbol(); -}; - - //////////// - // std::chrono::duration specializations - template - struct StringMaker> { - static std::string convert(std::chrono::duration const& duration) { - ReusableStringStream rss; - rss << duration.count() << ' ' << ratio_string::symbol() << 's'; - return rss.str(); - } - }; - template - struct StringMaker>> { - static std::string convert(std::chrono::duration> const& duration) { - ReusableStringStream rss; - rss << duration.count() << " s"; - return rss.str(); - } - }; - template - struct StringMaker>> { - static std::string convert(std::chrono::duration> const& duration) { - ReusableStringStream rss; - rss << duration.count() << " m"; - return rss.str(); - } - }; - template - struct StringMaker>> { - static std::string convert(std::chrono::duration> const& duration) { - ReusableStringStream rss; - rss << duration.count() << " h"; - return rss.str(); - } - }; - - //////////// - // std::chrono::time_point specialization - // Generic time_point cannot be specialized, only std::chrono::time_point - template - struct StringMaker> { - static std::string convert(std::chrono::time_point const& time_point) { - return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch"; - } - }; - // std::chrono::time_point specialization - template - struct StringMaker> { - static std::string convert(std::chrono::time_point const& time_point) { - auto converted = std::chrono::system_clock::to_time_t(time_point); - -#ifdef _MSC_VER - std::tm timeInfo = {}; - gmtime_s(&timeInfo, &converted); -#else - std::tm* timeInfo = std::gmtime(&converted); -#endif - - auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); - char timeStamp[timeStampSize]; - const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; - -#ifdef _MSC_VER - std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); -#else - std::strftime(timeStamp, timeStampSize, fmt, timeInfo); -#endif - return std::string(timeStamp); - } - }; -} -#endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -// end catch_tostring.h -#include - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4389) // '==' : signed/unsigned mismatch -#pragma warning(disable:4018) // more "signed/unsigned mismatch" -#pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform) -#pragma warning(disable:4180) // qualifier applied to function type has no meaning -#endif - -namespace Catch { - - struct ITransientExpression { - auto isBinaryExpression() const -> bool { return m_isBinaryExpression; } - auto getResult() const -> bool { return m_result; } - virtual void streamReconstructedExpression( std::ostream &os ) const = 0; - - ITransientExpression( bool isBinaryExpression, bool result ) - : m_isBinaryExpression( isBinaryExpression ), - m_result( result ) - {} - - // We don't actually need a virtual destructor, but many static analysers - // complain if it's not here :-( - virtual ~ITransientExpression(); - - bool m_isBinaryExpression; - bool m_result; - - }; - - void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ); - - template - class BinaryExpr : public ITransientExpression { - LhsT m_lhs; - StringRef m_op; - RhsT m_rhs; - - void streamReconstructedExpression( std::ostream &os ) const override { - formatReconstructedExpression - ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) ); - } - - public: - BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs ) - : ITransientExpression{ true, comparisonResult }, - m_lhs( lhs ), - m_op( op ), - m_rhs( rhs ) - {} - }; - - template - class UnaryExpr : public ITransientExpression { - LhsT m_lhs; - - void streamReconstructedExpression( std::ostream &os ) const override { - os << Catch::Detail::stringify( m_lhs ); - } - - public: - explicit UnaryExpr( LhsT lhs ) - : ITransientExpression{ false, lhs ? true : false }, - m_lhs( lhs ) - {} - }; - - // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int) - template - auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast(lhs == rhs); } - template - auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } - template - auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } - template - auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } - template - auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } - - template - auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast(lhs != rhs); } - template - auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } - template - auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } - template - auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) != rhs; } - template - auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) != rhs; } - - template - class ExprLhs { - LhsT m_lhs; - public: - explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {} - - template - auto operator == ( RhsT const& rhs ) -> BinaryExpr const { - return { compareEqual( m_lhs, rhs ), m_lhs, "==", rhs }; - } - auto operator == ( bool rhs ) -> BinaryExpr const { - return { m_lhs == rhs, m_lhs, "==", rhs }; - } - - template - auto operator != ( RhsT const& rhs ) -> BinaryExpr const { - return { compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs }; - } - auto operator != ( bool rhs ) -> BinaryExpr const { - return { m_lhs != rhs, m_lhs, "!=", rhs }; - } - - template - auto operator > ( RhsT const& rhs ) -> BinaryExpr const { - return { static_cast(m_lhs > rhs), m_lhs, ">", rhs }; - } - template - auto operator < ( RhsT const& rhs ) -> BinaryExpr const { - return { static_cast(m_lhs < rhs), m_lhs, "<", rhs }; - } - template - auto operator >= ( RhsT const& rhs ) -> BinaryExpr const { - return { static_cast(m_lhs >= rhs), m_lhs, ">=", rhs }; - } - template - auto operator <= ( RhsT const& rhs ) -> BinaryExpr const { - return { static_cast(m_lhs <= rhs), m_lhs, "<=", rhs }; - } - - auto makeUnaryExpr() const -> UnaryExpr { - return UnaryExpr{ m_lhs }; - } - }; - - void handleExpression( ITransientExpression const& expr ); - - template - void handleExpression( ExprLhs const& expr ) { - handleExpression( expr.makeUnaryExpr() ); - } - - struct Decomposer { - template - auto operator <= ( T const& lhs ) -> ExprLhs { - return ExprLhs{ lhs }; - } - - auto operator <=( bool value ) -> ExprLhs { - return ExprLhs{ value }; - } - }; - -} // end namespace Catch - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -// end catch_decomposer.h -// start catch_interfaces_capture.h - -#include - -namespace Catch { - - class AssertionResult; - struct AssertionInfo; - struct SectionInfo; - struct SectionEndInfo; - struct MessageInfo; - struct Counts; - struct BenchmarkInfo; - struct BenchmarkStats; - struct AssertionReaction; - - struct ITransientExpression; - - struct IResultCapture { - - virtual ~IResultCapture(); - - virtual bool sectionStarted( SectionInfo const& sectionInfo, - Counts& assertions ) = 0; - virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0; - virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0; - - virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0; - virtual void benchmarkEnded( BenchmarkStats const& stats ) = 0; - - virtual void pushScopedMessage( MessageInfo const& message ) = 0; - virtual void popScopedMessage( MessageInfo const& message ) = 0; - - virtual void handleFatalErrorCondition( StringRef message ) = 0; - - virtual void handleExpr - ( AssertionInfo const& info, - ITransientExpression const& expr, - AssertionReaction& reaction ) = 0; - virtual void handleMessage - ( AssertionInfo const& info, - ResultWas::OfType resultType, - StringRef const& message, - AssertionReaction& reaction ) = 0; - virtual void handleUnexpectedExceptionNotThrown - ( AssertionInfo const& info, - AssertionReaction& reaction ) = 0; - virtual void handleUnexpectedInflightException - ( AssertionInfo const& info, - std::string const& message, - AssertionReaction& reaction ) = 0; - virtual void handleIncomplete - ( AssertionInfo const& info ) = 0; - virtual void handleNonExpr - ( AssertionInfo const &info, - ResultWas::OfType resultType, - AssertionReaction &reaction ) = 0; - - virtual bool lastAssertionPassed() = 0; - virtual void assertionPassed() = 0; - - // Deprecated, do not use: - virtual std::string getCurrentTestName() const = 0; - virtual const AssertionResult* getLastResult() const = 0; - virtual void exceptionEarlyReported() = 0; - }; - - IResultCapture& getResultCapture(); -} - -// end catch_interfaces_capture.h -namespace Catch { - - struct TestFailureException{}; - struct AssertionResultData; - struct IResultCapture; - class RunContext; - - class LazyExpression { - friend class AssertionHandler; - friend struct AssertionStats; - friend class RunContext; - - ITransientExpression const* m_transientExpression = nullptr; - bool m_isNegated; - public: - LazyExpression( bool isNegated ); - LazyExpression( LazyExpression const& other ); - LazyExpression& operator = ( LazyExpression const& ) = delete; - - explicit operator bool() const; - - friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&; - }; - - struct AssertionReaction { - bool shouldDebugBreak = false; - bool shouldThrow = false; - }; - - class AssertionHandler { - AssertionInfo m_assertionInfo; - AssertionReaction m_reaction; - bool m_completed = false; - IResultCapture& m_resultCapture; - - public: - AssertionHandler - ( StringRef macroName, - SourceLineInfo const& lineInfo, - StringRef capturedExpression, - ResultDisposition::Flags resultDisposition ); - ~AssertionHandler() { - if ( !m_completed ) { - m_resultCapture.handleIncomplete( m_assertionInfo ); - } - } - - template - void handleExpr( ExprLhs const& expr ) { - handleExpr( expr.makeUnaryExpr() ); - } - void handleExpr( ITransientExpression const& expr ); - - void handleMessage(ResultWas::OfType resultType, StringRef const& message); - - void handleExceptionThrownAsExpected(); - void handleUnexpectedExceptionNotThrown(); - void handleExceptionNotThrownAsExpected(); - void handleThrowingCallSkipped(); - void handleUnexpectedInflightException(); - - void complete(); - void setCompleted(); - - // query - auto allowThrows() const -> bool; - }; - - void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ); - -} // namespace Catch - -// end catch_assertionhandler.h -// start catch_message.h - -#include - -namespace Catch { - - struct MessageInfo { - MessageInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ); - - std::string macroName; - std::string message; - SourceLineInfo lineInfo; - ResultWas::OfType type; - unsigned int sequence; - - bool operator == ( MessageInfo const& other ) const; - bool operator < ( MessageInfo const& other ) const; - private: - static unsigned int globalCount; - }; - - struct MessageStream { - - template - MessageStream& operator << ( T const& value ) { - m_stream << value; - return *this; - } - - ReusableStringStream m_stream; - }; - - struct MessageBuilder : MessageStream { - MessageBuilder( std::string const& macroName, - SourceLineInfo const& lineInfo, - ResultWas::OfType type ); - - template - MessageBuilder& operator << ( T const& value ) { - m_stream << value; - return *this; - } - - MessageInfo m_info; - }; - - class ScopedMessage { - public: - explicit ScopedMessage( MessageBuilder const& builder ); - ~ScopedMessage(); - - MessageInfo m_info; - }; - -} // end namespace Catch - -// end catch_message.h -#if !defined(CATCH_CONFIG_DISABLE) - -#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION) - #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__ -#else - #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION" -#endif - -#if defined(CATCH_CONFIG_FAST_COMPILE) - -/////////////////////////////////////////////////////////////////////////////// -// Another way to speed-up compilation is to omit local try-catch for REQUIRE* -// macros. -#define INTERNAL_CATCH_TRY -#define INTERNAL_CATCH_CATCH( capturer ) - -#else // CATCH_CONFIG_FAST_COMPILE - -#define INTERNAL_CATCH_TRY try -#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); } - -#endif - -#define INTERNAL_CATCH_REACT( handler ) handler.complete(); - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ - INTERNAL_CATCH_TRY { \ - CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ - catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ - CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ - } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( (void)0, false && static_cast( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look - // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \ - INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ - if( Catch::getResultCapture().lastAssertionPassed() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \ - INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ - if( !Catch::getResultCapture().lastAssertionPassed() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ - try { \ - static_cast(__VA_ARGS__); \ - catchAssertionHandler.handleExceptionNotThrownAsExpected(); \ - } \ - catch( ... ) { \ - catchAssertionHandler.handleUnexpectedInflightException(); \ - } \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \ - if( catchAssertionHandler.allowThrows() ) \ - try { \ - static_cast(__VA_ARGS__); \ - catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ - } \ - catch( ... ) { \ - catchAssertionHandler.handleExceptionThrownAsExpected(); \ - } \ - else \ - catchAssertionHandler.handleThrowingCallSkipped(); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \ - if( catchAssertionHandler.allowThrows() ) \ - try { \ - static_cast(expr); \ - catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ - } \ - catch( exceptionType const& ) { \ - catchAssertionHandler.handleExceptionThrownAsExpected(); \ - } \ - catch( ... ) { \ - catchAssertionHandler.handleUnexpectedInflightException(); \ - } \ - else \ - catchAssertionHandler.handleThrowingCallSkipped(); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ - catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_INFO( macroName, log ) \ - Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ); - -/////////////////////////////////////////////////////////////////////////////// -// Although this is matcher-based, it can be used with just a string -#define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ - if( catchAssertionHandler.allowThrows() ) \ - try { \ - static_cast(__VA_ARGS__); \ - catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ - } \ - catch( ... ) { \ - Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \ - } \ - else \ - catchAssertionHandler.handleThrowingCallSkipped(); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -#endif // CATCH_CONFIG_DISABLE - -// end catch_capture.hpp -// start catch_section.h - -// start catch_section_info.h - -// start catch_totals.h - -#include - -namespace Catch { - - struct Counts { - Counts operator - ( Counts const& other ) const; - Counts& operator += ( Counts const& other ); - - std::size_t total() const; - bool allPassed() const; - bool allOk() const; - - std::size_t passed = 0; - std::size_t failed = 0; - std::size_t failedButOk = 0; - }; - - struct Totals { - - Totals operator - ( Totals const& other ) const; - Totals& operator += ( Totals const& other ); - - Totals delta( Totals const& prevTotals ) const; - - int error = 0; - Counts assertions; - Counts testCases; - }; -} - -// end catch_totals.h -#include - -namespace Catch { - - struct SectionInfo { - SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name, - std::string const& _description = std::string() ); - - std::string name; - std::string description; - SourceLineInfo lineInfo; - }; - - struct SectionEndInfo { - SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ); - - SectionInfo sectionInfo; - Counts prevAssertions; - double durationInSeconds; - }; - -} // end namespace Catch - -// end catch_section_info.h -// start catch_timer.h - -#include - -namespace Catch { - - auto getCurrentNanosecondsSinceEpoch() -> uint64_t; - auto getEstimatedClockResolution() -> uint64_t; - - class Timer { - uint64_t m_nanoseconds = 0; - public: - void start(); - auto getElapsedNanoseconds() const -> uint64_t; - auto getElapsedMicroseconds() const -> uint64_t; - auto getElapsedMilliseconds() const -> unsigned int; - auto getElapsedSeconds() const -> double; - }; - -} // namespace Catch - -// end catch_timer.h -#include - -namespace Catch { - - class Section : NonCopyable { - public: - Section( SectionInfo const& info ); - ~Section(); - - // This indicates whether the section should be executed or not - explicit operator bool() const; - - private: - SectionInfo m_info; - - std::string m_name; - Counts m_assertions; - bool m_sectionIncluded; - Timer m_timer; - }; - -} // end namespace Catch - - #define INTERNAL_CATCH_SECTION( ... ) \ - if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) - -// end catch_section.h -// start catch_benchmark.h - -#include -#include - -namespace Catch { - - class BenchmarkLooper { - - std::string m_name; - std::size_t m_count = 0; - std::size_t m_iterationsToRun = 1; - uint64_t m_resolution; - Timer m_timer; - - static auto getResolution() -> uint64_t; - public: - // Keep most of this inline as it's on the code path that is being timed - BenchmarkLooper( StringRef name ) - : m_name( name ), - m_resolution( getResolution() ) - { - reportStart(); - m_timer.start(); - } - - explicit operator bool() { - if( m_count < m_iterationsToRun ) - return true; - return needsMoreIterations(); - } - - void increment() { - ++m_count; - } - - void reportStart(); - auto needsMoreIterations() -> bool; - }; - -} // end namespace Catch - -#define BENCHMARK( name ) \ - for( Catch::BenchmarkLooper looper( name ); looper; looper.increment() ) - -// end catch_benchmark.h -// start catch_interfaces_exception.h - -// start catch_interfaces_registry_hub.h - -#include -#include - -namespace Catch { - - class TestCase; - struct ITestCaseRegistry; - struct IExceptionTranslatorRegistry; - struct IExceptionTranslator; - struct IReporterRegistry; - struct IReporterFactory; - struct ITagAliasRegistry; - class StartupExceptionRegistry; - - using IReporterFactoryPtr = std::shared_ptr; - - struct IRegistryHub { - virtual ~IRegistryHub(); - - virtual IReporterRegistry const& getReporterRegistry() const = 0; - virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; - virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0; - - virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; - - virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0; - }; - - struct IMutableRegistryHub { - virtual ~IMutableRegistryHub(); - virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0; - virtual void registerListener( IReporterFactoryPtr const& factory ) = 0; - virtual void registerTest( TestCase const& testInfo ) = 0; - virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; - virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0; - virtual void registerStartupException() noexcept = 0; - }; - - IRegistryHub& getRegistryHub(); - IMutableRegistryHub& getMutableRegistryHub(); - void cleanUp(); - std::string translateActiveException(); - -} - -// end catch_interfaces_registry_hub.h -#if defined(CATCH_CONFIG_DISABLE) - #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \ - static std::string translatorName( signature ) -#endif - -#include -#include -#include - -namespace Catch { - using exceptionTranslateFunction = std::string(*)(); - - struct IExceptionTranslator; - using ExceptionTranslators = std::vector>; - - struct IExceptionTranslator { - virtual ~IExceptionTranslator(); - virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; - }; - - struct IExceptionTranslatorRegistry { - virtual ~IExceptionTranslatorRegistry(); - - virtual std::string translateActiveException() const = 0; - }; - - class ExceptionTranslatorRegistrar { - template - class ExceptionTranslator : public IExceptionTranslator { - public: - - ExceptionTranslator( std::string(*translateFunction)( T& ) ) - : m_translateFunction( translateFunction ) - {} - - std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { - try { - if( it == itEnd ) - std::rethrow_exception(std::current_exception()); - else - return (*it)->translate( it+1, itEnd ); - } - catch( T& ex ) { - return m_translateFunction( ex ); - } - } - - protected: - std::string(*m_translateFunction)( T& ); - }; - - public: - template - ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { - getMutableRegistryHub().registerTranslator - ( new ExceptionTranslator( translateFunction ) ); - } - }; -} - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \ - static std::string translatorName( signature ); \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ - CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ - static std::string translatorName( signature ) - -#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) - -// end catch_interfaces_exception.h -// start catch_approx.h - -#include -#include - -namespace Catch { -namespace Detail { - - class Approx { - private: - bool equalityComparisonImpl(double other) const; - - public: - explicit Approx ( double value ); - - static Approx custom(); - - template ::value>::type> - Approx operator()( T const& value ) { - Approx approx( static_cast(value) ); - approx.epsilon( m_epsilon ); - approx.margin( m_margin ); - approx.scale( m_scale ); - return approx; - } - - template ::value>::type> - explicit Approx( T const& value ): Approx(static_cast(value)) - {} - - template ::value>::type> - friend bool operator == ( const T& lhs, Approx const& rhs ) { - auto lhs_v = static_cast(lhs); - return rhs.equalityComparisonImpl(lhs_v); - } - - template ::value>::type> - friend bool operator == ( Approx const& lhs, const T& rhs ) { - return operator==( rhs, lhs ); - } - - template ::value>::type> - friend bool operator != ( T const& lhs, Approx const& rhs ) { - return !operator==( lhs, rhs ); - } - - template ::value>::type> - friend bool operator != ( Approx const& lhs, T const& rhs ) { - return !operator==( rhs, lhs ); - } - - template ::value>::type> - friend bool operator <= ( T const& lhs, Approx const& rhs ) { - return static_cast(lhs) < rhs.m_value || lhs == rhs; - } - - template ::value>::type> - friend bool operator <= ( Approx const& lhs, T const& rhs ) { - return lhs.m_value < static_cast(rhs) || lhs == rhs; - } - - template ::value>::type> - friend bool operator >= ( T const& lhs, Approx const& rhs ) { - return static_cast(lhs) > rhs.m_value || lhs == rhs; - } - - template ::value>::type> - friend bool operator >= ( Approx const& lhs, T const& rhs ) { - return lhs.m_value > static_cast(rhs) || lhs == rhs; - } - - template ::value>::type> - Approx& epsilon( T const& newEpsilon ) { - double epsilonAsDouble = static_cast(newEpsilon); - if( epsilonAsDouble < 0 || epsilonAsDouble > 1.0 ) { - throw std::domain_error - ( "Invalid Approx::epsilon: " + - Catch::Detail::stringify( epsilonAsDouble ) + - ", Approx::epsilon has to be between 0 and 1" ); - } - m_epsilon = epsilonAsDouble; - return *this; - } - - template ::value>::type> - Approx& margin( T const& newMargin ) { - double marginAsDouble = static_cast(newMargin); - if( marginAsDouble < 0 ) { - throw std::domain_error - ( "Invalid Approx::margin: " + - Catch::Detail::stringify( marginAsDouble ) + - ", Approx::Margin has to be non-negative." ); - - } - m_margin = marginAsDouble; - return *this; - } - - template ::value>::type> - Approx& scale( T const& newScale ) { - m_scale = static_cast(newScale); - return *this; - } - - std::string toString() const; - - private: - double m_epsilon; - double m_margin; - double m_scale; - double m_value; - }; -} - -template<> -struct StringMaker { - static std::string convert(Catch::Detail::Approx const& value); -}; - -} // end namespace Catch - -// end catch_approx.h -// start catch_string_manip.h - -#include -#include - -namespace Catch { - - bool startsWith( std::string const& s, std::string const& prefix ); - bool startsWith( std::string const& s, char prefix ); - bool endsWith( std::string const& s, std::string const& suffix ); - bool endsWith( std::string const& s, char suffix ); - bool contains( std::string const& s, std::string const& infix ); - void toLowerInPlace( std::string& s ); - std::string toLower( std::string const& s ); - std::string trim( std::string const& str ); - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); - - struct pluralise { - pluralise( std::size_t count, std::string const& label ); - - friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); - - std::size_t m_count; - std::string m_label; - }; -} - -// end catch_string_manip.h -#ifndef CATCH_CONFIG_DISABLE_MATCHERS -// start catch_capture_matchers.h - -// start catch_matchers.h - -#include -#include - -namespace Catch { -namespace Matchers { - namespace Impl { - - template struct MatchAllOf; - template struct MatchAnyOf; - template struct MatchNotOf; - - class MatcherUntypedBase { - public: - MatcherUntypedBase() = default; - MatcherUntypedBase ( MatcherUntypedBase const& ) = default; - MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete; - std::string toString() const; - - protected: - virtual ~MatcherUntypedBase(); - virtual std::string describe() const = 0; - mutable std::string m_cachedToString; - }; - - template - struct MatcherMethod { - virtual bool match( ObjectT const& arg ) const = 0; - }; - template - struct MatcherMethod { - virtual bool match( PtrT* arg ) const = 0; - }; - - template - struct MatcherBase : MatcherUntypedBase, MatcherMethod { - - MatchAllOf operator && ( MatcherBase const& other ) const; - MatchAnyOf operator || ( MatcherBase const& other ) const; - MatchNotOf operator ! () const; - }; - - template - struct MatchAllOf : MatcherBase { - bool match( ArgT const& arg ) const override { - for( auto matcher : m_matchers ) { - if (!matcher->match(arg)) - return false; - } - return true; - } - std::string describe() const override { - std::string description; - description.reserve( 4 + m_matchers.size()*32 ); - description += "( "; - bool first = true; - for( auto matcher : m_matchers ) { - if( first ) - first = false; - else - description += " and "; - description += matcher->toString(); - } - description += " )"; - return description; - } - - MatchAllOf& operator && ( MatcherBase const& other ) { - m_matchers.push_back( &other ); - return *this; - } - - std::vector const*> m_matchers; - }; - template - struct MatchAnyOf : MatcherBase { - - bool match( ArgT const& arg ) const override { - for( auto matcher : m_matchers ) { - if (matcher->match(arg)) - return true; - } - return false; - } - std::string describe() const override { - std::string description; - description.reserve( 4 + m_matchers.size()*32 ); - description += "( "; - bool first = true; - for( auto matcher : m_matchers ) { - if( first ) - first = false; - else - description += " or "; - description += matcher->toString(); - } - description += " )"; - return description; - } - - MatchAnyOf& operator || ( MatcherBase const& other ) { - m_matchers.push_back( &other ); - return *this; - } - - std::vector const*> m_matchers; - }; - - template - struct MatchNotOf : MatcherBase { - - MatchNotOf( MatcherBase const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {} - - bool match( ArgT const& arg ) const override { - return !m_underlyingMatcher.match( arg ); - } - - std::string describe() const override { - return "not " + m_underlyingMatcher.toString(); - } - MatcherBase const& m_underlyingMatcher; - }; - - template - MatchAllOf MatcherBase::operator && ( MatcherBase const& other ) const { - return MatchAllOf() && *this && other; - } - template - MatchAnyOf MatcherBase::operator || ( MatcherBase const& other ) const { - return MatchAnyOf() || *this || other; - } - template - MatchNotOf MatcherBase::operator ! () const { - return MatchNotOf( *this ); - } - - } // namespace Impl - -} // namespace Matchers - -using namespace Matchers; -using Matchers::Impl::MatcherBase; - -} // namespace Catch - -// end catch_matchers.h -// start catch_matchers_floating.h - -#include -#include - -namespace Catch { -namespace Matchers { - - namespace Floating { - - enum class FloatingPointKind : uint8_t; - - struct WithinAbsMatcher : MatcherBase { - WithinAbsMatcher(double target, double margin); - bool match(double const& matchee) const override; - std::string describe() const override; - private: - double m_target; - double m_margin; - }; - - struct WithinUlpsMatcher : MatcherBase { - WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType); - bool match(double const& matchee) const override; - std::string describe() const override; - private: - double m_target; - int m_ulps; - FloatingPointKind m_type; - }; - - } // namespace Floating - - // The following functions create the actual matcher objects. - // This allows the types to be inferred - Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff); - Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff); - Floating::WithinAbsMatcher WithinAbs(double target, double margin); - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_floating.h -// start catch_matchers_generic.hpp - -#include -#include - -namespace Catch { -namespace Matchers { -namespace Generic { - -namespace Detail { - std::string finalizeDescription(const std::string& desc); -} - -template -class PredicateMatcher : public MatcherBase { - std::function m_predicate; - std::string m_description; -public: - - PredicateMatcher(std::function const& elem, std::string const& descr) - :m_predicate(std::move(elem)), - m_description(Detail::finalizeDescription(descr)) - {} - - bool match( T const& item ) const override { - return m_predicate(item); - } - - std::string describe() const override { - return m_description; - } -}; - -} // namespace Generic - - // The following functions create the actual matcher objects. - // The user has to explicitly specify type to the function, because - // infering std::function is hard (but possible) and - // requires a lot of TMP. - template - Generic::PredicateMatcher Predicate(std::function const& predicate, std::string const& description = "") { - return Generic::PredicateMatcher(predicate, description); - } - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_generic.hpp -// start catch_matchers_string.h - -#include - -namespace Catch { -namespace Matchers { - - namespace StdString { - - struct CasedString - { - CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ); - std::string adjustString( std::string const& str ) const; - std::string caseSensitivitySuffix() const; - - CaseSensitive::Choice m_caseSensitivity; - std::string m_str; - }; - - struct StringMatcherBase : MatcherBase { - StringMatcherBase( std::string const& operation, CasedString const& comparator ); - std::string describe() const override; - - CasedString m_comparator; - std::string m_operation; - }; - - struct EqualsMatcher : StringMatcherBase { - EqualsMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - struct ContainsMatcher : StringMatcherBase { - ContainsMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - struct StartsWithMatcher : StringMatcherBase { - StartsWithMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - struct EndsWithMatcher : StringMatcherBase { - EndsWithMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - - struct RegexMatcher : MatcherBase { - RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity ); - bool match( std::string const& matchee ) const override; - std::string describe() const override; - - private: - std::string m_regex; - CaseSensitive::Choice m_caseSensitivity; - }; - - } // namespace StdString - - // The following functions create the actual matcher objects. - // This allows the types to be inferred - - StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_string.h -// start catch_matchers_vector.h - -#include - -namespace Catch { -namespace Matchers { - - namespace Vector { - namespace Detail { - template - size_t count(InputIterator first, InputIterator last, T const& item) { - size_t cnt = 0; - for (; first != last; ++first) { - if (*first == item) { - ++cnt; - } - } - return cnt; - } - template - bool contains(InputIterator first, InputIterator last, T const& item) { - for (; first != last; ++first) { - if (*first == item) { - return true; - } - } - return false; - } - } - - template - struct ContainsElementMatcher : MatcherBase> { - - ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} - - bool match(std::vector const &v) const override { - for (auto const& el : v) { - if (el == m_comparator) { - return true; - } - } - return false; - } - - std::string describe() const override { - return "Contains: " + ::Catch::Detail::stringify( m_comparator ); - } - - T const& m_comparator; - }; - - template - struct ContainsMatcher : MatcherBase> { - - ContainsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} - - bool match(std::vector const &v) const override { - // !TBD: see note in EqualsMatcher - if (m_comparator.size() > v.size()) - return false; - for (auto const& comparator : m_comparator) { - auto present = false; - for (const auto& el : v) { - if (el == comparator) { - present = true; - break; - } - } - if (!present) { - return false; - } - } - return true; - } - std::string describe() const override { - return "Contains: " + ::Catch::Detail::stringify( m_comparator ); - } - - std::vector const& m_comparator; - }; - - template - struct EqualsMatcher : MatcherBase> { - - EqualsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} - - bool match(std::vector const &v) const override { - // !TBD: This currently works if all elements can be compared using != - // - a more general approach would be via a compare template that defaults - // to using !=. but could be specialised for, e.g. std::vector etc - // - then just call that directly - if (m_comparator.size() != v.size()) - return false; - for (std::size_t i = 0; i < v.size(); ++i) - if (m_comparator[i] != v[i]) - return false; - return true; - } - std::string describe() const override { - return "Equals: " + ::Catch::Detail::stringify( m_comparator ); - } - std::vector const& m_comparator; - }; - - template - struct UnorderedEqualsMatcher : MatcherBase> { - UnorderedEqualsMatcher(std::vector const& target) : m_target(target) {} - bool match(std::vector const& vec) const override { - // Note: This is a reimplementation of std::is_permutation, - // because I don't want to include inside the common path - if (m_target.size() != vec.size()) { - return false; - } - auto lfirst = m_target.begin(), llast = m_target.end(); - auto rfirst = vec.begin(), rlast = vec.end(); - // Cut common prefix to optimize checking of permuted parts - while (lfirst != llast && *lfirst != *rfirst) { - ++lfirst; ++rfirst; - } - if (lfirst == llast) { - return true; - } - - for (auto mid = lfirst; mid != llast; ++mid) { - // Skip already counted items - if (Detail::contains(lfirst, mid, *mid)) { - continue; - } - size_t num_vec = Detail::count(rfirst, rlast, *mid); - if (num_vec == 0 || Detail::count(lfirst, llast, *mid) != num_vec) { - return false; - } - } - - return true; - } - - std::string describe() const override { - return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target); - } - private: - std::vector const& m_target; - }; - - } // namespace Vector - - // The following functions create the actual matcher objects. - // This allows the types to be inferred - - template - Vector::ContainsMatcher Contains( std::vector const& comparator ) { - return Vector::ContainsMatcher( comparator ); - } - - template - Vector::ContainsElementMatcher VectorContains( T const& comparator ) { - return Vector::ContainsElementMatcher( comparator ); - } - - template - Vector::EqualsMatcher Equals( std::vector const& comparator ) { - return Vector::EqualsMatcher( comparator ); - } - - template - Vector::UnorderedEqualsMatcher UnorderedEquals(std::vector const& target) { - return Vector::UnorderedEqualsMatcher(target); - } - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_vector.h -namespace Catch { - - template - class MatchExpr : public ITransientExpression { - ArgT const& m_arg; - MatcherT m_matcher; - StringRef m_matcherString; - public: - MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString ) - : ITransientExpression{ true, matcher.match( arg ) }, - m_arg( arg ), - m_matcher( matcher ), - m_matcherString( matcherString ) - {} - - void streamReconstructedExpression( std::ostream &os ) const override { - auto matcherAsString = m_matcher.toString(); - os << Catch::Detail::stringify( m_arg ) << ' '; - if( matcherAsString == Detail::unprintableString ) - os << m_matcherString; - else - os << matcherAsString; - } - }; - - using StringMatcher = Matchers::Impl::MatcherBase; - - void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ); - - template - auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString ) -> MatchExpr { - return MatchExpr( arg, matcher, matcherString ); - } - -} // namespace Catch - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ - INTERNAL_CATCH_TRY { \ - catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \ - } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ - if( catchAssertionHandler.allowThrows() ) \ - try { \ - static_cast(__VA_ARGS__ ); \ - catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ - } \ - catch( exceptionType const& ex ) { \ - catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \ - } \ - catch( ... ) { \ - catchAssertionHandler.handleUnexpectedInflightException(); \ - } \ - else \ - catchAssertionHandler.handleThrowingCallSkipped(); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -// end catch_capture_matchers.h -#endif - -// These files are included here so the single_include script doesn't put them -// in the conditionally compiled sections -// start catch_test_case_info.h - -#include -#include -#include - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -namespace Catch { - - struct ITestInvoker; - - struct TestCaseInfo { - enum SpecialProperties{ - None = 0, - IsHidden = 1 << 1, - ShouldFail = 1 << 2, - MayFail = 1 << 3, - Throws = 1 << 4, - NonPortable = 1 << 5, - Benchmark = 1 << 6 - }; - - TestCaseInfo( std::string const& _name, - std::string const& _className, - std::string const& _description, - std::vector const& _tags, - SourceLineInfo const& _lineInfo ); - - friend void setTags( TestCaseInfo& testCaseInfo, std::vector tags ); - - bool isHidden() const; - bool throws() const; - bool okToFail() const; - bool expectedToFail() const; - - std::string tagsAsString() const; - - std::string name; - std::string className; - std::string description; - std::vector tags; - std::vector lcaseTags; - SourceLineInfo lineInfo; - SpecialProperties properties; - }; - - class TestCase : public TestCaseInfo { - public: - - TestCase( ITestInvoker* testCase, TestCaseInfo&& info ); - - TestCase withName( std::string const& _newName ) const; - - void invoke() const; - - TestCaseInfo const& getTestCaseInfo() const; - - bool operator == ( TestCase const& other ) const; - bool operator < ( TestCase const& other ) const; - - private: - std::shared_ptr test; - }; - - TestCase makeTestCase( ITestInvoker* testCase, - std::string const& className, - NameAndTags const& nameAndTags, - SourceLineInfo const& lineInfo ); -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// end catch_test_case_info.h -// start catch_interfaces_runner.h - -namespace Catch { - - struct IRunner { - virtual ~IRunner(); - virtual bool aborting() const = 0; - }; -} - -// end catch_interfaces_runner.h - -#ifdef __OBJC__ -// start catch_objc.hpp - -#import - -#include - -// NB. Any general catch headers included here must be included -// in catch.hpp first to make sure they are included by the single -// header for non obj-usage - -/////////////////////////////////////////////////////////////////////////////// -// This protocol is really only here for (self) documenting purposes, since -// all its methods are optional. -@protocol OcFixture - -@optional - --(void) setUp; --(void) tearDown; - -@end - -namespace Catch { - - class OcMethod : public ITestInvoker { - - public: - OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} - - virtual void invoke() const { - id obj = [[m_cls alloc] init]; - - performOptionalSelector( obj, @selector(setUp) ); - performOptionalSelector( obj, m_sel ); - performOptionalSelector( obj, @selector(tearDown) ); - - arcSafeRelease( obj ); - } - private: - virtual ~OcMethod() {} - - Class m_cls; - SEL m_sel; - }; - - namespace Detail{ - - inline std::string getAnnotation( Class cls, - std::string const& annotationName, - std::string const& testCaseName ) { - NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; - SEL sel = NSSelectorFromString( selStr ); - arcSafeRelease( selStr ); - id value = performOptionalSelector( cls, sel ); - if( value ) - return [(NSString*)value UTF8String]; - return ""; - } - } - - inline std::size_t registerTestMethods() { - std::size_t noTestMethods = 0; - int noClasses = objc_getClassList( nullptr, 0 ); - - Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); - objc_getClassList( classes, noClasses ); - - for( int c = 0; c < noClasses; c++ ) { - Class cls = classes[c]; - { - u_int count; - Method* methods = class_copyMethodList( cls, &count ); - for( u_int m = 0; m < count ; m++ ) { - SEL selector = method_getName(methods[m]); - std::string methodName = sel_getName(selector); - if( startsWith( methodName, "Catch_TestCase_" ) ) { - std::string testCaseName = methodName.substr( 15 ); - std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); - std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); - const char* className = class_getName( cls ); - - getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo("",0) ) ); - noTestMethods++; - } - } - free(methods); - } - } - return noTestMethods; - } - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) - - namespace Matchers { - namespace Impl { - namespace NSStringMatchers { - - struct StringHolder : MatcherBase{ - StringHolder( NSString* substr ) : m_substr( [substr copy] ){} - StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} - StringHolder() { - arcSafeRelease( m_substr ); - } - - bool match( NSString* arg ) const override { - return false; - } - - NSString* CATCH_ARC_STRONG m_substr; - }; - - struct Equals : StringHolder { - Equals( NSString* substr ) : StringHolder( substr ){} - - bool match( NSString* str ) const override { - return (str != nil || m_substr == nil ) && - [str isEqualToString:m_substr]; - } - - std::string describe() const override { - return "equals string: " + Catch::Detail::stringify( m_substr ); - } - }; - - struct Contains : StringHolder { - Contains( NSString* substr ) : StringHolder( substr ){} - - bool match( NSString* str ) const { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location != NSNotFound; - } - - std::string describe() const override { - return "contains string: " + Catch::Detail::stringify( m_substr ); - } - }; - - struct StartsWith : StringHolder { - StartsWith( NSString* substr ) : StringHolder( substr ){} - - bool match( NSString* str ) const override { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location == 0; - } - - std::string describe() const override { - return "starts with: " + Catch::Detail::stringify( m_substr ); - } - }; - struct EndsWith : StringHolder { - EndsWith( NSString* substr ) : StringHolder( substr ){} - - bool match( NSString* str ) const override { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location == [str length] - [m_substr length]; - } - - std::string describe() const override { - return "ends with: " + Catch::Detail::stringify( m_substr ); - } - }; - - } // namespace NSStringMatchers - } // namespace Impl - - inline Impl::NSStringMatchers::Equals - Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } - - inline Impl::NSStringMatchers::Contains - Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } - - inline Impl::NSStringMatchers::StartsWith - StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } - - inline Impl::NSStringMatchers::EndsWith - EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } - - } // namespace Matchers - - using namespace Matchers; - -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -} // namespace Catch - -/////////////////////////////////////////////////////////////////////////////// -#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix -#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \ -+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \ -{ \ -return @ name; \ -} \ -+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \ -{ \ -return @ desc; \ -} \ --(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix ) - -#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ ) - -// end catch_objc.hpp -#endif - -#ifdef CATCH_CONFIG_EXTERNAL_INTERFACES -// start catch_external_interfaces.h - -// start catch_reporter_bases.hpp - -// start catch_interfaces_reporter.h - -// start catch_config.hpp - -// start catch_test_spec_parser.h - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -// start catch_test_spec.h - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -// start catch_wildcard_pattern.h - -namespace Catch -{ - class WildcardPattern { - enum WildcardPosition { - NoWildcard = 0, - WildcardAtStart = 1, - WildcardAtEnd = 2, - WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd - }; - - public: - - WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity ); - virtual ~WildcardPattern() = default; - virtual bool matches( std::string const& str ) const; - - private: - std::string adjustCase( std::string const& str ) const; - CaseSensitive::Choice m_caseSensitivity; - WildcardPosition m_wildcard = NoWildcard; - std::string m_pattern; - }; -} - -// end catch_wildcard_pattern.h -#include -#include -#include - -namespace Catch { - - class TestSpec { - struct Pattern { - virtual ~Pattern(); - virtual bool matches( TestCaseInfo const& testCase ) const = 0; - }; - using PatternPtr = std::shared_ptr; - - class NamePattern : public Pattern { - public: - NamePattern( std::string const& name ); - virtual ~NamePattern(); - virtual bool matches( TestCaseInfo const& testCase ) const override; - private: - WildcardPattern m_wildcardPattern; - }; - - class TagPattern : public Pattern { - public: - TagPattern( std::string const& tag ); - virtual ~TagPattern(); - virtual bool matches( TestCaseInfo const& testCase ) const override; - private: - std::string m_tag; - }; - - class ExcludedPattern : public Pattern { - public: - ExcludedPattern( PatternPtr const& underlyingPattern ); - virtual ~ExcludedPattern(); - virtual bool matches( TestCaseInfo const& testCase ) const override; - private: - PatternPtr m_underlyingPattern; - }; - - struct Filter { - std::vector m_patterns; - - bool matches( TestCaseInfo const& testCase ) const; - }; - - public: - bool hasFilters() const; - bool matches( TestCaseInfo const& testCase ) const; - - private: - std::vector m_filters; - - friend class TestSpecParser; - }; -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// end catch_test_spec.h -// start catch_interfaces_tag_alias_registry.h - -#include - -namespace Catch { - - struct TagAlias; - - struct ITagAliasRegistry { - virtual ~ITagAliasRegistry(); - // Nullptr if not present - virtual TagAlias const* find( std::string const& alias ) const = 0; - virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; - - static ITagAliasRegistry const& get(); - }; - -} // end namespace Catch - -// end catch_interfaces_tag_alias_registry.h -namespace Catch { - - class TestSpecParser { - enum Mode{ None, Name, QuotedName, Tag, EscapedName }; - Mode m_mode = None; - bool m_exclusion = false; - std::size_t m_start = std::string::npos, m_pos = 0; - std::string m_arg; - std::vector m_escapeChars; - TestSpec::Filter m_currentFilter; - TestSpec m_testSpec; - ITagAliasRegistry const* m_tagAliases = nullptr; - - public: - TestSpecParser( ITagAliasRegistry const& tagAliases ); - - TestSpecParser& parse( std::string const& arg ); - TestSpec testSpec(); - - private: - void visitChar( char c ); - void startNewMode( Mode mode, std::size_t start ); - void escape(); - std::string subString() const; - - template - void addPattern() { - std::string token = subString(); - for( std::size_t i = 0; i < m_escapeChars.size(); ++i ) - token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 ); - m_escapeChars.clear(); - if( startsWith( token, "exclude:" ) ) { - m_exclusion = true; - token = token.substr( 8 ); - } - if( !token.empty() ) { - TestSpec::PatternPtr pattern = std::make_shared( token ); - if( m_exclusion ) - pattern = std::make_shared( pattern ); - m_currentFilter.m_patterns.push_back( pattern ); - } - m_exclusion = false; - m_mode = None; - } - - void addFilter(); - }; - TestSpec parseTestSpec( std::string const& arg ); - -} // namespace Catch - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// end catch_test_spec_parser.h -// start catch_interfaces_config.h - -#include -#include -#include -#include - -namespace Catch { - - enum class Verbosity { - Quiet = 0, - Normal, - High - }; - - struct WarnAbout { enum What { - Nothing = 0x00, - NoAssertions = 0x01, - NoTests = 0x02 - }; }; - - struct ShowDurations { enum OrNot { - DefaultForReporter, - Always, - Never - }; }; - struct RunTests { enum InWhatOrder { - InDeclarationOrder, - InLexicographicalOrder, - InRandomOrder - }; }; - struct UseColour { enum YesOrNo { - Auto, - Yes, - No - }; }; - struct WaitForKeypress { enum When { - Never, - BeforeStart = 1, - BeforeExit = 2, - BeforeStartAndExit = BeforeStart | BeforeExit - }; }; - - class TestSpec; - - struct IConfig : NonCopyable { - - virtual ~IConfig(); - - virtual bool allowThrows() const = 0; - virtual std::ostream& stream() const = 0; - virtual std::string name() const = 0; - virtual bool includeSuccessfulResults() const = 0; - virtual bool shouldDebugBreak() const = 0; - virtual bool warnAboutMissingAssertions() const = 0; - virtual bool warnAboutNoTests() const = 0; - virtual int abortAfter() const = 0; - virtual bool showInvisibles() const = 0; - virtual ShowDurations::OrNot showDurations() const = 0; - virtual TestSpec const& testSpec() const = 0; - virtual bool hasTestFilters() const = 0; - virtual RunTests::InWhatOrder runOrder() const = 0; - virtual unsigned int rngSeed() const = 0; - virtual int benchmarkResolutionMultiple() const = 0; - virtual UseColour::YesOrNo useColour() const = 0; - virtual std::vector const& getSectionsToRun() const = 0; - virtual Verbosity verbosity() const = 0; - }; - - using IConfigPtr = std::shared_ptr; -} - -// end catch_interfaces_config.h -// Libstdc++ doesn't like incomplete classes for unique_ptr - -#include -#include -#include - -#ifndef CATCH_CONFIG_CONSOLE_WIDTH -#define CATCH_CONFIG_CONSOLE_WIDTH 80 -#endif - -namespace Catch { - - struct IStream; - - struct ConfigData { - bool listTests = false; - bool listTags = false; - bool listReporters = false; - bool listTestNamesOnly = false; - - bool showSuccessfulTests = false; - bool shouldDebugBreak = false; - bool noThrow = false; - bool showHelp = false; - bool showInvisibles = false; - bool filenamesAsTags = false; - bool libIdentify = false; - - int abortAfter = -1; - unsigned int rngSeed = 0; - int benchmarkResolutionMultiple = 100; - - Verbosity verbosity = Verbosity::Normal; - WarnAbout::What warnings = WarnAbout::Nothing; - ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter; - RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder; - UseColour::YesOrNo useColour = UseColour::Auto; - WaitForKeypress::When waitForKeypress = WaitForKeypress::Never; - - std::string outputFilename; - std::string name; - std::string processName; - - std::vector reporterNames; - std::vector testsOrTags; - std::vector sectionsToRun; - }; - - class Config : public IConfig { - public: - - Config() = default; - Config( ConfigData const& data ); - virtual ~Config() = default; - - std::string const& getFilename() const; - - bool listTests() const; - bool listTestNamesOnly() const; - bool listTags() const; - bool listReporters() const; - - std::string getProcessName() const; - - std::vector const& getReporterNames() const; - std::vector const& getTestsOrTags() const; - std::vector const& getSectionsToRun() const override; - - virtual TestSpec const& testSpec() const override; - bool hasTestFilters() const override; - - bool showHelp() const; - - // IConfig interface - bool allowThrows() const override; - std::ostream& stream() const override; - std::string name() const override; - bool includeSuccessfulResults() const override; - bool warnAboutMissingAssertions() const override; - bool warnAboutNoTests() const override; - ShowDurations::OrNot showDurations() const override; - RunTests::InWhatOrder runOrder() const override; - unsigned int rngSeed() const override; - int benchmarkResolutionMultiple() const override; - UseColour::YesOrNo useColour() const override; - bool shouldDebugBreak() const override; - int abortAfter() const override; - bool showInvisibles() const override; - Verbosity verbosity() const override; - - private: - - IStream const* openStream(); - ConfigData m_data; - - std::unique_ptr m_stream; - TestSpec m_testSpec; - bool m_hasTestFilters = false; - }; - -} // end namespace Catch - -// end catch_config.hpp -// start catch_assertionresult.h - -#include - -namespace Catch { - - struct AssertionResultData - { - AssertionResultData() = delete; - - AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression ); - - std::string message; - mutable std::string reconstructedExpression; - LazyExpression lazyExpression; - ResultWas::OfType resultType; - - std::string reconstructExpression() const; - }; - - class AssertionResult { - public: - AssertionResult() = delete; - AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); - - bool isOk() const; - bool succeeded() const; - ResultWas::OfType getResultType() const; - bool hasExpression() const; - bool hasMessage() const; - std::string getExpression() const; - std::string getExpressionInMacro() const; - bool hasExpandedExpression() const; - std::string getExpandedExpression() const; - std::string getMessage() const; - SourceLineInfo getSourceInfo() const; - StringRef getTestMacroName() const; - - //protected: - AssertionInfo m_info; - AssertionResultData m_resultData; - }; - -} // end namespace Catch - -// end catch_assertionresult.h -// start catch_option.hpp - -namespace Catch { - - // An optional type - template - class Option { - public: - Option() : nullableValue( nullptr ) {} - Option( T const& _value ) - : nullableValue( new( storage ) T( _value ) ) - {} - Option( Option const& _other ) - : nullableValue( _other ? new( storage ) T( *_other ) : nullptr ) - {} - - ~Option() { - reset(); - } - - Option& operator= ( Option const& _other ) { - if( &_other != this ) { - reset(); - if( _other ) - nullableValue = new( storage ) T( *_other ); - } - return *this; - } - Option& operator = ( T const& _value ) { - reset(); - nullableValue = new( storage ) T( _value ); - return *this; - } - - void reset() { - if( nullableValue ) - nullableValue->~T(); - nullableValue = nullptr; - } - - T& operator*() { return *nullableValue; } - T const& operator*() const { return *nullableValue; } - T* operator->() { return nullableValue; } - const T* operator->() const { return nullableValue; } - - T valueOr( T const& defaultValue ) const { - return nullableValue ? *nullableValue : defaultValue; - } - - bool some() const { return nullableValue != nullptr; } - bool none() const { return nullableValue == nullptr; } - - bool operator !() const { return nullableValue == nullptr; } - explicit operator bool() const { - return some(); - } - - private: - T *nullableValue; - alignas(alignof(T)) char storage[sizeof(T)]; - }; - -} // end namespace Catch - -// end catch_option.hpp -#include -#include -#include -#include -#include - -namespace Catch { - - struct ReporterConfig { - explicit ReporterConfig( IConfigPtr const& _fullConfig ); - - ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ); - - std::ostream& stream() const; - IConfigPtr fullConfig() const; - - private: - std::ostream* m_stream; - IConfigPtr m_fullConfig; - }; - - struct ReporterPreferences { - bool shouldRedirectStdOut = false; - }; - - template - struct LazyStat : Option { - LazyStat& operator=( T const& _value ) { - Option::operator=( _value ); - used = false; - return *this; - } - void reset() { - Option::reset(); - used = false; - } - bool used = false; - }; - - struct TestRunInfo { - TestRunInfo( std::string const& _name ); - std::string name; - }; - struct GroupInfo { - GroupInfo( std::string const& _name, - std::size_t _groupIndex, - std::size_t _groupsCount ); - - std::string name; - std::size_t groupIndex; - std::size_t groupsCounts; - }; - - struct AssertionStats { - AssertionStats( AssertionResult const& _assertionResult, - std::vector const& _infoMessages, - Totals const& _totals ); - - AssertionStats( AssertionStats const& ) = default; - AssertionStats( AssertionStats && ) = default; - AssertionStats& operator = ( AssertionStats const& ) = default; - AssertionStats& operator = ( AssertionStats && ) = default; - virtual ~AssertionStats(); - - AssertionResult assertionResult; - std::vector infoMessages; - Totals totals; - }; - - struct SectionStats { - SectionStats( SectionInfo const& _sectionInfo, - Counts const& _assertions, - double _durationInSeconds, - bool _missingAssertions ); - SectionStats( SectionStats const& ) = default; - SectionStats( SectionStats && ) = default; - SectionStats& operator = ( SectionStats const& ) = default; - SectionStats& operator = ( SectionStats && ) = default; - virtual ~SectionStats(); - - SectionInfo sectionInfo; - Counts assertions; - double durationInSeconds; - bool missingAssertions; - }; - - struct TestCaseStats { - TestCaseStats( TestCaseInfo const& _testInfo, - Totals const& _totals, - std::string const& _stdOut, - std::string const& _stdErr, - bool _aborting ); - - TestCaseStats( TestCaseStats const& ) = default; - TestCaseStats( TestCaseStats && ) = default; - TestCaseStats& operator = ( TestCaseStats const& ) = default; - TestCaseStats& operator = ( TestCaseStats && ) = default; - virtual ~TestCaseStats(); - - TestCaseInfo testInfo; - Totals totals; - std::string stdOut; - std::string stdErr; - bool aborting; - }; - - struct TestGroupStats { - TestGroupStats( GroupInfo const& _groupInfo, - Totals const& _totals, - bool _aborting ); - TestGroupStats( GroupInfo const& _groupInfo ); - - TestGroupStats( TestGroupStats const& ) = default; - TestGroupStats( TestGroupStats && ) = default; - TestGroupStats& operator = ( TestGroupStats const& ) = default; - TestGroupStats& operator = ( TestGroupStats && ) = default; - virtual ~TestGroupStats(); - - GroupInfo groupInfo; - Totals totals; - bool aborting; - }; - - struct TestRunStats { - TestRunStats( TestRunInfo const& _runInfo, - Totals const& _totals, - bool _aborting ); - - TestRunStats( TestRunStats const& ) = default; - TestRunStats( TestRunStats && ) = default; - TestRunStats& operator = ( TestRunStats const& ) = default; - TestRunStats& operator = ( TestRunStats && ) = default; - virtual ~TestRunStats(); - - TestRunInfo runInfo; - Totals totals; - bool aborting; - }; - - struct BenchmarkInfo { - std::string name; - }; - struct BenchmarkStats { - BenchmarkInfo info; - std::size_t iterations; - uint64_t elapsedTimeInNanoseconds; - }; - - struct IStreamingReporter { - virtual ~IStreamingReporter() = default; - - // Implementing class must also provide the following static methods: - // static std::string getDescription(); - // static std::set getSupportedVerbosities() - - virtual ReporterPreferences getPreferences() const = 0; - - virtual void noMatchingTestCases( std::string const& spec ) = 0; - - virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; - virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0; - - virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; - virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; - - // *** experimental *** - virtual void benchmarkStarting( BenchmarkInfo const& ) {} - - virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; - - // The return value indicates if the messages buffer should be cleared: - virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0; - - // *** experimental *** - virtual void benchmarkEnded( BenchmarkStats const& ) {} - - virtual void sectionEnded( SectionStats const& sectionStats ) = 0; - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; - virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; - - virtual void skipTest( TestCaseInfo const& testInfo ) = 0; - - // Default empty implementation provided - virtual void fatalErrorEncountered( StringRef name ); - - virtual bool isMulti() const; - }; - using IStreamingReporterPtr = std::unique_ptr; - - struct IReporterFactory { - virtual ~IReporterFactory(); - virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0; - virtual std::string getDescription() const = 0; - }; - using IReporterFactoryPtr = std::shared_ptr; - - struct IReporterRegistry { - using FactoryMap = std::map; - using Listeners = std::vector; - - virtual ~IReporterRegistry(); - virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0; - virtual FactoryMap const& getFactories() const = 0; - virtual Listeners const& getListeners() const = 0; - }; - - void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ); - -} // end namespace Catch - -// end catch_interfaces_reporter.h -#include -#include -#include -#include -#include -#include -#include - -namespace Catch { - void prepareExpandedExpression(AssertionResult& result); - - // Returns double formatted as %.3f (format expected on output) - std::string getFormattedDuration( double duration ); - - template - struct StreamingReporterBase : IStreamingReporter { - - StreamingReporterBase( ReporterConfig const& _config ) - : m_config( _config.fullConfig() ), - stream( _config.stream() ) - { - m_reporterPrefs.shouldRedirectStdOut = false; - if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) - throw std::domain_error( "Verbosity level not supported by this reporter" ); - } - - ReporterPreferences getPreferences() const override { - return m_reporterPrefs; - } - - static std::set getSupportedVerbosities() { - return { Verbosity::Normal }; - } - - ~StreamingReporterBase() override = default; - - void noMatchingTestCases(std::string const&) override {} - - void testRunStarting(TestRunInfo const& _testRunInfo) override { - currentTestRunInfo = _testRunInfo; - } - void testGroupStarting(GroupInfo const& _groupInfo) override { - currentGroupInfo = _groupInfo; - } - - void testCaseStarting(TestCaseInfo const& _testInfo) override { - currentTestCaseInfo = _testInfo; - } - void sectionStarting(SectionInfo const& _sectionInfo) override { - m_sectionStack.push_back(_sectionInfo); - } - - void sectionEnded(SectionStats const& /* _sectionStats */) override { - m_sectionStack.pop_back(); - } - void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override { - currentTestCaseInfo.reset(); - } - void testGroupEnded(TestGroupStats const& /* _testGroupStats */) override { - currentGroupInfo.reset(); - } - void testRunEnded(TestRunStats const& /* _testRunStats */) override { - currentTestCaseInfo.reset(); - currentGroupInfo.reset(); - currentTestRunInfo.reset(); - } - - void skipTest(TestCaseInfo const&) override { - // Don't do anything with this by default. - // It can optionally be overridden in the derived class. - } - - IConfigPtr m_config; - std::ostream& stream; - - LazyStat currentTestRunInfo; - LazyStat currentGroupInfo; - LazyStat currentTestCaseInfo; - - std::vector m_sectionStack; - ReporterPreferences m_reporterPrefs; - }; - - template - struct CumulativeReporterBase : IStreamingReporter { - template - struct Node { - explicit Node( T const& _value ) : value( _value ) {} - virtual ~Node() {} - - using ChildNodes = std::vector>; - T value; - ChildNodes children; - }; - struct SectionNode { - explicit SectionNode(SectionStats const& _stats) : stats(_stats) {} - virtual ~SectionNode() = default; - - bool operator == (SectionNode const& other) const { - return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; - } - bool operator == (std::shared_ptr const& other) const { - return operator==(*other); - } - - SectionStats stats; - using ChildSections = std::vector>; - using Assertions = std::vector; - ChildSections childSections; - Assertions assertions; - std::string stdOut; - std::string stdErr; - }; - - struct BySectionInfo { - BySectionInfo( SectionInfo const& other ) : m_other( other ) {} - BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} - bool operator() (std::shared_ptr const& node) const { - return ((node->stats.sectionInfo.name == m_other.name) && - (node->stats.sectionInfo.lineInfo == m_other.lineInfo)); - } - void operator=(BySectionInfo const&) = delete; - - private: - SectionInfo const& m_other; - }; - - using TestCaseNode = Node; - using TestGroupNode = Node; - using TestRunNode = Node; - - CumulativeReporterBase( ReporterConfig const& _config ) - : m_config( _config.fullConfig() ), - stream( _config.stream() ) - { - m_reporterPrefs.shouldRedirectStdOut = false; - if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) - throw std::domain_error( "Verbosity level not supported by this reporter" ); - } - ~CumulativeReporterBase() override = default; - - ReporterPreferences getPreferences() const override { - return m_reporterPrefs; - } - - static std::set getSupportedVerbosities() { - return { Verbosity::Normal }; - } - - void testRunStarting( TestRunInfo const& ) override {} - void testGroupStarting( GroupInfo const& ) override {} - - void testCaseStarting( TestCaseInfo const& ) override {} - - void sectionStarting( SectionInfo const& sectionInfo ) override { - SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); - std::shared_ptr node; - if( m_sectionStack.empty() ) { - if( !m_rootSection ) - m_rootSection = std::make_shared( incompleteStats ); - node = m_rootSection; - } - else { - SectionNode& parentNode = *m_sectionStack.back(); - auto it = - std::find_if( parentNode.childSections.begin(), - parentNode.childSections.end(), - BySectionInfo( sectionInfo ) ); - if( it == parentNode.childSections.end() ) { - node = std::make_shared( incompleteStats ); - parentNode.childSections.push_back( node ); - } - else - node = *it; - } - m_sectionStack.push_back( node ); - m_deepestSection = std::move(node); - } - - void assertionStarting(AssertionInfo const&) override {} - - bool assertionEnded(AssertionStats const& assertionStats) override { - assert(!m_sectionStack.empty()); - // AssertionResult holds a pointer to a temporary DecomposedExpression, - // which getExpandedExpression() calls to build the expression string. - // Our section stack copy of the assertionResult will likely outlive the - // temporary, so it must be expanded or discarded now to avoid calling - // a destroyed object later. - prepareExpandedExpression(const_cast( assertionStats.assertionResult ) ); - SectionNode& sectionNode = *m_sectionStack.back(); - sectionNode.assertions.push_back(assertionStats); - return true; - } - void sectionEnded(SectionStats const& sectionStats) override { - assert(!m_sectionStack.empty()); - SectionNode& node = *m_sectionStack.back(); - node.stats = sectionStats; - m_sectionStack.pop_back(); - } - void testCaseEnded(TestCaseStats const& testCaseStats) override { - auto node = std::make_shared(testCaseStats); - assert(m_sectionStack.size() == 0); - node->children.push_back(m_rootSection); - m_testCases.push_back(node); - m_rootSection.reset(); - - assert(m_deepestSection); - m_deepestSection->stdOut = testCaseStats.stdOut; - m_deepestSection->stdErr = testCaseStats.stdErr; - } - void testGroupEnded(TestGroupStats const& testGroupStats) override { - auto node = std::make_shared(testGroupStats); - node->children.swap(m_testCases); - m_testGroups.push_back(node); - } - void testRunEnded(TestRunStats const& testRunStats) override { - auto node = std::make_shared(testRunStats); - node->children.swap(m_testGroups); - m_testRuns.push_back(node); - testRunEndedCumulative(); - } - virtual void testRunEndedCumulative() = 0; - - void skipTest(TestCaseInfo const&) override {} - - IConfigPtr m_config; - std::ostream& stream; - std::vector m_assertions; - std::vector>> m_sections; - std::vector> m_testCases; - std::vector> m_testGroups; - - std::vector> m_testRuns; - - std::shared_ptr m_rootSection; - std::shared_ptr m_deepestSection; - std::vector> m_sectionStack; - ReporterPreferences m_reporterPrefs; - }; - - template - char const* getLineOfChars() { - static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; - if( !*line ) { - std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); - line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; - } - return line; - } - - struct TestEventListenerBase : StreamingReporterBase { - TestEventListenerBase( ReporterConfig const& _config ); - - void assertionStarting(AssertionInfo const&) override; - bool assertionEnded(AssertionStats const&) override; - }; - -} // end namespace Catch - -// end catch_reporter_bases.hpp -// start catch_console_colour.h - -namespace Catch { - - struct Colour { - enum Code { - None = 0, - - White, - Red, - Green, - Blue, - Cyan, - Yellow, - Grey, - - Bright = 0x10, - - BrightRed = Bright | Red, - BrightGreen = Bright | Green, - LightGrey = Bright | Grey, - BrightWhite = Bright | White, - BrightYellow = Bright | Yellow, - - // By intention - FileName = LightGrey, - Warning = BrightYellow, - ResultError = BrightRed, - ResultSuccess = BrightGreen, - ResultExpectedFailure = Warning, - - Error = BrightRed, - Success = Green, - - OriginalExpression = Cyan, - ReconstructedExpression = BrightYellow, - - SecondaryText = LightGrey, - Headers = White - }; - - // Use constructed object for RAII guard - Colour( Code _colourCode ); - Colour( Colour&& other ) noexcept; - Colour& operator=( Colour&& other ) noexcept; - ~Colour(); - - // Use static method for one-shot changes - static void use( Code _colourCode ); - - private: - bool m_moved = false; - }; - - std::ostream& operator << ( std::ostream& os, Colour const& ); - -} // end namespace Catch - -// end catch_console_colour.h -// start catch_reporter_registrars.hpp - - -namespace Catch { - - template - class ReporterRegistrar { - - class ReporterFactory : public IReporterFactory { - - virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { - return std::unique_ptr( new T( config ) ); - } - - virtual std::string getDescription() const override { - return T::getDescription(); - } - }; - - public: - - explicit ReporterRegistrar( std::string const& name ) { - getMutableRegistryHub().registerReporter( name, std::make_shared() ); - } - }; - - template - class ListenerRegistrar { - - class ListenerFactory : public IReporterFactory { - - virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { - return std::unique_ptr( new T( config ) ); - } - virtual std::string getDescription() const override { - return std::string(); - } - }; - - public: - - ListenerRegistrar() { - getMutableRegistryHub().registerListener( std::make_shared() ); - } - }; -} - -#if !defined(CATCH_CONFIG_DISABLE) - -#define CATCH_REGISTER_REPORTER( name, reporterType ) \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::ReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } \ - CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS - -#define CATCH_REGISTER_LISTENER( listenerType ) \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::ListenerRegistrar catch_internal_RegistrarFor##listenerType; } \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS -#else // CATCH_CONFIG_DISABLE - -#define CATCH_REGISTER_REPORTER(name, reporterType) -#define CATCH_REGISTER_LISTENER(listenerType) - -#endif // CATCH_CONFIG_DISABLE - -// end catch_reporter_registrars.hpp -// Allow users to base their work off existing reporters -// start catch_reporter_compact.h - -namespace Catch { - - struct CompactReporter : StreamingReporterBase { - - using StreamingReporterBase::StreamingReporterBase; - - ~CompactReporter() override; - - static std::string getDescription(); - - ReporterPreferences getPreferences() const override; - - void noMatchingTestCases(std::string const& spec) override; - - void assertionStarting(AssertionInfo const&) override; - - bool assertionEnded(AssertionStats const& _assertionStats) override; - - void sectionEnded(SectionStats const& _sectionStats) override; - - void testRunEnded(TestRunStats const& _testRunStats) override; - - }; - -} // end namespace Catch - -// end catch_reporter_compact.h -// start catch_reporter_console.h - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch - // Note that 4062 (not all labels are handled - // and default is missing) is enabled -#endif - -namespace Catch { - // Fwd decls - struct SummaryColumn; - class TablePrinter; - - struct ConsoleReporter : StreamingReporterBase { - std::unique_ptr m_tablePrinter; - - ConsoleReporter(ReporterConfig const& config); - ~ConsoleReporter() override; - static std::string getDescription(); - - void noMatchingTestCases(std::string const& spec) override; - - void assertionStarting(AssertionInfo const&) override; - - bool assertionEnded(AssertionStats const& _assertionStats) override; - - void sectionStarting(SectionInfo const& _sectionInfo) override; - void sectionEnded(SectionStats const& _sectionStats) override; - - void benchmarkStarting(BenchmarkInfo const& info) override; - void benchmarkEnded(BenchmarkStats const& stats) override; - - void testCaseEnded(TestCaseStats const& _testCaseStats) override; - void testGroupEnded(TestGroupStats const& _testGroupStats) override; - void testRunEnded(TestRunStats const& _testRunStats) override; - - private: - - void lazyPrint(); - - void lazyPrintWithoutClosingBenchmarkTable(); - void lazyPrintRunInfo(); - void lazyPrintGroupInfo(); - void printTestCaseAndSectionHeader(); - - void printClosedHeader(std::string const& _name); - void printOpenHeader(std::string const& _name); - - // if string has a : in first line will set indent to follow it on - // subsequent lines - void printHeaderString(std::string const& _string, std::size_t indent = 0); - - void printTotals(Totals const& totals); - void printSummaryRow(std::string const& label, std::vector const& cols, std::size_t row); - - void printTotalsDivider(Totals const& totals); - void printSummaryDivider(); - - private: - bool m_headerPrinted = false; - }; - -} // end namespace Catch - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif - -// end catch_reporter_console.h -// start catch_reporter_junit.h - -// start catch_xmlwriter.h - -#include - -namespace Catch { - - class XmlEncode { - public: - enum ForWhat { ForTextNodes, ForAttributes }; - - XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes ); - - void encodeTo( std::ostream& os ) const; - - friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ); - - private: - std::string m_str; - ForWhat m_forWhat; - }; - - class XmlWriter { - public: - - class ScopedElement { - public: - ScopedElement( XmlWriter* writer ); - - ScopedElement( ScopedElement&& other ) noexcept; - ScopedElement& operator=( ScopedElement&& other ) noexcept; - - ~ScopedElement(); - - ScopedElement& writeText( std::string const& text, bool indent = true ); - - template - ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { - m_writer->writeAttribute( name, attribute ); - return *this; - } - - private: - mutable XmlWriter* m_writer = nullptr; - }; - - XmlWriter( std::ostream& os = Catch::cout() ); - ~XmlWriter(); - - XmlWriter( XmlWriter const& ) = delete; - XmlWriter& operator=( XmlWriter const& ) = delete; - - XmlWriter& startElement( std::string const& name ); - - ScopedElement scopedElement( std::string const& name ); - - XmlWriter& endElement(); - - XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ); - - XmlWriter& writeAttribute( std::string const& name, bool attribute ); - - template - XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { - ReusableStringStream rss; - rss << attribute; - return writeAttribute( name, rss.str() ); - } - - XmlWriter& writeText( std::string const& text, bool indent = true ); - - XmlWriter& writeComment( std::string const& text ); - - void writeStylesheetRef( std::string const& url ); - - XmlWriter& writeBlankLine(); - - void ensureTagClosed(); - - private: - - void writeDeclaration(); - - void newlineIfNecessary(); - - bool m_tagIsOpen = false; - bool m_needsNewline = false; - std::vector m_tags; - std::string m_indent; - std::ostream& m_os; - }; - -} - -// end catch_xmlwriter.h -namespace Catch { - - class JunitReporter : public CumulativeReporterBase { - public: - JunitReporter(ReporterConfig const& _config); - - ~JunitReporter() override; - - static std::string getDescription(); - - void noMatchingTestCases(std::string const& /*spec*/) override; - - void testRunStarting(TestRunInfo const& runInfo) override; - - void testGroupStarting(GroupInfo const& groupInfo) override; - - void testCaseStarting(TestCaseInfo const& testCaseInfo) override; - bool assertionEnded(AssertionStats const& assertionStats) override; - - void testCaseEnded(TestCaseStats const& testCaseStats) override; - - void testGroupEnded(TestGroupStats const& testGroupStats) override; - - void testRunEndedCumulative() override; - - void writeGroup(TestGroupNode const& groupNode, double suiteTime); - - void writeTestCase(TestCaseNode const& testCaseNode); - - void writeSection(std::string const& className, - std::string const& rootName, - SectionNode const& sectionNode); - - void writeAssertions(SectionNode const& sectionNode); - void writeAssertion(AssertionStats const& stats); - - XmlWriter xml; - Timer suiteTimer; - std::string stdOutForSuite; - std::string stdErrForSuite; - unsigned int unexpectedExceptions = 0; - bool m_okToFail = false; - }; - -} // end namespace Catch - -// end catch_reporter_junit.h -// start catch_reporter_xml.h - -namespace Catch { - class XmlReporter : public StreamingReporterBase { - public: - XmlReporter(ReporterConfig const& _config); - - ~XmlReporter() override; - - static std::string getDescription(); - - virtual std::string getStylesheetRef() const; - - void writeSourceInfo(SourceLineInfo const& sourceInfo); - - public: // StreamingReporterBase - - void noMatchingTestCases(std::string const& s) override; - - void testRunStarting(TestRunInfo const& testInfo) override; - - void testGroupStarting(GroupInfo const& groupInfo) override; - - void testCaseStarting(TestCaseInfo const& testInfo) override; - - void sectionStarting(SectionInfo const& sectionInfo) override; - - void assertionStarting(AssertionInfo const&) override; - - bool assertionEnded(AssertionStats const& assertionStats) override; - - void sectionEnded(SectionStats const& sectionStats) override; - - void testCaseEnded(TestCaseStats const& testCaseStats) override; - - void testGroupEnded(TestGroupStats const& testGroupStats) override; - - void testRunEnded(TestRunStats const& testRunStats) override; - - private: - Timer m_testCaseTimer; - XmlWriter m_xml; - int m_sectionDepth = 0; - }; - -} // end namespace Catch - -// end catch_reporter_xml.h - -// end catch_external_interfaces.h -#endif - -#endif // ! CATCH_CONFIG_IMPL_ONLY - -#ifdef CATCH_IMPL -// start catch_impl.hpp - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wweak-vtables" -#endif - -// Keep these here for external reporters -// start catch_test_case_tracker.h - -#include -#include -#include - -namespace Catch { -namespace TestCaseTracking { - - struct NameAndLocation { - std::string name; - SourceLineInfo location; - - NameAndLocation( std::string const& _name, SourceLineInfo const& _location ); - }; - - struct ITracker; - - using ITrackerPtr = std::shared_ptr; - - struct ITracker { - virtual ~ITracker(); - - // static queries - virtual NameAndLocation const& nameAndLocation() const = 0; - - // dynamic queries - virtual bool isComplete() const = 0; // Successfully completed or failed - virtual bool isSuccessfullyCompleted() const = 0; - virtual bool isOpen() const = 0; // Started but not complete - virtual bool hasChildren() const = 0; - - virtual ITracker& parent() = 0; - - // actions - virtual void close() = 0; // Successfully complete - virtual void fail() = 0; - virtual void markAsNeedingAnotherRun() = 0; - - virtual void addChild( ITrackerPtr const& child ) = 0; - virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0; - virtual void openChild() = 0; - - // Debug/ checking - virtual bool isSectionTracker() const = 0; - virtual bool isIndexTracker() const = 0; - }; - - class TrackerContext { - - enum RunState { - NotStarted, - Executing, - CompletedCycle - }; - - ITrackerPtr m_rootTracker; - ITracker* m_currentTracker = nullptr; - RunState m_runState = NotStarted; - - public: - - static TrackerContext& instance(); - - ITracker& startRun(); - void endRun(); - - void startCycle(); - void completeCycle(); - - bool completedCycle() const; - ITracker& currentTracker(); - void setCurrentTracker( ITracker* tracker ); - }; - - class TrackerBase : public ITracker { - protected: - enum CycleState { - NotStarted, - Executing, - ExecutingChildren, - NeedsAnotherRun, - CompletedSuccessfully, - Failed - }; - - class TrackerHasName { - NameAndLocation m_nameAndLocation; - public: - TrackerHasName( NameAndLocation const& nameAndLocation ); - bool operator ()( ITrackerPtr const& tracker ) const; - }; - - using Children = std::vector; - NameAndLocation m_nameAndLocation; - TrackerContext& m_ctx; - ITracker* m_parent; - Children m_children; - CycleState m_runState = NotStarted; - - public: - TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); - - NameAndLocation const& nameAndLocation() const override; - bool isComplete() const override; - bool isSuccessfullyCompleted() const override; - bool isOpen() const override; - bool hasChildren() const override; - - void addChild( ITrackerPtr const& child ) override; - - ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override; - ITracker& parent() override; - - void openChild() override; - - bool isSectionTracker() const override; - bool isIndexTracker() const override; - - void open(); - - void close() override; - void fail() override; - void markAsNeedingAnotherRun() override; - - private: - void moveToParent(); - void moveToThis(); - }; - - class SectionTracker : public TrackerBase { - std::vector m_filters; - public: - SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); - - bool isSectionTracker() const override; - - static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ); - - void tryOpen(); - - void addInitialFilters( std::vector const& filters ); - void addNextFilters( std::vector const& filters ); - }; - - class IndexTracker : public TrackerBase { - int m_size; - int m_index = -1; - public: - IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ); - - bool isIndexTracker() const override; - void close() override; - - static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ); - - int index() const; - - void moveNext(); - }; - -} // namespace TestCaseTracking - -using TestCaseTracking::ITracker; -using TestCaseTracking::TrackerContext; -using TestCaseTracking::SectionTracker; -using TestCaseTracking::IndexTracker; - -} // namespace Catch - -// end catch_test_case_tracker.h - -// start catch_leak_detector.h - -namespace Catch { - - struct LeakDetector { - LeakDetector(); - }; - -} -// end catch_leak_detector.h -// Cpp files will be included in the single-header file here -// start catch_approx.cpp - -#include -#include - -namespace { - -// Performs equivalent check of std::fabs(lhs - rhs) <= margin -// But without the subtraction to allow for INFINITY in comparison -bool marginComparison(double lhs, double rhs, double margin) { - return (lhs + margin >= rhs) && (rhs + margin >= lhs); -} - -} - -namespace Catch { -namespace Detail { - - Approx::Approx ( double value ) - : m_epsilon( std::numeric_limits::epsilon()*100 ), - m_margin( 0.0 ), - m_scale( 0.0 ), - m_value( value ) - {} - - Approx Approx::custom() { - return Approx( 0 ); - } - - std::string Approx::toString() const { - ReusableStringStream rss; - rss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; - return rss.str(); - } - - bool Approx::equalityComparisonImpl(const double other) const { - // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value - // Thanks to Richard Harris for his help refining the scaled margin value - return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value))); - } - -} // end namespace Detail - -std::string StringMaker::convert(Catch::Detail::Approx const& value) { - return value.toString(); -} - -} // end namespace Catch -// end catch_approx.cpp -// start catch_assertionhandler.cpp - -// start catch_context.h - -#include - -namespace Catch { - - struct IResultCapture; - struct IRunner; - struct IConfig; - struct IMutableContext; - - using IConfigPtr = std::shared_ptr; - - struct IContext - { - virtual ~IContext(); - - virtual IResultCapture* getResultCapture() = 0; - virtual IRunner* getRunner() = 0; - virtual IConfigPtr const& getConfig() const = 0; - }; - - struct IMutableContext : IContext - { - virtual ~IMutableContext(); - virtual void setResultCapture( IResultCapture* resultCapture ) = 0; - virtual void setRunner( IRunner* runner ) = 0; - virtual void setConfig( IConfigPtr const& config ) = 0; - - private: - static IMutableContext *currentContext; - friend IMutableContext& getCurrentMutableContext(); - friend void cleanUpContext(); - static void createContext(); - }; - - inline IMutableContext& getCurrentMutableContext() - { - if( !IMutableContext::currentContext ) - IMutableContext::createContext(); - return *IMutableContext::currentContext; - } - - inline IContext& getCurrentContext() - { - return getCurrentMutableContext(); - } - - void cleanUpContext(); -} - -// end catch_context.h -// start catch_debugger.h - -namespace Catch { - bool isDebuggerActive(); -} - -#ifdef CATCH_PLATFORM_MAC - - #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ - -#elif defined(CATCH_PLATFORM_LINUX) - // If we can use inline assembler, do it because this allows us to break - // directly at the location of the failing check instead of breaking inside - // raise() called from it, i.e. one stack frame below. - #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) - #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */ - #else // Fall back to the generic way. - #include - - #define CATCH_TRAP() raise(SIGTRAP) - #endif -#elif defined(_MSC_VER) - #define CATCH_TRAP() __debugbreak() -#elif defined(__MINGW32__) - extern "C" __declspec(dllimport) void __stdcall DebugBreak(); - #define CATCH_TRAP() DebugBreak() -#endif - -#ifdef CATCH_TRAP - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } -#else - namespace Catch { - inline void doNothing() {} - } - #define CATCH_BREAK_INTO_DEBUGGER() Catch::doNothing() -#endif - -// end catch_debugger.h -// start catch_run_context.h - -// start catch_fatal_condition.h - -// start catch_windows_h_proxy.h - - -#if defined(CATCH_PLATFORM_WINDOWS) - -#if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) -# define CATCH_DEFINED_NOMINMAX -# define NOMINMAX -#endif -#if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) -# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -#endif - -#ifdef __AFXDLL -#include -#else -#include -#endif - -#ifdef CATCH_DEFINED_NOMINMAX -# undef NOMINMAX -#endif -#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN -# undef WIN32_LEAN_AND_MEAN -#endif - -#endif // defined(CATCH_PLATFORM_WINDOWS) - -// end catch_windows_h_proxy.h -#if defined( CATCH_CONFIG_WINDOWS_SEH ) - -namespace Catch { - - struct FatalConditionHandler { - - static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo); - FatalConditionHandler(); - static void reset(); - ~FatalConditionHandler(); - - private: - static bool isSet; - static ULONG guaranteeSize; - static PVOID exceptionHandlerHandle; - }; - -} // namespace Catch - -#elif defined ( CATCH_CONFIG_POSIX_SIGNALS ) - -#include - -namespace Catch { - - struct FatalConditionHandler { - - static bool isSet; - static struct sigaction oldSigActions[]; - static stack_t oldSigStack; - static char altStackMem[]; - - static void handleSignal( int sig ); - - FatalConditionHandler(); - ~FatalConditionHandler(); - static void reset(); - }; - -} // namespace Catch - -#else - -namespace Catch { - struct FatalConditionHandler { - void reset(); - }; -} - -#endif - -// end catch_fatal_condition.h -#include - -namespace Catch { - - struct IMutableContext; - - /////////////////////////////////////////////////////////////////////////// - - class RunContext : public IResultCapture, public IRunner { - - public: - RunContext( RunContext const& ) = delete; - RunContext& operator =( RunContext const& ) = delete; - - explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr&& reporter ); - - ~RunContext() override; - - void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ); - void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ); - - Totals runTest(TestCase const& testCase); - - IConfigPtr config() const; - IStreamingReporter& reporter() const; - - public: // IResultCapture - - // Assertion handlers - void handleExpr - ( AssertionInfo const& info, - ITransientExpression const& expr, - AssertionReaction& reaction ) override; - void handleMessage - ( AssertionInfo const& info, - ResultWas::OfType resultType, - StringRef const& message, - AssertionReaction& reaction ) override; - void handleUnexpectedExceptionNotThrown - ( AssertionInfo const& info, - AssertionReaction& reaction ) override; - void handleUnexpectedInflightException - ( AssertionInfo const& info, - std::string const& message, - AssertionReaction& reaction ) override; - void handleIncomplete - ( AssertionInfo const& info ) override; - void handleNonExpr - ( AssertionInfo const &info, - ResultWas::OfType resultType, - AssertionReaction &reaction ) override; - - bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override; - - void sectionEnded( SectionEndInfo const& endInfo ) override; - void sectionEndedEarly( SectionEndInfo const& endInfo ) override; - - void benchmarkStarting( BenchmarkInfo const& info ) override; - void benchmarkEnded( BenchmarkStats const& stats ) override; - - void pushScopedMessage( MessageInfo const& message ) override; - void popScopedMessage( MessageInfo const& message ) override; - - std::string getCurrentTestName() const override; - - const AssertionResult* getLastResult() const override; - - void exceptionEarlyReported() override; - - void handleFatalErrorCondition( StringRef message ) override; - - bool lastAssertionPassed() override; - - void assertionPassed() override; - - public: - // !TBD We need to do this another way! - bool aborting() const final; - - private: - - void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ); - void invokeActiveTestCase(); - - void resetAssertionInfo(); - bool testForMissingAssertions( Counts& assertions ); - - void assertionEnded( AssertionResult const& result ); - void reportExpr - ( AssertionInfo const &info, - ResultWas::OfType resultType, - ITransientExpression const *expr, - bool negated ); - - void populateReaction( AssertionReaction& reaction ); - - private: - - void handleUnfinishedSections(); - - TestRunInfo m_runInfo; - IMutableContext& m_context; - TestCase const* m_activeTestCase = nullptr; - ITracker* m_testCaseTracker; - Option m_lastResult; - - IConfigPtr m_config; - Totals m_totals; - IStreamingReporterPtr m_reporter; - std::vector m_messages; - AssertionInfo m_lastAssertionInfo; - std::vector m_unfinishedSections; - std::vector m_activeSections; - TrackerContext m_trackerContext; - bool m_lastAssertionPassed = false; - bool m_shouldReportUnexpected = true; - bool m_includeSuccessfulResults; - }; - -} // end namespace Catch - -// end catch_run_context.h -namespace Catch { - - auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& { - expr.streamReconstructedExpression( os ); - return os; - } - - LazyExpression::LazyExpression( bool isNegated ) - : m_isNegated( isNegated ) - {} - - LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {} - - LazyExpression::operator bool() const { - return m_transientExpression != nullptr; - } - - auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& { - if( lazyExpr.m_isNegated ) - os << "!"; - - if( lazyExpr ) { - if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() ) - os << "(" << *lazyExpr.m_transientExpression << ")"; - else - os << *lazyExpr.m_transientExpression; - } - else { - os << "{** error - unchecked empty expression requested **}"; - } - return os; - } - - AssertionHandler::AssertionHandler - ( StringRef macroName, - SourceLineInfo const& lineInfo, - StringRef capturedExpression, - ResultDisposition::Flags resultDisposition ) - : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition }, - m_resultCapture( getResultCapture() ) - {} - - void AssertionHandler::handleExpr( ITransientExpression const& expr ) { - m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction ); - } - void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) { - m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction ); - } - - auto AssertionHandler::allowThrows() const -> bool { - return getCurrentContext().getConfig()->allowThrows(); - } - - void AssertionHandler::complete() { - setCompleted(); - if( m_reaction.shouldDebugBreak ) { - - // If you find your debugger stopping you here then go one level up on the - // call-stack for the code that caused it (typically a failed assertion) - - // (To go back to the test and change execution, jump over the throw, next) - CATCH_BREAK_INTO_DEBUGGER(); - } - if( m_reaction.shouldThrow ) - throw Catch::TestFailureException(); - } - void AssertionHandler::setCompleted() { - m_completed = true; - } - - void AssertionHandler::handleUnexpectedInflightException() { - m_resultCapture.handleUnexpectedInflightException( m_assertionInfo, Catch::translateActiveException(), m_reaction ); - } - - void AssertionHandler::handleExceptionThrownAsExpected() { - m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); - } - void AssertionHandler::handleExceptionNotThrownAsExpected() { - m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); - } - - void AssertionHandler::handleUnexpectedExceptionNotThrown() { - m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction ); - } - - void AssertionHandler::handleThrowingCallSkipped() { - m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); - } - - // This is the overload that takes a string and infers the Equals matcher from it - // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp - void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { - handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); - } - -} // namespace Catch -// end catch_assertionhandler.cpp -// start catch_assertionresult.cpp - -namespace Catch { - AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): - lazyExpression(_lazyExpression), - resultType(_resultType) {} - - std::string AssertionResultData::reconstructExpression() const { - - if( reconstructedExpression.empty() ) { - if( lazyExpression ) { - ReusableStringStream rss; - rss << lazyExpression; - reconstructedExpression = rss.str(); - } - } - return reconstructedExpression; - } - - AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) - : m_info( info ), - m_resultData( data ) - {} - - // Result was a success - bool AssertionResult::succeeded() const { - return Catch::isOk( m_resultData.resultType ); - } - - // Result was a success, or failure is suppressed - bool AssertionResult::isOk() const { - return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); - } - - ResultWas::OfType AssertionResult::getResultType() const { - return m_resultData.resultType; - } - - bool AssertionResult::hasExpression() const { - return m_info.capturedExpression[0] != 0; - } - - bool AssertionResult::hasMessage() const { - return !m_resultData.message.empty(); - } - - std::string AssertionResult::getExpression() const { - if( isFalseTest( m_info.resultDisposition ) ) - return "!(" + m_info.capturedExpression + ")"; - else - return m_info.capturedExpression; - } - - std::string AssertionResult::getExpressionInMacro() const { - std::string expr; - if( m_info.macroName[0] == 0 ) - expr = m_info.capturedExpression; - else { - expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); - expr += m_info.macroName; - expr += "( "; - expr += m_info.capturedExpression; - expr += " )"; - } - return expr; - } - - bool AssertionResult::hasExpandedExpression() const { - return hasExpression() && getExpandedExpression() != getExpression(); - } - - std::string AssertionResult::getExpandedExpression() const { - std::string expr = m_resultData.reconstructExpression(); - return expr.empty() - ? getExpression() - : expr; - } - - std::string AssertionResult::getMessage() const { - return m_resultData.message; - } - SourceLineInfo AssertionResult::getSourceInfo() const { - return m_info.lineInfo; - } - - StringRef AssertionResult::getTestMacroName() const { - return m_info.macroName; - } - -} // end namespace Catch -// end catch_assertionresult.cpp -// start catch_benchmark.cpp - -namespace Catch { - - auto BenchmarkLooper::getResolution() -> uint64_t { - return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple(); - } - - void BenchmarkLooper::reportStart() { - getResultCapture().benchmarkStarting( { m_name } ); - } - auto BenchmarkLooper::needsMoreIterations() -> bool { - auto elapsed = m_timer.getElapsedNanoseconds(); - - // Exponentially increasing iterations until we're confident in our timer resolution - if( elapsed < m_resolution ) { - m_iterationsToRun *= 10; - return true; - } - - getResultCapture().benchmarkEnded( { { m_name }, m_count, elapsed } ); - return false; - } - -} // end namespace Catch -// end catch_benchmark.cpp -// start catch_capture_matchers.cpp - -namespace Catch { - - using StringMatcher = Matchers::Impl::MatcherBase; - - // This is the general overload that takes a any string matcher - // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers - // the Equals matcher (so the header does not mention matchers) - void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) { - std::string exceptionMessage = Catch::translateActiveException(); - MatchExpr expr( exceptionMessage, matcher, matcherString ); - handler.handleExpr( expr ); - } - -} // namespace Catch -// end catch_capture_matchers.cpp -// start catch_commandline.cpp - -// start catch_commandline.h - -// start catch_clara.h - -// Use Catch's value for console width (store Clara's off to the side, if present) -#ifdef CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#endif -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1 - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wweak-vtables" -#pragma clang diagnostic ignored "-Wexit-time-destructors" -#pragma clang diagnostic ignored "-Wshadow" -#endif - -// start clara.hpp -// Copyright 2017 Two Blue Cubes Ltd. All rights reserved. -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// See https://github.com/philsquared/Clara for more details - -// Clara v1.1.4 - - -#ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80 -#endif - -#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH -#endif - -#ifndef CLARA_CONFIG_OPTIONAL_TYPE -#ifdef __has_include -#if __has_include() && __cplusplus >= 201703L -#include -#define CLARA_CONFIG_OPTIONAL_TYPE std::optional -#endif -#endif -#endif - -// ----------- #included from clara_textflow.hpp ----------- - -// TextFlowCpp -// -// A single-header library for wrapping and laying out basic text, by Phil Nash -// -// This work is licensed under the BSD 2-Clause license. -// See the accompanying LICENSE file, or the one at https://opensource.org/licenses/BSD-2-Clause -// -// This project is hosted at https://github.com/philsquared/textflowcpp - - -#include -#include -#include -#include - -#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80 -#endif - -namespace Catch { namespace clara { namespace TextFlow { - - inline auto isWhitespace( char c ) -> bool { - static std::string chars = " \t\n\r"; - return chars.find( c ) != std::string::npos; - } - inline auto isBreakableBefore( char c ) -> bool { - static std::string chars = "[({<|"; - return chars.find( c ) != std::string::npos; - } - inline auto isBreakableAfter( char c ) -> bool { - static std::string chars = "])}>.,:;*+-=&/\\"; - return chars.find( c ) != std::string::npos; - } - - class Columns; - - class Column { - std::vector m_strings; - size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; - size_t m_indent = 0; - size_t m_initialIndent = std::string::npos; - - public: - class iterator { - friend Column; - - Column const& m_column; - size_t m_stringIndex = 0; - size_t m_pos = 0; - - size_t m_len = 0; - size_t m_end = 0; - bool m_suffix = false; - - iterator( Column const& column, size_t stringIndex ) - : m_column( column ), - m_stringIndex( stringIndex ) - {} - - auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } - - auto isBoundary( size_t at ) const -> bool { - assert( at > 0 ); - assert( at <= line().size() ); - - return at == line().size() || - ( isWhitespace( line()[at] ) && !isWhitespace( line()[at-1] ) ) || - isBreakableBefore( line()[at] ) || - isBreakableAfter( line()[at-1] ); - } - - void calcLength() { - assert( m_stringIndex < m_column.m_strings.size() ); - - m_suffix = false; - auto width = m_column.m_width-indent(); - m_end = m_pos; - while( m_end < line().size() && line()[m_end] != '\n' ) - ++m_end; - - if( m_end < m_pos + width ) { - m_len = m_end - m_pos; - } - else { - size_t len = width; - while (len > 0 && !isBoundary(m_pos + len)) - --len; - while (len > 0 && isWhitespace( line()[m_pos + len - 1] )) - --len; - - if (len > 0) { - m_len = len; - } else { - m_suffix = true; - m_len = width - 1; - } - } - } - - auto indent() const -> size_t { - auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; - return initial == std::string::npos ? m_column.m_indent : initial; - } - - auto addIndentAndSuffix(std::string const &plain) const -> std::string { - return std::string( indent(), ' ' ) + (m_suffix ? plain + "-" : plain); - } - - public: - explicit iterator( Column const& column ) : m_column( column ) { - assert( m_column.m_width > m_column.m_indent ); - assert( m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent ); - calcLength(); - if( m_len == 0 ) - m_stringIndex++; // Empty string - } - - auto operator *() const -> std::string { - assert( m_stringIndex < m_column.m_strings.size() ); - assert( m_pos <= m_end ); - if( m_pos + m_column.m_width < m_end ) - return addIndentAndSuffix(line().substr(m_pos, m_len)); - else - return addIndentAndSuffix(line().substr(m_pos, m_end - m_pos)); - } - - auto operator ++() -> iterator& { - m_pos += m_len; - if( m_pos < line().size() && line()[m_pos] == '\n' ) - m_pos += 1; - else - while( m_pos < line().size() && isWhitespace( line()[m_pos] ) ) - ++m_pos; - - if( m_pos == line().size() ) { - m_pos = 0; - ++m_stringIndex; - } - if( m_stringIndex < m_column.m_strings.size() ) - calcLength(); - return *this; - } - auto operator ++(int) -> iterator { - iterator prev( *this ); - operator++(); - return prev; - } - - auto operator ==( iterator const& other ) const -> bool { - return - m_pos == other.m_pos && - m_stringIndex == other.m_stringIndex && - &m_column == &other.m_column; - } - auto operator !=( iterator const& other ) const -> bool { - return !operator==( other ); - } - }; - using const_iterator = iterator; - - explicit Column( std::string const& text ) { m_strings.push_back( text ); } - - auto width( size_t newWidth ) -> Column& { - assert( newWidth > 0 ); - m_width = newWidth; - return *this; - } - auto indent( size_t newIndent ) -> Column& { - m_indent = newIndent; - return *this; - } - auto initialIndent( size_t newIndent ) -> Column& { - m_initialIndent = newIndent; - return *this; - } - - auto width() const -> size_t { return m_width; } - auto begin() const -> iterator { return iterator( *this ); } - auto end() const -> iterator { return { *this, m_strings.size() }; } - - inline friend std::ostream& operator << ( std::ostream& os, Column const& col ) { - bool first = true; - for( auto line : col ) { - if( first ) - first = false; - else - os << "\n"; - os << line; - } - return os; - } - - auto operator + ( Column const& other ) -> Columns; - - auto toString() const -> std::string { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - }; - - class Spacer : public Column { - - public: - explicit Spacer( size_t spaceWidth ) : Column( "" ) { - width( spaceWidth ); - } - }; - - class Columns { - std::vector m_columns; - - public: - - class iterator { - friend Columns; - struct EndTag {}; - - std::vector const& m_columns; - std::vector m_iterators; - size_t m_activeIterators; - - iterator( Columns const& columns, EndTag ) - : m_columns( columns.m_columns ), - m_activeIterators( 0 ) - { - m_iterators.reserve( m_columns.size() ); - - for( auto const& col : m_columns ) - m_iterators.push_back( col.end() ); - } - - public: - explicit iterator( Columns const& columns ) - : m_columns( columns.m_columns ), - m_activeIterators( m_columns.size() ) - { - m_iterators.reserve( m_columns.size() ); - - for( auto const& col : m_columns ) - m_iterators.push_back( col.begin() ); - } - - auto operator ==( iterator const& other ) const -> bool { - return m_iterators == other.m_iterators; - } - auto operator !=( iterator const& other ) const -> bool { - return m_iterators != other.m_iterators; - } - auto operator *() const -> std::string { - std::string row, padding; - - for( size_t i = 0; i < m_columns.size(); ++i ) { - auto width = m_columns[i].width(); - if( m_iterators[i] != m_columns[i].end() ) { - std::string col = *m_iterators[i]; - row += padding + col; - if( col.size() < width ) - padding = std::string( width - col.size(), ' ' ); - else - padding = ""; - } - else { - padding += std::string( width, ' ' ); - } - } - return row; - } - auto operator ++() -> iterator& { - for( size_t i = 0; i < m_columns.size(); ++i ) { - if (m_iterators[i] != m_columns[i].end()) - ++m_iterators[i]; - } - return *this; - } - auto operator ++(int) -> iterator { - iterator prev( *this ); - operator++(); - return prev; - } - }; - using const_iterator = iterator; - - auto begin() const -> iterator { return iterator( *this ); } - auto end() const -> iterator { return { *this, iterator::EndTag() }; } - - auto operator += ( Column const& col ) -> Columns& { - m_columns.push_back( col ); - return *this; - } - auto operator + ( Column const& col ) -> Columns { - Columns combined = *this; - combined += col; - return combined; - } - - inline friend std::ostream& operator << ( std::ostream& os, Columns const& cols ) { - - bool first = true; - for( auto line : cols ) { - if( first ) - first = false; - else - os << "\n"; - os << line; - } - return os; - } - - auto toString() const -> std::string { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - }; - - inline auto Column::operator + ( Column const& other ) -> Columns { - Columns cols; - cols += *this; - cols += other; - return cols; - } -}}} // namespace Catch::clara::TextFlow - -// ----------- end of #include from clara_textflow.hpp ----------- -// ........... back in clara.hpp - -#include -#include -#include - -#if !defined(CATCH_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) ) -#define CATCH_PLATFORM_WINDOWS -#endif - -namespace Catch { namespace clara { -namespace detail { - - // Traits for extracting arg and return type of lambdas (for single argument lambdas) - template - struct UnaryLambdaTraits : UnaryLambdaTraits {}; - - template - struct UnaryLambdaTraits { - static const bool isValid = false; - }; - - template - struct UnaryLambdaTraits { - static const bool isValid = true; - using ArgType = typename std::remove_const::type>::type; - using ReturnType = ReturnT; - }; - - class TokenStream; - - // Transport for raw args (copied from main args, or supplied via init list for testing) - class Args { - friend TokenStream; - std::string m_exeName; - std::vector m_args; - - public: - Args( int argc, char const* const* argv ) - : m_exeName(argv[0]), - m_args(argv + 1, argv + argc) {} - - Args( std::initializer_list args ) - : m_exeName( *args.begin() ), - m_args( args.begin()+1, args.end() ) - {} - - auto exeName() const -> std::string { - return m_exeName; - } - }; - - // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string - // may encode an option + its argument if the : or = form is used - enum class TokenType { - Option, Argument - }; - struct Token { - TokenType type; - std::string token; - }; - - inline auto isOptPrefix( char c ) -> bool { - return c == '-' -#ifdef CATCH_PLATFORM_WINDOWS - || c == '/' -#endif - ; - } - - // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled - class TokenStream { - using Iterator = std::vector::const_iterator; - Iterator it; - Iterator itEnd; - std::vector m_tokenBuffer; - - void loadBuffer() { - m_tokenBuffer.resize( 0 ); - - // Skip any empty strings - while( it != itEnd && it->empty() ) - ++it; - - if( it != itEnd ) { - auto const &next = *it; - if( isOptPrefix( next[0] ) ) { - auto delimiterPos = next.find_first_of( " :=" ); - if( delimiterPos != std::string::npos ) { - m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } ); - m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } ); - } else { - if( next[1] != '-' && next.size() > 2 ) { - std::string opt = "- "; - for( size_t i = 1; i < next.size(); ++i ) { - opt[1] = next[i]; - m_tokenBuffer.push_back( { TokenType::Option, opt } ); - } - } else { - m_tokenBuffer.push_back( { TokenType::Option, next } ); - } - } - } else { - m_tokenBuffer.push_back( { TokenType::Argument, next } ); - } - } - } - - public: - explicit TokenStream( Args const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {} - - TokenStream( Iterator it, Iterator itEnd ) : it( it ), itEnd( itEnd ) { - loadBuffer(); - } - - explicit operator bool() const { - return !m_tokenBuffer.empty() || it != itEnd; - } - - auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } - - auto operator*() const -> Token { - assert( !m_tokenBuffer.empty() ); - return m_tokenBuffer.front(); - } - - auto operator->() const -> Token const * { - assert( !m_tokenBuffer.empty() ); - return &m_tokenBuffer.front(); - } - - auto operator++() -> TokenStream & { - if( m_tokenBuffer.size() >= 2 ) { - m_tokenBuffer.erase( m_tokenBuffer.begin() ); - } else { - if( it != itEnd ) - ++it; - loadBuffer(); - } - return *this; - } - }; - - class ResultBase { - public: - enum Type { - Ok, LogicError, RuntimeError - }; - - protected: - ResultBase( Type type ) : m_type( type ) {} - virtual ~ResultBase() = default; - - virtual void enforceOk() const = 0; - - Type m_type; - }; - - template - class ResultValueBase : public ResultBase { - public: - auto value() const -> T const & { - enforceOk(); - return m_value; - } - - protected: - ResultValueBase( Type type ) : ResultBase( type ) {} - - ResultValueBase( ResultValueBase const &other ) : ResultBase( other ) { - if( m_type == ResultBase::Ok ) - new( &m_value ) T( other.m_value ); - } - - ResultValueBase( Type, T const &value ) : ResultBase( Ok ) { - new( &m_value ) T( value ); - } - - auto operator=( ResultValueBase const &other ) -> ResultValueBase & { - if( m_type == ResultBase::Ok ) - m_value.~T(); - ResultBase::operator=(other); - if( m_type == ResultBase::Ok ) - new( &m_value ) T( other.m_value ); - return *this; - } - - ~ResultValueBase() override { - if( m_type == Ok ) - m_value.~T(); - } - - union { - T m_value; - }; - }; - - template<> - class ResultValueBase : public ResultBase { - protected: - using ResultBase::ResultBase; - }; - - template - class BasicResult : public ResultValueBase { - public: - template - explicit BasicResult( BasicResult const &other ) - : ResultValueBase( other.type() ), - m_errorMessage( other.errorMessage() ) - { - assert( type() != ResultBase::Ok ); - } - - template - static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; } - static auto ok() -> BasicResult { return { ResultBase::Ok }; } - static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; } - static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; } - - explicit operator bool() const { return m_type == ResultBase::Ok; } - auto type() const -> ResultBase::Type { return m_type; } - auto errorMessage() const -> std::string { return m_errorMessage; } - - protected: - void enforceOk() const override { - - // Errors shouldn't reach this point, but if they do - // the actual error message will be in m_errorMessage - assert( m_type != ResultBase::LogicError ); - assert( m_type != ResultBase::RuntimeError ); - if( m_type != ResultBase::Ok ) - std::abort(); - } - - std::string m_errorMessage; // Only populated if resultType is an error - - BasicResult( ResultBase::Type type, std::string const &message ) - : ResultValueBase(type), - m_errorMessage(message) - { - assert( m_type != ResultBase::Ok ); - } - - using ResultValueBase::ResultValueBase; - using ResultBase::m_type; - }; - - enum class ParseResultType { - Matched, NoMatch, ShortCircuitAll, ShortCircuitSame - }; - - class ParseState { - public: - - ParseState( ParseResultType type, TokenStream const &remainingTokens ) - : m_type(type), - m_remainingTokens( remainingTokens ) - {} - - auto type() const -> ParseResultType { return m_type; } - auto remainingTokens() const -> TokenStream { return m_remainingTokens; } - - private: - ParseResultType m_type; - TokenStream m_remainingTokens; - }; - - using Result = BasicResult; - using ParserResult = BasicResult; - using InternalParseResult = BasicResult; - - struct HelpColumns { - std::string left; - std::string right; - }; - - template - inline auto convertInto( std::string const &source, T& target ) -> ParserResult { - std::stringstream ss; - ss << source; - ss >> target; - if( ss.fail() ) - return ParserResult::runtimeError( "Unable to convert '" + source + "' to destination type" ); - else - return ParserResult::ok( ParseResultType::Matched ); - } - inline auto convertInto( std::string const &source, std::string& target ) -> ParserResult { - target = source; - return ParserResult::ok( ParseResultType::Matched ); - } - inline auto convertInto( std::string const &source, bool &target ) -> ParserResult { - std::string srcLC = source; - std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), []( char c ) { return static_cast( ::tolower(c) ); } ); - if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on") - target = true; - else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off") - target = false; - else - return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); - return ParserResult::ok( ParseResultType::Matched ); - } -#ifdef CLARA_CONFIG_OPTIONAL_TYPE - template - inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE& target ) -> ParserResult { - T temp; - auto result = convertInto( source, temp ); - if( result ) - target = std::move(temp); - return result; - } -#endif // CLARA_CONFIG_OPTIONAL_TYPE - - struct NonCopyable { - NonCopyable() = default; - NonCopyable( NonCopyable const & ) = delete; - NonCopyable( NonCopyable && ) = delete; - NonCopyable &operator=( NonCopyable const & ) = delete; - NonCopyable &operator=( NonCopyable && ) = delete; - }; - - struct BoundRef : NonCopyable { - virtual ~BoundRef() = default; - virtual auto isContainer() const -> bool { return false; } - virtual auto isFlag() const -> bool { return false; } - }; - struct BoundValueRefBase : BoundRef { - virtual auto setValue( std::string const &arg ) -> ParserResult = 0; - }; - struct BoundFlagRefBase : BoundRef { - virtual auto setFlag( bool flag ) -> ParserResult = 0; - virtual auto isFlag() const -> bool { return true; } - }; - - template - struct BoundValueRef : BoundValueRefBase { - T &m_ref; - - explicit BoundValueRef( T &ref ) : m_ref( ref ) {} - - auto setValue( std::string const &arg ) -> ParserResult override { - return convertInto( arg, m_ref ); - } - }; - - template - struct BoundValueRef> : BoundValueRefBase { - std::vector &m_ref; - - explicit BoundValueRef( std::vector &ref ) : m_ref( ref ) {} - - auto isContainer() const -> bool override { return true; } - - auto setValue( std::string const &arg ) -> ParserResult override { - T temp; - auto result = convertInto( arg, temp ); - if( result ) - m_ref.push_back( temp ); - return result; - } - }; - - struct BoundFlagRef : BoundFlagRefBase { - bool &m_ref; - - explicit BoundFlagRef( bool &ref ) : m_ref( ref ) {} - - auto setFlag( bool flag ) -> ParserResult override { - m_ref = flag; - return ParserResult::ok( ParseResultType::Matched ); - } - }; - - template - struct LambdaInvoker { - static_assert( std::is_same::value, "Lambda must return void or clara::ParserResult" ); - - template - static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { - return lambda( arg ); - } - }; - - template<> - struct LambdaInvoker { - template - static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { - lambda( arg ); - return ParserResult::ok( ParseResultType::Matched ); - } - }; - - template - inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult { - ArgType temp{}; - auto result = convertInto( arg, temp ); - return !result - ? result - : LambdaInvoker::ReturnType>::invoke( lambda, temp ); - } - - template - struct BoundLambda : BoundValueRefBase { - L m_lambda; - - static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); - explicit BoundLambda( L const &lambda ) : m_lambda( lambda ) {} - - auto setValue( std::string const &arg ) -> ParserResult override { - return invokeLambda::ArgType>( m_lambda, arg ); - } - }; - - template - struct BoundFlagLambda : BoundFlagRefBase { - L m_lambda; - - static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); - static_assert( std::is_same::ArgType, bool>::value, "flags must be boolean" ); - - explicit BoundFlagLambda( L const &lambda ) : m_lambda( lambda ) {} - - auto setFlag( bool flag ) -> ParserResult override { - return LambdaInvoker::ReturnType>::invoke( m_lambda, flag ); - } - }; - - enum class Optionality { Optional, Required }; - - struct Parser; - - class ParserBase { - public: - virtual ~ParserBase() = default; - virtual auto validate() const -> Result { return Result::ok(); } - virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; - virtual auto cardinality() const -> size_t { return 1; } - - auto parse( Args const &args ) const -> InternalParseResult { - return parse( args.exeName(), TokenStream( args ) ); - } - }; - - template - class ComposableParserImpl : public ParserBase { - public: - template - auto operator|( T const &other ) const -> Parser; - - template - auto operator+( T const &other ) const -> Parser; - }; - - // Common code and state for Args and Opts - template - class ParserRefImpl : public ComposableParserImpl { - protected: - Optionality m_optionality = Optionality::Optional; - std::shared_ptr m_ref; - std::string m_hint; - std::string m_description; - - explicit ParserRefImpl( std::shared_ptr const &ref ) : m_ref( ref ) {} - - public: - template - ParserRefImpl( T &ref, std::string const &hint ) - : m_ref( std::make_shared>( ref ) ), - m_hint( hint ) - {} - - template - ParserRefImpl( LambdaT const &ref, std::string const &hint ) - : m_ref( std::make_shared>( ref ) ), - m_hint(hint) - {} - - auto operator()( std::string const &description ) -> DerivedT & { - m_description = description; - return static_cast( *this ); - } - - auto optional() -> DerivedT & { - m_optionality = Optionality::Optional; - return static_cast( *this ); - }; - - auto required() -> DerivedT & { - m_optionality = Optionality::Required; - return static_cast( *this ); - }; - - auto isOptional() const -> bool { - return m_optionality == Optionality::Optional; - } - - auto cardinality() const -> size_t override { - if( m_ref->isContainer() ) - return 0; - else - return 1; - } - - auto hint() const -> std::string { return m_hint; } - }; - - class ExeName : public ComposableParserImpl { - std::shared_ptr m_name; - std::shared_ptr m_ref; - - template - static auto makeRef(LambdaT const &lambda) -> std::shared_ptr { - return std::make_shared>( lambda) ; - } - - public: - ExeName() : m_name( std::make_shared( "" ) ) {} - - explicit ExeName( std::string &ref ) : ExeName() { - m_ref = std::make_shared>( ref ); - } - - template - explicit ExeName( LambdaT const& lambda ) : ExeName() { - m_ref = std::make_shared>( lambda ); - } - - // The exe name is not parsed out of the normal tokens, but is handled specially - auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { - return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); - } - - auto name() const -> std::string { return *m_name; } - auto set( std::string const& newName ) -> ParserResult { - - auto lastSlash = newName.find_last_of( "\\/" ); - auto filename = ( lastSlash == std::string::npos ) - ? newName - : newName.substr( lastSlash+1 ); - - *m_name = filename; - if( m_ref ) - return m_ref->setValue( filename ); - else - return ParserResult::ok( ParseResultType::Matched ); - } - }; - - class Arg : public ParserRefImpl { - public: - using ParserRefImpl::ParserRefImpl; - - auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override { - auto validationResult = validate(); - if( !validationResult ) - return InternalParseResult( validationResult ); - - auto remainingTokens = tokens; - auto const &token = *remainingTokens; - if( token.type != TokenType::Argument ) - return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); - - assert( !m_ref->isFlag() ); - auto valueRef = static_cast( m_ref.get() ); - - auto result = valueRef->setValue( remainingTokens->token ); - if( !result ) - return InternalParseResult( result ); - else - return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); - } - }; - - inline auto normaliseOpt( std::string const &optName ) -> std::string { -#ifdef CATCH_PLATFORM_WINDOWS - if( optName[0] == '/' ) - return "-" + optName.substr( 1 ); - else -#endif - return optName; - } - - class Opt : public ParserRefImpl { - protected: - std::vector m_optNames; - - public: - template - explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared>( ref ) ) {} - - explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared( ref ) ) {} - - template - Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} - - template - Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} - - auto operator[]( std::string const &optName ) -> Opt & { - m_optNames.push_back( optName ); - return *this; - } - - auto getHelpColumns() const -> std::vector { - std::ostringstream oss; - bool first = true; - for( auto const &opt : m_optNames ) { - if (first) - first = false; - else - oss << ", "; - oss << opt; - } - if( !m_hint.empty() ) - oss << " <" << m_hint << ">"; - return { { oss.str(), m_description } }; - } - - auto isMatch( std::string const &optToken ) const -> bool { - auto normalisedToken = normaliseOpt( optToken ); - for( auto const &name : m_optNames ) { - if( normaliseOpt( name ) == normalisedToken ) - return true; - } - return false; - } - - using ParserBase::parse; - - auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { - auto validationResult = validate(); - if( !validationResult ) - return InternalParseResult( validationResult ); - - auto remainingTokens = tokens; - if( remainingTokens && remainingTokens->type == TokenType::Option ) { - auto const &token = *remainingTokens; - if( isMatch(token.token ) ) { - if( m_ref->isFlag() ) { - auto flagRef = static_cast( m_ref.get() ); - auto result = flagRef->setFlag( true ); - if( !result ) - return InternalParseResult( result ); - if( result.value() == ParseResultType::ShortCircuitAll ) - return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); - } else { - auto valueRef = static_cast( m_ref.get() ); - ++remainingTokens; - if( !remainingTokens ) - return InternalParseResult::runtimeError( "Expected argument following " + token.token ); - auto const &argToken = *remainingTokens; - if( argToken.type != TokenType::Argument ) - return InternalParseResult::runtimeError( "Expected argument following " + token.token ); - auto result = valueRef->setValue( argToken.token ); - if( !result ) - return InternalParseResult( result ); - if( result.value() == ParseResultType::ShortCircuitAll ) - return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); - } - return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); - } - } - return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); - } - - auto validate() const -> Result override { - if( m_optNames.empty() ) - return Result::logicError( "No options supplied to Opt" ); - for( auto const &name : m_optNames ) { - if( name.empty() ) - return Result::logicError( "Option name cannot be empty" ); -#ifdef CATCH_PLATFORM_WINDOWS - if( name[0] != '-' && name[0] != '/' ) - return Result::logicError( "Option name must begin with '-' or '/'" ); -#else - if( name[0] != '-' ) - return Result::logicError( "Option name must begin with '-'" ); -#endif - } - return ParserRefImpl::validate(); - } - }; - - struct Help : Opt { - Help( bool &showHelpFlag ) - : Opt([&]( bool flag ) { - showHelpFlag = flag; - return ParserResult::ok( ParseResultType::ShortCircuitAll ); - }) - { - static_cast( *this ) - ("display usage information") - ["-?"]["-h"]["--help"] - .optional(); - } - }; - - struct Parser : ParserBase { - - mutable ExeName m_exeName; - std::vector m_options; - std::vector m_args; - - auto operator|=( ExeName const &exeName ) -> Parser & { - m_exeName = exeName; - return *this; - } - - auto operator|=( Arg const &arg ) -> Parser & { - m_args.push_back(arg); - return *this; - } - - auto operator|=( Opt const &opt ) -> Parser & { - m_options.push_back(opt); - return *this; - } - - auto operator|=( Parser const &other ) -> Parser & { - m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); - m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); - return *this; - } - - template - auto operator|( T const &other ) const -> Parser { - return Parser( *this ) |= other; - } - - // Forward deprecated interface with '+' instead of '|' - template - auto operator+=( T const &other ) -> Parser & { return operator|=( other ); } - template - auto operator+( T const &other ) const -> Parser { return operator|( other ); } - - auto getHelpColumns() const -> std::vector { - std::vector cols; - for (auto const &o : m_options) { - auto childCols = o.getHelpColumns(); - cols.insert( cols.end(), childCols.begin(), childCols.end() ); - } - return cols; - } - - void writeToStream( std::ostream &os ) const { - if (!m_exeName.name().empty()) { - os << "usage:\n" << " " << m_exeName.name() << " "; - bool required = true, first = true; - for( auto const &arg : m_args ) { - if (first) - first = false; - else - os << " "; - if( arg.isOptional() && required ) { - os << "["; - required = false; - } - os << "<" << arg.hint() << ">"; - if( arg.cardinality() == 0 ) - os << " ... "; - } - if( !required ) - os << "]"; - if( !m_options.empty() ) - os << " options"; - os << "\n\nwhere options are:" << std::endl; - } - - auto rows = getHelpColumns(); - size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; - size_t optWidth = 0; - for( auto const &cols : rows ) - optWidth = (std::max)(optWidth, cols.left.size() + 2); - - optWidth = (std::min)(optWidth, consoleWidth/2); - - for( auto const &cols : rows ) { - auto row = - TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + - TextFlow::Spacer(4) + - TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); - os << row << std::endl; - } - } - - friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { - parser.writeToStream( os ); - return os; - } - - auto validate() const -> Result override { - for( auto const &opt : m_options ) { - auto result = opt.validate(); - if( !result ) - return result; - } - for( auto const &arg : m_args ) { - auto result = arg.validate(); - if( !result ) - return result; - } - return Result::ok(); - } - - using ParserBase::parse; - - auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override { - - struct ParserInfo { - ParserBase const* parser = nullptr; - size_t count = 0; - }; - const size_t totalParsers = m_options.size() + m_args.size(); - assert( totalParsers < 512 ); - // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do - ParserInfo parseInfos[512]; - - { - size_t i = 0; - for (auto const &opt : m_options) parseInfos[i++].parser = &opt; - for (auto const &arg : m_args) parseInfos[i++].parser = &arg; - } - - m_exeName.set( exeName ); - - auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); - while( result.value().remainingTokens() ) { - bool tokenParsed = false; - - for( size_t i = 0; i < totalParsers; ++i ) { - auto& parseInfo = parseInfos[i]; - if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) { - result = parseInfo.parser->parse(exeName, result.value().remainingTokens()); - if (!result) - return result; - if (result.value().type() != ParseResultType::NoMatch) { - tokenParsed = true; - ++parseInfo.count; - break; - } - } - } - - if( result.value().type() == ParseResultType::ShortCircuitAll ) - return result; - if( !tokenParsed ) - return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token ); - } - // !TBD Check missing required options - return result; - } - }; - - template - template - auto ComposableParserImpl::operator|( T const &other ) const -> Parser { - return Parser() | static_cast( *this ) | other; - } -} // namespace detail - -// A Combined parser -using detail::Parser; - -// A parser for options -using detail::Opt; - -// A parser for arguments -using detail::Arg; - -// Wrapper for argc, argv from main() -using detail::Args; - -// Specifies the name of the executable -using detail::ExeName; - -// Convenience wrapper for option parser that specifies the help option -using detail::Help; - -// enum of result types from a parse -using detail::ParseResultType; - -// Result type for parser operation -using detail::ParserResult; - -}} // namespace Catch::clara - -// end clara.hpp -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// Restore Clara's value for console width, if present -#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#endif - -// end catch_clara.h -namespace Catch { - - clara::Parser makeCommandLineParser( ConfigData& config ); - -} // end namespace Catch - -// end catch_commandline.h -#include -#include - -namespace Catch { - - clara::Parser makeCommandLineParser( ConfigData& config ) { - - using namespace clara; - - auto const setWarning = [&]( std::string const& warning ) { - auto warningSet = [&]() { - if( warning == "NoAssertions" ) - return WarnAbout::NoAssertions; - - if ( warning == "NoTests" ) - return WarnAbout::NoTests; - - return WarnAbout::Nothing; - }(); - - if (warningSet == WarnAbout::Nothing) - return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); - config.warnings = static_cast( config.warnings | warningSet ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const loadTestNamesFromFile = [&]( std::string const& filename ) { - std::ifstream f( filename.c_str() ); - if( !f.is_open() ) - return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); - - std::string line; - while( std::getline( f, line ) ) { - line = trim(line); - if( !line.empty() && !startsWith( line, '#' ) ) { - if( !startsWith( line, '"' ) ) - line = '"' + line + '"'; - config.testsOrTags.push_back( line + ',' ); - } - } - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setTestOrder = [&]( std::string const& order ) { - if( startsWith( "declared", order ) ) - config.runOrder = RunTests::InDeclarationOrder; - else if( startsWith( "lexical", order ) ) - config.runOrder = RunTests::InLexicographicalOrder; - else if( startsWith( "random", order ) ) - config.runOrder = RunTests::InRandomOrder; - else - return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setRngSeed = [&]( std::string const& seed ) { - if( seed != "time" ) - return clara::detail::convertInto( seed, config.rngSeed ); - config.rngSeed = static_cast( std::time(nullptr) ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setColourUsage = [&]( std::string const& useColour ) { - auto mode = toLower( useColour ); - - if( mode == "yes" ) - config.useColour = UseColour::Yes; - else if( mode == "no" ) - config.useColour = UseColour::No; - else if( mode == "auto" ) - config.useColour = UseColour::Auto; - else - return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setWaitForKeypress = [&]( std::string const& keypress ) { - auto keypressLc = toLower( keypress ); - if( keypressLc == "start" ) - config.waitForKeypress = WaitForKeypress::BeforeStart; - else if( keypressLc == "exit" ) - config.waitForKeypress = WaitForKeypress::BeforeExit; - else if( keypressLc == "both" ) - config.waitForKeypress = WaitForKeypress::BeforeStartAndExit; - else - return ParserResult::runtimeError( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setVerbosity = [&]( std::string const& verbosity ) { - auto lcVerbosity = toLower( verbosity ); - if( lcVerbosity == "quiet" ) - config.verbosity = Verbosity::Quiet; - else if( lcVerbosity == "normal" ) - config.verbosity = Verbosity::Normal; - else if( lcVerbosity == "high" ) - config.verbosity = Verbosity::High; - else - return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - - auto cli - = ExeName( config.processName ) - | Help( config.showHelp ) - | Opt( config.listTests ) - ["-l"]["--list-tests"] - ( "list all/matching test cases" ) - | Opt( config.listTags ) - ["-t"]["--list-tags"] - ( "list all/matching tags" ) - | Opt( config.showSuccessfulTests ) - ["-s"]["--success"] - ( "include successful tests in output" ) - | Opt( config.shouldDebugBreak ) - ["-b"]["--break"] - ( "break into debugger on failure" ) - | Opt( config.noThrow ) - ["-e"]["--nothrow"] - ( "skip exception tests" ) - | Opt( config.showInvisibles ) - ["-i"]["--invisibles"] - ( "show invisibles (tabs, newlines)" ) - | Opt( config.outputFilename, "filename" ) - ["-o"]["--out"] - ( "output filename" ) - | Opt( config.reporterNames, "name" ) - ["-r"]["--reporter"] - ( "reporter to use (defaults to console)" ) - | Opt( config.name, "name" ) - ["-n"]["--name"] - ( "suite name" ) - | Opt( [&]( bool ){ config.abortAfter = 1; } ) - ["-a"]["--abort"] - ( "abort at first failure" ) - | Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" ) - ["-x"]["--abortx"] - ( "abort after x failures" ) - | Opt( setWarning, "warning name" ) - ["-w"]["--warn"] - ( "enable warnings" ) - | Opt( [&]( bool flag ) { config.showDurations = flag ? ShowDurations::Always : ShowDurations::Never; }, "yes|no" ) - ["-d"]["--durations"] - ( "show test durations" ) - | Opt( loadTestNamesFromFile, "filename" ) - ["-f"]["--input-file"] - ( "load test names to run from a file" ) - | Opt( config.filenamesAsTags ) - ["-#"]["--filenames-as-tags"] - ( "adds a tag for the filename" ) - | Opt( config.sectionsToRun, "section name" ) - ["-c"]["--section"] - ( "specify section to run" ) - | Opt( setVerbosity, "quiet|normal|high" ) - ["-v"]["--verbosity"] - ( "set output verbosity" ) - | Opt( config.listTestNamesOnly ) - ["--list-test-names-only"] - ( "list all/matching test cases names only" ) - | Opt( config.listReporters ) - ["--list-reporters"] - ( "list all reporters" ) - | Opt( setTestOrder, "decl|lex|rand" ) - ["--order"] - ( "test case order (defaults to decl)" ) - | Opt( setRngSeed, "'time'|number" ) - ["--rng-seed"] - ( "set a specific seed for random numbers" ) - | Opt( setColourUsage, "yes|no" ) - ["--use-colour"] - ( "should output be colourised" ) - | Opt( config.libIdentify ) - ["--libidentify"] - ( "report name and version according to libidentify standard" ) - | Opt( setWaitForKeypress, "start|exit|both" ) - ["--wait-for-keypress"] - ( "waits for a keypress before exiting" ) - | Opt( config.benchmarkResolutionMultiple, "multiplier" ) - ["--benchmark-resolution-multiple"] - ( "multiple of clock resolution to run benchmarks" ) - - | Arg( config.testsOrTags, "test name|pattern|tags" ) - ( "which test or tests to use" ); - - return cli; - } - -} // end namespace Catch -// end catch_commandline.cpp -// start catch_common.cpp - -#include -#include - -namespace Catch { - - bool SourceLineInfo::empty() const noexcept { - return file[0] == '\0'; - } - bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept { - return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0); - } - bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept { - return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0)); - } - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { -#ifndef __GNUG__ - os << info.file << '(' << info.line << ')'; -#else - os << info.file << ':' << info.line; -#endif - return os; - } - - std::string StreamEndStop::operator+() const { - return std::string(); - } - - NonCopyable::NonCopyable() = default; - NonCopyable::~NonCopyable() = default; - -} -// end catch_common.cpp -// start catch_config.cpp - -// start catch_enforce.h - -#include - -#define CATCH_PREPARE_EXCEPTION( type, msg ) \ - type( ( Catch::ReusableStringStream() << msg ).str() ) -#define CATCH_INTERNAL_ERROR( msg ) \ - throw CATCH_PREPARE_EXCEPTION( std::logic_error, CATCH_INTERNAL_LINEINFO << ": Internal Catch error: " << msg); -#define CATCH_ERROR( msg ) \ - throw CATCH_PREPARE_EXCEPTION( std::domain_error, msg ) -#define CATCH_ENFORCE( condition, msg ) \ - do{ if( !(condition) ) CATCH_ERROR( msg ); } while(false) - -// end catch_enforce.h -namespace Catch { - - Config::Config( ConfigData const& data ) - : m_data( data ), - m_stream( openStream() ) - { - TestSpecParser parser(ITagAliasRegistry::get()); - if (data.testsOrTags.empty()) { - parser.parse("~[.]"); // All not hidden tests - } - else { - m_hasTestFilters = true; - for( auto const& testOrTags : data.testsOrTags ) - parser.parse( testOrTags ); - } - m_testSpec = parser.testSpec(); - } - - std::string const& Config::getFilename() const { - return m_data.outputFilename ; - } - - bool Config::listTests() const { return m_data.listTests; } - bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; } - bool Config::listTags() const { return m_data.listTags; } - bool Config::listReporters() const { return m_data.listReporters; } - - std::string Config::getProcessName() const { return m_data.processName; } - - std::vector const& Config::getReporterNames() const { return m_data.reporterNames; } - std::vector const& Config::getTestsOrTags() const { return m_data.testsOrTags; } - std::vector const& Config::getSectionsToRun() const { return m_data.sectionsToRun; } - - TestSpec const& Config::testSpec() const { return m_testSpec; } - bool Config::hasTestFilters() const { return m_hasTestFilters; } - - bool Config::showHelp() const { return m_data.showHelp; } - - // IConfig interface - bool Config::allowThrows() const { return !m_data.noThrow; } - std::ostream& Config::stream() const { return m_stream->stream(); } - std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } - bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; } - bool Config::warnAboutMissingAssertions() const { return !!(m_data.warnings & WarnAbout::NoAssertions); } - bool Config::warnAboutNoTests() const { return !!(m_data.warnings & WarnAbout::NoTests); } - ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; } - RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; } - unsigned int Config::rngSeed() const { return m_data.rngSeed; } - int Config::benchmarkResolutionMultiple() const { return m_data.benchmarkResolutionMultiple; } - UseColour::YesOrNo Config::useColour() const { return m_data.useColour; } - bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; } - int Config::abortAfter() const { return m_data.abortAfter; } - bool Config::showInvisibles() const { return m_data.showInvisibles; } - Verbosity Config::verbosity() const { return m_data.verbosity; } - - IStream const* Config::openStream() { - return Catch::makeStream(m_data.outputFilename); - } - -} // end namespace Catch -// end catch_config.cpp -// start catch_console_colour.cpp - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wexit-time-destructors" -#endif - -// start catch_errno_guard.h - -namespace Catch { - - class ErrnoGuard { - public: - ErrnoGuard(); - ~ErrnoGuard(); - private: - int m_oldErrno; - }; - -} - -// end catch_errno_guard.h -#include - -namespace Catch { - namespace { - - struct IColourImpl { - virtual ~IColourImpl() = default; - virtual void use( Colour::Code _colourCode ) = 0; - }; - - struct NoColourImpl : IColourImpl { - void use( Colour::Code ) {} - - static IColourImpl* instance() { - static NoColourImpl s_instance; - return &s_instance; - } - }; - - } // anon namespace -} // namespace Catch - -#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI ) -# ifdef CATCH_PLATFORM_WINDOWS -# define CATCH_CONFIG_COLOUR_WINDOWS -# else -# define CATCH_CONFIG_COLOUR_ANSI -# endif -#endif - -#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// - -namespace Catch { -namespace { - - class Win32ColourImpl : public IColourImpl { - public: - Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) - { - CONSOLE_SCREEN_BUFFER_INFO csbiInfo; - GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); - originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY ); - originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); - } - - virtual void use( Colour::Code _colourCode ) override { - switch( _colourCode ) { - case Colour::None: return setTextAttribute( originalForegroundAttributes ); - case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); - case Colour::Red: return setTextAttribute( FOREGROUND_RED ); - case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); - case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE ); - case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN ); - case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN ); - case Colour::Grey: return setTextAttribute( 0 ); - - case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY ); - case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); - case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); - case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); - case Colour::BrightYellow: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN ); - - case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); - - default: - CATCH_ERROR( "Unknown colour requested" ); - } - } - - private: - void setTextAttribute( WORD _textAttribute ) { - SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes ); - } - HANDLE stdoutHandle; - WORD originalForegroundAttributes; - WORD originalBackgroundAttributes; - }; - - IColourImpl* platformColourInstance() { - static Win32ColourImpl s_instance; - - IConfigPtr config = getCurrentContext().getConfig(); - UseColour::YesOrNo colourMode = config - ? config->useColour() - : UseColour::Auto; - if( colourMode == UseColour::Auto ) - colourMode = UseColour::Yes; - return colourMode == UseColour::Yes - ? &s_instance - : NoColourImpl::instance(); - } - -} // end anon namespace -} // end namespace Catch - -#elif defined( CATCH_CONFIG_COLOUR_ANSI ) ////////////////////////////////////// - -#include - -namespace Catch { -namespace { - - // use POSIX/ ANSI console terminal codes - // Thanks to Adam Strzelecki for original contribution - // (http://github.com/nanoant) - // https://github.com/philsquared/Catch/pull/131 - class PosixColourImpl : public IColourImpl { - public: - virtual void use( Colour::Code _colourCode ) override { - switch( _colourCode ) { - case Colour::None: - case Colour::White: return setColour( "[0m" ); - case Colour::Red: return setColour( "[0;31m" ); - case Colour::Green: return setColour( "[0;32m" ); - case Colour::Blue: return setColour( "[0;34m" ); - case Colour::Cyan: return setColour( "[0;36m" ); - case Colour::Yellow: return setColour( "[0;33m" ); - case Colour::Grey: return setColour( "[1;30m" ); - - case Colour::LightGrey: return setColour( "[0;37m" ); - case Colour::BrightRed: return setColour( "[1;31m" ); - case Colour::BrightGreen: return setColour( "[1;32m" ); - case Colour::BrightWhite: return setColour( "[1;37m" ); - case Colour::BrightYellow: return setColour( "[1;33m" ); - - case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); - default: CATCH_INTERNAL_ERROR( "Unknown colour requested" ); - } - } - static IColourImpl* instance() { - static PosixColourImpl s_instance; - return &s_instance; - } - - private: - void setColour( const char* _escapeCode ) { - Catch::cout() << '\033' << _escapeCode; - } - }; - - bool useColourOnPlatform() { - return -#ifdef CATCH_PLATFORM_MAC - !isDebuggerActive() && -#endif -#if !(defined(__DJGPP__) && defined(__STRICT_ANSI__)) - isatty(STDOUT_FILENO) -#else - false -#endif - ; - } - IColourImpl* platformColourInstance() { - ErrnoGuard guard; - IConfigPtr config = getCurrentContext().getConfig(); - UseColour::YesOrNo colourMode = config - ? config->useColour() - : UseColour::Auto; - if( colourMode == UseColour::Auto ) - colourMode = useColourOnPlatform() - ? UseColour::Yes - : UseColour::No; - return colourMode == UseColour::Yes - ? PosixColourImpl::instance() - : NoColourImpl::instance(); - } - -} // end anon namespace -} // end namespace Catch - -#else // not Windows or ANSI /////////////////////////////////////////////// - -namespace Catch { - - static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); } - -} // end namespace Catch - -#endif // Windows/ ANSI/ None - -namespace Catch { - - Colour::Colour( Code _colourCode ) { use( _colourCode ); } - Colour::Colour( Colour&& rhs ) noexcept { - m_moved = rhs.m_moved; - rhs.m_moved = true; - } - Colour& Colour::operator=( Colour&& rhs ) noexcept { - m_moved = rhs.m_moved; - rhs.m_moved = true; - return *this; - } - - Colour::~Colour(){ if( !m_moved ) use( None ); } - - void Colour::use( Code _colourCode ) { - static IColourImpl* impl = platformColourInstance(); - impl->use( _colourCode ); - } - - std::ostream& operator << ( std::ostream& os, Colour const& ) { - return os; - } - -} // end namespace Catch - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - -// end catch_console_colour.cpp -// start catch_context.cpp - -namespace Catch { - - class Context : public IMutableContext, NonCopyable { - - public: // IContext - virtual IResultCapture* getResultCapture() override { - return m_resultCapture; - } - virtual IRunner* getRunner() override { - return m_runner; - } - - virtual IConfigPtr const& getConfig() const override { - return m_config; - } - - virtual ~Context() override; - - public: // IMutableContext - virtual void setResultCapture( IResultCapture* resultCapture ) override { - m_resultCapture = resultCapture; - } - virtual void setRunner( IRunner* runner ) override { - m_runner = runner; - } - virtual void setConfig( IConfigPtr const& config ) override { - m_config = config; - } - - friend IMutableContext& getCurrentMutableContext(); - - private: - IConfigPtr m_config; - IRunner* m_runner = nullptr; - IResultCapture* m_resultCapture = nullptr; - }; - - IMutableContext *IMutableContext::currentContext = nullptr; - - void IMutableContext::createContext() - { - currentContext = new Context(); - } - - void cleanUpContext() { - delete IMutableContext::currentContext; - IMutableContext::currentContext = nullptr; - } - IContext::~IContext() = default; - IMutableContext::~IMutableContext() = default; - Context::~Context() = default; -} -// end catch_context.cpp -// start catch_debug_console.cpp - -// start catch_debug_console.h - -#include - -namespace Catch { - void writeToDebugConsole( std::string const& text ); -} - -// end catch_debug_console.h -#ifdef CATCH_PLATFORM_WINDOWS - - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - ::OutputDebugStringA( text.c_str() ); - } - } - -#else - - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - // !TBD: Need a version for Mac/ XCode and other IDEs - Catch::cout() << text; - } - } - -#endif // Platform -// end catch_debug_console.cpp -// start catch_debugger.cpp - -#ifdef CATCH_PLATFORM_MAC - -# include -# include -# include -# include -# include -# include -# include - -namespace Catch { - - // The following function is taken directly from the following technical note: - // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html - - // Returns true if the current process is being debugged (either - // running under the debugger or has a debugger attached post facto). - bool isDebuggerActive(){ - - int mib[4]; - struct kinfo_proc info; - std::size_t size; - - // Initialize the flags so that, if sysctl fails for some bizarre - // reason, we get a predictable result. - - info.kp_proc.p_flag = 0; - - // Initialize mib, which tells sysctl the info we want, in this case - // we're looking for information about a specific process ID. - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PID; - mib[3] = getpid(); - - // Call sysctl. - - size = sizeof(info); - if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) { - Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; - return false; - } - - // We're being debugged if the P_TRACED flag is set. - - return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); - } - } // namespace Catch - -#elif defined(CATCH_PLATFORM_LINUX) - #include - #include - - namespace Catch{ - // The standard POSIX way of detecting a debugger is to attempt to - // ptrace() the process, but this needs to be done from a child and not - // this process itself to still allow attaching to this process later - // if wanted, so is rather heavy. Under Linux we have the PID of the - // "debugger" (which doesn't need to be gdb, of course, it could also - // be strace, for example) in /proc/$PID/status, so just get it from - // there instead. - bool isDebuggerActive(){ - // Libstdc++ has a bug, where std::ifstream sets errno to 0 - // This way our users can properly assert over errno values - ErrnoGuard guard; - std::ifstream in("/proc/self/status"); - for( std::string line; std::getline(in, line); ) { - static const int PREFIX_LEN = 11; - if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) { - // We're traced if the PID is not 0 and no other PID starts - // with 0 digit, so it's enough to check for just a single - // character. - return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0'; - } - } - - return false; - } - } // namespace Catch -#elif defined(_MSC_VER) - extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - namespace Catch { - bool isDebuggerActive() { - return IsDebuggerPresent() != 0; - } - } -#elif defined(__MINGW32__) - extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - namespace Catch { - bool isDebuggerActive() { - return IsDebuggerPresent() != 0; - } - } -#else - namespace Catch { - bool isDebuggerActive() { return false; } - } -#endif // Platform -// end catch_debugger.cpp -// start catch_decomposer.cpp - -namespace Catch { - - ITransientExpression::~ITransientExpression() = default; - - void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) { - if( lhs.size() + rhs.size() < 40 && - lhs.find('\n') == std::string::npos && - rhs.find('\n') == std::string::npos ) - os << lhs << " " << op << " " << rhs; - else - os << lhs << "\n" << op << "\n" << rhs; - } -} -// end catch_decomposer.cpp -// start catch_errno_guard.cpp - -#include - -namespace Catch { - ErrnoGuard::ErrnoGuard():m_oldErrno(errno){} - ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; } -} -// end catch_errno_guard.cpp -// start catch_exception_translator_registry.cpp - -// start catch_exception_translator_registry.h - -#include -#include -#include - -namespace Catch { - - class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { - public: - ~ExceptionTranslatorRegistry(); - virtual void registerTranslator( const IExceptionTranslator* translator ); - virtual std::string translateActiveException() const override; - std::string tryTranslators() const; - - private: - std::vector> m_translators; - }; -} - -// end catch_exception_translator_registry.h -#ifdef __OBJC__ -#import "Foundation/Foundation.h" -#endif - -namespace Catch { - - ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() { - } - - void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) { - m_translators.push_back( std::unique_ptr( translator ) ); - } - - std::string ExceptionTranslatorRegistry::translateActiveException() const { - try { -#ifdef __OBJC__ - // In Objective-C try objective-c exceptions first - @try { - return tryTranslators(); - } - @catch (NSException *exception) { - return Catch::Detail::stringify( [exception description] ); - } -#else - // Compiling a mixed mode project with MSVC means that CLR - // exceptions will be caught in (...) as well. However, these - // do not fill-in std::current_exception and thus lead to crash - // when attempting rethrow. - // /EHa switch also causes structured exceptions to be caught - // here, but they fill-in current_exception properly, so - // at worst the output should be a little weird, instead of - // causing a crash. - if (std::current_exception() == nullptr) { - return "Non C++ exception. Possibly a CLR exception."; - } - return tryTranslators(); -#endif - } - catch( TestFailureException& ) { - std::rethrow_exception(std::current_exception()); - } - catch( std::exception& ex ) { - return ex.what(); - } - catch( std::string& msg ) { - return msg; - } - catch( const char* msg ) { - return msg; - } - catch(...) { - return "Unknown exception"; - } - } - - std::string ExceptionTranslatorRegistry::tryTranslators() const { - if( m_translators.empty() ) - std::rethrow_exception(std::current_exception()); - else - return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() ); - } -} -// end catch_exception_translator_registry.cpp -// start catch_fatal_condition.cpp - -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wmissing-field-initializers" -#endif - -#if defined( CATCH_CONFIG_WINDOWS_SEH ) || defined( CATCH_CONFIG_POSIX_SIGNALS ) - -namespace { - // Report the error condition - void reportFatal( char const * const message ) { - Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message ); - } -} - -#endif // signals/SEH handling - -#if defined( CATCH_CONFIG_WINDOWS_SEH ) - -namespace Catch { - struct SignalDefs { DWORD id; const char* name; }; - - // There is no 1-1 mapping between signals and windows exceptions. - // Windows can easily distinguish between SO and SigSegV, - // but SigInt, SigTerm, etc are handled differently. - static SignalDefs signalDefs[] = { - { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" }, - { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" }, - { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" }, - { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" }, - }; - - LONG CALLBACK FatalConditionHandler::handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { - for (auto const& def : signalDefs) { - if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) { - reportFatal(def.name); - } - } - // If its not an exception we care about, pass it along. - // This stops us from eating debugger breaks etc. - return EXCEPTION_CONTINUE_SEARCH; - } - - FatalConditionHandler::FatalConditionHandler() { - isSet = true; - // 32k seems enough for Catch to handle stack overflow, - // but the value was found experimentally, so there is no strong guarantee - guaranteeSize = 32 * 1024; - exceptionHandlerHandle = nullptr; - // Register as first handler in current chain - exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException); - // Pass in guarantee size to be filled - SetThreadStackGuarantee(&guaranteeSize); - } - - void FatalConditionHandler::reset() { - if (isSet) { - RemoveVectoredExceptionHandler(exceptionHandlerHandle); - SetThreadStackGuarantee(&guaranteeSize); - exceptionHandlerHandle = nullptr; - isSet = false; - } - } - - FatalConditionHandler::~FatalConditionHandler() { - reset(); - } - -bool FatalConditionHandler::isSet = false; -ULONG FatalConditionHandler::guaranteeSize = 0; -PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr; - -} // namespace Catch - -#elif defined( CATCH_CONFIG_POSIX_SIGNALS ) - -namespace Catch { - - struct SignalDefs { - int id; - const char* name; - }; - static SignalDefs signalDefs[] = { - { SIGINT, "SIGINT - Terminal interrupt signal" }, - { SIGILL, "SIGILL - Illegal instruction signal" }, - { SIGFPE, "SIGFPE - Floating point error signal" }, - { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, - { SIGTERM, "SIGTERM - Termination request signal" }, - { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } - }; - - void FatalConditionHandler::handleSignal( int sig ) { - char const * name = ""; - for (auto const& def : signalDefs) { - if (sig == def.id) { - name = def.name; - break; - } - } - reset(); - reportFatal(name); - raise( sig ); - } - - FatalConditionHandler::FatalConditionHandler() { - isSet = true; - stack_t sigStack; - sigStack.ss_sp = altStackMem; - sigStack.ss_size = SIGSTKSZ; - sigStack.ss_flags = 0; - sigaltstack(&sigStack, &oldSigStack); - struct sigaction sa = { }; - - sa.sa_handler = handleSignal; - sa.sa_flags = SA_ONSTACK; - for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) { - sigaction(signalDefs[i].id, &sa, &oldSigActions[i]); - } - } - - FatalConditionHandler::~FatalConditionHandler() { - reset(); - } - - void FatalConditionHandler::reset() { - if( isSet ) { - // Set signals back to previous values -- hopefully nobody overwrote them in the meantime - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) { - sigaction(signalDefs[i].id, &oldSigActions[i], nullptr); - } - // Return the old stack - sigaltstack(&oldSigStack, nullptr); - isSet = false; - } - } - - bool FatalConditionHandler::isSet = false; - struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {}; - stack_t FatalConditionHandler::oldSigStack = {}; - char FatalConditionHandler::altStackMem[SIGSTKSZ] = {}; - -} // namespace Catch - -#else - -namespace Catch { - void FatalConditionHandler::reset() {} -} - -#endif // signals/SEH handling - -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif -// end catch_fatal_condition.cpp -// start catch_interfaces_capture.cpp - -namespace Catch { - IResultCapture::~IResultCapture() = default; -} -// end catch_interfaces_capture.cpp -// start catch_interfaces_config.cpp - -namespace Catch { - IConfig::~IConfig() = default; -} -// end catch_interfaces_config.cpp -// start catch_interfaces_exception.cpp - -namespace Catch { - IExceptionTranslator::~IExceptionTranslator() = default; - IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default; -} -// end catch_interfaces_exception.cpp -// start catch_interfaces_registry_hub.cpp - -namespace Catch { - IRegistryHub::~IRegistryHub() = default; - IMutableRegistryHub::~IMutableRegistryHub() = default; -} -// end catch_interfaces_registry_hub.cpp -// start catch_interfaces_reporter.cpp - -// start catch_reporter_multi.h - -namespace Catch { - - class MultipleReporters : public IStreamingReporter { - using Reporters = std::vector; - Reporters m_reporters; - - public: - void add( IStreamingReporterPtr&& reporter ); - - public: // IStreamingReporter - - ReporterPreferences getPreferences() const override; - - void noMatchingTestCases( std::string const& spec ) override; - - static std::set getSupportedVerbosities(); - - void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override; - void benchmarkEnded( BenchmarkStats const& benchmarkStats ) override; - - void testRunStarting( TestRunInfo const& testRunInfo ) override; - void testGroupStarting( GroupInfo const& groupInfo ) override; - void testCaseStarting( TestCaseInfo const& testInfo ) override; - void sectionStarting( SectionInfo const& sectionInfo ) override; - void assertionStarting( AssertionInfo const& assertionInfo ) override; - - // The return value indicates if the messages buffer should be cleared: - bool assertionEnded( AssertionStats const& assertionStats ) override; - void sectionEnded( SectionStats const& sectionStats ) override; - void testCaseEnded( TestCaseStats const& testCaseStats ) override; - void testGroupEnded( TestGroupStats const& testGroupStats ) override; - void testRunEnded( TestRunStats const& testRunStats ) override; - - void skipTest( TestCaseInfo const& testInfo ) override; - bool isMulti() const override; - - }; - -} // end namespace Catch - -// end catch_reporter_multi.h -namespace Catch { - - ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig ) - : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} - - ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ) - : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} - - std::ostream& ReporterConfig::stream() const { return *m_stream; } - IConfigPtr ReporterConfig::fullConfig() const { return m_fullConfig; } - - TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {} - - GroupInfo::GroupInfo( std::string const& _name, - std::size_t _groupIndex, - std::size_t _groupsCount ) - : name( _name ), - groupIndex( _groupIndex ), - groupsCounts( _groupsCount ) - {} - - AssertionStats::AssertionStats( AssertionResult const& _assertionResult, - std::vector const& _infoMessages, - Totals const& _totals ) - : assertionResult( _assertionResult ), - infoMessages( _infoMessages ), - totals( _totals ) - { - assertionResult.m_resultData.lazyExpression.m_transientExpression = _assertionResult.m_resultData.lazyExpression.m_transientExpression; - - if( assertionResult.hasMessage() ) { - // Copy message into messages list. - // !TBD This should have been done earlier, somewhere - MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); - builder << assertionResult.getMessage(); - builder.m_info.message = builder.m_stream.str(); - - infoMessages.push_back( builder.m_info ); - } - } - - AssertionStats::~AssertionStats() = default; - - SectionStats::SectionStats( SectionInfo const& _sectionInfo, - Counts const& _assertions, - double _durationInSeconds, - bool _missingAssertions ) - : sectionInfo( _sectionInfo ), - assertions( _assertions ), - durationInSeconds( _durationInSeconds ), - missingAssertions( _missingAssertions ) - {} - - SectionStats::~SectionStats() = default; - - TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo, - Totals const& _totals, - std::string const& _stdOut, - std::string const& _stdErr, - bool _aborting ) - : testInfo( _testInfo ), - totals( _totals ), - stdOut( _stdOut ), - stdErr( _stdErr ), - aborting( _aborting ) - {} - - TestCaseStats::~TestCaseStats() = default; - - TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo, - Totals const& _totals, - bool _aborting ) - : groupInfo( _groupInfo ), - totals( _totals ), - aborting( _aborting ) - {} - - TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo ) - : groupInfo( _groupInfo ), - aborting( false ) - {} - - TestGroupStats::~TestGroupStats() = default; - - TestRunStats::TestRunStats( TestRunInfo const& _runInfo, - Totals const& _totals, - bool _aborting ) - : runInfo( _runInfo ), - totals( _totals ), - aborting( _aborting ) - {} - - TestRunStats::~TestRunStats() = default; - - void IStreamingReporter::fatalErrorEncountered( StringRef ) {} - bool IStreamingReporter::isMulti() const { return false; } - - IReporterFactory::~IReporterFactory() = default; - IReporterRegistry::~IReporterRegistry() = default; - - void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ) { - - if( !existingReporter ) { - existingReporter = std::move( additionalReporter ); - return; - } - - MultipleReporters* multi = nullptr; - - if( existingReporter->isMulti() ) { - multi = static_cast( existingReporter.get() ); - } - else { - auto newMulti = std::unique_ptr( new MultipleReporters ); - newMulti->add( std::move( existingReporter ) ); - multi = newMulti.get(); - existingReporter = std::move( newMulti ); - } - multi->add( std::move( additionalReporter ) ); - } - -} // end namespace Catch -// end catch_interfaces_reporter.cpp -// start catch_interfaces_runner.cpp - -namespace Catch { - IRunner::~IRunner() = default; -} -// end catch_interfaces_runner.cpp -// start catch_interfaces_testcase.cpp - -namespace Catch { - ITestInvoker::~ITestInvoker() = default; - ITestCaseRegistry::~ITestCaseRegistry() = default; -} -// end catch_interfaces_testcase.cpp -// start catch_leak_detector.cpp - -#ifdef CATCH_CONFIG_WINDOWS_CRTDBG -#include - -namespace Catch { - - LeakDetector::LeakDetector() { - int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - flag |= _CRTDBG_LEAK_CHECK_DF; - flag |= _CRTDBG_ALLOC_MEM_DF; - _CrtSetDbgFlag(flag); - _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); - _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); - // Change this to leaking allocation's number to break there - _CrtSetBreakAlloc(-1); - } -} - -#else - - Catch::LeakDetector::LeakDetector() {} - -#endif -// end catch_leak_detector.cpp -// start catch_list.cpp - -// start catch_list.h - -#include - -namespace Catch { - - std::size_t listTests( Config const& config ); - - std::size_t listTestsNamesOnly( Config const& config ); - - struct TagInfo { - void add( std::string const& spelling ); - std::string all() const; - - std::set spellings; - std::size_t count = 0; - }; - - std::size_t listTags( Config const& config ); - - std::size_t listReporters( Config const& /*config*/ ); - - Option list( Config const& config ); - -} // end namespace Catch - -// end catch_list.h -// start catch_text.h - -namespace Catch { - using namespace clara::TextFlow; -} - -// end catch_text.h -#include -#include -#include - -namespace Catch { - - std::size_t listTests( Config const& config ) { - TestSpec testSpec = config.testSpec(); - if( config.hasTestFilters() ) - Catch::cout() << "Matching test cases:\n"; - else { - Catch::cout() << "All available test cases:\n"; - } - - auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); - for( auto const& testCaseInfo : matchedTestCases ) { - Colour::Code colour = testCaseInfo.isHidden() - ? Colour::SecondaryText - : Colour::None; - Colour colourGuard( colour ); - - Catch::cout() << Column( testCaseInfo.name ).initialIndent( 2 ).indent( 4 ) << "\n"; - if( config.verbosity() >= Verbosity::High ) { - Catch::cout() << Column( Catch::Detail::stringify( testCaseInfo.lineInfo ) ).indent(4) << std::endl; - std::string description = testCaseInfo.description; - if( description.empty() ) - description = "(NO DESCRIPTION)"; - Catch::cout() << Column( description ).indent(4) << std::endl; - } - if( !testCaseInfo.tags.empty() ) - Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n"; - } - - if( !config.hasTestFilters() ) - Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl; - else - Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl; - return matchedTestCases.size(); - } - - std::size_t listTestsNamesOnly( Config const& config ) { - TestSpec testSpec = config.testSpec(); - std::size_t matchedTests = 0; - std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); - for( auto const& testCaseInfo : matchedTestCases ) { - matchedTests++; - if( startsWith( testCaseInfo.name, '#' ) ) - Catch::cout() << '"' << testCaseInfo.name << '"'; - else - Catch::cout() << testCaseInfo.name; - if ( config.verbosity() >= Verbosity::High ) - Catch::cout() << "\t@" << testCaseInfo.lineInfo; - Catch::cout() << std::endl; - } - return matchedTests; - } - - void TagInfo::add( std::string const& spelling ) { - ++count; - spellings.insert( spelling ); - } - - std::string TagInfo::all() const { - std::string out; - for( auto const& spelling : spellings ) - out += "[" + spelling + "]"; - return out; - } - - std::size_t listTags( Config const& config ) { - TestSpec testSpec = config.testSpec(); - if( config.hasTestFilters() ) - Catch::cout() << "Tags for matching test cases:\n"; - else { - Catch::cout() << "All available tags:\n"; - } - - std::map tagCounts; - - std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); - for( auto const& testCase : matchedTestCases ) { - for( auto const& tagName : testCase.getTestCaseInfo().tags ) { - std::string lcaseTagName = toLower( tagName ); - auto countIt = tagCounts.find( lcaseTagName ); - if( countIt == tagCounts.end() ) - countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; - countIt->second.add( tagName ); - } - } - - for( auto const& tagCount : tagCounts ) { - ReusableStringStream rss; - rss << " " << std::setw(2) << tagCount.second.count << " "; - auto str = rss.str(); - auto wrapper = Column( tagCount.second.all() ) - .initialIndent( 0 ) - .indent( str.size() ) - .width( CATCH_CONFIG_CONSOLE_WIDTH-10 ); - Catch::cout() << str << wrapper << '\n'; - } - Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl; - return tagCounts.size(); - } - - std::size_t listReporters( Config const& /*config*/ ) { - Catch::cout() << "Available reporters:\n"; - IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); - std::size_t maxNameLen = 0; - for( auto const& factoryKvp : factories ) - maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() ); - - for( auto const& factoryKvp : factories ) { - Catch::cout() - << Column( factoryKvp.first + ":" ) - .indent(2) - .width( 5+maxNameLen ) - + Column( factoryKvp.second->getDescription() ) - .initialIndent(0) - .indent(2) - .width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) - << "\n"; - } - Catch::cout() << std::endl; - return factories.size(); - } - - Option list( Config const& config ) { - Option listedCount; - if( config.listTests() ) - listedCount = listedCount.valueOr(0) + listTests( config ); - if( config.listTestNamesOnly() ) - listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config ); - if( config.listTags() ) - listedCount = listedCount.valueOr(0) + listTags( config ); - if( config.listReporters() ) - listedCount = listedCount.valueOr(0) + listReporters( config ); - return listedCount; - } - -} // end namespace Catch -// end catch_list.cpp -// start catch_matchers.cpp - -namespace Catch { -namespace Matchers { - namespace Impl { - - std::string MatcherUntypedBase::toString() const { - if( m_cachedToString.empty() ) - m_cachedToString = describe(); - return m_cachedToString; - } - - MatcherUntypedBase::~MatcherUntypedBase() = default; - - } // namespace Impl -} // namespace Matchers - -using namespace Matchers; -using Matchers::Impl::MatcherBase; - -} // namespace Catch -// end catch_matchers.cpp -// start catch_matchers_floating.cpp - -#include -#include -#include -#include - -namespace Catch { -namespace Matchers { -namespace Floating { -enum class FloatingPointKind : uint8_t { - Float, - Double -}; -} -} -} - -namespace { - -template -struct Converter; - -template <> -struct Converter { - static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated"); - Converter(float f) { - std::memcpy(&i, &f, sizeof(f)); - } - int32_t i; -}; - -template <> -struct Converter { - static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated"); - Converter(double d) { - std::memcpy(&i, &d, sizeof(d)); - } - int64_t i; -}; - -template -auto convert(T t) -> Converter { - return Converter(t); -} - -template -bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) { - // Comparison with NaN should always be false. - // This way we can rule it out before getting into the ugly details - if (std::isnan(lhs) || std::isnan(rhs)) { - return false; - } - - auto lc = convert(lhs); - auto rc = convert(rhs); - - if ((lc.i < 0) != (rc.i < 0)) { - // Potentially we can have +0 and -0 - return lhs == rhs; - } - - auto ulpDiff = std::abs(lc.i - rc.i); - return ulpDiff <= maxUlpDiff; -} - -} - -namespace Catch { -namespace Matchers { -namespace Floating { - WithinAbsMatcher::WithinAbsMatcher(double target, double margin) - :m_target{ target }, m_margin{ margin } { - if (m_margin < 0) { - throw std::domain_error("Allowed margin difference has to be >= 0"); - } - } - - // Performs equivalent check of std::fabs(lhs - rhs) <= margin - // But without the subtraction to allow for INFINITY in comparison - bool WithinAbsMatcher::match(double const& matchee) const { - return (matchee + m_margin >= m_target) && (m_target + m_margin >= matchee); - } - - std::string WithinAbsMatcher::describe() const { - return "is within " + ::Catch::Detail::stringify(m_margin) + " of " + ::Catch::Detail::stringify(m_target); - } - - WithinUlpsMatcher::WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType) - :m_target{ target }, m_ulps{ ulps }, m_type{ baseType } { - if (m_ulps < 0) { - throw std::domain_error("Allowed ulp difference has to be >= 0"); - } - } - - bool WithinUlpsMatcher::match(double const& matchee) const { - switch (m_type) { - case FloatingPointKind::Float: - return almostEqualUlps(static_cast(matchee), static_cast(m_target), m_ulps); - case FloatingPointKind::Double: - return almostEqualUlps(matchee, m_target, m_ulps); - default: - throw std::domain_error("Unknown FloatingPointKind value"); - } - } - - std::string WithinUlpsMatcher::describe() const { - return "is within " + std::to_string(m_ulps) + " ULPs of " + ::Catch::Detail::stringify(m_target) + ((m_type == FloatingPointKind::Float)? "f" : ""); - } - -}// namespace Floating - -Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff) { - return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Double); -} - -Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff) { - return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Float); -} - -Floating::WithinAbsMatcher WithinAbs(double target, double margin) { - return Floating::WithinAbsMatcher(target, margin); -} - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_floating.cpp -// start catch_matchers_generic.cpp - -std::string Catch::Matchers::Generic::Detail::finalizeDescription(const std::string& desc) { - if (desc.empty()) { - return "matches undescribed predicate"; - } else { - return "matches predicate: \"" + desc + '"'; - } -} -// end catch_matchers_generic.cpp -// start catch_matchers_string.cpp - -#include - -namespace Catch { -namespace Matchers { - - namespace StdString { - - CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) - : m_caseSensitivity( caseSensitivity ), - m_str( adjustString( str ) ) - {} - std::string CasedString::adjustString( std::string const& str ) const { - return m_caseSensitivity == CaseSensitive::No - ? toLower( str ) - : str; - } - std::string CasedString::caseSensitivitySuffix() const { - return m_caseSensitivity == CaseSensitive::No - ? " (case insensitive)" - : std::string(); - } - - StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator ) - : m_comparator( comparator ), - m_operation( operation ) { - } - - std::string StringMatcherBase::describe() const { - std::string description; - description.reserve(5 + m_operation.size() + m_comparator.m_str.size() + - m_comparator.caseSensitivitySuffix().size()); - description += m_operation; - description += ": \""; - description += m_comparator.m_str; - description += "\""; - description += m_comparator.caseSensitivitySuffix(); - return description; - } - - EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {} - - bool EqualsMatcher::match( std::string const& source ) const { - return m_comparator.adjustString( source ) == m_comparator.m_str; - } - - ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {} - - bool ContainsMatcher::match( std::string const& source ) const { - return contains( m_comparator.adjustString( source ), m_comparator.m_str ); - } - - StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {} - - bool StartsWithMatcher::match( std::string const& source ) const { - return startsWith( m_comparator.adjustString( source ), m_comparator.m_str ); - } - - EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {} - - bool EndsWithMatcher::match( std::string const& source ) const { - return endsWith( m_comparator.adjustString( source ), m_comparator.m_str ); - } - - RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {} - - bool RegexMatcher::match(std::string const& matchee) const { - auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway - if (m_caseSensitivity == CaseSensitive::Choice::No) { - flags |= std::regex::icase; - } - auto reg = std::regex(m_regex, flags); - return std::regex_match(matchee, reg); - } - - std::string RegexMatcher::describe() const { - return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively"); - } - - } // namespace StdString - - StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) ); - } - StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) ); - } - StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) ); - } - StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) ); - } - - StdString::RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) { - return StdString::RegexMatcher(regex, caseSensitivity); - } - -} // namespace Matchers -} // namespace Catch -// end catch_matchers_string.cpp -// start catch_message.cpp - -// start catch_uncaught_exceptions.h - -namespace Catch { - bool uncaught_exceptions(); -} // end namespace Catch - -// end catch_uncaught_exceptions.h -namespace Catch { - - MessageInfo::MessageInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ) - : macroName( _macroName ), - lineInfo( _lineInfo ), - type( _type ), - sequence( ++globalCount ) - {} - - bool MessageInfo::operator==( MessageInfo const& other ) const { - return sequence == other.sequence; - } - - bool MessageInfo::operator<( MessageInfo const& other ) const { - return sequence < other.sequence; - } - - // This may need protecting if threading support is added - unsigned int MessageInfo::globalCount = 0; - - //////////////////////////////////////////////////////////////////////////// - - Catch::MessageBuilder::MessageBuilder( std::string const& macroName, - SourceLineInfo const& lineInfo, - ResultWas::OfType type ) - :m_info(macroName, lineInfo, type) {} - - //////////////////////////////////////////////////////////////////////////// - - ScopedMessage::ScopedMessage( MessageBuilder const& builder ) - : m_info( builder.m_info ) - { - m_info.message = builder.m_stream.str(); - getResultCapture().pushScopedMessage( m_info ); - } - - ScopedMessage::~ScopedMessage() { - if ( !uncaught_exceptions() ){ - getResultCapture().popScopedMessage(m_info); - } - } -} // end namespace Catch -// end catch_message.cpp -// start catch_random_number_generator.cpp - -// start catch_random_number_generator.h - -#include - -namespace Catch { - - struct IConfig; - - void seedRng( IConfig const& config ); - - unsigned int rngSeed(); - - struct RandomNumberGenerator { - using result_type = unsigned int; - - static constexpr result_type (min)() { return 0; } - static constexpr result_type (max)() { return 1000000; } - - result_type operator()( result_type n ) const; - result_type operator()() const; - - template - static void shuffle( V& vector ) { - RandomNumberGenerator rng; - std::shuffle( vector.begin(), vector.end(), rng ); - } - }; - -} - -// end catch_random_number_generator.h -#include - -namespace Catch { - - void seedRng( IConfig const& config ) { - if( config.rngSeed() != 0 ) - std::srand( config.rngSeed() ); - } - unsigned int rngSeed() { - return getCurrentContext().getConfig()->rngSeed(); - } - - RandomNumberGenerator::result_type RandomNumberGenerator::operator()( result_type n ) const { - return std::rand() % n; - } - RandomNumberGenerator::result_type RandomNumberGenerator::operator()() const { - return std::rand() % (max)(); - } - -} -// end catch_random_number_generator.cpp -// start catch_registry_hub.cpp - -// start catch_test_case_registry_impl.h - -#include -#include -#include -#include - -namespace Catch { - - class TestCase; - struct IConfig; - - std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ); - bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); - - void enforceNoDuplicateTestCases( std::vector const& functions ); - - std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); - std::vector const& getAllTestCasesSorted( IConfig const& config ); - - class TestRegistry : public ITestCaseRegistry { - public: - virtual ~TestRegistry() = default; - - virtual void registerTest( TestCase const& testCase ); - - std::vector const& getAllTests() const override; - std::vector const& getAllTestsSorted( IConfig const& config ) const override; - - private: - std::vector m_functions; - mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder; - mutable std::vector m_sortedFunctions; - std::size_t m_unnamedCount = 0; - std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised - }; - - /////////////////////////////////////////////////////////////////////////// - - class TestInvokerAsFunction : public ITestInvoker { - void(*m_testAsFunction)(); - public: - TestInvokerAsFunction( void(*testAsFunction)() ) noexcept; - - void invoke() const override; - }; - - std::string extractClassName( StringRef const& classOrQualifiedMethodName ); - - /////////////////////////////////////////////////////////////////////////// - -} // end namespace Catch - -// end catch_test_case_registry_impl.h -// start catch_reporter_registry.h - -#include - -namespace Catch { - - class ReporterRegistry : public IReporterRegistry { - - public: - - ~ReporterRegistry() override; - - IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override; - - void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ); - void registerListener( IReporterFactoryPtr const& factory ); - - FactoryMap const& getFactories() const override; - Listeners const& getListeners() const override; - - private: - FactoryMap m_factories; - Listeners m_listeners; - }; -} - -// end catch_reporter_registry.h -// start catch_tag_alias_registry.h - -// start catch_tag_alias.h - -#include - -namespace Catch { - - struct TagAlias { - TagAlias(std::string const& _tag, SourceLineInfo _lineInfo); - - std::string tag; - SourceLineInfo lineInfo; - }; - -} // end namespace Catch - -// end catch_tag_alias.h -#include - -namespace Catch { - - class TagAliasRegistry : public ITagAliasRegistry { - public: - ~TagAliasRegistry() override; - TagAlias const* find( std::string const& alias ) const override; - std::string expandAliases( std::string const& unexpandedTestSpec ) const override; - void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ); - - private: - std::map m_registry; - }; - -} // end namespace Catch - -// end catch_tag_alias_registry.h -// start catch_startup_exception_registry.h - -#include -#include - -namespace Catch { - - class StartupExceptionRegistry { - public: - void add(std::exception_ptr const& exception) noexcept; - std::vector const& getExceptions() const noexcept; - private: - std::vector m_exceptions; - }; - -} // end namespace Catch - -// end catch_startup_exception_registry.h -namespace Catch { - - namespace { - - class RegistryHub : public IRegistryHub, public IMutableRegistryHub, - private NonCopyable { - - public: // IRegistryHub - RegistryHub() = default; - IReporterRegistry const& getReporterRegistry() const override { - return m_reporterRegistry; - } - ITestCaseRegistry const& getTestCaseRegistry() const override { - return m_testCaseRegistry; - } - IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() override { - return m_exceptionTranslatorRegistry; - } - ITagAliasRegistry const& getTagAliasRegistry() const override { - return m_tagAliasRegistry; - } - StartupExceptionRegistry const& getStartupExceptionRegistry() const override { - return m_exceptionRegistry; - } - - public: // IMutableRegistryHub - void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override { - m_reporterRegistry.registerReporter( name, factory ); - } - void registerListener( IReporterFactoryPtr const& factory ) override { - m_reporterRegistry.registerListener( factory ); - } - void registerTest( TestCase const& testInfo ) override { - m_testCaseRegistry.registerTest( testInfo ); - } - void registerTranslator( const IExceptionTranslator* translator ) override { - m_exceptionTranslatorRegistry.registerTranslator( translator ); - } - void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { - m_tagAliasRegistry.add( alias, tag, lineInfo ); - } - void registerStartupException() noexcept override { - m_exceptionRegistry.add(std::current_exception()); - } - - private: - TestRegistry m_testCaseRegistry; - ReporterRegistry m_reporterRegistry; - ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; - TagAliasRegistry m_tagAliasRegistry; - StartupExceptionRegistry m_exceptionRegistry; - }; - - // Single, global, instance - RegistryHub*& getTheRegistryHub() { - static RegistryHub* theRegistryHub = nullptr; - if( !theRegistryHub ) - theRegistryHub = new RegistryHub(); - return theRegistryHub; - } - } - - IRegistryHub& getRegistryHub() { - return *getTheRegistryHub(); - } - IMutableRegistryHub& getMutableRegistryHub() { - return *getTheRegistryHub(); - } - void cleanUp() { - delete getTheRegistryHub(); - getTheRegistryHub() = nullptr; - cleanUpContext(); - ReusableStringStream::cleanup(); - } - std::string translateActiveException() { - return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); - } - -} // end namespace Catch -// end catch_registry_hub.cpp -// start catch_reporter_registry.cpp - -namespace Catch { - - ReporterRegistry::~ReporterRegistry() = default; - - IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const { - auto it = m_factories.find( name ); - if( it == m_factories.end() ) - return nullptr; - return it->second->create( ReporterConfig( config ) ); - } - - void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) { - m_factories.emplace(name, factory); - } - void ReporterRegistry::registerListener( IReporterFactoryPtr const& factory ) { - m_listeners.push_back( factory ); - } - - IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const { - return m_factories; - } - IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const { - return m_listeners; - } - -} -// end catch_reporter_registry.cpp -// start catch_result_type.cpp - -namespace Catch { - - bool isOk( ResultWas::OfType resultType ) { - return ( resultType & ResultWas::FailureBit ) == 0; - } - bool isJustInfo( int flags ) { - return flags == ResultWas::Info; - } - - ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { - return static_cast( static_cast( lhs ) | static_cast( rhs ) ); - } - - bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } - bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } - -} // end namespace Catch -// end catch_result_type.cpp -// start catch_run_context.cpp - -#include -#include -#include - -namespace Catch { - - class RedirectedStream { - std::ostream& m_originalStream; - std::ostream& m_redirectionStream; - std::streambuf* m_prevBuf; - - public: - RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream ) - : m_originalStream( originalStream ), - m_redirectionStream( redirectionStream ), - m_prevBuf( m_originalStream.rdbuf() ) - { - m_originalStream.rdbuf( m_redirectionStream.rdbuf() ); - } - ~RedirectedStream() { - m_originalStream.rdbuf( m_prevBuf ); - } - }; - - class RedirectedStdOut { - ReusableStringStream m_rss; - RedirectedStream m_cout; - public: - RedirectedStdOut() : m_cout( Catch::cout(), m_rss.get() ) {} - auto str() const -> std::string { return m_rss.str(); } - }; - - // StdErr has two constituent streams in C++, std::cerr and std::clog - // This means that we need to redirect 2 streams into 1 to keep proper - // order of writes - class RedirectedStdErr { - ReusableStringStream m_rss; - RedirectedStream m_cerr; - RedirectedStream m_clog; - public: - RedirectedStdErr() - : m_cerr( Catch::cerr(), m_rss.get() ), - m_clog( Catch::clog(), m_rss.get() ) - {} - auto str() const -> std::string { return m_rss.str(); } - }; - - RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter) - : m_runInfo(_config->name()), - m_context(getCurrentMutableContext()), - m_config(_config), - m_reporter(std::move(reporter)), - m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal }, - m_includeSuccessfulResults( m_config->includeSuccessfulResults() ) - { - m_context.setRunner(this); - m_context.setConfig(m_config); - m_context.setResultCapture(this); - m_reporter->testRunStarting(m_runInfo); - } - - RunContext::~RunContext() { - m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting())); - } - - void RunContext::testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount) { - m_reporter->testGroupStarting(GroupInfo(testSpec, groupIndex, groupsCount)); - } - - void RunContext::testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount) { - m_reporter->testGroupEnded(TestGroupStats(GroupInfo(testSpec, groupIndex, groupsCount), totals, aborting())); - } - - Totals RunContext::runTest(TestCase const& testCase) { - Totals prevTotals = m_totals; - - std::string redirectedCout; - std::string redirectedCerr; - - auto const& testInfo = testCase.getTestCaseInfo(); - - m_reporter->testCaseStarting(testInfo); - - m_activeTestCase = &testCase; - - ITracker& rootTracker = m_trackerContext.startRun(); - assert(rootTracker.isSectionTracker()); - static_cast(rootTracker).addInitialFilters(m_config->getSectionsToRun()); - do { - m_trackerContext.startCycle(); - m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo)); - runCurrentTest(redirectedCout, redirectedCerr); - } while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting()); - - Totals deltaTotals = m_totals.delta(prevTotals); - if (testInfo.expectedToFail() && deltaTotals.testCases.passed > 0) { - deltaTotals.assertions.failed++; - deltaTotals.testCases.passed--; - deltaTotals.testCases.failed++; - } - m_totals.testCases += deltaTotals.testCases; - m_reporter->testCaseEnded(TestCaseStats(testInfo, - deltaTotals, - redirectedCout, - redirectedCerr, - aborting())); - - m_activeTestCase = nullptr; - m_testCaseTracker = nullptr; - - return deltaTotals; - } - - IConfigPtr RunContext::config() const { - return m_config; - } - - IStreamingReporter& RunContext::reporter() const { - return *m_reporter; - } - - void RunContext::assertionEnded(AssertionResult const & result) { - if (result.getResultType() == ResultWas::Ok) { - m_totals.assertions.passed++; - m_lastAssertionPassed = true; - } else if (!result.isOk()) { - m_lastAssertionPassed = false; - if( m_activeTestCase->getTestCaseInfo().okToFail() ) - m_totals.assertions.failedButOk++; - else - m_totals.assertions.failed++; - } - else { - m_lastAssertionPassed = true; - } - - // We have no use for the return value (whether messages should be cleared), because messages were made scoped - // and should be let to clear themselves out. - static_cast(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals))); - - // Reset working state - resetAssertionInfo(); - m_lastResult = result; - } - void RunContext::resetAssertionInfo() { - m_lastAssertionInfo.macroName = StringRef(); - m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr; - } - - bool RunContext::sectionStarted(SectionInfo const & sectionInfo, Counts & assertions) { - ITracker& sectionTracker = SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(sectionInfo.name, sectionInfo.lineInfo)); - if (!sectionTracker.isOpen()) - return false; - m_activeSections.push_back(§ionTracker); - - m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; - - m_reporter->sectionStarting(sectionInfo); - - assertions = m_totals.assertions; - - return true; - } - - bool RunContext::testForMissingAssertions(Counts& assertions) { - if (assertions.total() != 0) - return false; - if (!m_config->warnAboutMissingAssertions()) - return false; - if (m_trackerContext.currentTracker().hasChildren()) - return false; - m_totals.assertions.failed++; - assertions.failed++; - return true; - } - - void RunContext::sectionEnded(SectionEndInfo const & endInfo) { - Counts assertions = m_totals.assertions - endInfo.prevAssertions; - bool missingAssertions = testForMissingAssertions(assertions); - - if (!m_activeSections.empty()) { - m_activeSections.back()->close(); - m_activeSections.pop_back(); - } - - m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions)); - m_messages.clear(); - } - - void RunContext::sectionEndedEarly(SectionEndInfo const & endInfo) { - if (m_unfinishedSections.empty()) - m_activeSections.back()->fail(); - else - m_activeSections.back()->close(); - m_activeSections.pop_back(); - - m_unfinishedSections.push_back(endInfo); - } - void RunContext::benchmarkStarting( BenchmarkInfo const& info ) { - m_reporter->benchmarkStarting( info ); - } - void RunContext::benchmarkEnded( BenchmarkStats const& stats ) { - m_reporter->benchmarkEnded( stats ); - } - - void RunContext::pushScopedMessage(MessageInfo const & message) { - m_messages.push_back(message); - } - - void RunContext::popScopedMessage(MessageInfo const & message) { - m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end()); - } - - std::string RunContext::getCurrentTestName() const { - return m_activeTestCase - ? m_activeTestCase->getTestCaseInfo().name - : std::string(); - } - - const AssertionResult * RunContext::getLastResult() const { - return &(*m_lastResult); - } - - void RunContext::exceptionEarlyReported() { - m_shouldReportUnexpected = false; - } - - void RunContext::handleFatalErrorCondition( StringRef message ) { - // First notify reporter that bad things happened - m_reporter->fatalErrorEncountered(message); - - // Don't rebuild the result -- the stringification itself can cause more fatal errors - // Instead, fake a result data. - AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } ); - tempResult.message = message; - AssertionResult result(m_lastAssertionInfo, tempResult); - - assertionEnded(result); - - handleUnfinishedSections(); - - // Recreate section for test case (as we will lose the one that was in scope) - auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); - - Counts assertions; - assertions.failed = 1; - SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false); - m_reporter->sectionEnded(testCaseSectionStats); - - auto const& testInfo = m_activeTestCase->getTestCaseInfo(); - - Totals deltaTotals; - deltaTotals.testCases.failed = 1; - deltaTotals.assertions.failed = 1; - m_reporter->testCaseEnded(TestCaseStats(testInfo, - deltaTotals, - std::string(), - std::string(), - false)); - m_totals.testCases.failed++; - testGroupEnded(std::string(), m_totals, 1, 1); - m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false)); - } - - bool RunContext::lastAssertionPassed() { - return m_lastAssertionPassed; - } - - void RunContext::assertionPassed() { - m_lastAssertionPassed = true; - ++m_totals.assertions.passed; - resetAssertionInfo(); - } - - bool RunContext::aborting() const { - return m_totals.assertions.failed == static_cast(m_config->abortAfter()); - } - - void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) { - auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); - m_reporter->sectionStarting(testCaseSection); - Counts prevAssertions = m_totals.assertions; - double duration = 0; - m_shouldReportUnexpected = true; - m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal }; - - seedRng(*m_config); - - Timer timer; - try { - if (m_reporter->getPreferences().shouldRedirectStdOut) { - RedirectedStdOut redirectedStdOut; - RedirectedStdErr redirectedStdErr; - timer.start(); - invokeActiveTestCase(); - redirectedCout += redirectedStdOut.str(); - redirectedCerr += redirectedStdErr.str(); - - } else { - timer.start(); - invokeActiveTestCase(); - } - duration = timer.getElapsedSeconds(); - } catch (TestFailureException&) { - // This just means the test was aborted due to failure - } catch (...) { - // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions - // are reported without translation at the point of origin. - if( m_shouldReportUnexpected ) { - AssertionReaction dummyReaction; - handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction ); - } - } - Counts assertions = m_totals.assertions - prevAssertions; - bool missingAssertions = testForMissingAssertions(assertions); - - m_testCaseTracker->close(); - handleUnfinishedSections(); - m_messages.clear(); - - SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions); - m_reporter->sectionEnded(testCaseSectionStats); - } - - void RunContext::invokeActiveTestCase() { - FatalConditionHandler fatalConditionHandler; // Handle signals - m_activeTestCase->invoke(); - fatalConditionHandler.reset(); - } - - void RunContext::handleUnfinishedSections() { - // If sections ended prematurely due to an exception we stored their - // infos here so we can tear them down outside the unwind process. - for (auto it = m_unfinishedSections.rbegin(), - itEnd = m_unfinishedSections.rend(); - it != itEnd; - ++it) - sectionEnded(*it); - m_unfinishedSections.clear(); - } - - void RunContext::handleExpr( - AssertionInfo const& info, - ITransientExpression const& expr, - AssertionReaction& reaction - ) { - m_reporter->assertionStarting( info ); - - bool negated = isFalseTest( info.resultDisposition ); - bool result = expr.getResult() != negated; - - if( result ) { - if (!m_includeSuccessfulResults) { - assertionPassed(); - } - else { - reportExpr(info, ResultWas::Ok, &expr, negated); - } - } - else { - reportExpr(info, ResultWas::ExpressionFailed, &expr, negated ); - populateReaction( reaction ); - } - } - void RunContext::reportExpr( - AssertionInfo const &info, - ResultWas::OfType resultType, - ITransientExpression const *expr, - bool negated ) { - - m_lastAssertionInfo = info; - AssertionResultData data( resultType, LazyExpression( negated ) ); - - AssertionResult assertionResult{ info, data }; - assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; - - assertionEnded( assertionResult ); - } - - void RunContext::handleMessage( - AssertionInfo const& info, - ResultWas::OfType resultType, - StringRef const& message, - AssertionReaction& reaction - ) { - m_reporter->assertionStarting( info ); - - m_lastAssertionInfo = info; - - AssertionResultData data( resultType, LazyExpression( false ) ); - data.message = message; - AssertionResult assertionResult{ m_lastAssertionInfo, data }; - assertionEnded( assertionResult ); - if( !assertionResult.isOk() ) - populateReaction( reaction ); - } - void RunContext::handleUnexpectedExceptionNotThrown( - AssertionInfo const& info, - AssertionReaction& reaction - ) { - handleNonExpr(info, Catch::ResultWas::DidntThrowException, reaction); - } - - void RunContext::handleUnexpectedInflightException( - AssertionInfo const& info, - std::string const& message, - AssertionReaction& reaction - ) { - m_lastAssertionInfo = info; - - AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); - data.message = message; - AssertionResult assertionResult{ info, data }; - assertionEnded( assertionResult ); - populateReaction( reaction ); - } - - void RunContext::populateReaction( AssertionReaction& reaction ) { - reaction.shouldDebugBreak = m_config->shouldDebugBreak(); - reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal); - } - - void RunContext::handleIncomplete( - AssertionInfo const& info - ) { - m_lastAssertionInfo = info; - - AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); - data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"; - AssertionResult assertionResult{ info, data }; - assertionEnded( assertionResult ); - } - void RunContext::handleNonExpr( - AssertionInfo const &info, - ResultWas::OfType resultType, - AssertionReaction &reaction - ) { - m_lastAssertionInfo = info; - - AssertionResultData data( resultType, LazyExpression( false ) ); - AssertionResult assertionResult{ info, data }; - assertionEnded( assertionResult ); - - if( !assertionResult.isOk() ) - populateReaction( reaction ); - } - - IResultCapture& getResultCapture() { - if (auto* capture = getCurrentContext().getResultCapture()) - return *capture; - else - CATCH_INTERNAL_ERROR("No result capture instance"); - } -} -// end catch_run_context.cpp -// start catch_section.cpp - -namespace Catch { - - Section::Section( SectionInfo const& info ) - : m_info( info ), - m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) - { - m_timer.start(); - } - - Section::~Section() { - if( m_sectionIncluded ) { - SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() ); - if( uncaught_exceptions() ) - getResultCapture().sectionEndedEarly( endInfo ); - else - getResultCapture().sectionEnded( endInfo ); - } - } - - // This indicates whether the section should be executed or not - Section::operator bool() const { - return m_sectionIncluded; - } - -} // end namespace Catch -// end catch_section.cpp -// start catch_section_info.cpp - -namespace Catch { - - SectionInfo::SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name, - std::string const& _description ) - : name( _name ), - description( _description ), - lineInfo( _lineInfo ) - {} - - SectionEndInfo::SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ) - : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) - {} - -} // end namespace Catch -// end catch_section_info.cpp -// start catch_session.cpp - -// start catch_session.h - -#include - -namespace Catch { - - class Session : NonCopyable { - public: - - Session(); - ~Session() override; - - void showHelp() const; - void libIdentify(); - - int applyCommandLine( int argc, char const * const * argv ); - - void useConfigData( ConfigData const& configData ); - - int run( int argc, char* argv[] ); - #if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(UNICODE) - int run( int argc, wchar_t* const argv[] ); - #endif - int run(); - - clara::Parser const& cli() const; - void cli( clara::Parser const& newParser ); - ConfigData& configData(); - Config& config(); - private: - int runInternal(); - - clara::Parser m_cli; - ConfigData m_configData; - std::shared_ptr m_config; - bool m_startupExceptions = false; - }; - -} // end namespace Catch - -// end catch_session.h -// start catch_version.h - -#include - -namespace Catch { - - // Versioning information - struct Version { - Version( Version const& ) = delete; - Version& operator=( Version const& ) = delete; - Version( unsigned int _majorVersion, - unsigned int _minorVersion, - unsigned int _patchNumber, - char const * const _branchName, - unsigned int _buildNumber ); - - unsigned int const majorVersion; - unsigned int const minorVersion; - unsigned int const patchNumber; - - // buildNumber is only used if branchName is not null - char const * const branchName; - unsigned int const buildNumber; - - friend std::ostream& operator << ( std::ostream& os, Version const& version ); - }; - - Version const& libraryVersion(); -} - -// end catch_version.h -#include -#include - -namespace Catch { - - namespace { - const int MaxExitCode = 255; - - IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) { - auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config); - CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'"); - - return reporter; - } - -#ifndef CATCH_CONFIG_DEFAULT_REPORTER -#define CATCH_CONFIG_DEFAULT_REPORTER "console" -#endif - - IStreamingReporterPtr makeReporter(std::shared_ptr const& config) { - auto const& reporterNames = config->getReporterNames(); - if (reporterNames.empty()) - return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config); - - IStreamingReporterPtr reporter; - for (auto const& name : reporterNames) - addReporter(reporter, createReporter(name, config)); - return reporter; - } - -#undef CATCH_CONFIG_DEFAULT_REPORTER - - void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) { - auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); - for (auto const& listener : listeners) - addReporter(reporters, listener->create(Catch::ReporterConfig(config))); - } - - Catch::Totals runTests(std::shared_ptr const& config) { - IStreamingReporterPtr reporter = makeReporter(config); - addListeners(reporter, config); - - RunContext context(config, std::move(reporter)); - - Totals totals; - - context.testGroupStarting(config->name(), 1, 1); - - TestSpec testSpec = config->testSpec(); - - auto const& allTestCases = getAllTestCasesSorted(*config); - for (auto const& testCase : allTestCases) { - if (!context.aborting() && matchTest(testCase, testSpec, *config)) - totals += context.runTest(testCase); - else - context.reporter().skipTest(testCase); - } - - if (config->warnAboutNoTests() && totals.testCases.total() == 0) { - ReusableStringStream testConfig; - - bool first = true; - for (const auto& input : config->getTestsOrTags()) { - if (!first) { testConfig << ' '; } - first = false; - testConfig << input; - } - - context.reporter().noMatchingTestCases(testConfig.str()); - totals.error = -1; - } - - context.testGroupEnded(config->name(), totals, 1, 1); - return totals; - } - - void applyFilenamesAsTags(Catch::IConfig const& config) { - auto& tests = const_cast&>(getAllTestCasesSorted(config)); - for (auto& testCase : tests) { - auto tags = testCase.tags; - - std::string filename = testCase.lineInfo.file; - auto lastSlash = filename.find_last_of("\\/"); - if (lastSlash != std::string::npos) { - filename.erase(0, lastSlash); - filename[0] = '#'; - } - - auto lastDot = filename.find_last_of('.'); - if (lastDot != std::string::npos) { - filename.erase(lastDot); - } - - tags.push_back(std::move(filename)); - setTags(testCase, tags); - } - } - - } // anon namespace - - Session::Session() { - static bool alreadyInstantiated = false; - if( alreadyInstantiated ) { - try { CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); } - catch(...) { getMutableRegistryHub().registerStartupException(); } - } - - const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions(); - if ( !exceptions.empty() ) { - m_startupExceptions = true; - Colour colourGuard( Colour::Red ); - Catch::cerr() << "Errors occurred during startup!" << '\n'; - // iterate over all exceptions and notify user - for ( const auto& ex_ptr : exceptions ) { - try { - std::rethrow_exception(ex_ptr); - } catch ( std::exception const& ex ) { - Catch::cerr() << Column( ex.what() ).indent(2) << '\n'; - } - } - } - - alreadyInstantiated = true; - m_cli = makeCommandLineParser( m_configData ); - } - Session::~Session() { - Catch::cleanUp(); - } - - void Session::showHelp() const { - Catch::cout() - << "\nCatch v" << libraryVersion() << "\n" - << m_cli << std::endl - << "For more detailed usage please see the project docs\n" << std::endl; - } - void Session::libIdentify() { - Catch::cout() - << std::left << std::setw(16) << "description: " << "A Catch test executable\n" - << std::left << std::setw(16) << "category: " << "testframework\n" - << std::left << std::setw(16) << "framework: " << "Catch Test\n" - << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl; - } - - int Session::applyCommandLine( int argc, char const * const * argv ) { - if( m_startupExceptions ) - return 1; - - auto result = m_cli.parse( clara::Args( argc, argv ) ); - if( !result ) { - Catch::cerr() - << Colour( Colour::Red ) - << "\nError(s) in input:\n" - << Column( result.errorMessage() ).indent( 2 ) - << "\n\n"; - Catch::cerr() << "Run with -? for usage\n" << std::endl; - return MaxExitCode; - } - - if( m_configData.showHelp ) - showHelp(); - if( m_configData.libIdentify ) - libIdentify(); - m_config.reset(); - return 0; - } - - void Session::useConfigData( ConfigData const& configData ) { - m_configData = configData; - m_config.reset(); - } - - int Session::run( int argc, char* argv[] ) { - if( m_startupExceptions ) - return 1; - int returnCode = applyCommandLine( argc, argv ); - if( returnCode == 0 ) - returnCode = run(); - return returnCode; - } - -#if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(UNICODE) - int Session::run( int argc, wchar_t* const argv[] ) { - - char **utf8Argv = new char *[ argc ]; - - for ( int i = 0; i < argc; ++i ) { - int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL ); - - utf8Argv[ i ] = new char[ bufSize ]; - - WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL ); - } - - int returnCode = run( argc, utf8Argv ); - - for ( int i = 0; i < argc; ++i ) - delete [] utf8Argv[ i ]; - - delete [] utf8Argv; - - return returnCode; - } -#endif - int Session::run() { - if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) { - Catch::cout() << "...waiting for enter/ return before starting" << std::endl; - static_cast(std::getchar()); - } - int exitCode = runInternal(); - if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) { - Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl; - static_cast(std::getchar()); - } - return exitCode; - } - - clara::Parser const& Session::cli() const { - return m_cli; - } - void Session::cli( clara::Parser const& newParser ) { - m_cli = newParser; - } - ConfigData& Session::configData() { - return m_configData; - } - Config& Session::config() { - if( !m_config ) - m_config = std::make_shared( m_configData ); - return *m_config; - } - - int Session::runInternal() { - if( m_startupExceptions ) - return 1; - - if( m_configData.showHelp || m_configData.libIdentify ) - return 0; - - try - { - config(); // Force config to be constructed - - seedRng( *m_config ); - - if( m_configData.filenamesAsTags ) - applyFilenamesAsTags( *m_config ); - - // Handle list request - if( Option listed = list( config() ) ) - return static_cast( *listed ); - - auto totals = runTests( m_config ); - // Note that on unices only the lower 8 bits are usually used, clamping - // the return value to 255 prevents false negative when some multiple - // of 256 tests has failed - return (std::min) (MaxExitCode, (std::max) (totals.error, static_cast(totals.assertions.failed))); - } - catch( std::exception& ex ) { - Catch::cerr() << ex.what() << std::endl; - return MaxExitCode; - } - } - -} // end namespace Catch -// end catch_session.cpp -// start catch_startup_exception_registry.cpp - -namespace Catch { - void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept { - try { - m_exceptions.push_back(exception); - } - catch(...) { - // If we run out of memory during start-up there's really not a lot more we can do about it - std::terminate(); - } - } - - std::vector const& StartupExceptionRegistry::getExceptions() const noexcept { - return m_exceptions; - } - -} // end namespace Catch -// end catch_startup_exception_registry.cpp -// start catch_stream.cpp - -#include -#include -#include -#include -#include -#include - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wexit-time-destructors" -#endif - -namespace Catch { - - Catch::IStream::~IStream() = default; - - namespace detail { namespace { - template - class StreamBufImpl : public std::streambuf { - char data[bufferSize]; - WriterF m_writer; - - public: - StreamBufImpl() { - setp( data, data + sizeof(data) ); - } - - ~StreamBufImpl() noexcept { - StreamBufImpl::sync(); - } - - private: - int overflow( int c ) override { - sync(); - - if( c != EOF ) { - if( pbase() == epptr() ) - m_writer( std::string( 1, static_cast( c ) ) ); - else - sputc( static_cast( c ) ); - } - return 0; - } - - int sync() override { - if( pbase() != pptr() ) { - m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); - setp( pbase(), epptr() ); - } - return 0; - } - }; - - /////////////////////////////////////////////////////////////////////////// - - struct OutputDebugWriter { - - void operator()( std::string const&str ) { - writeToDebugConsole( str ); - } - }; - - /////////////////////////////////////////////////////////////////////////// - - class FileStream : public IStream { - mutable std::ofstream m_ofs; - public: - FileStream( StringRef filename ) { - m_ofs.open( filename.c_str() ); - CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" ); - } - ~FileStream() override = default; - public: // IStream - std::ostream& stream() const override { - return m_ofs; - } - }; - - /////////////////////////////////////////////////////////////////////////// - - class CoutStream : public IStream { - mutable std::ostream m_os; - public: - // Store the streambuf from cout up-front because - // cout may get redirected when running tests - CoutStream() : m_os( Catch::cout().rdbuf() ) {} - ~CoutStream() override = default; - - public: // IStream - std::ostream& stream() const override { return m_os; } - }; - - /////////////////////////////////////////////////////////////////////////// - - class DebugOutStream : public IStream { - std::unique_ptr> m_streamBuf; - mutable std::ostream m_os; - public: - DebugOutStream() - : m_streamBuf( new StreamBufImpl() ), - m_os( m_streamBuf.get() ) - {} - - ~DebugOutStream() override = default; - - public: // IStream - std::ostream& stream() const override { return m_os; } - }; - - }} // namespace anon::detail - - /////////////////////////////////////////////////////////////////////////// - - auto makeStream( StringRef const &filename ) -> IStream const* { - if( filename.empty() ) - return new detail::CoutStream(); - else if( filename[0] == '%' ) { - if( filename == "%debug" ) - return new detail::DebugOutStream(); - else - CATCH_ERROR( "Unrecognised stream: '" << filename << "'" ); - } - else - return new detail::FileStream( filename ); - } - - // This class encapsulates the idea of a pool of ostringstreams that can be reused. - struct StringStreams { - std::vector> m_streams; - std::vector m_unused; - std::ostringstream m_referenceStream; // Used for copy state/ flags from - static StringStreams* s_instance; - - auto add() -> std::size_t { - if( m_unused.empty() ) { - m_streams.push_back( std::unique_ptr( new std::ostringstream ) ); - return m_streams.size()-1; - } - else { - auto index = m_unused.back(); - m_unused.pop_back(); - return index; - } - } - - void release( std::size_t index ) { - m_streams[index]->copyfmt( m_referenceStream ); // Restore initial flags and other state - m_unused.push_back(index); - } - - // !TBD: put in TLS - static auto instance() -> StringStreams& { - if( !s_instance ) - s_instance = new StringStreams(); - return *s_instance; - } - static void cleanup() { - delete s_instance; - s_instance = nullptr; - } - }; - - StringStreams* StringStreams::s_instance = nullptr; - - void ReusableStringStream::cleanup() { - StringStreams::cleanup(); - } - - ReusableStringStream::ReusableStringStream() - : m_index( StringStreams::instance().add() ), - m_oss( StringStreams::instance().m_streams[m_index].get() ) - {} - - ReusableStringStream::~ReusableStringStream() { - static_cast( m_oss )->str(""); - m_oss->clear(); - StringStreams::instance().release( m_index ); - } - - auto ReusableStringStream::str() const -> std::string { - return static_cast( m_oss )->str(); - } - - /////////////////////////////////////////////////////////////////////////// - -#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions - std::ostream& cout() { return std::cout; } - std::ostream& cerr() { return std::cerr; } - std::ostream& clog() { return std::clog; } -#endif -} - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif -// end catch_stream.cpp -// start catch_string_manip.cpp - -#include -#include -#include -#include - -namespace Catch { - - bool startsWith( std::string const& s, std::string const& prefix ) { - return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); - } - bool startsWith( std::string const& s, char prefix ) { - return !s.empty() && s[0] == prefix; - } - bool endsWith( std::string const& s, std::string const& suffix ) { - return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); - } - bool endsWith( std::string const& s, char suffix ) { - return !s.empty() && s[s.size()-1] == suffix; - } - bool contains( std::string const& s, std::string const& infix ) { - return s.find( infix ) != std::string::npos; - } - char toLowerCh(char c) { - return static_cast( std::tolower( c ) ); - } - void toLowerInPlace( std::string& s ) { - std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); - } - std::string toLower( std::string const& s ) { - std::string lc = s; - toLowerInPlace( lc ); - return lc; - } - std::string trim( std::string const& str ) { - static char const* whitespaceChars = "\n\r\t "; - std::string::size_type start = str.find_first_not_of( whitespaceChars ); - std::string::size_type end = str.find_last_not_of( whitespaceChars ); - - return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); - } - - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { - bool replaced = false; - std::size_t i = str.find( replaceThis ); - while( i != std::string::npos ) { - replaced = true; - str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); - if( i < str.size()-withThis.size() ) - i = str.find( replaceThis, i+withThis.size() ); - else - i = std::string::npos; - } - return replaced; - } - - pluralise::pluralise( std::size_t count, std::string const& label ) - : m_count( count ), - m_label( label ) - {} - - std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { - os << pluraliser.m_count << ' ' << pluraliser.m_label; - if( pluraliser.m_count != 1 ) - os << 's'; - return os; - } - -} -// end catch_string_manip.cpp -// start catch_stringref.cpp - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wexit-time-destructors" -#endif - -#include -#include -#include - -namespace { - const uint32_t byte_2_lead = 0xC0; - const uint32_t byte_3_lead = 0xE0; - const uint32_t byte_4_lead = 0xF0; -} - -namespace Catch { - StringRef::StringRef( char const* rawChars ) noexcept - : StringRef( rawChars, static_cast(std::strlen(rawChars) ) ) - {} - - StringRef::operator std::string() const { - return std::string( m_start, m_size ); - } - - void StringRef::swap( StringRef& other ) noexcept { - std::swap( m_start, other.m_start ); - std::swap( m_size, other.m_size ); - std::swap( m_data, other.m_data ); - } - - auto StringRef::c_str() const -> char const* { - if( isSubstring() ) - const_cast( this )->takeOwnership(); - return m_start; - } - auto StringRef::currentData() const noexcept -> char const* { - return m_start; - } - - auto StringRef::isOwned() const noexcept -> bool { - return m_data != nullptr; - } - auto StringRef::isSubstring() const noexcept -> bool { - return m_start[m_size] != '\0'; - } - - void StringRef::takeOwnership() { - if( !isOwned() ) { - m_data = new char[m_size+1]; - memcpy( m_data, m_start, m_size ); - m_data[m_size] = '\0'; - m_start = m_data; - } - } - auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef { - if( start < m_size ) - return StringRef( m_start+start, size ); - else - return StringRef(); - } - auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool { - return - size() == other.size() && - (std::strncmp( m_start, other.m_start, size() ) == 0); - } - auto StringRef::operator != ( StringRef const& other ) const noexcept -> bool { - return !operator==( other ); - } - - auto StringRef::operator[](size_type index) const noexcept -> char { - return m_start[index]; - } - - auto StringRef::numberOfCharacters() const noexcept -> size_type { - size_type noChars = m_size; - // Make adjustments for uft encodings - for( size_type i=0; i < m_size; ++i ) { - char c = m_start[i]; - if( ( c & byte_2_lead ) == byte_2_lead ) { - noChars--; - if (( c & byte_3_lead ) == byte_3_lead ) - noChars--; - if( ( c & byte_4_lead ) == byte_4_lead ) - noChars--; - } - } - return noChars; - } - - auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string { - std::string str; - str.reserve( lhs.size() + rhs.size() ); - str += lhs; - str += rhs; - return str; - } - auto operator + ( StringRef const& lhs, const char* rhs ) -> std::string { - return std::string( lhs ) + std::string( rhs ); - } - auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string { - return std::string( lhs ) + std::string( rhs ); - } - - auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& { - return os.write(str.currentData(), str.size()); - } - - auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& { - lhs.append(rhs.currentData(), rhs.size()); - return lhs; - } - -} // namespace Catch - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif -// end catch_stringref.cpp -// start catch_tag_alias.cpp - -namespace Catch { - TagAlias::TagAlias(std::string const & _tag, SourceLineInfo _lineInfo): tag(_tag), lineInfo(_lineInfo) {} -} -// end catch_tag_alias.cpp -// start catch_tag_alias_autoregistrar.cpp - -namespace Catch { - - RegistrarForTagAliases::RegistrarForTagAliases(char const* alias, char const* tag, SourceLineInfo const& lineInfo) { - try { - getMutableRegistryHub().registerTagAlias(alias, tag, lineInfo); - } catch (...) { - // Do not throw when constructing global objects, instead register the exception to be processed later - getMutableRegistryHub().registerStartupException(); - } - } - -} -// end catch_tag_alias_autoregistrar.cpp -// start catch_tag_alias_registry.cpp - -#include - -namespace Catch { - - TagAliasRegistry::~TagAliasRegistry() {} - - TagAlias const* TagAliasRegistry::find( std::string const& alias ) const { - auto it = m_registry.find( alias ); - if( it != m_registry.end() ) - return &(it->second); - else - return nullptr; - } - - std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { - std::string expandedTestSpec = unexpandedTestSpec; - for( auto const& registryKvp : m_registry ) { - std::size_t pos = expandedTestSpec.find( registryKvp.first ); - if( pos != std::string::npos ) { - expandedTestSpec = expandedTestSpec.substr( 0, pos ) + - registryKvp.second.tag + - expandedTestSpec.substr( pos + registryKvp.first.size() ); - } - } - return expandedTestSpec; - } - - void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) { - CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'), - "error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo ); - - CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second, - "error: tag alias, '" << alias << "' already registered.\n" - << "\tFirst seen at: " << find(alias)->lineInfo << "\n" - << "\tRedefined at: " << lineInfo ); - } - - ITagAliasRegistry::~ITagAliasRegistry() {} - - ITagAliasRegistry const& ITagAliasRegistry::get() { - return getRegistryHub().getTagAliasRegistry(); - } - -} // end namespace Catch -// end catch_tag_alias_registry.cpp -// start catch_test_case_info.cpp - -#include -#include -#include -#include - -namespace Catch { - - TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { - if( startsWith( tag, '.' ) || - tag == "!hide" ) - return TestCaseInfo::IsHidden; - else if( tag == "!throws" ) - return TestCaseInfo::Throws; - else if( tag == "!shouldfail" ) - return TestCaseInfo::ShouldFail; - else if( tag == "!mayfail" ) - return TestCaseInfo::MayFail; - else if( tag == "!nonportable" ) - return TestCaseInfo::NonPortable; - else if( tag == "!benchmark" ) - return static_cast( TestCaseInfo::Benchmark | TestCaseInfo::IsHidden ); - else - return TestCaseInfo::None; - } - bool isReservedTag( std::string const& tag ) { - return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] ); - } - void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { - CATCH_ENFORCE( !isReservedTag(tag), - "Tag name: [" << tag << "] is not allowed.\n" - << "Tag names starting with non alpha-numeric characters are reserved\n" - << _lineInfo ); - } - - TestCase makeTestCase( ITestInvoker* _testCase, - std::string const& _className, - NameAndTags const& nameAndTags, - SourceLineInfo const& _lineInfo ) - { - bool isHidden = false; - - // Parse out tags - std::vector tags; - std::string desc, tag; - bool inTag = false; - std::string _descOrTags = nameAndTags.tags; - for (char c : _descOrTags) { - if( !inTag ) { - if( c == '[' ) - inTag = true; - else - desc += c; - } - else { - if( c == ']' ) { - TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag ); - if( ( prop & TestCaseInfo::IsHidden ) != 0 ) - isHidden = true; - else if( prop == TestCaseInfo::None ) - enforceNotReservedTag( tag, _lineInfo ); - - tags.push_back( tag ); - tag.clear(); - inTag = false; - } - else - tag += c; - } - } - if( isHidden ) { - tags.push_back( "." ); - } - - TestCaseInfo info( nameAndTags.name, _className, desc, tags, _lineInfo ); - return TestCase( _testCase, std::move(info) ); - } - - void setTags( TestCaseInfo& testCaseInfo, std::vector tags ) { - std::sort(begin(tags), end(tags)); - tags.erase(std::unique(begin(tags), end(tags)), end(tags)); - testCaseInfo.lcaseTags.clear(); - - for( auto const& tag : tags ) { - std::string lcaseTag = toLower( tag ); - testCaseInfo.properties = static_cast( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); - testCaseInfo.lcaseTags.push_back( lcaseTag ); - } - testCaseInfo.tags = std::move(tags); - } - - TestCaseInfo::TestCaseInfo( std::string const& _name, - std::string const& _className, - std::string const& _description, - std::vector const& _tags, - SourceLineInfo const& _lineInfo ) - : name( _name ), - className( _className ), - description( _description ), - lineInfo( _lineInfo ), - properties( None ) - { - setTags( *this, _tags ); - } - - bool TestCaseInfo::isHidden() const { - return ( properties & IsHidden ) != 0; - } - bool TestCaseInfo::throws() const { - return ( properties & Throws ) != 0; - } - bool TestCaseInfo::okToFail() const { - return ( properties & (ShouldFail | MayFail ) ) != 0; - } - bool TestCaseInfo::expectedToFail() const { - return ( properties & (ShouldFail ) ) != 0; - } - - std::string TestCaseInfo::tagsAsString() const { - std::string ret; - // '[' and ']' per tag - std::size_t full_size = 2 * tags.size(); - for (const auto& tag : tags) { - full_size += tag.size(); - } - ret.reserve(full_size); - for (const auto& tag : tags) { - ret.push_back('['); - ret.append(tag); - ret.push_back(']'); - } - - return ret; - } - - TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {} - - TestCase TestCase::withName( std::string const& _newName ) const { - TestCase other( *this ); - other.name = _newName; - return other; - } - - void TestCase::invoke() const { - test->invoke(); - } - - bool TestCase::operator == ( TestCase const& other ) const { - return test.get() == other.test.get() && - name == other.name && - className == other.className; - } - - bool TestCase::operator < ( TestCase const& other ) const { - return name < other.name; - } - - TestCaseInfo const& TestCase::getTestCaseInfo() const - { - return *this; - } - -} // end namespace Catch -// end catch_test_case_info.cpp -// start catch_test_case_registry_impl.cpp - -#include - -namespace Catch { - - std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ) { - - std::vector sorted = unsortedTestCases; - - switch( config.runOrder() ) { - case RunTests::InLexicographicalOrder: - std::sort( sorted.begin(), sorted.end() ); - break; - case RunTests::InRandomOrder: - seedRng( config ); - RandomNumberGenerator::shuffle( sorted ); - break; - case RunTests::InDeclarationOrder: - // already in declaration order - break; - } - return sorted; - } - bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) { - return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() ); - } - - void enforceNoDuplicateTestCases( std::vector const& functions ) { - std::set seenFunctions; - for( auto const& function : functions ) { - auto prev = seenFunctions.insert( function ); - CATCH_ENFORCE( prev.second, - "error: TEST_CASE( \"" << function.name << "\" ) already defined.\n" - << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" - << "\tRedefined at " << function.getTestCaseInfo().lineInfo ); - } - } - - std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ) { - std::vector filtered; - filtered.reserve( testCases.size() ); - for( auto const& testCase : testCases ) - if( matchTest( testCase, testSpec, config ) ) - filtered.push_back( testCase ); - return filtered; - } - std::vector const& getAllTestCasesSorted( IConfig const& config ) { - return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config ); - } - - void TestRegistry::registerTest( TestCase const& testCase ) { - std::string name = testCase.getTestCaseInfo().name; - if( name.empty() ) { - ReusableStringStream rss; - rss << "Anonymous test case " << ++m_unnamedCount; - return registerTest( testCase.withName( rss.str() ) ); - } - m_functions.push_back( testCase ); - } - - std::vector const& TestRegistry::getAllTests() const { - return m_functions; - } - std::vector const& TestRegistry::getAllTestsSorted( IConfig const& config ) const { - if( m_sortedFunctions.empty() ) - enforceNoDuplicateTestCases( m_functions ); - - if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) { - m_sortedFunctions = sortTests( config, m_functions ); - m_currentSortOrder = config.runOrder(); - } - return m_sortedFunctions; - } - - /////////////////////////////////////////////////////////////////////////// - TestInvokerAsFunction::TestInvokerAsFunction( void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {} - - void TestInvokerAsFunction::invoke() const { - m_testAsFunction(); - } - - std::string extractClassName( StringRef const& classOrQualifiedMethodName ) { - std::string className = classOrQualifiedMethodName; - if( startsWith( className, '&' ) ) - { - std::size_t lastColons = className.rfind( "::" ); - std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); - if( penultimateColons == std::string::npos ) - penultimateColons = 1; - className = className.substr( penultimateColons, lastColons-penultimateColons ); - } - return className; - } - -} // end namespace Catch -// end catch_test_case_registry_impl.cpp -// start catch_test_case_tracker.cpp - -#include -#include -#include -#include -#include - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wexit-time-destructors" -#endif - -namespace Catch { -namespace TestCaseTracking { - - NameAndLocation::NameAndLocation( std::string const& _name, SourceLineInfo const& _location ) - : name( _name ), - location( _location ) - {} - - ITracker::~ITracker() = default; - - TrackerContext& TrackerContext::instance() { - static TrackerContext s_instance; - return s_instance; - } - - ITracker& TrackerContext::startRun() { - m_rootTracker = std::make_shared( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr ); - m_currentTracker = nullptr; - m_runState = Executing; - return *m_rootTracker; - } - - void TrackerContext::endRun() { - m_rootTracker.reset(); - m_currentTracker = nullptr; - m_runState = NotStarted; - } - - void TrackerContext::startCycle() { - m_currentTracker = m_rootTracker.get(); - m_runState = Executing; - } - void TrackerContext::completeCycle() { - m_runState = CompletedCycle; - } - - bool TrackerContext::completedCycle() const { - return m_runState == CompletedCycle; - } - ITracker& TrackerContext::currentTracker() { - return *m_currentTracker; - } - void TrackerContext::setCurrentTracker( ITracker* tracker ) { - m_currentTracker = tracker; - } - - TrackerBase::TrackerHasName::TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {} - bool TrackerBase::TrackerHasName::operator ()( ITrackerPtr const& tracker ) const { - return - tracker->nameAndLocation().name == m_nameAndLocation.name && - tracker->nameAndLocation().location == m_nameAndLocation.location; - } - - TrackerBase::TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) - : m_nameAndLocation( nameAndLocation ), - m_ctx( ctx ), - m_parent( parent ) - {} - - NameAndLocation const& TrackerBase::nameAndLocation() const { - return m_nameAndLocation; - } - bool TrackerBase::isComplete() const { - return m_runState == CompletedSuccessfully || m_runState == Failed; - } - bool TrackerBase::isSuccessfullyCompleted() const { - return m_runState == CompletedSuccessfully; - } - bool TrackerBase::isOpen() const { - return m_runState != NotStarted && !isComplete(); - } - bool TrackerBase::hasChildren() const { - return !m_children.empty(); - } - - void TrackerBase::addChild( ITrackerPtr const& child ) { - m_children.push_back( child ); - } - - ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) { - auto it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) ); - return( it != m_children.end() ) - ? *it - : nullptr; - } - ITracker& TrackerBase::parent() { - assert( m_parent ); // Should always be non-null except for root - return *m_parent; - } - - void TrackerBase::openChild() { - if( m_runState != ExecutingChildren ) { - m_runState = ExecutingChildren; - if( m_parent ) - m_parent->openChild(); - } - } - - bool TrackerBase::isSectionTracker() const { return false; } - bool TrackerBase::isIndexTracker() const { return false; } - - void TrackerBase::open() { - m_runState = Executing; - moveToThis(); - if( m_parent ) - m_parent->openChild(); - } - - void TrackerBase::close() { - - // Close any still open children (e.g. generators) - while( &m_ctx.currentTracker() != this ) - m_ctx.currentTracker().close(); - - switch( m_runState ) { - case NeedsAnotherRun: - break; - - case Executing: - m_runState = CompletedSuccessfully; - break; - case ExecutingChildren: - if( m_children.empty() || m_children.back()->isComplete() ) - m_runState = CompletedSuccessfully; - break; - - case NotStarted: - case CompletedSuccessfully: - case Failed: - CATCH_INTERNAL_ERROR( "Illogical state: " << m_runState ); - - default: - CATCH_INTERNAL_ERROR( "Unknown state: " << m_runState ); - } - moveToParent(); - m_ctx.completeCycle(); - } - void TrackerBase::fail() { - m_runState = Failed; - if( m_parent ) - m_parent->markAsNeedingAnotherRun(); - moveToParent(); - m_ctx.completeCycle(); - } - void TrackerBase::markAsNeedingAnotherRun() { - m_runState = NeedsAnotherRun; - } - - void TrackerBase::moveToParent() { - assert( m_parent ); - m_ctx.setCurrentTracker( m_parent ); - } - void TrackerBase::moveToThis() { - m_ctx.setCurrentTracker( this ); - } - - SectionTracker::SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) - : TrackerBase( nameAndLocation, ctx, parent ) - { - if( parent ) { - while( !parent->isSectionTracker() ) - parent = &parent->parent(); - - SectionTracker& parentSection = static_cast( *parent ); - addNextFilters( parentSection.m_filters ); - } - } - - bool SectionTracker::isSectionTracker() const { return true; } - - SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) { - std::shared_ptr section; - - ITracker& currentTracker = ctx.currentTracker(); - if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { - assert( childTracker ); - assert( childTracker->isSectionTracker() ); - section = std::static_pointer_cast( childTracker ); - } - else { - section = std::make_shared( nameAndLocation, ctx, ¤tTracker ); - currentTracker.addChild( section ); - } - if( !ctx.completedCycle() ) - section->tryOpen(); - return *section; - } - - void SectionTracker::tryOpen() { - if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) ) - open(); - } - - void SectionTracker::addInitialFilters( std::vector const& filters ) { - if( !filters.empty() ) { - m_filters.push_back(""); // Root - should never be consulted - m_filters.push_back(""); // Test Case - not a section filter - m_filters.insert( m_filters.end(), filters.begin(), filters.end() ); - } - } - void SectionTracker::addNextFilters( std::vector const& filters ) { - if( filters.size() > 1 ) - m_filters.insert( m_filters.end(), ++filters.begin(), filters.end() ); - } - - IndexTracker::IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ) - : TrackerBase( nameAndLocation, ctx, parent ), - m_size( size ) - {} - - bool IndexTracker::isIndexTracker() const { return true; } - - IndexTracker& IndexTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ) { - std::shared_ptr tracker; - - ITracker& currentTracker = ctx.currentTracker(); - if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { - assert( childTracker ); - assert( childTracker->isIndexTracker() ); - tracker = std::static_pointer_cast( childTracker ); - } - else { - tracker = std::make_shared( nameAndLocation, ctx, ¤tTracker, size ); - currentTracker.addChild( tracker ); - } - - if( !ctx.completedCycle() && !tracker->isComplete() ) { - if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun ) - tracker->moveNext(); - tracker->open(); - } - - return *tracker; - } - - int IndexTracker::index() const { return m_index; } - - void IndexTracker::moveNext() { - m_index++; - m_children.clear(); - } - - void IndexTracker::close() { - TrackerBase::close(); - if( m_runState == CompletedSuccessfully && m_index < m_size-1 ) - m_runState = Executing; - } - -} // namespace TestCaseTracking - -using TestCaseTracking::ITracker; -using TestCaseTracking::TrackerContext; -using TestCaseTracking::SectionTracker; -using TestCaseTracking::IndexTracker; - -} // namespace Catch - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif -// end catch_test_case_tracker.cpp -// start catch_test_registry.cpp - -namespace Catch { - - auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker* { - return new(std::nothrow) TestInvokerAsFunction( testAsFunction ); - } - - NameAndTags::NameAndTags( StringRef const& name_ , StringRef const& tags_ ) noexcept : name( name_ ), tags( tags_ ) {} - - AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept { - try { - getMutableRegistryHub() - .registerTest( - makeTestCase( - invoker, - extractClassName( classOrMethod ), - nameAndTags, - lineInfo)); - } catch (...) { - // Do not throw when constructing global objects, instead register the exception to be processed later - getMutableRegistryHub().registerStartupException(); - } - } - - AutoReg::~AutoReg() = default; -} -// end catch_test_registry.cpp -// start catch_test_spec.cpp - -#include -#include -#include -#include - -namespace Catch { - - TestSpec::Pattern::~Pattern() = default; - TestSpec::NamePattern::~NamePattern() = default; - TestSpec::TagPattern::~TagPattern() = default; - TestSpec::ExcludedPattern::~ExcludedPattern() = default; - - TestSpec::NamePattern::NamePattern( std::string const& name ) - : m_wildcardPattern( toLower( name ), CaseSensitive::No ) - {} - bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const { - return m_wildcardPattern.matches( toLower( testCase.name ) ); - } - - TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} - bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const { - return std::find(begin(testCase.lcaseTags), - end(testCase.lcaseTags), - m_tag) != end(testCase.lcaseTags); - } - - TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} - bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } - - bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const { - // All patterns in a filter must match for the filter to be a match - for( auto const& pattern : m_patterns ) { - if( !pattern->matches( testCase ) ) - return false; - } - return true; - } - - bool TestSpec::hasFilters() const { - return !m_filters.empty(); - } - bool TestSpec::matches( TestCaseInfo const& testCase ) const { - // A TestSpec matches if any filter matches - for( auto const& filter : m_filters ) - if( filter.matches( testCase ) ) - return true; - return false; - } -} -// end catch_test_spec.cpp -// start catch_test_spec_parser.cpp - -namespace Catch { - - TestSpecParser::TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} - - TestSpecParser& TestSpecParser::parse( std::string const& arg ) { - m_mode = None; - m_exclusion = false; - m_start = std::string::npos; - m_arg = m_tagAliases->expandAliases( arg ); - m_escapeChars.clear(); - for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) - visitChar( m_arg[m_pos] ); - if( m_mode == Name ) - addPattern(); - return *this; - } - TestSpec TestSpecParser::testSpec() { - addFilter(); - return m_testSpec; - } - - void TestSpecParser::visitChar( char c ) { - if( m_mode == None ) { - switch( c ) { - case ' ': return; - case '~': m_exclusion = true; return; - case '[': return startNewMode( Tag, ++m_pos ); - case '"': return startNewMode( QuotedName, ++m_pos ); - case '\\': return escape(); - default: startNewMode( Name, m_pos ); break; - } - } - if( m_mode == Name ) { - if( c == ',' ) { - addPattern(); - addFilter(); - } - else if( c == '[' ) { - if( subString() == "exclude:" ) - m_exclusion = true; - else - addPattern(); - startNewMode( Tag, ++m_pos ); - } - else if( c == '\\' ) - escape(); - } - else if( m_mode == EscapedName ) - m_mode = Name; - else if( m_mode == QuotedName && c == '"' ) - addPattern(); - else if( m_mode == Tag && c == ']' ) - addPattern(); - } - void TestSpecParser::startNewMode( Mode mode, std::size_t start ) { - m_mode = mode; - m_start = start; - } - void TestSpecParser::escape() { - if( m_mode == None ) - m_start = m_pos; - m_mode = EscapedName; - m_escapeChars.push_back( m_pos ); - } - std::string TestSpecParser::subString() const { return m_arg.substr( m_start, m_pos - m_start ); } - - void TestSpecParser::addFilter() { - if( !m_currentFilter.m_patterns.empty() ) { - m_testSpec.m_filters.push_back( m_currentFilter ); - m_currentFilter = TestSpec::Filter(); - } - } - - TestSpec parseTestSpec( std::string const& arg ) { - return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); - } - -} // namespace Catch -// end catch_test_spec_parser.cpp -// start catch_timer.cpp - -#include - -static const uint64_t nanosecondsInSecond = 1000000000; - -namespace Catch { - - auto getCurrentNanosecondsSinceEpoch() -> uint64_t { - return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); - } - - auto estimateClockResolution() -> uint64_t { - uint64_t sum = 0; - static const uint64_t iterations = 1000000; - - auto startTime = getCurrentNanosecondsSinceEpoch(); - - for( std::size_t i = 0; i < iterations; ++i ) { - - uint64_t ticks; - uint64_t baseTicks = getCurrentNanosecondsSinceEpoch(); - do { - ticks = getCurrentNanosecondsSinceEpoch(); - } while( ticks == baseTicks ); - - auto delta = ticks - baseTicks; - sum += delta; - - // If we have been calibrating for over 3 seconds -- the clock - // is terrible and we should move on. - // TBD: How to signal that the measured resolution is probably wrong? - if (ticks > startTime + 3 * nanosecondsInSecond) { - return sum / i; - } - } - - // We're just taking the mean, here. To do better we could take the std. dev and exclude outliers - // - and potentially do more iterations if there's a high variance. - return sum/iterations; - } - auto getEstimatedClockResolution() -> uint64_t { - static auto s_resolution = estimateClockResolution(); - return s_resolution; - } - - void Timer::start() { - m_nanoseconds = getCurrentNanosecondsSinceEpoch(); - } - auto Timer::getElapsedNanoseconds() const -> uint64_t { - return getCurrentNanosecondsSinceEpoch() - m_nanoseconds; - } - auto Timer::getElapsedMicroseconds() const -> uint64_t { - return getElapsedNanoseconds()/1000; - } - auto Timer::getElapsedMilliseconds() const -> unsigned int { - return static_cast(getElapsedMicroseconds()/1000); - } - auto Timer::getElapsedSeconds() const -> double { - return getElapsedMicroseconds()/1000000.0; - } - -} // namespace Catch -// end catch_timer.cpp -// start catch_tostring.cpp - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wexit-time-destructors" -# pragma clang diagnostic ignored "-Wglobal-constructors" -#endif - -// Enable specific decls locally -#if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) -#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER -#endif - -#include -#include - -namespace Catch { - -namespace Detail { - - const std::string unprintableString = "{?}"; - - namespace { - const int hexThreshold = 255; - - struct Endianness { - enum Arch { Big, Little }; - - static Arch which() { - union _{ - int asInt; - char asChar[sizeof (int)]; - } u; - - u.asInt = 1; - return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little; - } - }; - } - - std::string rawMemoryToString( const void *object, std::size_t size ) { - // Reverse order for little endian architectures - int i = 0, end = static_cast( size ), inc = 1; - if( Endianness::which() == Endianness::Little ) { - i = end-1; - end = inc = -1; - } - - unsigned char const *bytes = static_cast(object); - ReusableStringStream rss; - rss << "0x" << std::setfill('0') << std::hex; - for( ; i != end; i += inc ) - rss << std::setw(2) << static_cast(bytes[i]); - return rss.str(); - } -} - -template -std::string fpToString( T value, int precision ) { - if (std::isnan(value)) { - return "nan"; - } - - ReusableStringStream rss; - rss << std::setprecision( precision ) - << std::fixed - << value; - std::string d = rss.str(); - std::size_t i = d.find_last_not_of( '0' ); - if( i != std::string::npos && i != d.size()-1 ) { - if( d[i] == '.' ) - i++; - d = d.substr( 0, i+1 ); - } - return d; -} - -//// ======================================================= //// -// -// Out-of-line defs for full specialization of StringMaker -// -//// ======================================================= //// - -std::string StringMaker::convert(const std::string& str) { - if (!getCurrentContext().getConfig()->showInvisibles()) { - return '"' + str + '"'; - } - - std::string s("\""); - for (char c : str) { - switch (c) { - case '\n': - s.append("\\n"); - break; - case '\t': - s.append("\\t"); - break; - default: - s.push_back(c); - break; - } - } - s.append("\""); - return s; -} - -#ifdef CATCH_CONFIG_WCHAR -std::string StringMaker::convert(const std::wstring& wstr) { - std::string s; - s.reserve(wstr.size()); - for (auto c : wstr) { - s += (c <= 0xff) ? static_cast(c) : '?'; - } - return ::Catch::Detail::stringify(s); -} -#endif - -std::string StringMaker::convert(char const* str) { - if (str) { - return ::Catch::Detail::stringify(std::string{ str }); - } else { - return{ "{null string}" }; - } -} -std::string StringMaker::convert(char* str) { - if (str) { - return ::Catch::Detail::stringify(std::string{ str }); - } else { - return{ "{null string}" }; - } -} -#ifdef CATCH_CONFIG_WCHAR -std::string StringMaker::convert(wchar_t const * str) { - if (str) { - return ::Catch::Detail::stringify(std::wstring{ str }); - } else { - return{ "{null string}" }; - } -} -std::string StringMaker::convert(wchar_t * str) { - if (str) { - return ::Catch::Detail::stringify(std::wstring{ str }); - } else { - return{ "{null string}" }; - } -} -#endif - -std::string StringMaker::convert(int value) { - return ::Catch::Detail::stringify(static_cast(value)); -} -std::string StringMaker::convert(long value) { - return ::Catch::Detail::stringify(static_cast(value)); -} -std::string StringMaker::convert(long long value) { - ReusableStringStream rss; - rss << value; - if (value > Detail::hexThreshold) { - rss << " (0x" << std::hex << value << ')'; - } - return rss.str(); -} - -std::string StringMaker::convert(unsigned int value) { - return ::Catch::Detail::stringify(static_cast(value)); -} -std::string StringMaker::convert(unsigned long value) { - return ::Catch::Detail::stringify(static_cast(value)); -} -std::string StringMaker::convert(unsigned long long value) { - ReusableStringStream rss; - rss << value; - if (value > Detail::hexThreshold) { - rss << " (0x" << std::hex << value << ')'; - } - return rss.str(); -} - -std::string StringMaker::convert(bool b) { - return b ? "true" : "false"; -} - -std::string StringMaker::convert(char value) { - if (value == '\r') { - return "'\\r'"; - } else if (value == '\f') { - return "'\\f'"; - } else if (value == '\n') { - return "'\\n'"; - } else if (value == '\t') { - return "'\\t'"; - } else if ('\0' <= value && value < ' ') { - return ::Catch::Detail::stringify(static_cast(value)); - } else { - char chstr[] = "' '"; - chstr[1] = value; - return chstr; - } -} -std::string StringMaker::convert(signed char c) { - return ::Catch::Detail::stringify(static_cast(c)); -} -std::string StringMaker::convert(unsigned char c) { - return ::Catch::Detail::stringify(static_cast(c)); -} - -std::string StringMaker::convert(std::nullptr_t) { - return "nullptr"; -} - -std::string StringMaker::convert(float value) { - return fpToString(value, 5) + 'f'; -} -std::string StringMaker::convert(double value) { - return fpToString(value, 10); -} - -std::string ratio_string::symbol() { return "a"; } -std::string ratio_string::symbol() { return "f"; } -std::string ratio_string::symbol() { return "p"; } -std::string ratio_string::symbol() { return "n"; } -std::string ratio_string::symbol() { return "u"; } -std::string ratio_string::symbol() { return "m"; } - -} // end namespace Catch - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - -// end catch_tostring.cpp -// start catch_totals.cpp - -namespace Catch { - - Counts Counts::operator - ( Counts const& other ) const { - Counts diff; - diff.passed = passed - other.passed; - diff.failed = failed - other.failed; - diff.failedButOk = failedButOk - other.failedButOk; - return diff; - } - - Counts& Counts::operator += ( Counts const& other ) { - passed += other.passed; - failed += other.failed; - failedButOk += other.failedButOk; - return *this; - } - - std::size_t Counts::total() const { - return passed + failed + failedButOk; - } - bool Counts::allPassed() const { - return failed == 0 && failedButOk == 0; - } - bool Counts::allOk() const { - return failed == 0; - } - - Totals Totals::operator - ( Totals const& other ) const { - Totals diff; - diff.assertions = assertions - other.assertions; - diff.testCases = testCases - other.testCases; - return diff; - } - - Totals& Totals::operator += ( Totals const& other ) { - assertions += other.assertions; - testCases += other.testCases; - return *this; - } - - Totals Totals::delta( Totals const& prevTotals ) const { - Totals diff = *this - prevTotals; - if( diff.assertions.failed > 0 ) - ++diff.testCases.failed; - else if( diff.assertions.failedButOk > 0 ) - ++diff.testCases.failedButOk; - else - ++diff.testCases.passed; - return diff; - } - -} -// end catch_totals.cpp -// start catch_uncaught_exceptions.cpp - -#include - -namespace Catch { - bool uncaught_exceptions() { -#if defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) - return std::uncaught_exceptions() > 0; -#else - return std::uncaught_exception(); -#endif - } -} // end namespace Catch -// end catch_uncaught_exceptions.cpp -// start catch_version.cpp - -#include - -namespace Catch { - - Version::Version - ( unsigned int _majorVersion, - unsigned int _minorVersion, - unsigned int _patchNumber, - char const * const _branchName, - unsigned int _buildNumber ) - : majorVersion( _majorVersion ), - minorVersion( _minorVersion ), - patchNumber( _patchNumber ), - branchName( _branchName ), - buildNumber( _buildNumber ) - {} - - std::ostream& operator << ( std::ostream& os, Version const& version ) { - os << version.majorVersion << '.' - << version.minorVersion << '.' - << version.patchNumber; - // branchName is never null -> 0th char is \0 if it is empty - if (version.branchName[0]) { - os << '-' << version.branchName - << '.' << version.buildNumber; - } - return os; - } - - Version const& libraryVersion() { - static Version version( 2, 2, 2, "", 0 ); - return version; - } - -} -// end catch_version.cpp -// start catch_wildcard_pattern.cpp - -#include - -namespace Catch { - - WildcardPattern::WildcardPattern( std::string const& pattern, - CaseSensitive::Choice caseSensitivity ) - : m_caseSensitivity( caseSensitivity ), - m_pattern( adjustCase( pattern ) ) - { - if( startsWith( m_pattern, '*' ) ) { - m_pattern = m_pattern.substr( 1 ); - m_wildcard = WildcardAtStart; - } - if( endsWith( m_pattern, '*' ) ) { - m_pattern = m_pattern.substr( 0, m_pattern.size()-1 ); - m_wildcard = static_cast( m_wildcard | WildcardAtEnd ); - } - } - - bool WildcardPattern::matches( std::string const& str ) const { - switch( m_wildcard ) { - case NoWildcard: - return m_pattern == adjustCase( str ); - case WildcardAtStart: - return endsWith( adjustCase( str ), m_pattern ); - case WildcardAtEnd: - return startsWith( adjustCase( str ), m_pattern ); - case WildcardAtBothEnds: - return contains( adjustCase( str ), m_pattern ); - default: - CATCH_INTERNAL_ERROR( "Unknown enum" ); - } - } - - std::string WildcardPattern::adjustCase( std::string const& str ) const { - return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str; - } -} -// end catch_wildcard_pattern.cpp -// start catch_xmlwriter.cpp - -#include - -using uchar = unsigned char; - -namespace Catch { - -namespace { - - size_t trailingBytes(unsigned char c) { - if ((c & 0xE0) == 0xC0) { - return 2; - } - if ((c & 0xF0) == 0xE0) { - return 3; - } - if ((c & 0xF8) == 0xF0) { - return 4; - } - CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered"); - } - - uint32_t headerValue(unsigned char c) { - if ((c & 0xE0) == 0xC0) { - return c & 0x1F; - } - if ((c & 0xF0) == 0xE0) { - return c & 0x0F; - } - if ((c & 0xF8) == 0xF0) { - return c & 0x07; - } - CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered"); - } - - void hexEscapeChar(std::ostream& os, unsigned char c) { - os << "\\x" - << std::uppercase << std::hex << std::setfill('0') << std::setw(2) - << static_cast(c); - } - -} // anonymous namespace - - XmlEncode::XmlEncode( std::string const& str, ForWhat forWhat ) - : m_str( str ), - m_forWhat( forWhat ) - {} - - void XmlEncode::encodeTo( std::ostream& os ) const { - // Apostrophe escaping not necessary if we always use " to write attributes - // (see: http://www.w3.org/TR/xml/#syntax) - - for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) { - uchar c = m_str[idx]; - switch (c) { - case '<': os << "<"; break; - case '&': os << "&"; break; - - case '>': - // See: http://www.w3.org/TR/xml/#syntax - if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']') - os << ">"; - else - os << c; - break; - - case '\"': - if (m_forWhat == ForAttributes) - os << """; - else - os << c; - break; - - default: - // Check for control characters and invalid utf-8 - - // Escape control characters in standard ascii - // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 - if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) { - hexEscapeChar(os, c); - break; - } - - // Plain ASCII: Write it to stream - if (c < 0x7F) { - os << c; - break; - } - - // UTF-8 territory - // Check if the encoding is valid and if it is not, hex escape bytes. - // Important: We do not check the exact decoded values for validity, only the encoding format - // First check that this bytes is a valid lead byte: - // This means that it is not encoded as 1111 1XXX - // Or as 10XX XXXX - if (c < 0xC0 || - c >= 0xF8) { - hexEscapeChar(os, c); - break; - } - - auto encBytes = trailingBytes(c); - // Are there enough bytes left to avoid accessing out-of-bounds memory? - if (idx + encBytes - 1 >= m_str.size()) { - hexEscapeChar(os, c); - break; - } - // The header is valid, check data - // The next encBytes bytes must together be a valid utf-8 - // This means: bitpattern 10XX XXXX and the extracted value is sane (ish) - bool valid = true; - uint32_t value = headerValue(c); - for (std::size_t n = 1; n < encBytes; ++n) { - uchar nc = m_str[idx + n]; - valid &= ((nc & 0xC0) == 0x80); - value = (value << 6) | (nc & 0x3F); - } - - if ( - // Wrong bit pattern of following bytes - (!valid) || - // Overlong encodings - (value < 0x80) || - (0x80 <= value && value < 0x800 && encBytes > 2) || - (0x800 < value && value < 0x10000 && encBytes > 3) || - // Encoded value out of range - (value >= 0x110000) - ) { - hexEscapeChar(os, c); - break; - } - - // If we got here, this is in fact a valid(ish) utf-8 sequence - for (std::size_t n = 0; n < encBytes; ++n) { - os << m_str[idx + n]; - } - idx += encBytes - 1; - break; - } - } - } - - std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { - xmlEncode.encodeTo( os ); - return os; - } - - XmlWriter::ScopedElement::ScopedElement( XmlWriter* writer ) - : m_writer( writer ) - {} - - XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept - : m_writer( other.m_writer ){ - other.m_writer = nullptr; - } - XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept { - if ( m_writer ) { - m_writer->endElement(); - } - m_writer = other.m_writer; - other.m_writer = nullptr; - return *this; - } - - XmlWriter::ScopedElement::~ScopedElement() { - if( m_writer ) - m_writer->endElement(); - } - - XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string const& text, bool indent ) { - m_writer->writeText( text, indent ); - return *this; - } - - XmlWriter::XmlWriter( std::ostream& os ) : m_os( os ) - { - writeDeclaration(); - } - - XmlWriter::~XmlWriter() { - while( !m_tags.empty() ) - endElement(); - } - - XmlWriter& XmlWriter::startElement( std::string const& name ) { - ensureTagClosed(); - newlineIfNecessary(); - m_os << m_indent << '<' << name; - m_tags.push_back( name ); - m_indent += " "; - m_tagIsOpen = true; - return *this; - } - - XmlWriter::ScopedElement XmlWriter::scopedElement( std::string const& name ) { - ScopedElement scoped( this ); - startElement( name ); - return scoped; - } - - XmlWriter& XmlWriter::endElement() { - newlineIfNecessary(); - m_indent = m_indent.substr( 0, m_indent.size()-2 ); - if( m_tagIsOpen ) { - m_os << "/>"; - m_tagIsOpen = false; - } - else { - m_os << m_indent << ""; - } - m_os << std::endl; - m_tags.pop_back(); - return *this; - } - - XmlWriter& XmlWriter::writeAttribute( std::string const& name, std::string const& attribute ) { - if( !name.empty() && !attribute.empty() ) - m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"'; - return *this; - } - - XmlWriter& XmlWriter::writeAttribute( std::string const& name, bool attribute ) { - m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"'; - return *this; - } - - XmlWriter& XmlWriter::writeText( std::string const& text, bool indent ) { - if( !text.empty() ){ - bool tagWasOpen = m_tagIsOpen; - ensureTagClosed(); - if( tagWasOpen && indent ) - m_os << m_indent; - m_os << XmlEncode( text ); - m_needsNewline = true; - } - return *this; - } - - XmlWriter& XmlWriter::writeComment( std::string const& text ) { - ensureTagClosed(); - m_os << m_indent << ""; - m_needsNewline = true; - return *this; - } - - void XmlWriter::writeStylesheetRef( std::string const& url ) { - m_os << "\n"; - } - - XmlWriter& XmlWriter::writeBlankLine() { - ensureTagClosed(); - m_os << '\n'; - return *this; - } - - void XmlWriter::ensureTagClosed() { - if( m_tagIsOpen ) { - m_os << ">" << std::endl; - m_tagIsOpen = false; - } - } - - void XmlWriter::writeDeclaration() { - m_os << "\n"; - } - - void XmlWriter::newlineIfNecessary() { - if( m_needsNewline ) { - m_os << std::endl; - m_needsNewline = false; - } - } -} -// end catch_xmlwriter.cpp -// start catch_reporter_bases.cpp - -#include -#include -#include -#include -#include - -namespace Catch { - void prepareExpandedExpression(AssertionResult& result) { - result.getExpandedExpression(); - } - - // Because formatting using c++ streams is stateful, drop down to C is required - // Alternatively we could use stringstream, but its performance is... not good. - std::string getFormattedDuration( double duration ) { - // Max exponent + 1 is required to represent the whole part - // + 1 for decimal point - // + 3 for the 3 decimal places - // + 1 for null terminator - const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; - char buffer[maxDoubleSize]; - - // Save previous errno, to prevent sprintf from overwriting it - ErrnoGuard guard; -#ifdef _MSC_VER - sprintf_s(buffer, "%.3f", duration); -#else - sprintf(buffer, "%.3f", duration); -#endif - return std::string(buffer); - } - - TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config) - :StreamingReporterBase(_config) {} - - void TestEventListenerBase::assertionStarting(AssertionInfo const &) {} - - bool TestEventListenerBase::assertionEnded(AssertionStats const &) { - return false; - } - -} // end namespace Catch -// end catch_reporter_bases.cpp -// start catch_reporter_compact.cpp - -namespace { - -#ifdef CATCH_PLATFORM_MAC - const char* failedString() { return "FAILED"; } - const char* passedString() { return "PASSED"; } -#else - const char* failedString() { return "failed"; } - const char* passedString() { return "passed"; } -#endif - - // Colour::LightGrey - Catch::Colour::Code dimColour() { return Catch::Colour::FileName; } - - std::string bothOrAll( std::size_t count ) { - return count == 1 ? std::string() : - count == 2 ? "both " : "all " ; - } - -} // anon namespace - -namespace Catch { -namespace { -// Colour, message variants: -// - white: No tests ran. -// - red: Failed [both/all] N test cases, failed [both/all] M assertions. -// - white: Passed [both/all] N test cases (no assertions). -// - red: Failed N tests cases, failed M assertions. -// - green: Passed [both/all] N tests cases with M assertions. -void printTotals(std::ostream& out, const Totals& totals) { - if (totals.testCases.total() == 0) { - out << "No tests ran."; - } else if (totals.testCases.failed == totals.testCases.total()) { - Colour colour(Colour::ResultError); - const std::string qualify_assertions_failed = - totals.assertions.failed == totals.assertions.total() ? - bothOrAll(totals.assertions.failed) : std::string(); - out << - "Failed " << bothOrAll(totals.testCases.failed) - << pluralise(totals.testCases.failed, "test case") << ", " - "failed " << qualify_assertions_failed << - pluralise(totals.assertions.failed, "assertion") << '.'; - } else if (totals.assertions.total() == 0) { - out << - "Passed " << bothOrAll(totals.testCases.total()) - << pluralise(totals.testCases.total(), "test case") - << " (no assertions)."; - } else if (totals.assertions.failed) { - Colour colour(Colour::ResultError); - out << - "Failed " << pluralise(totals.testCases.failed, "test case") << ", " - "failed " << pluralise(totals.assertions.failed, "assertion") << '.'; - } else { - Colour colour(Colour::ResultSuccess); - out << - "Passed " << bothOrAll(totals.testCases.passed) - << pluralise(totals.testCases.passed, "test case") << - " with " << pluralise(totals.assertions.passed, "assertion") << '.'; - } -} - -// Implementation of CompactReporter formatting -class AssertionPrinter { -public: - AssertionPrinter& operator= (AssertionPrinter const&) = delete; - AssertionPrinter(AssertionPrinter const&) = delete; - AssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) - : stream(_stream) - , result(_stats.assertionResult) - , messages(_stats.infoMessages) - , itMessage(_stats.infoMessages.begin()) - , printInfoMessages(_printInfoMessages) {} - - void print() { - printSourceInfo(); - - itMessage = messages.begin(); - - switch (result.getResultType()) { - case ResultWas::Ok: - printResultType(Colour::ResultSuccess, passedString()); - printOriginalExpression(); - printReconstructedExpression(); - if (!result.hasExpression()) - printRemainingMessages(Colour::None); - else - printRemainingMessages(); - break; - case ResultWas::ExpressionFailed: - if (result.isOk()) - printResultType(Colour::ResultSuccess, failedString() + std::string(" - but was ok")); - else - printResultType(Colour::Error, failedString()); - printOriginalExpression(); - printReconstructedExpression(); - printRemainingMessages(); - break; - case ResultWas::ThrewException: - printResultType(Colour::Error, failedString()); - printIssue("unexpected exception with message:"); - printMessage(); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::FatalErrorCondition: - printResultType(Colour::Error, failedString()); - printIssue("fatal error condition with message:"); - printMessage(); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::DidntThrowException: - printResultType(Colour::Error, failedString()); - printIssue("expected exception, got none"); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::Info: - printResultType(Colour::None, "info"); - printMessage(); - printRemainingMessages(); - break; - case ResultWas::Warning: - printResultType(Colour::None, "warning"); - printMessage(); - printRemainingMessages(); - break; - case ResultWas::ExplicitFailure: - printResultType(Colour::Error, failedString()); - printIssue("explicitly"); - printRemainingMessages(Colour::None); - break; - // These cases are here to prevent compiler warnings - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - printResultType(Colour::Error, "** internal error **"); - break; - } - } - -private: - void printSourceInfo() const { - Colour colourGuard(Colour::FileName); - stream << result.getSourceInfo() << ':'; - } - - void printResultType(Colour::Code colour, std::string const& passOrFail) const { - if (!passOrFail.empty()) { - { - Colour colourGuard(colour); - stream << ' ' << passOrFail; - } - stream << ':'; - } - } - - void printIssue(std::string const& issue) const { - stream << ' ' << issue; - } - - void printExpressionWas() { - if (result.hasExpression()) { - stream << ';'; - { - Colour colour(dimColour()); - stream << " expression was:"; - } - printOriginalExpression(); - } - } - - void printOriginalExpression() const { - if (result.hasExpression()) { - stream << ' ' << result.getExpression(); - } - } - - void printReconstructedExpression() const { - if (result.hasExpandedExpression()) { - { - Colour colour(dimColour()); - stream << " for: "; - } - stream << result.getExpandedExpression(); - } - } - - void printMessage() { - if (itMessage != messages.end()) { - stream << " '" << itMessage->message << '\''; - ++itMessage; - } - } - - void printRemainingMessages(Colour::Code colour = dimColour()) { - if (itMessage == messages.end()) - return; - - // using messages.end() directly yields (or auto) compilation error: - std::vector::const_iterator itEnd = messages.end(); - const std::size_t N = static_cast(std::distance(itMessage, itEnd)); - - { - Colour colourGuard(colour); - stream << " with " << pluralise(N, "message") << ':'; - } - - for (; itMessage != itEnd; ) { - // If this assertion is a warning ignore any INFO messages - if (printInfoMessages || itMessage->type != ResultWas::Info) { - stream << " '" << itMessage->message << '\''; - if (++itMessage != itEnd) { - Colour colourGuard(dimColour()); - stream << " and"; - } - } - } - } - -private: - std::ostream& stream; - AssertionResult const& result; - std::vector messages; - std::vector::const_iterator itMessage; - bool printInfoMessages; -}; - -} // anon namespace - - std::string CompactReporter::getDescription() { - return "Reports test results on a single line, suitable for IDEs"; - } - - ReporterPreferences CompactReporter::getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = false; - return prefs; - } - - void CompactReporter::noMatchingTestCases( std::string const& spec ) { - stream << "No test cases matched '" << spec << '\'' << std::endl; - } - - void CompactReporter::assertionStarting( AssertionInfo const& ) {} - - bool CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) { - AssertionResult const& result = _assertionStats.assertionResult; - - bool printInfoMessages = true; - - // Drop out if result was successful and we're not printing those - if( !m_config->includeSuccessfulResults() && result.isOk() ) { - if( result.getResultType() != ResultWas::Warning ) - return false; - printInfoMessages = false; - } - - AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); - printer.print(); - - stream << std::endl; - return true; - } - - void CompactReporter::sectionEnded(SectionStats const& _sectionStats) { - if (m_config->showDurations() == ShowDurations::Always) { - stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; - } - } - - void CompactReporter::testRunEnded( TestRunStats const& _testRunStats ) { - printTotals( stream, _testRunStats.totals ); - stream << '\n' << std::endl; - StreamingReporterBase::testRunEnded( _testRunStats ); - } - - CompactReporter::~CompactReporter() {} - - CATCH_REGISTER_REPORTER( "compact", CompactReporter ) - -} // end namespace Catch -// end catch_reporter_compact.cpp -// start catch_reporter_console.cpp - -#include -#include - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch - // Note that 4062 (not all labels are handled - // and default is missing) is enabled -#endif - -namespace Catch { - -namespace { - -// Formatter impl for ConsoleReporter -class ConsoleAssertionPrinter { -public: - ConsoleAssertionPrinter& operator= (ConsoleAssertionPrinter const&) = delete; - ConsoleAssertionPrinter(ConsoleAssertionPrinter const&) = delete; - ConsoleAssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) - : stream(_stream), - stats(_stats), - result(_stats.assertionResult), - colour(Colour::None), - message(result.getMessage()), - messages(_stats.infoMessages), - printInfoMessages(_printInfoMessages) { - switch (result.getResultType()) { - case ResultWas::Ok: - colour = Colour::Success; - passOrFail = "PASSED"; - //if( result.hasMessage() ) - if (_stats.infoMessages.size() == 1) - messageLabel = "with message"; - if (_stats.infoMessages.size() > 1) - messageLabel = "with messages"; - break; - case ResultWas::ExpressionFailed: - if (result.isOk()) { - colour = Colour::Success; - passOrFail = "FAILED - but was ok"; - } else { - colour = Colour::Error; - passOrFail = "FAILED"; - } - if (_stats.infoMessages.size() == 1) - messageLabel = "with message"; - if (_stats.infoMessages.size() > 1) - messageLabel = "with messages"; - break; - case ResultWas::ThrewException: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "due to unexpected exception with "; - if (_stats.infoMessages.size() == 1) - messageLabel += "message"; - if (_stats.infoMessages.size() > 1) - messageLabel += "messages"; - break; - case ResultWas::FatalErrorCondition: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "due to a fatal error condition"; - break; - case ResultWas::DidntThrowException: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "because no exception was thrown where one was expected"; - break; - case ResultWas::Info: - messageLabel = "info"; - break; - case ResultWas::Warning: - messageLabel = "warning"; - break; - case ResultWas::ExplicitFailure: - passOrFail = "FAILED"; - colour = Colour::Error; - if (_stats.infoMessages.size() == 1) - messageLabel = "explicitly with message"; - if (_stats.infoMessages.size() > 1) - messageLabel = "explicitly with messages"; - break; - // These cases are here to prevent compiler warnings - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - passOrFail = "** internal error **"; - colour = Colour::Error; - break; - } - } - - void print() const { - printSourceInfo(); - if (stats.totals.assertions.total() > 0) { - if (result.isOk()) - stream << '\n'; - printResultType(); - printOriginalExpression(); - printReconstructedExpression(); - } else { - stream << '\n'; - } - printMessage(); - } - -private: - void printResultType() const { - if (!passOrFail.empty()) { - Colour colourGuard(colour); - stream << passOrFail << ":\n"; - } - } - void printOriginalExpression() const { - if (result.hasExpression()) { - Colour colourGuard(Colour::OriginalExpression); - stream << " "; - stream << result.getExpressionInMacro(); - stream << '\n'; - } - } - void printReconstructedExpression() const { - if (result.hasExpandedExpression()) { - stream << "with expansion:\n"; - Colour colourGuard(Colour::ReconstructedExpression); - stream << Column(result.getExpandedExpression()).indent(2) << '\n'; - } - } - void printMessage() const { - if (!messageLabel.empty()) - stream << messageLabel << ':' << '\n'; - for (auto const& msg : messages) { - // If this assertion is a warning ignore any INFO messages - if (printInfoMessages || msg.type != ResultWas::Info) - stream << Column(msg.message).indent(2) << '\n'; - } - } - void printSourceInfo() const { - Colour colourGuard(Colour::FileName); - stream << result.getSourceInfo() << ": "; - } - - std::ostream& stream; - AssertionStats const& stats; - AssertionResult const& result; - Colour::Code colour; - std::string passOrFail; - std::string messageLabel; - std::string message; - std::vector messages; - bool printInfoMessages; -}; - -std::size_t makeRatio(std::size_t number, std::size_t total) { - std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0; - return (ratio == 0 && number > 0) ? 1 : ratio; -} - -std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) { - if (i > j && i > k) - return i; - else if (j > k) - return j; - else - return k; -} - -struct ColumnInfo { - enum Justification { Left, Right }; - std::string name; - int width; - Justification justification; -}; -struct ColumnBreak {}; -struct RowBreak {}; - -class Duration { - enum class Unit { - Auto, - Nanoseconds, - Microseconds, - Milliseconds, - Seconds, - Minutes - }; - static const uint64_t s_nanosecondsInAMicrosecond = 1000; - static const uint64_t s_nanosecondsInAMillisecond = 1000 * s_nanosecondsInAMicrosecond; - static const uint64_t s_nanosecondsInASecond = 1000 * s_nanosecondsInAMillisecond; - static const uint64_t s_nanosecondsInAMinute = 60 * s_nanosecondsInASecond; - - uint64_t m_inNanoseconds; - Unit m_units; - -public: - explicit Duration(uint64_t inNanoseconds, Unit units = Unit::Auto) - : m_inNanoseconds(inNanoseconds), - m_units(units) { - if (m_units == Unit::Auto) { - if (m_inNanoseconds < s_nanosecondsInAMicrosecond) - m_units = Unit::Nanoseconds; - else if (m_inNanoseconds < s_nanosecondsInAMillisecond) - m_units = Unit::Microseconds; - else if (m_inNanoseconds < s_nanosecondsInASecond) - m_units = Unit::Milliseconds; - else if (m_inNanoseconds < s_nanosecondsInAMinute) - m_units = Unit::Seconds; - else - m_units = Unit::Minutes; - } - - } - - auto value() const -> double { - switch (m_units) { - case Unit::Microseconds: - return m_inNanoseconds / static_cast(s_nanosecondsInAMicrosecond); - case Unit::Milliseconds: - return m_inNanoseconds / static_cast(s_nanosecondsInAMillisecond); - case Unit::Seconds: - return m_inNanoseconds / static_cast(s_nanosecondsInASecond); - case Unit::Minutes: - return m_inNanoseconds / static_cast(s_nanosecondsInAMinute); - default: - return static_cast(m_inNanoseconds); - } - } - auto unitsAsString() const -> std::string { - switch (m_units) { - case Unit::Nanoseconds: - return "ns"; - case Unit::Microseconds: - return "µs"; - case Unit::Milliseconds: - return "ms"; - case Unit::Seconds: - return "s"; - case Unit::Minutes: - return "m"; - default: - return "** internal error **"; - } - - } - friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& { - return os << duration.value() << " " << duration.unitsAsString(); - } -}; -} // end anon namespace - -class TablePrinter { - std::ostream& m_os; - std::vector m_columnInfos; - std::ostringstream m_oss; - int m_currentColumn = -1; - bool m_isOpen = false; - -public: - TablePrinter( std::ostream& os, std::vector columnInfos ) - : m_os( os ), - m_columnInfos( std::move( columnInfos ) ) {} - - auto columnInfos() const -> std::vector const& { - return m_columnInfos; - } - - void open() { - if (!m_isOpen) { - m_isOpen = true; - *this << RowBreak(); - for (auto const& info : m_columnInfos) - *this << info.name << ColumnBreak(); - *this << RowBreak(); - m_os << Catch::getLineOfChars<'-'>() << "\n"; - } - } - void close() { - if (m_isOpen) { - *this << RowBreak(); - m_os << std::endl; - m_isOpen = false; - } - } - - template - friend TablePrinter& operator << (TablePrinter& tp, T const& value) { - tp.m_oss << value; - return tp; - } - - friend TablePrinter& operator << (TablePrinter& tp, ColumnBreak) { - auto colStr = tp.m_oss.str(); - // This takes account of utf8 encodings - auto strSize = Catch::StringRef(colStr).numberOfCharacters(); - tp.m_oss.str(""); - tp.open(); - if (tp.m_currentColumn == static_cast(tp.m_columnInfos.size() - 1)) { - tp.m_currentColumn = -1; - tp.m_os << "\n"; - } - tp.m_currentColumn++; - - auto colInfo = tp.m_columnInfos[tp.m_currentColumn]; - auto padding = (strSize + 2 < static_cast(colInfo.width)) - ? std::string(colInfo.width - (strSize + 2), ' ') - : std::string(); - if (colInfo.justification == ColumnInfo::Left) - tp.m_os << colStr << padding << " "; - else - tp.m_os << padding << colStr << " "; - return tp; - } - - friend TablePrinter& operator << (TablePrinter& tp, RowBreak) { - if (tp.m_currentColumn > 0) { - tp.m_os << "\n"; - tp.m_currentColumn = -1; - } - return tp; - } -}; - -ConsoleReporter::ConsoleReporter(ReporterConfig const& config) - : StreamingReporterBase(config), - m_tablePrinter(new TablePrinter(config.stream(), - { - { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 32, ColumnInfo::Left }, - { "iters", 8, ColumnInfo::Right }, - { "elapsed ns", 14, ColumnInfo::Right }, - { "average", 14, ColumnInfo::Right } - })) {} -ConsoleReporter::~ConsoleReporter() = default; - -std::string ConsoleReporter::getDescription() { - return "Reports test results as plain lines of text"; -} - -void ConsoleReporter::noMatchingTestCases(std::string const& spec) { - stream << "No test cases matched '" << spec << '\'' << std::endl; -} - -void ConsoleReporter::assertionStarting(AssertionInfo const&) {} - -bool ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) { - AssertionResult const& result = _assertionStats.assertionResult; - - bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); - - // Drop out if result was successful but we're not printing them. - if (!includeResults && result.getResultType() != ResultWas::Warning) - return false; - - lazyPrint(); - - ConsoleAssertionPrinter printer(stream, _assertionStats, includeResults); - printer.print(); - stream << std::endl; - return true; -} - -void ConsoleReporter::sectionStarting(SectionInfo const& _sectionInfo) { - m_headerPrinted = false; - StreamingReporterBase::sectionStarting(_sectionInfo); -} -void ConsoleReporter::sectionEnded(SectionStats const& _sectionStats) { - m_tablePrinter->close(); - if (_sectionStats.missingAssertions) { - lazyPrint(); - Colour colour(Colour::ResultError); - if (m_sectionStack.size() > 1) - stream << "\nNo assertions in section"; - else - stream << "\nNo assertions in test case"; - stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl; - } - if (m_config->showDurations() == ShowDurations::Always) { - stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; - } - if (m_headerPrinted) { - m_headerPrinted = false; - } - StreamingReporterBase::sectionEnded(_sectionStats); -} - -void ConsoleReporter::benchmarkStarting(BenchmarkInfo const& info) { - lazyPrintWithoutClosingBenchmarkTable(); - - auto nameCol = Column( info.name ).width( static_cast( m_tablePrinter->columnInfos()[0].width - 2 ) ); - - bool firstLine = true; - for (auto line : nameCol) { - if (!firstLine) - (*m_tablePrinter) << ColumnBreak() << ColumnBreak() << ColumnBreak(); - else - firstLine = false; - - (*m_tablePrinter) << line << ColumnBreak(); - } -} -void ConsoleReporter::benchmarkEnded(BenchmarkStats const& stats) { - Duration average(stats.elapsedTimeInNanoseconds / stats.iterations); - (*m_tablePrinter) - << stats.iterations << ColumnBreak() - << stats.elapsedTimeInNanoseconds << ColumnBreak() - << average << ColumnBreak(); -} - -void ConsoleReporter::testCaseEnded(TestCaseStats const& _testCaseStats) { - m_tablePrinter->close(); - StreamingReporterBase::testCaseEnded(_testCaseStats); - m_headerPrinted = false; -} -void ConsoleReporter::testGroupEnded(TestGroupStats const& _testGroupStats) { - if (currentGroupInfo.used) { - printSummaryDivider(); - stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; - printTotals(_testGroupStats.totals); - stream << '\n' << std::endl; - } - StreamingReporterBase::testGroupEnded(_testGroupStats); -} -void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) { - printTotalsDivider(_testRunStats.totals); - printTotals(_testRunStats.totals); - stream << std::endl; - StreamingReporterBase::testRunEnded(_testRunStats); -} - -void ConsoleReporter::lazyPrint() { - - m_tablePrinter->close(); - lazyPrintWithoutClosingBenchmarkTable(); -} - -void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() { - - if (!currentTestRunInfo.used) - lazyPrintRunInfo(); - if (!currentGroupInfo.used) - lazyPrintGroupInfo(); - - if (!m_headerPrinted) { - printTestCaseAndSectionHeader(); - m_headerPrinted = true; - } -} -void ConsoleReporter::lazyPrintRunInfo() { - stream << '\n' << getLineOfChars<'~'>() << '\n'; - Colour colour(Colour::SecondaryText); - stream << currentTestRunInfo->name - << " is a Catch v" << libraryVersion() << " host application.\n" - << "Run with -? for options\n\n"; - - if (m_config->rngSeed() != 0) - stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n"; - - currentTestRunInfo.used = true; -} -void ConsoleReporter::lazyPrintGroupInfo() { - if (!currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1) { - printClosedHeader("Group: " + currentGroupInfo->name); - currentGroupInfo.used = true; - } -} -void ConsoleReporter::printTestCaseAndSectionHeader() { - assert(!m_sectionStack.empty()); - printOpenHeader(currentTestCaseInfo->name); - - if (m_sectionStack.size() > 1) { - Colour colourGuard(Colour::Headers); - - auto - it = m_sectionStack.begin() + 1, // Skip first section (test case) - itEnd = m_sectionStack.end(); - for (; it != itEnd; ++it) - printHeaderString(it->name, 2); - } - - SourceLineInfo lineInfo = m_sectionStack.back().lineInfo; - - if (!lineInfo.empty()) { - stream << getLineOfChars<'-'>() << '\n'; - Colour colourGuard(Colour::FileName); - stream << lineInfo << '\n'; - } - stream << getLineOfChars<'.'>() << '\n' << std::endl; -} - -void ConsoleReporter::printClosedHeader(std::string const& _name) { - printOpenHeader(_name); - stream << getLineOfChars<'.'>() << '\n'; -} -void ConsoleReporter::printOpenHeader(std::string const& _name) { - stream << getLineOfChars<'-'>() << '\n'; - { - Colour colourGuard(Colour::Headers); - printHeaderString(_name); - } -} - -// if string has a : in first line will set indent to follow it on -// subsequent lines -void ConsoleReporter::printHeaderString(std::string const& _string, std::size_t indent) { - std::size_t i = _string.find(": "); - if (i != std::string::npos) - i += 2; - else - i = 0; - stream << Column(_string).indent(indent + i).initialIndent(indent) << '\n'; -} - -struct SummaryColumn { - - SummaryColumn( std::string _label, Colour::Code _colour ) - : label( std::move( _label ) ), - colour( _colour ) {} - SummaryColumn addRow( std::size_t count ) { - ReusableStringStream rss; - rss << count; - std::string row = rss.str(); - for (auto& oldRow : rows) { - while (oldRow.size() < row.size()) - oldRow = ' ' + oldRow; - while (oldRow.size() > row.size()) - row = ' ' + row; - } - rows.push_back(row); - return *this; - } - - std::string label; - Colour::Code colour; - std::vector rows; - -}; - -void ConsoleReporter::printTotals( Totals const& totals ) { - if (totals.testCases.total() == 0) { - stream << Colour(Colour::Warning) << "No tests ran\n"; - } else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) { - stream << Colour(Colour::ResultSuccess) << "All tests passed"; - stream << " (" - << pluralise(totals.assertions.passed, "assertion") << " in " - << pluralise(totals.testCases.passed, "test case") << ')' - << '\n'; - } else { - - std::vector columns; - columns.push_back(SummaryColumn("", Colour::None) - .addRow(totals.testCases.total()) - .addRow(totals.assertions.total())); - columns.push_back(SummaryColumn("passed", Colour::Success) - .addRow(totals.testCases.passed) - .addRow(totals.assertions.passed)); - columns.push_back(SummaryColumn("failed", Colour::ResultError) - .addRow(totals.testCases.failed) - .addRow(totals.assertions.failed)); - columns.push_back(SummaryColumn("failed as expected", Colour::ResultExpectedFailure) - .addRow(totals.testCases.failedButOk) - .addRow(totals.assertions.failedButOk)); - - printSummaryRow("test cases", columns, 0); - printSummaryRow("assertions", columns, 1); - } -} -void ConsoleReporter::printSummaryRow(std::string const& label, std::vector const& cols, std::size_t row) { - for (auto col : cols) { - std::string value = col.rows[row]; - if (col.label.empty()) { - stream << label << ": "; - if (value != "0") - stream << value; - else - stream << Colour(Colour::Warning) << "- none -"; - } else if (value != "0") { - stream << Colour(Colour::LightGrey) << " | "; - stream << Colour(col.colour) - << value << ' ' << col.label; - } - } - stream << '\n'; -} - -void ConsoleReporter::printTotalsDivider(Totals const& totals) { - if (totals.testCases.total() > 0) { - std::size_t failedRatio = makeRatio(totals.testCases.failed, totals.testCases.total()); - std::size_t failedButOkRatio = makeRatio(totals.testCases.failedButOk, totals.testCases.total()); - std::size_t passedRatio = makeRatio(totals.testCases.passed, totals.testCases.total()); - while (failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH - 1) - findMax(failedRatio, failedButOkRatio, passedRatio)++; - while (failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH - 1) - findMax(failedRatio, failedButOkRatio, passedRatio)--; - - stream << Colour(Colour::Error) << std::string(failedRatio, '='); - stream << Colour(Colour::ResultExpectedFailure) << std::string(failedButOkRatio, '='); - if (totals.testCases.allPassed()) - stream << Colour(Colour::ResultSuccess) << std::string(passedRatio, '='); - else - stream << Colour(Colour::Success) << std::string(passedRatio, '='); - } else { - stream << Colour(Colour::Warning) << std::string(CATCH_CONFIG_CONSOLE_WIDTH - 1, '='); - } - stream << '\n'; -} -void ConsoleReporter::printSummaryDivider() { - stream << getLineOfChars<'-'>() << '\n'; -} - -CATCH_REGISTER_REPORTER("console", ConsoleReporter) - -} // end namespace Catch - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif -// end catch_reporter_console.cpp -// start catch_reporter_junit.cpp - -#include -#include -#include -#include - -namespace Catch { - - namespace { - std::string getCurrentTimestamp() { - // Beware, this is not reentrant because of backward compatibility issues - // Also, UTC only, again because of backward compatibility (%z is C++11) - time_t rawtime; - std::time(&rawtime); - auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); - -#ifdef _MSC_VER - std::tm timeInfo = {}; - gmtime_s(&timeInfo, &rawtime); -#else - std::tm* timeInfo; - timeInfo = std::gmtime(&rawtime); -#endif - - char timeStamp[timeStampSize]; - const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; - -#ifdef _MSC_VER - std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); -#else - std::strftime(timeStamp, timeStampSize, fmt, timeInfo); -#endif - return std::string(timeStamp); - } - - std::string fileNameTag(const std::vector &tags) { - auto it = std::find_if(begin(tags), - end(tags), - [] (std::string const& tag) {return tag.front() == '#'; }); - if (it != tags.end()) - return it->substr(1); - return std::string(); - } - } // anonymous namespace - - JunitReporter::JunitReporter( ReporterConfig const& _config ) - : CumulativeReporterBase( _config ), - xml( _config.stream() ) - { - m_reporterPrefs.shouldRedirectStdOut = true; - } - - JunitReporter::~JunitReporter() {} - - std::string JunitReporter::getDescription() { - return "Reports test results in an XML format that looks like Ant's junitreport target"; - } - - void JunitReporter::noMatchingTestCases( std::string const& /*spec*/ ) {} - - void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) { - CumulativeReporterBase::testRunStarting( runInfo ); - xml.startElement( "testsuites" ); - } - - void JunitReporter::testGroupStarting( GroupInfo const& groupInfo ) { - suiteTimer.start(); - stdOutForSuite.clear(); - stdErrForSuite.clear(); - unexpectedExceptions = 0; - CumulativeReporterBase::testGroupStarting( groupInfo ); - } - - void JunitReporter::testCaseStarting( TestCaseInfo const& testCaseInfo ) { - m_okToFail = testCaseInfo.okToFail(); - } - - bool JunitReporter::assertionEnded( AssertionStats const& assertionStats ) { - if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail ) - unexpectedExceptions++; - return CumulativeReporterBase::assertionEnded( assertionStats ); - } - - void JunitReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { - stdOutForSuite += testCaseStats.stdOut; - stdErrForSuite += testCaseStats.stdErr; - CumulativeReporterBase::testCaseEnded( testCaseStats ); - } - - void JunitReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { - double suiteTime = suiteTimer.getElapsedSeconds(); - CumulativeReporterBase::testGroupEnded( testGroupStats ); - writeGroup( *m_testGroups.back(), suiteTime ); - } - - void JunitReporter::testRunEndedCumulative() { - xml.endElement(); - } - - void JunitReporter::writeGroup( TestGroupNode const& groupNode, double suiteTime ) { - XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); - TestGroupStats const& stats = groupNode.value; - xml.writeAttribute( "name", stats.groupInfo.name ); - xml.writeAttribute( "errors", unexpectedExceptions ); - xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions ); - xml.writeAttribute( "tests", stats.totals.assertions.total() ); - xml.writeAttribute( "hostname", "tbd" ); // !TBD - if( m_config->showDurations() == ShowDurations::Never ) - xml.writeAttribute( "time", "" ); - else - xml.writeAttribute( "time", suiteTime ); - xml.writeAttribute( "timestamp", getCurrentTimestamp() ); - - // Write test cases - for( auto const& child : groupNode.children ) - writeTestCase( *child ); - - xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite ), false ); - xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite ), false ); - } - - void JunitReporter::writeTestCase( TestCaseNode const& testCaseNode ) { - TestCaseStats const& stats = testCaseNode.value; - - // All test cases have exactly one section - which represents the - // test case itself. That section may have 0-n nested sections - assert( testCaseNode.children.size() == 1 ); - SectionNode const& rootSection = *testCaseNode.children.front(); - - std::string className = stats.testInfo.className; - - if( className.empty() ) { - className = fileNameTag(stats.testInfo.tags); - if ( className.empty() ) - className = "global"; - } - - if ( !m_config->name().empty() ) - className = m_config->name() + "." + className; - - writeSection( className, "", rootSection ); - } - - void JunitReporter::writeSection( std::string const& className, - std::string const& rootName, - SectionNode const& sectionNode ) { - std::string name = trim( sectionNode.stats.sectionInfo.name ); - if( !rootName.empty() ) - name = rootName + '/' + name; - - if( !sectionNode.assertions.empty() || - !sectionNode.stdOut.empty() || - !sectionNode.stdErr.empty() ) { - XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); - if( className.empty() ) { - xml.writeAttribute( "classname", name ); - xml.writeAttribute( "name", "root" ); - } - else { - xml.writeAttribute( "classname", className ); - xml.writeAttribute( "name", name ); - } - xml.writeAttribute( "time", ::Catch::Detail::stringify( sectionNode.stats.durationInSeconds ) ); - - writeAssertions( sectionNode ); - - if( !sectionNode.stdOut.empty() ) - xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); - if( !sectionNode.stdErr.empty() ) - xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); - } - for( auto const& childNode : sectionNode.childSections ) - if( className.empty() ) - writeSection( name, "", *childNode ); - else - writeSection( className, name, *childNode ); - } - - void JunitReporter::writeAssertions( SectionNode const& sectionNode ) { - for( auto const& assertion : sectionNode.assertions ) - writeAssertion( assertion ); - } - - void JunitReporter::writeAssertion( AssertionStats const& stats ) { - AssertionResult const& result = stats.assertionResult; - if( !result.isOk() ) { - std::string elementName; - switch( result.getResultType() ) { - case ResultWas::ThrewException: - case ResultWas::FatalErrorCondition: - elementName = "error"; - break; - case ResultWas::ExplicitFailure: - elementName = "failure"; - break; - case ResultWas::ExpressionFailed: - elementName = "failure"; - break; - case ResultWas::DidntThrowException: - elementName = "failure"; - break; - - // We should never see these here: - case ResultWas::Info: - case ResultWas::Warning: - case ResultWas::Ok: - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - elementName = "internalError"; - break; - } - - XmlWriter::ScopedElement e = xml.scopedElement( elementName ); - - xml.writeAttribute( "message", result.getExpandedExpression() ); - xml.writeAttribute( "type", result.getTestMacroName() ); - - ReusableStringStream rss; - if( !result.getMessage().empty() ) - rss << result.getMessage() << '\n'; - for( auto const& msg : stats.infoMessages ) - if( msg.type == ResultWas::Info ) - rss << msg.message << '\n'; - - rss << "at " << result.getSourceInfo(); - xml.writeText( rss.str(), false ); - } - } - - CATCH_REGISTER_REPORTER( "junit", JunitReporter ) - -} // end namespace Catch -// end catch_reporter_junit.cpp -// start catch_reporter_multi.cpp - -namespace Catch { - - void MultipleReporters::add( IStreamingReporterPtr&& reporter ) { - m_reporters.push_back( std::move( reporter ) ); - } - - ReporterPreferences MultipleReporters::getPreferences() const { - return m_reporters[0]->getPreferences(); - } - - std::set MultipleReporters::getSupportedVerbosities() { - return std::set{ }; - } - - void MultipleReporters::noMatchingTestCases( std::string const& spec ) { - for( auto const& reporter : m_reporters ) - reporter->noMatchingTestCases( spec ); - } - - void MultipleReporters::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) { - for( auto const& reporter : m_reporters ) - reporter->benchmarkStarting( benchmarkInfo ); - } - void MultipleReporters::benchmarkEnded( BenchmarkStats const& benchmarkStats ) { - for( auto const& reporter : m_reporters ) - reporter->benchmarkEnded( benchmarkStats ); - } - - void MultipleReporters::testRunStarting( TestRunInfo const& testRunInfo ) { - for( auto const& reporter : m_reporters ) - reporter->testRunStarting( testRunInfo ); - } - - void MultipleReporters::testGroupStarting( GroupInfo const& groupInfo ) { - for( auto const& reporter : m_reporters ) - reporter->testGroupStarting( groupInfo ); - } - - void MultipleReporters::testCaseStarting( TestCaseInfo const& testInfo ) { - for( auto const& reporter : m_reporters ) - reporter->testCaseStarting( testInfo ); - } - - void MultipleReporters::sectionStarting( SectionInfo const& sectionInfo ) { - for( auto const& reporter : m_reporters ) - reporter->sectionStarting( sectionInfo ); - } - - void MultipleReporters::assertionStarting( AssertionInfo const& assertionInfo ) { - for( auto const& reporter : m_reporters ) - reporter->assertionStarting( assertionInfo ); - } - - // The return value indicates if the messages buffer should be cleared: - bool MultipleReporters::assertionEnded( AssertionStats const& assertionStats ) { - bool clearBuffer = false; - for( auto const& reporter : m_reporters ) - clearBuffer |= reporter->assertionEnded( assertionStats ); - return clearBuffer; - } - - void MultipleReporters::sectionEnded( SectionStats const& sectionStats ) { - for( auto const& reporter : m_reporters ) - reporter->sectionEnded( sectionStats ); - } - - void MultipleReporters::testCaseEnded( TestCaseStats const& testCaseStats ) { - for( auto const& reporter : m_reporters ) - reporter->testCaseEnded( testCaseStats ); - } - - void MultipleReporters::testGroupEnded( TestGroupStats const& testGroupStats ) { - for( auto const& reporter : m_reporters ) - reporter->testGroupEnded( testGroupStats ); - } - - void MultipleReporters::testRunEnded( TestRunStats const& testRunStats ) { - for( auto const& reporter : m_reporters ) - reporter->testRunEnded( testRunStats ); - } - - void MultipleReporters::skipTest( TestCaseInfo const& testInfo ) { - for( auto const& reporter : m_reporters ) - reporter->skipTest( testInfo ); - } - - bool MultipleReporters::isMulti() const { - return true; - } - -} // end namespace Catch -// end catch_reporter_multi.cpp -// start catch_reporter_xml.cpp - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch - // Note that 4062 (not all labels are handled - // and default is missing) is enabled -#endif - -namespace Catch { - XmlReporter::XmlReporter( ReporterConfig const& _config ) - : StreamingReporterBase( _config ), - m_xml(_config.stream()) - { - m_reporterPrefs.shouldRedirectStdOut = true; - } - - XmlReporter::~XmlReporter() = default; - - std::string XmlReporter::getDescription() { - return "Reports test results as an XML document"; - } - - std::string XmlReporter::getStylesheetRef() const { - return std::string(); - } - - void XmlReporter::writeSourceInfo( SourceLineInfo const& sourceInfo ) { - m_xml - .writeAttribute( "filename", sourceInfo.file ) - .writeAttribute( "line", sourceInfo.line ); - } - - void XmlReporter::noMatchingTestCases( std::string const& s ) { - StreamingReporterBase::noMatchingTestCases( s ); - } - - void XmlReporter::testRunStarting( TestRunInfo const& testInfo ) { - StreamingReporterBase::testRunStarting( testInfo ); - std::string stylesheetRef = getStylesheetRef(); - if( !stylesheetRef.empty() ) - m_xml.writeStylesheetRef( stylesheetRef ); - m_xml.startElement( "Catch" ); - if( !m_config->name().empty() ) - m_xml.writeAttribute( "name", m_config->name() ); - } - - void XmlReporter::testGroupStarting( GroupInfo const& groupInfo ) { - StreamingReporterBase::testGroupStarting( groupInfo ); - m_xml.startElement( "Group" ) - .writeAttribute( "name", groupInfo.name ); - } - - void XmlReporter::testCaseStarting( TestCaseInfo const& testInfo ) { - StreamingReporterBase::testCaseStarting(testInfo); - m_xml.startElement( "TestCase" ) - .writeAttribute( "name", trim( testInfo.name ) ) - .writeAttribute( "description", testInfo.description ) - .writeAttribute( "tags", testInfo.tagsAsString() ); - - writeSourceInfo( testInfo.lineInfo ); - - if ( m_config->showDurations() == ShowDurations::Always ) - m_testCaseTimer.start(); - m_xml.ensureTagClosed(); - } - - void XmlReporter::sectionStarting( SectionInfo const& sectionInfo ) { - StreamingReporterBase::sectionStarting( sectionInfo ); - if( m_sectionDepth++ > 0 ) { - m_xml.startElement( "Section" ) - .writeAttribute( "name", trim( sectionInfo.name ) ) - .writeAttribute( "description", sectionInfo.description ); - writeSourceInfo( sectionInfo.lineInfo ); - m_xml.ensureTagClosed(); - } - } - - void XmlReporter::assertionStarting( AssertionInfo const& ) { } - - bool XmlReporter::assertionEnded( AssertionStats const& assertionStats ) { - - AssertionResult const& result = assertionStats.assertionResult; - - bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); - - if( includeResults || result.getResultType() == ResultWas::Warning ) { - // Print any info messages in tags. - for( auto const& msg : assertionStats.infoMessages ) { - if( msg.type == ResultWas::Info && includeResults ) { - m_xml.scopedElement( "Info" ) - .writeText( msg.message ); - } else if ( msg.type == ResultWas::Warning ) { - m_xml.scopedElement( "Warning" ) - .writeText( msg.message ); - } - } - } - - // Drop out if result was successful but we're not printing them. - if( !includeResults && result.getResultType() != ResultWas::Warning ) - return true; - - // Print the expression if there is one. - if( result.hasExpression() ) { - m_xml.startElement( "Expression" ) - .writeAttribute( "success", result.succeeded() ) - .writeAttribute( "type", result.getTestMacroName() ); - - writeSourceInfo( result.getSourceInfo() ); - - m_xml.scopedElement( "Original" ) - .writeText( result.getExpression() ); - m_xml.scopedElement( "Expanded" ) - .writeText( result.getExpandedExpression() ); - } - - // And... Print a result applicable to each result type. - switch( result.getResultType() ) { - case ResultWas::ThrewException: - m_xml.startElement( "Exception" ); - writeSourceInfo( result.getSourceInfo() ); - m_xml.writeText( result.getMessage() ); - m_xml.endElement(); - break; - case ResultWas::FatalErrorCondition: - m_xml.startElement( "FatalErrorCondition" ); - writeSourceInfo( result.getSourceInfo() ); - m_xml.writeText( result.getMessage() ); - m_xml.endElement(); - break; - case ResultWas::Info: - m_xml.scopedElement( "Info" ) - .writeText( result.getMessage() ); - break; - case ResultWas::Warning: - // Warning will already have been written - break; - case ResultWas::ExplicitFailure: - m_xml.startElement( "Failure" ); - writeSourceInfo( result.getSourceInfo() ); - m_xml.writeText( result.getMessage() ); - m_xml.endElement(); - break; - default: - break; - } - - if( result.hasExpression() ) - m_xml.endElement(); - - return true; - } - - void XmlReporter::sectionEnded( SectionStats const& sectionStats ) { - StreamingReporterBase::sectionEnded( sectionStats ); - if( --m_sectionDepth > 0 ) { - XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); - e.writeAttribute( "successes", sectionStats.assertions.passed ); - e.writeAttribute( "failures", sectionStats.assertions.failed ); - e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); - - if ( m_config->showDurations() == ShowDurations::Always ) - e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); - - m_xml.endElement(); - } - } - - void XmlReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { - StreamingReporterBase::testCaseEnded( testCaseStats ); - XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); - e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() ); - - if ( m_config->showDurations() == ShowDurations::Always ) - e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); - - if( !testCaseStats.stdOut.empty() ) - m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false ); - if( !testCaseStats.stdErr.empty() ) - m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false ); - - m_xml.endElement(); - } - - void XmlReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { - StreamingReporterBase::testGroupEnded( testGroupStats ); - // TODO: Check testGroupStats.aborting and act accordingly. - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", testGroupStats.totals.assertions.passed ) - .writeAttribute( "failures", testGroupStats.totals.assertions.failed ) - .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); - m_xml.endElement(); - } - - void XmlReporter::testRunEnded( TestRunStats const& testRunStats ) { - StreamingReporterBase::testRunEnded( testRunStats ); - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", testRunStats.totals.assertions.passed ) - .writeAttribute( "failures", testRunStats.totals.assertions.failed ) - .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk ); - m_xml.endElement(); - } - - CATCH_REGISTER_REPORTER( "xml", XmlReporter ) - -} // end namespace Catch - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif -// end catch_reporter_xml.cpp - -namespace Catch { - LeakDetector leakDetector; -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// end catch_impl.hpp -#endif - -#ifdef CATCH_CONFIG_MAIN -// start catch_default_main.hpp - -#ifndef __OBJC__ - -#if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) -// Standard C/C++ Win32 Unicode wmain entry point -extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) { -#else -// Standard C/C++ main entry point -int main (int argc, char * argv[]) { -#endif - - return Catch::Session().run( argc, argv ); -} - -#else // __OBJC__ - -// Objective-C entry point -int main (int argc, char * const argv[]) { -#if !CATCH_ARC_ENABLED - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; -#endif - - Catch::registerTestMethods(); - int result = Catch::Session().run( argc, (char**)argv ); - -#if !CATCH_ARC_ENABLED - [pool drain]; -#endif - - return result; -} - -#endif // __OBJC__ - -// end catch_default_main.hpp -#endif - -#if !defined(CATCH_CONFIG_IMPL_ONLY) - -#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED -# undef CLARA_CONFIG_MAIN -#endif - -#if !defined(CATCH_CONFIG_DISABLE) -////// -// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ -#ifdef CATCH_CONFIG_PREFIX_ALL - -#define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) - -#define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", __VA_ARGS__ ) -#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) -#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) -#endif// CATCH_CONFIG_DISABLE_MATCHERS -#define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) - -#define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) -#define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) - -#define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", __VA_ARGS__ ) -#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) -#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) - -#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) -#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) -#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) - -#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) -#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) -#define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) -#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) -#define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - -#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() - -// "BDD-style" convenience wrappers -#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) -#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) -#define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc ) -#define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc ) -#define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc ) -#define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc ) -#define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc ) - -// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required -#else - -#define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) - -#define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) -#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) - -#define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) -#define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) - -#define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) -#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) - -#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) -#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) -#define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) - -#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) -#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) -#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) -#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) -#define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() - -#endif - -#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) - -// "BDD-style" convenience wrappers -#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) -#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) - -#define GIVEN( desc ) SECTION( std::string(" Given: ") + desc ) -#define WHEN( desc ) SECTION( std::string(" When: ") + desc ) -#define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc ) -#define THEN( desc ) SECTION( std::string(" Then: ") + desc ) -#define AND_THEN( desc ) SECTION( std::string(" And: ") + desc ) - -using Catch::Detail::Approx; - -#else -////// -// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ -#ifdef CATCH_CONFIG_PREFIX_ALL - -#define CATCH_REQUIRE( ... ) (void)(0) -#define CATCH_REQUIRE_FALSE( ... ) (void)(0) - -#define CATCH_REQUIRE_THROWS( ... ) (void)(0) -#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) -#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) -#endif// CATCH_CONFIG_DISABLE_MATCHERS -#define CATCH_REQUIRE_NOTHROW( ... ) (void)(0) - -#define CATCH_CHECK( ... ) (void)(0) -#define CATCH_CHECK_FALSE( ... ) (void)(0) -#define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__) -#define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) -#define CATCH_CHECK_NOFAIL( ... ) (void)(0) - -#define CATCH_CHECK_THROWS( ... ) (void)(0) -#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0) -#define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define CATCH_CHECK_NOTHROW( ... ) (void)(0) - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_CHECK_THAT( arg, matcher ) (void)(0) - -#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -#define CATCH_INFO( msg ) (void)(0) -#define CATCH_WARN( msg ) (void)(0) -#define CATCH_CAPTURE( msg ) (void)(0) - -#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define CATCH_METHOD_AS_TEST_CASE( method, ... ) -#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0) -#define CATCH_SECTION( ... ) -#define CATCH_FAIL( ... ) (void)(0) -#define CATCH_FAIL_CHECK( ... ) (void)(0) -#define CATCH_SUCCEED( ... ) (void)(0) - -#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) - -// "BDD-style" convenience wrappers -#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className ) -#define CATCH_GIVEN( desc ) -#define CATCH_WHEN( desc ) -#define CATCH_AND_WHEN( desc ) -#define CATCH_THEN( desc ) -#define CATCH_AND_THEN( desc ) - -// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required -#else - -#define REQUIRE( ... ) (void)(0) -#define REQUIRE_FALSE( ... ) (void)(0) - -#define REQUIRE_THROWS( ... ) (void)(0) -#define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) -#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define REQUIRE_NOTHROW( ... ) (void)(0) - -#define CHECK( ... ) (void)(0) -#define CHECK_FALSE( ... ) (void)(0) -#define CHECKED_IF( ... ) if (__VA_ARGS__) -#define CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) -#define CHECK_NOFAIL( ... ) (void)(0) - -#define CHECK_THROWS( ... ) (void)(0) -#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0) -#define CHECK_THROWS_WITH( expr, matcher ) (void)(0) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define CHECK_NOTHROW( ... ) (void)(0) - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CHECK_THAT( arg, matcher ) (void)(0) - -#define REQUIRE_THAT( arg, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -#define INFO( msg ) (void)(0) -#define WARN( msg ) (void)(0) -#define CAPTURE( msg ) (void)(0) - -#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define METHOD_AS_TEST_CASE( method, ... ) -#define REGISTER_TEST_CASE( Function, ... ) (void)(0) -#define SECTION( ... ) -#define FAIL( ... ) (void)(0) -#define FAIL_CHECK( ... ) (void)(0) -#define SUCCEED( ... ) (void)(0) -#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) - -#endif - -#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) - -// "BDD-style" convenience wrappers -#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) ) -#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className ) - -#define GIVEN( desc ) -#define WHEN( desc ) -#define AND_WHEN( desc ) -#define THEN( desc ) -#define AND_THEN( desc ) - -using Catch::Detail::Approx; - -#endif - -#endif // ! CATCH_CONFIG_IMPL_ONLY - -// start catch_reenable_warnings.h - - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(pop) -# else -# pragma clang diagnostic pop -# endif -#elif defined __GNUC__ -# pragma GCC diagnostic pop -#endif - -// end catch_reenable_warnings.h -// end catch.hpp -#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED - From dd993042b74782dca7712d56f007058a3969e285 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 22:04:44 -0500 Subject: [PATCH 289/305] Detect if running on Travis --- src/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e9e1fae1d..c7505067b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,12 @@ if(DEFINED ENV{SLIC3R_VAR_ABS_PATH}) set(CMAKE_CXX_FLAGS "-DVAR_ABS_PATH=$ENV{SLIC3R_VAR_ABS_PATH}") endif(DEFINED ENV{SLIC3R_VAR_ABS_PATH}) +if($ENV{TRAVIS}) + if($ENV{TRAVIS} STREQUAL "true") + message(STATUS "Building on Travis-CI.") + set(IS_TRAVIS_BUILD TRUE) + endif() +endif() execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_VERSION ERROR_QUIET) From 953317c602423ac70c5e8f0b9242ec7a4ba4baeb Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 22:06:19 -0500 Subject: [PATCH 290/305] Build and run tests. Also use correct location for catch header. --- .travis.yml | 1 + src/CMakeLists.txt | 42 +++++++++++++++++++++++++--- src/test/GUI/test_field_checkbox.cpp | 2 +- src/test/GUI/test_harness_gui.cpp | 2 +- src/test/test_harness.cpp | 2 ++ 5 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 src/test/test_harness.cpp diff --git a/.travis.yml b/.travis.yml index 7ed9a0680..cf218240d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ script: - mkdir build && cd build - cmake -DBOOST_ROOT=$BOOST_DIR -DSLIC3R_STATIC=ON ../src - cmake --build . + - ctest . branches: only: - master diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7505067b..fea83f0a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -172,7 +172,9 @@ set(UI_TEST_SOURCES ${GUI_TESTDIR}/test_harness_gui.cpp ${GUI_TESTDIR}/test_field_checkbox.cpp ) - +set(SLIC3R_TEST_SOURCES + ${TESTDIR}/test_harness.cpp +) add_executable(slic3r slic3r.cpp) #set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1) #set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1) @@ -276,9 +278,8 @@ IF(wxWidgets_FOUND) target_compile_definitions(Catch INTERFACE $<$:_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING>) endif() add_executable(gui_test ${UI_TEST_SOURCES}) - add_test(NAME TestBase COMMAND gui_test) + add_test(NAME TestGUI COMMAND gui_test) target_link_libraries(gui_test PUBLIC libslic3r slic3r_gui Catch ${wxWidgets_LIBRARIES}) - endif() ELSE(wxWidgets_FOUND) # For convenience. When we cannot continue, inform the user @@ -306,7 +307,40 @@ IF (WIN32) ENDIF(WIN32) - +if (SLIC3R_BUILD_TESTS) + enable_testing() + if (NOT TARGET Catch) + include (ExternalProject) + if(IS_TRAVIS_BUILD) # on travis, use git for fetching instead of wget + set(FETCH_EXTERNAL_CATCH + GIT_REPOSITORY https://github.com/philsquared/Catch.git + GIT_TAG 19ab2117c5bac2f376f8da4a4b25e183137bcec0) + elseif(WIN32) + set(FETCH_EXTERNAL_CATCH + URL https://github.com/catchorg/Catch2/archive/v2.0.1.zip + URL_HASH MD5=1abca1b324b99b1631e999119b172620) + else() + set(FETCH_EXTERNAL_CATCH + URL https://github.com/catchorg/Catch2/archive/v2.0.1.tar.gz + URL_HASH MD5=2080f4696579351d9323b3b5a8c3c71b) + endif() + ExternalProject_Add(Catch-External + PREFIX ${CMAKE_BINARY_DIR}/external/Catch + ${FETCH_EXTERNAL_CATCH} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/external/Catch/src/Catch-External/single_include/catch.hpp + ${CMAKE_BINARY_DIR}/external/Catch/include/catch.hpp + ) + add_library(Catch INTERFACE) + add_dependencies(Catch Catch-External) + target_include_directories(Catch INTERFACE ${CMAKE_BINARY_DIR}/external/Catch/include) + target_compile_definitions(Catch INTERFACE $<$:_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING>) + endif() + add_executable(slic3r_test ${SLIC3R_TEST_SOURCES}) + add_test(NAME TestSlic3r COMMAND slic3r_test) + target_link_libraries(slic3r_test PUBLIC libslic3r Catch) +endif() diff --git a/src/test/GUI/test_field_checkbox.cpp b/src/test/GUI/test_field_checkbox.cpp index 23f275068..5453ee270 100644 --- a/src/test/GUI/test_field_checkbox.cpp +++ b/src/test/GUI/test_field_checkbox.cpp @@ -1,4 +1,4 @@ -#include "test/catch.hpp" +#include #ifndef WX_PRECOMP #include "wx/app.h" diff --git a/src/test/GUI/test_harness_gui.cpp b/src/test/GUI/test_harness_gui.cpp index fe8666f2d..3c3c6f2f5 100644 --- a/src/test/GUI/test_harness_gui.cpp +++ b/src/test/GUI/test_harness_gui.cpp @@ -1,2 +1,2 @@ #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file -#include "test/catch.hpp" +#include diff --git a/src/test/test_harness.cpp b/src/test/test_harness.cpp new file mode 100644 index 000000000..3c3c6f2f5 --- /dev/null +++ b/src/test/test_harness.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#include From 306013bf30c3a4c73f9048b2dcc0d1973c5d6eab Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 22:19:53 -0500 Subject: [PATCH 291/305] start xvfb on osx? --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index cf218240d..61d3d8806 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: generic before_install: - sh package/linux/travis-decrypt-key + - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ( sudo Xvfb :99 -ac -screen 0 1024x768x8; echo ok )& fi + - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then sh -e /etc/init.d/xvfb start; fi script: - bash package/linux/travis-setup.sh - mkdir build && cd build @@ -46,6 +48,7 @@ matrix: - CC=gcc-7 - CXX=g++-7 - BOOST_DIR=$HOME/boost_1_63_0 + - DISPLAY=:99.0 after_success: - cp slic3r ../ - LD_LIBRARY_PATH=$WXDIR/lib package/linux/make_archive.sh linux-x64 @@ -57,6 +60,7 @@ matrix: env: - WXVERSION=pkg - BOOST_DIR=$HOME/boost_1_63_0 + - DISPLAY=:99.0 env: global: - secure: eEVRZNMv7FM6jrOU9iAFkDhWxFQ1WtHBEaObImcvtFUxy6vWSt3ehFFeTRouj3uHQAnbvUzziDyvPPm8/95alv5g/du8ML6YzzqKBKfazM0xQ7SF6R2DQL8lfFIp+RSV7T02byEP1f1g7Zva7xH9szIlDcSfU0pXW4KWbkBFMd8= From 1d4df82c92606412f20edc5e5ea5b5d4f6956102 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 23:03:00 -0500 Subject: [PATCH 292/305] spliced test harness wxApp class from wxWidgets tests --- src/test/GUI/test_harness_gui.cpp | 239 +++++++++++++++++++++++++++++- 1 file changed, 238 insertions(+), 1 deletion(-) diff --git a/src/test/GUI/test_harness_gui.cpp b/src/test/GUI/test_harness_gui.cpp index 3c3c6f2f5..3ff5ef555 100644 --- a/src/test/GUI/test_harness_gui.cpp +++ b/src/test/GUI/test_harness_gui.cpp @@ -1,2 +1,239 @@ -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#define CATCH_CONFIG_RUNNER #include +#include "wx/wx.h" + +#include "wx/apptrait.h" +#include "testableframe.h" + +#undef wxUSE_GUI +#define wxUSE_GUI 1 +#undef wxUSE_LOG +#define wxUSE_LOG 0 + +typedef int (*FilterEventFunc)(wxEvent&); +typedef bool (*ProcessEventFunc)(wxEvent&); + +typedef wxApp TestAppBase; +typedef wxGUIAppTraits TestAppTraitsBase; +using namespace std; + +// The application class +// +class TestApp : public TestAppBase +{ +public: + TestApp(); + + // standard overrides + virtual bool OnInit(); + virtual int OnExit(); + +#ifdef __WIN32__ + virtual wxAppTraits *CreateTraits() + { + // Define a new class just to customize CanUseStderr() behaviour. + class TestAppTraits : public TestAppTraitsBase + { + public: + // We want to always use stderr, tests are also run unattended and + // in this case we really don't want to show any message boxes, as + // wxMessageOutputBest, used e.g. from the default implementation + // of wxApp::OnUnhandledException(), would do by default. + virtual bool CanUseStderr() { return true; } + + // Overriding CanUseStderr() is not enough, we also need to + // override this one to avoid returning false from it. + virtual bool WriteToStderr(const wxString& text) + { + wxFputs(text, stderr); + fflush(stderr); + + // Intentionally ignore any errors, we really don't want to + // show any message boxes in any case. + return true; + } + }; + + return new TestAppTraits; + } +#endif // __WIN32__ + + // Also override this method to avoid showing any dialogs from here -- and + // show some details about the exception along the way. + virtual bool OnExceptionInMainLoop() + { + wxFprintf(stderr, "Unhandled exception in the main loop: %s\n", + Catch::translateActiveException()); + + throw; + } + + // used by events propagation test + virtual int FilterEvent(wxEvent& event); + virtual bool ProcessEvent(wxEvent& event); + + void SetFilterEventFunc(FilterEventFunc f) { m_filterEventFunc = f; } + void SetProcessEventFunc(ProcessEventFunc f) { m_processEventFunc = f; } + + // In console applications we run the tests directly from the overridden + // OnRun(), but in the GUI ones we run them when we get the first call to + // our EVT_IDLE handler to ensure that we do everything from inside the + // main event loop. This is especially important under wxOSX/Cocoa where + // the main event loop is different from the others but it's also safer to + // do it like this in the other ports as we test the GUI code in the same + // context as it's used usually, in normal programs, and it might behave + // differently without the event loop. +#if wxUSE_GUI + void OnIdle(wxIdleEvent& event) + { + if ( m_runTests ) + { + m_runTests = false; + +#ifdef __WXOSX__ + // we need to wait until the window is activated and fully ready + // otherwise no events can be posted + wxEventLoopBase* const loop = wxEventLoop::GetActive(); + if ( loop ) + { + loop->DispatchTimeout(1000); + loop->Yield(); + } +#endif // __WXOSX__ + + m_exitcode = RunTests(); + ExitMainLoop(); + } + + event.Skip(); + } + + virtual int OnRun() + { + if ( TestAppBase::OnRun() != 0 ) + m_exitcode = EXIT_FAILURE; + + return m_exitcode; + } +#else // !wxUSE_GUI + virtual int OnRun() + { + return RunTests(); + } +#endif // wxUSE_GUI/!wxUSE_GUI + +private: + int RunTests(); + + // flag telling us whether we should run tests from our EVT_IDLE handler + bool m_runTests; + + // event handling hooks + FilterEventFunc m_filterEventFunc; + ProcessEventFunc m_processEventFunc; + +#if wxUSE_GUI + // the program exit code + int m_exitcode; +#endif // wxUSE_GUI +}; + +wxIMPLEMENT_APP_NO_MAIN(TestApp); + +// ---------------------------------------------------------------------------- +// TestApp +// ---------------------------------------------------------------------------- + +TestApp::TestApp() +{ + m_runTests = true; + + m_filterEventFunc = NULL; + m_processEventFunc = NULL; + +#if wxUSE_GUI + m_exitcode = EXIT_SUCCESS; +#endif // wxUSE_GUI +} + +// Init +// +bool TestApp::OnInit() +{ + // Hack: don't call TestAppBase::OnInit() to let CATCH handle command line. + + // Output some important information about the test environment. +#if wxUSE_GUI + cout << "Test program for wxWidgets GUI features\n" +#else + cout << "Test program for wxWidgets non-GUI features\n" +#endif + << "build: " << WX_BUILD_OPTIONS_SIGNATURE << "\n" + << "running under " << wxGetOsDescription() + << " as " << wxGetUserId() + << ", locale is " << setlocale(LC_ALL, NULL) + << std::endl; + +#if wxUSE_GUI + // create a parent window to be used as parent for the GUI controls + new wxTestableFrame(); + + Connect(wxEVT_IDLE, wxIdleEventHandler(TestApp::OnIdle)); + +#ifdef GDK_WINDOWING_X11 + XSetErrorHandler(wxTestX11ErrorHandler); +#endif // GDK_WINDOWING_X11 + +#endif // wxUSE_GUI + + return true; +} + +// Event handling +int TestApp::FilterEvent(wxEvent& event) +{ + if ( m_filterEventFunc ) + return (*m_filterEventFunc)(event); + + return TestAppBase::FilterEvent(event); +} + +bool TestApp::ProcessEvent(wxEvent& event) +{ + if ( m_processEventFunc ) + return (*m_processEventFunc)(event); + + return TestAppBase::ProcessEvent(event); +} + +// Run +// +int TestApp::RunTests() +{ +#if wxUSE_LOG + // Switch off logging unless --verbose + bool verbose = wxLog::GetVerbose(); + wxLog::EnableLogging(verbose); +#else + bool verbose = false; +#endif + + // Cast is needed under MSW where Catch also provides an overload taking + // wchar_t, but as it simply converts arguments to char internally anyhow, + // we can just as well always use the char version. + return Catch::Session().run(argc, static_cast(argv)); +} + +int TestApp::OnExit() +{ +#if wxUSE_GUI + delete GetTopWindow(); +#endif // wxUSE_GUI + + return TestAppBase::OnExit(); +} + +int main(int argc, char **argv) +{ + return wxEntry(argc, argv); +} From cdb9d61aef3da588f6cd76c6b6951867a5f21c35 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 23:05:33 -0500 Subject: [PATCH 293/305] Added a test with a tiny bit of meaning (cribbed from wxWidgets tests). --- src/test/GUI/test_field_checkbox.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/GUI/test_field_checkbox.cpp b/src/test/GUI/test_field_checkbox.cpp index 5453ee270..3818bb9ba 100644 --- a/src/test/GUI/test_field_checkbox.cpp +++ b/src/test/GUI/test_field_checkbox.cpp @@ -7,5 +7,20 @@ #include "testableframe.h" -TEST_CASE( "Dummy" ) { +SCENARIO( "checkboxes return true when checked.", "[checkbox]" ) { + GIVEN( "A checkbox item") { + wxCheckBox* m_check = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, "Check box"); + WHEN ( "the box is checked") { + m_check->SetValue(true); + THEN ( "the checkbox reads true") { + REQUIRE(m_check->IsChecked() == true); + } + } + WHEN ( "the box is not checked") { + m_check->SetValue(false); + THEN ( "the checkbox reads false") { + REQUIRE(m_check->IsChecked() == false); + } + } + } } From aa85c50b4624b12d0f667351f319b37895456f6a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 23:15:07 -0500 Subject: [PATCH 294/305] add all of the library dependencies that Slic3r needs to the test as well. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fea83f0a6..aa0bf6cf8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -339,7 +339,7 @@ if (SLIC3R_BUILD_TESTS) endif() add_executable(slic3r_test ${SLIC3R_TEST_SOURCES}) add_test(NAME TestSlic3r COMMAND slic3r_test) - target_link_libraries(slic3r_test PUBLIC libslic3r Catch) + target_link_libraries(slic3r_test PUBLIC libslic3r Catch admesh BSpline clipper expat polypartition poly2tri ZipArchive ${Boost_LIBRARIES}) endif() From a8293029fb7f7d8123424d0fdfacadbe5394bd26 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 23:25:43 -0500 Subject: [PATCH 295/305] refactor libslic3r dependencies --- src/CMakeLists.txt | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aa0bf6cf8..d813327ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,8 @@ project (slic3r) option(GUI_BUILD_TESTS "Build tests for Slic3r GUI." ON) option(SLIC3R_BUILD_TESTS "Build tests for libslic3r." ON) +option(SLIC3R_STATIC "Build and link Slic3r statically." ON) +option(BUILD_EXTRUDE_TIN "Build and link the extrude-tin application." OFF) # only on newer GCCs: -ftemplate-backtrace-limit=0 set(CMAKE_CXX_FLAGS "-g ${CMAKE_CXX_FLAGS} -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") @@ -46,7 +48,6 @@ ELSE(CMAKE_HOST_APPLE) # set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -L.") ENDIF(CMAKE_HOST_APPLE) -option(SLIC3R_STATIC "Build and link Slic3r statically." ON) if(SLIC3R_STATIC) set(Boost_USE_STATIC_LIBS ON) @@ -138,6 +139,8 @@ add_library(libslic3r STATIC ) target_compile_features(libslic3r PUBLIC cxx_std_11) + + add_library(BSpline STATIC ${LIBDIR}/BSpline/BSpline.cpp ) @@ -167,6 +170,8 @@ add_library(poly2tri STATIC ${LIBDIR}/poly2tri/sweep/sweep.cc ) + + set(UI_TEST_SOURCES ${GUI_TESTDIR}/testableframe.cpp ${GUI_TESTDIR}/test_harness_gui.cpp @@ -179,9 +184,6 @@ add_executable(slic3r slic3r.cpp) #set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1) #set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1) -#add_executable(extrude-tin utils/extrude-tin.cpp) -#set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_START_STATIC 1) -#set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_END_STATIC 1) set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_STATIC_RUNTIME OFF) @@ -208,6 +210,18 @@ IF(CMAKE_HOST_UNIX) #set(Boost_LIBRARIES bsystem bthread bfilesystem) ENDIF(CMAKE_HOST_UNIX) +# Libraries that Libslic3r itself depends on. +set(LIBSLIC3R_DEPENDS + admesh + BSpline + clipper + expat + polypartition + poly2tri + ZipArchive + ${Boost_LIBRARIES} +) + IF(wxWidgets_FOUND) MESSAGE("wx found!") @@ -287,7 +301,13 @@ ELSE(wxWidgets_FOUND) #skip gui when no wx included ENDIF(wxWidgets_FOUND) -target_link_libraries (slic3r libslic3r admesh BSpline clipper expat polypartition poly2tri ZipArchive ${Boost_LIBRARIES}) +target_link_libraries (slic3r libslic3r ${LIBSLIC3R_DEPENDS}) + +if (BUILD_EXTRUDE_TIN) + add_executable(extrude-tin utils/extrude-tin.cpp) + set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_START_STATIC 1) + set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_END_STATIC 1) +endif() # Windows needs a compiled component for Boost.nowide IF (WIN32) @@ -302,8 +322,10 @@ IF (WIN32) # deal with it. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_EXE_LINKER_FLAGS "-Wl,--allow-multiple-definition") - endif() -# target_link_libraries(extrude-tin boost-nowide) + endif() + if (BUILD_EXTRUDE_TIN) + target_link_libraries(extrude-tin boost-nowide) + endif() ENDIF(WIN32) @@ -339,9 +361,9 @@ if (SLIC3R_BUILD_TESTS) endif() add_executable(slic3r_test ${SLIC3R_TEST_SOURCES}) add_test(NAME TestSlic3r COMMAND slic3r_test) - target_link_libraries(slic3r_test PUBLIC libslic3r Catch admesh BSpline clipper expat polypartition poly2tri ZipArchive ${Boost_LIBRARIES}) + target_link_libraries(slic3r_test PUBLIC libslic3r Catch ${LIBSLIC3R_DEPENDS}) endif() - - -#target_link_libraries (extrude-tin libslic3r admesh BSpline clipper expat polypartition poly2tri ${Boost_LIBRARIES}) +if (BUILD_EXTRUDE_TIN) + target_link_libraries (extrude-tin libslic3r ${LIBSLIC3R_DEPENDS}) +endif() From 0f01bd16f0bb042726ed108ba7442433b10ddd0c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 23:26:00 -0500 Subject: [PATCH 296/305] use xvfb-run instead of starting it by hand --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 61d3d8806..41dd46154 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,12 @@ language: generic before_install: - sh package/linux/travis-decrypt-key - - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ( sudo Xvfb :99 -ac -screen 0 1024x768x8; echo ok )& fi - - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then sh -e /etc/init.d/xvfb start; fi script: - bash package/linux/travis-setup.sh - mkdir build && cd build - cmake -DBOOST_ROOT=$BOOST_DIR -DSLIC3R_STATIC=ON ../src - cmake --build . - - ctest . + - xvfb-run ctest . branches: only: - master From b241731e8a2982b81e4e32cfc05c1e73b1a21109 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 23:41:27 -0500 Subject: [PATCH 297/305] Test GUI functions on osx travis until I figure out what is up with linux. Run TestSlic3r on both. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 41dd46154..415cb45d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,14 @@ language: generic before_install: - sh package/linux/travis-decrypt-key + - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ( sudo Xvfb :99 -ac -screen 0 1024x768x8; echo ok )& fi script: - bash package/linux/travis-setup.sh - mkdir build && cd build - cmake -DBOOST_ROOT=$BOOST_DIR -DSLIC3R_STATIC=ON ../src - cmake --build . - - xvfb-run ctest . + - ctest . -R TestSlic3r + - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ctest . -R TestGUI; fi branches: only: - master From 7ffa425d6534ab7844e99605441ed474fbe87cf6 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 21 Jun 2018 23:42:54 -0500 Subject: [PATCH 298/305] try one last time to run gui tests on travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 415cb45d4..93bf65b99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,13 @@ language: generic before_install: - sh package/linux/travis-decrypt-key - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ( sudo Xvfb :99 -ac -screen 0 1024x768x8; echo ok )& fi + - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then ( sudo Xvfb :99 -ac -screen 0 1024x768x8; echo ok )& fi script: - bash package/linux/travis-setup.sh - mkdir build && cd build - cmake -DBOOST_ROOT=$BOOST_DIR -DSLIC3R_STATIC=ON ../src - cmake --build . - - ctest . -R TestSlic3r + - ctest . - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ctest . -R TestGUI; fi branches: only: From e0aa6d2f858e23d5e06746fc9cfb2979e9e599d1 Mon Sep 17 00:00:00 2001 From: Benjamin Landers Date: Fri, 22 Jun 2018 02:40:40 -0700 Subject: [PATCH 299/305] Patch menu deletion issue --- src/GUI/Plater.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 301917f46..af7688394 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -500,7 +500,8 @@ void Plater::on_model_change(bool force_autocenter) { auto* menu = this->GetFrame()->plater_select_menu; if (menu != nullptr) { - for (auto* item : menu->GetMenuItems() ) { menu->Delete(item); } + auto list = menu->GetMenuItems(); + for (auto it = list.begin();it!=list.end(); it++) { menu->Delete(*it); } for (const auto& obj : this->objects) { const auto idx {obj.identifier}; auto name {wxString(obj.name)}; From f352d433bcebb812122a068d0202ac6ae3f34132 Mon Sep 17 00:00:00 2001 From: Benjamin Landers Date: Fri, 22 Jun 2018 03:00:07 -0700 Subject: [PATCH 300/305] Basic Plate3D implementation (selection not working) Additionally, OpenGL added to the cmakelist and xs/slic3r/GUI files fixed to be compiled. --- src/CMakeLists.txt | 6 +- src/GUI/Plater/Plate3D.cpp | 112 ++++++++ src/GUI/Plater/Plate3D.hpp | 19 +- src/GUI/Scene3D.cpp | 508 +++++++++++++++++++++++++++++++++++++ src/GUI/Scene3D.hpp | 55 ++++ 5 files changed, 694 insertions(+), 6 deletions(-) create mode 100644 src/GUI/Plater/Plate3D.cpp create mode 100644 src/GUI/Scene3D.cpp create mode 100644 src/GUI/Scene3D.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d813327ab..bdd272f3e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -249,11 +249,14 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/Plater.cpp + ${GUI_LIBDIR}/Scene3D.cpp ${GUI_LIBDIR}/Plater/Plate2D.cpp + ${GUI_LIBDIR}/Plater/Plate3D.cpp ${GUI_LIBDIR}/Plater/PlaterObject.cpp ${GUI_LIBDIR}/ProgressStatusBar.cpp ${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/misc_ui.cpp + ${LIBDIR}/slic3r/GUI/3DScene.cpp ) target_compile_features(slic3r_gui PUBLIC cxx_std_14) #only build GUI lib if building with wx @@ -301,7 +304,8 @@ ELSE(wxWidgets_FOUND) #skip gui when no wx included ENDIF(wxWidgets_FOUND) -target_link_libraries (slic3r libslic3r ${LIBSLIC3R_DEPENDS}) +find_package(OpenGL) +target_link_libraries (slic3r libslic3r ${LIBSLIC3R_DEPENDS} ${OPENGL_LIBRARIES}) if (BUILD_EXTRUDE_TIN) add_executable(extrude-tin utils/extrude-tin.cpp) diff --git a/src/GUI/Plater/Plate3D.cpp b/src/GUI/Plater/Plate3D.cpp new file mode 100644 index 000000000..592effb34 --- /dev/null +++ b/src/GUI/Plater/Plate3D.cpp @@ -0,0 +1,112 @@ +#include "Plater/Plate3D.hpp" +#include "misc_ui.hpp" + +namespace Slic3r { namespace GUI { + +Plate3D::Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : + Scene3D(parent, size), objects(_objects), model(_model), config(_config) +{ + + //this->glContext = new wxGLContext(this); + //this->Bind(wxEVT_PAINT, [this](wxPaintEvent& e) { this->repaint(e); }); + //delete this->glContext; + //this->glContext = new wxGLContext(this); // Update glContext (look for better way) + //}); + + // Bind the varying mouse events + this->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { this->mouse_down(e); }); + this->Bind(wxEVT_RIGHT_DOWN, [this](wxMouseEvent &e) { this->mouse_down(e); }); +} + +void Plate3D::mouse_down(wxMouseEvent &e){ + if(!hover){ + //select logic + } +} + + +void Plate3D::mouse_move(wxMouseEvent &e){ + if(!e.Dragging()){ + pos = Point(e.GetX(),e.GetY()); + mouse = true; + Refresh(); + } else { + Scene3D::mouse_move(e); + } +} + + +void Plate3D::update(){ + volumes.clear(); + for(const PlaterObject &object: objects){ + const auto &modelobj = model->objects.at(object.identifier); + for(ModelInstance *instance: modelobj->instances){ + for(ModelVolume* volume: modelobj->volumes){ + volumes.push_back(load_object(*volume,*instance)); + } + } + } + +} + +void Plate3D::color_volumes(){ + uint i = 0; + for(const PlaterObject &object: objects){ + const auto &modelobj = model->objects.at(object.identifier); + for(ModelInstance *instance: modelobj->instances){ + for(ModelVolume* volume: modelobj->volumes){ + auto& rendervolume = volumes.at(i); + if(object.selected){ + rendervolume.color = ui_settings->color->SELECTED_COLOR(); + }else{ + rendervolume.color = wxColor(255,255,0);//ui_settings->color->COLOR_PARTS(); <- invisible because alpha is 1 (out of 255) + } + } + } + } + if(hover){ + volumes.at(hover_volume).color = ui_settings->color->HOVER_COLOR(); + } +} + +void Plate3D::before_render(){ + if (!mouse)return; + + //glDisable(GL_MULTISAMPLE) if ($self->{can_multisample}); + glDisable(GL_LIGHTING); + uint i = 0; + for(Volume &volume : volumes){ + volume.color = wxColor((i>>16)&0xFF,(i>>8)&0xFF,i&0xFF); + i++; + } + draw_volumes(); + glFlush(); + glFinish(); + GLubyte color[4] = {0,0,0,0}; + glReadPixels(pos.x, /*offset*/GetSize().GetHeight()- pos.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, color); + + uint index = color[0] + (color[1]<<8) + (color[2]<<16); + hover = false; + ///*$self->_hover_volume_idx(undef); + //$_->hover(0) for @{$self->volumes}; + if (index < volumes.size()) { + hover = true; + hover_volume = index; + /* + $self->volumes->[$volume_idx]->hover(1); + my $group_id = $self->volumes->[$volume_idx]->select_group_id; + if ($group_id != -1) { + $_->hover(1) for grep { $_->select_group_id == $group_id } @{$self->volumes}; + }*/ + + //$self->on_hover->($volume_idx) if $self->on_hover; + } + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glFlush(); + glFinish(); + glEnable(GL_LIGHTING); + color_volumes(); + mouse = false; +} + +} } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Plate3D.hpp b/src/GUI/Plater/Plate3D.hpp index 8e6814d25..1c5954c87 100644 --- a/src/GUI/Plater/Plate3D.hpp +++ b/src/GUI/Plater/Plate3D.hpp @@ -4,18 +4,27 @@ #ifndef WX_PRECOMP #include #endif +#include "Plater/PlaterObject.hpp" +#include "Scene3D.hpp" +#include "Settings.hpp" #include "Model.hpp" #include "Config.hpp" namespace Slic3r { namespace GUI { -class Plate3D : public wxPanel { +class Plate3D : public Scene3D { public: - void update() {}; - Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) - {} + void update(); + Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config); +protected: + void before_render(); + void mouse_move(wxMouseEvent &e); + void mouse_down(wxMouseEvent &e); private: + void color_volumes(); + Point pos; + bool hover = false, mouse = false; + uint hover_volume; std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; diff --git a/src/GUI/Scene3D.cpp b/src/GUI/Scene3D.cpp new file mode 100644 index 000000000..e379eda27 --- /dev/null +++ b/src/GUI/Scene3D.cpp @@ -0,0 +1,508 @@ +#include "Scene3D.hpp" +#include "Line.hpp" +#include "ClipperUtils.hpp" +#include "misc_ui.hpp" + +#include + +namespace Slic3r { namespace GUI { + +Scene3D::Scene3D(wxWindow* parent, const wxSize& size) : + wxGLCanvas(parent, wxID_ANY, wxDefaultPosition, size) +{ + + this->glContext = new wxGLContext(this); + this->Bind(wxEVT_PAINT, [this](wxPaintEvent &e) { this->repaint(e); }); + this->Bind(wxEVT_SIZE, [this](wxSizeEvent &e ){ + dirty = true; + Refresh(); + }); + + + // Bind the varying mouse events + this->Bind(wxEVT_MOTION, [this](wxMouseEvent &e) { this->mouse_move(e); }); + this->Bind(wxEVT_LEFT_UP, [this](wxMouseEvent &e) { this->mouse_up(e); }); + this->Bind(wxEVT_RIGHT_UP, [this](wxMouseEvent &e) { this->mouse_up(e); }); + this->Bind(wxEVT_MIDDLE_DCLICK, [this](wxMouseEvent &e) { this->mouse_dclick(e); }); + this->Bind(wxEVT_MOUSEWHEEL, [this](wxMouseEvent &e) { this->mouse_wheel(e); }); +/* + if (user_drawn_background) { + this->Bind(wxEVT_ERASE_BACKGROUND, [this](wxEraseEvent& e){ }); + } + + this->Bind(wxEVT_CHAR, [this](wxKeyEvent &e) { this->nudge_key(e);}); + */ + Points p; + const coord_t w = scale_(200), z = 0; + p.push_back(Point(z,z)); + p.push_back(Point(z,w)); + p.push_back(Point(w,w)); + p.push_back(Point(w,z)); + set_bed_shape(p); +} + +float clamp(float low, float x, float high){ + if(x < low) return low; + if(x > high) return high; + return x; +} + +Linef3 mouse_ray(Point win){ + GLdouble proj[16], mview[16]; + glGetDoublev(GL_MODELVIEW_MATRIX, mview); + glGetDoublev(GL_PROJECTION_MATRIX, proj); + GLint view[4]; + glGetIntegerv(GL_VIEWPORT, view); + win.y = view[3]-win.y; + GLdouble x = 0.0, y = 0.0, z = 0.0; + gluUnProject(win.x,win.y,0,mview,proj,view,&x,&y,&z); + Pointf3 first = Pointf3(x,y,z); + GLint a = gluUnProject(win.x,win.y,1,mview,proj,view,&x,&y,&z); + return Linef3(first,Pointf3(x,y,z)); +} + +void Scene3D::mouse_move(wxMouseEvent &e){ + if(e.Dragging()){ + //const auto s = GetSize(); + const auto pos = Point(e.GetX(),e.GetY()); + if(dragging){ + if (e.ShiftDown()) { // TODO: confirm alt -> shift is ok + // Move the camera center on the Z axis based on mouse Y axis movement + _camera_target.translate(0, 0, (pos.y - drag_start.y)); + } else if (e.LeftIsDown()) { + // if dragging over blank area with left button, rotate + //if (TURNTABLE_MODE) { + const float TRACKBALLSIZE = 0.8f, GIMBAL_LOCK_THETA_MAX = 170.0f; + + phi += (pos.x - drag_start.x) * TRACKBALLSIZE; + theta -= (pos.y - drag_start.y) * TRACKBALLSIZE; + theta = clamp(0, theta, GIMBAL_LOCK_THETA_MAX); + /*} else { + my $size = $self->GetClientSize; + my @quat = trackball( + $orig->x / ($size->width / 2) - 1, + 1 - $orig->y / ($size->height / 2), #/ + $pos->x / ($size->width / 2) - 1, + 1 - $pos->y / ($size->height / 2), #/ + ); + $self->_quat(mulquats($self->_quat, \@quat)); + }*/ + } else if (e.MiddleIsDown() || e.RightIsDown()) { + // if dragging over blank area with right button, translate + // get point in model space at Z = 0 + const auto current = mouse_ray(pos).intersect_plane(0); + const auto old = mouse_ray(drag_start).intersect_plane(0); + _camera_target.translate(current.vector_to(old)); + } + //$self->on_viewport_changed->() if $self->on_viewport_changed; + Refresh(); + } + dragging = true; + drag_start = pos; + }else{ + e.Skip(); + } +} + +void Scene3D::mouse_up(wxMouseEvent &e){ + dragging = false; + Refresh(); +} + +void Scene3D::mouse_wheel(wxMouseEvent &e){ + // Calculate the zoom delta and apply it to the current zoom factor + auto _zoom = ((float)e.GetWheelRotation()) / e.GetWheelDelta(); + /*if ($Slic3r::GUI::Settings->{_}{invert_zoom}) { + _zoom *= -1; + }*/ + _zoom = clamp(-4, _zoom,4); + _zoom /= 10; + zoom /= 1-_zoom; + /* + # In order to zoom around the mouse point we need to translate + # the camera target + my $size = Slic3r::Pointf->new($self->GetSizeWH); + my $pos = Slic3r::Pointf->new($e->GetX, $size->y - $e->GetY); #- + $self->_camera_target->translate( + # ($pos - $size/2) represents the vector from the viewport center + # to the mouse point. By multiplying it by $zoom we get the new, + # transformed, length of such vector. + # Since we want that point to stay fixed, we move our camera target + # in the opposite direction by the delta of the length of such vector + # ($zoom - 1). We then scale everything by 1/$self->_zoom since + # $self->_camera_target is expressed in terms of model units. + -($pos->x - $size->x/2) * ($zoom) / $self->_zoom, + -($pos->y - $size->y/2) * ($zoom) / $self->_zoom, + 0, + ) if 0; + */ + + dirty = true; + Refresh(); +} + +void Scene3D::mouse_dclick(wxMouseEvent &e){ + /* + if (@{$self->volumes}) { + $self->zoom_to_volumes; + } else { + $self->zoom_to_bed; + }*/ + + dirty = true; + Refresh(); +} + +void Scene3D::resize(){ + if(!dirty)return; + dirty = false; + const auto s = GetSize(); + glViewport(0,0,s.GetWidth(),s.GetHeight()); + const auto x = s.GetWidth()/zoom, + y = s.GetHeight()/zoom, + depth = 1000.0f; // my $depth = 10 * max(@{ $self->max_bounding_box->size }); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho( + -x/2, x/2, -y/2, y/2, + -depth, 2*depth + ); + glMatrixMode(GL_MODELVIEW); +} + +void Scene3D::set_bed_shape(Points _bed_shape){ + + bed_shape = _bed_shape; + const float GROUND_Z = -0.02f; + + // triangulate bed + const auto expoly = ExPolygon(Polygon(bed_shape)); + const auto box = expoly.bounding_box(); + bed_bound = box; + { + std::vector triangles; + expoly.triangulate(&triangles); + bed_verts.clear(); + for(const auto &triangle : triangles){ + for(const auto &point : triangle.points){ + bed_verts.push_back(unscale(point.x)); + bed_verts.push_back(unscale(point.y)); + bed_verts.push_back(GROUND_Z); + } + } + } + { + std::vector lines; + Points tmp; + for (coord_t x = box.min.x; x <= box.max.x; x += scale_(10)) { + lines.push_back(Polyline()); + lines.back().append(Point(x,box.min.y)); + lines.back().append(Point(x,box.max.y)); + } + for (coord_t y = box.min.y; y <= box.max.y; y += scale_(10)) { + lines.push_back(Polyline()); + lines.back().append(Point(box.min.x,y)); + lines.back().append(Point(box.max.x,y)); + } + // clip with a slightly grown expolygon because our lines lay on the contours and + // may get erroneously clipped + // my @lines = map Slic3r::Line->new(@$_[0,-1]), + grid_verts.clear(); + const Polylines clipped = intersection_pl(lines,offset_ex(expoly,SCALED_EPSILON).at(0)); + for(const Polyline &line : clipped){ + for(const Point &point : line.points){ + grid_verts.push_back(unscale(point.x)); + grid_verts.push_back(unscale(point.y)); + grid_verts.push_back(GROUND_Z); + } + } + // append bed contours + for(const Line &line : expoly.lines()){ + grid_verts.push_back(unscale(line.a.x)); + grid_verts.push_back(unscale(line.a.y)); + grid_verts.push_back(GROUND_Z); + grid_verts.push_back(unscale(line.b.x)); + grid_verts.push_back(unscale(line.b.y)); + grid_verts.push_back(GROUND_Z); + } + } + + //$self->origin(Slic3r::Pointf->new(0,0)); +} + +void Scene3D::init_gl(){ + if(this->init)return; + this->init = true; + + glClearColor(0, 0, 0, 1); + glColor3f(1, 0, 0); + glEnable(GL_DEPTH_TEST); + glClearDepth(1.0); + glDepthFunc(GL_LEQUAL); + glEnable(GL_CULL_FACE); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + // Set antialiasing/multisampling + glDisable(GL_LINE_SMOOTH); + glDisable(GL_POLYGON_SMOOTH); + //glEnable(GL_MULTISAMPLE) if ($self->{can_multisample}); + + // ambient lighting + GLfloat ambient[] = {0.1f, 0.1f, 0.1f, 1.0f}; + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHT1); + + // light from camera + GLfloat pos[] = {1.0f, 0.0f, 1.0f, 0.0f}, spec[] = {0.8f, 0.8f, 0.8f, 1.0f}, diff[] = {0.4f, 0.4f, 0.4f, 1.0f}; + glLightfv(GL_LIGHT1, GL_POSITION, pos); + glLightfv(GL_LIGHT1, GL_SPECULAR, spec); + glLightfv(GL_LIGHT1, GL_DIFFUSE, diff); + + // Enables Smooth Color Shading; try GL_FLAT for (lack of) fun. Default: GL_SMOOTH + glShadeModel(GL_SMOOTH); + + GLfloat fbdiff[] = {0.3f, 0.3f, 0.3f,1}, fbspec[] = {1.0f, 1.0f, 1.0f, 1.0f}, fbemis[] = {0.1f,0.1f,0.1f,0.9f}; + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, fbdiff); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, fbspec); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50); + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, fbemis); + + // A handy trick -- have surface material mirror the color. + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); + //glEnable(GL_MULTISAMPLE) if ($self->{can_multisample}); +} + +void Scene3D::draw_background(){ + glDisable(GL_LIGHTING); + glPushMatrix(); + glLoadIdentity(); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glBegin(GL_QUADS); + auto bottom = ui_settings->color->BOTTOM_COLOR(), top = ui_settings->color->TOP_COLOR(); + if(ui_settings->color->SOLID_BACKGROUNDCOLOR()){ + bottom = top = ui_settings->color->BACKGROUND_COLOR(); + } + glColor3ub(bottom.Red(), bottom.Green(), bottom.Blue()); + glVertex2f(-1.0,-1.0); + glVertex2f(1,-1.0); + glColor3ub(top.Red(), top.Green(), top.Blue()); + glVertex2f(1, 1); + glVertex2f(-1.0, 1); + glEnd(); + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void Scene3D::draw_ground(){ + glDisable(GL_DEPTH_TEST); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnableClientState(GL_VERTEX_ARRAY); + /*my $triangle_vertex; + if (HAS_VBO) { + ($triangle_vertex) = + glGenBuffersARB_p(1); + $self->bed_triangles->bind($triangle_vertex); + glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $self->bed_triangles, GL_STATIC_DRAW_ARB); + glVertexPointer_c(3, GL_FLOAT, 0, 0); + } else {*/ + // fall back on old behavior + glVertexPointer(3, GL_FLOAT, 0, bed_verts.data()); + const auto ground = ui_settings->color->GROUND_COLOR(), grid = ui_settings->color->GRID_COLOR(); + + glColor4ub(ground.Red(), ground.Green(), ground.Blue(),ground.Alpha()); + glNormal3d(0,0,1); + glDrawArrays(GL_TRIANGLES, 0, bed_verts.size() / 3); + + // we need depth test for grid, otherwise it would disappear when looking + // the object from below + glEnable(GL_DEPTH_TEST); + + // draw grid + glLineWidth(2); + /*my $grid_vertex; + if (HAS_VBO) { + ($grid_vertex) = + glGenBuffersARB_p(1); + $self->bed_grid_lines->bind($grid_vertex); + glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $self->bed_grid_lines, GL_STATIC_DRAW_ARB); + glVertexPointer_c(3, GL_FLOAT, 0, 0); + } else {*/ + // fall back on old behavior + glVertexPointer(3, GL_FLOAT, 0, grid_verts.data()); + + glColor4ub(grid.Red(), grid.Green(), grid.Blue(),grid.Alpha()); + glNormal3d(0,0,1); + glDrawArrays(GL_LINES, 0, grid_verts.size() / 3); + glDisableClientState(GL_VERTEX_ARRAY); + + glDisable(GL_BLEND); + /*if (HAS_VBO) { + # Turn off buffer objects to let the rest of the draw code work. + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glDeleteBuffersARB_p($grid_vertex); + glDeleteBuffersARB_p($triangle_vertex); + }*/ +} + +void Scene3D::draw_axes (Pointf3 center, float length, int width, bool always_visible){ + /* + my $volumes_bb = $self->volumes_bounding_box; + + { + # draw axes + # disable depth testing so that axes are not covered by ground + glDisable(GL_DEPTH_TEST); + my $origin = $self->origin; + my $axis_len = max( + max(@{ $self->bed_bounding_box->size }), + 1.2 * max(@{ $volumes_bb->size }), + ); + glLineWidth(2); + glBegin(GL_LINES); + # draw line for x axis + glColor3f(1, 0, 0); + glVertex3f(@$origin, $ground_z); + glVertex3f($origin->x + $axis_len, $origin->y, $ground_z); #,, + # draw line for y axis + glColor3f(0, 1, 0); + glVertex3f(@$origin, $ground_z); + glVertex3f($origin->x, $origin->y + $axis_len, $ground_z); #++ + glEnd(); + # draw line for Z axis + # (re-enable depth test so that axis is correctly shown when objects are behind it) + glEnable(GL_DEPTH_TEST); + glBegin(GL_LINES); + glColor3f(0, 0, 1); + glVertex3f(@$origin, $ground_z); + glVertex3f(@$origin, $ground_z+$axis_len); + glEnd(); + } + */ + if (always_visible) { + glDisable(GL_DEPTH_TEST); + } else { + glEnable(GL_DEPTH_TEST); + } + glLineWidth(width); + glBegin(GL_LINES); + // draw line for x axis + glColor3f(1, 0, 0); + glVertex3f(center.x, center.y, center.z); + glVertex3f(center.x + length, center.y, center.z); + // draw line for y axis + glColor3f(0, 1, 0); + glVertex3f(center.x, center.y, center.z); + glVertex3f(center.x, center.y + length, center.z); + // draw line for Z axis + glColor3f(0, 0, 1); + glVertex3f(center.x, center.y, center.z); + glVertex3f(center.x, center.y, center.z + length); + glEnd(); + glEnable(GL_DEPTH_TEST); +} +void Scene3D::draw_volumes(){ + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + + for(const Volume &volume : volumes){ + glPushMatrix(); + glTranslatef(volume.origin.x, volume.origin.y, volume.origin.z); + glCullFace(GL_BACK); + glVertexPointer(3, GL_FLOAT, 0, volume.model.verts.data()); + glNormalPointer(GL_FLOAT, 0, volume.model.norms.data()); + glColor4ub(volume.color.Red(), volume.color.Green(), volume.color.Blue(), volume.color.Alpha()); + glDrawArrays(GL_TRIANGLES, 0, volume.model.verts.size()/3); + glPopMatrix(); + } + + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + glDisable(GL_BLEND); +} + +void Scene3D::repaint(wxPaintEvent& e) { + if(!this->IsShownOnScreen())return; + // There should be a context->IsOk check once wx is updated + if(!this->SetCurrent(*(this->glContext)))return; + init_gl(); + resize(); + + glClearColor(1, 1, 1, 1); + glClearDepth(1); + glDepthFunc(GL_LESS); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glRotatef(-theta, 1, 0, 0); // pitch + glRotatef(phi, 0, 0, 1); // yaw + /*} else { + my @rotmat = quat_to_rotmatrix($self->quat); + glMultMatrixd_p(@rotmat[0..15]); + }*/ + glTranslatef(-_camera_target.x, -_camera_target.y, -_camera_target.z); + + // light from above + GLfloat pos[] = {-0.5f, -0.5f, 1.0f, 0.0f}, spec[] = {0.2f, 0.2f, 0.2f, 1.0f}, diff[] = {0.5f, 0.5f, 0.5f, 1.0f}; + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glLightfv(GL_LIGHT0, GL_SPECULAR, spec); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diff); + + before_render(); + + draw_background(); + draw_ground(); + /*my $origin = $self->origin; + my $axis_len = max( + max(@{ $self->bed_bounding_box->size }), + 1.2 * max(@{ $volumes_bb->size }), + );*/ + draw_axes(Pointf3(0.0f,0.0f,0.0f), + unscale(bed_bound.radius()),2,true/*origin,calulcated length,2, true*/); + + // draw objects + glEnable(GL_LIGHTING); + draw_volumes(); + + after_render(); + + if (dragging/*defined $self->_drag_start_pos || defined $self->_drag_start_xy*/) { + draw_axes(_camera_target, 10.0f, 1, true/*camera,10,1,true*/); + draw_axes(_camera_target, 10.0f, 4, false/*camera,10,4,false*/); + } + + glFlush(); + SwapBuffers(); + // Calling glFinish has a performance penalty, but it seems to fix some OpenGL driver hang-up with extremely large scenes. + glFinish(); + +} + +Volume Scene3D::load_object(ModelVolume &mv, ModelInstance &mi){ + TriangleMesh copy = mv.mesh; + mi.transform_mesh(©); + GLVertexArray model; + model.load_mesh(copy); + return Volume{ wxColor(200,200,200), Pointf3(0,0,0), model, copy.bounding_box()}; +} + +} } // Namespace Slic3r::GUI diff --git a/src/GUI/Scene3D.hpp b/src/GUI/Scene3D.hpp new file mode 100644 index 000000000..d78ec01b9 --- /dev/null +++ b/src/GUI/Scene3D.hpp @@ -0,0 +1,55 @@ +#ifndef SCENE3D_HPP +#define SCENE3D_HPP +#include +#ifndef WX_PRECOMP + #include +#endif + #include +#include "Settings.hpp" +#include "Point.hpp" +#include "3DScene.hpp" +#include "BoundingBox.hpp" +#include "Model.hpp" + +namespace Slic3r { namespace GUI { + +struct Volume { + wxColor color; + Pointf3 origin; + GLVertexArray model; + BoundingBoxf3 bb; +}; + +class Scene3D : public wxGLCanvas { +public: + Scene3D(wxWindow* parent, const wxSize& size); +private: + wxGLContext* glContext; + bool init = false, dirty = true, dragging = false; + float zoom = 5.0f, phi = 0.0f, theta = 0.0f; + Point drag_start = Point(0,0); + Pointf3 _camera_target = Pointf3(0.0f,0.0f,0.0f); + std::vector bed_verts, grid_verts; + Points bed_shape; + BoundingBox bed_bound; + void resize(); + void repaint(wxPaintEvent &e); + void init_gl(); + void draw_background(); + void draw_ground(); + void draw_axes(Pointf3 center, float length, int width, bool alwaysvisible); +protected: + void draw_volumes(); + virtual void mouse_up(wxMouseEvent &e); + virtual void mouse_move(wxMouseEvent &e); + virtual void mouse_dclick(wxMouseEvent &e); + virtual void mouse_wheel(wxMouseEvent &e); + virtual void before_render(){}; + virtual void after_render(){}; + Volume load_object(ModelVolume &mv, ModelInstance &mi); + void set_bed_shape(Points _bed_shape); + std::vector volumes; + }; + +} } // Namespace Slic3r::GUI +#endif From 7362e5657814511366f9849dba05758104bbce2d Mon Sep 17 00:00:00 2001 From: Benjamin Landers Date: Fri, 22 Jun 2018 23:02:21 -0700 Subject: [PATCH 301/305] Fix color issues --- src/GUI/ColorScheme/Default.hpp | 10 +++++----- src/GUI/Plater/Plate3D.cpp | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/GUI/ColorScheme/Default.hpp b/src/GUI/ColorScheme/Default.hpp index 69b7e0a98..2adb8cc61 100644 --- a/src/GUI/ColorScheme/Default.hpp +++ b/src/GUI/ColorScheme/Default.hpp @@ -7,7 +7,7 @@ class DefaultColor : public ColorScheme { public: const std::string name() const { return "Default"; } const bool SOLID_BACKGROUNDCOLOR() const { return false; }; - const wxColour SELECTED_COLOR() const { return wxColour(0, 1, 0); }; + const wxColour SELECTED_COLOR() const { return wxColour(0, 255, 0); }; const wxColour HOVER_COLOR() const { return wxColour(255*0.4, 255*0.9, 0); }; //color->SELECTED_COLOR(); }else{ - rendervolume.color = wxColor(255,255,0);//ui_settings->color->COLOR_PARTS(); <- invisible because alpha is 1 (out of 255) + rendervolume.color = ui_settings->color->COLOR_PARTS(); } + i++; } } } @@ -74,7 +75,7 @@ void Plate3D::before_render(){ //glDisable(GL_MULTISAMPLE) if ($self->{can_multisample}); glDisable(GL_LIGHTING); - uint i = 0; + uint i = 1; for(Volume &volume : volumes){ volume.color = wxColor((i>>16)&0xFF,(i>>8)&0xFF,i&0xFF); i++; @@ -82,16 +83,16 @@ void Plate3D::before_render(){ draw_volumes(); glFlush(); glFinish(); - GLubyte color[4] = {0,0,0,0}; - glReadPixels(pos.x, /*offset*/GetSize().GetHeight()- pos.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, color); + GLubyte color[4] = {0,0,0,0}; + glReadPixels(pos.x, GetSize().GetHeight()- pos.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, color); - uint index = color[0] + (color[1]<<8) + (color[2]<<16); + uint index = (color[0]<<16) + (color[1]<<8) + color[2]; hover = false; ///*$self->_hover_volume_idx(undef); //$_->hover(0) for @{$self->volumes}; - if (index < volumes.size()) { + if (index != 0 && index <= volumes.size()) { hover = true; - hover_volume = index; + hover_volume = index - 1; /* $self->volumes->[$volume_idx]->hover(1); my $group_id = $self->volumes->[$volume_idx]->select_group_id; @@ -105,7 +106,7 @@ void Plate3D::before_render(){ glFlush(); glFinish(); glEnable(GL_LIGHTING); - color_volumes(); + color_volumes(); mouse = false; } From 2258fd5978d620d406202c842740b25363253bcc Mon Sep 17 00:00:00 2001 From: Benjamin Landers Date: Mon, 25 Jun 2018 03:44:31 -0700 Subject: [PATCH 302/305] Added selection and moving volumes to Plate3D --- src/GUI/Plater.cpp | 5 +++ src/GUI/Plater/Plate3D.cpp | 92 +++++++++++++++++++++++++++++++------- src/GUI/Plater/Plate3D.hpp | 12 +++-- src/GUI/Scene3D.cpp | 2 +- src/GUI/Scene3D.hpp | 1 + 5 files changed, 92 insertions(+), 20 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index af7688394..f72a70b96 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -88,6 +88,9 @@ Plater::Plater(wxWindow* parent, const wxString& title) : canvas3D = new Plate3D(preview_notebook, wxDefaultSize, objects, model, config); preview_notebook->AddPage(canvas3D, _("3D")); + canvas3D->on_select_object = std::function(on_select_object); + canvas3D->on_instances_moved = std::function(on_instances_moved); + preview3D = new Preview3D(preview_notebook, wxDefaultSize, objects, model, config); preview_notebook->AddPage(preview3D, _("Preview")); @@ -494,6 +497,7 @@ void Plater::arrange() { } void Plater::on_model_change(bool force_autocenter) { + Log::info(LogChannel, L"Called on_modal_change"); // reload the select submenu (if already initialized) { @@ -562,6 +566,7 @@ void Plater::select_object() { void Plater::selection_changed() { // Remove selection in 2D plater this->canvas2D->set_selected(-1, -1); + this->canvas3D->selection_changed(); auto obj = this->selected_object(); bool have_sel {obj != this->objects.end()}; diff --git a/src/GUI/Plater/Plate3D.cpp b/src/GUI/Plater/Plate3D.cpp index 1aa6544d8..185d06e6c 100644 --- a/src/GUI/Plater/Plate3D.cpp +++ b/src/GUI/Plater/Plate3D.cpp @@ -6,30 +6,74 @@ namespace Slic3r { namespace GUI { Plate3D::Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : Scene3D(parent, size), objects(_objects), model(_model), config(_config) { - - //this->glContext = new wxGLContext(this); - //this->Bind(wxEVT_PAINT, [this](wxPaintEvent& e) { this->repaint(e); }); - //delete this->glContext; - //this->glContext = new wxGLContext(this); // Update glContext (look for better way) - //}); - - // Bind the varying mouse events + // Bind the extra mouse events this->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { this->mouse_down(e); }); this->Bind(wxEVT_RIGHT_DOWN, [this](wxMouseEvent &e) { this->mouse_down(e); }); } void Plate3D::mouse_down(wxMouseEvent &e){ - if(!hover){ - //select logic + if(hover){ + on_select_object(hover_object); + moving = true; + moving_volume = hover_volume; + move_start = Point(e.GetX(),e.GetY()); + }else{ + on_select_object(-1); } + hover = false; } - +void Plate3D::mouse_up(wxMouseEvent &e){ + if(moving){ + //translate object + moving = false; + uint i = 0; + for(const PlaterObject &object: objects){ + const auto &modelobj = model->objects.at(object.identifier); + for(ModelInstance *instance: modelobj->instances){ + uint size = modelobj->volumes.size(); + if(i <= moving_volume && moving_volume < i+size){ + + instance->offset.translate(volumes.at(i).origin); + modelobj->update_bounding_box(); + on_instances_moved(); + Refresh(); + return; + }else{ + i+=size; + } + } + } + } + Scene3D::mouse_up(e); +} void Plate3D::mouse_move(wxMouseEvent &e){ if(!e.Dragging()){ pos = Point(e.GetX(),e.GetY()); mouse = true; Refresh(); + } else if(moving){ + const auto p = Point(e.GetX(),e.GetY()); + const auto current = mouse_ray(p).intersect_plane(0); + const auto old = mouse_ray(move_start).intersect_plane(0); + move_start = p; + uint i = 0; + for(const PlaterObject &object: objects){ + const auto &modelobj = model->objects.at(object.identifier); + for(ModelInstance *instance: modelobj->instances){ + uint size = modelobj->volumes.size(); + if(i <= moving_volume && moving_volume < i+size){ + for(ModelVolume* volume: modelobj->volumes){ + volumes.at(i).origin.translate(old.vector_to(current)); + i++; + } + Refresh(); + return; + }else{ + i+=size; + } + } + } } else { Scene3D::mouse_move(e); } @@ -47,32 +91,37 @@ void Plate3D::update(){ } } color_volumes(); + Refresh(); } void Plate3D::color_volumes(){ uint i = 0; for(const PlaterObject &object: objects){ const auto &modelobj = model->objects.at(object.identifier); + bool hover_object = hover && i <= hover_volume && hover_volume < i+modelobj->instances.size()*modelobj->volumes.size(); for(ModelInstance *instance: modelobj->instances){ for(ModelVolume* volume: modelobj->volumes){ auto& rendervolume = volumes.at(i); if(object.selected){ rendervolume.color = ui_settings->color->SELECTED_COLOR(); - }else{ + }else if(hover_object){ + rendervolume.color = ui_settings->color->HOVER_COLOR(); + } else { rendervolume.color = ui_settings->color->COLOR_PARTS(); } i++; } } } - if(hover){ - volumes.at(hover_volume).color = ui_settings->color->HOVER_COLOR(); - } } void Plate3D::before_render(){ - if (!mouse)return; + if (!mouse){ + color_volumes(); + return; + } + // Color each volume a different color, render and test which color is beneath the mouse. //glDisable(GL_MULTISAMPLE) if ($self->{can_multisample}); glDisable(GL_LIGHTING); uint i = 1; @@ -86,6 +135,8 @@ void Plate3D::before_render(){ GLubyte color[4] = {0,0,0,0}; glReadPixels(pos.x, GetSize().GetHeight()- pos.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, color); + + // Handle the hovered volume uint index = (color[0]<<16) + (color[1]<<8) + color[2]; hover = false; ///*$self->_hover_volume_idx(undef); @@ -93,6 +144,15 @@ void Plate3D::before_render(){ if (index != 0 && index <= volumes.size()) { hover = true; hover_volume = index - 1; + uint k = 0; + for(const PlaterObject &object: objects){ + const auto &modelobj = model->objects.at(object.identifier); + if(k <= hover_volume && hover_volume < k+modelobj->instances.size()*modelobj->volumes.size()){ + hover_object = k; + break; + } + k++; + } /* $self->volumes->[$volume_idx]->hover(1); my $group_id = $self->volumes->[$volume_idx]->select_group_id; diff --git a/src/GUI/Plater/Plate3D.hpp b/src/GUI/Plater/Plate3D.hpp index 1c5954c87..f83dbc292 100644 --- a/src/GUI/Plater/Plate3D.hpp +++ b/src/GUI/Plater/Plate3D.hpp @@ -15,16 +15,22 @@ namespace Slic3r { namespace GUI { class Plate3D : public Scene3D { public: void update(); + /// Registered function to fire when objects are selected. + std::function on_select_object {}; + /// Registered function to fire when an instance is moved. + std::function on_instances_moved {}; + void selection_changed(){Refresh();} Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config); protected: void before_render(); + void mouse_up(wxMouseEvent &e); void mouse_move(wxMouseEvent &e); void mouse_down(wxMouseEvent &e); private: void color_volumes(); - Point pos; - bool hover = false, mouse = false; - uint hover_volume; + Point pos, move_start; + bool hover = false, mouse = false, moving = false; + uint hover_volume, hover_object, moving_volume; std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; diff --git a/src/GUI/Scene3D.cpp b/src/GUI/Scene3D.cpp index e379eda27..110d06eb4 100644 --- a/src/GUI/Scene3D.cpp +++ b/src/GUI/Scene3D.cpp @@ -47,7 +47,7 @@ float clamp(float low, float x, float high){ return x; } -Linef3 mouse_ray(Point win){ +Linef3 Scene3D::mouse_ray(Point win){ GLdouble proj[16], mview[16]; glGetDoublev(GL_MODELVIEW_MATRIX, mview); glGetDoublev(GL_PROJECTION_MATRIX, proj); diff --git a/src/GUI/Scene3D.hpp b/src/GUI/Scene3D.hpp index d78ec01b9..02daa984a 100644 --- a/src/GUI/Scene3D.hpp +++ b/src/GUI/Scene3D.hpp @@ -39,6 +39,7 @@ private: void draw_ground(); void draw_axes(Pointf3 center, float length, int width, bool alwaysvisible); protected: + Linef3 mouse_ray(Point win); void draw_volumes(); virtual void mouse_up(wxMouseEvent &e); virtual void mouse_move(wxMouseEvent &e); From 40decdc405464a3ddb26a3235b272f98babffa14 Mon Sep 17 00:00:00 2001 From: Benjamin Landers Date: Wed, 27 Jun 2018 21:17:10 -0700 Subject: [PATCH 303/305] Cleanup --- src/GUI/Plater/Plate3D.cpp | 21 +++++++++++--------- src/GUI/Plater/Plate3D.hpp | 15 +++++++++++++-- src/GUI/Scene3D.cpp | 16 +--------------- src/GUI/Scene3D.hpp | 39 +++++++++++++++++++++++++++----------- 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/GUI/Plater/Plate3D.cpp b/src/GUI/Plater/Plate3D.cpp index 185d06e6c..6750a8897 100644 --- a/src/GUI/Plater/Plate3D.cpp +++ b/src/GUI/Plater/Plate3D.cpp @@ -31,9 +31,8 @@ void Plate3D::mouse_up(wxMouseEvent &e){ for(const PlaterObject &object: objects){ const auto &modelobj = model->objects.at(object.identifier); for(ModelInstance *instance: modelobj->instances){ - uint size = modelobj->volumes.size(); + uint size = modelobj->volumes.size(); if(i <= moving_volume && moving_volume < i+size){ - instance->offset.translate(volumes.at(i).origin); modelobj->update_bounding_box(); on_instances_moved(); @@ -47,6 +46,7 @@ void Plate3D::mouse_up(wxMouseEvent &e){ } Scene3D::mouse_up(e); } + void Plate3D::mouse_move(wxMouseEvent &e){ if(!e.Dragging()){ pos = Point(e.GetX(),e.GetY()); @@ -61,7 +61,7 @@ void Plate3D::mouse_move(wxMouseEvent &e){ for(const PlaterObject &object: objects){ const auto &modelobj = model->objects.at(object.identifier); for(ModelInstance *instance: modelobj->instances){ - uint size = modelobj->volumes.size(); + uint size = modelobj->volumes.size(); if(i <= moving_volume && moving_volume < i+size){ for(ModelVolume* volume: modelobj->volumes){ volumes.at(i).origin.translate(old.vector_to(current)); @@ -79,15 +79,18 @@ void Plate3D::mouse_move(wxMouseEvent &e){ } } - void Plate3D::update(){ volumes.clear(); for(const PlaterObject &object: objects){ const auto &modelobj = model->objects.at(object.identifier); for(ModelInstance *instance: modelobj->instances){ for(ModelVolume* volume: modelobj->volumes){ - volumes.push_back(load_object(*volume,*instance)); - } + TriangleMesh copy = volume->mesh; + instance->transform_mesh(©); + GLVertexArray model; + model.load_mesh(copy); + volumes.push_back(Volume{ wxColor(200,200,200), Pointf3(0,0,0), model, copy.bounding_box()}); + } } } color_volumes(); @@ -110,7 +113,7 @@ void Plate3D::color_volumes(){ rendervolume.color = ui_settings->color->COLOR_PARTS(); } i++; - } + } } } } @@ -122,6 +125,7 @@ void Plate3D::before_render(){ } // Color each volume a different color, render and test which color is beneath the mouse. + //glDisable(GL_MULTISAMPLE) if ($self->{can_multisample}); glDisable(GL_LIGHTING); uint i = 1; @@ -135,7 +139,6 @@ void Plate3D::before_render(){ GLubyte color[4] = {0,0,0,0}; glReadPixels(pos.x, GetSize().GetHeight()- pos.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, color); - // Handle the hovered volume uint index = (color[0]<<16) + (color[1]<<8) + color[2]; hover = false; @@ -149,7 +152,7 @@ void Plate3D::before_render(){ const auto &modelobj = model->objects.at(object.identifier); if(k <= hover_volume && hover_volume < k+modelobj->instances.size()*modelobj->volumes.size()){ hover_object = k; - break; + break; } k++; } diff --git a/src/GUI/Plater/Plate3D.hpp b/src/GUI/Plater/Plate3D.hpp index f83dbc292..605ce9d65 100644 --- a/src/GUI/Plater/Plate3D.hpp +++ b/src/GUI/Plater/Plate3D.hpp @@ -14,23 +14,34 @@ namespace Slic3r { namespace GUI { class Plate3D : public Scene3D { public: + Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config); + + /// Called to regenerate rendered volumes from the model void update(); + /// Registered function to fire when objects are selected. std::function on_select_object {}; + /// Registered function to fire when an instance is moved. std::function on_instances_moved {}; + void selection_changed(){Refresh();} - Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config); -protected: + protected: + // Render each volume as a different color and check what color is beneath + // the mouse to detemine the hovered volume void before_render(); + + // Mouse events are needed to handle selecting and moving objects void mouse_up(wxMouseEvent &e); void mouse_move(wxMouseEvent &e); void mouse_down(wxMouseEvent &e); + private: void color_volumes(); Point pos, move_start; bool hover = false, mouse = false, moving = false; uint hover_volume, hover_object, moving_volume; + std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; diff --git a/src/GUI/Scene3D.cpp b/src/GUI/Scene3D.cpp index 110d06eb4..cb4b059bd 100644 --- a/src/GUI/Scene3D.cpp +++ b/src/GUI/Scene3D.cpp @@ -25,13 +25,7 @@ Scene3D::Scene3D(wxWindow* parent, const wxSize& size) : this->Bind(wxEVT_RIGHT_UP, [this](wxMouseEvent &e) { this->mouse_up(e); }); this->Bind(wxEVT_MIDDLE_DCLICK, [this](wxMouseEvent &e) { this->mouse_dclick(e); }); this->Bind(wxEVT_MOUSEWHEEL, [this](wxMouseEvent &e) { this->mouse_wheel(e); }); -/* - if (user_drawn_background) { - this->Bind(wxEVT_ERASE_BACKGROUND, [this](wxEraseEvent& e){ }); - } - - this->Bind(wxEVT_CHAR, [this](wxKeyEvent &e) { this->nudge_key(e);}); - */ + Points p; const coord_t w = scale_(200), z = 0; p.push_back(Point(z,z)); @@ -497,12 +491,4 @@ void Scene3D::repaint(wxPaintEvent& e) { } -Volume Scene3D::load_object(ModelVolume &mv, ModelInstance &mi){ - TriangleMesh copy = mv.mesh; - mi.transform_mesh(©); - GLVertexArray model; - model.load_mesh(copy); - return Volume{ wxColor(200,200,200), Pointf3(0,0,0), model, copy.bounding_box()}; -} - } } // Namespace Slic3r::GUI diff --git a/src/GUI/Scene3D.hpp b/src/GUI/Scene3D.hpp index 02daa984a..21dd47108 100644 --- a/src/GUI/Scene3D.hpp +++ b/src/GUI/Scene3D.hpp @@ -25,31 +25,48 @@ public: Scene3D(wxWindow* parent, const wxSize& size); private: wxGLContext* glContext; - bool init = false, dirty = true, dragging = false; + + // Camera settings float zoom = 5.0f, phi = 0.0f, theta = 0.0f; - Point drag_start = Point(0,0); Pointf3 _camera_target = Pointf3(0.0f,0.0f,0.0f); + + // Optional point used for dragging calculations + bool dragging = false; + Point drag_start = Point(0,0); + + // Bed Stuff std::vector bed_verts, grid_verts; Points bed_shape; BoundingBox bed_bound; - void resize(); - void repaint(wxPaintEvent &e); - void init_gl(); + + void repaint(wxPaintEvent &e); // Redraws every frame + + bool dirty = true; // Resize needs to be called before render + void resize(); // Handle glViewport and projection matrices + + bool init = false; // Has opengl been initted + void init_gl(); // Handles lights and materials + + // Useded in repaint void draw_background(); void draw_ground(); void draw_axes(Pointf3 center, float length, int width, bool alwaysvisible); + protected: - Linef3 mouse_ray(Point win); - void draw_volumes(); - virtual void mouse_up(wxMouseEvent &e); + Linef3 mouse_ray(Point win); // Utility for backtracking from window coordinates + void draw_volumes(); // Draws volumes (for use in before_render) + void set_bed_shape(Points _bed_shape); + + std::vector volumes; + Volume load_object(ModelVolume &mv, ModelInstance &mi); + + // Virtual methods to override + virtual void mouse_up(wxMouseEvent &e); virtual void mouse_move(wxMouseEvent &e); virtual void mouse_dclick(wxMouseEvent &e); virtual void mouse_wheel(wxMouseEvent &e); virtual void before_render(){}; virtual void after_render(){}; - Volume load_object(ModelVolume &mv, ModelInstance &mi); - void set_bed_shape(Points _bed_shape); - std::vector volumes; }; } } // Namespace Slic3r::GUI From 9ca0fed4b5c8d1c7dbb9b0e5a35435503dcb539a Mon Sep 17 00:00:00 2001 From: Benjamin Landers Date: Mon, 2 Jul 2018 15:16:34 -0700 Subject: [PATCH 304/305] Added the rough form of ObjectCutDialog OptionsGroup needs to be more complete before moving ahead with this --- src/CMakeLists.txt | 1 + src/GUI/Dialogs/ObjectCutDialog.cpp | 351 ++++++++++++++++++++++++++++ src/GUI/Dialogs/ObjectCutDialog.hpp | 51 ++++ src/GUI/Plater.cpp | 8 + 4 files changed, 411 insertions(+) create mode 100644 src/GUI/Dialogs/ObjectCutDialog.cpp create mode 100644 src/GUI/Dialogs/ObjectCutDialog.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdd272f3e..6767d1a25 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -246,6 +246,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/Dialogs/PrintEditor.cpp ${GUI_LIBDIR}/Dialogs/PrinterEditor.cpp ${GUI_LIBDIR}/Dialogs/MaterialEditor.cpp + ${GUI_LIBDIR}/Dialogs/ObjectCutDialog.cpp ${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/Plater.cpp diff --git a/src/GUI/Dialogs/ObjectCutDialog.cpp b/src/GUI/Dialogs/ObjectCutDialog.cpp new file mode 100644 index 000000000..75f412b08 --- /dev/null +++ b/src/GUI/Dialogs/ObjectCutDialog.cpp @@ -0,0 +1,351 @@ +#include "ObjectCutDialog.hpp" + + +// Cut an object at a Z position, keep either the top or the bottom of the object. +// This dialog gets opened with the "Cut..." button above the platter. + +namespace Slic3r { namespace GUI { + +ObjectCutDialog::ObjectCutDialog(wxWindow* parent, ModelObject* _model_object/*, ...*/): wxDialog(parent, -1, _(_model_object->name), wxDefaultPosition, wxSize(500, 500), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), model_object(_model_object) { + +/* + $self->{model_object}->transform_by_instance($self->{model_object}->get_instance(0), 1); + + // cut options + my $size_z = $self->{model_object}->instance_bounding_box(0)->size->z; + $self->{cut_options} = { + axis => Z, + z => $size_z/2, + keep_upper => 0, + keep_lower => 1, + rotate_lower => 0, + preview => 1, + }; + + my $optgroup; + $optgroup = $self->{optgroup} = Slic3r::GUI::OptionsGroup->new( + parent => $self, + title => 'Cut', + on_change => sub { + my ($opt_id) = @_; + # There seems to be an issue with wxWidgets 3.0.2/3.0.3, where the slider + # genates tens of events for a single value change. + # Only trigger the recalculation if the value changes + # or a live preview was activated and the mesh cut is not valid yet. + if ($self->{cut_options}{$opt_id} != $optgroup->get_value($opt_id) || + ! $self->{mesh_cut_valid} && $self->_life_preview_active()) { + $self->{cut_options}{$opt_id} = $optgroup->get_value($opt_id); + $self->{mesh_cut_valid} = 0; + wxTheApp->CallAfter(sub { + $self->_update; + }); + } + }, + label_width => 120, + ); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'axis', + type => 'select', + label => 'Axis', + labels => ['X','Y','Z'], + values => [X,Y,Z], + default => $self->{cut_options}{axis}, + )); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'z', + type => 'slider', + label => 'Z', + default => $self->{cut_options}{z}, + min => 0, + max => $size_z, + full_width => 1, + )); + { + my $line = Slic3r::GUI::OptionsGroup::Line->new( + label => 'Keep', + ); + $line->append_option(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'keep_upper', + type => 'bool', + label => 'Upper part', + default => $self->{cut_options}{keep_upper}, + )); + $line->append_option(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'keep_lower', + type => 'bool', + label => 'Lower part', + default => $self->{cut_options}{keep_lower}, + )); + $optgroup->append_line($line); + } + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'rotate_lower', + label => 'Rotate lower part upwards', + type => 'bool', + tooltip => 'If enabled, the lower part will be rotated by 180° so that the flat cut surface lies on the print bed.', + default => $self->{cut_options}{rotate_lower}, + )); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'preview', + label => 'Show preview', + type => 'bool', + tooltip => 'If enabled, object will be cut in real time.', + default => $self->{cut_options}{preview}, + )); + { + my $cut_button_sizer = Wx::BoxSizer->new(wxVERTICAL); + + $self->{btn_cut} = Wx::Button->new($self, -1, "Perform cut", wxDefaultPosition, wxDefaultSize); + $self->{btn_cut}->SetDefault; + $cut_button_sizer->Add($self->{btn_cut}, 0, wxALIGN_RIGHT | wxALL, 10); + + $self->{btn_cut_grid} = Wx::Button->new($self, -1, "Cut by grid…", wxDefaultPosition, wxDefaultSize); + $cut_button_sizer->Add($self->{btn_cut_grid}, 0, wxALIGN_RIGHT | wxALL, 10); + + $optgroup->append_line(Slic3r::GUI::OptionsGroup::Line->new( + sizer => $cut_button_sizer, + )); + } + + # left pane with tree + my $left_sizer = Wx::BoxSizer->new(wxVERTICAL); + $left_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + + # right pane with preview canvas + my $canvas; + if ($Slic3r::GUI::have_OpenGL) { + $canvas = $self->{canvas} = Slic3r::GUI::3DScene->new($self); + $canvas->load_object($self->{model_object}, undef, [0]); + $canvas->set_auto_bed_shape; + $canvas->SetSize([500,500]); + $canvas->SetMinSize($canvas->GetSize); + $canvas->zoom_to_volumes; + } + + $self->{sizer} = Wx::BoxSizer->new(wxHORIZONTAL); + $self->{sizer}->Add($left_sizer, 0, wxEXPAND | wxTOP | wxBOTTOM, 10); + $self->{sizer}->Add($canvas, 1, wxEXPAND | wxALL, 0) if $canvas; + + $self->SetSizer($self->{sizer}); + $self->SetMinSize($self->GetSize); + $self->{sizer}->SetSizeHints($self); + + EVT_BUTTON($self, $self->{btn_cut}, sub { + // Recalculate the cut if the preview was not active. + $self->_perform_cut() unless $self->{mesh_cut_valid}; + + // Adjust position / orientation of the split object halves. + if (my $lower = $self->{new_model_objects}[0]) { + if ($self->{cut_options}{rotate_lower} && $self->{cut_options}{axis} == Z) { + $lower->rotate(PI, X); + } + $lower->center_around_origin; # align to Z = 0 + } + if (my $upper = $self->{new_model_objects}[1]) { + $upper->center_around_origin; # align to Z = 0 + } + + // Note that the window was already closed, so a pending update will not be executed. + already_closed = true; + EndModal(wxID_OK); + Destroy(); + }); + + EVT_BUTTON($self, $self->{btn_cut_grid}, sub { + my $grid_x = Wx::GetTextFromUser("Enter the width of the desired tiles along the X axis:", + "Cut by Grid", 100, $self); + return if !looks_like_number($grid_x) || $grid_x <= 0; + + my $grid_y = Wx::GetTextFromUser("Enter the width of the desired tiles along the Y axis:", + "Cut by Grid", 100, $self); + return if !looks_like_number($grid_y) || $grid_y <= 0; + + my $process_dialog = Wx::ProgressDialog->new('Cutting…', "Cutting model by grid…", 100, $self, 0); + $process_dialog->Pulse; + + my $meshes = $self->{model_object}->mesh->cut_by_grid(Slic3r::Pointf->new($grid_x, $grid_y)); + $self->{new_model_objects} = []; + + my $bb = $self->{model_object}->bounding_box; + $self->{new_model} = my $model = Slic3r::Model->new; + for my $i (0..$#$meshes) { + push @{$self->{new_model_objects}}, my $o = $model->add_object( + name => sprintf('%s (%d)', $self->{model_object}->name, $i+1), + ); + my $v = $o->add_volume( + mesh => $meshes->[$i], + name => $o->name, + ); + $o->center_around_origin; + my $i = $o->add_instance( + offset => Slic3r::Pointf->new(@{$o->origin_translation->negative}[X,Y]), + ); + $i->offset->translate( + 5 * ceil(($i->offset->x - $bb->center->x) / $grid_x), + 5 * ceil(($i->offset->y - $bb->center->y) / $grid_y), + ); + } + + $process_dialog->Destroy; + + # Note that the window was already closed, so a pending update will not be executed. + $self->{already_closed} = 1; + $self->EndModal(wxID_OK); + $self->Destroy(); + }); + + EVT_CLOSE($self, sub { + # Note that the window was already closed, so a pending update will not be executed. + already_closed = true; + EndModal(wxID_CANCEL); + Destroy(); + }); +*/ + _update(); + +} + +// scale Z down to original size since we're using the transformed mesh for 3D preview +// and cut dialog but ModelObject::cut() needs Z without any instance transformation +void ObjectCutDialog::_mesh_slice_z_pos(){ +/* + my $bb = $self->{model_object}->instance_bounding_box(0); + my $z = $self->{cut_options}{axis} == X ? $bb->x_min + : $self->{cut_options}{axis} == Y ? $bb->y_min + : $bb->z_min; + + $z += $self->{cut_options}{z} / $self->{model_object}->instances->[0]->scaling_factor; + + return $z; +*/ +} + +// Only perform live preview if just a single part of the object shall survive. +void ObjectCutDialog::_life_preview_active() { + /* + return $self->{cut_options}{preview} && ($self->{cut_options}{keep_upper} != $self->{cut_options}{keep_lower}); + */ +} + +// Slice the mesh, keep the top / bottom part. +void ObjectCutDialog::_perform_cut(){ + + + // Early exit. If the cut is valid, don't recalculate it. + if (mesh_cut_valid) return; + +/* + my $z = $self->_mesh_slice_z_pos(); + + my ($new_model) = $self->{model_object}->cut($self->{cut_options}{axis}, $z); + my ($upper_object, $lower_object) = @{$new_model->objects}; + $self->{new_model} = $new_model; + $self->{new_model_objects} = []; + if ($self->{cut_options}{keep_upper} && $upper_object->volumes_count > 0) { + $self->{new_model_objects}[1] = $upper_object; + } + if ($self->{cut_options}{keep_lower} && $lower_object->volumes_count > 0) { + $self->{new_model_objects}[0] = $lower_object; + } +*/ + mesh_cut_valid = true; +} + +void ObjectCutDialog::_update() { + + // Don't update if the window was already closed. + // We are not sure whether the action planned by wxTheApp->CallAfter() may be triggered after the window is closed. + // Probably not, but better be safe than sorry, which is espetially true on multiple platforms. + if (already_closed) return; +/* + # Only recalculate the cut, if the live cut preview is active. + my $life_preview_active = $self->_life_preview_active(); + $self->_perform_cut() if $life_preview_active; + + { + # scale Z down to original size since we're using the transformed mesh for 3D preview + # and cut dialog but ModelObject::cut() needs Z without any instance transformation + my $z = $self->_mesh_slice_z_pos(); + + # update canvas + if ($self->{canvas}) { + # get volumes to render + my @objects = (); + if ($life_preview_active) { + push @objects, grep defined, @{$self->{new_model_objects}}; + } else { + push @objects, $self->{model_object}; + } + + # get section contour + my @expolygons = (); + foreach my $volume (@{$self->{model_object}->volumes}) { + next if !$volume->mesh; + next if $volume->modifier; + my $expp = $volume->mesh->slice_at($self->{cut_options}{axis}, $z); + push @expolygons, @$expp; + } + + my $offset = $self->{model_object}->instances->[0]->offset; + foreach my $expolygon (@expolygons) { + $self->{model_object}->instances->[0]->transform_polygon($_) + for @$expolygon; + + if ($self->{cut_options}{axis} != X) { + $expolygon->translate(0, Slic3r::Geometry::scale($offset->y)); #) + } + if ($self->{cut_options}{axis} != Y) { + $expolygon->translate(Slic3r::Geometry::scale($offset->x), 0); + } + } + + $self->{canvas}->reset_objects; + $self->{canvas}->load_object($_, undef, [0]) for @objects; + + my $plane_z = $self->{cut_options}{z}; + $plane_z += 0.02 if !$self->{cut_options}{keep_upper}; + $plane_z -= 0.02 if !$self->{cut_options}{keep_lower}; + $self->{canvas}->SetCuttingPlane( + $self->{cut_options}{axis}, + $plane_z, + [@expolygons], + ); + $self->{canvas}->Render; + } + } + + # update controls + { + my $z = $self->{cut_options}{z}; + my $optgroup = $self->{optgroup}; + { + my $bb = $self->{model_object}->instance_bounding_box(0); + my $max = $self->{cut_options}{axis} == X ? $bb->size->x + : $self->{cut_options}{axis} == Y ? $bb->size->y ### + : $bb->size->z; + $optgroup->get_field('z')->set_range(0, $max); + } + $optgroup->get_field('keep_upper')->toggle(my $have_upper = abs($z - $optgroup->get_option('z')->max) > 0.1); + $optgroup->get_field('keep_lower')->toggle(my $have_lower = $z > 0.1); + $optgroup->get_field('rotate_lower')->toggle($z > 0 && $self->{cut_options}{keep_lower} && $self->{cut_options}{axis} == Z); + $optgroup->get_field('preview')->toggle($self->{cut_options}{keep_upper} != $self->{cut_options}{keep_lower}); + + # update cut button + if (($self->{cut_options}{keep_upper} && $have_upper) + || ($self->{cut_options}{keep_lower} && $have_lower)) { + $self->{btn_cut}->Enable; + } else { + $self->{btn_cut}->Disable; + } + } +*/ +} + +void ObjectCutDialog::NewModelObjects() { +/* + my ($self) = @_; + return grep defined, @{ $self->{new_model_objects} }; +*/ +} + +}} // namespace Slic3r::GUI diff --git a/src/GUI/Dialogs/ObjectCutDialog.hpp b/src/GUI/Dialogs/ObjectCutDialog.hpp new file mode 100644 index 000000000..f87cc66ef --- /dev/null +++ b/src/GUI/Dialogs/ObjectCutDialog.hpp @@ -0,0 +1,51 @@ +#ifndef OBJECTCUTDIALOG_HPP +#define OBJECTCUTDIALOG_HPP + + +#include + +#include "Scene3D.hpp" +#include "Model.hpp" + +namespace Slic3r { namespace GUI { + +class ObjectCutCanvas : public Scene3D { + // Not sure yet + +protected: + // Draws the cutting plane + void after_render(); +}; + +struct CutOptions { + float z; + enum {X,Y,Z} axis; + bool keep_upper, keep_lower, rotate_lower; + bool preview; +}; + +class ObjectCutDialog : public wxDialog { +public: + ObjectCutDialog(wxWindow* parent, ModelObject* _model); +private: + // Mark whether the mesh cut is valid. + // If not, it needs to be recalculated by _update() on wxTheApp->CallAfter() or on exit of the dialog. + bool mesh_cut_valid = false; + // Note whether the window was already closed, so a pending update is not executed. + bool already_closed = false; + +// ObjectCutCanvas canvas; + ModelObject* model_object; + + //std::shared_ptr model; + + void _mesh_slice_z_pos(); + void _life_preview_active(); + void _perform_cut(); + void _update(); + void NewModelObjects(); + +}; + +}} // namespace Slic3r::GUI +#endif // OBJECTCUTDIALOG_HPP diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index f72a70b96..cfad2149b 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -13,6 +13,7 @@ #include "BoundingBox.hpp" #include "Geometry.hpp" #include "Dialogs/AnglePicker.hpp" +#include "Dialogs/ObjectCutDialog.hpp" namespace Slic3r { namespace GUI { @@ -888,6 +889,13 @@ void Plater::changescale() { void Plater::object_cut_dialog() { //TODO + ObjRef obj {this->selected_object()}; + if (obj == this->objects.end()) return; + + auto* model_object {this->model->objects.at(obj->identifier)}; + auto cut_dialog = new ObjectCutDialog(nullptr, model_object); + cut_dialog->ShowModal(); + cut_dialog->Destroy(); } void Plater::object_layers_dialog() { From c1d71bd520ddcaf885e9eabb6633c41c7d9c56b3 Mon Sep 17 00:00:00 2001 From: Benjamin Landers Date: Tue, 10 Jul 2018 14:08:17 -0700 Subject: [PATCH 305/305] First steps for Preview3d This is now blocking on the slicing pipeline being set up to test --- src/CMakeLists.txt | 1 + src/GUI/Plater.cpp | 2 +- src/GUI/Plater/3DPreview.pm | 171 +++++++++++++++++++++++++++++++++++ src/GUI/Plater/Preview3D.cpp | 145 +++++++++++++++++++++++++++++ src/GUI/Plater/Preview3D.hpp | 26 +++++- 5 files changed, 339 insertions(+), 6 deletions(-) create mode 100644 src/GUI/Plater/3DPreview.pm create mode 100644 src/GUI/Plater/Preview3D.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6767d1a25..5dd58eaa2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -253,6 +253,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/Scene3D.cpp ${GUI_LIBDIR}/Plater/Plate2D.cpp ${GUI_LIBDIR}/Plater/Plate3D.cpp + ${GUI_LIBDIR}/Plater/Preview3D.cpp ${GUI_LIBDIR}/Plater/PlaterObject.cpp ${GUI_LIBDIR}/ProgressStatusBar.cpp ${GUI_LIBDIR}/Settings.cpp diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index cfad2149b..ca5ad6fa1 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -92,7 +92,7 @@ Plater::Plater(wxWindow* parent, const wxString& title) : canvas3D->on_select_object = std::function(on_select_object); canvas3D->on_instances_moved = std::function(on_instances_moved); - preview3D = new Preview3D(preview_notebook, wxDefaultSize, objects, model, config); + preview3D = new Preview3D(preview_notebook, wxDefaultSize, print, objects, model, config); preview_notebook->AddPage(preview3D, _("Preview")); preview2D = new Preview2D(preview_notebook, wxDefaultSize, objects, model, config); diff --git a/src/GUI/Plater/3DPreview.pm b/src/GUI/Plater/3DPreview.pm new file mode 100644 index 000000000..c4f9e6c5e --- /dev/null +++ b/src/GUI/Plater/3DPreview.pm @@ -0,0 +1,171 @@ +package Slic3r::GUI::Plater::3DPreview; +use strict; +use warnings; +use utf8; + +use Slic3r::Print::State ':steps'; +use Wx qw(:misc :sizer :slider :statictext); +use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN); +use base qw(Wx::Panel Class::Accessor); + +__PACKAGE__->mk_accessors(qw(print enabled _loaded canvas slider)); + +sub new { + my $class = shift; + my ($parent, $print) = @_; + + my $self = $class->SUPER::new($parent, -1, wxDefaultPosition); + + # init GUI elements + my $canvas = Slic3r::GUI::3DScene->new($self); + $self->canvas($canvas); + my $slider = Wx::Slider->new( + $self, -1, + 0, # default + 0, # min + # we set max to a bogus non-zero value because the MSW implementation of wxSlider + # will skip drawing the slider if max <= min: + 1, # max + wxDefaultPosition, + wxDefaultSize, + wxVERTICAL | wxSL_INVERSE, + ); + $self->slider($slider); + + my $z_label = $self->{z_label} = Wx::StaticText->new($self, -1, "", wxDefaultPosition, + [40,-1], wxALIGN_CENTRE_HORIZONTAL); + $z_label->SetFont($Slic3r::GUI::small_font); + + my $vsizer = Wx::BoxSizer->new(wxVERTICAL); + $vsizer->Add($slider, 1, wxALL | wxEXPAND | wxALIGN_CENTER, 3); + $vsizer->Add($z_label, 0, wxALL | wxEXPAND | wxALIGN_CENTER, 3); + + my $sizer = Wx::BoxSizer->new(wxHORIZONTAL); + $sizer->Add($canvas, 1, wxALL | wxEXPAND, 0); + $sizer->Add($vsizer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5); + + EVT_SLIDER($self, $slider, sub { + $self->set_z($self->{layers_z}[$slider->GetValue]) + if $self->enabled; + }); + EVT_KEY_DOWN($canvas, sub { + my ($s, $event) = @_; + + my $key = $event->GetKeyCode; + if ($key == 85 || $key == 315) { + $slider->SetValue($slider->GetValue + 1); + $self->set_z($self->{layers_z}[$slider->GetValue]); + } elsif ($key == 68 || $key == 317) { + $slider->SetValue($slider->GetValue - 1); + $self->set_z($self->{layers_z}[$slider->GetValue]); + } else { + $event->Skip; + } + }); + + $self->SetSizer($sizer); + $self->SetMinSize($self->GetSize); + $sizer->SetSizeHints($self); + + # init canvas + $self->print($print); + $self->reload_print; + + return $self; +} + +sub reload_print { + my ($self, $obj_idx) = @_; + + $self->canvas->reset_objects; + $self->_loaded(0); + $self->load_print($obj_idx); +} + +sub load_print { + my ($self, $obj_idx) = @_; + + return if $self->_loaded; + + # we require that there's at least one object and the posSlice step + # is performed on all of them (this ensures that _shifted_copies was + # populated and we know the number of layers) + if (!$self->print->object_step_done(STEP_SLICE)) { + $self->enabled(0); + $self->slider->Hide; + $self->canvas->Refresh; # clears canvas + return; + } + + my $z_idx; + { + my %z = (); # z => 1 + if(defined $obj_idx) { # Load only given object + foreach my $layer (@{$self->{print}->get_object($obj_idx)->layers}) { + $z{$layer->print_z} = 1; + } + }else{ # Load all objects on the plater + support material + foreach my $object (@{$self->{print}->objects}) { + foreach my $layer (@{$object->layers}, @{$object->support_layers}) { + $z{$layer->print_z} = 1; + } + } + } + $self->enabled(1); + $self->{layers_z} = [ sort { $a <=> $b } keys %z ]; + $self->slider->SetRange(0, scalar(@{$self->{layers_z}})-1); + if (($z_idx = $self->slider->GetValue) <= $#{$self->{layers_z}} && $self->slider->GetValue != 0) { + # use $z_idx + } else { + $self->slider->SetValue(scalar(@{$self->{layers_z}})-1); + $z_idx = @{$self->{layers_z}} ? -1 : undef; + } + $self->slider->Show; + $self->Layout; + } + + if ($self->IsShown) { + # set colors + $self->canvas->color_toolpaths_by($Slic3r::GUI::Settings->{_}{color_toolpaths_by}); + if ($self->canvas->color_toolpaths_by eq 'extruder') { + my @filament_colors = map { s/^#//; [ map $_/255, (unpack 'C*', pack 'H*', $_), 255 ] } + @{$self->print->config->filament_colour}; + $self->canvas->colors->[$_] = $filament_colors[$_] for 0..$#filament_colors; + } else { + $self->canvas->colors([ $self->canvas->default_colors ]); + } + + if(defined $obj_idx) { # Load only one object + $self->canvas->load_print_object_toolpaths($self->{print}->get_object($obj_idx)); + }else{ # load all objects + # load skirt and brim + $self->canvas->load_print_toolpaths($self->print); + + foreach my $object (@{$self->print->objects}) { + $self->canvas->load_print_object_toolpaths($object); + + #my @volume_ids = $self->canvas->load_object($object->model_object); + #$self->canvas->volumes->[$_]->color->[3] = 0.2 for @volume_ids; + } + } + $self->_loaded(1); + } + + $self->set_z($self->{layers_z}[$z_idx]); +} + +sub set_z { + my ($self, $z) = @_; + + return if !$self->enabled; + $self->{z_label}->SetLabel(sprintf '%.2f', $z); + $self->canvas->set_toolpaths_range(0, $z); + $self->canvas->Refresh if $self->IsShown; +} + +sub set_bed_shape { + my ($self, $bed_shape) = @_; + $self->canvas->set_bed_shape($bed_shape); +} + +1; diff --git a/src/GUI/Plater/Preview3D.cpp b/src/GUI/Plater/Preview3D.cpp new file mode 100644 index 000000000..139f521fb --- /dev/null +++ b/src/GUI/Plater/Preview3D.cpp @@ -0,0 +1,145 @@ +#include "Preview3D.hpp" +#include + +namespace Slic3r { namespace GUI { + +Preview3D::Preview3D(wxWindow* parent, const wxSize& size, std::shared_ptr _print, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), print(_print), objects(_objects), model(_model), config(_config), canvas(this,size) +{ + + // init GUI elements + slider = new wxSlider( + this, -1, + 0, // default + 0, // min + // we set max to a bogus non-zero value because the MSW implementation of wxSlider + // will skip drawing the slider if max <= min: + 1, // max + wxDefaultPosition, + wxDefaultSize, + wxVERTICAL | wxSL_INVERSE + ); + + this->z_label = new wxStaticText(this, -1, "", wxDefaultPosition, + wxSize(40,-1), wxALIGN_CENTRE_HORIZONTAL); + //z_label->SetFont(Slic3r::GUI::small_font); + + auto* vsizer = new wxBoxSizer(wxVERTICAL); + vsizer->Add(slider, 1, wxALL | wxEXPAND | wxALIGN_CENTER, 3); + vsizer->Add(z_label, 0, wxALL | wxEXPAND | wxALIGN_CENTER, 3); + + auto* sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(&canvas, 1, wxALL | wxEXPAND, 0); + sizer->Add(vsizer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5); + + this->Bind(wxEVT_SLIDER, [this](wxCommandEvent &e){ + //$self->set_z($self->{layers_z}[$slider->GetValue]) + // if $self->enabled; + }); + this->Bind(wxEVT_CHAR, [this](wxKeyEvent &e) { + /*my ($s, $event) = @_; + + my $key = $event->GetKeyCode; + if ($key == 85 || $key == 315) { + $slider->SetValue($slider->GetValue + 1); + $self->set_z($self->{layers_z}[$slider->GetValue]); + } elsif ($key == 68 || $key == 317) { + $slider->SetValue($slider->GetValue - 1); + $self->set_z($self->{layers_z}[$slider->GetValue]); + } else { + $event->Skip; + }*/ + }); + + SetSizer(sizer); + SetMinSize(GetSize()); + sizer->SetSizeHints(this); + + // init canvas + reload_print(); + +} +void Preview3D::reload_print(){ + + canvas.resetObjects(); + loaded = false; + load_print(); +} + +void Preview3D::load_print() { + if(loaded) return; + + // we require that there's at least one object and the posSlice step + // is performed on all of them (this ensures that _shifted_copies was + // populated and we know the number of layers) + if(!print->step_done(posSlice)) { + _enabled = false; + slider->Hide(); + canvas.Refresh(); // clears canvas + return; + } + + size_t z_idx = 0; + { + layers_z.clear(); + // Load all objects on the plater + support material + for(auto* object : print->objects) { + for(auto layer : object->layers){ + layers_z.push_back(layer->print_z); + } + for(auto layer : object->support_layers) { + layers_z.push_back(layer->print_z); + } + } + + _enabled = true; + std::sort(layers_z.begin(),layers_z.end()); + slider->SetRange(0, layers_z.size()-1); + z_idx = slider->GetValue(); + // If invalide z_idx, move the slider to the top + if (z_idx >= layers_z.size() || slider->GetValue() == 0) { + slider->SetValue(layers_z.size()-1); + //$z_idx = @{$self->{layer_z}} ? -1 : undef; + z_idx = slider->GetValue(); // not sure why the perl version makes z_idx invalid + } + slider->Show(); + Layout(); + } + if (IsShown()) { + // set colors + /*canvas.color_toolpaths_by($Slic3r::GUI::Settings->{_}{color_toolpaths_by}); + if ($self->canvas->color_toolpaths_by eq 'extruder') { + my @filament_colors = map { s/^#//; [ map $_/255, (unpack 'C*', pack 'H*', $_), 255 ] } + @{$self->print->config->filament_colour}; + $self->canvas->colors->[$_] = $filament_colors[$_] for 0..$#filament_colors; + } else { + $self->canvas->colors([ $self->canvas->default_colors ]); + }*/ + + // load skirt and brim + //$self->canvas->load_print_toolpaths($self->print); + + /*foreach my $object (@{$self->print->objects}) { + canvas.load_print_object_toolpaths($object); + }*/ + loaded = true; + } + + set_z(layers_z.at(z_idx)); +} +void Preview3D::set_z(float z) { + if(!_enabled) return; + z_label->SetLabel(std::to_string(z)); + //canvas.set_toolpaths_range(0, $z); + if(IsShown())canvas.Refresh(); +} + +/* +void set_bed_shape() { + my ($self, $bed_shape) = @_; + $self->canvas->set_bed_shape($bed_shape); +} +*/ + +} } // Namespace Slic3r::GUI + diff --git a/src/GUI/Plater/Preview3D.hpp b/src/GUI/Plater/Preview3D.hpp index d2ec12b48..15af3e95b 100644 --- a/src/GUI/Plater/Preview3D.hpp +++ b/src/GUI/Plater/Preview3D.hpp @@ -5,20 +5,36 @@ #include #endif +#include "PlaterObject.hpp" +#include "Scene3D.hpp" #include "Model.hpp" #include "Config.hpp" +#include "Print.hpp" namespace Slic3r { namespace GUI { +class PreviewScene3D : public Scene3D { +public: + PreviewScene3D(wxWindow* parent, const wxSize& size) : Scene3D(parent,size){} + // TODO: load_print_toolpaths(Print); + // TODO: load_print_object_toolpaths(PrintObject); + void resetObjects(){volumes.clear();} +}; + class Preview3D : public wxPanel { public: - void reload_print() {}; - Preview3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) - {} - + void reload_print(); + Preview3D(wxWindow* parent, const wxSize& size, std::shared_ptr _print, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config); void enabled(bool enable = true) {} private: + void load_print(); + void set_z(float z); + bool loaded = false, _enabled = false; + std::vector layers_z; + std::shared_ptr print; + PreviewScene3D canvas; + wxSlider* slider; + wxStaticText* z_label; std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config;