mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-24 01:01:15 -06:00
PhysicalPrinter : Next improvements:
* Create full printer name as a PrinterName + RelatedPresetName * Added printer model to the PhysicalPrinter.config => Enable to select just between presets with same printer model * When physical printer is selected and create new preset ask if should we use this preset for selected ph_printer or just to switch for it
This commit is contained in:
parent
1a2926050f
commit
d96b5f3606
8 changed files with 225 additions and 61 deletions
|
|
@ -26,6 +26,7 @@
|
|||
#include <boost/format.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
#include <boost/nowide/cenv.hpp>
|
||||
|
|
@ -1351,6 +1352,7 @@ const std::vector<std::string>& PhysicalPrinter::printer_options()
|
|||
s_opts = {
|
||||
"preset_name",
|
||||
"printer_technology",
|
||||
"printer_model",
|
||||
"host_type",
|
||||
"print_host",
|
||||
"printhost_apikey",
|
||||
|
|
@ -1363,21 +1365,28 @@ const std::vector<std::string>& PhysicalPrinter::printer_options()
|
|||
return s_opts;
|
||||
}
|
||||
|
||||
const std::string& PhysicalPrinter::get_preset_name()
|
||||
const std::string& PhysicalPrinter::get_preset_name() const
|
||||
{
|
||||
return config.opt_string("preset_name");
|
||||
}
|
||||
|
||||
const std::string& PhysicalPrinter::get_printer_model() const
|
||||
{
|
||||
return config.opt_string("printer_model");
|
||||
}
|
||||
|
||||
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));
|
||||
update_full_name();
|
||||
}
|
||||
|
||||
void PhysicalPrinter::update_from_config(const DynamicPrintConfig& new_config)
|
||||
{
|
||||
config.apply_only(new_config, printer_options(), false);
|
||||
update_full_name();
|
||||
}
|
||||
|
||||
PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) :
|
||||
|
|
@ -1386,6 +1395,24 @@ PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset)
|
|||
update_from_preset(preset);
|
||||
}
|
||||
|
||||
void PhysicalPrinter::set_name(const std::string& name)
|
||||
{
|
||||
this->name = name;
|
||||
update_full_name();
|
||||
}
|
||||
|
||||
void PhysicalPrinter::update_full_name()
|
||||
{
|
||||
full_name = name + " * " + get_preset_name();
|
||||
}
|
||||
|
||||
std::string PhysicalPrinter::get_short_name(std::string full_name)
|
||||
{
|
||||
int pos = full_name.find_first_of(" * ");
|
||||
boost::erase_tail(full_name, full_name.length() - pos);
|
||||
return full_name;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------
|
||||
// *** PhysicalPrinterCollection ***
|
||||
|
|
@ -1470,6 +1497,7 @@ void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_print
|
|||
// Printer with the same name found.
|
||||
// Overwriting an existing preset.
|
||||
it->config = std::move(edited_printer.config);
|
||||
it->full_name = edited_printer.full_name;
|
||||
}
|
||||
else {
|
||||
// Creating a new printer.
|
||||
|
|
@ -1516,8 +1544,9 @@ bool PhysicalPrinterCollection::delete_selected_printer()
|
|||
return true;
|
||||
}
|
||||
|
||||
PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(const std::string& name)
|
||||
PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(std::string name)
|
||||
{
|
||||
name = PhysicalPrinter::get_short_name(name);
|
||||
auto it = this->find_printer_internal(name);
|
||||
assert(it != m_printers.end());
|
||||
|
||||
|
|
|
|||
|
|
@ -538,20 +538,24 @@ public:
|
|||
PhysicalPrinter() {}
|
||||
PhysicalPrinter(const std::string& name) : name(name){}
|
||||
PhysicalPrinter(const std::string& name, const Preset& preset);
|
||||
void set_name(const std::string &name);
|
||||
void update_full_name();
|
||||
|
||||
// Name of the Physical Printer, usually derived form the file name.
|
||||
std::string name;
|
||||
// Full name of the Physical Printer, included related preset name
|
||||
std::string full_name;
|
||||
// File name of the Physical Printer.
|
||||
std::string file;
|
||||
// Configuration data, loaded from a file, or set from the defaults.
|
||||
DynamicPrintConfig config;
|
||||
|
||||
// Has this profile been loaded?
|
||||
bool loaded = false;
|
||||
|
||||
// Configuration data, loaded from a file, or set from the defaults.
|
||||
DynamicPrintConfig config;
|
||||
|
||||
static const std::vector<std::string>& printer_options();
|
||||
const std::string& get_preset_name();
|
||||
const std::string& get_preset_name() const;
|
||||
const std::string& get_printer_model() const;
|
||||
|
||||
void save() { this->config.save(this->file); }
|
||||
void save_to(const std::string& file_name) const { this->config.save(file_name); }
|
||||
|
|
@ -570,6 +574,9 @@ public:
|
|||
// Sort lexicographically by a preset name. The preset name shall be unique across a single PresetCollection.
|
||||
bool operator<(const PhysicalPrinter& other) const { return this->name < other.name; }
|
||||
|
||||
// get printer name from the full name uncluded preset name
|
||||
static std::string get_short_name(std::string full_name);
|
||||
|
||||
protected:
|
||||
friend class PhysicalPrinterCollection;
|
||||
};
|
||||
|
|
@ -622,10 +629,17 @@ public:
|
|||
size_t get_selected_idx() const { return m_idx_selected; }
|
||||
// Returns the name of the selected preset, or an empty string if no preset is selected.
|
||||
std::string get_selected_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().name; }
|
||||
// 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); }
|
||||
|
||||
// select printer with name and return reference on it
|
||||
PhysicalPrinter& select_printer_by_name(const std::string& name);
|
||||
PhysicalPrinter& select_printer_by_name(std::string name);
|
||||
bool has_selection() const { return m_idx_selected != size_t(-1); }
|
||||
void unselect_printer() { m_idx_selected = size_t(-1); }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue