2015-12-04 20:25:45 +00:00
|
|
|
#include "GUI.hpp"
|
2018-09-19 16:02:04 +00:00
|
|
|
#include "../AppController.hpp"
|
2018-03-27 11:44:18 +00:00
|
|
|
#include "WipeTowerDialog.hpp"
|
2015-12-04 20:25:45 +00:00
|
|
|
|
2017-11-02 15:21:34 +00:00
|
|
|
#include <assert.h>
|
2018-04-09 12:41:55 +00:00
|
|
|
#include <cmath>
|
2017-11-02 15:21:34 +00:00
|
|
|
|
2018-01-07 17:41:40 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2018-05-21 20:10:38 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2018-02-07 10:37:15 +00:00
|
|
|
#include <boost/format.hpp>
|
2018-09-17 13:12:13 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2018-02-02 11:38:35 +00:00
|
|
|
|
2015-12-04 20:25:45 +00:00
|
|
|
#if __APPLE__
|
|
|
|
#import <IOKit/pwr_mgt/IOPMLib.h>
|
|
|
|
#elif _WIN32
|
|
|
|
#include <Windows.h>
|
2017-12-13 13:45:10 +00:00
|
|
|
// Undefine min/max macros incompatible with the standard library
|
|
|
|
// For example, std::numeric_limits<std::streamsize>::max()
|
|
|
|
// produces some weird errors
|
|
|
|
#ifdef min
|
|
|
|
#undef min
|
|
|
|
#endif
|
|
|
|
#ifdef max
|
|
|
|
#undef max
|
|
|
|
#endif
|
2017-11-02 15:21:34 +00:00
|
|
|
#include "boost/nowide/convert.hpp"
|
2015-12-04 20:25:45 +00:00
|
|
|
#endif
|
|
|
|
|
2017-12-04 09:48:40 +00:00
|
|
|
#include <wx/app.h>
|
|
|
|
#include <wx/button.h>
|
2018-02-15 17:13:37 +00:00
|
|
|
#include <wx/dir.h>
|
|
|
|
#include <wx/filename.h>
|
2017-12-04 09:48:40 +00:00
|
|
|
#include <wx/frame.h>
|
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/notebook.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
2018-02-02 11:38:35 +00:00
|
|
|
#include <wx/combo.h>
|
2017-12-13 13:45:10 +00:00
|
|
|
#include <wx/window.h>
|
2018-04-16 14:52:11 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2018-04-09 12:41:55 +00:00
|
|
|
#include <wx/settings.h>
|
2018-06-11 16:24:13 +00:00
|
|
|
#include <wx/display.h>
|
2018-04-25 11:25:34 +00:00
|
|
|
#include <wx/collpane.h>
|
|
|
|
#include <wx/wupdlock.h>
|
2018-02-02 11:38:35 +00:00
|
|
|
|
2018-02-02 12:56:25 +00:00
|
|
|
#include "wxExtensions.hpp"
|
2017-12-04 09:48:40 +00:00
|
|
|
|
2018-01-23 10:42:04 +00:00
|
|
|
#include "Tab.hpp"
|
2018-01-23 10:37:19 +00:00
|
|
|
#include "TabIface.hpp"
|
2018-09-18 11:35:05 +00:00
|
|
|
#include "GUI_Preview.hpp"
|
|
|
|
#include "GUI_PreviewIface.hpp"
|
2018-04-09 15:03:37 +00:00
|
|
|
#include "AboutDialog.hpp"
|
2018-01-05 14:11:33 +00:00
|
|
|
#include "AppConfig.hpp"
|
2018-04-10 14:27:42 +00:00
|
|
|
#include "ConfigSnapshotDialog.hpp"
|
2018-09-12 11:17:47 +00:00
|
|
|
#include "ProgressStatusBar.hpp"
|
2018-02-08 09:58:13 +00:00
|
|
|
#include "Utils.hpp"
|
2018-04-30 12:31:57 +00:00
|
|
|
#include "MsgDialog.hpp"
|
2018-03-13 11:39:57 +00:00
|
|
|
#include "ConfigWizard.hpp"
|
2018-02-22 10:12:29 +00:00
|
|
|
#include "Preferences.hpp"
|
2018-03-09 16:17:51 +00:00
|
|
|
#include "PresetBundle.hpp"
|
2018-04-27 10:29:18 +00:00
|
|
|
#include "UpdateDialogs.hpp"
|
2018-05-04 14:04:43 +00:00
|
|
|
#include "FirmwareDialog.hpp"
|
2018-06-13 14:39:33 +00:00
|
|
|
#include "GUI_ObjectParts.hpp"
|
2017-12-05 14:54:01 +00:00
|
|
|
|
2018-04-16 14:52:11 +00:00
|
|
|
#include "../Utils/PresetUpdater.hpp"
|
2018-04-10 14:27:42 +00:00
|
|
|
#include "../Config/Snapshot.hpp"
|
2018-07-17 06:54:17 +00:00
|
|
|
|
2018-06-22 10:27:56 +00:00
|
|
|
#include "3DScene.hpp"
|
2018-06-20 16:33:46 +00:00
|
|
|
#include "libslic3r/I18N.hpp"
|
2018-06-14 13:33:42 +00:00
|
|
|
#include "Model.hpp"
|
2018-06-14 19:48:06 +00:00
|
|
|
#include "LambdaObjectDialog.hpp"
|
2017-12-05 14:54:01 +00:00
|
|
|
|
2018-03-23 10:41:20 +00:00
|
|
|
#include "../../libslic3r/Print.hpp"
|
|
|
|
|
2015-12-04 20:25:45 +00:00
|
|
|
namespace Slic3r { namespace GUI {
|
|
|
|
|
2015-12-05 10:48:24 +00:00
|
|
|
#if __APPLE__
|
2015-12-04 20:25:45 +00:00
|
|
|
IOPMAssertionID assertionID;
|
2015-12-05 10:48:24 +00:00
|
|
|
#endif
|
2015-12-04 20:25:45 +00:00
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
void disable_screensaver()
|
2015-12-04 20:25:45 +00:00
|
|
|
{
|
|
|
|
#if __APPLE__
|
|
|
|
CFStringRef reasonForActivity = CFSTR("Slic3r");
|
|
|
|
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
|
|
|
|
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
|
|
|
|
// ignore result: success == kIOReturnSuccess
|
|
|
|
#elif _WIN32
|
2015-12-06 10:17:50 +00:00
|
|
|
SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_CONTINUOUS);
|
2015-12-04 20:25:45 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
void enable_screensaver()
|
2015-12-04 20:25:45 +00:00
|
|
|
{
|
|
|
|
#if __APPLE__
|
|
|
|
IOReturn success = IOPMAssertionRelease(assertionID);
|
|
|
|
#elif _WIN32
|
2015-12-06 10:17:50 +00:00
|
|
|
SetThreadExecutionState(ES_CONTINUOUS);
|
2015-12-04 20:25:45 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
bool debugged()
|
2016-04-13 18:45:44 +00:00
|
|
|
{
|
2016-04-13 18:51:03 +00:00
|
|
|
#ifdef _WIN32
|
2016-04-13 18:45:44 +00:00
|
|
|
return IsDebuggerPresent();
|
2016-04-13 18:51:03 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif /* _WIN32 */
|
2016-04-13 18:45:44 +00:00
|
|
|
}
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
void break_to_debugger()
|
2016-04-13 18:45:44 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (IsDebuggerPresent())
|
|
|
|
DebugBreak();
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:33:41 +00:00
|
|
|
// #ys_FIXME_for_delete
|
2018-02-09 10:04:34 +00:00
|
|
|
std::vector<Tab *> g_tabs_list;
|
|
|
|
|
2018-05-17 08:46:32 +00:00
|
|
|
//showed/hided controls according to the view mode
|
2018-05-21 12:49:31 +00:00
|
|
|
wxWindow *g_right_panel = nullptr;
|
2018-05-17 08:46:32 +00:00
|
|
|
wxBoxSizer *g_frequently_changed_parameters_sizer = nullptr;
|
2018-09-17 13:12:13 +00:00
|
|
|
wxBoxSizer *g_info_sizer = nullptr;
|
2018-07-04 10:38:34 +00:00
|
|
|
wxBoxSizer *g_object_list_sizer = nullptr;
|
2018-09-17 13:12:13 +00:00
|
|
|
std::vector<wxButton*> g_buttons;
|
2018-05-18 09:39:49 +00:00
|
|
|
wxStaticBitmap *g_manifold_warning_icon = nullptr;
|
2018-05-17 12:07:50 +00:00
|
|
|
bool g_show_print_info = false;
|
2018-05-18 09:39:49 +00:00
|
|
|
bool g_show_manifold_warning_icon = false;
|
2018-05-17 08:46:32 +00:00
|
|
|
|
2018-09-19 06:59:11 +00:00
|
|
|
PreviewIface* g_preview = nullptr;
|
2018-09-18 11:35:05 +00:00
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
enum ActionButtons
|
2018-06-22 10:27:56 +00:00
|
|
|
{
|
2018-09-17 13:12:13 +00:00
|
|
|
abExportGCode,
|
|
|
|
abReslice,
|
|
|
|
abPrint,
|
|
|
|
abSendGCode,
|
|
|
|
};
|
2018-06-22 10:27:56 +00:00
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
void set_objects_from_perl( wxWindow* parent,
|
|
|
|
wxBoxSizer *frequently_changed_parameters_sizer,
|
|
|
|
wxBoxSizer *info_sizer,
|
2018-05-27 20:12:01 +00:00
|
|
|
wxButton *btn_export_gcode,
|
2018-09-17 13:12:13 +00:00
|
|
|
wxButton *btn_reslice,
|
|
|
|
wxButton *btn_print,
|
|
|
|
wxButton *btn_send_gcode,
|
2018-05-18 09:39:49 +00:00
|
|
|
wxStaticBitmap *manifold_warning_icon)
|
2018-05-17 08:46:32 +00:00
|
|
|
{
|
2018-09-17 13:12:13 +00:00
|
|
|
g_right_panel = parent->GetParent();
|
2018-05-17 08:46:32 +00:00
|
|
|
g_frequently_changed_parameters_sizer = frequently_changed_parameters_sizer;
|
2018-09-17 13:12:13 +00:00
|
|
|
g_info_sizer = info_sizer;
|
|
|
|
|
|
|
|
g_buttons.push_back(btn_export_gcode);
|
|
|
|
g_buttons.push_back(btn_reslice);
|
|
|
|
g_buttons.push_back(btn_print);
|
|
|
|
g_buttons.push_back(btn_send_gcode);
|
|
|
|
|
|
|
|
// Update font style for buttons
|
2018-10-01 13:09:31 +00:00
|
|
|
// for (auto btn : g_buttons)
|
|
|
|
// btn->SetFont(bold_font());
|
2018-09-17 13:12:13 +00:00
|
|
|
|
2018-05-18 09:39:49 +00:00
|
|
|
g_manifold_warning_icon = manifold_warning_icon;
|
2018-05-17 12:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_show_print_info(bool show)
|
|
|
|
{
|
|
|
|
g_show_print_info = show;
|
2018-05-17 08:46:32 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 09:39:49 +00:00
|
|
|
void set_show_manifold_warning_icon(bool show)
|
|
|
|
{
|
|
|
|
g_show_manifold_warning_icon = show;
|
2018-09-17 13:12:13 +00:00
|
|
|
if (!g_manifold_warning_icon)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// update manifold_warning_icon showing
|
|
|
|
if (show && !g_info_sizer->IsShown(static_cast<size_t>(0)))
|
|
|
|
g_show_manifold_warning_icon = false;
|
|
|
|
|
|
|
|
g_manifold_warning_icon->Show(g_show_manifold_warning_icon);
|
|
|
|
g_manifold_warning_icon->GetParent()->Layout();
|
2018-05-18 09:39:49 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 10:38:34 +00:00
|
|
|
void set_objects_list_sizer(wxBoxSizer *objects_list_sizer){
|
|
|
|
g_object_list_sizer = objects_list_sizer;
|
|
|
|
}
|
|
|
|
|
2018-06-14 13:33:42 +00:00
|
|
|
void open_model(wxWindow *parent, wxArrayString& input_files){
|
2018-09-20 11:12:35 +00:00
|
|
|
auto dialog = new wxFileDialog(parent /*? parent : GetTopWindow()*/,
|
2018-09-20 06:40:22 +00:00
|
|
|
_(L("Choose one or more files (STL/OBJ/AMF/3MF/PRUSA):")),
|
2018-10-02 11:23:38 +00:00
|
|
|
get_app_config()->get_last_dir(), "",
|
2018-06-13 14:39:33 +00:00
|
|
|
MODEL_WILDCARD, wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST);
|
|
|
|
if (dialog->ShowModal() != wxID_OK) {
|
|
|
|
dialog->Destroy();
|
2018-06-14 13:33:42 +00:00
|
|
|
return ;
|
2018-06-13 14:39:33 +00:00
|
|
|
}
|
2018-06-14 13:33:42 +00:00
|
|
|
|
2018-06-13 14:39:33 +00:00
|
|
|
dialog->GetPaths(input_files);
|
|
|
|
dialog->Destroy();
|
|
|
|
}
|
|
|
|
|
2018-04-24 16:06:42 +00:00
|
|
|
bool config_wizard_startup(bool app_config_exists)
|
2018-04-16 14:52:11 +00:00
|
|
|
{
|
2018-10-02 11:23:38 +00:00
|
|
|
if (!app_config_exists || wxGetApp().preset_bundle->printers.size() <= 1) {
|
2018-04-24 16:06:42 +00:00
|
|
|
config_wizard(ConfigWizard::RR_DATA_EMPTY);
|
|
|
|
return true;
|
2018-10-02 11:23:38 +00:00
|
|
|
} else if (get_app_config()->legacy_datadir()) {
|
2018-04-16 14:52:11 +00:00
|
|
|
// Looks like user has legacy pre-vendorbundle data directory,
|
|
|
|
// explain what this is and run the wizard
|
|
|
|
|
2018-04-27 10:29:18 +00:00
|
|
|
MsgDataLegacy dlg;
|
|
|
|
dlg.ShowModal();
|
2018-04-16 14:52:11 +00:00
|
|
|
|
2018-04-24 16:06:42 +00:00
|
|
|
config_wizard(ConfigWizard::RR_DATA_LEGACY);
|
|
|
|
return true;
|
2018-04-16 14:52:11 +00:00
|
|
|
}
|
2018-04-24 16:06:42 +00:00
|
|
|
return false;
|
2018-04-16 14:52:11 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 16:06:42 +00:00
|
|
|
void config_wizard(int reason)
|
2018-03-13 11:39:57 +00:00
|
|
|
{
|
2018-04-11 10:21:15 +00:00
|
|
|
// Exit wizard if there are unsaved changes and the user cancels the action.
|
2018-10-01 13:09:31 +00:00
|
|
|
if (! wxGetApp().check_unsaved_changes())
|
2018-04-16 14:52:11 +00:00
|
|
|
return;
|
2018-04-11 10:21:15 +00:00
|
|
|
|
2018-06-04 07:07:29 +00:00
|
|
|
try {
|
|
|
|
ConfigWizard wizard(nullptr, static_cast<ConfigWizard::RunReason>(reason));
|
2018-10-02 11:23:38 +00:00
|
|
|
wizard.run(wxGetApp().preset_bundle, wxGetApp().preset_updater);
|
2018-06-04 07:07:29 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception &e) {
|
|
|
|
show_error(nullptr, e.what());
|
|
|
|
}
|
2018-04-11 10:21:15 +00:00
|
|
|
|
2018-06-06 08:52:19 +00:00
|
|
|
// Load the currently selected preset into the GUI, update the preset selection box.
|
2018-10-01 13:09:31 +00:00
|
|
|
wxGetApp().load_current_presets();
|
2017-12-04 09:48:40 +00:00
|
|
|
}
|
2018-10-01 13:09:31 +00:00
|
|
|
// #ys_FIXME_for_delete
|
2018-08-08 14:22:56 +00:00
|
|
|
std::vector<PresetTab> preset_tabs = {
|
|
|
|
{ "print", nullptr, ptFFF },
|
|
|
|
{ "filament", nullptr, ptFFF },
|
|
|
|
{ "sla_material", nullptr, ptSLA }
|
|
|
|
};
|
2018-09-20 23:33:41 +00:00
|
|
|
std::vector<PresetTab>* get_preset_tabs() {
|
|
|
|
return &preset_tabs;
|
2018-08-08 14:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Tab* get_tab(const std::string& name)
|
|
|
|
{
|
|
|
|
std::vector<PresetTab>::iterator it = std::find_if(preset_tabs.begin(), preset_tabs.end(),
|
|
|
|
[name](PresetTab& tab){ return name == tab.name; });
|
|
|
|
return it != preset_tabs.end() ? it->panel : nullptr;
|
2017-12-22 10:50:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 10:37:19 +00:00
|
|
|
TabIface* get_preset_tab_iface(char *name)
|
|
|
|
{
|
2018-08-08 14:22:56 +00:00
|
|
|
Tab* tab = get_tab(name);
|
|
|
|
if (tab) return new TabIface(tab);
|
|
|
|
|
2018-10-02 11:23:38 +00:00
|
|
|
for (size_t i = 0; i < wxGetApp().tab_panel()->GetPageCount(); ++i) {
|
|
|
|
Tab *tab = dynamic_cast<Tab*>(wxGetApp().tab_panel()->GetPage(i));
|
2018-01-23 10:37:19 +00:00
|
|
|
if (! tab)
|
|
|
|
continue;
|
2018-01-25 20:44:22 +00:00
|
|
|
if (tab->name() == name) {
|
2018-01-23 10:37:19 +00:00
|
|
|
return new TabIface(tab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new TabIface(nullptr);
|
|
|
|
}
|
|
|
|
|
2018-09-18 11:35:05 +00:00
|
|
|
PreviewIface* create_preview_iface(wxNotebook* parent, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data)
|
|
|
|
{
|
|
|
|
if (g_preview == nullptr)
|
|
|
|
{
|
|
|
|
Preview* panel = new Preview(parent, config, print, gcode_preview_data);
|
|
|
|
g_preview = new PreviewIface(panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_preview;
|
|
|
|
}
|
|
|
|
|
2018-02-15 16:30:33 +00:00
|
|
|
// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element)
|
2018-04-13 10:35:04 +00:00
|
|
|
void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/)
|
2018-01-07 17:41:40 +00:00
|
|
|
{
|
|
|
|
try{
|
|
|
|
switch (config.def()->get(opt_key)->type){
|
2018-01-09 12:52:01 +00:00
|
|
|
case coFloatOrPercent:{
|
2018-02-20 11:30:13 +00:00
|
|
|
std::string str = boost::any_cast<std::string>(value);
|
|
|
|
bool percent = false;
|
|
|
|
if (str.back() == '%'){
|
|
|
|
str.pop_back();
|
|
|
|
percent = true;
|
|
|
|
}
|
|
|
|
double val = stod(str);
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent));
|
2018-01-09 12:52:01 +00:00
|
|
|
break;}
|
2018-01-07 17:41:40 +00:00
|
|
|
case coPercent:
|
2018-01-11 09:33:17 +00:00
|
|
|
config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast<double>(value)));
|
2018-01-09 12:52:01 +00:00
|
|
|
break;
|
|
|
|
case coFloat:{
|
2018-01-07 17:41:40 +00:00
|
|
|
double& val = config.opt_float(opt_key);
|
2018-01-09 08:41:07 +00:00
|
|
|
val = boost::any_cast<double>(value);
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-26 08:57:08 +00:00
|
|
|
case coPercents:{
|
|
|
|
ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast<double>(value) };
|
|
|
|
config.option<ConfigOptionPercents>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
2018-01-09 12:52:01 +00:00
|
|
|
break;
|
2018-02-26 08:57:08 +00:00
|
|
|
}
|
|
|
|
case coFloats:{
|
|
|
|
ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast<double>(value) };
|
|
|
|
config.option<ConfigOptionFloats>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
|
|
|
break;
|
2018-01-09 12:52:01 +00:00
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
case coString:
|
2018-01-09 12:52:01 +00:00
|
|
|
config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast<std::string>(value)));
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
2018-01-12 11:41:13 +00:00
|
|
|
case coStrings:{
|
2018-04-13 10:35:04 +00:00
|
|
|
if (opt_key.compare("compatible_printers") == 0) {
|
|
|
|
config.option<ConfigOptionStrings>(opt_key)->values =
|
|
|
|
boost::any_cast<std::vector<std::string>>(value);
|
|
|
|
}
|
|
|
|
else if (config.def()->get(opt_key)->gui_flags.compare("serialized") == 0){
|
|
|
|
std::string str = boost::any_cast<std::string>(value);
|
|
|
|
if (str.back() == ';') str.pop_back();
|
|
|
|
// Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values.
|
|
|
|
// Currently used for the post_process config value only.
|
|
|
|
std::vector<std::string> values;
|
|
|
|
boost::split(values, str, boost::is_any_of(";"));
|
|
|
|
if (values.size() == 1 && values[0] == "")
|
2018-03-07 14:05:41 +00:00
|
|
|
break;
|
2018-03-23 16:27:43 +00:00
|
|
|
config.option<ConfigOptionStrings>(opt_key)->values = values;
|
2018-01-12 11:41:13 +00:00
|
|
|
}
|
|
|
|
else{
|
2018-01-25 12:46:04 +00:00
|
|
|
ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast<std::string>(value) };
|
2018-03-02 12:41:37 +00:00
|
|
|
config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, 0);
|
2018-01-12 11:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
|
|
|
case coBool:
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast<bool>(value)));
|
|
|
|
break;
|
2018-01-09 12:52:01 +00:00
|
|
|
case coBools:{
|
2018-03-09 16:17:51 +00:00
|
|
|
ConfigOptionBools* vec_new = new ConfigOptionBools{ (bool)boost::any_cast<unsigned char>(value) };
|
2018-03-02 12:41:37 +00:00
|
|
|
config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, 0);
|
2018-01-09 12:52:01 +00:00
|
|
|
break;}
|
2018-01-07 17:41:40 +00:00
|
|
|
case coInt:
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value)));
|
|
|
|
break;
|
2018-01-12 11:41:13 +00:00
|
|
|
case coInts:{
|
|
|
|
ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast<int>(value) };
|
2018-03-02 12:41:37 +00:00
|
|
|
config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, 0);
|
2018-01-12 11:41:13 +00:00
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
2018-01-11 09:33:17 +00:00
|
|
|
case coEnum:{
|
|
|
|
if (opt_key.compare("external_fill_pattern") == 0 ||
|
|
|
|
opt_key.compare("fill_pattern") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<InfillPattern>(boost::any_cast<InfillPattern>(value)));
|
|
|
|
else if (opt_key.compare("gcode_flavor") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<GCodeFlavor>(boost::any_cast<GCodeFlavor>(value)));
|
|
|
|
else if (opt_key.compare("support_material_pattern") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<SupportMaterialPattern>(boost::any_cast<SupportMaterialPattern>(value)));
|
|
|
|
else if (opt_key.compare("seam_position") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<SeamPosition>(boost::any_cast<SeamPosition>(value)));
|
2018-07-08 12:32:48 +00:00
|
|
|
else if (opt_key.compare("host_type") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<PrintHostType>(boost::any_cast<PrintHostType>(value)));
|
2018-01-11 09:33:17 +00:00
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
2018-01-30 11:10:12 +00:00
|
|
|
case coPoints:{
|
2018-03-23 16:27:43 +00:00
|
|
|
if (opt_key.compare("bed_shape") == 0){
|
2018-08-21 19:05:24 +00:00
|
|
|
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value);
|
2018-03-23 16:27:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-08-21 19:05:24 +00:00
|
|
|
ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast<Vec2d>(value) };
|
2018-03-08 10:58:06 +00:00
|
|
|
config.option<ConfigOptionPoints>(opt_key)->set_at(vec_new, opt_index, 0);
|
2018-01-30 11:10:12 +00:00
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
|
|
|
case coNone:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
2018-01-09 12:52:01 +00:00
|
|
|
int i = 0;//no reason, just experiment
|
2018-01-07 17:41:40 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-06 08:52:19 +00:00
|
|
|
|
2018-04-30 12:31:57 +00:00
|
|
|
void show_error(wxWindow* parent, const wxString& message) {
|
|
|
|
ErrorDialog msg(parent, message);
|
|
|
|
msg.ShowModal();
|
2017-12-22 10:50:28 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 12:31:57 +00:00
|
|
|
void show_error_id(int id, const std::string& message) {
|
|
|
|
auto *parent = id != 0 ? wxWindow::FindWindowById(id) : nullptr;
|
2018-05-22 12:33:11 +00:00
|
|
|
show_error(parent, wxString::FromUTF8(message.data()));
|
2017-12-22 10:50:28 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 10:35:04 +00:00
|
|
|
void show_info(wxWindow* parent, const wxString& message, const wxString& title){
|
2018-04-30 12:31:57 +00:00
|
|
|
wxMessageDialog msg_wingow(parent, message, title.empty() ? _(L("Notice")) : title, wxOK | wxICON_INFORMATION);
|
|
|
|
msg_wingow.ShowModal();
|
2017-12-04 09:48:40 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 10:35:04 +00:00
|
|
|
void warning_catcher(wxWindow* parent, const wxString& message){
|
2018-05-02 11:20:36 +00:00
|
|
|
if (message == "GLUquadricObjPtr | " + _(L("Attempt to free unreferenced scalar")) )
|
2018-02-22 10:12:29 +00:00
|
|
|
return;
|
2018-04-30 12:31:57 +00:00
|
|
|
wxMessageDialog msg(parent, message, _(L("Warning")), wxOK | wxICON_WARNING);
|
|
|
|
msg.ShowModal();
|
2018-02-22 10:12:29 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:41:20 +00:00
|
|
|
// Assign a Lambda to the print object to emit a wxWidgets Command with the provided ID
|
|
|
|
// to deliver a progress status message.
|
|
|
|
void set_print_callback_event(Print *print, int id)
|
|
|
|
{
|
|
|
|
print->set_status_callback([id](int percent, const std::string &message){
|
|
|
|
wxCommandEvent event(id);
|
|
|
|
event.SetInt(percent);
|
|
|
|
event.SetString(message);
|
2018-10-02 11:23:38 +00:00
|
|
|
wxQueueEvent(wxGetApp().mainframe, event.Clone());
|
2018-03-23 10:41:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:21:25 +00:00
|
|
|
wxWindow* get_right_panel(){
|
|
|
|
return g_right_panel;
|
2018-06-14 13:33:42 +00:00
|
|
|
}
|
2018-02-02 11:38:35 +00:00
|
|
|
void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value)
|
|
|
|
{
|
2018-02-06 11:43:25 +00:00
|
|
|
if (comboCtrl == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxCheckListBoxComboPopup* popup = new wxCheckListBoxComboPopup;
|
2018-02-02 11:38:35 +00:00
|
|
|
if (popup != nullptr)
|
|
|
|
{
|
2018-02-20 14:22:30 +00:00
|
|
|
// FIXME If the following line is removed, the combo box popup list will not react to mouse clicks.
|
|
|
|
// On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10.
|
|
|
|
comboCtrl->UseAltPopupWindow();
|
|
|
|
|
|
|
|
comboCtrl->EnablePopupAnimation(false);
|
2018-02-02 11:38:35 +00:00
|
|
|
comboCtrl->SetPopupControl(popup);
|
2018-02-28 14:39:20 +00:00
|
|
|
popup->SetStringValue(from_u8(text));
|
2018-02-20 10:40:15 +00:00
|
|
|
popup->Bind(wxEVT_CHECKLISTBOX, [popup](wxCommandEvent& evt) { popup->OnCheckListBox(evt); });
|
|
|
|
popup->Bind(wxEVT_LISTBOX, [popup](wxCommandEvent& evt) { popup->OnListBoxSelection(evt); });
|
2018-02-20 13:25:40 +00:00
|
|
|
popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); });
|
|
|
|
popup->Bind(wxEVT_KEY_UP, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); });
|
2018-02-02 11:38:35 +00:00
|
|
|
|
|
|
|
std::vector<std::string> items_str;
|
|
|
|
boost::split(items_str, items, boost::is_any_of("|"), boost::token_compress_off);
|
|
|
|
|
|
|
|
for (const std::string& item : items_str)
|
|
|
|
{
|
2018-02-26 15:23:44 +00:00
|
|
|
popup->Append(from_u8(item));
|
2018-02-02 11:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < popup->GetCount(); ++i)
|
|
|
|
{
|
|
|
|
popup->Check(i, initial_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int combochecklist_get_flags(wxComboCtrl* comboCtrl)
|
|
|
|
{
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
wxCheckListBoxComboPopup* popup = wxDynamicCast(comboCtrl->GetPopupControl(), wxCheckListBoxComboPopup);
|
|
|
|
if (popup != nullptr)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < popup->GetCount(); ++i)
|
|
|
|
{
|
|
|
|
if (popup->IsChecked(i))
|
2018-02-13 16:46:23 +00:00
|
|
|
flags |= 1 << i;
|
2018-02-02 11:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2018-02-22 10:12:29 +00:00
|
|
|
AppConfig* get_app_config()
|
|
|
|
{
|
2018-10-02 11:23:38 +00:00
|
|
|
return wxGetApp().app_config;
|
2018-02-22 10:12:29 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 08:44:53 +00:00
|
|
|
wxString L_str(const std::string &str)
|
2018-02-22 10:34:41 +00:00
|
|
|
{
|
2018-02-23 08:16:35 +00:00
|
|
|
//! Explicitly specify that the source string is already in UTF-8 encoding
|
2018-02-22 10:34:41 +00:00
|
|
|
return wxGetTranslation(wxString(str.c_str(), wxConvUTF8));
|
|
|
|
}
|
|
|
|
|
2018-03-06 08:44:53 +00:00
|
|
|
wxString from_u8(const std::string &str)
|
2018-02-22 10:34:41 +00:00
|
|
|
{
|
|
|
|
return wxString::FromUTF8(str.c_str());
|
|
|
|
}
|
|
|
|
|
2018-09-19 08:34:21 +00:00
|
|
|
std::string into_u8(const wxString &str)
|
|
|
|
{
|
|
|
|
auto buffer_utf8 = str.utf8_str();
|
|
|
|
return std::string(buffer_utf8.data());
|
|
|
|
}
|
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
void set_model_events_from_perl(Model &model,
|
|
|
|
int event_object_selection_changed,
|
|
|
|
int event_object_settings_changed,
|
|
|
|
int event_remove_object,
|
|
|
|
int event_update_scene)
|
2018-06-12 21:42:01 +00:00
|
|
|
{
|
2018-06-15 23:21:25 +00:00
|
|
|
set_event_object_selection_changed(event_object_selection_changed);
|
|
|
|
set_event_object_settings_changed(event_object_settings_changed);
|
2018-07-04 06:54:30 +00:00
|
|
|
set_event_remove_object(event_remove_object);
|
2018-07-26 08:59:03 +00:00
|
|
|
set_event_update_scene(event_update_scene);
|
2018-07-24 10:15:36 +00:00
|
|
|
set_objects_from_model(model);
|
2018-06-18 12:20:29 +00:00
|
|
|
init_mesh_icons();
|
|
|
|
|
2018-07-23 15:35:50 +00:00
|
|
|
// wxWindowUpdateLocker noUpdates(parent);
|
2018-06-12 21:42:01 +00:00
|
|
|
|
2018-07-04 10:38:34 +00:00
|
|
|
// add_objects_list(parent, sizer);
|
2018-07-04 06:54:30 +00:00
|
|
|
|
|
|
|
// add_collapsible_panes(parent, sizer);
|
2018-06-12 21:42:01 +00:00
|
|
|
}
|
2018-02-07 10:37:15 +00:00
|
|
|
|
2018-05-17 12:07:50 +00:00
|
|
|
void show_buttons(bool show)
|
2018-03-12 15:52:21 +00:00
|
|
|
{
|
2018-09-17 13:12:13 +00:00
|
|
|
g_buttons[abReslice]->Show(show);
|
2018-10-02 11:23:38 +00:00
|
|
|
for (size_t i = 0; i < wxGetApp().tab_panel()->GetPageCount(); ++i) {
|
|
|
|
TabPrinter *tab = dynamic_cast<TabPrinter*>(wxGetApp().tab_panel()->GetPage(i));
|
2018-05-17 12:07:50 +00:00
|
|
|
if (!tab)
|
|
|
|
continue;
|
2018-10-02 11:23:38 +00:00
|
|
|
if (wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptFFF) {
|
2018-09-17 13:12:13 +00:00
|
|
|
g_buttons[abPrint]->Show(show && !tab->m_config->opt_string("serial_port").empty());
|
|
|
|
g_buttons[abSendGCode]->Show(show && !tab->m_config->opt_string("print_host").empty());
|
2018-08-24 14:56:42 +00:00
|
|
|
}
|
2018-05-17 12:07:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-03-27 11:44:18 +00:00
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
void show_info_sizer(const bool show)
|
2018-05-17 12:07:50 +00:00
|
|
|
{
|
2018-09-17 13:12:13 +00:00
|
|
|
g_info_sizer->Show(static_cast<size_t>(0), show);
|
|
|
|
g_info_sizer->Show(1, show && g_show_print_info);
|
2018-05-18 09:39:49 +00:00
|
|
|
g_manifold_warning_icon->Show(show && g_show_manifold_warning_icon);
|
2018-05-17 12:07:50 +00:00
|
|
|
}
|
2018-03-27 11:44:18 +00:00
|
|
|
|
2018-08-28 13:51:53 +00:00
|
|
|
void show_object_name(bool show)
|
|
|
|
{
|
|
|
|
wxGridSizer* grid_sizer = get_optgroup(ogFrequentlyObjectSettings)->get_grid_sizer();
|
|
|
|
grid_sizer->Show(static_cast<size_t>(0), show);
|
|
|
|
grid_sizer->Show(static_cast<size_t>(1), show);
|
|
|
|
}
|
|
|
|
|
2018-05-22 14:14:41 +00:00
|
|
|
ConfigOptionsGroup* get_optgroup(size_t i)
|
2018-03-12 15:52:21 +00:00
|
|
|
{
|
2018-10-03 13:14:52 +00:00
|
|
|
return wxGetApp().mainframe->m_plater->sidebar().get_optgroup(i);
|
|
|
|
// return m_optgroups.empty() ? nullptr : m_optgroups[i].get();
|
2018-03-12 15:52:21 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 23:21:25 +00:00
|
|
|
std::vector <std::shared_ptr<ConfigOptionsGroup>>& get_optgroups() {
|
2018-10-03 13:14:52 +00:00
|
|
|
return wxGetApp().mainframe->m_plater->sidebar().get_optgroups();//m_optgroups;
|
2018-04-04 12:41:23 +00:00
|
|
|
}
|
2018-04-04 11:06:46 +00:00
|
|
|
|
2018-03-22 12:49:48 +00:00
|
|
|
wxWindow* export_option_creator(wxWindow* parent)
|
|
|
|
{
|
|
|
|
wxPanel* panel = new wxPanel(parent, -1);
|
|
|
|
wxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
wxCheckBox* cbox = new wxCheckBox(panel, wxID_HIGHEST + 1, L("Export print config"));
|
2018-04-25 13:31:37 +00:00
|
|
|
cbox->SetValue(true);
|
2018-03-22 12:49:48 +00:00
|
|
|
sizer->AddSpacer(5);
|
|
|
|
sizer->Add(cbox, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
|
|
|
|
panel->SetSizer(sizer);
|
|
|
|
sizer->SetSizeHints(panel);
|
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_export_option(wxFileDialog* dlg, const std::string& format)
|
|
|
|
{
|
|
|
|
if ((dlg != nullptr) && (format == "AMF") || (format == "3MF"))
|
|
|
|
{
|
|
|
|
if (dlg->SupportsExtraControl())
|
|
|
|
dlg->SetExtraControlCreator(export_option_creator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_export_option(wxFileDialog* dlg)
|
|
|
|
{
|
|
|
|
if (dlg != nullptr)
|
|
|
|
{
|
|
|
|
wxWindow* wnd = dlg->GetExtraControl();
|
|
|
|
if (wnd != nullptr)
|
|
|
|
{
|
|
|
|
wxPanel* panel = dynamic_cast<wxPanel*>(wnd);
|
|
|
|
if (panel != nullptr)
|
|
|
|
{
|
|
|
|
wxWindow* child = panel->FindWindow(wxID_HIGHEST + 1);
|
|
|
|
if (child != nullptr)
|
|
|
|
{
|
|
|
|
wxCheckBox* cbox = dynamic_cast<wxCheckBox*>(child);
|
|
|
|
if (cbox != nullptr)
|
|
|
|
return cbox->IsChecked() ? 1 : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2018-04-04 12:41:23 +00:00
|
|
|
|
2018-03-22 12:49:48 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
bool get_current_screen_size(wxWindow *window, unsigned &width, unsigned &height)
|
2018-06-11 16:24:13 +00:00
|
|
|
{
|
2018-09-17 13:12:13 +00:00
|
|
|
const auto idx = wxDisplay::GetFromWindow(window);
|
|
|
|
if (idx == wxNOT_FOUND) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxDisplay display(idx);
|
2018-06-11 16:24:13 +00:00
|
|
|
const auto disp_size = display.GetClientArea();
|
|
|
|
width = disp_size.GetWidth();
|
|
|
|
height = disp_size.GetHeight();
|
2018-09-17 13:12:13 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void save_window_size(wxTopLevelWindow *window, const std::string &name)
|
|
|
|
{
|
|
|
|
const wxSize size = window->GetSize();
|
|
|
|
const wxPoint pos = window->GetPosition();
|
|
|
|
const auto maximized = window->IsMaximized() ? "1" : "0";
|
|
|
|
|
2018-10-02 11:23:38 +00:00
|
|
|
get_app_config()->set((boost::format("window_%1%_size") % name).str(), (boost::format("%1%;%2%") % size.GetWidth() % size.GetHeight()).str());
|
|
|
|
get_app_config()->set((boost::format("window_%1%_maximized") % name).str(), maximized);
|
2018-09-17 13:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void restore_window_size(wxTopLevelWindow *window, const std::string &name)
|
|
|
|
{
|
|
|
|
// XXX: This still doesn't behave nicely in some situations (mostly on Linux).
|
|
|
|
// The problem is that it's hard to obtain window position with respect to screen geometry reliably
|
|
|
|
// from wxWidgets. Sometimes wxWidgets claim a window is located on a different screen than on which
|
|
|
|
// it's actually visible. I suspect this has something to do with window initialization (maybe we
|
|
|
|
// restore window geometry too early), but haven't yet found a workaround.
|
|
|
|
|
|
|
|
const auto display_idx = wxDisplay::GetFromWindow(window);
|
|
|
|
if (display_idx == wxNOT_FOUND) { return; }
|
|
|
|
|
|
|
|
const auto display = wxDisplay(display_idx).GetClientArea();
|
|
|
|
std::vector<std::string> pair;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const auto key_size = (boost::format("window_%1%_size") % name).str();
|
2018-10-02 11:23:38 +00:00
|
|
|
if (get_app_config()->has(key_size)) {
|
|
|
|
if (unescape_strings_cstyle(get_app_config()->get(key_size), pair) && pair.size() == 2) {
|
2018-09-17 13:12:13 +00:00
|
|
|
auto width = boost::lexical_cast<int>(pair[0]);
|
|
|
|
auto height = boost::lexical_cast<int>(pair[1]);
|
|
|
|
|
|
|
|
window->SetSize(width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(const boost::bad_lexical_cast &) {}
|
|
|
|
|
|
|
|
// Maximizing should be the last thing to do.
|
|
|
|
// This ensure the size and position are sane when the user un-maximizes the window.
|
|
|
|
const auto key_maximized = (boost::format("window_%1%_maximized") % name).str();
|
2018-10-02 11:23:38 +00:00
|
|
|
if (get_app_config()->get(key_maximized) == "1") {
|
2018-09-17 13:12:13 +00:00
|
|
|
window->Maximize(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void enable_action_buttons(bool enable)
|
|
|
|
{
|
|
|
|
if (g_buttons.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Update background colour for buttons
|
|
|
|
const wxColour bgrd_color = enable ? wxColour(224, 224, 224/*255, 96, 0*/) : wxColour(204, 204, 204);
|
|
|
|
|
|
|
|
for (auto btn : g_buttons) {
|
|
|
|
btn->Enable(enable);
|
|
|
|
btn->SetBackgroundColour(bgrd_color);
|
|
|
|
}
|
2018-06-11 16:24:13 +00:00
|
|
|
}
|
|
|
|
|
2018-04-09 15:03:37 +00:00
|
|
|
void about()
|
|
|
|
{
|
|
|
|
AboutDialog dlg;
|
|
|
|
dlg.ShowModal();
|
|
|
|
dlg.Destroy();
|
|
|
|
}
|
|
|
|
|
2018-05-21 19:04:03 +00:00
|
|
|
void desktop_open_datadir_folder()
|
2018-06-04 07:07:29 +00:00
|
|
|
{
|
2018-05-21 20:10:38 +00:00
|
|
|
// Execute command to open a file explorer, platform dependent.
|
2018-06-04 07:07:29 +00:00
|
|
|
// FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade.
|
|
|
|
|
|
|
|
const auto path = data_dir();
|
2018-05-21 19:04:03 +00:00
|
|
|
#ifdef _WIN32
|
2018-06-04 07:07:29 +00:00
|
|
|
const auto widepath = wxString::FromUTF8(path.data());
|
|
|
|
const wchar_t *argv[] = { L"explorer", widepath.GetData(), nullptr };
|
|
|
|
::wxExecute(const_cast<wchar_t**>(argv), wxEXEC_ASYNC, nullptr);
|
2018-05-21 19:04:03 +00:00
|
|
|
#elif __APPLE__
|
2018-06-04 07:07:29 +00:00
|
|
|
const char *argv[] = { "open", path.data(), nullptr };
|
|
|
|
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr);
|
2018-05-21 19:04:03 +00:00
|
|
|
#else
|
2018-06-04 07:07:29 +00:00
|
|
|
const char *argv[] = { "xdg-open", path.data(), nullptr };
|
|
|
|
|
|
|
|
// Check if we're running in an AppImage container, if so, we need to remove AppImage's env vars,
|
|
|
|
// because they may mess up the environment expected by the file manager.
|
|
|
|
// Mostly this is about LD_LIBRARY_PATH, but we remove a few more too for good measure.
|
|
|
|
if (wxGetEnv("APPIMAGE", nullptr)) {
|
|
|
|
// We're running from AppImage
|
|
|
|
wxEnvVariableHashMap env_vars;
|
|
|
|
wxGetEnvMap(&env_vars);
|
|
|
|
|
|
|
|
env_vars.erase("APPIMAGE");
|
|
|
|
env_vars.erase("APPDIR");
|
|
|
|
env_vars.erase("LD_LIBRARY_PATH");
|
|
|
|
env_vars.erase("LD_PRELOAD");
|
|
|
|
env_vars.erase("UNION_PRELOAD");
|
|
|
|
|
|
|
|
wxExecuteEnv exec_env;
|
|
|
|
exec_env.env = std::move(env_vars);
|
|
|
|
|
|
|
|
wxString owd;
|
|
|
|
if (wxGetEnv("OWD", &owd)) {
|
|
|
|
// This is the original work directory from which the AppImage image was run,
|
|
|
|
// set it as CWD for the child process:
|
|
|
|
exec_env.cwd = std::move(owd);
|
|
|
|
}
|
|
|
|
|
|
|
|
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, &exec_env);
|
|
|
|
} else {
|
|
|
|
// Looks like we're NOT running from AppImage, we'll make no changes to the environment.
|
|
|
|
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, nullptr);
|
|
|
|
}
|
2018-05-21 20:10:38 +00:00
|
|
|
#endif
|
2018-03-12 15:52:21 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 16:02:04 +00:00
|
|
|
namespace {
|
|
|
|
AppControllerPtr g_appctl;
|
|
|
|
}
|
|
|
|
|
|
|
|
AppControllerPtr get_appctl()
|
|
|
|
{
|
|
|
|
return g_appctl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_cli_appctl()
|
|
|
|
{
|
|
|
|
g_appctl = std::make_shared<AppControllerCli>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_gui_appctl()
|
|
|
|
{
|
|
|
|
g_appctl = std::make_shared<AppControllerGui>();
|
|
|
|
}
|
|
|
|
|
2015-12-04 20:25:45 +00:00
|
|
|
} }
|