OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp} Namespace Reference

Classes

struct  PluginScriptAction
struct  PluginPageAction
struct  SettingText
struct  SettingAction
struct  PlateAction
struct  RecentProjectAction

Functions

nlohmann::json parse_config_json (const std::string &value, nlohmann::json fallback)
nlohmann::json read_section (const char *key, nlohmann::json fallback)
void write_section (const char *key, const nlohmann::json &j)
std::vector< std::string > read_string_array (const char *key)
double frecency_score (int count, long long last, long long now)
std::string find_loaded_source_name (PluginManager &manager, const std::string &plugin_key)
AppActionRunResult script_outcome_to_action_result (const ScriptCompletion &completion)
void notify_script_outcome (const ScriptCompletion &completion)
std::unique_ptr< AppAction > make_action (const std::string &plugin_key, const std::string &capability, const std::string &source_name)
std::unique_ptr< AppAction > make_page_action (const std::string &plugin_key, const std::string &capability, const std::string &source_name)
const char * setting_type_context (Preset::Type type)
SettingText setting_text (const std::wstring &def_label, const std::string &display_label, const wxString &row_label, bool row_multi, const std::string &type_name, const std::wstring &category, const std::wstring &group)
const char * mode_key (ConfigOptionMode mode)
void seed_from (const nlohmann::json &stats, const std::vector< std::string > &favs, const std::string &id, AppAction &a)
void drop_stale (std::unordered_map< std::string, std::shared_ptr< AppAction > > &actions, const char *prefix, const std::unordered_set< std::string > &seen)

Variables

constexpr const char * kConfigSection = "speed_dial"
constexpr const char * kSettingPrefix = "orca_setting"
constexpr const char * kPlateGotoPrefix = "orca_plate_goto"
constexpr const char * kRecentProjectPrefix = "orca_recent_project"

Class Documentation

◆ Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::SettingText

struct Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::SettingText
Collaboration diagram for Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::SettingText:
Class Members
string full_label
string source
string title

Function Documentation

◆ drop_stale()

void Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::drop_stale ( std::unordered_map< std::string, std::shared_ptr< AppAction > > & actions,
const char * prefix,
const std::unordered_set< std::string > & seen )
382{
383 for (auto it = actions.begin(); it != actions.end();) {
384 if (it->first.rfind(prefix, 0) == 0 && !seen.count(it->first))
385 it = actions.erase(it);
386 else
387 ++it;
388 }
389}

References drop_stale().

Referenced by drop_stale().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_loaded_source_name()

std::string Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::find_loaded_source_name ( PluginManager & manager,
const std::string & plugin_key )
98{
99 PluginDescriptor descriptor;
100 if (manager.try_get_plugin_descriptor(plugin_key, descriptor) && !descriptor.name.empty())
101 return descriptor.name;
102 return plugin_key;
103}
bool try_get_plugin_descriptor(const std::string &plugin_key, PluginDescriptor &out) const
Definition PluginManager.cpp:502
Definition PluginDescriptor.hpp:53
std::string name
Definition PluginDescriptor.hpp:55

References find_loaded_source_name(), Slic3r::PluginDescriptor::name, and Slic3r::PluginManager::try_get_plugin_descriptor().

Referenced by find_loaded_source_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ frecency_score()

double Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::frecency_score ( int count,
long long last,
long long now )
87{
88 if (count <= 0)
89 return 0.0;
90 constexpr double HALF_LIFE_DAYS = 30.0;
91 double age = std::max(0.0, double(now - last) / 86400.0);
92 return count * std::pow(2.0, -age / HALF_LIFE_DAYS);
93}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246

References count, and frecency_score().

Referenced by frecency_score().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_action()

std::unique_ptr< AppAction > Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::make_action ( const std::string & plugin_key,
const std::string & capability,
const std::string & source_name )
205{
207 if (!manager.is_plugin_loaded(plugin_key))
208 return nullptr;
209 // only_enabled defaults true, so a disabled capability resolves to nullptr here.
210 if (!manager.get_plugin_capability({PluginCapabilityType::Script, capability, plugin_key}))
211 return nullptr;
212 return std::make_unique<PluginScriptAction>(plugin_key, capability, source_name);
213}
Definition PluginManager.hpp:116
bool is_plugin_loaded(const std::string &plugin_key) const
Definition PluginManager.cpp:674
static PluginManager & instance()
Definition PluginManager.cpp:74
std::shared_ptr< PluginCapabilityInterface > get_plugin_capability(const PluginCapabilityId &id, bool only_enabled=true) const
Definition PluginManager.cpp:616

References Slic3r::PluginManager::get_plugin_capability(), Slic3r::PluginManager::instance(), Slic3r::PluginManager::is_plugin_loaded(), and make_action().

Referenced by make_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_page_action()

std::unique_ptr< AppAction > Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::make_page_action ( const std::string & plugin_key,
const std::string & capability,
const std::string & source_name )
255{
257 if (!manager.is_plugin_loaded(plugin_key))
258 return nullptr;
259 // only_enabled defaults true, so a disabled capability resolves to nullptr here.
260 if (!manager.get_plugin_capability({PluginCapabilityType::Pages, capability, plugin_key}))
261 return nullptr;
262 return std::make_unique<PluginPageAction>(plugin_key, capability, source_name);
263}

