mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-24 01:01:15 -06:00
PhysicalPrinterDialog is completed
This commit is contained in:
parent
0b88e86634
commit
c5197f3350
4 changed files with 230 additions and 49 deletions
|
|
@ -1345,6 +1345,11 @@ const Preset* PrinterPresetCollection::find_by_model_id(const std::string &model
|
|||
// *** PhysicalPrinter ***
|
||||
// -------------------------
|
||||
|
||||
std::string PhysicalPrinter::separator()
|
||||
{
|
||||
return " * ";
|
||||
}
|
||||
|
||||
const std::vector<std::string>& PhysicalPrinter::printer_options()
|
||||
{
|
||||
static std::vector<std::string> s_opts;
|
||||
|
|
@ -1370,9 +1375,9 @@ const std::string& PhysicalPrinter::get_preset_name() const
|
|||
return config.opt_string("preset_name");
|
||||
}
|
||||
|
||||
const std::string& PhysicalPrinter::get_printer_model() const
|
||||
const std::set<std::string>& PhysicalPrinter::get_preset_names() const
|
||||
{
|
||||
return config.opt_string("printer_model");
|
||||
return preset_names;
|
||||
}
|
||||
|
||||
bool PhysicalPrinter::has_empty_config() const
|
||||
|
|
@ -1384,20 +1389,62 @@ bool PhysicalPrinter::has_empty_config() const
|
|||
config.opt_string("password" ).empty();
|
||||
}
|
||||
|
||||
void PhysicalPrinter::update_preset_names_in_config()
|
||||
{
|
||||
if (!preset_names.empty()) {
|
||||
std::string name;
|
||||
for (auto el : preset_names)
|
||||
name += el + ";";
|
||||
name.pop_back();
|
||||
config.set_key_value("preset_name", new ConfigOptionString(name));
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicalPrinter::save(const std::string& file_name_from, const std::string& file_name_to)
|
||||
{
|
||||
// rename the file
|
||||
boost::nowide::rename(file_name_from.data(), file_name_to.data());
|
||||
this->file = file_name_to;
|
||||
// save configuration
|
||||
this->config.save(this->file);
|
||||
}
|
||||
|
||||
void PhysicalPrinter::update_from_preset(const Preset& preset)
|
||||
{
|
||||
config.apply_only(preset.config, printer_options(), false);
|
||||
// add preset name to the options list
|
||||
config.set_key_value("preset_name", new ConfigOptionString(preset.name));
|
||||
// add preset names to the options list
|
||||
auto ret = preset_names.emplace(preset.name);
|
||||
update_preset_names_in_config();
|
||||
|
||||
update_full_name();
|
||||
}
|
||||
|
||||
void PhysicalPrinter::update_from_config(const DynamicPrintConfig& new_config)
|
||||
{
|
||||
config.apply_only(new_config, printer_options(), false);
|
||||
|
||||
std::string str = config.opt_string("preset_name");
|
||||
std::set<std::string> values{};
|
||||
if (!str.empty()) {
|
||||
boost::split(values, str, boost::is_any_of(";"));
|
||||
for (const std::string& val : values)
|
||||
preset_names.emplace(val);
|
||||
}
|
||||
preset_names = values;
|
||||
|
||||
update_full_name();
|
||||
}
|
||||
|
||||
void PhysicalPrinter::reset_presets()
|
||||
{
|
||||
return preset_names.clear();
|
||||
}
|
||||
|
||||
bool PhysicalPrinter::add_preset(const std::string& preset_name)
|
||||
{
|
||||
return preset_names.emplace(preset_name).second;
|
||||
}
|
||||
|
||||
PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) :
|
||||
name(name)
|
||||
{
|
||||
|
|
@ -1412,16 +1459,23 @@ void PhysicalPrinter::set_name(const std::string& name)
|
|||
|
||||
void PhysicalPrinter::update_full_name()
|
||||
{
|
||||
full_name = name + " * " + get_preset_name();
|
||||
full_name = name + separator() + get_preset_name();
|
||||
}
|
||||
|
||||
std::string PhysicalPrinter::get_short_name(std::string full_name)
|
||||
{
|
||||
int pos = full_name.find_first_of(" * ");
|
||||
int pos = full_name.find(separator());
|
||||
boost::erase_tail(full_name, full_name.length() - pos);
|
||||
return full_name;
|
||||
}
|
||||
|
||||
std::string PhysicalPrinter::get_preset_name(std::string full_name)
|
||||
{
|
||||
int pos = full_name.find(separator());
|
||||
boost::erase_head(full_name, pos + 2);
|
||||
return full_name;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------
|
||||
// *** PhysicalPrinterCollection ***
|
||||
|
|
@ -1497,15 +1551,18 @@ std::string PhysicalPrinterCollection::path_from_name(const std::string& new_nam
|
|||
return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
|
||||
}
|
||||
|
||||
void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_printer)
|
||||
void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_printer, const std::string& renamed_from)
|
||||
{
|
||||
std::string name = renamed_from.empty() ? edited_printer.name : renamed_from;
|
||||
// 1) Find the printer with a new_name or create a new one,
|
||||
// initialize it with the edited config.
|
||||
auto it = this->find_printer_internal(edited_printer.name);
|
||||
if (it != m_printers.end() && it->name == edited_printer.name) {
|
||||
auto it = this->find_printer_internal(name);
|
||||
if (it != m_printers.end() && it->name == name) {
|
||||
// Printer with the same name found.
|
||||
// Overwriting an existing preset.
|
||||
it->config = std::move(edited_printer.config);
|
||||
it->name = edited_printer.name;
|
||||
it->preset_names = edited_printer.preset_names;
|
||||
it->full_name = edited_printer.full_name;
|
||||
}
|
||||
else {
|
||||
|
|
@ -1518,7 +1575,12 @@ void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_print
|
|||
PhysicalPrinter& printer = *it;
|
||||
if (printer.file.empty())
|
||||
printer.file = this->path_from_name(printer.name);
|
||||
printer.save();
|
||||
|
||||
if (printer.file == this->path_from_name(printer.name))
|
||||
printer.save();
|
||||
else
|
||||
// if printer was renamed, we should rename a file and than save the config
|
||||
printer.save(printer.file, this->path_from_name(printer.name));
|
||||
|
||||
// update idx_selected
|
||||
m_idx_selected = it - m_printers.begin();
|
||||
|
|
|
|||
|
|
@ -549,20 +549,33 @@ public:
|
|||
std::string file;
|
||||
// Configuration data, loaded from a file, or set from the defaults.
|
||||
DynamicPrintConfig config;
|
||||
// set of presets used with this physical printer
|
||||
std::set<std::string> preset_names;
|
||||
|
||||
static std::string separator();
|
||||
|
||||
// Has this profile been loaded?
|
||||
bool loaded = false;
|
||||
|
||||
static const std::vector<std::string>& printer_options();
|
||||
const std::string& get_preset_name() const;
|
||||
const std::string& get_printer_model() const;
|
||||
static const std::vector<std::string>& printer_options();
|
||||
const std::string& get_preset_name() const;
|
||||
|
||||
const std::set<std::string>& get_preset_names() const;
|
||||
|
||||
bool has_empty_config() const;
|
||||
void update_preset_names_in_config();
|
||||
|
||||
void save() { this->config.save(this->file); }
|
||||
void save_to(const std::string& file_name) const { this->config.save(file_name); }
|
||||
void save(const std::string& file_name_from, const std::string& file_name_to);
|
||||
|
||||
void update_from_preset(const Preset& preset);
|
||||
void update_from_config(const DynamicPrintConfig &new_config);
|
||||
|
||||
// add preset to the preset_names
|
||||
// return false, if preset with this name is already exist in the set
|
||||
bool add_preset(const std::string& preset_name);
|
||||
void reset_presets();
|
||||
|
||||
// Return a printer technology, return ptFFF if the printer technology is not set.
|
||||
static PrinterTechnology printer_technology(const DynamicPrintConfig& cfg) {
|
||||
auto* opt = cfg.option<ConfigOptionEnum<PrinterTechnology>>("printer_technology");
|
||||
|
|
@ -578,6 +591,9 @@ public:
|
|||
// get printer name from the full name uncluded preset name
|
||||
static std::string get_short_name(std::string full_name);
|
||||
|
||||
// get preset name from the full name uncluded printer name
|
||||
static std::string get_preset_name(std::string full_name);
|
||||
|
||||
protected:
|
||||
friend class PhysicalPrinterCollection;
|
||||
};
|
||||
|
|
@ -615,7 +631,7 @@ public:
|
|||
// Save the printer under a new name. If the name is different from the old one,
|
||||
// a new printer is stored into the list of printers.
|
||||
// New printer is activated.
|
||||
void save_printer(const PhysicalPrinter& printer);
|
||||
void save_printer(const PhysicalPrinter& printer, const std::string& renamed_from);
|
||||
|
||||
// Delete the current preset, activate the first visible preset.
|
||||
// returns true if the preset was deleted successfully.
|
||||
|
|
@ -633,8 +649,6 @@ public:
|
|||
// Returns the full name of the selected preset, or an empty string if no preset is selected.
|
||||
std::string get_selected_full_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().full_name; }
|
||||
// Returns the printer model of the selected preset, or an empty string if no preset is selected.
|
||||
std::string get_selected_printer_model() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_printer_model(); }
|
||||
// Returns the printer model of the selected preset, or an empty string if no preset is selected.
|
||||
std::string get_selected_printer_preset_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_preset_name(); }
|
||||
// Returns the config of the selected preset, or nullptr if no preset is selected.
|
||||
DynamicPrintConfig* get_selected_printer_config() { return (m_idx_selected == size_t(-1)) ? nullptr : &(this->get_selected_printer().config); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue