mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-03 19:20:38 +08:00
CLI: Improved read of data
+ implemented CLI_DynamicPrintConfig as DynamicPrintConfig with info about type of cli config and related config_def and overridden handle_legacy().
This commit is contained in:
parent
e88ec2d62d
commit
1f55b1ad79
@ -3,8 +3,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "CLI_DynamicPrintConfig.hpp"
|
||||
|
||||
#ifdef SLIC3R_GUI
|
||||
#include "slic3r/GUI/GUI_Init.hpp"
|
||||
@ -15,16 +15,18 @@ namespace Slic3r::CLI
|
||||
// struct which is filled from comand line input
|
||||
struct Data
|
||||
{
|
||||
DynamicPrintConfig input_config;
|
||||
DynamicPrintConfig overrides_config;
|
||||
DynamicPrintConfig transform_config;
|
||||
DynamicPrintConfig misc_config;
|
||||
DynamicPrintConfig actions_config;
|
||||
Data();
|
||||
|
||||
CLI_DynamicPrintConfig input_config;
|
||||
CLI_DynamicPrintConfig overrides_config;
|
||||
CLI_DynamicPrintConfig transform_config;
|
||||
CLI_DynamicPrintConfig misc_config;
|
||||
CLI_DynamicPrintConfig actions_config;
|
||||
|
||||
std::vector<std::string> input_files;
|
||||
|
||||
bool empty() {
|
||||
return input_files.empty()
|
||||
return input_files.empty()
|
||||
&& input_config.empty()
|
||||
&& overrides_config.empty()
|
||||
&& transform_config.empty()
|
||||
|
47
src/CLI/CLI_DynamicPrintConfig.hpp
Normal file
47
src/CLI/CLI_DynamicPrintConfig.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
|
||||
namespace Slic3r::CLI
|
||||
{
|
||||
enum class Type
|
||||
{
|
||||
Input,
|
||||
Overrides,
|
||||
Transformations,
|
||||
Misc,
|
||||
Actions,
|
||||
Undef
|
||||
};
|
||||
|
||||
class CLI_DynamicPrintConfig : public DynamicPrintConfig
|
||||
{
|
||||
public:
|
||||
CLI_DynamicPrintConfig() {}
|
||||
CLI_DynamicPrintConfig(Type type, const ConfigDef* config_def) :
|
||||
m_type (type),
|
||||
m_config_def (config_def) {}
|
||||
CLI_DynamicPrintConfig(const CLI_DynamicPrintConfig& other) :
|
||||
DynamicPrintConfig(other),
|
||||
m_type (other.type()),
|
||||
m_config_def (other.def()) {}
|
||||
|
||||
// Overrides ConfigBase::def(). Static configuration definition. Any value stored into this ConfigBase shall have its definition here.
|
||||
const ConfigDef* def() const override { return m_config_def; }
|
||||
|
||||
// Verify whether the opt_key has not been obsoleted or renamed.
|
||||
// Both opt_key and value may be modified by handle_legacy().
|
||||
// If the opt_key is no more valid in this version of Slic3r, opt_key is cleared by handle_legacy().
|
||||
// handle_legacy() is called internally by set_deserialize().
|
||||
void handle_legacy(t_config_option_key& opt_key, std::string& value) const override {
|
||||
if (m_type == Type::Overrides)
|
||||
DynamicPrintConfig::handle_legacy(opt_key, value);
|
||||
}
|
||||
|
||||
Type type() const { return m_type; }
|
||||
|
||||
private:
|
||||
Type m_type { Type::Undef };
|
||||
const ConfigDef* m_config_def { nullptr };
|
||||
};
|
||||
}
|
@ -23,33 +23,55 @@
|
||||
|
||||
namespace Slic3r::CLI {
|
||||
|
||||
enum class Type
|
||||
Data::Data()
|
||||
{
|
||||
Input,
|
||||
Overrides,
|
||||
Transformations,
|
||||
Misc,
|
||||
Actions
|
||||
};
|
||||
input_config = CLI_DynamicPrintConfig(Type::Input, &cli_input_config_def);
|
||||
overrides_config = CLI_DynamicPrintConfig(Type::Overrides, &print_config_def);
|
||||
transform_config = CLI_DynamicPrintConfig(Type::Transformations, &cli_transform_config_def);
|
||||
misc_config = CLI_DynamicPrintConfig(Type::Misc, &cli_misc_config_def);
|
||||
actions_config = CLI_DynamicPrintConfig(Type::Actions, &cli_actions_config_def);
|
||||
}
|
||||
|
||||
using opts_map = std::map<std::string, std::pair<std::string, Type> >;
|
||||
|
||||
static opts_map get_opts_map(const Data& data)
|
||||
{
|
||||
opts_map ret;
|
||||
|
||||
for (const CLI_DynamicPrintConfig* config : { &data.input_config ,
|
||||
&data.overrides_config,
|
||||
&data.transform_config,
|
||||
&data.misc_config ,
|
||||
&data.actions_config })
|
||||
{
|
||||
for (const auto& oit : config->def()->options)
|
||||
for (const std::string& t : oit.second.cli_args(oit.first))
|
||||
ret[t] = { oit.first , config->type()};
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static CLI_DynamicPrintConfig* get_config(Data& data, Type type)
|
||||
{
|
||||
for (CLI_DynamicPrintConfig* config : { &data.input_config ,
|
||||
&data.overrides_config,
|
||||
&data.transform_config,
|
||||
&data.misc_config ,
|
||||
&data.actions_config })
|
||||
{
|
||||
if (type == config->type())
|
||||
return config;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static bool read(Data& data, int argc, const char* const argv[])
|
||||
{
|
||||
// cache the CLI option => opt_key mapping
|
||||
std::map<std::string, std::pair<std::string, Type> > opts;
|
||||
|
||||
std::initializer_list<std::pair<const ConfigDef&, Type>> list = {
|
||||
{ cli_input_config_def, Type::Input},
|
||||
{ print_config_def, Type::Overrides},
|
||||
{ cli_transform_config_def, Type::Transformations},
|
||||
{ cli_misc_config_def, Type::Misc},
|
||||
{ cli_actions_config_def, Type::Actions}
|
||||
};
|
||||
|
||||
for (const auto& [config_def, type] : list) {
|
||||
for (const auto& oit : config_def.options)
|
||||
for (const std::string& t : oit.second.cli_args(oit.first))
|
||||
opts[t] = { oit.first , type };
|
||||
}
|
||||
opts_map opts = get_opts_map(data);
|
||||
|
||||
bool parse_options = true;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
@ -100,33 +122,10 @@ static bool read(Data& data, int argc, const char* const argv[])
|
||||
token = yes_token;
|
||||
}
|
||||
|
||||
//const t_config_option_key& opt_key = it->second.first;
|
||||
//const ConfigOptionDef& optdef = *this->option_def(opt_key);
|
||||
const auto& [opt_key, type] = it->second;
|
||||
const ConfigDef* config_def;
|
||||
DynamicPrintConfig* config;
|
||||
if (type == Type::Input) {
|
||||
config_def = &cli_input_config_def;
|
||||
config = &data.input_config;
|
||||
}
|
||||
else if (type == Type::Transformations) {
|
||||
config_def = &cli_transform_config_def;
|
||||
config = &data.transform_config;
|
||||
}
|
||||
else if(type == Type::Misc) {
|
||||
config_def = &cli_misc_config_def;
|
||||
config = &data.misc_config;
|
||||
}
|
||||
else if(type == Type::Actions) {
|
||||
config_def = &cli_actions_config_def;
|
||||
config = &data.actions_config;
|
||||
}
|
||||
else {
|
||||
config_def = &print_config_def;
|
||||
config = &data.overrides_config;
|
||||
}
|
||||
|
||||
const ConfigOptionDef* optdef = config_def->get(opt_key);
|
||||
CLI_DynamicPrintConfig* config = get_config(data, type);
|
||||
const ConfigOptionDef* optdef = config->option_def(opt_key);
|
||||
assert(optdef);
|
||||
|
||||
// If the option type expects a value and it was not already provided,
|
||||
|
@ -99,6 +99,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/platform/osx/Info.plist.in ${CMAKE_CU
|
||||
set(SLIC3R_CLI_SOURCES
|
||||
PrusaSlicer.hpp
|
||||
CLI/CLI.hpp
|
||||
CLI/CLI_DynamicPrintConfig.hpp
|
||||
CLI/PrintHelp.cpp
|
||||
CLI/Setup.cpp
|
||||
CLI/LoadPrintData.cpp
|
||||
|
Loading…
x
Reference in New Issue
Block a user