References Slic3r::PluginManager::get_plugin_capability(), Slic3r::PluginManager::instance(), Slic3r::PluginManager::is_plugin_loaded(), and make_page_action().

Referenced by make_page_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mode_key()

const char * Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::mode_key ( ConfigOptionMode mode)
320{
321 switch (mode) {
322 case comAdvanced: return "advanced";
323 case comExpert: return "expert";
324 case comDevelop: return "develop";
325 default: return "simple";
326 }
327}
@ comDevelop
Definition Config.hpp:225
@ comAdvanced
Definition Config.hpp:223
@ comExpert
Definition Config.hpp:224

References Slic3r::comAdvanced, Slic3r::comDevelop, Slic3r::comExpert, and mode_key().

Referenced by mode_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_script_outcome()

void Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::notify_script_outcome ( const ScriptCompletion & completion)
127{
128 if (completion.cancelled)
129 return;
130 if (wxTheApp == nullptr || wxGetApp().is_closing())
131 return;
132
133 Plater* plater = wxGetApp().plater();
134 if (plater == nullptr || wxGetApp().imgui() == nullptr || !wxGetApp().imgui()->display_initialized())
135 return;
136
137 const AppActionRunResult action_result = script_outcome_to_action_result(completion);
138 const auto level = action_result.level == AppActionRunResult::Level::Error
141 plater->get_notification_manager()->push_notification(NotificationType::CustomNotification, level, into_u8(action_result.message));
142}
@ RegularNotificationLevel
Definition NotificationManager.hpp:216
@ ErrorNotificationLevel
Definition NotificationManager.hpp:228
Definition Plater.hpp:337
AppActionRunResult script_outcome_to_action_result(const ScriptCompletion &completion)
Definition ActionRegistry.cpp:107
static Plater * plater()
Definition GUI_Factories.cpp:400
@ CustomNotification
Definition NotificationManager.hpp:66
std::string into_u8(const wxString &str)
Definition GUI.cpp:549
bool cancelled
Definition PluginManager.hpp:112
Definition ActionRegistry.hpp:30
Level level
Definition ActionRegistry.hpp:33
wxString message
Definition ActionRegistry.hpp:34
@ Error
Definition ActionRegistry.hpp:31

References Slic3r::ScriptCompletion::cancelled, Slic3r::GUI::CustomNotification, Slic3r::GUI::AppActionRunResult::Error, Slic3r::GUI::NotificationManager::ErrorNotificationLevel, Slic3r::GUI::into_u8(), Slic3r::GUI::AppActionRunResult::level, Slic3r::GUI::AppActionRunResult::message, notify_script_outcome(), Slic3r::GUI::plater(), Slic3r::GUI::NotificationManager::RegularNotificationLevel, and script_outcome_to_action_result().

Referenced by notify_script_outcome(), and Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::PluginScriptAction::run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_config_json()

nlohmann::json Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::parse_config_json ( const std::string & value,
nlohmann::json fallback )
65{
66 nlohmann::json parsed = nlohmann::json::parse(value, nullptr, false);
67 return parsed.is_discarded() ? std::move(fallback) : parsed;
68}

References parse_config_json().

Referenced by parse_config_json(), and read_section().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_section()

nlohmann::json Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::read_section ( const char * key,
nlohmann::json fallback )
71{ return parse_config_json(wxGetApp().app_config->get(kConfigSection, key), std::move(fallback)); }
constexpr const char * kConfigSection
Definition ActionRegistry.cpp:62
nlohmann::json parse_config_json(const std::string &value, nlohmann::json fallback)
Definition ActionRegistry.cpp:64

References kConfigSection, parse_config_json(), and read_section().

Referenced by read_section(), and read_string_array().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_string_array()

std::vector< std::string > Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::read_string_array ( const char * key)
76{
77 auto j = read_section(key, nlohmann::json::array());
78 std::vector<std::string> v;
79 for (auto& e : j)
80 if (e.is_string())
81 v.push_back(e.get<std::string>());
82 return v;
83}
nlohmann::json read_section(const char *key, nlohmann::json fallback)
Definition ActionRegistry.cpp:70

References read_section(), and read_string_array().

Referenced by read_string_array().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ script_outcome_to_action_result()

