#include "PluginHostBindings.hpp" #include #include #include #include #include #include #include namespace py = pybind11; namespace Slic3r { namespace { GUI::Plater* current_plater() { if (wxTheApp == nullptr) throw std::runtime_error("OrcaSlicer application is not initialized"); GUI::Plater* plater = GUI::wxGetApp().plater(); if (plater == nullptr) throw std::runtime_error("Plater is not available"); return plater; } PresetBundle* current_preset_bundle() { if (wxTheApp == nullptr) throw std::runtime_error("OrcaSlicer application is not initialized"); PresetBundle* preset_bundle = GUI::wxGetApp().preset_bundle; if (preset_bundle == nullptr) throw std::runtime_error("Preset bundle is not available"); return preset_bundle; } } // namespace // Access to the live GUI application: the Plater and the module-level // plater()/model()/preset_bundle() accessors. Everything here is owned by the // app and only reachable once the GUI is up (the accessors throw before that). void host_bindings::register_app(py::module_& host) { py::class_>(host, "Plater") .def("model", static_cast(&GUI::Plater::model), py::return_value_policy::reference_internal) .def("is_project_dirty", &GUI::Plater::is_project_dirty) .def("is_presets_dirty", &GUI::Plater::is_presets_dirty) .def("inside_snapshot_capture", &GUI::Plater::inside_snapshot_capture); host.def("plater", ¤t_plater, py::return_value_policy::reference); host.def("model", []() -> Model& { return current_plater()->model(); }, py::return_value_policy::reference); host.def("preset_bundle", ¤t_preset_bundle, py::return_value_policy::reference); // UI language of the running app ("en_US", "ru_RU", ...), so plugins can // localize their own dialogs. The app config file that stores this value // is deny-listed by the audit hook (it sits next to cloud secrets), so a // read-only accessor is the supported way to get just the language. host.def("app_language", []() -> std::string { if (wxTheApp == nullptr) throw std::runtime_error("OrcaSlicer application is not initialized"); return GUI::into_u8(GUI::wxGetApp().current_language_code_safe()); }); } } // namespace Slic3r