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

Classes

struct  PresetEditor
struct  SelectionCancelled
struct  PresetUpdateResult
struct  PresetTransaction
struct  ComboPresetMatch

Functions

py::list current_filament_presets (PresetBundle &bundle)
PresetCollection & printer_presets (PresetBundle &bundle)
const char * preset_tab_name (Preset::Type type)
PresetCollection & collection_for (PresetBundle &bundle, Preset::Type type)
GUI::GUI_App & require_gui_app ()
GUI::Tab * require_tab (GUI::GUI_App &app, Preset::Type type)
bool combo_item_is_marker (GUI::PresetComboBox &combo, int item)
ComboPresetMatch resolve_combo_preset (GUI::PresetComboBox &combo, const std::string &requested)
int combo_item_for_preset (GUI::PresetComboBox &combo, const std::string &preset_name)
std::string resolve_preset_in_combo (GUI::PresetComboBox &combo, const std::string &requested, const std::string &category, const std::string &selector)
std::string resolved_slot_preset (PresetBundle &bundle, int slot_number)
void bind_preset_target (Preset::Type type, const std::string &preset_name, PresetTransaction &transaction)
PresetTransaction begin_preset_update (Preset::Type type, const std::string &preset_name)
void bind_filament_target (int slot_number, const std::string &preset_name, PresetTransaction &transaction)
PresetTransaction begin_filament_update (int slot_number, const std::string &preset_name)
void update_edited_preset (Preset::Type type, const std::string &key, const std::string &value)
void update_filament_slot (int slot_number, const std::string &key, const std::string &value)
void reload_local_bundle (const std::string &bundle_id)
std::vector< std::string > list_bundle_ids ()

Class Documentation

◆ Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetEditor

struct Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetEditor
Class Members
Type type = Preset::TYPE_INVALID

◆ Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult

struct Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult
Collaboration diagram for Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult:
Class Members
bool dirty = false
vector< string > keys
bool selection_changed = false
vector< int > shared_slots
bool slot_assignment_changed = false
int slot_number = -1
string target_name
Type type = Preset::TYPE_INVALID

◆ Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch

struct Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch
Collaboration diagram for Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch:
Class Members
bool ambiguous = false
string internal_name
int item = -1

Function Documentation

◆ begin_filament_update()

PresetTransaction Slic3r::anonymous_namespace{PluginHostPresets.cpp}::begin_filament_update ( int slot_number,
const std::string & preset_name )
570{
571 PresetTransaction transaction;
572 PluginHostUi::run_on_ui_thread([&] { bind_filament_target(slot_number, preset_name, transaction); });
573 return transaction;
574}
static void run_on_ui_thread(std::function< void()> fn)
Definition PluginHostUi.cpp:677
void bind_filament_target(int slot_number, const std::string &preset_name, PresetTransaction &transaction)
Definition PluginHostPresets.cpp:429

References begin_filament_update(), bind_filament_target(), and Slic3r::PluginHostUi::run_on_ui_thread().

Referenced by begin_filament_update(), and update_filament_slot().

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

◆ begin_preset_update()

PresetTransaction Slic3r::anonymous_namespace{PluginHostPresets.cpp}::begin_preset_update ( Preset::Type type,
const std::string & preset_name )
412{
413 PresetTransaction transaction;
414 PluginHostUi::run_on_ui_thread([&] { bind_preset_target(type, preset_name, transaction); });
415 return transaction;
416}
void bind_preset_target(Preset::Type type, const std::string &preset_name, PresetTransaction &transaction)
Definition PluginHostPresets.cpp:361

References begin_preset_update(), bind_preset_target(), and Slic3r::PluginHostUi::run_on_ui_thread().

Referenced by begin_preset_update(), and update_edited_preset().

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

◆ bind_filament_target()