AppActionRunResult Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::script_outcome_to_action_result ( const ScriptCompletion & completion)
108{
109 // Cancelled by PluginManager (unload/shutdown): expected termination, nothing to show.
110 if (completion.cancelled)
111 return {};
112
113 if (!completion.error.empty())
114 return {AppActionRunResult::Level::Error, from_u8(completion.error)};
115
116 const ExecutionResult& result = completion.result;
117 const bool skipped = result.status == PluginResult::Skipped;
118 const wxString fallback = skipped ? _L("Script plugin skipped.") : _L("Script plugin finished.");
120 result.message.empty() ? fallback : from_u8(result.message)};
121}
#define _L(s)
Definition OBJ.cpp:34
wxString from_u8(const std::string &str)
Definition GUI.cpp:544
ExecutionResult result
Definition PluginManager.hpp:110
@ Skipped
Definition PythonPluginInterface.hpp:105
std::string error
Definition PluginManager.hpp:111
Definition PythonPluginInterface.hpp:108
std::string message
Definition PythonPluginInterface.hpp:110
PluginResult status
Definition PythonPluginInterface.hpp:109
@ Info
Definition ActionRegistry.hpp:31
@ Success
Definition ActionRegistry.hpp:31

References _L, Slic3r::ScriptCompletion::cancelled, Slic3r::GUI::AppActionRunResult::Error, Slic3r::ScriptCompletion::error, Slic3r::GUI::from_u8(), Slic3r::GUI::AppActionRunResult::Info, Slic3r::ExecutionResult::message, Slic3r::ScriptCompletion::result, script_outcome_to_action_result(), Slic3r::Skipped, Slic3r::ExecutionResult::status, and Slic3r::GUI::AppActionRunResult::Success.

Referenced by notify_script_outcome(), Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::PluginScriptAction::run(), and script_outcome_to_action_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ seed_from()

void Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::seed_from ( const nlohmann::json & stats,
const std::vector< std::string > & favs,
const std::string & id,
AppAction & a )
371{
372 a.favourite = std::find(favs.begin(), favs.end(), id) != favs.end();
373 if (auto it = stats.find(id); it != stats.end() && it->is_object()) {
374 a.count = it->value("count", 0);
375 a.last = it->value("last", 0LL);
376 }
377}
long long last
Definition ActionRegistry.hpp:71
int count
Definition ActionRegistry.hpp:70
bool favourite
Definition ActionRegistry.hpp:69

References Slic3r::GUI::AppAction::count, Slic3r::GUI::AppAction::favourite, Slic3r::GUI::AppAction::last, and seed_from().

Referenced by seed_from().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setting_text()

SettingText Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::setting_text ( const std::wstring & def_label,
const std::string & display_label,
const wxString & row_label,
bool row_multi,
const std::string & type_name,
const std::wstring & category,
const std::wstring & group )
300{
301 SettingText text;
302 const std::string def = boost::nowide::narrow(def_label);
303 text.title = into_u8(Search::resolve_setting_title(from_u8(display_label), row_label, row_multi));
304 if (text.title.empty())
305 text.title = def;
306 if (text.title != def)
307 text.full_label = def;
308
309 std::wstring path = boost::nowide::widen(type_name);
310 if (!category.empty())
311 path += L" : " + category;
312 if (!group.empty())
313 path += L" : " + group;
314 text.source = boost::nowide::narrow(path);
315 return text;
316}
#define L(s)
Definition ExtrusionEntity.cpp:25
std::string full_label
Definition ActionRegistry.cpp:291
std::string title
Definition ActionRegistry.cpp:290
std::string source
Definition ActionRegistry.cpp:293
wxString resolve_setting_title(const wxString &precomposed, const wxString &live_label, bool live_multi)
Definition SettingsIndex.hpp:50

References Slic3r::GUI::from_u8(), Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::SettingText::full_label, Slic3r::GUI::into_u8(), L, Slic3r::Search::resolve_setting_title(), setting_text(), Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::SettingText::source, and Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::SettingText::title.

Referenced by setting_text().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setting_type_context()

const char * Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::setting_type_context ( Preset::Type type)
275{
276 switch (type) {
278 case Preset::TYPE_SLA_MATERIAL: return L("Filament");
279 case Preset::TYPE_PRINTER: return L("Printer");
282 default: return L("Process");
283 }
284}
@ TYPE_SLA_PRINT
Definition Preset.hpp:247
@ TYPE_PRINTER
Definition Preset.hpp:250
@ TYPE_PRINT
Definition Preset.hpp:246
@ TYPE_SLA_MATERIAL
Definition Preset.hpp:249
@ TYPE_FILAMENT
Definition Preset.hpp:248

References L, setting_type_context(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, Slic3r::Preset::TYPE_PRINTER, Slic3r::Preset::TYPE_SLA_MATERIAL, and Slic3r::Preset::TYPE_SLA_PRINT.

Referenced by setting_type_context().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_section()

void Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::write_section ( const char * key,
const nlohmann::json & j )
73{ wxGetApp().app_config->set(kConfigSection, key, j.dump()); }

References kConfigSection, and write_section().

Referenced by write_section().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kConfigSection

const char* Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::kConfigSection = "speed_dial"
constexpr

Referenced by read_section(), and write_section().

◆ kPlateGotoPrefix

const char* Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::kPlateGotoPrefix = "orca_plate_goto"
constexpr

◆ kRecentProjectPrefix

const char* Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::kRecentProjectPrefix = "orca_recent_project"
constexpr

◆ kSettingPrefix

const char* Slic3r::GUI::anonymous_namespace{ActionRegistry.cpp}::kSettingPrefix = "orca_setting"
constexpr