2018-04-06 14:49:33 +00:00
# ifndef slic3r_GUI_ConfigIndex_
# define slic3r_GUI_ConfigIndex_
# include <string>
# include <vector>
2020-02-28 10:13:14 +00:00
# include <boost/filesystem/path.hpp>
2018-04-09 15:03:37 +00:00
2018-12-06 11:52:28 +00:00
# include "libslic3r/FileParserError.hpp"
2019-08-09 15:01:37 +00:00
# include "libslic3r/Semver.hpp"
2018-04-06 14:49:33 +00:00
namespace Slic3r {
namespace GUI {
namespace Config {
// Configuration bundle version.
struct Version
{
// Version of this config.
Semver config_version = Semver : : invalid ( ) ;
// Minimum Slic3r version, for which this config is applicable.
Semver min_slic3r_version = Semver : : zero ( ) ;
// Maximum Slic3r version, for which this config is recommended.
// Slic3r should read older configuration and upgrade to a newer format,
// but likely there has been a better configuration published, using the new features.
Semver max_slic3r_version = Semver : : inf ( ) ;
// Single comment line.
std : : string comment ;
2018-04-13 14:15:30 +00:00
bool is_slic3r_supported ( const Semver & slicer_version ) const ;
2018-04-06 14:49:33 +00:00
bool is_current_slic3r_supported ( ) const ;
2020-02-04 14:24:35 +00:00
bool is_current_slic3r_downgrade ( ) const ;
2018-04-06 14:49:33 +00:00
} ;
// Index of vendor specific config bundle versions and Slic3r compatibilities.
// The index is being downloaded from the internet, also an initial version of the index
// is contained in the Slic3r installation.
//
// The index has a simple format:
//
// min_sic3r_version =
// max_slic3r_version =
// config_version "comment"
// config_version "comment"
// ...
// min_slic3r_version =
// max_slic3r_version =
// config_version comment
// config_version comment
// ...
//
// The min_slic3r_version, max_slic3r_version keys are applied to the config versions below,
// empty slic3r version means an open interval.
class Index
{
public :
2020-02-28 10:13:14 +00:00
typedef std : : vector < Version > : : const_iterator const_iterator ;
2018-04-06 14:49:33 +00:00
// Read a config index file in the simple format described in the Index class comment.
// Throws Slic3r::file_parser_error and the standard std file access exceptions.
2018-04-09 15:03:37 +00:00
size_t load ( const boost : : filesystem : : path & path ) ;
const std : : string & vendor ( ) const { return m_vendor ; }
2018-04-13 12:49:33 +00:00
// Returns version of the index as the highest version of all the configs.
// If there is no config, Semver::zero() is returned.
Semver version ( ) const ;
2018-04-06 14:49:33 +00:00
const_iterator begin ( ) const { return m_configs . begin ( ) ; }
const_iterator end ( ) const { return m_configs . end ( ) ; }
2018-04-12 18:04:48 +00:00
const_iterator find ( const Semver & ver ) const ;
2018-04-06 14:49:33 +00:00
const std : : vector < Version > & configs ( ) const { return m_configs ; }
// Finds a recommended config to be installed for the current Slic3r version.
// Returns configs().end() if such version does not exist in the index. This shall never happen
// if the index is valid.
const_iterator recommended ( ) const ;
2019-12-05 10:04:18 +00:00
// Recommended config for a provided slic3r version. Used when checking for slic3r update (slic3r_version is the old one read out from PrusaSlicer.ini)
const_iterator recommended ( const Semver & slic3r_version ) const ;
2018-04-06 14:49:33 +00:00
2019-06-03 09:31:32 +00:00
// Returns the filesystem path from which this index has originally been loaded
const boost : : filesystem : : path & path ( ) const { return m_path ; }
2018-04-09 15:03:37 +00:00
// Load all vendor specific indices.
// Throws Slic3r::file_parser_error and the standard std file access exceptions.
static std : : vector < Index > load_db ( ) ;
2018-04-06 14:49:33 +00:00
private :
2018-04-09 15:03:37 +00:00
std : : string m_vendor ;
2018-04-06 14:49:33 +00:00
std : : vector < Version > m_configs ;
2019-06-03 09:31:32 +00:00
boost : : filesystem : : path m_path ;
2018-04-06 14:49:33 +00:00
} ;
} // namespace Config
} // namespace GUI
} // namespace Slic3r
# endif /* slic3r_GUI_ConfigIndex_ */