2020-09-08 11:40:06 +02:00
#include "libslic3r/Technologies.hpp"
2018-09-20 08:40:22 +02:00
#include "GUI_App.hpp"
2020-10-22 16:28:49 +02:00
#include "GUI_Init.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-11-26 14:41:58 +01:00
#include "I18N.hpp"
2018-09-20 08:40:22 +02:00
2019-05-03 16:27:56 +02:00
#include <algorithm>
#include <iterator>
2019-02-14 15:28:18 +01:00
#include <exception>
2019-08-29 14:07:45 +02:00
#include <cstdlib>
2018-09-20 08:40:22 +02:00
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
2019-02-14 15:28:18 +01:00
#include <boost/log/trivial.hpp>
2020-03-13 14:19:02 +01:00
#include <boost/nowide/convert.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>
2019-03-26 10:08:57 +01:00
#include <wx/progdlg.h>
2018-10-02 13:23:38 +02:00
#include <wx/dir.h>
2018-11-26 14:41:58 +01:00
#include <wx/wupdlock.h>
2019-01-04 12:06:25 +01:00
#include <wx/filefn.h>
2019-03-18 12:48:39 +01:00
#include <wx/sysopt.h>
2020-04-22 17:14:09 +02:00
#include <wx/richmsgdlg.h>
2019-04-09 11:28:11 +02:00
#include <wx/log.h>
2019-05-03 16:27:56 +02:00
#include <wx/intl.h>
2018-11-26 14:41:58 +01:00
2020-07-21 16:21:18 +02:00
#include <wx/dialog.h>
#include <wx/textctrl.h>
2020-09-04 13:42:44 +02:00
#include <wx/splash.h>
2020-10-06 10:33:05 +02:00
#include <wx/fontutil.h>
2020-07-21 16:21:18 +02:00
2018-11-26 14:41:58 +01:00
#include "libslic3r/Utils.hpp"
#include "libslic3r/Model.hpp"
#include "libslic3r/I18N.hpp"
2020-06-16 16:58:41 +02:00
#include "libslic3r/PresetBundle.hpp"
2018-09-20 08:40:22 +02:00
#include "GUI.hpp"
2018-10-17 14:01:10 +02:00
#include "GUI_Utils.hpp"
2020-03-04 11:32:22 +01:00
#include "3DScene.hpp"
2020-05-26 17:42:57 +02:00
#include "MainFrame.hpp"
#include "Plater.hpp"
2020-08-05 13:30:05 +02:00
#include "GLCanvas3D.hpp"
2018-09-20 08:40:22 +02:00
#include "../Utils/PresetUpdater.hpp"
2018-12-11 10:33:11 +01:00
#include "../Utils/PrintHost.hpp"
2020-10-06 09:56:36 +02:00
#include "../Utils/Process.hpp"
2019-04-26 16:59:14 +02:00
#include "../Utils/MacDarkMode.hpp"
2018-09-21 01:33:41 +02:00
#include "slic3r/Config/Snapshot.hpp"
#include "ConfigSnapshotDialog.hpp"
#include "FirmwareDialog.hpp"
#include "Preferences.hpp"
#include "Tab.hpp"
2018-10-25 12:48:19 +02:00
#include "SysInfoDialog.hpp"
2018-12-19 13:06:24 +01:00
#include "KBShortcutsDialog.hpp"
2019-06-04 18:01:41 +02:00
#include "UpdateDialogs.hpp"
2020-03-31 09:01:48 +02:00
#include "Mouse3DController.hpp"
2019-11-27 15:47:37 +01:00
#include "RemovableDriveManager.hpp"
2020-04-29 10:50:28 +02:00
#include "InstanceCheck.hpp"
2020-08-03 15:36:55 +02:00
#include "NotificationManager.hpp"
2020-08-14 18:17:16 +02:00
#include "UnsavedChangesDialog.hpp"
2020-10-19 14:17:45 +02:00
#include "SavePresetDialog.hpp"
2018-09-20 08:40:22 +02:00
2020-09-28 20:41:22 +02:00
#include "BitmapCache.hpp"
2019-05-03 15:50:05 +02:00
#ifdef __WXMSW__
2020-03-13 14:19:02 +01:00
#include <dbt.h>
2020-03-27 08:10:00 +01:00
#include <shlobj.h>
2019-05-03 15:50:05 +02:00
#endif // __WXMSW__
2019-12-03 12:44:20 +01:00
#if ENABLE_THUMBNAIL_GENERATOR_DEBUG
2019-10-25 12:18:10 +02:00
#include <boost/beast/core/detail/base64.hpp>
2019-10-25 14:32:31 +02:00
#include <boost/nowide/fstream.hpp>
2019-12-03 12:44:20 +01:00
#endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG
2019-10-25 12:18:10 +02:00
2018-09-20 08:40:22 +02:00
namespace Slic3r {
namespace GUI {
2020-03-13 14:19:02 +01:00
class MainFrame ;
2018-10-04 11:12:55 +02:00
2020-09-04 20:25:27 +02:00
class SplashScreen : public wxSplashScreen
{
public :
2020-10-05 19:53:24 +02:00
SplashScreen ( const wxBitmap & bitmap , long splashStyle , int milliseconds , wxPoint pos = wxDefaultPosition )
2020-11-26 13:45:30 +01:00
: wxSplashScreen ( bitmap , splashStyle , milliseconds , static_cast < wxWindow *> ( wxGetApp (). mainframe ), wxID_ANY , wxDefaultPosition , wxDefaultSize ,
2020-09-29 08:39:57 +02:00
#ifdef __APPLE__
wxSIMPLE_BORDER | wxFRAME_NO_TASKBAR | wxSTAY_ON_TOP
#else
wxSIMPLE_BORDER | wxFRAME_NO_TASKBAR
#endif // !__APPLE__
)
2020-09-04 20:25:27 +02:00
{
wxASSERT ( bitmap . IsOk ());
2020-09-07 21:20:49 +02:00
2020-10-05 19:53:24 +02:00
int init_dpi = get_dpi_for_window ( this );
this -> SetPosition ( pos );
this -> CenterOnScreen ();
int new_dpi = get_dpi_for_window ( this );
2020-09-10 16:03:43 +02:00
2020-10-05 19:53:24 +02:00
m_scale = ( float )( new_dpi ) / ( float )( init_dpi );
m_main_bitmap = bitmap ;
2020-09-10 16:03:43 +02:00
2020-10-05 19:53:24 +02:00
scale_bitmap ( m_main_bitmap , m_scale );
2020-10-06 10:33:05 +02:00
2020-10-06 19:38:30 +02:00
// init constant texts and scale fonts
init_constant_text ();
2020-10-06 10:33:05 +02:00
2020-10-06 19:38:30 +02:00
// this font will be used for the action string
m_action_font = m_constant_text . credits_font . Bold ();
2020-10-06 10:33:05 +02:00
2020-10-05 19:53:24 +02:00
// draw logo and constant info text
Decorate ( m_main_bitmap );
2020-09-04 20:25:27 +02:00
}
void SetText ( const wxString & text )
{
2020-09-10 16:03:43 +02:00
set_bitmap ( m_main_bitmap );
2020-09-04 20:25:27 +02:00
if ( ! text . empty ()) {
wxBitmap bitmap ( m_main_bitmap );
2020-09-07 21:20:49 +02:00
wxMemoryDC memDC ;
2020-09-04 20:25:27 +02:00
memDC . SelectObject ( bitmap );
2020-10-06 19:38:30 +02:00
memDC . SetFont ( m_action_font );
2020-09-04 20:25:27 +02:00
memDC . SetTextForeground ( wxColour ( 237 , 107 , 33 ));
2020-10-15 19:10:34 +02:00
memDC . DrawText ( text , int ( m_scale * 60 ), int ( m_scale * 275 ));
2020-09-04 20:25:27 +02:00
memDC . SelectObject ( wxNullBitmap );
2020-09-10 16:03:43 +02:00
set_bitmap ( bitmap );
2020-10-02 22:27:20 +02:00
#ifdef __WXOSX__
// without this code splash screen wouldn't be updated under OSX
wxYield ();
#endif
2020-09-04 20:25:27 +02:00
}
}
2020-09-28 20:41:22 +02:00
static wxBitmap MakeBitmap ( wxBitmap bmp )
{
if ( ! bmp . IsOk ())
return wxNullBitmap ;
// create dark grey background for the splashscreen
// It will be 5/3 of the weight of the bitmap
int width = lround (( double ) 5 / 3 * bmp . GetWidth ());
int height = bmp . GetHeight ();
wxImage image ( width , height );
unsigned char * imgdata_ = image . GetData ();
for ( int i = 0 ; i < width * height ; ++ i ) {
* imgdata_ ++ = 51 ;
* imgdata_ ++ = 51 ;
* imgdata_ ++ = 51 ;
}
wxBitmap new_bmp ( image );
wxMemoryDC memDC ;
memDC . SelectObject ( new_bmp );
memDC . DrawBitmap ( bmp , width - bmp . GetWidth (), 0 , true );
return new_bmp ;
}
2020-10-06 10:33:05 +02:00
void Decorate ( wxBitmap & bmp )
2020-09-10 16:03:43 +02:00
{
if ( ! bmp . IsOk ())
2020-10-06 10:33:05 +02:00
return ;
2020-09-10 16:03:43 +02:00
2020-09-28 20:41:22 +02:00
// draw text to the box at the left of the splashscreen.
2020-09-10 16:03:43 +02:00
// this box will be 2/5 of the weight of the bitmap, and be at the left.
2020-09-28 20:41:22 +02:00
int width = lround ( bmp . GetWidth () * 0.4 );
// load bitmap for logo
BitmapCache bmp_cache ;
int logo_size = lround ( width * 0.25 );
wxBitmap logo_bmp = * bmp_cache . load_svg ( wxGetApp (). is_editor () ? "prusa_slicer_logo" : "add_gcode" , logo_size , logo_size );
2020-09-10 16:03:43 +02:00
2020-10-05 19:53:24 +02:00
wxCoord margin = int ( m_scale * 20 );
2020-09-28 20:41:22 +02:00
2020-10-15 19:10:34 +02:00
wxRect banner_rect ( wxPoint ( 0 , logo_size ), wxPoint ( width , bmp . GetHeight ()));
banner_rect . Deflate ( margin , 2 * margin );
2020-09-10 16:03:43 +02:00
2020-09-28 20:41:22 +02:00
// use a memory DC to draw directly onto the bitmap
wxMemoryDC memDc ( bmp );
2020-09-10 16:03:43 +02:00
2020-09-28 20:41:22 +02:00
// draw logo
memDc . DrawBitmap ( logo_bmp , margin , margin , true );
// draw the (white) labels inside of our black box (at the left of the splashscreen)
2020-09-25 11:02:29 +02:00
memDc . SetTextForeground ( wxColour ( 255 , 255 , 255 ));
2020-09-10 16:03:43 +02:00
2020-10-06 19:38:30 +02:00
memDc . SetFont ( m_constant_text . title_font );
2020-10-15 19:10:34 +02:00
memDc . DrawLabel ( m_constant_text . title , banner_rect , wxALIGN_TOP | wxALIGN_LEFT );
int title_height = memDc . GetTextExtent ( m_constant_text . title ). GetY ();
banner_rect . SetTop ( banner_rect . GetTop () + title_height );
banner_rect . SetHeight ( banner_rect . GetHeight () - title_height );
2020-09-10 16:03:43 +02:00
2020-10-06 19:38:30 +02:00
memDc . SetFont ( m_constant_text . version_font );
2020-10-15 19:10:34 +02:00
memDc . DrawLabel ( m_constant_text . version , banner_rect , wxALIGN_TOP | wxALIGN_LEFT );
2020-09-10 16:03:43 +02:00
2020-10-06 19:38:30 +02:00
memDc . SetFont ( m_constant_text . credits_font );
2020-10-15 19:10:34 +02:00
memDc . DrawLabel ( m_constant_text . credits , banner_rect , wxALIGN_BOTTOM | wxALIGN_LEFT );
2020-09-10 16:03:43 +02:00
}
private :
wxBitmap m_main_bitmap ;
2020-10-06 19:38:30 +02:00
wxFont m_action_font ;
2020-09-10 16:03:43 +02:00
float m_scale { 1.0 };
2020-10-15 19:10:34 +02:00
struct ConstantText
2020-10-06 10:33:05 +02:00
{
wxString title ;
wxString version ;
wxString credits ;
2020-10-06 19:38:30 +02:00
wxFont title_font ;
wxFont version_font ;
wxFont credits_font ;
void init ( wxFont init_font )
2020-10-06 10:33:05 +02:00
{
// title
title = wxGetApp (). is_editor () ? SLIC3R_APP_NAME : GCODEVIEWER_APP_NAME ;
// dynamically get the version to display
version = _L ( "Version" ) + " " + std :: string ( SLIC3R_VERSION );
// credits infornation
credits = title + " " +
_L ( "is based on Slic3r by Alessandro Ranellucci and the RepRap community." ) + " \n\n " +
title + " " + _L ( "is licensed under the" ) + " " + _L ( "GNU Affero General Public License, version 3" ) + " \n\n " +
_L ( "Contributions by Vojtech Bubnik, Enrico Turri, Oleksandra Iushchenko, Tamas Meszaros, Lukas Matena, Vojtech Kral, David Kocik and numerous others." ) + " \n\n " +
_L ( "Artwork model by Nora Al-Badri and Jan Nikolai Nelles" );
2020-10-06 19:38:30 +02:00
title_font = version_font = credits_font = init_font ;
2020-10-06 10:33:05 +02:00
}
}
m_constant_text ;
2020-10-06 19:38:30 +02:00
void init_constant_text ()
{
m_constant_text . init ( get_default_font ( this ));
// As default we use a system font for current display.
// Scale fonts in respect to banner width
int text_banner_width = lround ( 0.4 * m_main_bitmap . GetWidth ()) - roundl ( m_scale * 50 ); // banner_width - margins
float title_font_scale = ( float ) text_banner_width / GetTextExtent ( m_constant_text . title ). GetX ();
scale_font ( m_constant_text . title_font , title_font_scale > 3.5f ? 3.5f : title_font_scale );
scale_font ( m_constant_text . version_font , 2.f );
// The width of the credits information string doesn't respect to the banner width some times.
// So, scale credits_font in the respect to the longest string width
int longest_string_width = word_wrap_string ( m_constant_text . credits );
float font_scale = ( float ) text_banner_width / longest_string_width ;
scale_font ( m_constant_text . credits_font , font_scale );
}
2020-09-10 16:03:43 +02:00
void set_bitmap ( wxBitmap & bmp )
2020-09-04 20:25:27 +02:00
{
m_window -> SetBitmap ( bmp );
m_window -> Refresh ();
m_window -> Update ();
}
2020-10-06 10:33:05 +02:00
void scale_bitmap ( wxBitmap & bmp , float scale )
2020-09-10 16:03:43 +02:00
{
if ( scale == 1.0 )
return ;
wxImage image = bmp . ConvertToImage ();
if ( ! image . IsOk () || image . GetWidth () == 0 || image . GetHeight () == 0 )
return ;
int width = int ( scale * image . GetWidth ());
int height = int ( scale * image . GetHeight ());
image . Rescale ( width , height , wxIMAGE_QUALITY_BILINEAR );
bmp = wxBitmap ( std :: move ( image ));
}
2020-10-06 10:33:05 +02:00
void scale_font ( wxFont & font , float scale )
{
2020-10-06 11:15:24 +02:00
#ifdef __WXMSW__
// Workaround for the font scaling in respect to the current active display,
// not for the primary display, as it's implemented in Font.cpp
// See https://github.com/wxWidgets/wxWidgets/blob/master/src/msw/font.cpp
// void wxNativeFontInfo::SetFractionalPointSize(float pointSizeNew)
2020-10-06 10:33:05 +02:00
wxNativeFontInfo nfi = * font . GetNativeFontInfo ();
float pointSizeNew = scale * font . GetPointSize ();
nfi . lf . lfHeight = nfi . GetLogFontHeightAtPPI ( pointSizeNew , get_dpi_for_window ( this ));
nfi . pointSize = pointSizeNew ;
font = wxFont ( nfi );
2020-10-06 11:15:24 +02:00
#else
font . Scale ( scale );
#endif //__WXMSW__
2020-10-06 10:33:05 +02:00
}
// wrap a string for the strings no longer then 55 symbols
// return extent of the longest string
int word_wrap_string ( wxString & input )
{
2020-10-06 11:15:24 +02:00
size_t line_len = 55 ; // count of symbols in one line
2020-09-10 16:03:43 +02:00
int idx = - 1 ;
2020-10-06 11:15:24 +02:00
size_t cur_len = 0 ;
2020-10-06 10:33:05 +02:00
wxString longest_sub_string ;
auto get_longest_sub_string = [ longest_sub_string , input ]( wxString & longest_sub_str , int cur_len , size_t i ) {
if ( cur_len > longest_sub_str . Len ())
longest_sub_str = input . SubString ( i - cur_len + 1 , i );
};
2020-09-10 16:03:43 +02:00
for ( size_t i = 0 ; i < input . Len (); i ++ )
{
cur_len ++ ;
if ( input [ i ] == ' ' )
idx = i ;
if ( input [ i ] == '\n' )
{
2020-10-06 10:33:05 +02:00
get_longest_sub_string ( longest_sub_string , cur_len , i );
2020-09-10 16:03:43 +02:00
idx = - 1 ;
cur_len = 0 ;
}
if ( cur_len >= line_len && idx >= 0 )
{
2020-10-06 10:33:05 +02:00
get_longest_sub_string ( longest_sub_string , cur_len , i );
2020-09-10 16:03:43 +02:00
input [ idx ] = '\n' ;
2020-10-06 11:15:24 +02:00
cur_len = i - static_cast < size_t > ( idx );
2020-09-10 16:03:43 +02:00
}
}
2020-10-06 10:33:05 +02:00
return GetTextExtent ( longest_sub_string ). GetX ();
2020-09-10 16:03:43 +02:00
}
2020-09-04 20:25:27 +02:00
};
2020-10-21 13:21:45 +02:00
#ifdef __linux__
bool static check_old_linux_datadir ( const wxString & app_name ) {
// If we are on Linux and the datadir does not exist yet, look into the old
// location where the datadir was before version 2.3. If we find it there,
// tell the user that he might wanna migrate to the new location.
// (https://github.com/prusa3d/PrusaSlicer/issues/2911)
// To be precise, the datadir should exist, it is created when single instance
// lock happens. Instead of checking for existence, check the contents.
namespace fs = boost :: filesystem ;
std :: string new_path = Slic3r :: data_dir ();
2020-10-26 12:54:00 +01:00
wxString dir ;
if ( ! wxGetEnv ( wxS ( "XDG_CONFIG_HOME" ), & dir ) || dir . empty () )
dir = wxFileName :: GetHomeDir () + wxS ( "/.config" );
std :: string default_path = ( dir + "/" + app_name ). ToUTF8 (). data ();
if ( new_path != default_path ) {
2020-10-21 13:21:45 +02:00
// This happens when the user specifies a custom --datadir.
// Do not show anything in that case.
return true ;
}
fs :: path data_dir = fs :: path ( new_path );
if ( ! fs :: is_directory ( data_dir ))
return true ; // This should not happen.
int file_count = std :: distance ( fs :: directory_iterator ( data_dir ), fs :: directory_iterator ());
if ( file_count <= 1 ) { // just cache dir with an instance lock
std :: string old_path = wxStandardPaths :: Get (). GetUserDataDir (). ToUTF8 (). data ();
if ( fs :: is_directory ( old_path )) {
wxString msg = from_u8 (( boost :: format ( _u8L ( "Starting with %1% 2.3, configuration "
"directory on Linux has changed (according to XDG Base Directory Specification) to \n %2%. \n\n "
"This directory did not exist yet (maybe you run the new version for the first time). \n However, "
"an old %1% configuration directory was detected in \n %3%. \n\n "
"Consider moving the contents of the old directory to the new location in order to access "
"your profiles, etc. \n Note that if you decide to downgrade %1% in future, it will use the old "
"location again. \n\n "
"What do you want to do now?" )) % SLIC3R_APP_NAME % new_path % old_path ). str ());
wxString caption = from_u8 (( boost :: format ( _u8L ( "%s - BREAKING CHANGE" )) % SLIC3R_APP_NAME ). str ());
wxRichMessageDialog dlg ( nullptr , msg , caption , wxYES_NO );
dlg . SetYesNoLabels ( _L ( "Quit, I will move my data now" ), _L ( "Start the application" ));
if ( dlg . ShowModal () != wxID_NO )
return false ;
}
} else {
// If the new directory exists, be silent. The user likely already saw the message.
}
return true ;
}
#endif
2018-12-06 17:32:49 +01:00
wxString file_wildcards ( FileType file_type , const std :: string & custom_extension )
{
2018-12-20 18:23:11 +01:00
static const std :: string defaults [ FT_SIZE ] = {
2019-05-15 10:23:02 +02: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_PROJECT */ "Project files (*.3mf, *.amf)|*.3mf;*.3MF;*.amf;*.AMF" ,
2018-10-04 11:12:55 +02:00
2019-07-18 11:12:11 +02:00
/* FT_INI */ "INI files (*.ini)|*.ini;*.INI" ,
/* FT_SVG */ "SVG files (*.svg)|*.svg;*.SVG" ,
/* FT_TEX */ "Texture (*.png, *.svg)|*.png;*.PNG;*.svg;*.SVG" ,
/* FT_PNGZIP */ "Masked SLA files (*.sl1)|*.sl1;*.SL1" ,
2018-12-06 17:32:49 +01:00
};
2018-10-04 11:12:55 +02:00
2018-12-20 18:23:11 +01:00
std :: string out = defaults [ file_type ];
2018-12-06 17:32:49 +01:00
if ( ! custom_extension . empty ()) {
2018-12-20 18:23:11 +01: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 17:32:49 +01:00
}
2019-01-07 19:17:10 +01:00
return from_u8 ( out );
2018-12-06 17:32:49 +01:00
}
2018-10-04 11:12:55 +02:00
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 (); }
2019-04-02 12:00:50 +02:00
#ifdef WIN32
2020-06-16 08:15:36 +02:00
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
2020-03-13 14:19:02 +01:00
static void register_win32_dpi_event ()
{
2019-04-02 12:00:50 +02:00
enum { WM_DPICHANGED_ = 0x02e0 };
wxWindow :: MSWRegisterMessageHandler ( WM_DPICHANGED_ , []( wxWindow * win , WXUINT nMsg , WXWPARAM wParam , WXLPARAM lParam ) {
const int dpi = wParam & 0xffff ;
const auto rect = reinterpret_cast < PRECT > ( lParam );
const wxRect wxrect ( wxPoint ( rect -> top , rect -> left ), wxPoint ( rect -> bottom , rect -> right ));
2019-11-11 17:10:29 +01:00
DpiChangedEvent evt ( EVT_DPI_CHANGED_SLICER , dpi , wxrect );
2019-04-02 12:00:50 +02:00
win -> GetEventHandler () -> AddPendingEvent ( evt );
return true ;
});
}
2020-06-19 11:04:08 +02:00
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
2019-04-02 12:00:50 +02:00
2020-03-13 14:19:02 +01:00
static GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2 , 0xF16F , 0x11CF , 0x88 , 0xCB , 0x00 , 0x11 , 0x11 , 0x00 , 0x00 , 0x30 };
static void register_win32_device_notification_event ()
{
wxWindow :: MSWRegisterMessageHandler ( WM_DEVICECHANGE , []( wxWindow * win , WXUINT /* nMsg */ , WXWPARAM wParam , WXLPARAM lParam ) {
// Some messages are sent to top level windows by default, some messages are sent to only registered windows, and we explictely register on MainFrame only.
auto main_frame = dynamic_cast < MainFrame *> ( win );
auto plater = ( main_frame == nullptr ) ? nullptr : main_frame -> plater ();
if ( plater == nullptr )
// Maybe some other top level window like a dialog or maybe a pop-up menu?
return true ;
PDEV_BROADCAST_HDR lpdb = ( PDEV_BROADCAST_HDR ) lParam ;
switch ( wParam ) {
case DBT_DEVICEARRIVAL :
if ( lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME )
plater -> GetEventHandler () -> AddPendingEvent ( VolumeAttachedEvent ( EVT_VOLUME_ATTACHED ));
else if ( lpdb -> dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE ) {
PDEV_BROADCAST_DEVICEINTERFACE lpdbi = ( PDEV_BROADCAST_DEVICEINTERFACE ) lpdb ;
// if (lpdbi->dbcc_classguid == GUID_DEVINTERFACE_VOLUME) {
// printf("DBT_DEVICEARRIVAL %d - Media has arrived: %ws\n", msg_count, lpdbi->dbcc_name);
if ( lpdbi -> dbcc_classguid == GUID_DEVINTERFACE_HID )
plater -> GetEventHandler () -> AddPendingEvent ( HIDDeviceAttachedEvent ( EVT_HID_DEVICE_ATTACHED , boost :: nowide :: narrow ( lpdbi -> dbcc_name )));
}
break ;
case DBT_DEVICEREMOVECOMPLETE :
if ( lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME )
plater -> GetEventHandler () -> AddPendingEvent ( VolumeDetachedEvent ( EVT_VOLUME_DETACHED ));
else if ( lpdb -> dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE ) {
PDEV_BROADCAST_DEVICEINTERFACE lpdbi = ( PDEV_BROADCAST_DEVICEINTERFACE ) lpdb ;
// if (lpdbi->dbcc_classguid == GUID_DEVINTERFACE_VOLUME)
// printf("DBT_DEVICEARRIVAL %d - Media was removed: %ws\n", msg_count, lpdbi->dbcc_name);
if ( lpdbi -> dbcc_classguid == GUID_DEVINTERFACE_HID )
plater -> GetEventHandler () -> AddPendingEvent ( HIDDeviceDetachedEvent ( EVT_HID_DEVICE_DETACHED , boost :: nowide :: narrow ( lpdbi -> dbcc_name )));
}
break ;
default :
break ;
}
return true ;
});
2020-03-27 08:10:00 +01:00
wxWindow :: MSWRegisterMessageHandler ( MainFrame :: WM_USER_MEDIACHANGED , []( wxWindow * win , WXUINT /* nMsg */ , WXWPARAM wParam , WXLPARAM lParam ) {
// Some messages are sent to top level windows by default, some messages are sent to only registered windows, and we explictely register on MainFrame only.
auto main_frame = dynamic_cast < MainFrame *> ( win );
auto plater = ( main_frame == nullptr ) ? nullptr : main_frame -> plater ();
if ( plater == nullptr )
// Maybe some other top level window like a dialog or maybe a pop-up menu?
return true ;
wchar_t sPath [ MAX_PATH ];
if ( lParam == SHCNE_MEDIAINSERTED || lParam == SHCNE_MEDIAREMOVED ) {
struct _ITEMIDLIST * pidl = * reinterpret_cast < struct _ITEMIDLIST **> ( wParam );
if ( ! SHGetPathFromIDList ( pidl , sPath )) {
BOOST_LOG_TRIVIAL ( error ) << "MediaInserted: SHGetPathFromIDList failed" ;
return false ;
}
}
switch ( lParam ) {
case SHCNE_MEDIAINSERTED :
{
//printf("SHCNE_MEDIAINSERTED %S\n", sPath);
plater -> GetEventHandler () -> AddPendingEvent ( VolumeAttachedEvent ( EVT_VOLUME_ATTACHED ));
break ;
}
case SHCNE_MEDIAREMOVED :
{
//printf("SHCNE_MEDIAREMOVED %S\n", sPath);
plater -> GetEventHandler () -> AddPendingEvent ( VolumeDetachedEvent ( EVT_VOLUME_DETACHED ));
break ;
}
default :
// printf("Unknown\n");
break ;
}
return true ;
});
2020-03-31 09:01:48 +02:00
wxWindow :: MSWRegisterMessageHandler ( WM_INPUT , []( wxWindow * win , WXUINT /* nMsg */ , WXWPARAM wParam , WXLPARAM lParam ) {
auto main_frame = dynamic_cast < MainFrame *> ( Slic3r :: GUI :: find_toplevel_parent ( win ));
auto plater = ( main_frame == nullptr ) ? nullptr : main_frame -> plater ();
// if (wParam == RIM_INPUTSINK && plater != nullptr && main_frame->IsActive()) {
if ( wParam == RIM_INPUT && plater != nullptr && main_frame -> IsActive ()) {
RAWINPUT raw ;
UINT rawSize = sizeof ( RAWINPUT );
:: GetRawInputData (( HRAWINPUT ) lParam , RID_INPUT , & raw , & rawSize , sizeof ( RAWINPUTHEADER ));
if ( raw . header . dwType == RIM_TYPEHID && plater -> get_mouse3d_controller (). handle_raw_input_win32 ( raw . data . hid . bRawData , raw . data . hid . dwSizeHid ))
return true ;
}
return false ;
});
2020-04-29 10:50:28 +02:00
wxWindow :: MSWRegisterMessageHandler ( WM_COPYDATA , []( wxWindow * win , WXUINT /* nMsg */ , WXWPARAM wParam , WXLPARAM lParam ) {
COPYDATASTRUCT * copy_data_structure = { 0 };
copy_data_structure = ( COPYDATASTRUCT * ) lParam ;
if ( copy_data_structure -> dwData == 1 ) {
LPCWSTR arguments = ( LPCWSTR ) copy_data_structure -> lpData ;
Slic3r :: GUI :: wxGetApp (). other_instance_message_handler () -> handle_message ( boost :: nowide :: narrow ( arguments ));
}
return true ;
});
2020-03-13 14:19:02 +01:00
}
#endif // WIN32
2019-04-09 11:28:11 +02:00
static void generic_exception_handle ()
{
// Note: Some wxWidgets APIs use wxLogError() to report errors, eg. wxImage
// - see https://docs.wxwidgets.org/3.1/classwx_image.html#aa249e657259fe6518d68a5208b9043d0
//
// wxLogError typically goes around exception handling and display an error dialog some time
// after an error is logged even if exception handling and OnExceptionInMainLoop() take place.
// This is why we use wxLogError() here as well instead of a custom dialog, because it accumulates
// errors if multiple have been collected and displays just one error message for all of them.
// Otherwise we would get multiple error messages for one missing png, for example.
//
// If a custom error message window (or some other solution) were to be used, it would be necessary
// to turn off wxLogError() usage in wx APIs, most notably in wxImage
// - see https://docs.wxwidgets.org/trunk/classwx_image.html#aa32e5d3507cc0f8c3330135bc0befc6a
try {
throw ;
2019-08-08 15:17:17 +02:00
} catch ( const std :: bad_alloc & ex ) {
// bad_alloc in main thread is most likely fatal. Report immediately to the user (wxLogError would be delayed)
// and terminate the app so it is at least certain to happen now.
2020-10-06 15:11:08 +02:00
wxString errmsg = wxString :: Format ( _L ( "%s has encountered an error. It was likely caused by running out of memory. "
2019-08-08 15:17:17 +02:00
"If you are sure you have enough RAM on your system, this may also be a bug and we would "
2020-10-06 15:11:08 +02:00
"be glad if you reported it. \n\n The application will now terminate." ), SLIC3R_APP_NAME );
wxMessageBox ( errmsg + " \n\n " + wxString ( ex . what ()), _L ( "Fatal error" ), wxOK | wxICON_ERROR );
2019-08-08 15:17:17 +02:00
BOOST_LOG_TRIVIAL ( error ) << boost :: format ( "std::bad_alloc exception: %1%" ) % ex . what ();
std :: terminate ();
} catch ( const std :: exception & ex ) {
2019-04-09 11:28:11 +02:00
wxLogError ( "Internal error: %s" , ex . what ());
BOOST_LOG_TRIVIAL ( error ) << boost :: format ( "Uncaught exception: %1%" ) % ex . what ();
throw ;
}
}
2020-10-22 16:28:49 +02:00
void GUI_App :: post_init ()
2020-10-02 22:27:20 +02:00
{
2020-10-22 16:28:49 +02:00
assert ( initialized ());
if ( ! this -> initialized ())
throw Slic3r :: RuntimeError ( "Calling post_init() while not yet initialized" );
2020-10-02 22:27:20 +02:00
2020-10-22 16:28:49 +02:00
if ( this -> init_params -> start_as_gcodeviewer ) {
if ( ! this -> init_params -> input_files . empty ())
this -> plater () -> load_gcode ( wxString :: FromUTF8 ( this -> init_params -> input_files [ 0 ]. c_str ()));
2020-10-02 22:27:20 +02:00
}
else {
#if 0
// Load the cummulative config over the currently active profiles.
//FIXME if multiple configs are loaded, only the last one will have an effect.
// We need to decide what to do about loading of separate presets (just print preset, just filament preset etc).
// As of now only the full configs are supported here.
if (!m_print_config.empty())
2020-10-22 16:28:49 +02:00
this->gui->mainframe->load_config(m_print_config);
2020-10-02 22:27:20 +02:00
#endif
2020-10-22 16:28:49 +02:00
if ( ! this -> init_params -> load_configs . empty ())
2020-10-02 22:27:20 +02:00
// Load the last config to give it a name at the UI. The name of the preset may be later
// changed by loading an AMF or 3MF.
//FIXME this is not strictly correct, as one may pass a print/filament/printer profile here instead of a full config.
2020-10-22 16:28:49 +02:00
this -> mainframe -> load_config_file ( this -> init_params -> load_configs . back ());
2020-10-02 22:27:20 +02:00
// If loading a 3MF file, the config is loaded from the last one.
2020-10-22 16:28:49 +02:00
if ( ! this -> init_params -> input_files . empty ())
this -> plater () -> load_files ( this -> init_params -> input_files , true , true );
if ( ! this -> init_params -> extra_config . empty ())
this -> mainframe -> load_config ( this -> init_params -> extra_config );
2020-10-02 22:27:20 +02:00
}
2020-10-22 16:28:49 +02:00
}
2020-10-02 22:27:20 +02:00
2018-09-21 01:33:41 +02:00
IMPLEMENT_APP ( GUI_App )
2018-11-26 10:56:07 +01:00
2020-09-08 11:40:06 +02:00
GUI_App :: GUI_App ( EAppMode mode )
2018-11-26 10:56:07 +01:00
: wxApp ()
2020-09-08 11:40:06 +02:00
, m_app_mode ( mode )
2019-02-21 18:59:21 +01:00
, m_em_unit ( 10 )
2019-04-01 14:12:05 +02:00
, m_imgui ( new ImGuiWrapper ())
2019-06-04 18:01:41 +02:00
, m_wizard ( nullptr )
2020-03-06 15:10:58 +01:00
, m_removable_drive_manager ( std :: make_unique < RemovableDriveManager > ())
2020-04-29 10:50:28 +02:00
, m_other_instance_message_handler ( std :: make_unique < OtherInstanceMessageHandler > ())
{
//app config initializes early becasuse it is used in instance checking in PrusaSlicer.cpp
this -> init_app_config ();
}
2018-11-26 10:56:07 +01:00
2019-06-27 14:42:55 +02:00
GUI_App ::~ GUI_App ()
{
if ( app_config != nullptr )
delete app_config ;
if ( preset_bundle != nullptr )
delete preset_bundle ;
if ( preset_updater != nullptr )
delete preset_updater ;
}
2020-03-02 10:58:46 +01:00
std :: string GUI_App :: get_gl_info ( bool format_as_html , bool extensions )
{
2020-05-06 14:38:53 +02:00
return OpenGLManager :: get_gl_info (). to_string ( format_as_html , extensions );
2020-03-02 10:58:46 +01:00
}
wxGLContext * GUI_App :: init_glcontext ( wxGLCanvas & canvas )
{
2020-05-06 14:38:53 +02:00
return m_opengl_mgr . init_glcontext ( canvas );
2020-03-02 10:58:46 +01:00
}
bool GUI_App :: init_opengl ()
{
2020-05-06 14:38:53 +02:00
return m_opengl_mgr . init_gl ();
2020-03-02 10:58:46 +01:00
}
2020-04-29 10:50:28 +02:00
void GUI_App :: init_app_config ()
{
// Profiles for the alpha are stored into the PrusaSlicer-alpha directory to not mix with the current release.
2020-11-28 11:14:53 +01:00
// SetAppName(SLIC3R_APP_KEY);
SetAppName ( SLIC3R_APP_KEY "-beta" );
2020-05-05 13:11:32 +02:00
// SetAppDisplayName(SLIC3R_APP_NAME);
2020-04-29 10:50:28 +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"
2020-10-21 13:21:45 +02:00
if ( data_dir (). empty ()) {
#ifndef __linux__
set_data_dir ( wxStandardPaths :: Get (). GetUserDataDir (). ToUTF8 (). data ());
#else
// Since version 2.3, config dir on Linux is in ${XDG_CONFIG_HOME}.
// https://github.com/prusa3d/PrusaSlicer/issues/2911
2020-10-26 12:54:00 +01:00
wxString dir ;
if ( ! wxGetEnv ( wxS ( "XDG_CONFIG_HOME" ), & dir ) || dir . empty () )
dir = wxFileName :: GetHomeDir () + wxS ( "/.config" );
set_data_dir (( dir + "/" + GetAppName ()). ToUTF8 (). data ());
2020-10-21 13:21:45 +02:00
#endif
}
2020-04-29 10:50:28 +02:00
if ( ! app_config )
2020-10-05 15:42:35 +02:00
app_config = new AppConfig ( is_editor () ? AppConfig :: EAppMode :: Editor : AppConfig :: EAppMode :: GCodeViewer );
2020-09-08 11:40:06 +02:00
2020-04-29 10:50:28 +02:00
// load settings
2020-10-12 08:39:40 +02:00
m_app_conf_exists = app_config -> exists ();
if ( m_app_conf_exists ) {
2020-08-08 17:03:20 +02:00
std :: string error = app_config -> load ();
2020-10-05 15:42:35 +02:00
if ( ! error . empty ()) {
// Error while parsing config file. We'll customize the error message and rethrow to be displayed.
if ( is_editor ()) {
throw Slic3r :: RuntimeError (
_u8L ( "Error parsing PrusaSlicer config file, it is probably corrupted. "
"Try to manually delete the file to recover from the error. Your user profiles will not be affected." ) +
" \n\n " + app_config -> config_path () + " \n\n " + error );
}
else {
throw Slic3r :: RuntimeError (
_u8L ( "Error parsing PrusaGCodeViewer config file, it is probably corrupted. "
"Try to manually delete the file to recover from the error." ) +
" \n\n " + app_config -> config_path () + " \n\n " + error );
}
}
}
2020-04-29 10:50:28 +02:00
}
2020-05-06 14:38:53 +02:00
2020-05-14 12:15:02 +02:00
void GUI_App :: init_single_instance_checker ( const std :: string & name , const std :: string & path )
{
BOOST_LOG_TRIVIAL ( debug ) << "init wx instance checker " << name << " " << path ;
m_single_instance_checker = std :: make_unique < wxSingleInstanceChecker > ( boost :: nowide :: widen ( name ), boost :: nowide :: widen ( path ));
}
2018-09-20 08:40:22 +02:00
bool GUI_App :: OnInit ()
2019-04-09 11:28:11 +02:00
{
try {
return on_init_inner ();
2019-08-26 17:17:23 +02:00
} catch ( const std :: exception & ) {
2019-04-09 11:28:11 +02:00
generic_exception_handle ();
return false ;
}
}
bool GUI_App :: on_init_inner ()
2018-09-20 08:40:22 +02:00
{
2019-01-04 12:06:25 +01: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 10:19:44 +01:00
2020-10-21 13:21:45 +02:00
#ifdef __linux__
if ( ! check_old_linux_datadir ( GetAppName ())) {
std :: cerr << "Quitting, user chose to move his data to new location." << std :: endl ;
return false ;
}
#endif
2020-09-08 11:40:06 +02:00
// Enable this to get the default Win32 COMCTRL32 behavior of static boxes.
2019-03-18 12:48:39 +01:00
// wxSystemOptions::SetOption("msw.staticbox.optimized-paint", 0);
2020-04-29 10:50:28 +02:00
// Enable this to disable Windows Vista themes for all wxNotebooks. The themes seem to lead to terrible
// performance when working on high resolution multi-display setups.
2019-03-18 20:54:01 +01:00
// wxSystemOptions::SetOption("msw.notebook.themed-background", 0);
2019-03-18 12:48:39 +01:00
2018-09-21 01:33:41 +02:00
// Slic3r::debugf "wxWidgets version %s, Wx version %s\n", wxVERSION_STRING, wxVERSION;
2020-09-08 11:40:06 +02:00
2020-10-07 11:04:06 +02:00
if ( is_editor ()) {
std :: string msg = Http :: tls_global_init ();
std :: string ssl_cert_store = app_config -> get ( "tls_accepted_cert_store_location" );
bool ssl_accept = app_config -> get ( "tls_cert_store_accepted" ) == "yes" && ssl_cert_store == Http :: tls_system_cert_store ();
2020-09-08 11:40:06 +02:00
2020-10-07 11:04:06 +02:00
if ( ! msg . empty () && ! ssl_accept ) {
wxRichMessageDialog
dlg ( nullptr ,
wxString :: Format ( _L ( "%s \n Do you want to continue?" ), msg ),
"PrusaSlicer" , wxICON_QUESTION | wxYES_NO );
dlg . ShowCheckBox ( _L ( "Remember my choice" ));
if ( dlg . ShowModal () != wxID_YES ) return false ;
2018-09-21 01:33:41 +02:00
2020-10-07 11:04:06 +02:00
app_config -> set ( "tls_cert_store_accepted" ,
dlg . IsCheckBoxChecked () ? "yes" : "no" );
app_config -> set ( "tls_accepted_cert_store_location" ,
dlg . IsCheckBoxChecked () ? Http :: tls_system_cert_store () : "" );
}
2020-04-22 17:14:09 +02:00
}
2020-09-08 11:40:06 +02:00
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 ();
2020-10-05 19:53:24 +02:00
2020-09-08 09:12:40 +02:00
wxInitAllImageHandlers ();
2020-09-04 20:25:27 +02:00
2020-09-10 16:03:43 +02:00
SplashScreen * scrn = nullptr ;
2020-10-12 11:47:11 +02:00
if ( app_config -> get ( "show_splash_screen" ) == "1" ) {
2020-10-05 19:53:24 +02:00
// make a bitmap with dark grey banner on the left side
2020-10-02 13:20:48 +02:00
wxBitmap bmp = SplashScreen :: MakeBitmap ( wxBitmap ( from_u8 ( var ( is_editor () ? "splashscreen.jpg" : "splashscreen-gcodepreview.jpg" )), wxBITMAP_TYPE_JPEG ));
2020-09-07 21:20:49 +02:00
2020-09-10 16:03:43 +02:00
// Detect position (display) to show the splash screen
// Now this position is equal to the mainframe position
wxPoint splashscreen_pos = wxDefaultPosition ;
if ( app_config -> has ( "window_mainframe" )) {
auto metrics = WindowMetrics :: deserialize ( app_config -> get ( "window_mainframe" ));
if ( metrics )
splashscreen_pos = metrics -> get_rect (). GetPosition ();
}
2020-09-07 21:20:49 +02:00
2020-09-10 16:03:43 +02:00
// create splash screen with updated bmp
scrn = new SplashScreen ( bmp . IsOk () ? bmp : create_scaled_bitmap ( "prusa_slicer_logo" , nullptr , 400 ),
2020-10-05 19:53:24 +02:00
wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT , 4000 , splashscreen_pos );
2020-11-14 11:17:09 +01:00
#ifndef __linux__
2020-10-06 10:33:05 +02:00
wxYield ();
2020-11-14 11:17:09 +01:00
#endif
2020-11-18 12:30:00 +01:00
scrn -> SetText ( _L ( "Loading configuration" ) + dots );
2020-09-10 16:03:43 +02:00
}
2020-09-08 11:40:06 +02:00
2018-09-21 01:33:41 +02:00
preset_bundle = new PresetBundle ();
2020-09-08 11:40:06 +02:00
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
2019-04-09 11:28:11 +02:00
preset_bundle -> setup_directories ();
2018-12-03 13:14:28 +01:00
2020-09-08 11:40:06 +02:00
if ( is_editor ()) {
2020-08-03 15:36:55 +02:00
#ifdef __WXMSW__
2020-11-26 10:09:34 +01:00
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
if ( app_config -> get ( "associate_3mf" ) == "1" )
#endif // ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
associate_3mf_files ();
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
if ( app_config -> get ( "associate_stl" ) == "1" )
associate_stl_files ();
#endif // ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
2019-05-03 15:50:05 +02:00
#endif // __WXMSW__
2020-09-08 11:40:06 +02:00
preset_updater = new PresetUpdater ();
Bind ( EVT_SLIC3R_VERSION_ONLINE , [ this ]( const wxCommandEvent & evt ) {
app_config -> set ( "version_online" , into_u8 ( evt . GetString ()));
app_config -> save ();
if ( this -> plater_ != nullptr ) {
if ( * Semver :: parse ( SLIC3R_VERSION ) < * Semver :: parse ( into_u8 ( evt . GetString ()))) {
2020-11-30 13:45:17 +01:00
this -> plater_ -> get_notification_manager () -> push_notification ( NotificationType :: NewAppAvailable );
2020-09-08 11:40:06 +02:00
}
}
});
}
2020-10-08 08:32:51 +02:00
else {
#ifdef __WXMSW__
2020-11-26 10:09:34 +01:00
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
if ( app_config -> get ( "associate_gcode" ) == "1" )
#endif // ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
associate_gcode_files ();
2020-10-08 08:32:51 +02:00
#endif // __WXMSW__
}
2018-09-20 08:40:22 +02:00
2019-03-29 14:57:53 +01:00
// initialize label colors and fonts
init_label_colours ();
init_fonts ();
2019-08-28 11:53:53 +02:00
// If load_language() fails, the application closes.
2019-08-29 14:07:45 +02:00
load_language ( wxString (), true );
2018-09-20 08:40:22 +02:00
// Suppress the '- default -' presets.
2018-10-31 16:22:36 +01:00
preset_bundle -> set_default_suppressed ( app_config -> get ( "no_defaults" ) == "1" );
2019-04-09 11:28:11 +02:00
try {
preset_bundle -> load_presets ( * app_config );
} catch ( const std :: exception & ex ) {
2020-02-21 13:38:06 +01:00
show_error ( nullptr , ex . what ());
2019-04-09 11:28:11 +02:00
}
2018-09-20 08:40:22 +02:00
2020-03-13 14:19:02 +01:00
#ifdef WIN32
2020-06-16 08:15:36 +02:00
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
2020-03-13 14:19:02 +01:00
register_win32_dpi_event ();
2020-06-19 11:04:08 +02:00
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
2020-03-13 14:19:02 +01:00
register_win32_device_notification_event ();
#endif // WIN32
2019-04-02 12:00:50 +02:00
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 );
2018-09-20 08:40:22 +02:00
// application frame
2020-09-10 16:03:43 +02:00
if ( scrn && is_editor ())
2020-11-18 12:30:00 +01:00
scrn -> SetText ( _L ( "Preparing settings tabs" ) + dots );
2020-09-04 20:25:27 +02:00
2018-12-19 17:38:41 +01:00
mainframe = new MainFrame ();
2020-05-04 22:30:38 +02:00
// hide settings tabs after first Layout
2020-10-05 16:06:14 +02:00
if ( is_editor ())
mainframe -> select_tab ( size_t ( 0 ));
2020-04-23 21:00:00 +02:00
2018-10-05 23:29:15 +02:00
sidebar (). obj_list () -> init_objects (); // propagate model objects to object list
2019-01-24 12:11:01 +01:00
// update_mode(); // !!! do that later
2018-09-20 08:40:22 +02:00
SetTopWindow ( mainframe );
2018-12-14 15:27:34 +01:00
m_printhost_job_queue . reset ( new PrintHostJobQueue ( mainframe -> printhost_queue_dlg ()));
2019-12-09 17:12:22 +01:00
2018-10-02 13:23:38 +02:00
Bind ( wxEVT_IDLE , [ this ]( wxIdleEvent & event )
{
2019-04-09 11:28:11 +02:00
if ( ! plater_ )
return ;
2019-03-11 11:03:13 +01:00
2020-04-29 10:50:28 +02:00
2019-02-22 17:18:58 +01:00
if ( app_config -> dirty () && app_config -> get ( "autosave" ) == "1" )
2018-10-02 13:23:38 +02:00
app_config -> save ();
2018-12-20 20:12:26 +01:00
2019-03-11 11:03:13 +01:00
this -> obj_manipul () -> update_if_dirty ();
2018-09-20 08:40:22 +02:00
2020-10-02 22:27:20 +02:00
static bool update_gui_after_init = true ;
2020-10-12 11:47:11 +02:00
if ( update_gui_after_init ) {
2020-10-02 22:27:20 +02:00
update_gui_after_init = false ;
2020-10-14 12:55:00 +02:00
#ifdef WIN32
this -> mainframe -> register_win32_callbacks ();
#endif
2020-10-22 16:28:49 +02:00
this -> post_init ();
2020-10-02 22:27:20 +02:00
}
2020-02-04 15:24:35 +01:00
// Preset updating & Configwizard are done after the above initializations,
// and after MainFrame is created & shown.
// The extra CallAfter() is needed because of Mac, where this is the only way
// to popup a modal dialog on start without screwing combo boxes.
// This is ugly but I honestly found no better way to do it.
// Neither wxShowEvent nor wxWindowCreateEvent work reliably.
2019-02-28 16:19:53 +01:00
static bool once = true ;
if ( once ) {
once = false ;
2020-10-12 13:44:08 +02:00
2020-09-08 11:40:06 +02:00
if ( preset_updater != nullptr ) {
check_updates ( false );
CallAfter ([ this ] {
config_wizard_startup ();
preset_updater -> slic3r_update_notify ();
preset_updater -> sync ( preset_bundle );
});
}
2019-02-28 16:19:53 +01:00
2020-05-14 12:15:02 +02:00
#ifdef _WIN32
//sets window property to mainframe so other instances can indentify it
OtherInstanceMessageHandler :: init_windows_properties ( mainframe , m_instance_hash_int );
#endif //WIN32
2018-12-03 13:14:28 +01:00
}
2018-10-02 13:23:38 +02:00
});
2020-09-08 11:40:06 +02:00
if ( is_gcode_viewer ()) {
mainframe -> update_layout ();
if ( plater_ != nullptr )
// ensure the selected technology is ptFFF
plater_ -> set_printer_technology ( ptFFF );
}
2020-09-08 15:30:01 +02:00
else
load_current_presets ();
2018-09-20 08:40:22 +02:00
mainframe -> Show ( true );
2019-03-26 18:01:44 +01:00
/* Temporary workaround for the correct behavior of the Scrolled sidebar panel:
* change min hight of object list to the normal min value (15 * wxGetApp().em_unit())
* after first whole Mainframe updating/layouting
*/
2019-09-03 10:59:04 +02:00
const int list_min_height = 15 * em_unit ();
if ( obj_list () -> GetMinSize (). GetY () > list_min_height )
obj_list () -> SetMinSize ( wxSize ( - 1 , list_min_height ));
2019-03-26 18:01:44 +01:00
2019-03-13 13:13:18 +01:00
update_mode (); // update view mode after fix of the object_list size
2019-03-26 18:01:44 +01:00
2020-10-12 13:44:08 +02:00
#ifdef __APPLE__
other_instance_message_handler () -> bring_instance_forward ();
#endif //__APPLE__
2019-02-28 16:19:53 +01:00
m_initialized = true ;
return true ;
2018-09-20 08:40:22 +02:00
}
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
));
}
2019-04-26 16:59:14 +02:00
bool GUI_App :: dark_mode ()
{
#if __APPLE__
2020-02-27 14:38:39 +01:00
// The check for dark mode returns false positive on 10.12 and 10.13,
// which allowed setting dark menu bar and dock area, which is
// is detected as dark mode. We must run on at least 10.14 where the
// proper dark mode was first introduced.
return wxPlatformInfo :: Get (). CheckOSVersion ( 10 , 14 ) && mac_dark_mode ();
2019-04-26 16:59:14 +02:00
#else
2019-12-18 15:54:01 +01:00
const unsigned luma = get_colour_approx_luma ( wxSystemSettings :: GetColour ( wxSYS_COLOUR_WINDOW ));
return luma < 128 ;
2019-04-26 16:59:14 +02:00
#endif
}
2018-10-01 15:09:31 +02:00
void GUI_App :: init_label_colours ()
{
2019-04-26 16:59:14 +02:00
if ( dark_mode ()) {
2018-10-01 15:09:31 +02:00
m_color_label_modified = wxColour ( 253 , 111 , 40 );
m_color_label_sys = wxColour ( 115 , 220 , 103 );
}
2019-05-03 13:09:42 +02:00
else {
m_color_label_modified = wxColour ( 252 , 77 , 1 );
m_color_label_sys = wxColour ( 26 , 132 , 57 );
}
2018-10-01 15:09:31 +02:00
m_color_label_default = wxSystemSettings :: GetColour ( wxSYS_COLOUR_WINDOWTEXT );
}
void GUI_App :: update_label_colours_from_appconfig ()
{
2018-10-31 12:56:08 +01:00
if ( app_config -> has ( "label_clr_sys" )) {
2018-10-01 15:09:31 +02:00
auto str = app_config -> get ( "label_clr_sys" );
if ( str != "" )
m_color_label_sys = wxColour ( str );
}
2018-10-31 12:56:08 +01:00
if ( app_config -> has ( "label_clr_modified" )) {
2018-10-01 15:09:31 +02: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 ();
2019-03-18 20:54:01 +01:00
m_normal_font = wxSystemSettings :: GetFont ( wxSYS_DEFAULT_GUI_FONT );
2019-01-31 15:55:09 +01:00
2018-10-01 15:09:31 +02:00
#ifdef __WXMAC__
m_small_font . SetPointSize ( 11 );
m_bold_font . SetPointSize ( 13 );
#endif /*__WXMAC__*/
2020-09-13 02:17:19 +02:00
// wxSYS_OEM_FIXED_FONT and wxSYS_ANSI_FIXED_FONT use the same as
// DEFAULT in wxGtk. Use the TELETYPE family as a work-around
m_code_font = wxFont ( wxFontInfo (). Family ( wxFONTFAMILY_TELETYPE ));
m_code_font . SetPointSize ( m_normal_font . GetPointSize ());
2018-10-01 15:09:31 +02:00
}
2019-05-06 18:28:23 +02:00
void GUI_App :: update_fonts ( const MainFrame * main_frame )
2019-04-13 23:46:52 +02:00
{
2019-04-18 02:03:40 +02:00
/* Only normal and bold fonts are used for an application rescale,
* because of under MSW small and normal fonts are the same.
* To avoid same rescaling twice, just fill this values
* from rescaled MainFrame
*/
2019-05-06 18:28:23 +02:00
if ( main_frame == nullptr )
main_frame = this -> mainframe ;
m_normal_font = main_frame -> normal_font ();
m_small_font = m_normal_font ;
m_bold_font = main_frame -> normal_font (). Bold ();
m_em_unit = main_frame -> em_unit ();
2020-09-13 02:17:19 +02:00
m_code_font . SetPointSize ( m_normal_font . GetPointSize ());
2019-04-13 23:46:52 +02:00
}
2018-10-01 15:09:31 +02:00
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 ();
}
2020-05-22 15:23:05 +02:00
wxSize GUI_App :: get_min_size () const
{
return wxSize ( 76 * m_em_unit , 49 * m_em_unit );
}
2019-05-22 13:51:02 +02:00
float GUI_App :: toolbar_icon_scale ( const bool is_limited /* = false*/ ) const
{
#ifdef __APPLE__
const float icon_sc = 1.0f ; // for Retina display will be used its own scale
#else
const float icon_sc = m_em_unit * 0.1f ;
#endif // __APPLE__
const std :: string & use_val = app_config -> get ( "use_custom_toolbar_size" );
const std :: string & val = app_config -> get ( "custom_toolbar_size" );
2020-05-12 23:07:06 +02:00
const std :: string & auto_val = app_config -> get ( "auto_toolbar_size" );
2019-05-22 13:51:02 +02:00
2020-05-12 23:07:06 +02:00
if ( val . empty () || auto_val . empty () || use_val . empty ())
2019-05-22 13:51:02 +02:00
return icon_sc ;
2020-05-12 23:07:06 +02:00
int int_val = use_val == "0" ? 100 : atoi ( val . c_str ());
// correct value in respect to auto_toolbar_size
int_val = std :: min ( atoi ( auto_val . c_str ()), int_val );
2019-05-22 13:51:02 +02:00
if ( is_limited && int_val < 50 )
int_val = 50 ;
return 0.01f * int_val * icon_sc ;
}
2020-05-12 23:07:06 +02:00
void GUI_App :: set_auto_toolbar_icon_scale ( float scale ) const
{
#ifdef __APPLE__
const float icon_sc = 1.0f ; // for Retina display will be used its own scale
#else
const float icon_sc = m_em_unit * 0.1f ;
#endif // __APPLE__
2020-05-18 15:56:33 +02:00
long int_val = std :: min ( int ( std :: lround ( scale / icon_sc * 100 )), 100 );
2020-05-12 23:07:06 +02:00
std :: string val = std :: to_string ( int_val );
app_config -> set ( "auto_toolbar_size" , val );
}
2020-07-21 16:21:18 +02:00
// check user printer_presets for the containing information about "Print Host upload"
void GUI_App :: check_printer_presets ()
{
2020-07-28 11:31:16 +02:00
std :: vector < std :: string > preset_names = PhysicalPrinter :: presets_with_print_host_information ( preset_bundle -> printers );
if ( preset_names . empty ())
2020-07-21 16:21:18 +02:00
return ;
2020-10-07 18:08:16 +02:00
wxString msg_text = _L ( "You have the following presets with saved options for \" Print Host upload \" " ) + ":" ;
2020-07-28 11:31:16 +02:00
for ( const std :: string & preset_name : preset_names )
msg_text += " \n \" " + from_u8 ( preset_name ) + " \" ," ;
msg_text . RemoveLast ();
2020-11-05 22:17:49 +01:00
msg_text += " \n\n " + _L ( "But since this version of PrusaSlicer we don't show this information in Printer Settings anymore. \n "
"Settings will be available in physical printers settings." ) + " \n\n " +
2020-07-28 11:31:16 +02:00
_L ( "By default new Printer devices will be named as \" Printer N \" during its creation. \n "
"Note: This name can be changed later from the physical printers settings" );
2020-07-21 16:21:18 +02:00
2020-07-28 11:31:16 +02:00
wxMessageDialog ( nullptr , msg_text , _L ( "Information" ), wxOK | wxICON_INFORMATION ). ShowModal ();
2020-07-21 16:21:18 +02:00
2020-07-28 11:31:16 +02:00
preset_bundle -> physical_printers . load_printers_from_presets ( preset_bundle -> printers );
2020-07-21 16:21:18 +02:00
}
2020-05-07 15:36:50 +02:00
void GUI_App :: recreate_GUI ( const wxString & msg_name )
2018-09-20 08:40:22 +02:00
{
2020-10-12 08:39:40 +02:00
m_is_recreating_gui = true ;
2020-03-07 12:24:40 +01:00
mainframe -> shutdown ();
2019-03-26 10:08:57 +01:00
2020-07-10 10:20:57 +02:00
wxProgressDialog dlg ( msg_name , msg_name , 100 , nullptr , wxPD_AUTO_HIDE );
2019-03-26 10:08:57 +01:00
dlg . Pulse ();
2020-07-10 10:20:57 +02:00
dlg . Update ( 10 , _L ( "Recreating" ) + dots );
2019-03-26 10:08:57 +01:00
2020-03-07 12:24:40 +01:00
MainFrame * old_main_frame = mainframe ;
2018-12-19 17:38:41 +01:00
mainframe = new MainFrame ();
2020-10-12 08:39:40 +02:00
if ( is_editor ())
// hide settings tabs after first Layout
mainframe -> select_tab ( size_t ( 0 ));
2020-03-07 12:24:40 +01:00
// Propagate model objects to object list.
sidebar (). obj_list () -> init_objects ();
SetTopWindow ( mainframe );
2019-01-24 12:11:01 +01:00
2020-07-10 10:20:57 +02:00
dlg . Update ( 30 , _L ( "Recreating" ) + dots );
2020-03-07 12:24:40 +01:00
old_main_frame -> Destroy ();
// For this moment ConfigWizard is deleted, invalidate it.
m_wizard = nullptr ;
2018-09-20 08:40:22 +02:00
2020-07-10 10:20:57 +02:00
dlg . Update ( 80 , _L ( "Loading of current presets" ) + dots );
2018-12-19 17:38:41 +01:00
m_printhost_job_queue . reset ( new PrintHostJobQueue ( mainframe -> printhost_queue_dlg ()));
2019-01-24 15:32:50 +01:00
load_current_presets ();
2018-12-19 17:38:41 +01:00
mainframe -> Show ( true );
2020-07-10 10:20:57 +02:00
dlg . Update ( 90 , _L ( "Loading of a mode view" ) + dots );
2019-03-26 18:01:44 +01:00
/* Temporary workaround for the correct behavior of the Scrolled sidebar panel:
* change min hight of object list to the normal min value (15 * wxGetApp().em_unit())
* after first whole Mainframe updating/layouting
*/
2019-09-03 10:59:04 +02:00
const int list_min_height = 15 * em_unit ();
if ( obj_list () -> GetMinSize (). GetY () > list_min_height )
obj_list () -> SetMinSize ( wxSize ( - 1 , list_min_height ));
2019-03-26 10:08:57 +01:00
update_mode ();
// #ys_FIXME_delete_after_testing Do we still need this ?
// CallAfter([]() {
// // Run the config wizard, don't offer the "reset user profile" checkbox.
// config_wizard_startup(true);
// });
2020-10-12 08:39:40 +02:00
m_is_recreating_gui = false ;
2018-09-20 08:40:22 +02:00
}
void GUI_App :: system_info ()
{
2018-10-25 12:48:19 +02:00
SysInfoDialog dlg ;
dlg . ShowModal ();
2018-09-20 08:40:22 +02:00
}
2018-12-19 13:06:24 +01:00
void GUI_App :: keyboard_shortcuts ()
{
KBShortcutsDialog dlg ;
dlg . ShowModal ();
}
2018-09-20 08:40:22 +02: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 12:56:08 +01:00
const std :: string & err /*= ""*/ )
{
2018-09-20 08:40:22 +02: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 12:56:08 +01:00
void fatal_error ( wxWindow * parent )
{
2018-09-20 08:40:22 +02: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.
2020-10-19 12:34:33 +02:00
void GUI_App :: update_ui_from_settings ( bool apply_free_camera_correction )
2018-10-31 12:56:08 +01:00
{
2020-10-19 12:34:33 +02:00
mainframe -> update_ui_from_settings ( apply_free_camera_correction );
2018-09-20 08:40:22 +02:00
}
2019-04-29 16:55:41 +02:00
void GUI_App :: persist_window_geometry ( wxTopLevelWindow * window , bool default_maximized )
2019-01-11 18:09:21 +01:00
{
const std :: string name = into_u8 ( window -> GetName ());
window -> Bind ( wxEVT_CLOSE_WINDOW , [ = ]( wxCloseEvent & event ) {
window_pos_save ( window , name );
event . Skip ();
});
2019-04-29 16:55:41 +02:00
window_pos_restore ( window , name , default_maximized );
2019-02-07 15:55:47 +01:00
on_window_geometry ( window , [ = ]() {
window_pos_sanitize ( window );
2019-01-11 18:09:21 +01:00
});
}
2019-07-17 15:48:53 +02:00
void GUI_App :: load_project ( wxWindow * parent , wxString & input_file ) const
2018-09-20 13:12:35 +02:00
{
2018-11-15 15:27:39 +01:00
input_file . Clear ();
wxFileDialog dialog ( parent ? parent : GetTopWindow (),
2020-10-06 15:11:08 +02:00
_L ( "Choose one file (3MF/AMF):" ),
2018-11-15 15:27:39 +01:00
app_config -> get_last_dir (), "" ,
2019-05-15 10:23:02 +02:00
file_wildcards ( FT_PROJECT ), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
2018-11-15 15:27:39 +01:00
if ( dialog . ShowModal () == wxID_OK )
input_file = dialog . GetPath ();
}
2019-07-17 15:48:53 +02:00
void GUI_App :: import_model ( wxWindow * parent , wxArrayString & input_files ) const
2018-11-15 15:27:39 +01:00
{
input_files . Clear ();
wxFileDialog dialog ( parent ? parent : GetTopWindow (),
2020-10-06 15:11:08 +02:00
_L ( "Choose one or more files (STL/OBJ/AMF/3MF/PRUSA):" ),
2019-01-02 15:11:05 +01:00
from_u8 ( app_config -> get_last_dir ()), "" ,
2018-12-06 17:32:49 +01:00
file_wildcards ( FT_MODEL ), wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST );
2018-09-20 13:12:35 +02:00
2018-11-15 15:27:39 +01:00
if ( dialog . ShowModal () == wxID_OK )
dialog . GetPaths ( input_files );
2018-09-20 13:12:35 +02:00
}
2018-09-20 08:40:22 +02:00
2020-06-05 16:50:17 +02:00
void GUI_App :: load_gcode ( wxWindow * parent , wxString & input_file ) const
{
input_file . Clear ();
wxFileDialog dialog ( parent ? parent : GetTopWindow (),
2020-10-06 15:11:08 +02:00
_L ( "Choose one file (GCODE/.GCO/.G/.ngc/NGC):" ),
2020-06-05 16:50:17 +02:00
app_config -> get_last_dir (), "" ,
file_wildcards ( FT_GCODE ), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if ( dialog . ShowModal () == wxID_OK )
input_file = dialog . GetPath ();
}
2019-04-29 18:27:46 +02:00
bool GUI_App :: switch_language ()
2018-10-02 13:23:38 +02:00
{
2019-05-03 16:27:56 +02:00
if ( select_language ()) {
2020-05-07 15:36:50 +02:00
recreate_GUI ( _L ( "Changing of an application language" ) + dots );
2019-04-29 18:27:46 +02:00
return true ;
} else {
return false ;
2018-10-02 13:23:38 +02:00
}
2019-04-29 18:27:46 +02:00
}
2018-10-02 13:23:38 +02:00
// select language from the list of installed languages
2019-05-03 16:27:56 +02:00
bool GUI_App :: select_language ()
2018-10-02 13:23:38 +02:00
{
2019-08-29 14:07:45 +02:00
wxArrayString translations = wxTranslations :: Get () -> GetAvailableTranslations ( SLIC3R_APP_KEY );
std :: vector < const wxLanguageInfo *> language_infos ;
language_infos . emplace_back ( wxLocale :: GetLanguageInfo ( wxLANGUAGE_ENGLISH ));
2020-11-30 11:57:16 +01:00
#ifdef __linux__
// wxWidgets consider the default English locale to be en_GB, which is often missing on Linux.
// Thus we offer en_US on Linux as well.
language_infos . emplace_back ( wxLocale :: GetLanguageInfo ( wxLANGUAGE_ENGLISH_US ));
2020-12-05 09:12:28 +01:00
//FIXME https://github.com/prusa3d/PrusaSlicer/issues/2580#issuecomment-524546743
// In a correctly set up system, "locale -a" will get all the installed locales on that system.
// According to the installed locales, the locales for the dictionaries may be modified with the available
// CanonicalName of the locale, possibly duplicating the entries for each CanonicalName of the dictionary.
// Other languages with missing locales of the system can be greyed out or not shown at all.
2020-11-30 11:57:16 +01:00
#endif // __linux__
2019-08-29 14:07:45 +02:00
for ( size_t i = 0 ; i < translations . GetCount (); ++ i ) {
const wxLanguageInfo * langinfo = wxLocale :: FindLanguageInfo ( translations [ i ]);
if ( langinfo != nullptr )
language_infos . emplace_back ( langinfo );
}
sort_remove_duplicates ( language_infos );
std :: sort ( language_infos . begin (), language_infos . end (), []( const wxLanguageInfo * l , const wxLanguageInfo * r ) { return l -> Description < r -> Description ; });
2019-05-03 16:27:56 +02:00
wxArrayString names ;
2019-08-29 14:07:45 +02:00
names . Alloc ( language_infos . size ());
2019-05-03 16:27:56 +02:00
2019-08-28 11:53:53 +02:00
// Some valid language should be selected since the application start up.
2019-08-29 14:07:45 +02:00
const wxLanguage current_language = wxLanguage ( m_wxLocale -> GetLanguage ());
int init_selection = - 1 ;
int init_selection_alt = - 1 ;
int init_selection_default = - 1 ;
for ( size_t i = 0 ; i < language_infos . size (); ++ i ) {
if ( wxLanguage ( language_infos [ i ] -> Language ) == current_language )
// The dictionary matches the active language and country.
2019-05-03 16:27:56 +02:00
init_selection = i ;
2019-08-29 14:07:45 +02:00
else if (( language_infos [ i ] -> CanonicalName . BeforeFirst ( '_' ) == m_wxLocale -> GetCanonicalName (). BeforeFirst ( '_' )) ||
// if the active language is Slovak, mark the Czech language as active.
( language_infos [ i ] -> CanonicalName . BeforeFirst ( '_' ) == "cs" && m_wxLocale -> GetCanonicalName (). BeforeFirst ( '_' ) == "sk" ))
// The dictionary matches the active language, it does not necessarily match the country.
init_selection_alt = i ;
if ( language_infos [ i ] -> CanonicalName . BeforeFirst ( '_' ) == "en" )
// This will be the default selection if the active language does not match any dictionary.
init_selection_default = i ;
2020-11-30 11:57:16 +01:00
#ifdef __linux__
// wxWidgets consider the default English locale to be en_GB, which is often missing on Linux.
// Thus we make the distintion between "en_US" and "en_GB" clear.
if ( language_infos [ i ] -> CanonicalName == "en_GB" && language_infos [ i ] -> Description == "English" )
names . Add ( "English (U.K.)" );
else
#endif // __linux__
2019-08-29 14:07:45 +02:00
names . Add ( language_infos [ i ] -> Description );
2018-10-02 13:23:38 +02:00
}
2019-08-29 14:07:45 +02:00
if ( init_selection == - 1 )
// This is the dictionary matching the active language.
init_selection = init_selection_alt ;
if ( init_selection != - 1 )
// This is the language to highlight in the choice dialog initially.
init_selection_default = init_selection ;
2019-05-03 16:27:56 +02:00
2020-10-06 15:11:08 +02:00
const long index = wxGetSingleChoiceIndex ( _L ( "Select the language" ), _L ( "Language" ), names , init_selection_default );
2019-08-28 11:53:53 +02:00
// Try to load a new language.
2019-08-29 15:35:28 +02:00
if ( index != - 1 && ( init_selection == - 1 || init_selection != index )) {
const wxLanguageInfo * new_language_info = language_infos [ index ];
if ( this -> load_language ( new_language_info -> CanonicalName , false )) {
// Save language at application config.
2020-03-26 14:27:18 +01:00
// Which language to save as the selected dictionary language?
// 1) Hopefully the language set to wxTranslations by this->load_language(), but that API is weird and we don't want to rely on its
// stability in the future:
// wxTranslations::Get()->GetBestTranslation(SLIC3R_APP_KEY, wxLANGUAGE_ENGLISH);
// 2) Current locale language may not match the dictionary name, see GH issue #3901
// m_wxLocale->GetCanonicalName()
// 3) new_language_info->CanonicalName is a safe bet. It points to a valid dictionary name.
app_config -> set ( "translation_language" , new_language_info -> CanonicalName . ToUTF8 (). data ());
2019-08-29 15:35:28 +02:00
app_config -> save ();
return true ;
}
2018-10-02 13:23:38 +02:00
}
2019-05-03 16:27:56 +02:00
2018-10-02 13:23:38 +02:00
return false ;
}
2019-05-10 14:43:35 +02:00
// Load gettext translation files and activate them at the start of the application,
// based on the "translation_language" key stored in the application config.
2019-08-29 14:07:45 +02:00
bool GUI_App :: load_language ( wxString language , bool initial )
2018-09-21 01:33:41 +02:00
{
2019-08-29 14:07:45 +02:00
if ( initial ) {
// There is a static list of lookup path prefixes in wxWidgets. Add ours.
wxFileTranslationsLoader :: AddCatalogLookupPathPrefix ( from_u8 ( localization_dir ()));
// Get the active language from PrusaSlicer.ini, or empty string if the key does not exist.
language = app_config -> get ( "translation_language" );
2019-08-30 10:20:38 +02:00
if ( ! language . empty ())
BOOST_LOG_TRIVIAL ( trace ) << boost :: format ( "translation_language provided by PrusaSlicer.ini: %1%" ) % language ;
2019-08-29 15:35:28 +02:00
// Get the system language.
{
const wxLanguage lang_system = wxLanguage ( wxLocale :: GetSystemLanguage ());
2019-08-30 10:20:38 +02:00
if ( lang_system != wxLANGUAGE_UNKNOWN ) {
2019-08-29 15:35:28 +02:00
m_language_info_system = wxLocale :: GetLanguageInfo ( lang_system );
2019-08-30 10:20:38 +02:00
BOOST_LOG_TRIVIAL ( trace ) << boost :: format ( "System language detected (user locales and such): %1%" ) % m_language_info_system -> CanonicalName . ToUTF8 (). data ();
}
2019-08-29 15:35:28 +02:00
}
2019-08-29 14:07:45 +02:00
{
// Allocating a temporary locale will switch the default wxTranslations to its internal wxTranslations instance.
wxLocale temp_locale ;
// Set the current translation's language to default, otherwise GetBestTranslation() may not work (see the wxWidgets source code).
wxTranslations :: Get () -> SetLanguage ( wxLANGUAGE_DEFAULT );
// Let the wxFileTranslationsLoader enumerate all translation dictionaries for PrusaSlicer
// and try to match them with the system specific "preferred languages".
// There seems to be a support for that on Windows and OSX, while on Linuxes the code just returns wxLocale::GetSystemLanguage().
// The last parameter gets added to the list of detected dictionaries. This is a workaround
// for not having the English dictionary. Let's hope wxWidgets of various versions process this call the same way.
wxString best_language = wxTranslations :: Get () -> GetBestTranslation ( SLIC3R_APP_KEY , wxLANGUAGE_ENGLISH );
2019-08-30 10:20:38 +02:00
if ( ! best_language . IsEmpty ()) {
2019-08-29 15:35:28 +02:00
m_language_info_best = wxLocale :: FindLanguageInfo ( best_language );
2019-08-30 10:20:38 +02:00
BOOST_LOG_TRIVIAL ( trace ) << boost :: format ( "Best translation language detected (may be different from user locales): %1%" ) % m_language_info_best -> CanonicalName . ToUTF8 (). data ();
}
2019-08-29 14:07:45 +02:00
}
2019-08-29 15:35:28 +02:00
}
2019-08-30 14:13:47 +02:00
const wxLanguageInfo * language_info = language . empty () ? nullptr : wxLocale :: FindLanguageInfo ( language );
if ( ! language . empty () && ( language_info == nullptr || language_info -> CanonicalName . empty ())) {
// Fix for wxWidgets issue, where the FindLanguageInfo() returns locales with undefined ANSII code (wxLANGUAGE_KONKANI or wxLANGUAGE_MANIPURI).
language_info = nullptr ;
2019-08-30 10:20:38 +02:00
BOOST_LOG_TRIVIAL ( error ) << boost :: format ( "Language code \" %1% \" is not supported" ) % language . ToUTF8 (). data ();
2019-08-30 14:13:47 +02:00
}
2019-08-29 15:35:28 +02:00
2019-08-30 10:20:38 +02:00
if ( language_info != nullptr && language_info -> LayoutDirection == wxLayout_RightToLeft ) {
BOOST_LOG_TRIVIAL ( trace ) << boost :: format ( "The following language code requires right to left layout, which is not supported by PrusaSlicer: %1%" ) % language_info -> CanonicalName . ToUTF8 (). data ();
language_info = nullptr ;
}
if ( language_info == nullptr ) {
2020-03-26 14:27:18 +01:00
// PrusaSlicer does not support the Right to Left languages yet.
2019-08-29 15:35:28 +02:00
if ( m_language_info_system != nullptr && m_language_info_system -> LayoutDirection != wxLayout_RightToLeft )
2019-08-30 10:20:38 +02:00
language_info = m_language_info_system ;
2019-08-29 15:35:28 +02:00
if ( m_language_info_best != nullptr && m_language_info_best -> LayoutDirection != wxLayout_RightToLeft )
2019-08-30 10:20:38 +02:00
language_info = m_language_info_best ;
if ( language_info == nullptr )
language_info = wxLocale :: GetLanguageInfo ( wxLANGUAGE_ENGLISH_US );
2019-08-29 14:07:45 +02:00
}
2019-08-30 10:20:38 +02:00
BOOST_LOG_TRIVIAL ( trace ) << boost :: format ( "Switching wxLocales to %1%" ) % language_info -> CanonicalName . ToUTF8 (). data ();
2019-08-28 11:53:53 +02:00
2019-08-28 11:59:30 +02:00
// Alternate language code.
2019-08-29 14:07:45 +02:00
wxLanguage language_dict = wxLanguage ( language_info -> Language );
2019-08-30 10:20:38 +02:00
if ( language_info -> CanonicalName . BeforeFirst ( '_' ) == "sk" ) {
2019-08-28 11:59:30 +02:00
// Slovaks understand Czech well. Give them the Czech translation.
2019-08-29 14:07:45 +02:00
language_dict = wxLANGUAGE_CZECH ;
2019-08-30 10:20:38 +02:00
BOOST_LOG_TRIVIAL ( trace ) << "Using Czech dictionaries for Slovak language" ;
}
2019-08-28 11:59:30 +02:00
2020-03-26 14:27:18 +01:00
// Select language for locales. This language may be different from the language of the dictionary.
if ( language_info == m_language_info_best || language_info == m_language_info_system ) {
// The current language matches user's default profile exactly. That's great.
} else if ( m_language_info_best != nullptr && language_info -> CanonicalName . BeforeFirst ( '_' ) == m_language_info_best -> CanonicalName . BeforeFirst ( '_' )) {
// Use whatever the operating system recommends, if it the language code of the dictionary matches the recommended language.
// This allows a Swiss guy to use a German dictionary without forcing him to German locales.
language_info = m_language_info_best ;
} else if ( m_language_info_system != nullptr && language_info -> CanonicalName . BeforeFirst ( '_' ) == m_language_info_system -> CanonicalName . BeforeFirst ( '_' ))
language_info = m_language_info_system ;
2019-08-29 14:07:45 +02:00
if ( ! wxLocale :: IsAvailable ( language_info -> Language )) {
2019-08-28 11:53:53 +02:00
// Loading the language dictionary failed.
2019-08-29 14:07:45 +02:00
wxString message = "Switching PrusaSlicer to language " + language_info -> CanonicalName + " failed." ;
2019-08-28 11:53:53 +02:00
#if !defined(_WIN32) && !defined(__APPLE__)
2019-08-29 14:07:45 +02:00
// likely some linux system
message += " \n You may need to reconfigure the missing locales, likely by running the \" locale-gen \" and \" dpkg-reconfigure locales \" commands. \n " ;
2019-08-28 11:53:53 +02:00
#endif
2019-08-29 14:07:45 +02:00
if ( initial )
2019-08-28 11:53:53 +02:00
message + " \n\n Application will close." ;
2019-09-24 16:01:01 +02:00
wxMessageBox ( message , "PrusaSlicer - Switching language failed" , wxOK | wxICON_ERROR );
2019-08-29 14:07:45 +02:00
if ( initial )
std :: exit ( EXIT_FAILURE );
2019-08-28 11:53:53 +02:00
else
return false ;
2019-05-10 14:43:35 +02:00
}
2019-08-29 14:07:45 +02:00
// Release the old locales, create new locales.
2019-08-29 15:35:28 +02:00
//FIXME wxWidgets cause havoc if the current locale is deleted. We just forget it causing memory leaks for now.
2019-08-29 14:07:45 +02:00
m_wxLocale . release ();
2019-08-29 14:51:24 +02:00
m_wxLocale = Slic3r :: make_unique < wxLocale > ();
2019-08-29 14:07:45 +02:00
m_wxLocale -> Init ( language_info -> Language );
// Override language at the active wxTranslations class (which is stored in the active m_wxLocale)
// to load possibly different dictionary, for example, load Czech dictionary for Slovak language.
wxTranslations :: Get () -> SetLanguage ( language_dict );
2019-08-28 11:53:53 +02:00
m_wxLocale -> AddCatalog ( SLIC3R_APP_KEY );
2019-08-29 14:07:45 +02:00
m_imgui -> set_language ( into_u8 ( language_info -> CanonicalName ));
2020-03-02 10:58:46 +01:00
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
2019-05-10 14:43:35 +02:00
wxSetlocale ( LC_NUMERIC , "C" );
2020-06-16 16:58:41 +02:00
Preset :: update_suffix_modified (( " (" + _L ( "modified" ) + ")" ). ToUTF8 (). data ());
2019-08-28 13:23:58 +02:00
return true ;
2018-09-21 01:33:41 +02:00
}
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 )
2020-02-27 11:44:01 +01:00
return tab -> completed () ? tab : nullptr ; // To avoid actions with no-completed Tab
2018-10-10 13:53:45 +02:00
return nullptr ;
}
2019-01-10 11:05:58 +01:00
ConfigOptionMode GUI_App :: get_mode ()
2018-09-21 01:33:41 +02:00
{
if ( ! app_config -> has ( "view_mode" ))
2019-01-10 11:05:58 +01:00
return comSimple ;
2018-09-21 01:33:41 +02:00
const auto mode = app_config -> get ( "view_mode" );
2019-01-10 11:05:58 +01:00
return mode == "expert" ? comExpert :
mode == "simple" ? comSimple : comAdvanced ;
2018-09-21 01:33:41 +02:00
}
2019-01-10 11:05:58 +01: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 09:19:00 +01:00
}
2018-10-03 15:14:52 +02:00
// Update view mode according to selected menu
void GUI_App :: update_mode ()
{
2019-03-01 12:03:14 +01:00
sidebar (). update_mode ();
2018-10-19 13:55:29 +02:00
for ( auto tab : tabs_list )
2019-03-20 16:22:01 +01:00
tab -> update_mode ();
2018-12-07 17:50:48 +01:00
plater () -> update_object_menu ();
2020-08-05 13:30:05 +02:00
plater () -> canvas3D () -> update_gizmos_on_off_state ();
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 ();
2019-05-21 14:06:43 +02:00
wxWindowID config_id_base = wxWindow :: NewControlId ( int ( ConfigMenuCnt ));
2018-09-21 01:33:41 +02:00
2020-02-24 10:54:50 +01:00
const auto config_wizard_name = _ ( ConfigWizard :: name ( true ));
2020-03-02 11:48:31 +01:00
const auto config_wizard_tooltip = from_u8 (( boost :: format ( _utf8 ( L ( "Run %s" ))) % config_wizard_name ). str ());
2018-09-21 01:33:41 +02:00
// Cmd+, is standard on OS X - what about other operating systems?
2020-10-06 15:11:08 +02:00
if ( is_editor ()) {
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 +
2019-02-03 12:12:26 +01:00
#ifdef __APPLE__
" \t Ctrl+," ,
#else
" \t Ctrl+P" ,
#endif
2020-10-06 15:11:08 +02:00
_L ( "Application preferences" ));
wxMenu * mode_menu = nullptr ;
if ( is_editor ()) {
local_menu -> AppendSeparator ();
mode_menu = new wxMenu ();
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 + ConfigMenuModeAdvanced , _CTX ( L_CONTEXT ( "Advanced" , "Mode" ), "Mode" ), _L ( "Advanced View Mode" ));
mode_menu -> AppendRadioItem ( config_id_base + ConfigMenuModeExpert , _L ( "Expert" ), _L ( "Expert View Mode" ));
Bind ( wxEVT_UPDATE_UI , [ this ]( wxUpdateUIEvent & evt ) { if ( get_mode () == comSimple ) evt . Check ( true ); }, config_id_base + ConfigMenuModeSimple );
Bind ( wxEVT_UPDATE_UI , [ this ]( wxUpdateUIEvent & evt ) { if ( get_mode () == comAdvanced ) evt . Check ( true ); }, config_id_base + ConfigMenuModeAdvanced );
Bind ( wxEVT_UPDATE_UI , [ this ]( wxUpdateUIEvent & evt ) { if ( get_mode () == comExpert ) evt . Check ( true ); }, config_id_base + ConfigMenuModeExpert );
2019-02-06 10:47:19 +01:00
2020-10-06 15:11:08 +02:00
local_menu -> AppendSubMenu ( mode_menu , _L ( "Mode" ), wxString :: Format ( _L ( "%s View Mode" ), SLIC3R_APP_NAME ));
2020-10-12 08:39:40 +02:00
}
local_menu -> AppendSeparator ();
local_menu -> Append ( config_id_base + ConfigMenuLanguage , _L ( "&Language" ));
if ( is_editor ()) {
2020-10-06 15:11:08 +02:00
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"));
}
2018-09-21 01:33:41 +02:00
2018-10-31 12:56:08 +01:00
local_menu -> Bind ( wxEVT_MENU , [ this , config_id_base ]( wxEvent & event ) {
2018-09-21 01:33:41 +02:00
switch ( event . GetId () - config_id_base ) {
case ConfigMenuWizard :
2019-06-04 18:01:41 +02:00
run_wizard ( ConfigWizard :: RR_USER );
2018-09-21 01:33:41 +02:00
break ;
2020-02-04 15:24:35 +01:00
case ConfigMenuUpdate :
check_updates ( true );
break ;
2018-09-21 01:33:41 +02:00
case ConfigMenuTakeSnapshot :
// Take a configuration snapshot.
if ( check_unsaved_changes ()) {
2020-10-06 15:11:08 +02:00
wxTextEntryDialog dlg ( nullptr , _L ( "Taking configuration snapshot" ), _L ( "Snapshot name" ));
2019-04-18 15:05:17 +02:00
// set current normal font for dialog children,
// because of just dlg.SetFont(normal_font()) has no result;
for ( auto child : dlg . GetChildren ())
child -> SetFont ( normal_font ());
2018-09-21 01:33:41 +02:00
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 ()) {
2020-12-07 19:47:37 +01:00
if ( ! Config :: SnapshotDB :: singleton (). is_on_snapshot ( * app_config ))
2018-09-21 01:33:41 +02:00
Config :: SnapshotDB :: singleton (). take_snapshot ( * app_config , Config :: Snapshot :: SNAPSHOT_BEFORE_ROLLBACK );
2020-12-07 19:47:37 +01:00
try {
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 ();
} catch ( std :: exception & ex ) {
GUI :: show_error ( nullptr , _L ( "Failed to activate configuration snapshot." ) + " \n " + into_u8 ( ex . what ()));
}
2018-09-21 01:33:41 +02:00
}
}
break ;
case ConfigMenuPreferences :
{
2020-06-11 14:02:59 +02:00
bool app_layout_changed = false ;
2020-05-07 15:36:50 +02:00
{
// the dialog needs to be destroyed before the call to recreate_GUI()
// or sometimes the application crashes into wxDialogBase() destructor
// so we put it into an inner scope
PreferencesDialog dlg ( mainframe );
dlg . ShowModal ();
2020-06-11 14:02:59 +02:00
app_layout_changed = dlg . settings_layout_changed ();
2020-10-15 10:25:13 +02:00
if ( dlg . seq_top_layer_only_changed ())
this -> plater_ -> refresh_print ();
2020-11-26 10:09:34 +01:00
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
#ifdef _WIN32
if ( is_editor ()) {
if ( app_config -> get ( "associate_3mf" ) == "1" )
associate_3mf_files ();
if ( app_config -> get ( "associate_stl" ) == "1" )
associate_stl_files ();
}
else {
if ( app_config -> get ( "associate_gcode" ) == "1" )
associate_gcode_files ();
}
#endif // _WIN32
#endif // ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
2020-05-07 15:36:50 +02:00
}
2020-06-19 11:04:08 +02:00
if ( app_layout_changed ) {
2020-09-03 09:27:53 +02:00
// hide full main_sizer for mainFrame
mainframe -> GetSizer () -> Show ( false );
2020-06-11 14:02:59 +02:00
mainframe -> update_layout ();
2020-09-24 15:41:48 +02:00
mainframe -> select_tab ( size_t ( 0 ));
2020-06-11 14:02:59 +02:00
}
2018-09-21 01:33:41 +02:00
break ;
}
case ConfigMenuLanguage :
{
2019-03-28 10:54:56 +01:00
/* Before change application language, let's check unsaved changes on 3D-Scene
2019-03-26 18:01:44 +01:00
* and draw user's attention to the application restarting after a language change
*/
2020-03-11 12:19:52 +01:00
{
// the dialog needs to be destroyed before the call to switch_language()
// or sometimes the application crashes into wxDialogBase() destructor
// so we put it into an inner scope
2020-10-12 08:39:40 +02:00
wxString title = is_editor () ? wxString ( SLIC3R_APP_NAME ) : wxString ( GCODEVIEWER_APP_NAME );
title += " - " + _L ( "Language selection" );
2020-03-11 12:19:52 +01:00
wxMessageDialog dialog ( nullptr ,
2020-10-06 15:11:08 +02:00
_L ( "Switching the language will trigger application restart. \n "
"You will lose content of the plater." ) + " \n\n " +
_L ( "Do you want to proceed?" ),
2020-10-12 08:39:40 +02:00
title ,
2020-03-11 12:19:52 +01:00
wxICON_QUESTION | wxOK | wxCANCEL );
if ( dialog . ShowModal () == wxID_CANCEL )
return ;
}
2019-03-26 18:01:44 +01:00
2019-04-29 18:27:46 +02:00
switch_language ();
2018-09-21 01:33:41 +02:00
break ;
}
case ConfigMenuFlashFirmware :
FirmwareDialog :: run ( mainframe );
break ;
default :
break ;
}
});
2019-05-21 14:06:43 +02:00
using std :: placeholders :: _1 ;
2020-10-12 12:38:34 +02:00
2020-10-06 15:11:08 +02:00
if ( mode_menu != nullptr ) {
auto modfn = [ this ]( int mode , wxCommandEvent & ) { if ( get_mode () != mode ) save_mode ( mode ); };
mode_menu -> Bind ( wxEVT_MENU , std :: bind ( modfn , comSimple , _1 ), config_id_base + ConfigMenuModeSimple );
mode_menu -> Bind ( wxEVT_MENU , std :: bind ( modfn , comAdvanced , _1 ), config_id_base + ConfigMenuModeAdvanced );
mode_menu -> Bind ( wxEVT_MENU , std :: bind ( modfn , comExpert , _1 ), config_id_base + ConfigMenuModeExpert );
}
2019-05-21 14:06:43 +02:00
2020-10-06 15:11:08 +02:00
menu -> Append ( local_menu , _L ( "&Configuration" ));
2018-09-21 01:33:41 +02:00
}
// 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.
2019-07-18 17:41:47 +02:00
bool GUI_App :: check_unsaved_changes ( const wxString & header )
2018-09-21 01:33:41 +02:00
{
2018-10-31 16:22:36 +01:00
PrinterTechnology printer_technology = preset_bundle -> printers . get_edited_preset (). printer_technology ();
2020-08-14 18:17:16 +02:00
bool has_unsaved_changes = false ;
for ( Tab * tab : tabs_list )
2019-09-03 10:27:16 +02:00
if ( tab -> supports_printer_technology ( printer_technology ) && tab -> current_preset_is_dirty ()) {
2020-08-14 18:17:16 +02:00
has_unsaved_changes = true ;
break ;
2019-09-03 10:27:16 +02:00
}
2020-08-14 18:17:16 +02:00
if ( has_unsaved_changes )
{
UnsavedChangesDialog dlg ( header );
2020-10-15 16:48:48 +02:00
if ( wxGetApp (). app_config -> get ( "default_action_on_close_application" ) == "none" && dlg . ShowModal () == wxID_CANCEL )
2020-08-14 18:17:16 +02:00
return false ;
if ( dlg . save_preset ()) // save selected changes
{
2020-10-03 03:15:54 +02:00
for ( const std :: pair < std :: string , Preset :: Type >& nt : dlg . get_names_and_types ())
preset_bundle -> save_changes_for_preset ( nt . first , nt . second , dlg . get_unselected_options ( nt . second ));
2020-08-14 18:17:16 +02:00
// if we saved changes to the new presets, we should to
// synchronize config.ini with the current selections.
preset_bundle -> export_selections ( * app_config );
2020-10-06 12:32:11 +02:00
wxMessageBox ( _L ( "The preset(s) modifications are successfully saved" ));
2020-08-14 18:17:16 +02:00
}
}
return true ;
2018-09-21 01:33:41 +02:00
}
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 ;
}
// Update UI / Tabs to reflect changes in the currently loaded presets
2020-12-03 13:24:55 +01:00
void GUI_App :: load_current_presets ( bool check_printer_presets_ /*= true*/ )
2018-10-01 15:09:31 +02:00
{
2020-07-21 16:21:18 +02:00
// check printer_presets for the containing information about "Print Host upload"
// and create physical printer from it, if any exists
2020-12-03 13:24:55 +01:00
if ( check_printer_presets_ )
check_printer_presets ();
2020-07-21 16:21:18 +02:00
2018-10-31 16:22:36 +01:00
PrinterTechnology printer_technology = preset_bundle -> printers . get_edited_preset (). printer_technology ();
2018-12-03 13:14:28 +01:00
this -> plater () -> set_printer_technology ( printer_technology );
2018-10-31 16:22:36 +01:00
for ( Tab * tab : tabs_list )
2018-10-31 18:05:25 +01:00
if ( tab -> supports_printer_technology ( printer_technology )) {
2020-01-24 15:16:28 +01:00
if ( tab -> type () == Preset :: TYPE_PRINTER ) {
2018-10-31 18:05:25 +01:00
static_cast < TabPrinter *> ( tab ) -> update_pages ();
2020-01-24 15:16:28 +01:00
// Mark the plater to update print bed by tab->load_current_preset() from Plater::on_config_change().
this -> plater () -> force_print_bed_update ();
}
2018-10-31 18:05:25 +01:00
tab -> load_current_preset ();
}
2018-10-01 15:09:31 +02:00
}
2019-02-14 15:28:18 +01:00
bool GUI_App :: OnExceptionInMainLoop ()
{
2019-04-09 11:28:11 +02:00
generic_exception_handle ();
2019-02-14 15:28:18 +01:00
return false ;
}
2019-01-09 15:40:12 +01:00
#ifdef __APPLE__
2020-10-06 15:09:38 +02:00
// This callback is called from wxEntry()->wxApp::CallOnInit()->NSApplication run
// that is, before GUI_App::OnInit(), so we have a chance to switch GUI_App
// to a G-code viewer.
2020-10-06 14:23:17 +02:00
void GUI_App :: OSXStoreOpenFiles ( const wxArrayString & fileNames )
{
2020-10-06 15:43:21 +02:00
size_t num_gcodes = 0 ;
for ( const wxString & filename : fileNames ) {
wxString fn = filename . Upper ();
if ( fn . EndsWith ( ".G" ) || fn . EndsWith ( ".GCODE" ))
++ num_gcodes ;
2020-10-06 14:23:17 +02:00
}
2020-10-06 15:43:21 +02:00
if ( fileNames . size () == num_gcodes ) {
// Opening PrusaSlicer by drag & dropping a G-Code onto PrusaSlicer icon in Finder,
// just G-codes were passed. Switch to G-code viewer mode.
2020-10-06 15:09:38 +02:00
m_app_mode = EAppMode :: GCodeViewer ;
2020-10-14 08:46:30 +02:00
unlock_lockfile ( get_instance_hash_string () + ".lock" , data_dir () + "/cache/" );
2020-10-12 13:44:08 +02:00
if ( app_config != nullptr )
delete app_config ;
app_config = nullptr ;
init_app_config ();
2020-10-06 14:23:17 +02:00
}
2020-10-06 15:43:21 +02:00
wxApp :: OSXStoreOpenFiles ( fileNames );
2020-10-06 11:07:49 +02:00
}
2019-01-09 15:40:12 +01:00
// wxWidgets override to get an event on open files.
void GUI_App :: MacOpenFiles ( const wxArrayString & fileNames )
{
std :: vector < std :: string > files ;
2020-10-06 11:07:49 +02:00
std :: vector < wxString > gcode_files ;
2020-10-12 13:44:08 +02:00
std :: vector < wxString > non_gcode_files ;
2020-10-06 09:56:36 +02:00
for ( const auto & filename : fileNames ) {
2020-10-06 15:43:21 +02:00
wxString fn = filename . Upper ();
if ( fn . EndsWith ( ".G" ) || fn . EndsWith ( ".GCODE" ))
2020-10-06 11:07:49 +02:00
gcode_files . emplace_back ( filename );
2020-10-12 13:44:08 +02:00
else {
2020-10-06 15:43:21 +02:00
files . emplace_back ( into_u8 ( filename ));
2020-10-12 13:44:08 +02:00
non_gcode_files . emplace_back ( filename );
}
2020-10-06 09:56:36 +02:00
}
2020-10-06 15:43:21 +02:00
if ( m_app_mode == EAppMode :: GCodeViewer ) {
// Running in G-code viewer.
// Load the first G-code into the G-code viewer.
2020-10-12 13:44:08 +02:00
// Or if no G-codes, send other files to slicer.
2020-10-06 15:43:21 +02:00
if ( ! gcode_files . empty ())
this -> plater () -> load_gcode ( gcode_files . front ());
2020-10-12 13:44:08 +02:00
if ( ! non_gcode_files . empty ())
start_new_slicer ( non_gcode_files , true );
2020-10-06 15:43:21 +02:00
} else {
2020-11-27 12:51:49 +01:00
if ( ! files . empty ()) {
#if ENABLE_DRAG_AND_DROP_FIX
wxArrayString input_files ;
for ( size_t i = 0 ; i < non_gcode_files . size (); ++ i ) {
input_files . push_back ( non_gcode_files [ i ]);
}
this -> plater () -> load_files ( input_files );
#else
2020-10-06 15:43:21 +02:00
this -> plater () -> load_files ( files , true , true );
2020-11-27 12:51:49 +01:00
#endif
}
2020-10-06 11:07:49 +02:00
for ( const wxString & filename : gcode_files )
start_new_gcodeviewer ( & filename );
}
2019-01-09 15:40:12 +01:00
}
#endif /* __APPLE */
2018-10-04 16:43:10 +02:00
Sidebar & GUI_App :: sidebar ()
{
2018-10-24 12:57:23 +02:00
return plater_ -> sidebar ();
2018-10-04 16:43:10 +02:00
}
ObjectManipulation * GUI_App :: obj_manipul ()
{
2019-01-14 14:42:21 +01: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 16:43:10 +02:00
}
2018-11-09 18:39:07 +01:00
ObjectSettings * GUI_App :: obj_settings ()
{
return sidebar (). obj_settings ();
}
2018-10-05 23:29:15 +02:00
ObjectList * GUI_App :: obj_list ()
{
return sidebar (). obj_list ();
}
2019-05-28 16:38:04 +02:00
ObjectLayers * GUI_App :: obj_layers ()
{
return sidebar (). obj_layers ();
}
2018-10-08 16:27:38 +02:00
Plater * GUI_App :: plater ()
{
2018-10-24 12:57:23 +02:00
return plater_ ;
2018-10-08 16:27:38 +02:00
}
2019-07-18 17:41:47 +02:00
Model & GUI_App :: model ()
2018-10-05 23:29:15 +02:00
{
2019-07-18 17:41:47 +02:00
return plater_ -> model ();
2018-10-05 23:29:15 +02:00
}
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 ;
}
2019-06-03 14:52:15 +02:00
// extruders count from selected printer preset
2019-03-19 14:36:32 +01:00
int GUI_App :: extruders_cnt () const
{
const Preset & preset = preset_bundle -> printers . get_selected_preset ();
return preset . printer_technology () == ptSLA ? 1 :
preset . config . option < ConfigOptionFloats > ( "nozzle_diameter" ) -> values . size ();
}
2019-06-03 14:52:15 +02:00
// extruders count from edited printer preset
int GUI_App :: extruders_edited_cnt () const
{
const Preset & preset = preset_bundle -> printers . get_edited_preset ();
return preset . printer_technology () == ptSLA ? 1 :
preset . config . option < ConfigOptionFloats > ( "nozzle_diameter" ) -> values . size ();
}
2019-07-29 17:55:50 +02:00
wxString GUI_App :: current_language_code_safe () const
{
// Translate the language code to a code, for which Prusa Research maintains translations.
const std :: map < wxString , wxString > mapping {
{ "cs" , "cs_CZ" , },
2019-08-06 17:27:36 +02:00
{ "sk" , "cs_CZ" , },
2019-07-29 17:55:50 +02:00
{ "de" , "de_DE" , },
{ "es" , "es_ES" , },
{ "fr" , "fr_FR" , },
{ "it" , "it_IT" , },
{ "ja" , "ja_JP" , },
{ "ko" , "ko_KR" , },
{ "pl" , "pl_PL" , },
{ "uk" , "uk_UA" , },
{ "zh" , "zh_CN" , },
2020-12-01 16:43:34 +01:00
{ "ru" , "ru_RU" , },
2019-07-29 17:55:50 +02:00
};
2019-08-29 14:07:45 +02:00
wxString language_code = this -> current_language_code (). BeforeFirst ( '_' );
2019-07-29 17:55:50 +02:00
auto it = mapping . find ( language_code );
if ( it != mapping . end ())
language_code = it -> second ;
else
language_code = "en_US" ;
return language_code ;
}
2019-05-13 16:34:41 +02:00
void GUI_App :: open_web_page_localized ( const std :: string & http_address )
{
2019-07-29 17:55:50 +02:00
wxLaunchDefaultBrowser ( http_address + "&lng=" + this -> current_language_code_safe ());
2019-05-13 16:34:41 +02:00
}
2019-06-04 18:01:41 +02:00
bool GUI_App :: run_wizard ( ConfigWizard :: RunReason reason , ConfigWizard :: StartPage start_page )
{
2019-06-17 16:39:22 +02:00
wxCHECK_MSG ( mainframe != nullptr , false , "Internal error: Main frame not created / null" );
2019-06-04 18:01:41 +02:00
if ( ! m_wizard ) {
2019-06-17 16:39:22 +02:00
m_wizard = new ConfigWizard ( mainframe );
2019-06-04 18:01:41 +02:00
}
const bool res = m_wizard -> run ( reason , start_page );
if ( res ) {
load_current_presets ();
if ( preset_bundle -> printers . get_edited_preset (). printer_technology () == ptSLA
&& Slic3r :: model_has_multi_part_objects ( wxGetApp (). model ())) {
GUI :: show_info ( nullptr ,
2020-10-06 15:11:08 +02:00
_L ( "It's impossible to print multi-part object(s) with SLA technology." ) + " \n\n " +
_L ( "Please check and fix your object list." ),
_L ( "Attention!" ));
2019-06-04 18:01:41 +02:00
}
}
return res ;
}
2019-11-07 09:01:28 +01:00
#if ENABLE_THUMBNAIL_GENERATOR_DEBUG
2019-10-25 12:18:10 +02:00
void GUI_App :: gcode_thumbnails_debug ()
{
const std :: string BEGIN_MASK = "; thumbnail begin" ;
const std :: string END_MASK = "; thumbnail end" ;
std :: string gcode_line ;
bool reading_image = false ;
unsigned int width = 0 ;
unsigned int height = 0 ;
2020-10-06 15:11:08 +02:00
wxFileDialog dialog ( GetTopWindow (), _L ( "Select a gcode file:" ), "" , "" , "G-code files (*.gcode)|*.gcode ; * . GCODE ; ", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
2019-10-25 12:18:10 +02:00
if ( dialog . ShowModal () != wxID_OK )
return ;
std :: string in_filename = into_u8 ( dialog . GetPath ());
std :: string out_path = boost :: filesystem :: path ( in_filename ). remove_filename (). append ( L "thumbnail" ). string ();
2019-11-04 15:38:15 +01:00
boost :: nowide :: ifstream in_file ( in_filename . c_str ());
2019-10-25 12:18:10 +02:00
std :: vector < std :: string > rows ;
2019-11-04 14:00:26 +01:00
std :: string row ;
2019-11-04 15:38:15 +01:00
if ( in_file . good ())
2019-10-25 12:18:10 +02:00
{
2019-11-04 15:38:15 +01:00
while ( std :: getline ( in_file , gcode_line ))
2019-10-25 12:18:10 +02:00
{
2019-11-04 15:38:15 +01:00
if ( in_file . good ())
2019-10-25 12:18:10 +02:00
{
if ( boost :: starts_with ( gcode_line , BEGIN_MASK ))
{
reading_image = true ;
gcode_line = gcode_line . substr ( BEGIN_MASK . length () + 1 );
std :: string :: size_type x_pos = gcode_line . find ( 'x' );
std :: string width_str = gcode_line . substr ( 0 , x_pos );
width = ( unsigned int ) :: atoi ( width_str . c_str ());
std :: string height_str = gcode_line . substr ( x_pos + 1 );
height = ( unsigned int ) :: atoi ( height_str . c_str ());
2019-11-04 14:00:26 +01:00
row . clear ();
2019-10-25 12:18:10 +02:00
}
else if ( reading_image && boost :: starts_with ( gcode_line , END_MASK ))
{
2019-11-04 15:38:15 +01:00
std :: string out_filename = out_path + std :: to_string ( width ) + "x" + std :: to_string ( height ) + ".png" ;
boost :: nowide :: ofstream out_file ( out_filename . c_str (), std :: ios :: binary );
if ( out_file . good ())
{
2019-11-11 11:21:08 +01:00
std :: string decoded ;
decoded . resize ( boost :: beast :: detail :: base64 :: decoded_size ( row . size ()));
decoded . resize ( boost :: beast :: detail :: base64 :: decode (( void * ) & decoded [ 0 ], row . data (), row . size ()). first );
out_file . write ( decoded . c_str (), decoded . size ());
2019-11-04 15:38:15 +01:00
out_file . close ();
}
2019-10-25 12:18:10 +02:00
reading_image = false ;
width = 0 ;
height = 0 ;
rows . clear ();
}
else if ( reading_image )
2019-11-04 14:00:26 +01:00
row += gcode_line . substr ( 2 );
2019-10-25 12:18:10 +02:00
}
}
2019-11-04 15:38:15 +01:00
in_file . close ();
2019-10-25 12:18:10 +02:00
}
}
2019-11-07 09:01:28 +01:00
#endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG
2019-10-25 12:18:10 +02:00
2019-01-11 18:09:21 +01: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 ();
}
2019-04-29 16:55:41 +02:00
void GUI_App :: window_pos_restore ( wxTopLevelWindow * window , const std :: string & name , bool default_maximized )
2019-01-11 18:09:21 +01:00
{
if ( name . empty ()) { return ; }
const auto config_key = ( boost :: format ( "window_%1%" ) % name ). str ();
2019-04-29 16:55:41 +02:00
if ( ! app_config -> has ( config_key )) {
window -> Maximize ( default_maximized );
return ;
}
2019-01-11 18:09:21 +01:00
auto metrics = WindowMetrics :: deserialize ( app_config -> get ( config_key ));
2019-04-29 16:55:41 +02:00
if ( ! metrics ) {
window -> Maximize ( default_maximized );
return ;
}
2019-01-11 18:09:21 +01:00
2020-06-11 16:07:28 +02:00
const wxRect & rect = metrics -> get_rect ();
window -> SetPosition ( rect . GetPosition ());
window -> SetSize ( rect . GetSize ());
2019-01-11 18:09:21 +01:00
window -> Maximize ( metrics -> get_maximized ());
}
void GUI_App :: window_pos_sanitize ( wxTopLevelWindow * window )
{
2019-09-03 10:59:04 +02:00
/*unsigned*/ int display_idx = wxDisplay :: GetFromWindow ( window );
2019-01-11 18:09:21 +01:00
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 ());
}
}
2019-06-04 18:01:41 +02:00
bool GUI_App :: config_wizard_startup ()
{
2020-10-12 08:39:40 +02:00
if ( ! m_app_conf_exists || preset_bundle -> printers . size () <= 1 ) {
2019-06-04 18:01:41 +02:00
run_wizard ( ConfigWizard :: RR_DATA_EMPTY );
return true ;
} else if ( get_app_config () -> legacy_datadir ()) {
// Looks like user has legacy pre-vendorbundle data directory,
// explain what this is and run the wizard
MsgDataLegacy dlg ;
dlg . ShowModal ();
run_wizard ( ConfigWizard :: RR_DATA_LEGACY );
return true ;
}
return false ;
}
2020-02-04 15:24:35 +01:00
void GUI_App :: check_updates ( const bool verbose )
2020-10-12 08:39:40 +02:00
{
2020-02-04 15:24:35 +01:00
PresetUpdater :: UpdateResult updater_result ;
try {
2020-08-03 15:36:55 +02:00
updater_result = preset_updater -> config_update ( app_config -> orig_version (), verbose );
2020-02-04 15:24:35 +01:00
if ( updater_result == PresetUpdater :: R_INCOMPAT_EXIT ) {
mainframe -> Close ();
}
else if ( updater_result == PresetUpdater :: R_INCOMPAT_CONFIGURED ) {
2020-10-12 08:39:40 +02:00
m_app_conf_exists = true ;
2020-02-04 15:24:35 +01:00
}
2020-10-12 08:39:40 +02:00
else if ( verbose && updater_result == PresetUpdater :: R_NOOP ) {
2020-02-04 15:24:35 +01:00
MsgNoUpdates dlg ;
dlg . ShowModal ();
}
}
catch ( const std :: exception & ex ) {
2020-02-21 13:38:06 +01:00
show_error ( nullptr , ex . what ());
2020-02-04 15:24:35 +01:00
}
}
2020-10-12 08:39:40 +02:00
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???
2018-10-31 12:56:08 +01:00
// void GUI_App::notify(message) {
2018-09-20 08:40:22 +02: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 ?
// }
2019-05-03 15:50:05 +02:00
#ifdef __WXMSW__
2020-10-08 08:32:51 +02:00
static bool set_into_win_registry ( HKEY hkeyHive , const wchar_t * pszVar , const wchar_t * pszValue )
2019-05-03 15:50:05 +02:00
{
// see as reference: https://stackoverflow.com/questions/20245262/c-program-needs-an-file-association
2020-10-08 08:32:51 +02:00
wchar_t szValueCurrent [ 1000 ];
DWORD dwType ;
DWORD dwSize = sizeof ( szValueCurrent );
2019-05-03 15:50:05 +02:00
2020-10-08 08:32:51 +02:00
int iRC = :: RegGetValueW ( hkeyHive , pszVar , nullptr , RRF_RT_ANY , & dwType , szValueCurrent , & dwSize );
2019-05-03 15:50:05 +02:00
2020-10-08 08:32:51 +02:00
bool bDidntExist = iRC == ERROR_FILE_NOT_FOUND ;
2019-05-03 15:50:05 +02:00
2020-10-08 08:32:51 +02:00
if (( iRC != ERROR_SUCCESS ) && ! bDidntExist )
// an error occurred
return false ;
2019-05-03 15:50:05 +02:00
2020-10-08 08:32:51 +02:00
if ( ! bDidntExist ) {
if ( dwType != REG_SZ )
// invalid type
2019-05-17 11:35:35 +02:00
return false ;
2019-05-03 15:50:05 +02:00
2020-10-08 08:32:51 +02:00
if ( :: wcscmp ( szValueCurrent , pszValue ) == 0 )
// value already set
return false ;
}
2019-05-03 15:50:05 +02:00
2020-10-08 08:32:51 +02:00
DWORD dwDisposition ;
HKEY hkey ;
iRC = :: RegCreateKeyExW ( hkeyHive , pszVar , 0 , 0 , 0 , KEY_ALL_ACCESS , nullptr , & hkey , & dwDisposition );
bool ret = false ;
if ( iRC == ERROR_SUCCESS ) {
iRC = :: RegSetValueExW ( hkey , L "" , 0 , REG_SZ , ( BYTE * ) pszValue , ( :: wcslen ( pszValue ) + 1 ) * sizeof ( wchar_t ));
2019-05-03 15:50:05 +02:00
if ( iRC == ERROR_SUCCESS )
2020-10-08 08:32:51 +02:00
ret = true ;
}
2019-05-03 15:50:05 +02:00
2020-10-08 08:32:51 +02:00
RegCloseKey ( hkey );
return ret ;
}
2019-05-03 15:50:05 +02:00
2020-10-08 08:32:51 +02:00
void GUI_App :: associate_3mf_files ()
{
2019-05-03 15:50:05 +02:00
wchar_t app_path [ MAX_PATH ];
:: GetModuleFileNameW ( nullptr , app_path , sizeof ( app_path ));
std :: wstring prog_path = L " \" " + std :: wstring ( app_path ) + L " \" " ;
std :: wstring prog_id = L "Prusa.Slicer.1" ;
std :: wstring prog_desc = L "PrusaSlicer" ;
std :: wstring prog_command = prog_path + L " \" %1 \" " ;
std :: wstring reg_base = L "Software \\ Classes" ;
std :: wstring reg_extension = reg_base + L " \\ .3mf" ;
std :: wstring reg_prog_id = reg_base + L " \\ " + prog_id ;
std :: wstring reg_prog_id_command = reg_prog_id + L " \\ Shell \\ Open \\ Command" ;
2019-05-17 11:35:35 +02:00
bool is_new = false ;
2020-10-08 08:32:51 +02:00
is_new |= set_into_win_registry ( HKEY_CURRENT_USER , reg_extension . c_str (), prog_id . c_str ());
is_new |= set_into_win_registry ( HKEY_CURRENT_USER , reg_prog_id . c_str (), prog_desc . c_str ());
is_new |= set_into_win_registry ( HKEY_CURRENT_USER , reg_prog_id_command . c_str (), prog_command . c_str ());
if ( is_new )
// notify Windows only when any of the values gets changed
:: SHChangeNotify ( SHCNE_ASSOCCHANGED , SHCNF_IDLIST , nullptr , nullptr );
}
2020-11-26 10:09:34 +01:00
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
void GUI_App :: associate_stl_files ()
{
wchar_t app_path [ MAX_PATH ];
:: GetModuleFileNameW ( nullptr , app_path , sizeof ( app_path ));
std :: wstring prog_path = L " \" " + std :: wstring ( app_path ) + L " \" " ;
std :: wstring prog_id = L "Prusa.Slicer.1" ;
std :: wstring prog_desc = L "PrusaSlicer" ;
std :: wstring prog_command = prog_path + L " \" %1 \" " ;
std :: wstring reg_base = L "Software \\ Classes" ;
std :: wstring reg_extension = reg_base + L " \\ .stl" ;
std :: wstring reg_prog_id = reg_base + L " \\ " + prog_id ;
std :: wstring reg_prog_id_command = reg_prog_id + L " \\ Shell \\ Open \\ Command" ;
bool is_new = false ;
is_new |= set_into_win_registry ( HKEY_CURRENT_USER , reg_extension . c_str (), prog_id . c_str ());
is_new |= set_into_win_registry ( HKEY_CURRENT_USER , reg_prog_id . c_str (), prog_desc . c_str ());
is_new |= set_into_win_registry ( HKEY_CURRENT_USER , reg_prog_id_command . c_str (), prog_command . c_str ());
if ( is_new )
// notify Windows only when any of the values gets changed
:: SHChangeNotify ( SHCNE_ASSOCCHANGED , SHCNF_IDLIST , nullptr , nullptr );
}
#endif // ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
2020-10-08 08:32:51 +02:00
void GUI_App :: associate_gcode_files ()
{
wchar_t app_path [ MAX_PATH ];
:: GetModuleFileNameW ( nullptr , app_path , sizeof ( app_path ));
std :: wstring prog_path = L " \" " + std :: wstring ( app_path ) + L " \" " ;
std :: wstring prog_id = L "PrusaSlicer.GCodeViewer.1" ;
std :: wstring prog_desc = L "PrusaSlicerGCodeViewer" ;
std :: wstring prog_command = prog_path + L " \" %1 \" " ;
std :: wstring reg_base = L "Software \\ Classes" ;
std :: wstring reg_extension = reg_base + L " \\ .gcode" ;
std :: wstring reg_prog_id = reg_base + L " \\ " + prog_id ;
std :: wstring reg_prog_id_command = reg_prog_id + L " \\ Shell \\ Open \\ Command" ;
bool is_new = false ;
is_new |= set_into_win_registry ( HKEY_CURRENT_USER , reg_extension . c_str (), prog_id . c_str ());
is_new |= set_into_win_registry ( HKEY_CURRENT_USER , reg_prog_id . c_str (), prog_desc . c_str ());
is_new |= set_into_win_registry ( HKEY_CURRENT_USER , reg_prog_id_command . c_str (), prog_command . c_str ());
2019-05-03 15:50:05 +02:00
2019-05-17 11:35:35 +02:00
if ( is_new )
// notify Windows only when any of the values gets changed
:: SHChangeNotify ( SHCNE_ASSOCCHANGED , SHCNF_IDLIST , nullptr , nullptr );
2019-05-03 15:50:05 +02:00
}
#endif // __WXMSW__
2018-09-20 08:40:22 +02:00
} // GUI
2018-11-12 18:09:47 +01:00
} //Slic3r