mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-08 08:11:14 +00:00
* Ignore Clipper, libpng, mcut and Boost.Polygon Internals in clang-tidy Each only works through a wrapper or umbrella header: libslic3r/clipper.hpp or clipper_z.hpp configure Clipper before including it, png.h pulls in libpng's config headers, and Boost.Polygon's headers only compile through polygon.hpp or voronoi.hpp. * Ignore minilzo's Config Headers in clang-tidy lzoconf.h and lzodefs.h are internal to minilzo.h, which is what the code includes. * Add Missing Includes Across the Remaining Sources and Tests Covers src/slic3r/Utils, src/slic3r/plugin, src/slic3r/Config, src/libvgcode, src/dev-utils, src/OrcaSlicer.cpp and tests/, the directories left after src/slic3r/GUI and src/libslic3r. Generated with clang-tidy misc-include-cleaner. libvgcode's own headers are included by relative path as in the rest of that library, and Catch2 and pybind11 with angle brackets as elsewhere in the repo. * Make the GUI and Test Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Headers that only compile on one platform, or that nothing built includes, are left alone. * Keep Windows and nanosvg Setup Ahead of the Added Includes OrcaSlicer.cpp and several tests set _WIN32_WINNT, WIN32_LEAN_AND_MEAN or NOMINMAX before including Windows.h, and the profile validator defines NANOSVG_IMPLEMENTATION before any libslic3r header. The added includes had landed above those blocks, which broke the Windows build. * Add the GUI Includes the First Pass Missed Covers headers that only became editable once they compiled on their own, and wx symbols whose suggested header changed as the clang-tidy ignore list grew after the src/slic3r/GUI pass. * Keep the Added Test Includes Below the NOMINMAX Guard test_marchingsquares.cpp and test_texture_displacement.cpp had includes inside #ifndef NOMINMAX, which the tests inherit as defined on Windows from libslic3r, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory, as in #16068.
168 lines
6.0 KiB
C++
168 lines
6.0 KiB
C++
#include "Process.hpp"
|
|
|
|
#include <cstdlib>
|
|
#include <libslic3r/AppConfig.hpp>
|
|
|
|
#include "../GUI/GUI.hpp"
|
|
// for file_wildcards()
|
|
#include "../GUI/GUI_App.hpp"
|
|
// localization
|
|
#include "../GUI/I18N.hpp"
|
|
|
|
#include <iostream>
|
|
#include <fstream>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/log/trivial.hpp>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <wx/utils.h>
|
|
#include <wx/filedlg.h>
|
|
#include <wx/string.h>
|
|
|
|
// For starting another OrcaSlicer instance on OSX.
|
|
// Fails to compile on Windows on the build server.
|
|
#ifdef __APPLE__
|
|
#include <boost/process/spawn.hpp>
|
|
#include <boost/process/args.hpp>
|
|
#endif
|
|
|
|
#include <wx/filename.h>
|
|
#include <wx/stdpaths.h>
|
|
|
|
namespace Slic3r {
|
|
namespace GUI {
|
|
|
|
enum class NewSlicerInstanceType {
|
|
Slicer,
|
|
GCodeViewer
|
|
};
|
|
|
|
// Start a new Slicer process instance either in a Slicer mode or in a G-code mode.
|
|
// Optionally load a 3MF, STL or a G-code on start.
|
|
static void start_new_slicer_or_gcodeviewer(const NewSlicerInstanceType instance_type, const std::vector<wxString> paths_to_open, bool single_instance)
|
|
{
|
|
#ifdef _WIN32
|
|
wxString path;
|
|
wxFileName::SplitPath(wxStandardPaths::Get().GetExecutablePath(), &path, nullptr, nullptr, wxPATH_NATIVE);
|
|
path += "\\";
|
|
path += (instance_type == NewSlicerInstanceType::Slicer) ? "orca-slicer.exe" : "bambu-gcodeviewer.exe";
|
|
std::vector<const wchar_t*> args;
|
|
args.reserve(4);
|
|
args.emplace_back(path.wc_str());
|
|
if (!paths_to_open.empty()) {
|
|
for (const auto& file : paths_to_open)
|
|
args.emplace_back(file);
|
|
}
|
|
if (instance_type == NewSlicerInstanceType::Slicer && single_instance)
|
|
args.emplace_back(L"--single-instance");
|
|
args.emplace_back(nullptr);
|
|
BOOST_LOG_TRIVIAL(info) << "Trying to spawn a new slicer \"" << into_u8(path) << "\"";
|
|
// Don't call with wxEXEC_HIDE_CONSOLE, OrcaSlicer in GUI mode would just show the splash screen. It would not open the main window though, it would
|
|
// just hang in the background.
|
|
if (wxExecute(const_cast<wchar_t**>(args.data()), wxEXEC_ASYNC) <= 0)
|
|
BOOST_LOG_TRIVIAL(error) << "Failed to spawn a new slicer \"" << into_u8(path);
|
|
#else
|
|
// Own executable path.
|
|
boost::filesystem::path bin_path = into_path(wxStandardPaths::Get().GetExecutablePath());
|
|
#if defined(__APPLE__)
|
|
{
|
|
auto bundle_path = bin_path.parent_path().parent_path().parent_path();
|
|
//bin_path = bin_path.parent_path() / "OrcaSlicer";
|
|
bin_path = "/usr/bin/open";
|
|
// On Apple the wxExecute fails, thus we use boost::process instead.
|
|
BOOST_LOG_TRIVIAL(info) << "Trying to spawn a new slicer \"" << bin_path.string() << "\"";
|
|
try {
|
|
std::vector<std::string> args = { "-n", "-a", bundle_path.string()};
|
|
if (!paths_to_open.empty()) {
|
|
for (const auto& file : paths_to_open)
|
|
args.emplace_back(into_u8(file));
|
|
}
|
|
args.emplace_back("--args");
|
|
if (instance_type == NewSlicerInstanceType::GCodeViewer)
|
|
args.emplace_back("--gcodeviewer");
|
|
if (instance_type == NewSlicerInstanceType::Slicer && single_instance)
|
|
args.emplace_back("--single-instance");
|
|
boost::process::spawn(bin_path, args);
|
|
}
|
|
catch (const std::exception& ex) {
|
|
BOOST_LOG_TRIVIAL(error) << "Failed to spawn a new slicer \"" << bin_path.string() << "\": " << ex.what();
|
|
}
|
|
}
|
|
#else // Linux or Unix
|
|
{
|
|
std::vector<const char*> args;
|
|
args.reserve(3);
|
|
#ifdef __linux__
|
|
static const char* gcodeviewer_param = "--gcodeviewer";
|
|
{
|
|
// If executed by an AppImage, start the AppImage, not the main process.
|
|
// see https://docs.appimage.org/packaging-guide/environment-variables.html#id2
|
|
const char* appimage_binary = std::getenv("APPIMAGE");
|
|
if (appimage_binary) {
|
|
args.emplace_back(appimage_binary);
|
|
if (instance_type == NewSlicerInstanceType::GCodeViewer)
|
|
args.emplace_back(gcodeviewer_param);
|
|
}
|
|
}
|
|
#endif // __linux__
|
|
std::string my_path;
|
|
if (args.empty()) {
|
|
// Binary path was not set to the AppImage in the Linux specific block above, call the application directly.
|
|
my_path = (bin_path.parent_path() / ((instance_type == NewSlicerInstanceType::Slicer) ? "orca-slicer" : "bambu-gcodeviewer")).string();
|
|
args.emplace_back(my_path.c_str());
|
|
}
|
|
std::string to_open;
|
|
if (!paths_to_open.empty()) {
|
|
for (const auto& file : paths_to_open) {
|
|
to_open = into_u8(file);
|
|
args.emplace_back(to_open.c_str());
|
|
}
|
|
}
|
|
if (instance_type == NewSlicerInstanceType::Slicer && single_instance)
|
|
args.emplace_back("--single-instance");
|
|
args.emplace_back(nullptr);
|
|
BOOST_LOG_TRIVIAL(info) << "Trying to spawn a new slicer \"" << args[0] << "\"";
|
|
if (wxExecute(const_cast<char**>(args.data()), wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER) <= 0)
|
|
BOOST_LOG_TRIVIAL(error) << "Failed to spawn a new slicer \"" << args[0];
|
|
}
|
|
#endif // Linux or Unix
|
|
#endif // Win32
|
|
}
|
|
static void start_new_slicer_or_gcodeviewer(const NewSlicerInstanceType instance_type, const wxString* path_to_open, bool single_instance)
|
|
{
|
|
std::vector<wxString> paths;
|
|
if (path_to_open != nullptr)
|
|
paths.emplace_back(path_to_open->wc_str());
|
|
start_new_slicer_or_gcodeviewer(instance_type, paths, single_instance);
|
|
}
|
|
|
|
void start_new_slicer(const wxString *path_to_open, bool single_instance)
|
|
{
|
|
start_new_slicer_or_gcodeviewer(NewSlicerInstanceType::Slicer, path_to_open, single_instance);
|
|
}
|
|
void start_new_slicer(const std::vector<wxString>& files, bool single_instance)
|
|
{
|
|
start_new_slicer_or_gcodeviewer(NewSlicerInstanceType::Slicer, files, single_instance);
|
|
}
|
|
|
|
void start_new_gcodeviewer(const wxString *path_to_open)
|
|
{
|
|
start_new_slicer_or_gcodeviewer(NewSlicerInstanceType::GCodeViewer, path_to_open, false);
|
|
}
|
|
|
|
void start_new_gcodeviewer_open_file(wxWindow *parent)
|
|
{
|
|
wxFileDialog dialog(parent ? parent : wxGetApp().GetTopWindow(),
|
|
_L("Open G-code file:"),
|
|
from_u8(wxGetApp().app_config->get_last_dir()), wxString(),
|
|
file_wildcards(FT_GCODE), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
|
if (dialog.ShowModal() == wxID_OK) {
|
|
wxString path = dialog.GetPath();
|
|
start_new_gcodeviewer(&path);
|
|
}
|
|
}
|
|
|
|
} // namespace GUI
|
|
} // namespace Slic3r
|