2018-09-20 08:40:22 +02:00
#include "GUI_App.hpp"
2018-10-05 23:29:15 +02:00
#include "GUI_ObjectList.hpp"
2018-10-04 16:43:10 +02:00
#include "GUI_ObjectManipulation.hpp"
2018-09-20 08:40:22 +02:00
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
2018-09-21 11:40:32 +02:00
#include <boost/filesystem.hpp>
2018-09-20 08:40:22 +02:00
#include <wx/stdpaths.h>
#include <wx/imagpng.h>
#include <wx/display.h>
#include <wx/menu.h>
#include <wx/menuitem.h>
2018-09-20 13:12:35 +02:00
#include <wx/filedlg.h>
2018-10-02 13:23:38 +02:00
#include <wx/dir.h>
2018-09-20 08:40:22 +02:00
#include "Utils.hpp"
#include "GUI.hpp"
#include "AppConfig.hpp"
#include "PresetBundle.hpp"
#include "3DScene.hpp"
2018-10-05 23:29:15 +02:00
#include "Model.hpp"
2018-09-20 08:40:22 +02:00
#include "../Utils/PresetUpdater.hpp"
2018-09-21 01:33:41 +02:00
#include "ConfigWizard_private.hpp"
#include "slic3r/Config/Snapshot.hpp"
#include "ConfigSnapshotDialog.hpp"
#include "FirmwareDialog.hpp"
#include "Preferences.hpp"
#include "Tab.hpp"
2018-10-01 15:09:31 +02:00
#include <I18N.hpp>
2018-10-03 15:14:52 +02:00
#include <wx/wupdlock.h>
2018-09-20 08:40:22 +02:00
namespace Slic3r {
namespace GUI {
2018-10-04 11:12:55 +02:00
const wxString file_wildcards [ FT_SIZE ] = {
/* 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-10-01 15:09:31 +02:00
static std :: string libslic3r_translate_callback ( const char * s ) { return wxGetTranslation ( wxString ( s , wxConvUTF8 )). utf8_str (). data (); }
2018-09-21 01:33:41 +02:00
IMPLEMENT_APP ( GUI_App )
2018-09-20 08:40:22 +02:00
bool GUI_App :: OnInit ()
{
SetAppName ( "Slic3rPE" );
SetAppDisplayName ( "Slic3r Prusa Edition" );
2018-09-21 01:33:41 +02:00
// Slic3r::debugf "wxWidgets version %s, Wx version %s\n", wxVERSION_STRING, wxVERSION;
2018-09-20 08:40:22 +02: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 11:40:32 +02:00
if ( data_dir (). empty ())
2018-10-01 15:09:31 +02:00
set_data_dir ( wxStandardPaths :: Get (). GetUserDataDir (). ToUTF8 (). data ());
2018-09-20 08:40:22 +02:00
2018-09-21 01:33:41 +02:00
app_config = new AppConfig ();
preset_bundle = new PresetBundle ();
2018-09-20 08:40:22 +02: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
// eval{
2018-09-21 01:33:41 +02:00
preset_bundle -> setup_directories ();
2018-09-20 08:40:22 +02:00
// };
// if ($@) {
// warn $@ . "\n";
// fatal_error(undef, $@);
// }
2018-09-21 01:33:41 +02:00
app_conf_exists = app_config -> exists ();
2018-09-20 08:40:22 +02:00
// load settings
2018-09-21 01:33:41 +02:00
if ( app_conf_exists ) app_config -> load ();
2018-10-01 15:09:31 +02:00
app_config -> set ( "version" , SLIC3R_VERSION );
2018-09-21 01:33:41 +02:00
app_config -> save ();
2018-09-20 08:40:22 +02:00
2018-10-01 15:09:31 +02:00
preset_updater = new PresetUpdater ();
2018-09-20 08:40:22 +02:00
2018-09-21 01:33:41 +02:00
load_language ();
2018-09-20 08:40:22 +02:00
// Suppress the '- default -' presets.
2018-09-21 01:33:41 +02:00
preset_bundle -> set_default_suppressed ( app_config -> get ( "no_defaults" ). empty () ? false : true );
2018-09-20 08:40:22 +02:00
// eval{
2018-09-21 01:33:41 +02:00
preset_bundle -> load_presets ( * app_config );
2018-09-20 08:40:22 +02:00
// };
// if ($@) {
// warn $@ . "\n";
// show_error(undef, $@);
// }
2018-10-01 15:09:31 +02: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 08:40:22 +02:00
// application frame
2018-10-01 15:09:31 +02:00
std :: cerr << "Creating main frame..." << std :: endl ;
2018-09-20 08:40:22 +02:00
// wxImage::FindHandlerType(wxBITMAP_TYPE_PNG) ||
wxImage :: AddHandler ( new wxPNGHandler ());
2018-10-02 13:23:38 +02:00
mainframe = new MainFrame ( no_plater , false );
2018-10-05 23:29:15 +02:00
sidebar (). obj_list () -> init_objects (); // propagate model objects to object list
update_mode ();
2018-09-20 08:40:22 +02:00
SetTopWindow ( mainframe );
// This makes CallAfter() work
2018-10-02 13:23:38 +02:00
Bind ( wxEVT_IDLE , [ this ]( wxIdleEvent & event )
{
std :: function < void () > cur_cb { nullptr };
// try to get the mutex. If we can't, just skip this idle event and get the next one.
if ( ! callback_register . try_lock ()) return ;
// pop callback
if ( m_cb . size () != 0 ){
cur_cb = m_cb . top ();
m_cb . pop ();
}
// unlock mutex
this -> callback_register . unlock ();
try { // call the function if it's not nullptr;
if ( cur_cb != nullptr ) cur_cb ();
}
catch ( std :: exception & e ) {
std :: cerr << "Exception thrown: " << e . what () << std :: endl ;
}
if ( app_config -> dirty ())
app_config -> save ();
});
2018-09-20 08:40:22 +02: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-02 13:23:38 +02:00
CallAfter ([ this ](){
// eval{
if ( ! preset_updater -> config_update ())
mainframe -> Close ();
// };
// if ($@) {
// show_error(undef, $@);
// mainframe->Close();
// }
});
CallAfter ([ this ](){
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 );
});
2018-09-20 08:40:22 +02:00
mainframe -> Show ( true );
return true ;
}
2018-10-01 15:09:31 +02: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 ()
{
if ( app_config -> has ( "label_clr_sys" )){
auto str = app_config -> get ( "label_clr_sys" );
if ( str != "" )
m_color_label_sys = wxColour ( str );
}
if ( app_config -> has ( "label_clr_modified" )){
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 08:40:22 +02:00
void GUI_App :: recreate_GUI ()
{
2018-10-01 15:09:31 +02:00
std :: cerr << "recreate_GUI" << std :: endl ;
2018-09-20 08:40:22 +02:00
auto topwindow = GetTopWindow ();
2018-10-02 13:23:38 +02:00
mainframe = new MainFrame ( no_plater , false );
2018-10-05 23:29:15 +02:00
sidebar (). obj_list () -> init_objects (); // propagate model objects to object list
update_mode ();
2018-09-20 08:40:22 +02:00
if ( topwindow ) {
SetTopWindow ( mainframe );
topwindow -> Destroy ();
}
// On OSX the UI was not initialized correctly if the wizard was called
// before the UI was up and running.
CallAfter ([](){
// Run the config wizard, don't offer the "reset user profile" checkbox.
2018-10-02 13:23:38 +02:00
config_wizard_startup ( true );
2018-09-20 08:40:22 +02:00
});
}
void GUI_App :: system_info ()
{
// auto slic3r_info = Slic3r::slic3r_info(format = > 'html');
// auto copyright_info = Slic3r::copyright_info(format = > 'html');
// auto system_info = Slic3r::system_info(format = > 'html');
std :: string opengl_info = "" ;
std :: string opengl_info_txt = "" ;
if ( mainframe && mainframe -> m_plater /*&& mainframe->m_plater->canvas3D*/ ) {
opengl_info = _3DScene :: get_gl_info ( true , true );
opengl_info_txt = _3DScene :: get_gl_info ( false , true );
}
// auto about = new SystemInfo(nullptr, slic3r_info, /*copyright_info,*/system_info, opengl_info,
// text_info = > Slic3r::slic3r_info.Slic3r::system_info.$opengl_info_txt,
// );
// about->ShowModal();
// about->Destroy();
}
// static method accepting a wxWindow object as first parameter
bool GUI_App :: catch_error ( std :: function < void () > cb ,
// wxMessageDialog* message_dialog,
const std :: string & err /*= ""*/ ){
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
void fatal_error ( wxWindow * parent ){
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.
void GUI_App :: update_ui_from_settings (){
mainframe -> update_ui_from_settings ();
}
2018-09-20 13:12:35 +02:00
void GUI_App :: open_model ( wxWindow * parent , wxArrayString & input_files )
{
auto dialog = new wxFileDialog ( parent ? parent : GetTopWindow (),
_ ( L ( "Choose one or more files (STL/OBJ/AMF/3MF/PRUSA):" )),
app_config -> get_last_dir (), "" ,
2018-10-04 11:12:55 +02:00
file_wildcards [ FT_MODEL ], wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST );
2018-09-20 13:12:35 +02:00
if ( dialog -> ShowModal () != wxID_OK ) {
dialog -> Destroy ();
return ;
}
dialog -> GetPaths ( input_files );
dialog -> Destroy ();
}
2018-09-20 08:40:22 +02:00
void GUI_App :: CallAfter ( std :: function < void () > cb )
{
// set mutex
callback_register . lock ();
// push function onto stack
m_cb . emplace ( cb );
// unset mutex
callback_register . unlock ();
}
wxMenuItem * GUI_App :: append_submenu ( wxMenu * menu ,
wxMenu * sub_menu ,
int id ,
const wxString & string ,
const wxString & description ,
const std :: string & icon )
{
if ( id == wxID_ANY )
id = wxNewId ();
auto item = new wxMenuItem ( menu , id , string , description );
if ( ! icon . empty ())
item -> SetBitmap ( wxBitmap ( Slic3r :: var ( icon ), wxBITMAP_TYPE_PNG ));
item -> SetSubMenu ( sub_menu );
menu -> Append ( item );
return item ;
}
void GUI_App :: save_window_pos ( wxTopLevelWindow * window , const std :: string & name ){
int x , y ;
window -> GetScreenPosition ( & x , & y );
app_config -> set ( name + "_pos" , wxString :: Format ( "%d,%d" , x , y ). ToStdString ());
window -> GetSize ( & x , & y );
app_config -> set ( name + "_size" , wxString :: Format ( "%d,%d" , x , y ). ToStdString ());
app_config -> set ( name + "_maximized" , window -> IsMaximized () ? "1" : "0" );
app_config -> save ();
}
2018-10-02 13:23:38 +02:00
void GUI_App :: restore_window_pos ( wxTopLevelWindow * window , const std :: string & name )
{
2018-09-20 08:40:22 +02:00
if ( ! app_config -> has ( name + "_pos" ))
return ;
std :: string str = app_config -> get ( name + "_size" );
std :: vector < std :: string > values ;
boost :: split ( values , str , boost :: is_any_of ( "," ));
wxSize size = wxSize ( atoi ( values [ 0 ]. c_str ()), atoi ( values [ 1 ]. c_str ()));
window -> SetSize ( size );
auto display = ( new wxDisplay ()) -> GetClientArea ();
str = app_config -> get ( name + "_pos" );
values . resize ( 0 );
boost :: split ( values , str , boost :: is_any_of ( "," ));
wxPoint pos = wxPoint ( atoi ( values [ 0 ]. c_str ()), atoi ( values [ 1 ]. c_str ()));
if ( pos . x + 0.5 * size . GetWidth () < display . GetRight () &&
pos . y + 0.5 * size . GetHeight () < display . GetBottom ())
window -> Move ( pos );
if ( app_config -> get ( name + "_maximized" ) == "1" )
window -> Maximize ();
}
2018-10-02 13:23:38 +02: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 ;
for ( auto lang : identifiers ){
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 ]);
m_wxLocale -> AddCatalogLookupPathPrefix ( localization_dir ());
m_wxLocale -> AddCatalog ( GetAppName ());
wxSetlocale ( LC_NUMERIC , "C" );
Preset :: update_suffix_modified ();
return true ;
}
return false ;
}
// load language saved at application config
2018-09-21 01:33:41 +02: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 13:23:38 +02:00
m_wxLocale = new wxLocale ;
m_wxLocale -> Init ( identifiers [ i ]);
m_wxLocale -> AddCatalogLookupPathPrefix ( localization_dir ());
m_wxLocale -> AddCatalog ( GetAppName ());
2018-09-21 01:33:41 +02:00
wxSetlocale ( LC_NUMERIC , "C" );
Preset :: update_suffix_modified ();
return true ;
}
}
return false ;
}
2018-10-02 13:23:38 +02:00
// save language at application config
void GUI_App :: save_language ()
{
wxString language = wxEmptyString ;
if ( m_wxLocale )
language = m_wxLocale -> GetCanonicalName ();
app_config -> set ( "translation_language" , language . ToStdString ());
app_config -> save ();
}
// get list of installed languages
void GUI_App :: get_installed_languages ( wxArrayString & names , wxArrayLong & identifiers )
{
names . Clear ();
identifiers . Clear ();
wxDir dir ( localization_dir ());
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 () +
GetAppName () + wxT ( ".mo" );
if ( wxFileExists ( full_file_name ))
{
names . Add ( langinfo -> Description );
identifiers . Add ( langinfo -> Language );
}
}
}
}
2018-10-10 13:53:45 +02:00
Tab * GUI_App :: get_tab ( Preset :: Type type )
{
for ( Tab * tab : tabs_list )
if ( tab -> type () == type )
return tab ;
return nullptr ;
}
2018-09-21 01:33:41 +02:00
ConfigMenuIDs GUI_App :: get_view_mode ()
{
if ( ! app_config -> has ( "view_mode" ))
return ConfigMenuModeSimple ;
const auto mode = app_config -> get ( "view_mode" );
return mode == "expert" ? ConfigMenuModeExpert : ConfigMenuModeSimple ;
}
2018-10-03 15:14:52 +02:00
// Update view mode according to selected menu
void GUI_App :: update_mode ()
{
2018-10-05 23:29:15 +02:00
wxWindowUpdateLocker noUpdates ( mainframe -> m_plater );
2018-10-03 15:14:52 +02:00
ConfigMenuIDs mode = wxGetApp (). get_view_mode ();
2018-10-05 23:29:15 +02:00
obj_list () -> get_sizer () -> Show ( mode == ConfigMenuModeExpert );
sidebar (). show_info_sizers ( mode == ConfigMenuModeExpert );
sidebar (). show_buttons ( mode == ConfigMenuModeExpert );
obj_manipul () -> show_object_name ( mode == ConfigMenuModeSimple );
obj_list () -> update_manipulation_sizer ( mode == ConfigMenuModeSimple );
2018-10-03 15:14:52 +02:00
2018-10-05 23:29:15 +02:00
sidebar (). Layout ();
mainframe -> m_plater -> Layout ();
2018-10-03 15:14:52 +02:00
}
2018-09-21 01:33:41 +02:00
void GUI_App :: add_config_menu ( wxMenuBar * menu )
{
auto local_menu = new wxMenu ();
wxWindowID config_id_base = wxWindow :: NewControlId (( int ) ConfigMenuCnt );
const auto config_wizard_name = _ ( ConfigWizard :: name (). wx_str ());
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 );
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" )));
// local_menu->Append(config_id_base + ConfigMenuUpdate, _(L("Check for updates")), _(L("Check for configuration updates")));
local_menu -> AppendSeparator ();
local_menu -> Append ( config_id_base + ConfigMenuPreferences , _ ( L ( "Preferences" )) + dots + " \t Ctrl+," , _ ( L ( "Application preferences" )));
local_menu -> AppendSeparator ();
auto mode_menu = new wxMenu ();
mode_menu -> AppendRadioItem ( config_id_base + ConfigMenuModeSimple , _ ( L ( "&Simple" )), _ ( L ( "Simple View Mode" )));
mode_menu -> AppendRadioItem ( config_id_base + ConfigMenuModeExpert , _ ( L ( "&Expert" )), _ ( L ( "Expert View Mode" )));
mode_menu -> Check ( config_id_base + get_view_mode (), true );
local_menu -> AppendSubMenu ( mode_menu , _ ( L ( "&Mode" )), _ ( L ( "Slic3r View Mode" )));
local_menu -> AppendSeparator ();
local_menu -> Append ( config_id_base + ConfigMenuLanguage , _ ( L ( "Change Application Language" )));
local_menu -> AppendSeparator ();
local_menu -> Append ( config_id_base + ConfigMenuFlashFirmware , _ ( L ( "Flash printer firmware" )), _ ( L ( "Upload a firmware image into an Arduino based printer" )));
// 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")));
local_menu -> Bind ( wxEVT_MENU , [ this , config_id_base ]( wxEvent & event ){
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 13:23:38 +02:00
PreferencesDialog dlg ( mainframe );
dlg . ShowModal ();
2018-09-21 01:33:41 +02: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 ) {
std :: string mode = event . GetId () - config_id_base == ConfigMenuModeExpert ?
"expert" : "simple" ;
app_config -> set ( "view_mode" , mode );
app_config -> save ();
update_mode ();
});
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 ;
for ( Tab * tab : tabs_list )
if ( tab -> current_preset_is_dirty ())
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 15:09:31 +02: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 ()
{
for ( Tab * tab : tabs_list ) {
tab -> load_current_preset ();
}
}
2018-10-04 16:43:10 +02:00
Sidebar & GUI_App :: sidebar ()
{
return mainframe -> m_plater -> sidebar ();
}
ObjectManipulation * GUI_App :: obj_manipul ()
{
return sidebar (). obj_manipul ();
}
2018-10-05 23:29:15 +02:00
ObjectList * GUI_App :: obj_list ()
{
return sidebar (). obj_list ();
}
2018-10-08 16:27:38 +02:00
Plater * GUI_App :: plater ()
{
return mainframe -> m_plater ;
}
2018-10-11 15:57:09 +02:00
wxGLCanvas * GUI_App :: canvas3D ()
{
return mainframe -> m_plater -> canvas3D ();
}
2018-10-05 23:29:15 +02:00
ModelObjectPtrs * GUI_App :: model_objects ()
{
return & mainframe -> m_plater -> model (). objects ;
}
2018-10-04 16:43:10 +02:00
wxNotebook * GUI_App :: tab_panel () const
2018-09-21 01:33:41 +02:00
{
return mainframe -> m_tabpanel ;
}
2018-09-20 08:40:22 +02: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???
// void GUI_App::notify(message){
// 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
} //Slic3r