2018-09-20 06:40:22 +00:00
# include "GUI_App.hpp"
2018-10-05 21:29:15 +00:00
# include "GUI_ObjectList.hpp"
2018-10-04 14:43:10 +00:00
# include "GUI_ObjectManipulation.hpp"
2018-11-26 13:41:58 +00:00
# include "I18N.hpp"
2018-09-20 06:40:22 +00:00
# include <boost/lexical_cast.hpp>
# include <boost/algorithm/string.hpp>
# include <wx/stdpaths.h>
# include <wx/imagpng.h>
# include <wx/display.h>
# include <wx/menu.h>
# include <wx/menuitem.h>
2018-09-20 11:12:35 +00:00
# include <wx/filedlg.h>
2018-10-02 11:23:38 +00:00
# include <wx/dir.h>
2018-11-26 13:41:58 +00:00
# include <wx/wupdlock.h>
2019-01-04 11:06:25 +00:00
# include <wx/filefn.h>
2018-11-26 13:41:58 +00:00
# include "libslic3r/Utils.hpp"
# include "libslic3r/Model.hpp"
# include "libslic3r/I18N.hpp"
2018-09-20 06:40:22 +00:00
# include "GUI.hpp"
2018-10-17 12:01:10 +00:00
# include "GUI_Utils.hpp"
2018-09-20 06:40:22 +00:00
# include "AppConfig.hpp"
# include "PresetBundle.hpp"
# include "3DScene.hpp"
# include "../Utils/PresetUpdater.hpp"
2018-12-11 09:33:11 +00:00
# include "../Utils/PrintHost.hpp"
2018-09-20 23:33:41 +00:00
# include "ConfigWizard_private.hpp"
# include "slic3r/Config/Snapshot.hpp"
# include "ConfigSnapshotDialog.hpp"
# include "FirmwareDialog.hpp"
# include "Preferences.hpp"
# include "Tab.hpp"
2018-10-25 10:48:19 +00:00
# include "SysInfoDialog.hpp"
2018-12-19 12:06:24 +00:00
# include "KBShortcutsDialog.hpp"
2018-09-20 06:40:22 +00:00
namespace Slic3r {
namespace GUI {
2018-10-04 09:12:55 +00:00
2018-12-06 16:32:49 +00:00
wxString file_wildcards ( FileType file_type , const std : : string & custom_extension )
{
2018-12-20 17:23:11 +00:00
static const std : : string defaults [ FT_SIZE ] = {
2018-12-06 16:32:49 +00:00
/* FT_STL */ " STL files (*.stl)|*.stl;*.STL " ,
/* FT_OBJ */ " OBJ files (*.obj)|*.obj;*.OBJ " ,
/* FT_AMF */ " AMF files (*.amf)|*.zip.amf;*.amf;*.AMF;*.xml;*.XML " ,
/* FT_3MF */ " 3MF files (*.3mf)|*.3mf;*.3MF; " ,
/* FT_PRUSA */ " Prusa Control files (*.prusa)|*.prusa;*.PRUSA " ,
/* FT_GCODE */ " G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC " ,
/* FT_MODEL */ " Known files (*.stl, *.obj, *.amf, *.xml, *.3mf, *.prusa)|*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML;*.3mf;*.3MF;*.prusa;*.PRUSA " ,
/* FT_INI */ " INI files (*.ini)|*.ini;*.INI " ,
/* FT_SVG */ " SVG files (*.svg)|*.svg;*.SVG " ,
2018-12-21 18:48:33 +00:00
/* FT_PNGZIP */ " Zipped PNG files (*.dwz)|*.dwz;*.DWZ " , // This is lame, but that's what we use for SLA
2018-12-06 16:32:49 +00:00
} ;
2018-12-20 17:23:11 +00:00
std : : string out = defaults [ file_type ] ;
2018-12-06 16:32:49 +00:00
if ( ! custom_extension . empty ( ) ) {
2018-12-20 17:23:11 +00:00
// Find the custom extension in the template.
if ( out . find ( std : : string ( " * " ) + custom_extension + " , " ) = = std : : string : : npos & & out . find ( std : : string ( " * " ) + custom_extension + " ) " ) = = std : : string : : npos ) {
// The custom extension was not found in the template.
// Append the custom extension to the wildcards, so that the file dialog would not add the default extension to it.
boost : : replace_first ( out , " )| " , std : : string ( " , * " ) + custom_extension + " )| " ) ;
out + = std : : string ( " ;* " ) + custom_extension ;
}
2018-12-06 16:32:49 +00:00
}
2019-01-07 18:17:10 +00:00
return from_u8 ( out ) ;
2018-12-06 16:32:49 +00:00
}
2018-10-04 09:12:55 +00:00
2018-10-01 13:09:31 +00:00
static std : : string libslic3r_translate_callback ( const char * s ) { return wxGetTranslation ( wxString ( s , wxConvUTF8 ) ) . utf8_str ( ) . data ( ) ; }
2018-09-20 23:33:41 +00:00
IMPLEMENT_APP ( GUI_App )
2018-11-26 09:56:07 +00:00
GUI_App : : GUI_App ( )
: wxApp ( )
2018-11-27 11:18:43 +00:00
# if ENABLE_IMGUI
2018-11-26 09:56:07 +00:00
, m_imgui ( new ImGuiWrapper ( ) )
2018-11-27 11:18:43 +00:00
# endif // ENABLE_IMGUI
2018-11-26 09:56:07 +00:00
{ }
2018-09-20 06:40:22 +00:00
bool GUI_App : : OnInit ( )
{
2019-01-04 11:06:25 +00:00
// Verify resources path
const wxString resources_dir = from_u8 ( Slic3r : : resources_dir ( ) ) ;
wxCHECK_MSG ( wxDirExists ( resources_dir ) , false ,
wxString : : Format ( " Resources path does not exist or is not a directory: %s " , resources_dir ) ) ;
2018-10-31 09:19:44 +00:00
# if ENABLE_IMGUI
2018-11-26 09:56:07 +00:00
wxCHECK_MSG ( m_imgui - > init ( ) , false , " Failed to initialize ImGui " ) ;
2018-10-31 09:19:44 +00:00
# endif // ENABLE_IMGUI
2018-10-30 14:24:36 +00:00
SetAppName ( " Slic3rPE-alpha " ) ;
2018-09-20 06:40:22 +00:00
SetAppDisplayName ( " Slic3r Prusa Edition " ) ;
2018-09-20 23:33:41 +00:00
// Slic3r::debugf "wxWidgets version %s, Wx version %s\n", wxVERSION_STRING, wxVERSION;
2018-09-20 06:40:22 +00:00
// Set the Slic3r data directory at the Slic3r XS module.
// Unix: ~/ .Slic3r
// Windows : "C:\Users\username\AppData\Roaming\Slic3r" or "C:\Documents and Settings\username\Application Data\Slic3r"
// Mac : "~/Library/Application Support/Slic3r"
2018-09-21 09:40:32 +00:00
if ( data_dir ( ) . empty ( ) )
2018-10-01 13:09:31 +00:00
set_data_dir ( wxStandardPaths : : Get ( ) . GetUserDataDir ( ) . ToUTF8 ( ) . data ( ) ) ;
2018-09-20 06:40:22 +00:00
2018-09-20 23:33:41 +00:00
app_config = new AppConfig ( ) ;
preset_bundle = new PresetBundle ( ) ;
2018-09-20 06:40:22 +00:00
// just checking for existence of Slic3r::data_dir is not enough : it may be an empty directory
// supplied as argument to --datadir; in that case we should still run the wizard
2018-12-03 12:14:28 +00:00
try {
preset_bundle - > setup_directories ( ) ;
} catch ( const std : : exception & ex ) {
show_error ( nullptr , ex . what ( ) ) ;
// Exit the application.
return false ;
}
2018-09-20 23:33:41 +00:00
app_conf_exists = app_config - > exists ( ) ;
2018-09-20 06:40:22 +00:00
// load settings
2018-12-03 12:14:28 +00:00
if ( app_conf_exists )
app_config - > load ( ) ;
2018-10-01 13:09:31 +00:00
app_config - > set ( " version " , SLIC3R_VERSION ) ;
2018-09-20 23:33:41 +00:00
app_config - > save ( ) ;
2018-09-20 06:40:22 +00:00
2018-10-01 13:09:31 +00:00
preset_updater = new PresetUpdater ( ) ;
2018-09-20 06:40:22 +00:00
2018-09-20 23:33:41 +00:00
load_language ( ) ;
2018-09-20 06:40:22 +00:00
// Suppress the '- default -' presets.
2018-10-31 15:22:36 +00:00
preset_bundle - > set_default_suppressed ( app_config - > get ( " no_defaults " ) = = " 1 " ) ;
2018-11-08 19:18:40 +00:00
try {
preset_bundle - > load_presets ( * app_config ) ;
2018-12-03 12:14:28 +00:00
} catch ( const std : : exception & ex ) {
show_error ( nullptr , ex . what ( ) ) ;
2018-11-08 19:18:40 +00:00
}
2018-09-20 06:40:22 +00:00
2018-10-01 13:09:31 +00:00
// Let the libslic3r know the callback, which will translate messages on demand.
Slic3r : : I18N : : set_translate_callback ( libslic3r_translate_callback ) ;
// initialize label colors and fonts
init_label_colours ( ) ;
init_fonts ( ) ;
2018-09-20 06:40:22 +00:00
// application frame
2018-12-06 13:47:53 +00:00
if ( wxImage : : FindHandler ( wxBITMAP_TYPE_PNG ) = = nullptr )
wxImage : : AddHandler ( new wxPNGHandler ( ) ) ;
2018-12-19 16:38:41 +00:00
mainframe = new MainFrame ( ) ;
2018-10-05 21:29:15 +00:00
sidebar ( ) . obj_list ( ) - > init_objects ( ) ; // propagate model objects to object list
2018-12-21 13:40:25 +00:00
// update_mode(); // do that later
2018-09-20 06:40:22 +00:00
SetTopWindow ( mainframe ) ;
2018-12-14 14:27:34 +00:00
m_printhost_job_queue . reset ( new PrintHostJobQueue ( mainframe - > printhost_queue_dlg ( ) ) ) ;
2018-11-15 11:25:08 +00:00
CallAfter ( [ this ] ( ) {
// temporary workaround for the correct behavior of the Scrolled sidebar panel
auto & panel = sidebar ( ) ;
if ( panel . obj_list ( ) - > GetMinHeight ( ) > 200 ) {
wxWindowUpdateLocker noUpdates_sidebar ( & panel ) ;
panel . obj_list ( ) - > SetMinSize ( wxSize ( - 1 , 200 ) ) ;
2018-12-21 13:40:25 +00:00
// panel.Layout();
2018-11-15 11:25:08 +00:00
}
2018-12-21 13:40:25 +00:00
update_mode ( ) ; // update view mode after fix of the object_list size
// to correct later layouts
2018-11-15 11:25:08 +00:00
} ) ;
2018-10-02 11:23:38 +00:00
Bind ( wxEVT_IDLE , [ this ] ( wxIdleEvent & event )
{
if ( app_config - > dirty ( ) )
app_config - > save ( ) ;
2018-12-20 19:12:26 +00:00
2019-01-02 12:42:29 +00:00
# if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
2018-12-20 19:12:26 +00:00
if ( this - > plater ( ) ! = nullptr )
this - > obj_manipul ( ) - > update_if_dirty ( ) ;
2019-01-02 12:42:29 +00:00
# endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
2018-10-02 11:23:38 +00:00
} ) ;
2018-09-20 06:40:22 +00:00
// On OS X the UI tends to freeze in weird ways if modal dialogs(config wizard, update notifications, ...)
// are shown before or in the same event callback with the main frame creation.
// Therefore we schedule them for later using CallAfter.
2018-10-31 11:56:08 +00:00
CallAfter ( [ this ] ( ) {
2018-12-03 12:14:28 +00:00
try {
if ( ! preset_updater - > config_update ( ) )
mainframe - > Close ( ) ;
} catch ( const std : : exception & ex ) {
show_error ( nullptr , ex . what ( ) ) ;
2018-10-02 11:23:38 +00:00
mainframe - > Close ( ) ;
2018-12-03 12:14:28 +00:00
}
2018-10-02 11:23:38 +00:00
} ) ;
2018-10-31 11:56:08 +00:00
CallAfter ( [ this ] ( ) {
2018-10-02 11:23:38 +00:00
if ( ! config_wizard_startup ( app_conf_exists ) ) {
// Only notify if there was not wizard so as not to bother too much ...
preset_updater - > slic3r_update_notify ( ) ;
}
preset_updater - > sync ( preset_bundle ) ;
2019-01-23 13:38:05 +00:00
load_current_presets ( ) ;
2018-10-02 11:23:38 +00:00
} ) ;
2018-09-20 06:40:22 +00:00
mainframe - > Show ( true ) ;
return true ;
}
2018-10-01 13:09:31 +00:00
unsigned GUI_App : : get_colour_approx_luma ( const wxColour & colour )
{
double r = colour . Red ( ) ;
double g = colour . Green ( ) ;
double b = colour . Blue ( ) ;
return std : : round ( std : : sqrt (
r * r * .241 +
g * g * .691 +
b * b * .068
) ) ;
}
void GUI_App : : init_label_colours ( )
{
auto luma = get_colour_approx_luma ( wxSystemSettings : : GetColour ( wxSYS_COLOUR_WINDOW ) ) ;
if ( luma > = 128 ) {
m_color_label_modified = wxColour ( 252 , 77 , 1 ) ;
m_color_label_sys = wxColour ( 26 , 132 , 57 ) ;
}
else {
m_color_label_modified = wxColour ( 253 , 111 , 40 ) ;
m_color_label_sys = wxColour ( 115 , 220 , 103 ) ;
}
m_color_label_default = wxSystemSettings : : GetColour ( wxSYS_COLOUR_WINDOWTEXT ) ;
}
void GUI_App : : update_label_colours_from_appconfig ( )
{
2018-10-31 11:56:08 +00:00
if ( app_config - > has ( " label_clr_sys " ) ) {
2018-10-01 13:09:31 +00:00
auto str = app_config - > get ( " label_clr_sys " ) ;
if ( str ! = " " )
m_color_label_sys = wxColour ( str ) ;
}
2018-10-31 11:56:08 +00:00
if ( app_config - > has ( " label_clr_modified " ) ) {
2018-10-01 13:09:31 +00:00
auto str = app_config - > get ( " label_clr_modified " ) ;
if ( str ! = " " )
m_color_label_modified = wxColour ( str ) ;
}
}
void GUI_App : : init_fonts ( )
{
m_small_font = wxSystemSettings : : GetFont ( wxSYS_DEFAULT_GUI_FONT ) ;
m_bold_font = wxSystemSettings : : GetFont ( wxSYS_DEFAULT_GUI_FONT ) . Bold ( ) ;
# ifdef __WXMAC__
m_small_font . SetPointSize ( 11 ) ;
m_bold_font . SetPointSize ( 13 ) ;
# endif /*__WXMAC__*/
}
void GUI_App : : set_label_clr_modified ( const wxColour & clr ) {
m_color_label_modified = clr ;
auto clr_str = wxString : : Format ( wxT ( " #%02X%02X%02X " ) , clr . Red ( ) , clr . Green ( ) , clr . Blue ( ) ) ;
std : : string str = clr_str . ToStdString ( ) ;
app_config - > set ( " label_clr_modified " , str ) ;
app_config - > save ( ) ;
}
void GUI_App : : set_label_clr_sys ( const wxColour & clr ) {
m_color_label_sys = clr ;
auto clr_str = wxString : : Format ( wxT ( " #%02X%02X%02X " ) , clr . Red ( ) , clr . Green ( ) , clr . Blue ( ) ) ;
std : : string str = clr_str . ToStdString ( ) ;
app_config - > set ( " label_clr_sys " , str ) ;
app_config - > save ( ) ;
}
2018-09-20 06:40:22 +00:00
void GUI_App : : recreate_GUI ( )
{
2018-10-01 13:09:31 +00:00
std : : cerr < < " recreate_GUI " < < std : : endl ;
2018-09-20 06:40:22 +00:00
2018-12-19 16:38:41 +00:00
MainFrame * topwindow = dynamic_cast < MainFrame * > ( GetTopWindow ( ) ) ;
mainframe = new MainFrame ( ) ;
2018-10-05 21:29:15 +00:00
sidebar ( ) . obj_list ( ) - > init_objects ( ) ; // propagate model objects to object list
2018-12-21 13:40:25 +00:00
// update_mode(); // do that later
2018-09-20 06:40:22 +00:00
if ( topwindow ) {
SetTopWindow ( mainframe ) ;
topwindow - > Destroy ( ) ;
}
2018-12-19 16:38:41 +00:00
m_printhost_job_queue . reset ( new PrintHostJobQueue ( mainframe - > printhost_queue_dlg ( ) ) ) ;
CallAfter ( [ this ] ( ) {
// temporary workaround for the correct behavior of the Scrolled sidebar panel
auto & panel = sidebar ( ) ;
if ( panel . obj_list ( ) - > GetMinHeight ( ) > 200 ) {
wxWindowUpdateLocker noUpdates_sidebar ( & panel ) ;
panel . obj_list ( ) - > SetMinSize ( wxSize ( - 1 , 200 ) ) ;
2018-12-21 13:40:25 +00:00
// panel.Layout();
2018-12-19 16:38:41 +00:00
}
2018-12-21 13:40:25 +00:00
update_mode ( ) ; // update view mode after fix of the object_list size
// to correct later layouts
2018-12-19 16:38:41 +00:00
} ) ;
mainframe - > Show ( true ) ;
2018-09-20 06:40:22 +00:00
// On OSX the UI was not initialized correctly if the wizard was called
// before the UI was up and running.
2018-10-31 11:56:08 +00:00
CallAfter ( [ ] ( ) {
2018-09-20 06:40:22 +00:00
// Run the config wizard, don't offer the "reset user profile" checkbox.
2018-10-02 11:23:38 +00:00
config_wizard_startup ( true ) ;
2018-09-20 06:40:22 +00:00
} ) ;
}
void GUI_App : : system_info ( )
{
2018-10-25 10:48:19 +00:00
SysInfoDialog dlg ;
dlg . ShowModal ( ) ;
dlg . Destroy ( ) ;
2018-09-20 06:40:22 +00:00
}
2018-12-19 12:06:24 +00:00
void GUI_App : : keyboard_shortcuts ( )
{
KBShortcutsDialog dlg ;
dlg . ShowModal ( ) ;
dlg . Destroy ( ) ;
}
2018-09-20 06:40:22 +00:00
// static method accepting a wxWindow object as first parameter
bool GUI_App : : catch_error ( std : : function < void ( ) > cb ,
// wxMessageDialog* message_dialog,
2018-10-31 11:56:08 +00:00
const std : : string & err /*= ""*/ )
{
2018-09-20 06:40:22 +00:00
if ( ! err . empty ( ) ) {
if ( cb )
cb ( ) ;
// if (message_dialog)
// message_dialog->(err, "Error", wxOK | wxICON_ERROR);
show_error ( /*this*/ nullptr , err ) ;
return true ;
}
return false ;
}
// static method accepting a wxWindow object as first parameter
2018-10-31 11:56:08 +00:00
void fatal_error ( wxWindow * parent )
{
2018-09-20 06:40:22 +00:00
show_error ( parent , " " ) ;
// exit 1; // #ys_FIXME
}
// Called after the Preferences dialog is closed and the program settings are saved.
// Update the UI based on the current preferences.
2018-10-31 11:56:08 +00:00
void GUI_App : : update_ui_from_settings ( )
{
2018-09-20 06:40:22 +00:00
mainframe - > update_ui_from_settings ( ) ;
}
2019-01-11 17:09:21 +00:00
void GUI_App : : persist_window_geometry ( wxTopLevelWindow * window )
{
const std : : string name = into_u8 ( window - > GetName ( ) ) ;
window - > Bind ( wxEVT_CLOSE_WINDOW , [ = ] ( wxCloseEvent & event ) {
window_pos_save ( window , name ) ;
event . Skip ( ) ;
} ) ;
window_pos_restore ( window , name ) ;
# ifdef _WIN32
// On windows, the wxEVT_SHOW is not received if the window is created maximized
// cf. https://groups.google.com/forum/#!topic/wx-users/c7ntMt6piRI
// so we sanitize the position right away
window_pos_sanitize ( window ) ;
# else
// On other platforms on the other hand it's needed to wait before the window is actually on screen
// and some initial round of events is complete otherwise position / display index is not reported correctly.
window - > Bind ( wxEVT_SHOW , [ = ] ( wxShowEvent & event ) {
CallAfter ( [ = ] ( ) {
window_pos_sanitize ( window ) ;
} ) ;
event . Skip ( ) ;
} ) ;
# endif
}
2018-11-15 14:27:39 +00:00
void GUI_App : : load_project ( wxWindow * parent , wxString & input_file )
{
input_file . Clear ( ) ;
wxFileDialog dialog ( parent ? parent : GetTopWindow ( ) ,
_ ( L ( " Choose one file (3MF): " ) ) ,
app_config - > get_last_dir ( ) , " " ,
2018-12-06 16:32:49 +00:00
file_wildcards ( FT_3MF ) , wxFD_OPEN | wxFD_FILE_MUST_EXIST ) ;
2018-09-20 11:12:35 +00:00
2018-11-15 14:27:39 +00:00
if ( dialog . ShowModal ( ) = = wxID_OK )
input_file = dialog . GetPath ( ) ;
}
void GUI_App : : import_model ( wxWindow * parent , wxArrayString & input_files )
2018-09-20 11:12:35 +00:00
{
2018-11-15 14:27:39 +00:00
input_files . Clear ( ) ;
wxFileDialog dialog ( parent ? parent : GetTopWindow ( ) ,
2018-09-20 11:12:35 +00:00
_ ( L ( " Choose one or more files (STL/OBJ/AMF/3MF/PRUSA): " ) ) ,
2019-01-02 14:11:05 +00:00
from_u8 ( app_config - > get_last_dir ( ) ) , " " ,
2018-12-06 16:32:49 +00:00
file_wildcards ( FT_MODEL ) , wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST ) ;
2018-09-20 11:12:35 +00:00
2018-11-15 14:27:39 +00:00
if ( dialog . ShowModal ( ) = = wxID_OK )
dialog . GetPaths ( input_files ) ;
2018-09-20 11:12:35 +00:00
}
2018-09-20 06:40:22 +00:00
2018-10-02 11:23:38 +00:00
// select language from the list of installed languages
bool GUI_App : : select_language ( wxArrayString & names ,
wxArrayLong & identifiers )
{
wxCHECK_MSG ( names . Count ( ) = = identifiers . Count ( ) , false ,
_ ( L ( " Array of language names and identifiers should have the same size. " ) ) ) ;
int init_selection = 0 ;
long current_language = m_wxLocale ? m_wxLocale - > GetLanguage ( ) : wxLANGUAGE_UNKNOWN ;
2018-10-31 11:56:08 +00:00
for ( auto lang : identifiers ) {
2018-10-02 11:23:38 +00:00
if ( lang = = current_language )
break ;
+ + init_selection ;
}
if ( init_selection = = identifiers . size ( ) )
init_selection = 0 ;
long index = wxGetSingleChoiceIndex ( _ ( L ( " Select the language " ) ) , _ ( L ( " Language " ) ) ,
names , init_selection ) ;
if ( index ! = - 1 )
{
m_wxLocale = new wxLocale ;
m_wxLocale - > Init ( identifiers [ index ] ) ;
2019-01-07 18:17:10 +00:00
m_wxLocale - > AddCatalogLookupPathPrefix ( from_u8 ( localization_dir ( ) ) ) ;
2018-12-19 13:50:56 +00:00
m_wxLocale - > AddCatalog ( /*GetAppName()*/ " Slic3rPE " ) ;
2019-01-04 14:42:44 +00:00
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
wxSetlocale ( LC_NUMERIC , " C " ) ;
2018-10-02 11:23:38 +00:00
Preset : : update_suffix_modified ( ) ;
return true ;
}
return false ;
}
// load language saved at application config
2018-09-20 23:33:41 +00:00
bool GUI_App : : load_language ( )
{
wxString language = wxEmptyString ;
if ( app_config - > has ( " translation_language " ) )
language = app_config - > get ( " translation_language " ) ;
if ( language . IsEmpty ( ) )
return false ;
wxArrayString names ;
wxArrayLong identifiers ;
get_installed_languages ( names , identifiers ) ;
for ( size_t i = 0 ; i < identifiers . Count ( ) ; i + + )
{
if ( wxLocale : : GetLanguageCanonicalName ( identifiers [ i ] ) = = language )
{
2018-10-02 11:23:38 +00:00
m_wxLocale = new wxLocale ;
m_wxLocale - > Init ( identifiers [ i ] ) ;
2019-01-07 18:17:10 +00:00
m_wxLocale - > AddCatalogLookupPathPrefix ( from_u8 ( localization_dir ( ) ) ) ;
2018-12-19 13:50:56 +00:00
m_wxLocale - > AddCatalog ( /*GetAppName()*/ " Slic3rPE " ) ;
2019-01-04 14:42:44 +00:00
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
2018-09-20 23:33:41 +00:00
wxSetlocale ( LC_NUMERIC , " C " ) ;
2019-01-02 14:35:40 +00:00
Preset : : update_suffix_modified ( ) ;
2018-09-20 23:33:41 +00:00
return true ;
}
}
return false ;
}
2018-10-02 11:23:38 +00:00
// save language at application config
void GUI_App : : save_language ( )
{
wxString language = wxEmptyString ;
if ( m_wxLocale )
language = m_wxLocale - > GetCanonicalName ( ) ;
2019-01-03 13:34:53 +00:00
app_config - > set ( " translation_language " , language . ToUTF8 ( ) . data ( ) ) ;
2018-10-02 11:23:38 +00:00
app_config - > save ( ) ;
}
// get list of installed languages
void GUI_App : : get_installed_languages ( wxArrayString & names , wxArrayLong & identifiers )
{
names . Clear ( ) ;
identifiers . Clear ( ) ;
2019-01-07 18:17:10 +00:00
wxDir dir ( from_u8 ( localization_dir ( ) ) ) ;
2018-10-02 11:23:38 +00:00
wxString filename ;
const wxLanguageInfo * langinfo ;
wxString name = wxLocale : : GetLanguageName ( wxLANGUAGE_DEFAULT ) ;
if ( ! name . IsEmpty ( ) )
{
names . Add ( _ ( L ( " Default " ) ) ) ;
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 ( ) +
2018-12-19 13:50:56 +00:00
/*GetAppName()*/ " Slic3rPE " +
wxT ( " .mo " ) ;
2018-10-02 11:23:38 +00:00
if ( wxFileExists ( full_file_name ) )
{
names . Add ( langinfo - > Description ) ;
identifiers . Add ( langinfo - > Language ) ;
}
}
}
}
2018-10-10 11:53:45 +00:00
Tab * GUI_App : : get_tab ( Preset : : Type type )
{
for ( Tab * tab : tabs_list )
if ( tab - > type ( ) = = type )
return tab ;
return nullptr ;
}
2019-01-10 10:05:58 +00:00
ConfigOptionMode GUI_App : : get_mode ( )
2018-09-20 23:33:41 +00:00
{
if ( ! app_config - > has ( " view_mode " ) )
2019-01-10 10:05:58 +00:00
return comSimple ;
2018-09-20 23:33:41 +00:00
const auto mode = app_config - > get ( " view_mode " ) ;
2019-01-10 10:05:58 +00:00
return mode = = " expert " ? comExpert :
mode = = " simple " ? comSimple : comAdvanced ;
2018-09-20 23:33:41 +00:00
}
2019-01-10 10:05:58 +00:00
void GUI_App : : save_mode ( const /*ConfigOptionMode*/ int mode )
{
const std : : string mode_str = mode = = comExpert ? " expert " :
mode = = comSimple ? " simple " : " advanced " ;
app_config - > set ( " view_mode " , mode_str ) ;
app_config - > save ( ) ;
update_mode ( ) ;
2018-12-21 08:19:00 +00:00
}
2018-10-03 13:14:52 +00:00
// Update view mode according to selected menu
void GUI_App : : update_mode ( )
{
2018-11-13 11:19:56 +00:00
wxWindowUpdateLocker noUpdates ( & sidebar ( ) ) ;
2018-10-03 13:14:52 +00:00
2019-01-10 10:05:58 +00:00
const ConfigOptionMode mode = wxGetApp ( ) . get_mode ( ) ;
2018-10-03 13:14:52 +00:00
2019-01-10 10:05:58 +00:00
obj_list ( ) - > get_sizer ( ) - > Show ( mode = = comExpert ) ;
2018-11-13 11:19:56 +00:00
sidebar ( ) . set_mode_value ( mode ) ;
2019-01-10 10:05:58 +00:00
// sidebar().show_buttons(mode == comExpert);
2018-11-13 11:19:56 +00:00
obj_list ( ) - > update_selections ( ) ;
2018-10-03 13:14:52 +00:00
2019-01-10 10:05:58 +00:00
sidebar ( ) . update_mode_sizer ( mode ) ;
2018-10-05 21:29:15 +00:00
sidebar ( ) . Layout ( ) ;
2018-10-19 11:55:29 +00:00
for ( auto tab : tabs_list )
2018-12-21 08:19:00 +00:00
tab - > update_visibility ( ) ;
2018-12-07 16:50:48 +00:00
plater ( ) - > update_object_menu ( ) ;
2018-10-03 13:14:52 +00:00
}
2018-09-20 23:33:41 +00:00
void GUI_App : : add_config_menu ( wxMenuBar * menu )
{
auto local_menu = new wxMenu ( ) ;
wxWindowID config_id_base = wxWindow : : NewControlId ( ( int ) ConfigMenuCnt ) ;
2019-01-21 11:34:28 +00:00
const auto config_wizard_name = _ ( ConfigWizard : : name ( true ) . wx_str ( ) ) ;
2018-09-20 23:33:41 +00:00
const auto config_wizard_tooltip = wxString : : Format ( _ ( L ( " Run %s " ) ) , config_wizard_name ) ;
// Cmd+, is standard on OS X - what about other operating systems?
local_menu - > Append ( config_id_base + ConfigMenuWizard , config_wizard_name + dots , config_wizard_tooltip ) ;
2019-01-21 11:34:28 +00:00
local_menu - > Append ( config_id_base + ConfigMenuSnapshots , _ ( L ( " &Configuration Snapshots " ) ) + dots , _ ( L ( " Inspect / activate configuration snapshots " ) ) ) ;
local_menu - > Append ( config_id_base + ConfigMenuTakeSnapshot , _ ( L ( " Take Configuration &Snapshot " ) ) , _ ( L ( " Capture a configuration snapshot " ) ) ) ;
2018-09-20 23:33:41 +00:00
// local_menu->Append(config_id_base + ConfigMenuUpdate, _(L("Check for updates")), _(L("Check for configuration updates")));
local_menu - > AppendSeparator ( ) ;
2019-01-21 11:34:28 +00:00
local_menu - > Append ( config_id_base + ConfigMenuPreferences , _ ( L ( " &Preferences " ) ) + dots + " \t Ctrl+P " , _ ( L ( " Application preferences " ) ) ) ;
2018-09-20 23:33:41 +00:00
local_menu - > AppendSeparator ( ) ;
auto mode_menu = new wxMenu ( ) ;
2018-11-21 09:21:12 +00:00
mode_menu - > AppendRadioItem ( config_id_base + ConfigMenuModeSimple , _ ( L ( " Simple " ) ) , _ ( L ( " Simple View Mode " ) ) ) ;
mode_menu - > AppendRadioItem ( config_id_base + ConfigMenuModeAdvanced , _ ( L ( " Advanced " ) ) , _ ( L ( " Advanced View Mode " ) ) ) ;
mode_menu - > AppendRadioItem ( config_id_base + ConfigMenuModeExpert , _ ( L ( " Expert " ) ) , _ ( L ( " Expert View Mode " ) ) ) ;
2019-01-10 10:05:58 +00:00
mode_menu - > Check ( config_id_base + ConfigMenuModeSimple + get_mode ( ) , true ) ;
2018-11-21 09:21:12 +00:00
local_menu - > AppendSubMenu ( mode_menu , _ ( L ( " Mode " ) ) , _ ( L ( " Slic3r View Mode " ) ) ) ;
2018-09-20 23:33:41 +00:00
local_menu - > AppendSeparator ( ) ;
2019-01-21 11:34:28 +00:00
local_menu - > Append ( config_id_base + ConfigMenuLanguage , _ ( L ( " Change Application &Language " ) ) ) ;
2018-09-20 23:33:41 +00:00
local_menu - > AppendSeparator ( ) ;
2019-01-21 11:34:28 +00:00
local_menu - > Append ( config_id_base + ConfigMenuFlashFirmware , _ ( L ( " Flash printer &firmware " ) ) , _ ( L ( " Upload a firmware image into an Arduino based printer " ) ) ) ;
2018-09-20 23:33:41 +00:00
// TODO: for when we're able to flash dictionaries
// local_menu->Append(config_id_base + FirmwareMenuDict, _(L("Flash language file")), _(L("Upload a language dictionary file into a Prusa printer")));
2018-10-31 11:56:08 +00:00
local_menu - > Bind ( wxEVT_MENU , [ this , config_id_base ] ( wxEvent & event ) {
2018-09-20 23:33:41 +00:00
switch ( event . GetId ( ) - config_id_base ) {
case ConfigMenuWizard :
config_wizard ( ConfigWizard : : RR_USER ) ;
break ;
case ConfigMenuTakeSnapshot :
// Take a configuration snapshot.
if ( check_unsaved_changes ( ) ) {
wxTextEntryDialog dlg ( nullptr , _ ( L ( " Taking configuration snapshot " ) ) , _ ( L ( " Snapshot name " ) ) ) ;
if ( dlg . ShowModal ( ) = = wxID_OK )
app_config - > set ( " on_snapshot " ,
Slic3r : : GUI : : Config : : SnapshotDB : : singleton ( ) . take_snapshot (
* app_config , Slic3r : : GUI : : Config : : Snapshot : : SNAPSHOT_USER , dlg . GetValue ( ) . ToUTF8 ( ) . data ( ) ) . id ) ;
}
break ;
case ConfigMenuSnapshots :
if ( check_unsaved_changes ( ) ) {
std : : string on_snapshot ;
if ( Config : : SnapshotDB : : singleton ( ) . is_on_snapshot ( * app_config ) )
on_snapshot = app_config - > get ( " on_snapshot " ) ;
ConfigSnapshotDialog dlg ( Slic3r : : GUI : : Config : : SnapshotDB : : singleton ( ) , on_snapshot ) ;
dlg . ShowModal ( ) ;
if ( ! dlg . snapshot_to_activate ( ) . empty ( ) ) {
if ( ! Config : : SnapshotDB : : singleton ( ) . is_on_snapshot ( * app_config ) )
Config : : SnapshotDB : : singleton ( ) . take_snapshot ( * app_config , Config : : Snapshot : : SNAPSHOT_BEFORE_ROLLBACK ) ;
app_config - > set ( " on_snapshot " ,
Config : : SnapshotDB : : singleton ( ) . restore_snapshot ( dlg . snapshot_to_activate ( ) , * app_config ) . id ) ;
preset_bundle - > load_presets ( * app_config ) ;
// Load the currently selected preset into the GUI, update the preset selection box.
load_current_presets ( ) ;
}
}
break ;
case ConfigMenuPreferences :
{
2018-10-02 11:23:38 +00:00
PreferencesDialog dlg ( mainframe ) ;
dlg . ShowModal ( ) ;
2018-09-20 23:33:41 +00:00
break ;
}
case ConfigMenuLanguage :
{
wxArrayString names ;
wxArrayLong identifiers ;
get_installed_languages ( names , identifiers ) ;
if ( select_language ( names , identifiers ) ) {
save_language ( ) ;
show_info ( mainframe - > m_tabpanel , _ ( L ( " Application will be restarted " ) ) , _ ( L ( " Attention! " ) ) ) ;
_3DScene : : remove_all_canvases ( ) ; // remove all canvas before recreate GUI
recreate_GUI ( ) ;
}
break ;
}
case ConfigMenuFlashFirmware :
FirmwareDialog : : run ( mainframe ) ;
break ;
default :
break ;
}
} ) ;
mode_menu - > Bind ( wxEVT_MENU , [ this , config_id_base ] ( wxEvent & event ) {
2018-10-19 11:55:29 +00:00
int id_mode = event . GetId ( ) - config_id_base ;
2019-01-10 10:05:58 +00:00
save_mode ( id_mode - ConfigMenuModeSimple ) ;
2018-09-20 23:33:41 +00:00
} ) ;
menu - > Append ( local_menu , _ ( L ( " &Configuration " ) ) ) ;
}
// This is called when closing the application, when loading a config file or when starting the config wizard
// to notify the user whether he is aware that some preset changes will be lost.
bool GUI_App : : check_unsaved_changes ( )
{
std : : string dirty ;
2018-10-31 15:22:36 +00:00
PrinterTechnology printer_technology = preset_bundle - > printers . get_edited_preset ( ) . printer_technology ( ) ;
2018-09-20 23:33:41 +00:00
for ( Tab * tab : tabs_list )
2018-10-31 15:22:36 +00:00
if ( tab - > supports_printer_technology ( printer_technology ) & & tab - > current_preset_is_dirty ( ) )
2018-09-20 23:33:41 +00:00
if ( dirty . empty ( ) )
dirty = tab - > name ( ) ;
else
dirty + = std : : string ( " , " ) + tab - > name ( ) ;
if ( dirty . empty ( ) )
// No changes, the application may close or reload presets.
return true ;
// Ask the user.
auto dialog = new wxMessageDialog ( mainframe ,
_ ( L ( " You have unsaved changes " ) ) + dirty + _ ( L ( " . Discard changes and continue anyway? " ) ) ,
_ ( L ( " Unsaved Presets " ) ) ,
wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT ) ;
return dialog - > ShowModal ( ) = = wxID_YES ;
}
2018-10-01 13:09:31 +00:00
bool GUI_App : : checked_tab ( Tab * tab )
{
bool ret = true ;
if ( find ( tabs_list . begin ( ) , tabs_list . end ( ) , tab ) = = tabs_list . end ( ) )
ret = false ;
return ret ;
}
void GUI_App : : delete_tab_from_list ( Tab * tab )
{
std : : vector < Tab * > : : iterator itr = find ( tabs_list . begin ( ) , tabs_list . end ( ) , tab ) ;
if ( itr ! = tabs_list . end ( ) )
tabs_list . erase ( itr ) ;
}
// Update UI / Tabs to reflect changes in the currently loaded presets
void GUI_App : : load_current_presets ( )
{
2018-10-31 15:22:36 +00:00
PrinterTechnology printer_technology = preset_bundle - > printers . get_edited_preset ( ) . printer_technology ( ) ;
2018-12-03 12:14:28 +00:00
this - > plater ( ) - > set_printer_technology ( printer_technology ) ;
2018-10-31 15:22:36 +00:00
for ( Tab * tab : tabs_list )
2018-10-31 17:05:25 +00:00
if ( tab - > supports_printer_technology ( printer_technology ) ) {
if ( tab - > name ( ) = = " printer " )
static_cast < TabPrinter * > ( tab ) - > update_pages ( ) ;
tab - > load_current_preset ( ) ;
}
2018-10-01 13:09:31 +00:00
}
2019-01-09 14:40:12 +00:00
# ifdef __APPLE__
// wxWidgets override to get an event on open files.
void GUI_App : : MacOpenFiles ( const wxArrayString & fileNames )
{
std : : vector < std : : string > files ;
2019-01-09 15:05:36 +00:00
for ( size_t i = 0 ; i < fileNames . GetCount ( ) ; + + i )
2019-01-09 14:40:12 +00:00
files . emplace_back ( fileNames [ i ] . ToUTF8 ( ) . data ( ) ) ;
this - > plater ( ) - > load_files ( files , true , true ) ;
}
# endif /* __APPLE */
2018-10-04 14:43:10 +00:00
Sidebar & GUI_App : : sidebar ( )
{
2018-10-24 10:57:23 +00:00
return plater_ - > sidebar ( ) ;
2018-10-04 14:43:10 +00:00
}
ObjectManipulation * GUI_App : : obj_manipul ( )
{
2019-01-14 13:42:21 +00:00
// If this method is called before plater_ has been initialized, return nullptr (to avoid a crash)
return ( plater_ ! = nullptr ) ? sidebar ( ) . obj_manipul ( ) : nullptr ;
2018-10-04 14:43:10 +00:00
}
2018-11-09 17:39:07 +00:00
ObjectSettings * GUI_App : : obj_settings ( )
{
return sidebar ( ) . obj_settings ( ) ;
}
2018-10-05 21:29:15 +00:00
ObjectList * GUI_App : : obj_list ( )
2018-09-20 23:33:41 +00:00
{
2018-10-05 21:29:15 +00:00
return sidebar ( ) . obj_list ( ) ;
2018-09-20 23:33:41 +00:00
}
2018-10-08 14:27:38 +00:00
Plater * GUI_App : : plater ( )
{
2018-10-24 10:57:23 +00:00
return plater_ ;
2018-10-08 14:27:38 +00:00
}
2018-10-05 21:29:15 +00:00
ModelObjectPtrs * GUI_App : : model_objects ( )
{
2018-10-24 10:57:23 +00:00
return & plater_ - > model ( ) . objects ;
2018-10-05 21:29:15 +00:00
}
2018-09-20 23:33:41 +00:00
2018-10-05 21:29:15 +00:00
wxNotebook * GUI_App : : tab_panel ( ) const
{
return mainframe - > m_tabpanel ;
}
2018-09-20 23:33:41 +00:00
2019-01-11 17:09:21 +00:00
void GUI_App : : window_pos_save ( wxTopLevelWindow * window , const std : : string & name )
{
if ( name . empty ( ) ) { return ; }
const auto config_key = ( boost : : format ( " window_%1% " ) % name ) . str ( ) ;
WindowMetrics metrics = WindowMetrics : : from_window ( window ) ;
app_config - > set ( config_key , metrics . serialize ( ) ) ;
app_config - > save ( ) ;
}
void GUI_App : : window_pos_restore ( wxTopLevelWindow * window , const std : : string & name )
{
if ( name . empty ( ) ) { return ; }
const auto config_key = ( boost : : format ( " window_%1% " ) % name ) . str ( ) ;
if ( ! app_config - > has ( config_key ) ) { return ; }
auto metrics = WindowMetrics : : deserialize ( app_config - > get ( config_key ) ) ;
if ( ! metrics ) { return ; }
window - > SetSize ( metrics - > get_rect ( ) ) ;
window - > Maximize ( metrics - > get_maximized ( ) ) ;
}
void GUI_App : : window_pos_sanitize ( wxTopLevelWindow * window )
{
unsigned display_idx = wxDisplay : : GetFromWindow ( window ) ;
wxRect display ;
if ( display_idx = = wxNOT_FOUND ) {
display = wxDisplay ( 0u ) . GetClientArea ( ) ;
window - > Move ( display . GetTopLeft ( ) ) ;
} else {
display = wxDisplay ( display_idx ) . GetClientArea ( ) ;
}
auto metrics = WindowMetrics : : from_window ( window ) ;
metrics . sanitize_for_display ( display ) ;
if ( window - > GetScreenRect ( ) ! = metrics . get_rect ( ) ) {
window - > SetSize ( metrics . get_rect ( ) ) ;
}
}
2018-09-20 06:40:22 +00:00
// static method accepting a wxWindow object as first parameter
// void warning_catcher{
// my($self, $message_dialog) = @_;
// return sub{
// my $message = shift;
// return if $message = ~/ GLUquadricObjPtr | Attempt to free unreferenced scalar / ;
// my @params = ($message, 'Warning', wxOK | wxICON_WARNING);
// $message_dialog
// ? $message_dialog->(@params)
// : Wx::MessageDialog->new($self, @params)->ShowModal;
// };
// }
// Do we need this function???
2018-10-31 11:56:08 +00:00
// void GUI_App::notify(message) {
2018-09-20 06:40:22 +00:00
// auto frame = GetTopWindow();
// // try harder to attract user attention on OS X
// if (!frame->IsActive())
// frame->RequestUserAttention(defined(__WXOSX__/*&Wx::wxMAC */)? wxUSER_ATTENTION_ERROR : wxUSER_ATTENTION_INFO);
//
// // There used to be notifier using a Growl application for OSX, but Growl is dead.
// // The notifier also supported the Linux X D - bus notifications, but that support was broken.
// //TODO use wxNotificationMessage ?
// }
} // GUI
2018-11-12 17:09:47 +00:00
} //Slic3r