1 //Copyright (c) 2018 Ultimaker B.V.
2 //CuraEngine is released under the terms of the AGPLv3 or higher.
3 
4 #ifndef SETTINGS_SETTINGS_H
5 #define SETTINGS_SETTINGS_H
6 
7 #ifndef VERSION
8 #define VERSION "DEV"
9 #endif
10 
11 #define MAX_EXTRUDERS 16
12 
13 //Maximum number of infill layers that can be combined into a single infill extrusion area.
14 #define MAX_INFILL_COMBINE 8
15 
16 #include <vector>
17 #include <map>
18 #include <unordered_map>
19 #include <sstream>
20 
21 namespace cura
22 {
23 
24 /*!
25  * \brief Container for a set of settings.
26  *
27  * You can ask this container for the value of a certain setting that should be
28  * used in the context where this settings container is located.
29  *
30  * Before the settings can be returned, the settings have to be added first
31  * using the add() function.
32  */
33 class Settings
34 {
35 public:
36     /*
37      * \brief Properly initialises the Settings instance.
38      */
39     Settings();
40 
41     /*!
42      * \brief Adds a new setting.
43      * \param key The name by which the setting is identified.
44      * \param value The value of the setting. The value is always added and
45      * stored in serialised form as a string.
46      */
47     void add(const std::string& key, const std::string value);
48 
49     /*!
50      * \brief Get the value of a setting.
51      *
52      * This value is then evaluated using the following technique:
53      *  1. If this container contains a value for the setting, it uses that
54      *     value directly.
55      *  2. Otherwise it checks if the setting is limited to an extruder, and if
56      *     so, takes the setting value from that extruder. It applies the
57      *     limiting only once at most.
58      *  3. Otherwise it asks its parent settings container for the setting value
59      *     and returns that. The parent then goes through the same process. The
60      *     root of this inheritance structure should always have a value for all
61      *     settings.
62      *  4. If a setting is not known at all, an error is returned and the
63      *     application is closed with an error value of 2.
64      * \param key The key of the setting to get.
65      * \return The setting's value, cast to the desired type.
66      */
67     template<typename A> A get(const std::string& key) const;
68 
69     /*!
70      * \brief Get a string containing all settings in this container.
71      *
72      * The string is formatted in the same way as the command line arguments
73      * when slicing using CuraEngine from the command line. In theory you could
74      * put the output of this command in a call to CuraEngine.
75      * \return A string containing all settings and their values.
76      */
77     const std::string getAllSettingsString() const;
78 
79     /*!
80      * \brief Indicate whether this settings instance has an entry for the
81      * specified setting.
82      *
83      * If this returns ``false``, that means that the setting would be obtained
84      * via some inheritance.
85      * \param key The setting to check.
86      * \return Whether that setting is contained in this particular Settings
87      * instance (``true``) or would be obtained via inheritance (``false``).
88      */
89     bool has(const std::string& key) const;
90 
91     /*
92      * Change the parent settings object.
93      *
94      * If this set of settings has no value for a setting, the parent is asked.
95      */
96     void setParent(Settings* new_parent);
97 
98 private:
99     /*!
100      * Optionally, a parent setting container to ask for the value of a setting
101      * if this container has no value for it.
102      */
103     Settings* parent;
104 
105     /*!
106      * \brief A dictionary to map the setting keys to the actual setting values.
107      */
108     std::unordered_map<std::string, std::string> settings;
109 
110     /*!
111      * \brief Get the value of a setting, but without looking at the limiting to
112      * extruder.
113      *
114      * This is the same as the normal ``get`` function, but skipping step 2 and
115      * only for strings.
116      * \param key The key of the setting to get.
117      * \return The setting's value.
118      */
119     std::string getWithoutLimiting(const std::string& key) const;
120 };
121 
122 } //namespace cura
123 
124 #endif //SETTINGS_SETTINGS_H
125 
126