void Slic3r::anonymous_namespace{PluginHostPresets.cpp}::bind_filament_target ( int slot_number,
const std::string & preset_name,
PresetTransaction & transaction )
430{
432 PresetBundle& bundle = *app.preset_bundle;
433 GUI::Plater* plater = app.plater();
434
435 // A mixed-color virtual slot has no single filament preset behind it, so every form of this
436 // call is rejected: with or without a preset_name there is no one preset to edit or assign.
437 // Range-guarded so an out-of-range slot still gets resolved_slot_preset()'s clear error.
438 if (slot_number >= 1 && static_cast<size_t>(slot_number) <= bundle.filament_presets.size()
439 && bundle.is_mixed_filament(static_cast<size_t>(slot_number) - 1))
440 throw std::invalid_argument("Filament slot " + std::to_string(slot_number)
441 + " is a mixed-color virtual slot; it has no single filament preset to edit or assign");
442
443 // Resolve and validate before any selection, so a bad slot fails without a prompt.
444 const std::string assigned_internal = resolved_slot_preset(bundle, slot_number);
445
447
448 const size_t slot_index = static_cast<size_t>(slot_number) - 1;
449
450 std::string target = assigned_internal;
451 if (!preset_name.empty()) {
452 // Resolve against the requested sidebar slot's own selector, not the tab's: that is the
453 // model the user picks this slot's filament from, including its compatibility filter. The
454 // selector matches the exact name shown (display label or item alias).
455 std::vector<GUI::PlaterPresetComboBox*>& slot_combos = plater->sidebar().combos_filament();
456 GUI::PlaterPresetComboBox* slot_combo = slot_index < slot_combos.size() ? slot_combos[slot_index] : nullptr;
457 std::string resolved;
458 if (slot_combo != nullptr && slot_combo->GetCount() > 0) {
459 const ComboPresetMatch match = resolve_combo_preset(*slot_combo, preset_name);
460 if (match.ambiguous)
461 throw std::invalid_argument("The filament name \"" + preset_name
462 + "\" is ambiguous in the filament preset selector for filament slot "
463 + std::to_string(slot_number)
464 + "; more than one entry shows it, so name the preset by its own entry");
465 if (match.item >= 0) {
466 resolved = match.internal_name;
467 } else {
468 // Not shown by this slot's selector. Only the slot's current assignment stays
469 // targetable (a hidden or incompatible-but-selected preset the dropdown omits);
470 // resolve it by internal name or by display alias and accept only that preset. A
471 // different preset the tab happens to edit is a globally edited target, not an
472 // offered choice for this slot, and is rejected.
473 Preset* by_name = bundle.filaments.find_preset(preset_name);
474 if (by_name == nullptr) {
475 const std::string& alias_name = bundle.filaments.get_preset_name_by_alias(preset_name);
476 by_name = bundle.filaments.find_preset(alias_name);
477 }
478 if (by_name == nullptr || by_name->name != assigned_internal)
479 throw std::invalid_argument("Filament preset \"" + preset_name
480 + "\" is not offered by the filament preset selector for filament slot "
481 + std::to_string(slot_number));
482 resolved = by_name->name;
483 }
484 } else {
485 // The slot selector is not populated; fall back to the tab selector, then to collection
486 // internal names, so the call still works when the sidebar has not been laid out.
487 GUI::TabPresetComboBox* tab_combo = tab->get_combo_box();
488 if (tab_combo != nullptr && tab_combo->GetCount() > 0)
489 resolved = resolve_preset_in_combo(*tab_combo, preset_name, "filament",
490 "filament preset selector for the selected printer");
491 else
492 resolved = preset_name;
493 }
494
495 Preset* requested = bundle.filaments.find_preset(resolved);
496 if (requested == nullptr)
497 throw std::invalid_argument("No filament preset named \"" + resolved + "\" is available to select");
498 target = requested->name;
499 }
500
501 bool selection_changed = false;
502 if (bundle.filaments.get_edited_preset().name != target) {
503 // A declined prompt is a user cancellation: it is thrown before any slot-assignment change,
504 // so neither the mapping nor a setting is touched.
505 if (!tab->select_preset(target))
506 throw SelectionCancelled("Switching the edited filament preset to \"" + target + "\" for filament slot "
507 + std::to_string(slot_number)
508 + " was canceled; neither the slot assignment nor any setting was changed");
509 if (bundle.filaments.get_edited_preset().name != target)
510 throw std::runtime_error("The edited filament preset is \"" + bundle.filaments.get_edited_preset().name
511 + "\", not \"" + target + "\"; the transaction was not created");
512 selection_changed = true;
513 }
514
515 bool assignment_changed = false;
516 if (!preset_name.empty() && target != assigned_internal) {
517 if (app.app_config == nullptr)
518 throw std::runtime_error("Application configuration is not available");
519 // Mirror the filament branch of Plater::priv::on_select_preset() (the sidebar's normal
520 // preset selection): update the mapping, then every dependent project/UI side effect,
521 // rather than the vector entry alone.
522 const bool was_support = GUI::is_support_filament(static_cast<int>(slot_index));
523 bundle.set_filament_preset(slot_index, target);
525 bundle.export_selections(*app.app_config);
527 // Assigning a support filament (or moving away from one) changes which filaments the
528 // flush rules apply to, so the normal flow recalculates the flushing volumes when
529 // auto-calc covers every filament.
530 if (GUI::is_support_filament(static_cast<int>(slot_index)) != was_support
531 && app.app_config->get("auto_calculate_flush") == "all")
532 plater->sidebar().auto_calc_flushing_volumes(static_cast<int>(slot_index));
533 // Refresh the requested slot's own sidebar combo so its list and current selection show the
534 // newly assigned target (the list may not have contained it), matching the sidebar
535 // selection path. Fetch the pointer after update_dynamic_filament_list(), which may
536 // rebuild the combo vector.
537 std::vector<GUI::PlaterPresetComboBox*>& slot_combos = plater->sidebar().combos_filament();
538 if (slot_index < slot_combos.size() && slot_combos[slot_index] != nullptr) {
539 GUI::PlaterPresetComboBox* slot_combo = slot_combos[slot_index];
540 slot_combo->update();
541 // Keep the slot's AMS sync badge truthful, reading the item's own flag, the same source
542 // on_select_preset() reads, so no UI state is invented here.
543 const int item = combo_item_for_preset(*slot_combo, target);
544 if (item >= 0)
545 slot_combo->set_sync_badge(slot_combo->GetFlag(item)
547 }
548 plater->on_filament_change(slot_index);
549 assignment_changed = true;
550 }
551
552 // Match PlaterPresetComboBox::switch_to_tab(): record which 0-based filament slot this tab
553 // combobox now edits, so the GUI shows the slot the value was written for.
554 if (GUI::TabPresetComboBox* combo = tab->get_combo_box())
555 combo->set_filament_idx(slot_number - 1);
556
557 transaction.type = Preset::TYPE_FILAMENT;
558 transaction.filament = true;
559 transaction.slot_number = slot_number;
560 transaction.target_name = target;
561 transaction.selection_changed = selection_changed;
562 transaction.slot_assignment_changed = assignment_changed;
563 // Snapshot the mapping after the explicit assignment, as the slot's resolved internal name,
564 // so commit() compares like with like (a stored alias resolves to the same internal preset).
565 transaction.slot_assignment_snapshot = resolved_slot_preset(bundle, slot_number);
566}
unsigned int GetCount() const override
Definition ComboBox.cpp:311
bool get(const std::string &section, const std::string &key, std::string &value) const
Definition AppConfig.hpp:147
Definition GUI_App.hpp:255
Plater * plater()
Definition GUI_App.cpp:9709
PresetBundle * preset_bundle
Definition GUI_App.hpp:788
AppConfig * app_config
Definition GUI_App.hpp:787
Definition PresetComboBoxes.hpp:194
Definition Plater.hpp:337
void on_filament_change(size_t filament_idx)
Definition Plater.cpp:21362
void update_project_dirty_from_presets()
Definition Plater.cpp:15664
Sidebar & sidebar()
Definition Plater.cpp:16046
@ FROM_AMS
Definition PresetComboBoxes.hpp:67
std::vector< PlaterPresetComboBox * > & combos_filament()
Definition Plater.cpp:6891
void auto_calc_flushing_volumes(const int filament_idx=-1, const int extruder_id=-1)
Automatically calculates flushing volumes.
Definition Plater.cpp:6973
void update_dynamic_filament_list()
Definition Plater.cpp:6627
Definition Tab.hpp:152
TabPresetComboBox * get_combo_box()
Definition Tab.hpp:495
bool select_preset(std::string preset_name="", bool delete_current=false, const std::string &last_selected_ph_printer_name="", bool force_select=false, bool force_no_transfer=false)
Definition Tab.cpp:7387
Definition PresetBundle.hpp:210
void set_filament_preset(size_t idx, const std::string &name)
Definition PresetBundle.cpp:8730
void export_selections(AppConfig &config)
Definition PresetBundle.cpp:4232
PresetCollection filaments
Definition PresetBundle.hpp:499
bool is_mixed_filament(size_t idx) const
Definition PresetBundle.cpp:4465
std::vector< std::string > filament_presets
Definition PresetBundle.hpp:507
Preset & get_edited_preset()
Definition Preset.hpp:756
const std::string & get_preset_name_by_alias(const std::string &alias) const
Definition Preset.cpp:3719
Preset * find_preset(const std::string &name, bool first_visible_if_not_found=false, bool real=false, bool only_from_library=false)
Definition Preset.cpp:3772
Definition Preset.hpp:241
std::string name
Definition Preset.hpp:288
@ TYPE_FILAMENT
Definition Preset.hpp:248
bool is_support_filament(int extruder_id, bool strict_check)
Definition GUI_App.cpp:10492
GUI::Tab * require_tab(GUI::GUI_App &app, Preset::Type type)
Definition PluginHostPresets.cpp:172
std::string internal_name
Definition PluginHostPresets.cpp:198
std::string resolved_slot_preset(PresetBundle &bundle, int slot_number)
Definition PluginHostPresets.cpp:266
ComboPresetMatch resolve_combo_preset(GUI::PresetComboBox &combo, const std::string &requested)
Definition PluginHostPresets.cpp:207
int combo_item_for_preset(GUI::PresetComboBox &combo, const std::string &preset_name)
Definition PluginHostPresets.cpp:233
GUI::GUI_App & require_gui_app()
Definition PluginHostPresets.cpp:160
std::string resolve_preset_in_combo(GUI::PresetComboBox &combo, const std::string &requested, const std::string &category, const std::string &selector)
Definition PluginHostPresets.cpp:252
@ Preset
Definition calib.hpp:39
Preset::Type type
Definition PluginHostPresets.cpp:144
std::string slot_assignment_snapshot
Definition PluginHostPresets.cpp:148
std::string target_name
Definition PluginHostPresets.cpp:145
bool slot_assignment_changed
Definition PluginHostPresets.cpp:150

References Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch::ambiguous, Slic3r::GUI::GUI_App::app_config, Slic3r::GUI::Sidebar::auto_calc_flushing_volumes(), bind_filament_target(), combo_item_for_preset(), Slic3r::GUI::Sidebar::combos_filament(), Slic3r::PresetBundle::export_selections(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::filament, Slic3r::PresetBundle::filament_presets, Slic3r::PresetBundle::filaments, Slic3r::PresetCollection::find_preset(), Slic3r::GUI::PresetComboBox::FROM_AMS, Slic3r::AppConfig::get(), Slic3r::GUI::Tab::get_combo_box(), Slic3r::PresetCollection::get_edited_preset(), Slic3r::PresetCollection::get_preset_name_by_alias(), ComboBox::GetCount(), ComboBox::GetFlag(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch::internal_name, Slic3r::PresetBundle::is_mixed_filament(), Slic3r::GUI::is_support_filament(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch::item, Slic3r::Preset::name, Slic3r::GUI::Plater::on_filament_change(), Slic3r::GUI::GUI_App::plater(), Slic3r::GUI::GUI_App::preset_bundle, require_gui_app(), require_tab(), resolve_combo_preset(), resolve_preset_in_combo(), resolved_slot_preset(), Slic3r::GUI::Tab::select_preset(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::selection_changed, Slic3r::PresetBundle::set_filament_preset(), Slic3r::GUI::PlaterPresetComboBox::set_sync_badge(), Slic3r::GUI::Plater::sidebar(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::slot_assignment_changed, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::slot_assignment_snapshot, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::slot_number, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::target_name, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::type, Slic3r::Preset::TYPE_FILAMENT, Slic3r::GUI::PlaterPresetComboBox::update(), Slic3r::GUI::Sidebar::update_dynamic_filament_list(), and Slic3r::GUI::Plater::update_project_dirty_from_presets().

Referenced by begin_filament_update(), and bind_filament_target().

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

◆ bind_preset_target()

void Slic3r::anonymous_namespace{PluginHostPresets.cpp}::bind_preset_target ( Preset::Type type,
const std::string & preset_name,
PresetTransaction & transaction )
362{
364 GUI::Tab* tab = require_tab(app, type);
365 PresetCollection& collection = collection_for(*app.preset_bundle, type);
366
367 const std::string current = collection.get_edited_preset().name;
368 std::string target = current;
369 bool selection_changed = false;
370
371 if (!preset_name.empty()) {
372 // Resolve by the name the tab's dropdown actually shows (display label or item alias), so a
373 // plugin can pass exactly what the user sees. With no populated dropdown there is nothing
374 // to resolve against, so fall back to collection internal names.
376 std::string resolved;
377 if (combo != nullptr && combo->GetCount() > 0)
378 resolved = resolve_preset_in_combo(*combo, preset_name, preset_tab_name(type),
379 "preset selector for the selected printer");
380 else
381 resolved = preset_name;
382
383 Preset* requested = collection.find_preset(resolved);
384 if (requested == nullptr)
385 throw std::invalid_argument("No " + std::string(preset_tab_name(type)) + " preset named \"" + resolved
386 + "\" is available to select");
387 target = requested->name;
388 if (target != current) {
389 // Normal UI selection: honours the unsaved-edit prompt; a declined prompt returns false
390 // and is a user cancellation, distinct from any other resolution failure.
391 if (!tab->select_preset(target))
392 throw SelectionCancelled("Switching the edited " + std::string(preset_tab_name(type)) + " preset to \""
393 + target + "\" was canceled; nothing was staged");
394 selection_changed = true;
395 }
396 }
397
398 // select_preset() can still leave a different preset edited (e.g. the target is not an
399 // allowed dropdown choice), so confirm before binding.
400 if (collection.get_edited_preset().name != target)
401 throw std::runtime_error("The edited " + std::string(preset_tab_name(type)) + " preset is \""
402 + collection.get_edited_preset().name + "\", not \"" + target
403 + "\"; the transaction was not created");
404
405 transaction.type = type;
406 transaction.target_name = target;
407 transaction.selection_changed = selection_changed;
408}
Definition PresetComboBoxes.hpp:235
Definition Preset.hpp:570
const char * preset_tab_name(Preset::Type type)
Definition PluginHostPresets.cpp:62
PresetCollection & collection_for(PresetBundle &bundle, Preset::Type type)
Definition PluginHostPresets.cpp:72

References bind_preset_target(), collection_for(), Slic3r::PresetCollection::find_preset(), Slic3r::GUI::Tab::get_combo_box(), Slic3r::PresetCollection::get_edited_preset(), ComboBox::GetCount(), Slic3r::Preset::name, Slic3r::GUI::GUI_App::preset_bundle, preset_tab_name(), require_gui_app(), require_tab(), resolve_preset_in_combo(), Slic3r::GUI::Tab::select_preset(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::selection_changed, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::target_name, and Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::type.

Referenced by begin_preset_update(), and bind_preset_target().

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

◆ collection_for()

PresetCollection & Slic3r::anonymous_namespace{PluginHostPresets.cpp}::collection_for ( PresetBundle & bundle,
Preset::Type type )
73{
74 switch (type) {
75 case Preset::TYPE_PRINT: return bundle.prints;
76 case Preset::TYPE_FILAMENT: return bundle.filaments;
77 case Preset::TYPE_PRINTER: return printer_presets(bundle);
78 default: throw std::invalid_argument("Unsupported preset category");
79 }
80}
PresetCollection prints
Definition PresetBundle.hpp:497
@ TYPE_PRINTER
Definition Preset.hpp:250
@ TYPE_PRINT
Definition Preset.hpp:246
PresetCollection & printer_presets(PresetBundle &bundle)
Definition PluginHostPresets.cpp:50

References collection_for(), Slic3r::PresetBundle::filaments, printer_presets(), Slic3r::PresetBundle::prints, Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, and Slic3r::Preset::TYPE_PRINTER.

Referenced by bind_preset_target(), collection_for(), and Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit().

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

◆ combo_item_for_preset()

int Slic3r::anonymous_namespace{PluginHostPresets.cpp}::combo_item_for_preset ( GUI::PresetComboBox & combo,
const std::string & preset_name )
234{
235 const std::string want = Preset::remove_suffix_modified(preset_name);
236 const int item_count = combo.GetCount();
237 for (int item = 0; item < item_count; ++item) {
238 if (combo_item_is_marker(combo, item))
239 continue;
240 const wxString alias = combo.GetItemAlias(item);
241 const std::string alias_name = alias.empty() ? std::string()
242 : Preset::remove_suffix_modified(alias.ToUTF8().data());
243 if (!alias_name.empty() && alias_name == want)
244 return item;
245 }
246 return -1;
247}
wxString GetItemAlias(unsigned int n) const
Definition ComboBox.cpp:343
static std::string remove_suffix_modified(const std::string &name)
Definition Preset.cpp:516
bool combo_item_is_marker(GUI::PresetComboBox &combo, int item)
Definition PluginHostPresets.cpp:187

References combo_item_for_preset(), combo_item_is_marker(), ComboBox::GetCount(), ComboBox::GetItemAlias(), and Slic3r::Preset::remove_suffix_modified().

Referenced by bind_filament_target(), and combo_item_for_preset().

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

◆ combo_item_is_marker()

bool Slic3r::anonymous_namespace{PluginHostPresets.cpp}::combo_item_is_marker ( GUI::PresetComboBox & combo,
int item )
188{
189 const auto marker = reinterpret_cast<std::size_t>(combo.GetClientData(item));
191}
@ LABEL_ITEM_MAX
Definition PresetComboBoxes.hpp:62
@ LABEL_ITEM_DISABLED
Definition PresetComboBoxes.hpp:54

References combo_item_is_marker(), Slic3r::GUI::PresetComboBox::LABEL_ITEM_DISABLED, and Slic3r::GUI::PresetComboBox::LABEL_ITEM_MAX.

Referenced by combo_item_for_preset(), combo_item_is_marker(), and resolve_combo_preset().

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

◆ current_filament_presets()

py::list Slic3r::anonymous_namespace{PluginHostPresets.cpp}::current_filament_presets ( PresetBundle & bundle)
38{
39 py::list presets;
40 for (const std::string& preset_name : bundle.filament_presets) {
41 Preset* preset = bundle.filaments.find_preset(preset_name);
42 if (preset == nullptr)
43 presets.append(py::none());
44 else
45 presets.append(py::cast(preset, py::return_value_policy::reference));
46 }
47 return presets;
48}

References current_filament_presets(), Slic3r::PresetBundle::filament_presets, Slic3r::PresetBundle::filaments, and Slic3r::PresetCollection::find_preset().

Referenced by current_filament_presets().

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

◆ list_bundle_ids()

std::vector< std::string > Slic3r::anonymous_namespace{PluginHostPresets.cpp}::list_bundle_ids ( )
624{
625 std::vector<std::string> ids;
627 GUI::GUI_App& app = GUI::wxGetApp();
628 if (app.is_closing())
629 throw std::runtime_error("OrcaSlicer is closing");
630 if (app.preset_bundle == nullptr)
631 throw std::runtime_error("Preset bundle is not available");
632 if (app.app_config == nullptr)
633 throw std::runtime_error("Application configuration is not available");
634
635 ids = app.preset_bundle->list_local_bundle_ids(app.app_config->get("preset_folder"));
636 });
637 return ids;
638}
bool is_closing() const
Definition GUI_App.hpp:436
std::vector< std::string > list_local_bundle_ids(const std::string &preset_folder)
Definition PresetBundle.cpp:1579

References Slic3r::GUI::GUI_App::app_config, Slic3r::AppConfig::get(), Slic3r::GUI::GUI_App::is_closing(), list_bundle_ids(), Slic3r::PresetBundle::list_local_bundle_ids(), Slic3r::GUI::GUI_App::preset_bundle, and Slic3r::PluginHostUi::run_on_ui_thread().

Referenced by list_bundle_ids().

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

◆ preset_tab_name()

const char * Slic3r::anonymous_namespace{PluginHostPresets.cpp}::preset_tab_name ( Preset::Type type)
63{
64 switch (type) {
65 case Preset::TYPE_PRINT: return "process";
66 case Preset::TYPE_FILAMENT: return "filament";
67 case Preset::TYPE_PRINTER: return "printer";
68 default: return "preset";
69 }
70}

References preset_tab_name(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, and Slic3r::Preset::TYPE_PRINTER.

Referenced by bind_preset_target(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit(), preset_tab_name(), and require_tab().

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

◆ printer_presets()

PresetCollection & Slic3r::anonymous_namespace{PluginHostPresets.cpp}::printer_presets ( PresetBundle & bundle)
51{
52 return static_cast<PresetCollection&>(bundle.printers);
53}
PrinterPresetCollection printers
Definition PresetBundle.hpp:503

References printer_presets(), and Slic3r::PresetBundle::printers.

Referenced by collection_for(), and printer_presets().

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

◆ reload_local_bundle()

void Slic3r::anonymous_namespace{PluginHostPresets.cpp}::reload_local_bundle ( const std::string & bundle_id)
593{
594 bool reloaded = false;
595 std::string error;
597 GUI::GUI_App& app = GUI::wxGetApp();
598 if (app.is_closing())
599 throw std::runtime_error("OrcaSlicer is closing");
600 if (app.preset_bundle == nullptr)
601 throw std::runtime_error("Preset bundle is not available");
602 if (app.app_config == nullptr)
603 throw std::runtime_error("Application configuration is not available");
604 if (app.mainframe == nullptr)
605 throw std::runtime_error("OrcaSlicer main window is not available");
606
607 reloaded = app.preset_bundle->reload_local_bundle(app.app_config->get("preset_folder"), bundle_id, &error);
608 if (!reloaded)
609 return;
610
612 for (GUI::Tab* tab : app.tabs_list) {
613 tab->reload_config();
614 tab->update_changed_ui();
615 }
616 if (GUI::Plater* plater = app.plater())
617 plater->sidebar().update_all_preset_comboboxes();
618 });
619 if (!reloaded)
620 throw std::runtime_error(error.empty() ? "Local bundle was not reloaded" : error);
621}
std::vector< Tab * > tabs_list
Definition GUI_App.hpp:803
MainFrame * mainframe
Definition GUI_App.hpp:790
void update_side_preset_ui()
Definition MainFrame.cpp:4735
virtual void reload_config()
Definition Tab.cpp:1783
void update_changed_ui()
Definition Tab.cpp:1106
bool reload_local_bundle(const std::string &preset_folder, const std::string &bundle_id, std::string *error=nullptr)
Definition PresetBundle.cpp:1609

References Slic3r::GUI::GUI_App::app_config, Slic3r::AppConfig::get(), Slic3r::GUI::GUI_App::is_closing(), Slic3r::GUI::GUI_App::mainframe, Slic3r::GUI::GUI_App::plater(), Slic3r::GUI::GUI_App::preset_bundle, Slic3r::GUI::Tab::reload_config(), reload_local_bundle(), Slic3r::PresetBundle::reload_local_bundle(), Slic3r::PluginHostUi::run_on_ui_thread(), Slic3r::GUI::GUI_App::tabs_list, Slic3r::GUI::Tab::update_changed_ui(), and Slic3r::GUI::MainFrame::update_side_preset_ui().

Referenced by reload_local_bundle().

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

◆ require_gui_app()

GUI::GUI_App & Slic3r::anonymous_namespace{PluginHostPresets.cpp}::require_gui_app ( )
161{
162 GUI::GUI_App& app = GUI::wxGetApp();
163 if (app.is_closing())
164 throw std::runtime_error("OrcaSlicer is closing");
165 if (app.preset_bundle == nullptr)
166 throw std::runtime_error("Preset bundle is not available");
167 if (app.plater() == nullptr)
168 throw std::runtime_error("OrcaSlicer main window is not available");
169 return app;
170}

References Slic3r::GUI::GUI_App::is_closing(), Slic3r::GUI::GUI_App::plater(), Slic3r::GUI::GUI_App::preset_bundle, and require_gui_app().

Referenced by bind_filament_target(), bind_preset_target(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit(), and require_gui_app().

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

◆ require_tab()

GUI::Tab * Slic3r::anonymous_namespace{PluginHostPresets.cpp}::require_tab ( GUI::GUI_App & app,
Preset::Type type )
173{
174 GUI::Tab* tab = app.get_tab(type);
175 if (tab == nullptr)
176 throw std::runtime_error(std::string("The ") + preset_tab_name(type) + " preset tab is not available");
177 // The tab for this preset type exists, but the selected printer's technology may not use it
178 // (the print tab no-ops under SLA); refuse instead of writing a value the UI cannot apply.
180 throw std::runtime_error(std::string("The ") + preset_tab_name(type)
181 + " preset is not available for the selected printer technology");
182 return tab;
183}
Tab * get_tab(Preset::Type type)
Definition GUI_App.cpp:8680
virtual bool supports_printer_technology(const PrinterTechnology tech) const =0
Preset & get_selected_preset()
Definition Preset.hpp:731
static PrinterTechnology printer_technology(const DynamicPrintConfig &cfg)
Definition Preset.hpp:392

References Slic3r::PresetCollection::get_selected_preset(), Slic3r::GUI::GUI_App::get_tab(), Slic3r::GUI::GUI_App::preset_bundle, preset_tab_name(), Slic3r::Preset::printer_technology(), Slic3r::PresetBundle::printers, require_tab(), and Slic3r::GUI::Tab::supports_printer_technology().

Referenced by bind_filament_target(), bind_preset_target(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit(), and require_tab().

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

◆ resolve_combo_preset()

ComboPresetMatch Slic3r::anonymous_namespace{PluginHostPresets.cpp}::resolve_combo_preset ( GUI::PresetComboBox & combo,
const std::string & requested )
208{
209 ComboPresetMatch match;
210 const std::string want = Preset::remove_suffix_modified(requested);
211 const int item_count = combo.GetCount();
212 for (int item = 0; item < item_count; ++item) {
213 if (combo_item_is_marker(combo, item))
214 continue;
215 const wxString alias = combo.GetItemAlias(item);
216 const std::string alias_name = alias.empty() ? std::string()
217 : Preset::remove_suffix_modified(alias.ToUTF8().data());
218 const std::string label_name = Preset::remove_suffix_modified(combo.GetString(item).ToUTF8().data());
219 if ((alias_name.empty() || alias_name != want) && label_name != want)
220 continue;
221 if (match.item >= 0 && match.item != item) {
222 match.ambiguous = true;
223 return match;
224 }
225 match.item = item;
226 match.internal_name = alias_name.empty() ? label_name : alias_name;
227 }
228 return match;
229}
wxString GetString(unsigned int n) const override
Definition ComboBox.cpp:320

References Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch::ambiguous, combo_item_is_marker(), ComboBox::GetCount(), ComboBox::GetItemAlias(), ComboBox::GetString(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch::internal_name, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch::item, Slic3r::Preset::remove_suffix_modified(), and resolve_combo_preset().

Referenced by bind_filament_target(), resolve_combo_preset(), and resolve_preset_in_combo().

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

◆ resolve_preset_in_combo()

std::string Slic3r::anonymous_namespace{PluginHostPresets.cpp}::resolve_preset_in_combo ( GUI::PresetComboBox & combo,
const std::string & requested,
const std::string & category,
const std::string & selector )
254{
255 const ComboPresetMatch match = resolve_combo_preset(combo, requested);
256 if (match.ambiguous)
257 throw std::invalid_argument("The " + category + " name \"" + requested + "\" is ambiguous in the " + selector
258 + "; more than one entry shows it, so name the preset by its own entry");
259 if (match.item < 0)
260 throw std::invalid_argument("The " + category + " preset \"" + requested + "\" is not offered by the " + selector);
261 return match.internal_name;
262}

References Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch::ambiguous, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch::internal_name, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::ComboPresetMatch::item, resolve_combo_preset(), and resolve_preset_in_combo().

Referenced by bind_filament_target(), bind_preset_target(), and resolve_preset_in_combo().

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

◆ resolved_slot_preset()

std::string Slic3r::anonymous_namespace{PluginHostPresets.cpp}::resolved_slot_preset ( PresetBundle & bundle,
int slot_number )
267{
268 if (slot_number < 1 || static_cast<size_t>(slot_number) > bundle.filament_presets.size())
269 throw std::out_of_range("Filament slot " + std::to_string(slot_number)
270 + " is out of range; slot numbers are 1-based and this printer has "
271 + std::to_string(bundle.filament_presets.size()) + " filament slot(s)");
272 const std::string& assigned_name = bundle.filament_presets[static_cast<size_t>(slot_number) - 1];
273 if (assigned_name.empty())
274 throw std::runtime_error("Filament slot " + std::to_string(slot_number) + " has no assigned filament preset");
275 Preset* preset = bundle.filaments.find_preset(assigned_name);
276 if (preset == nullptr)
277 throw std::runtime_error("Filament slot " + std::to_string(slot_number) + " is assigned \"" + assigned_name
278 + "\", which does not resolve to a filament preset");
279 return preset->name;
280}

References Slic3r::PresetBundle::filament_presets, Slic3r::PresetBundle::filaments, Slic3r::PresetCollection::find_preset(), Slic3r::Preset::name, and resolved_slot_preset().

Referenced by bind_filament_target(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit(), and resolved_slot_preset().

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

◆ update_edited_preset()

void Slic3r::anonymous_namespace{PluginHostPresets.cpp}::update_edited_preset ( Preset::Type type,
const std::string & key,
const std::string & value )
579{
580 PresetTransaction transaction = begin_preset_update(type, std::string());
581 transaction.set(key, value);
582 transaction.commit();
583}
PresetTransaction begin_preset_update(Preset::Type type, const std::string &preset_name)
Definition PluginHostPresets.cpp:411
PresetUpdateResult commit()
Definition PluginHostPresets.cpp:295
void set(const std::string &key, const std::string &value)
Definition PluginHostPresets.cpp:282

References begin_preset_update(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::set(), and update_edited_preset().

Referenced by update_edited_preset().

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

◆ update_filament_slot()

void Slic3r::anonymous_namespace{PluginHostPresets.cpp}::update_filament_slot ( int slot_number,
const std::string & key,
const std::string & value )
586{
587 PresetTransaction transaction = begin_filament_update(slot_number, std::string());
588 transaction.set(key, value);
589 transaction.commit();
590}
PresetTransaction begin_filament_update(int slot_number, const std::string &preset_name)
Definition PluginHostPresets.cpp:569

References begin_filament_update(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::set(), and update_filament_slot().

Referenced by update_filament_slot().

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