Macos: add the support of file association

Change-Id: Iacd3b35423dac6f63416628d28b0502ba175f7b4
This commit is contained in:
lane.wei 2022-08-02 12:12:45 +08:00 committed by Lane.Wei
parent 55d59c7248
commit b1e8fadb09
5 changed files with 159 additions and 34 deletions

View File

@ -26,6 +26,94 @@
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string> <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>stl</string>
<string>STL</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>stl.icns</string>
<key>CFBundleTypeName</key>
<string>STL</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LISsAppleDefaultForType</key>
<true/>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>obj</string>
<string>OBJ</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>BambuStudio.icns</string>
<key>CFBundleTypeName</key>
<string>STL</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LISsAppleDefaultForType</key>
<true/>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>amf</string>
<string>AMF</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>BambuStudio.icns</string>
<key>CFBundleTypeName</key>
<string>AMF</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LISsAppleDefaultForType</key>
<true/>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>3mf</string>
<string>3MF</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>BambuStudio.icns</string>
<key>CFBundleTypeName</key>
<string>3MF</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LISsAppleDefaultForType</key>
<true/>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>gcode</string>
<string>GCODE</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>gcode.icns</string>
<key>CFBundleTypeName</key>
<string>GCODE</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LISsAppleDefaultForType</key>
<true/>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
</array>
<key>CSResourcesFileMapped</key> <key>CSResourcesFileMapped</key>
<true/> <true/>
<key>NSRequiresAquaSystemAppearance</key> <key>NSRequiresAquaSystemAppearance</key>

View File

@ -189,7 +189,25 @@ int CLI::run(int argc, char **argv)
params.argv = argv; params.argv = argv;
params.load_configs = load_configs; params.load_configs = load_configs;
params.extra_config = std::move(m_extra_config); params.extra_config = std::move(m_extra_config);
params.input_files = std::move(m_input_files);
std::vector<std::string> gcode_files;
std::vector<std::string> non_gcode_files;
for (const auto& filename : m_input_files) {
if (is_gcode_file(filename))
gcode_files.emplace_back(filename);
else {
non_gcode_files.emplace_back(filename);
}
}
if (non_gcode_files.empty() && !gcode_files.empty()) {
params.input_gcode = true;
params.input_files = std::move(gcode_files);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", gcode only, gcode_files size = "<<params.input_files.size();
}
else {
params.input_files = std::move(m_input_files);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", normal mode, input_files size = "<<params.input_files.size();
}
//BBS: remove GCodeViewer as seperate APP logic //BBS: remove GCodeViewer as seperate APP logic
//params.start_as_gcodeviewer = start_as_gcodeviewer; //params.start_as_gcodeviewer = start_as_gcodeviewer;

View File

