2015-12-04 20:25:45 +00:00
|
|
|
#include "GUI.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>
|
|
|
|
|
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
2017-11-02 15:29:03 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2018-01-07 17:41:40 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2018-02-02 11:38:35 +00:00
|
|
|
#include <boost/algorithm/string/split.hpp>
|
|
|
|
#include <boost/algorithm/string/classification.hpp>
|
2018-02-07 10:37:15 +00:00
|
|
|
#include <boost/format.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
|
|
|
#pragma comment(lib, "user32.lib")
|
|
|
|
#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-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-01-05 14:11:33 +00:00
|
|
|
#include "AppConfig.hpp"
|
2018-02-08 09:58:13 +00:00
|
|
|
#include "Utils.hpp"
|
2018-02-22 10:12:29 +00:00
|
|
|
#include "Preferences.hpp"
|
2018-03-09 16:17:51 +00:00
|
|
|
#include "PresetBundle.hpp"
|
2017-12-05 14:54:01 +00:00
|
|
|
|
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-11-02 15:21:34 +00:00
|
|
|
std::vector<std::string> scan_serial_ports()
|
|
|
|
{
|
|
|
|
std::vector<std::string> out;
|
|
|
|
#ifdef _WIN32
|
|
|
|
// 1) Open the registry key SERIALCOM.
|
|
|
|
HKEY hKey;
|
|
|
|
LONG lRes = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &hKey);
|
|
|
|
assert(lRes == ERROR_SUCCESS);
|
|
|
|
if (lRes == ERROR_SUCCESS) {
|
|
|
|
// 2) Get number of values of SERIALCOM key.
|
|
|
|
DWORD cValues; // number of values for key
|
|
|
|
{
|
|
|
|
TCHAR achKey[255]; // buffer for subkey name
|
|
|
|
DWORD cbName; // size of name string
|
|
|
|
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
|
|
|
|
DWORD cchClassName = MAX_PATH; // size of class string
|
|
|
|
DWORD cSubKeys=0; // number of subkeys
|
|
|
|
DWORD cbMaxSubKey; // longest subkey size
|
|
|
|
DWORD cchMaxClass; // longest class string
|
|
|
|
DWORD cchMaxValue; // longest value name
|
|
|
|
DWORD cbMaxValueData; // longest value data
|
|
|
|
DWORD cbSecurityDescriptor; // size of security descriptor
|
|
|
|
FILETIME ftLastWriteTime; // last write time
|
|
|
|
// Get the class name and the value count.
|
|
|
|
lRes = RegQueryInfoKey(
|
|
|
|
hKey, // key handle
|
|
|
|
achClass, // buffer for class name
|
|
|
|
&cchClassName, // size of class string
|
|
|
|
NULL, // reserved
|
|
|
|
&cSubKeys, // number of subkeys
|
|
|
|
&cbMaxSubKey, // longest subkey size
|
|
|
|
&cchMaxClass, // longest class string
|
|
|
|
&cValues, // number of values for this key
|
|
|
|
&cchMaxValue, // longest value name
|
|
|
|
&cbMaxValueData, // longest value data
|
|
|
|
&cbSecurityDescriptor, // security descriptor
|
|
|
|
&ftLastWriteTime); // last write time
|
|
|
|
assert(lRes == ERROR_SUCCESS);
|
|
|
|
}
|
|
|
|
// 3) Read the SERIALCOM values.
|
|
|
|
{
|
|
|
|
DWORD dwIndex = 0;
|
|
|
|
for (int i = 0; i < cValues; ++ i, ++ dwIndex) {
|
|
|
|
wchar_t valueName[2048];
|
|
|
|
DWORD valNameLen = 2048;
|
|
|
|
DWORD dataType;
|
|
|
|
wchar_t data[2048];
|
|
|
|
DWORD dataSize = 4096;
|
|
|
|
lRes = ::RegEnumValueW(hKey, dwIndex, valueName, &valNameLen, nullptr, &dataType, (BYTE*)&data, &dataSize);
|
|
|
|
if (lRes == ERROR_SUCCESS && dataType == REG_SZ && valueName[0] != 0)
|
|
|
|
out.emplace_back(boost::nowide::narrow(data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
::RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// UNIX and OS X
|
|
|
|
std::initializer_list<const char*> prefixes { "ttyUSB" , "ttyACM", "tty.", "cu.", "rfcomm" };
|
2017-11-02 15:40:25 +00:00
|
|
|
for (auto &dir_entry : boost::filesystem::directory_iterator(boost::filesystem::path("/dev"))) {
|
|
|
|
std::string name = dir_entry.path().filename().string();
|
2017-11-02 15:35:46 +00:00
|
|
|
for (const char *prefix : prefixes) {
|
|
|
|
if (boost::starts_with(name, prefix)) {
|
2017-11-02 15:40:25 +00:00
|
|
|
out.emplace_back(dir_entry.path().string());
|
2017-11-02 15:21:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-11-02 15:35:46 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-02 15:21:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
out.erase(std::remove_if(out.begin(), out.end(),
|
|
|
|
[](const std::string &key){
|
|
|
|
return boost::starts_with(key, "Bluetooth") || boost::starts_with(key, "FireFly");
|
|
|
|
}),
|
|
|
|
out.end());
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|
2017-12-04 09:48:40 +00:00
|
|
|
// Passing the wxWidgets GUI classes instantiated by the Perl part to C++.
|
|
|
|
wxApp *g_wxApp = nullptr;
|
|
|
|
wxFrame *g_wxMainFrame = nullptr;
|
|
|
|
wxNotebook *g_wxTabPanel = nullptr;
|
2018-02-20 07:58:46 +00:00
|
|
|
AppConfig *g_AppConfig = nullptr;
|
2018-03-09 16:17:51 +00:00
|
|
|
PresetBundle *g_PresetBundle= nullptr;
|
2017-12-04 09:48:40 +00:00
|
|
|
|
2018-02-09 10:04:34 +00:00
|
|
|
std::vector<Tab *> g_tabs_list;
|
|
|
|
|
2018-02-12 07:57:32 +00:00
|
|
|
wxLocale* g_wxLocale;
|
2018-02-08 09:58:13 +00:00
|
|
|
|
2018-03-09 16:17:51 +00:00
|
|
|
std::shared_ptr<ConfigOptionsGroup> m_optgroup;
|
2018-03-13 15:14:36 +00:00
|
|
|
double m_brim_width = 0.0;
|
2018-03-09 16:17:51 +00:00
|
|
|
|
2017-12-04 09:48:40 +00:00
|
|
|
void set_wxapp(wxApp *app)
|
|
|
|
{
|
|
|
|
g_wxApp = app;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_main_frame(wxFrame *main_frame)
|
|
|
|
{
|
|
|
|
g_wxMainFrame = main_frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_tab_panel(wxNotebook *tab_panel)
|
|
|
|
{
|
|
|
|
g_wxTabPanel = tab_panel;
|
|
|
|
}
|
|
|
|
|
2018-02-20 07:58:46 +00:00
|
|
|
void set_app_config(AppConfig *app_config)
|
|
|
|
{
|
|
|
|
g_AppConfig = app_config;
|
|
|
|
}
|
|
|
|
|
2018-03-09 16:17:51 +00:00
|
|
|
void set_preset_bundle(PresetBundle *preset_bundle)
|
|
|
|
{
|
|
|
|
g_PresetBundle = preset_bundle;
|
|
|
|
}
|
|
|
|
|
2018-02-09 10:04:34 +00:00
|
|
|
std::vector<Tab *>& get_tabs_list()
|
2017-12-04 09:48:40 +00:00
|
|
|
{
|
2018-02-09 10:04:34 +00:00
|
|
|
return g_tabs_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool checked_tab(Tab* tab)
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
if (find(g_tabs_list.begin(), g_tabs_list.end(), tab) == g_tabs_list.end())
|
|
|
|
ret = false;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void delete_tab_from_list(Tab* tab)
|
|
|
|
{
|
|
|
|
std::vector<Tab *>::iterator itr = find(g_tabs_list.begin(), g_tabs_list.end(), tab);
|
|
|
|
if (itr != g_tabs_list.end())
|
|
|
|
g_tabs_list.erase(itr);
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:58:13 +00:00
|
|
|
bool select_language(wxArrayString & names,
|
|
|
|
wxArrayLong & identifiers)
|
|
|
|
{
|
|
|
|
wxCHECK_MSG(names.Count() == identifiers.Count(), false,
|
2018-02-23 08:16:35 +00:00
|
|
|
_(L("Array of language names and identifiers should have the same size.")));
|
2018-02-12 07:57:32 +00:00
|
|
|
int init_selection = 0;
|
|
|
|
long current_language = g_wxLocale ? g_wxLocale->GetLanguage() : wxLANGUAGE_UNKNOWN;
|
|
|
|
for (auto lang : identifiers){
|
|
|
|
if (lang == current_language)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
++init_selection;
|
|
|
|
}
|
|
|
|
if (init_selection == identifiers.size())
|
|
|
|
init_selection = 0;
|
2018-02-23 08:16:35 +00:00
|
|
|
long index = wxGetSingleChoiceIndex(_(L("Select the language")), _(L("Language")),
|
2018-02-12 07:57:32 +00:00
|
|
|
names, init_selection);
|
2018-02-08 09:58:13 +00:00
|
|
|
if (index != -1)
|
|
|
|
{
|
2018-02-12 07:57:32 +00:00
|
|
|
g_wxLocale = new wxLocale;
|
|
|
|
g_wxLocale->Init(identifiers[index]);
|
|
|
|
g_wxLocale->AddCatalogLookupPathPrefix(wxPathOnly(localization_dir()));
|
|
|
|
g_wxLocale->AddCatalog(g_wxApp->GetAppName());
|
2018-03-06 08:44:53 +00:00
|
|
|
wxSetlocale(LC_NUMERIC, "C");
|
2018-02-08 09:58:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool load_language()
|
|
|
|
{
|
|
|
|
long language;
|
2018-02-20 07:58:46 +00:00
|
|
|
if (!g_AppConfig->has("translation_language"))
|
2018-02-12 07:57:32 +00:00
|
|
|
language = wxLANGUAGE_UNKNOWN;
|
2018-02-20 07:58:46 +00:00
|
|
|
else {
|
|
|
|
auto str_language = g_AppConfig->get("translation_language");
|
|
|
|
language = str_language != "" ? stol(str_language) : wxLANGUAGE_UNKNOWN;
|
2018-02-09 10:04:34 +00:00
|
|
|
}
|
2018-02-20 07:58:46 +00:00
|
|
|
|
2018-02-12 07:57:32 +00:00
|
|
|
if (language == wxLANGUAGE_UNKNOWN)
|
|
|
|
return false;
|
|
|
|
wxArrayString names;
|
|
|
|
wxArrayLong identifiers;
|
2018-02-08 09:58:13 +00:00
|
|
|
get_installed_languages(names, identifiers);
|
|
|
|
for (size_t i = 0; i < identifiers.Count(); i++)
|
|
|
|
{
|
|
|
|
if (identifiers[i] == language)
|
|
|
|
{
|
2018-02-12 07:57:32 +00:00
|
|
|
g_wxLocale = new wxLocale;
|
|
|
|
g_wxLocale->Init(identifiers[i]);
|
|
|
|
g_wxLocale->AddCatalogLookupPathPrefix(wxPathOnly(localization_dir()));
|
|
|
|
g_wxLocale->AddCatalog(g_wxApp->GetAppName());
|
2018-03-06 08:44:53 +00:00
|
|
|
wxSetlocale(LC_NUMERIC, "C");
|
2018-02-08 09:58:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-12 07:57:32 +00:00
|
|
|
void save_language()
|
2018-02-08 09:58:13 +00:00
|
|
|
{
|
|
|
|
long language = wxLANGUAGE_UNKNOWN;
|
2018-02-12 07:57:32 +00:00
|
|
|
if (g_wxLocale) {
|
|
|
|
language = g_wxLocale->GetLanguage();
|
2018-02-08 09:58:13 +00:00
|
|
|
}
|
2018-02-20 07:58:46 +00:00
|
|
|
std::string str_language = std::to_string(language);
|
|
|
|
g_AppConfig->set("translation_language", str_language);
|
|
|
|
g_AppConfig->save();
|
2017-12-04 09:48:40 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 09:58:13 +00:00
|
|
|
void get_installed_languages(wxArrayString & names,
|
|
|
|
wxArrayLong & identifiers)
|
2017-12-04 09:48:40 +00:00
|
|
|
{
|
2018-02-08 09:58:13 +00:00
|
|
|
names.Clear();
|
|
|
|
identifiers.Clear();
|
|
|
|
|
2018-02-12 07:57:32 +00:00
|
|
|
wxDir dir(wxPathOnly(localization_dir()));
|
2018-02-08 09:58:13 +00:00
|
|
|
wxString filename;
|
|
|
|
const wxLanguageInfo * langinfo;
|
|
|
|
wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT);
|
|
|
|
if (!name.IsEmpty())
|
|
|
|
{
|
2018-02-23 08:16:35 +00:00
|
|
|
names.Add(_(L("Default")));
|
2018-02-08 09:58:13 +00:00
|
|
|
identifiers.Add(wxLANGUAGE_DEFAULT);
|
|
|
|
}
|
|
|
|
for (bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
|
|
|
|
cont; cont = dir.GetNext(&filename))
|
|
|
|
{
|
|
|
|
langinfo = wxLocale::FindLanguageInfo(filename);
|
|
|
|
if (langinfo != NULL)
|
|
|
|
{
|
|
|
|
auto full_file_name = dir.GetName() + wxFileName::GetPathSeparator() +
|
|
|
|
filename + wxFileName::GetPathSeparator() +
|
|
|
|
g_wxApp->GetAppName() + wxT(".mo");
|
|
|
|
if (wxFileExists(full_file_name))
|
|
|
|
{
|
|
|
|
names.Add(langinfo->Description);
|
|
|
|
identifiers.Add(langinfo->Language);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 10:04:34 +00:00
|
|
|
void add_debug_menu(wxMenuBar *menu, int event_language_change)
|
2017-12-04 09:48:40 +00:00
|
|
|
{
|
2018-02-08 09:58:13 +00:00
|
|
|
//#if 0
|
|
|
|
auto local_menu = new wxMenu();
|
2018-02-23 08:16:35 +00:00
|
|
|
local_menu->Append(wxWindow::NewControlId(1), _(L("Change Application Language")));
|
2018-02-09 10:04:34 +00:00
|
|
|
local_menu->Bind(wxEVT_MENU, [event_language_change](wxEvent&){
|
2018-02-08 09:58:13 +00:00
|
|
|
wxArrayString names;
|
|
|
|
wxArrayLong identifiers;
|
|
|
|
get_installed_languages(names, identifiers);
|
2018-02-09 10:04:34 +00:00
|
|
|
if (select_language(names, identifiers)){
|
2018-02-12 07:57:32 +00:00
|
|
|
save_language();
|
2018-02-23 08:16:35 +00:00
|
|
|
show_info(g_wxTabPanel, _(L("Application will be restarted")), _(L("Attention!")));
|
2018-02-09 10:04:34 +00:00
|
|
|
if (event_language_change > 0) {
|
|
|
|
wxCommandEvent event(event_language_change);
|
|
|
|
g_wxApp->ProcessEvent(event);
|
|
|
|
}
|
|
|
|
}
|
2018-02-08 09:58:13 +00:00
|
|
|
});
|
2018-02-26 12:57:36 +00:00
|
|
|
menu->Append(local_menu, _(L("&Localization")));
|
2018-02-08 09:58:13 +00:00
|
|
|
//#endif
|
2017-12-04 09:48:40 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 10:12:29 +00:00
|
|
|
void open_preferences_dialog(int event_preferences)
|
|
|
|
{
|
|
|
|
auto dlg = new PreferencesDialog(g_wxMainFrame, event_preferences);
|
|
|
|
dlg->ShowModal();
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:06:26 +00:00
|
|
|
void create_preset_tabs(bool no_controller, int event_value_change, int event_presets_changed)
|
2018-01-05 14:11:33 +00:00
|
|
|
{
|
2018-03-09 16:17:51 +00:00
|
|
|
add_created_tab(new TabPrint (g_wxTabPanel, no_controller));
|
|
|
|
add_created_tab(new TabFilament (g_wxTabPanel, no_controller));
|
2018-03-15 17:06:26 +00:00
|
|
|
add_created_tab(new TabPrinter (g_wxTabPanel, no_controller));
|
2018-01-21 22:35:00 +00:00
|
|
|
for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) {
|
|
|
|
Tab *tab = dynamic_cast<Tab*>(g_wxTabPanel->GetPage(i));
|
|
|
|
if (! tab)
|
|
|
|
continue;
|
|
|
|
tab->set_event_value_change(wxEventType(event_value_change));
|
|
|
|
tab->set_event_presets_changed(wxEventType(event_presets_changed));
|
|
|
|
}
|
2017-12-22 10:50:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 10:37:19 +00:00
|
|
|
TabIface* get_preset_tab_iface(char *name)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) {
|
|
|
|
Tab *tab = dynamic_cast<Tab*>(g_wxTabPanel->GetPage(i));
|
|
|
|
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-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)
|
|
|
|
void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, 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-03-07 14:05:41 +00:00
|
|
|
if (opt_key.compare("compatible_printers") == 0 ||
|
|
|
|
config.def()->get(opt_key)->gui_flags.compare("serialized") == 0){
|
2018-01-25 12:46:04 +00:00
|
|
|
config.option<ConfigOptionStrings>(opt_key)->values.resize(0);
|
2018-03-07 14:05:41 +00:00
|
|
|
std::vector<std::string> values = boost::any_cast<std::vector<std::string>>(value);
|
|
|
|
if (values.size() == 1 && values[0] == "")
|
|
|
|
break;
|
|
|
|
for (auto el : values)
|
2018-01-25 12:46:04 +00:00
|
|
|
config.option<ConfigOptionStrings>(opt_key)->values.push_back(el);
|
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-01-07 17:41:40 +00:00
|
|
|
break;
|
2018-01-30 11:10:12 +00:00
|
|
|
case coPoints:{
|
2018-03-08 10:58:06 +00:00
|
|
|
ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast<Pointf>(value) };
|
|
|
|
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-03-09 16:17:51 +00:00
|
|
|
void add_created_tab(Tab* panel)
|
2017-12-22 10:50:28 +00:00
|
|
|
{
|
2018-03-09 16:17:51 +00:00
|
|
|
panel->create_preset_tab(g_PresetBundle);
|
2018-01-05 14:11:33 +00:00
|
|
|
|
2018-01-16 15:28:01 +00:00
|
|
|
// Load the currently selected preset into the GUI, update the preset selection box.
|
|
|
|
panel->load_current_preset();
|
2017-12-22 10:50:28 +00:00
|
|
|
g_wxTabPanel->AddPage(panel, panel->title());
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:13:52 +00:00
|
|
|
void show_error(wxWindow* parent, wxString message){
|
2018-02-23 08:16:35 +00:00
|
|
|
auto msg_wingow = new wxMessageDialog(parent, message, _(L("Error")), wxOK | wxICON_ERROR);
|
2017-12-22 10:50:28 +00:00
|
|
|
msg_wingow->ShowModal();
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:13:52 +00:00
|
|
|
void show_info(wxWindow* parent, wxString message, wxString title){
|
2018-02-23 08:16:35 +00:00
|
|
|
auto msg_wingow = new wxMessageDialog(parent, message, title.empty() ? _(L("Notice")) : title, wxOK | wxICON_INFORMATION);
|
2017-12-22 10:50:28 +00:00
|
|
|
msg_wingow->ShowModal();
|
2017-12-04 09:48:40 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 10:12:29 +00:00
|
|
|
void warning_catcher(wxWindow* parent, wxString message){
|
2018-02-23 08:16:35 +00:00
|
|
|
if (message == _(L("GLUquadricObjPtr | Attempt to free unreferenced scalar")) )
|
2018-02-22 10:12:29 +00:00
|
|
|
return;
|
2018-02-23 08:16:35 +00:00
|
|
|
auto msg = new wxMessageDialog(parent, message, _(L("Warning")), wxOK | wxICON_WARNING);
|
2018-02-22 10:12:29 +00:00
|
|
|
msg->ShowModal();
|
|
|
|
}
|
|
|
|
|
2018-02-05 15:12:16 +00:00
|
|
|
wxApp* get_app(){
|
|
|
|
return g_wxApp;
|
2017-12-04 09:48:40 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 08:08:11 +00:00
|
|
|
wxColour* get_modified_label_clr()
|
|
|
|
{
|
2018-03-06 08:44:53 +00:00
|
|
|
return new wxColour(253, 88, 0);
|
2018-03-02 08:08:11 +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()
|
|
|
|
{
|
|
|
|
return g_AppConfig;
|
|
|
|
}
|
|
|
|
|
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-02-07 10:37:15 +00:00
|
|
|
|
2018-03-09 17:34:30 +00:00
|
|
|
void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFlexGridSizer* preset_sizer)
|
|
|
|
{
|
|
|
|
DynamicPrintConfig* config = &g_PresetBundle->prints.get_edited_preset().config;
|
|
|
|
m_optgroup = std::make_shared<ConfigOptionsGroup>(parent, "", config);
|
|
|
|
const wxArrayInt& ar = preset_sizer->GetColWidths();
|
2018-03-13 15:14:36 +00:00
|
|
|
m_optgroup->label_width = ar.IsEmpty() ? 100 : ar.front();
|
2018-03-12 15:52:21 +00:00
|
|
|
m_optgroup->m_on_change = [config](t_config_option_key opt_key, boost::any value){
|
|
|
|
TabPrint* tab_print = nullptr;
|
|
|
|
for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++i) {
|
|
|
|
Tab *tab = dynamic_cast<Tab*>(g_wxTabPanel->GetPage(i));
|
|
|
|
if (!tab)
|
|
|
|
continue;
|
|
|
|
if (tab->name() == "print"){
|
|
|
|
tab_print = static_cast<TabPrint*>(tab);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tab_print == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (opt_key == "fill_density"){
|
|
|
|
value = m_optgroup->get_config_value(*config, opt_key);
|
|
|
|
tab_print->set_value(opt_key, value);
|
2018-03-14 09:14:48 +00:00
|
|
|
tab_print->update();
|
2018-03-12 15:52:21 +00:00
|
|
|
}
|
2018-03-13 15:14:36 +00:00
|
|
|
else{
|
|
|
|
DynamicPrintConfig new_conf = *config;
|
|
|
|
if (opt_key == "brim"){
|
|
|
|
double new_val;
|
|
|
|
double brim_width = config->opt_float("brim_width");
|
|
|
|
if (boost::any_cast<bool>(value) == true)
|
|
|
|
{
|
|
|
|
new_val = m_brim_width == 0.0 ? 10 :
|
|
|
|
m_brim_width < 0.0 ? m_brim_width * (-1) :
|
|
|
|
m_brim_width;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
m_brim_width = brim_width * (-1);
|
|
|
|
new_val = 0;
|
|
|
|
}
|
|
|
|
new_conf.set_key_value("brim_width", new ConfigOptionFloat(new_val));
|
|
|
|
}
|
|
|
|
else{ //(opt_key == "support")
|
|
|
|
const wxString& selection = boost::any_cast<wxString>(value);
|
|
|
|
|
|
|
|
auto support_material = selection == _("None") ? false : true;
|
|
|
|
new_conf.set_key_value("support_material", new ConfigOptionBool(support_material));
|
|
|
|
|
|
|
|
if (selection == _("Everywhere"))
|
|
|
|
new_conf.set_key_value("support_material_buildplate_only", new ConfigOptionBool(false));
|
|
|
|
else if (selection == _("Support on build plate only"))
|
|
|
|
new_conf.set_key_value("support_material_buildplate_only", new ConfigOptionBool(true));
|
2018-03-12 15:52:21 +00:00
|
|
|
}
|
2018-03-13 15:14:36 +00:00
|
|
|
tab_print->load_config(new_conf);
|
2018-03-12 15:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tab_print->update_dirty();
|
2018-03-09 17:34:30 +00:00
|
|
|
};
|
2018-03-12 15:52:21 +00:00
|
|
|
|
2018-03-13 15:14:36 +00:00
|
|
|
const int width = 250;
|
2018-03-12 15:52:21 +00:00
|
|
|
Option option = m_optgroup->get_option("fill_density");
|
|
|
|
option.opt.sidetext = "";
|
2018-03-13 15:14:36 +00:00
|
|
|
option.opt.width = width;
|
2018-03-12 15:52:21 +00:00
|
|
|
m_optgroup->append_single_option_line(option);
|
2018-03-09 17:34:30 +00:00
|
|
|
|
|
|
|
ConfigOptionDef def;
|
|
|
|
|
|
|
|
def.label = L("Support");
|
2018-03-13 15:14:36 +00:00
|
|
|
def.type = coStrings;
|
2018-03-09 17:34:30 +00:00
|
|
|
def.gui_type = "select_open";
|
|
|
|
def.tooltip = L("Select what kind of support do you need");
|
|
|
|
def.enum_labels.push_back(L("None"));
|
|
|
|
def.enum_labels.push_back(L("Support on build plate only"));
|
|
|
|
def.enum_labels.push_back(L("Everywhere"));
|
2018-03-13 15:14:36 +00:00
|
|
|
std::string selection = !config->opt_bool("support_material") ?
|
|
|
|
"None" :
|
|
|
|
config->opt_bool("support_material_buildplate_only") ?
|
|
|
|
"Support on build plate only" :
|
|
|
|
"Everywhere";
|
|
|
|
def.default_value = new ConfigOptionStrings { selection };
|
2018-03-12 15:52:21 +00:00
|
|
|
option = Option(def, "support");
|
2018-03-13 15:14:36 +00:00
|
|
|
option.opt.width = width;
|
2018-03-09 17:34:30 +00:00
|
|
|
m_optgroup->append_single_option_line(option);
|
|
|
|
|
2018-03-13 15:14:36 +00:00
|
|
|
m_brim_width = config->opt_float("brim_width");
|
2018-03-09 17:34:30 +00:00
|
|
|
def.label = L("Brim");
|
|
|
|
def.type = coBool;
|
|
|
|
def.tooltip = L("This flag enables the brim that will be printed around each object on the first layer.");
|
|
|
|
def.gui_type = "";
|
2018-03-13 15:14:36 +00:00
|
|
|
def.default_value = new ConfigOptionBool{ m_brim_width > 0.0 ? true : false };
|
2018-03-09 17:34:30 +00:00
|
|
|
option = Option(def, "brim");
|
|
|
|
m_optgroup->append_single_option_line(option);
|
|
|
|
|
2018-03-27 11:44:18 +00:00
|
|
|
|
|
|
|
Line line = { _(L("")), "" };
|
|
|
|
line.widget = [config](wxWindow* parent){
|
|
|
|
auto wiping_dialog_button = new wxButton(parent, wxID_ANY, _(L("Purging volumes"))+"\u2026", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
|
|
|
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sizer->Add(wiping_dialog_button);
|
|
|
|
wiping_dialog_button->Bind(wxEVT_BUTTON, ([config, parent](wxCommandEvent& e)
|
|
|
|
{
|
|
|
|
std::vector<double> init_matrix = (config->option<ConfigOptionFloats>("wiping_volumes_matrix"))->values;
|
|
|
|
std::vector<double> init_extruders = (config->option<ConfigOptionFloats>("wiping_volumes_extruders"))->values;
|
|
|
|
|
|
|
|
WipingDialog dlg(parent,std::vector<float>(init_matrix.begin(),init_matrix.end()),std::vector<float>(init_extruders.begin(),init_extruders.end()));
|
|
|
|
|
|
|
|
if (dlg.ShowModal() == wxID_OK) {
|
|
|
|
std::vector<float> matrix = dlg.get_matrix();
|
|
|
|
std::vector<float> extruders = dlg.get_extruders();
|
|
|
|
(config->option<ConfigOptionFloats>("wiping_volumes_matrix"))->values = std::vector<double>(matrix.begin(),matrix.end());
|
|
|
|
(config->option<ConfigOptionFloats>("wiping_volumes_extruders"))->values = std::vector<double>(extruders.begin(),extruders.end());
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
return sizer;
|
|
|
|
};
|
|
|
|
m_optgroup->append_line(line);
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-09 17:34:30 +00:00
|
|
|
sizer->Add(m_optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxBottom, 1);
|
|
|
|
}
|
|
|
|
|
2018-03-12 15:52:21 +00:00
|
|
|
ConfigOptionsGroup* get_optgroup()
|
|
|
|
{
|
|
|
|
return m_optgroup.get();
|
|
|
|
}
|
|
|
|
|
2015-12-04 20:25:45 +00:00
|
|
|
} }
|