OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction Struct Reference
Collaboration diagram for Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction:

Public Member Functions

void set (const std::string &key, const std::string &value)
PresetUpdateResult commit ()

Public Attributes

Preset::Type type = Preset::TYPE_INVALID
std::string target_name
bool filament = false
int slot_number = 0
std::string slot_assignment_snapshot
bool selection_changed = false
bool slot_assignment_changed = false
std::vector< std::pair< std::string, std::string > > staged
std::set< std::string > staged_keys
bool committed = false

Detailed Description

Member Function Documentation

◆ commit()

PresetUpdateResult Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit ( )
296{
297 if (committed)
298 throw std::runtime_error("This preset transaction has already been committed; start a new begin_update()");
300 throw std::runtime_error("This preset transaction has no target");
301
302 PresetUpdateResult result;
304 GUI::GUI_App& app = require_gui_app();
305 GUI::Tab* tab = require_tab(app, type);
306 PresetBundle& bundle = *app.preset_bundle;
307 PresetCollection& collection = collection_for(bundle, type);
308
309 // The target must still be the edited preset: the user may have switched away while the
310 // transaction was staged, and editing a different preset would break "explicit target".
311 const std::string edited = collection.get_edited_preset().name;
312 if (edited != target_name)
313 throw std::runtime_error("The edited " + std::string(preset_tab_name(type)) + " preset is \"" + edited
314 + "\", not this transaction's target \"" + target_name
315 + "\"; nothing was applied");
316
317 if (filament) {
318 // Reject a stale slot mapping instead of editing whatever the slot now points at.
319 const std::string now_assigned = resolved_slot_preset(bundle, slot_number);
320 if (now_assigned != slot_assignment_snapshot)
321 throw std::runtime_error("Filament slot " + std::to_string(slot_number) + " now holds \"" + now_assigned
322 + "\", not \"" + slot_assignment_snapshot
323 + "\" as when this transaction was created; the slot mapping changed, so nothing was applied");
324 }
325
326 // Apply the whole batch through the tab's batch path: it validates every key and value before
327 // touching the preset, rejects duplicate keys, runs the same per-setting commit path a hand
328 // edit uses (validation, on_change, dirty state) and refreshes once for the batch. A failure
329 // restores the edited preset, so no staged setting survives a failed commit.
330 tab->apply_preset_config_values(staged);
331
332 result.type = type;
333 result.target_name = target_name;
334 result.selection_changed = selection_changed;
335 result.slot_number = filament ? slot_number : -1;
336 result.slot_assignment_changed = slot_assignment_changed;
337 result.keys.reserve(staged.size());
338 for (const auto& entry : staged)
339 result.keys.push_back(entry.first);
340 result.dirty = collection.get_edited_preset().is_dirty;
341
342 if (filament) {
343 // Every slot whose assigned preset resolves to the edited one is affected: the preset
344 // is shared, not a per-slot override.
345 for (std::size_t index = 0; index < bundle.filament_presets.size(); ++index) {
346 Preset* preset = bundle.filaments.find_preset(bundle.filament_presets[index]);
347 if (preset != nullptr && preset->name == target_name)
348 result.shared_slots.push_back(static_cast<int>(index) + 1);
349 }
350 }
351 });
352
353 committed = true;
354 return result;
355}
static void run_on_ui_thread(std::function< void()> fn)
Definition PluginHostUi.cpp:677
@ TYPE_INVALID
Definition Preset.hpp:245
GUI::Tab * require_tab(GUI::GUI_App &app, Preset::Type type)
Definition PluginHostPresets.cpp:172
std::string resolved_slot_preset(PresetBundle &bundle, int slot_number)
Definition PluginHostPresets.cpp:266
const char * preset_tab_name(Preset::Type type)
Definition PluginHostPresets.cpp:62
GUI::GUI_App & require_gui_app()
Definition PluginHostPresets.cpp:160
PresetCollection & collection_for(PresetBundle &bundle, Preset::Type type)
Definition PluginHostPresets.cpp:72
@ Preset
Definition calib.hpp:39
Preset::Type type
Definition PluginHostPresets.cpp:144
std::string slot_assignment_snapshot
Definition PluginHostPresets.cpp:148
std::vector< std::pair< std::string, std::string > > staged
Definition PluginHostPresets.cpp:152
std::string target_name
Definition PluginHostPresets.cpp:145
bool slot_assignment_changed
Definition PluginHostPresets.cpp:150

References Slic3r::GUI::Tab::apply_preset_config_values(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::collection_for(), commit(), committed, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult::dirty, filament, Slic3r::PresetBundle::filament_presets, Slic3r::PresetBundle::filaments, Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::get_edited_preset(), Slic3r::Preset::is_dirty, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult::keys, Slic3r::Preset::name, Slic3r::GUI::GUI_App::preset_bundle, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::preset_tab_name(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::require_gui_app(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::require_tab(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::resolved_slot_preset(), Slic3r::PluginHostUi::run_on_ui_thread(), selection_changed, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult::selection_changed, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult::shared_slots, slot_assignment_changed, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult::slot_assignment_changed, slot_assignment_snapshot, slot_number, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult::slot_number, staged, target_name, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult::target_name, type, Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetUpdateResult::type, and Slic3r::Preset::TYPE_INVALID.

Referenced by commit(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::update_edited_preset(), and Slic3r::anonymous_namespace{PluginHostPresets.cpp}::update_filament_slot().

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

◆ set()

void Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::set ( const std::string & key,
const std::string & value )
283{
284 if (committed)
285 throw std::runtime_error("This preset transaction has already been committed; start a new begin_update()");
286 if (key.empty())
287 throw std::invalid_argument("A setting key is required");
288 // Conflicting duplicate writes to one setting are rejected rather than resolved by order.
289 if (!staged_keys.insert(key).second)
290 throw std::invalid_argument("Setting \"" + key + "\" is already staged in this transaction; "
291 "conflicting duplicate writes to one setting are rejected");
292 staged.emplace_back(key, value);
293}
std::set< std::string > staged_keys
Definition PluginHostPresets.cpp:153

References committed, set(), staged, and staged_keys.

Referenced by set(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::update_edited_preset(), and Slic3r::anonymous_namespace{PluginHostPresets.cpp}::update_filament_slot().

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

Member Data Documentation

◆ committed

bool Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::committed = false

Referenced by commit(), and set().

◆ filament

bool Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::filament = false

◆ selection_changed

bool Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::selection_changed = false

◆ slot_assignment_changed

bool Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::slot_assignment_changed = false

◆ slot_assignment_snapshot

std::string Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::slot_assignment_snapshot

◆ slot_number

int Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::slot_number = 0

◆ staged

std::vector<std::pair<std::string, std::string> > Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::staged

Referenced by commit(), and set().

◆ staged_keys

std::set<std::string> Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::staged_keys

Referenced by set().

◆ target_name

std::string Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::target_name

◆ type


The documentation for this struct was generated from the following file: