mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-07-31 14:52:01 +08:00
Added draft of optionsgroup folder and some initial tests.
This commit is contained in:
parent
662b95b1ca
commit
b6a5d600b3
@ -194,6 +194,7 @@ set(UI_TEST_SOURCES
|
|||||||
${GUI_TESTDIR}/test_field_point3.cpp
|
${GUI_TESTDIR}/test_field_point3.cpp
|
||||||
${GUI_TESTDIR}/test_field_colorpicker.cpp
|
${GUI_TESTDIR}/test_field_colorpicker.cpp
|
||||||
${GUI_TESTDIR}/test_field_slider.cpp
|
${GUI_TESTDIR}/test_field_slider.cpp
|
||||||
|
${GUI_TESTDIR}/test_optionsgroup.cpp
|
||||||
${GUI_TESTDIR}/test_misc_ui.cpp
|
${GUI_TESTDIR}/test_misc_ui.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
70
src/GUI/OptionsGroup.hpp
Normal file
70
src/GUI/OptionsGroup.hpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include "ConfigBase.hpp"
|
||||||
|
#include "Config.hpp"
|
||||||
|
#include "OptionsGroup/Field.hpp"
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
|
class Option;
|
||||||
|
class Line;
|
||||||
|
class OptionsGroup;
|
||||||
|
class ConfigOptionsGroup;
|
||||||
|
|
||||||
|
/// Class to
|
||||||
|
class Option {
|
||||||
|
public:
|
||||||
|
/// TODO: Constructor needs to include a default value
|
||||||
|
/// Reference to the configuration store.
|
||||||
|
ConfigOptionDef& desc;
|
||||||
|
Option(const ConfigOptionType& _type, const ConfigOption& _def) : desc(this->_desc) {
|
||||||
|
desc.type = _type;
|
||||||
|
// set _default to whatever it needs to be based on _type
|
||||||
|
|
||||||
|
|
||||||
|
// set desc default value to our stored one.
|
||||||
|
desc.default_value = _default;
|
||||||
|
}
|
||||||
|
|
||||||
|
// move constructor, owns the Config item.
|
||||||
|
Option(ConfigOptionDef&& remote) : desc(this->_desc), _desc(std::move(remote)) { }
|
||||||
|
|
||||||
|
/// Destructor to take care of the owned default value.
|
||||||
|
~Option() {
|
||||||
|
if (_default != nullptr) delete _default;
|
||||||
|
_default = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// TODO: Represent a sidebar widget
|
||||||
|
void* side_widget {nullptr};
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// Actual configuration store.
|
||||||
|
/// Holds important information related to this configuration item.
|
||||||
|
ConfigOptionDef _desc;
|
||||||
|
|
||||||
|
/// default value, passed into _desc on construction.
|
||||||
|
/// Owns the data.
|
||||||
|
ConfigOption* _default {nullptr};
|
||||||
|
};
|
||||||
|
|
||||||
|
class OptionsGroup {
|
||||||
|
public:
|
||||||
|
OptionsGroup() {}
|
||||||
|
ConfigOption* get_field(const t_config_option_key& opt_id) { return nullptr; }
|
||||||
|
protected:
|
||||||
|
std::map<t_config_option_key, std::unique_ptr<Option>> _options;
|
||||||
|
std::map<t_config_option_key, std::unique_ptr<UI_Field>> _fields;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ConfigOptionsGroup : public OptionsGroup {
|
||||||
|
public:
|
||||||
|
|
||||||
|
std::shared_ptr<Slic3r::Config> config;
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}} // namespace Slic3r::GUI
|
29
src/test/GUI/test_optionsgroup.cpp
Normal file
29
src/test/GUI/test_optionsgroup.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <catch.hpp>
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/app.h"
|
||||||
|
#include "wx/sizer.h"
|
||||||
|
#include "wx/uiaction.h"
|
||||||
|
#endif // WX_PRECOMP
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "OptionsGroup.hpp"
|
||||||
|
#include "ConfigBase.hpp"
|
||||||
|
#include "Config.hpp"
|
||||||
|
|
||||||
|
using namespace Slic3r::GUI;
|
||||||
|
|
||||||
|
SCENARIO("OptionsGroup: Construction.") {
|
||||||
|
}
|
||||||
|
SCENARIO("ConfigOptionsGroup: Factory methods") {
|
||||||
|
GIVEN("A default Slic3r config") {
|
||||||
|
OptionsGroup optgroup;
|
||||||
|
WHEN("add_single_option is called for avoid_crossing_perimeters") {
|
||||||
|
THEN("a UI_Checkbox is added to the field map") {
|
||||||
|
REQUIRE(optgroup.get_field("avoid_crossing_perimeters") != nullptr);
|
||||||
|
}
|
||||||
|
THEN("a ConfigOptionBool is added to the option map") {
|
||||||
|
REQUIRE(optgroup.get_field("avoid_crossing_perimeters") != nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user