@ -930,23 +930,32 @@ void GUI_App::post_init()
bool switch_to_3d = false; bool switch_to_3d = false;
if (!this->init_params->input_files.empty()) { if (!this->init_params->input_files.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", init with input files, size %1%, input_gcode %2%")
%this->init_params->input_files.size() %this->init_params->input_gcode;
switch_to_3d = true; switch_to_3d = true;
mainframe->select_tab(size_t(MainFrame::tp3DEditor)); if (this->init_params->input_gcode) {
plater_->select_view_3D("3D"); mainframe->select_tab(size_t(MainFrame::tp3DEditor));
const std::vector<size_t> res = this->plater()->load_files(this->init_params->input_files); plater_->select_view_3D("3D");
if (!res.empty()) { this->plater()->load_gcode(from_u8(this->init_params->input_files.front()));
if (this->init_params->input_files.size() == 1) { }
// Update application titlebar when opening a project file else {
const std::string& filename = this->init_params->input_files.front(); mainframe->select_tab(size_t(MainFrame::tp3DEditor));
//BBS: remove amf logic as project plater_->select_view_3D("3D");
if (boost::algorithm::iends_with(filename, ".3mf")) const std::vector<size_t> res = this->plater()->load_files(this->init_params->input_files);
this->plater()->set_project_filename(from_u8(filename)); if (!res.empty()) {
if (this->init_params->input_files.size() == 1) {
// Update application titlebar when opening a project file
const std::string& filename = this->init_params->input_files.front();
//BBS: remove amf logic as project
if (boost::algorithm::iends_with(filename, ".3mf"))
this->plater()->set_project_filename(from_u8(filename));
}
} }
} }
} }
#if BBL_HAS_FIRST_PAGE #if BBL_HAS_FIRST_PAGE
if (!switch_to_3d) { if (!switch_to_3d) {
BOOST_LOG_TRIVIAL(info) << "begin load_gl_resources"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", begin load_gl_resources";
mainframe->Freeze(); mainframe->Freeze();
plater_->canvas3D()->enable_render(false); plater_->canvas3D()->enable_render(false);
mainframe->select_tab(size_t(MainFrame::tp3DEditor)); mainframe->select_tab(size_t(MainFrame::tp3DEditor));
@ -954,26 +963,26 @@ void GUI_App::post_init()
//BBS init the opengl resource here //BBS init the opengl resource here
Size canvas_size = plater_->canvas3D()->get_canvas_size(); Size canvas_size = plater_->canvas3D()->get_canvas_size();
wxGetApp().imgui()->set_display_size(static_cast<float>(canvas_size.get_width()), static_cast<float>(canvas_size.get_height())); wxGetApp().imgui()->set_display_size(static_cast<float>(canvas_size.get_width()), static_cast<float>(canvas_size.get_height()));
BOOST_LOG_TRIVIAL(info) << "start to init opengl"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", start to init opengl";
wxGetApp().init_opengl(); wxGetApp().init_opengl();
BOOST_LOG_TRIVIAL(info) << "finished init opengl"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished init opengl";
plater_->canvas3D()->init(); plater_->canvas3D()->init();
BOOST_LOG_TRIVIAL(info) << "finished init canvas3D"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished init canvas3D";
wxGetApp().imgui()->new_frame(); wxGetApp().imgui()->new_frame();
BOOST_LOG_TRIVIAL(info) << "finished init imgui frame"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished init imgui frame";
plater_->canvas3D()->enable_render(true); plater_->canvas3D()->enable_render(true);
BOOST_LOG_TRIVIAL(info) << "start to render a first frame for test"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", start to render a first frame for test";
plater_->canvas3D()->render(false); plater_->canvas3D()->render(false);
BOOST_LOG_TRIVIAL(info) << "finished rendering a first frame for test"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished rendering a first frame for test";
if (is_editor()) if (is_editor())
mainframe->select_tab(size_t(0)); mainframe->select_tab(size_t(0));
mainframe->Thaw(); mainframe->Thaw();
plater_->trigger_restore_project(1); plater_->trigger_restore_project(1);
BOOST_LOG_TRIVIAL(info) << "end load_gl_resources"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", end load_gl_resources";
} }
#endif #endif
@ -2121,16 +2130,17 @@ bool GUI_App::on_init_inner()
// BBS // BBS
//this->obj_manipul()->update_if_dirty(); //this->obj_manipul()->update_if_dirty();
static bool update_gui_after_init = true; //use m_post_initialized instead
//static bool update_gui_after_init = true;
// An ugly solution to GH #5537 in which GUI_App::init_opengl (normally called from events wxEVT_PAINT // An ugly solution to GH #5537 in which GUI_App::init_opengl (normally called from events wxEVT_PAINT
// and wxEVT_SET_FOCUS before GUI_App::post_init is called) wasn't called before GUI_App::post_init and OpenGL wasn't initialized. // and wxEVT_SET_FOCUS before GUI_App::post_init is called) wasn't called before GUI_App::post_init and OpenGL wasn't initialized.
#ifdef __linux__ #ifdef __linux__
if (update_gui_after_init && m_opengl_initialized) { if (!m_post_initialized && m_opengl_initialized) {
#else #else
if (update_gui_after_init) { if (!m_post_initialized) {
#endif #endif
update_gui_after_init = false; m_post_initialized = true;
#ifdef WIN32 #ifdef WIN32
this->mainframe->register_win32_callbacks(); this->mainframe->register_win32_callbacks();
#endif #endif
@ -4321,6 +4331,7 @@ void GUI_App::MacOpenFiles(const wxArrayString &fileNames)
std::vector<std::string> files; std::vector<std::string> files;
std::vector<wxString> gcode_files; std::vector<wxString> gcode_files;
std::vector<wxString> non_gcode_files; std::vector<wxString> non_gcode_files;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", open files, size " << fileNames.size();
for (const auto& filename : fileNames) { for (const auto& filename : fileNames) {
if (is_gcode_file(into_u8(filename))) if (is_gcode_file(into_u8(filename)))
gcode_files.emplace_back(filename); gcode_files.emplace_back(filename);
@ -4341,21 +4352,27 @@ void GUI_App::MacOpenFiles(const wxArrayString &fileNames)
} else*/ } else*/
{ {
if (! files.empty()) { if (! files.empty()) {
wxArrayString input_files; if (m_post_initialized) {
for (size_t i = 0; i < non_gcode_files.size(); ++i) { wxArrayString input_files;
input_files.push_back(non_gcode_files[i]); 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);
} }
this->plater()->load_files(input_files); else {
if (gcode_files.size() > 0) { for (size_t i = 0; i < files.size(); ++i) {
show_info(this->plater(), _L("G-code files can not be loaded with models together!"), _L("G-code loading")); this->init_params->input_files.emplace_back(files[i]);
}
} }
} }
else { else {
wxArrayString input_files; if (m_post_initialized) {
for (size_t i = 0; i < gcode_files.size(); ++i) { this->plater()->load_gcode(gcode_files.front());
input_files.push_back(gcode_files[i]); }
else {
this->init_params->input_gcode = true;
this->init_params->input_files = { into_u8(gcode_files.front()) };
} }
this->plater()->load_files(input_files);
} }
/*for (const wxString &filename : gcode_files) /*for (const wxString &filename : gcode_files)
start_new_gcodeviewer(&filename);*/ start_new_gcodeviewer(&filename);*/

View File

@ -194,7 +194,7 @@ public:
class GUI_App : public wxApp class GUI_App : public wxApp
{ {
public: public:
//BBS: remove GCodeViewer as seperate APP logic //BBS: remove GCodeViewer as seperate APP logic
enum class EAppMode : unsigned char enum class EAppMode : unsigned char
{ {
@ -204,6 +204,7 @@ public:
private: private:
bool m_initialized { false }; bool m_initialized { false };
bool m_post_initialized { false };
bool m_app_conf_exists{ false }; bool m_app_conf_exists{ false };
EAppMode m_app_mode{ EAppMode::Editor }; EAppMode m_app_mode{ EAppMode::Editor };
bool m_is_recreating_gui{ false }; bool m_is_recreating_gui{ false };

View File

@ -22,6 +22,7 @@ struct GUI_InitParams
//BBS: remove start_as_gcodeviewer logic //BBS: remove start_as_gcodeviewer logic
//bool start_as_gcodeviewer; //bool start_as_gcodeviewer;
bool input_gcode { false };
}; };
int GUI_Run(GUI_InitParams &params); int GUI_Run(GUI_InitParams &params);