Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LambdaObjectDialog.cpp « GUI « slic3r « src « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d741be7ffa5484fc01e82aeaa4c5f88e186fd7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "LambdaObjectDialog.hpp"

#include <wx/window.h>
#include <wx/button.h>
#include "OptionsGroup.hpp"

namespace Slic3r
{
namespace GUI
{
static wxString dots("…", wxConvUTF8);

LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent,
                                       const wxString type_name):
                                       m_type_name(type_name)
{
	Create(parent, wxID_ANY, _(L("Lambda Object")),
        parent->GetScreenPosition(), wxDefaultSize,
		wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);

	// instead of double dim[3] = { 1.0, 1.0, 1.0 };
	object_parameters.dim[0] = 1.0;
	object_parameters.dim[1] = 1.0;
	object_parameters.dim[2] = 1.0;

	sizer = new wxBoxSizer(wxVERTICAL);

	// modificator options
    if (m_type_name == wxEmptyString) {
        m_modificator_options_book = new wxChoicebook(  this, wxID_ANY, wxDefaultPosition,
                                                        wxDefaultSize, wxCHB_TOP);
        sizer->Add(m_modificator_options_book, 1, wxEXPAND | wxALL, 10);
    }
    else {
        m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
        sizer->Add(m_panel, 1, wxEXPAND | wxALL, 10);
    }

    ConfigOptionDef def;
    def.width = 70;
	auto optgroup = init_modificator_options_page(_(L("Box")));
    if (optgroup){
		optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value){
			int opt_id =	opt_key == "l" ? 0 :
							opt_key == "w" ? 1 : 
							opt_key == "h" ? 2 : -1;
			if (opt_id < 0) return;
			object_parameters.dim[opt_id] = boost::any_cast<double>(value);
		};

		def.type = coFloat;
		def.default_value = new ConfigOptionFloat{ 1.0 };
		def.label = L("L");
		Option option(def, "l");
		optgroup->append_single_option_line(option);
		
		def.label = L("W");
		option = Option(def, "w");
		optgroup->append_single_option_line(option);
		
		def.label = L("H");
		option = Option(def, "h");
		optgroup->append_single_option_line(option);
	}

	optgroup = init_modificator_options_page(_(L("Cylinder")));
	if (optgroup){
		optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value){
			int val = boost::any_cast<int>(value);
			if (opt_key == "cyl_r")
				object_parameters.cyl_r = val;
			else if (opt_key == "cyl_h")
				object_parameters.cyl_h = val;
			else return;
		};

		def.type = coInt;
		def.default_value = new ConfigOptionInt{ 1 };
		def.label = L("Radius");
		auto option = Option(def, "cyl_r");
		optgroup->append_single_option_line(option);

		def.label = L("Height");
		option = Option(def, "cyl_h");
		optgroup->append_single_option_line(option);
    }

	optgroup = init_modificator_options_page(_(L("Sphere")));
	if (optgroup){
		optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value){
			if (opt_key == "sph_rho")
				object_parameters.sph_rho = boost::any_cast<double>(value);
			else return;
		};

		def.type = coFloat;
		def.default_value = new ConfigOptionFloat{ 1.0 };
		def.label = L("Rho");
		auto option = Option(def, "sph_rho");
		optgroup->append_single_option_line(option);
	}

	optgroup = init_modificator_options_page(_(L("Slab")));
	if (optgroup){
		optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value){
			double val = boost::any_cast<double>(value);
			if (opt_key == "slab_z")
				object_parameters.slab_z = val;
			else if (opt_key == "slab_h")
				object_parameters.slab_h = val;
			else return;
		};

		def.type = coFloat;
		def.default_value = new ConfigOptionFloat{ 1.0 };
		def.label = L("H");
		auto option = Option(def, "slab_h");
		optgroup->append_single_option_line(option);

		def.label = L("Initial Z");
		option = Option(def, "slab_z");
		optgroup->append_single_option_line(option);
	}

	Bind(wxEVT_CHOICEBOOK_PAGE_CHANGED, ([this](wxCommandEvent e)
	{
		auto page_idx = m_modificator_options_book->GetSelection();
		if (page_idx < 0) return;
		switch (page_idx)
		{
		case 0:
			object_parameters.type = LambdaTypeBox;
			break;
		case 1:
			object_parameters.type = LambdaTypeCylinder;
			break;
		case 2:
			object_parameters.type = LambdaTypeSphere;
			break;
		case 3:
			object_parameters.type = LambdaTypeSlab;
			break;
		default:
			break;
		}
	}));

	const auto button_sizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL);

	wxButton* btn_OK = static_cast<wxButton*>(FindWindowById(wxID_OK, this));
	btn_OK->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
		// validate user input
		if (!CanClose())return;
		EndModal(wxID_OK);
		Destroy();
	});

	wxButton* btn_CANCEL = static_cast<wxButton*>(FindWindowById(wxID_CANCEL, this));
	btn_CANCEL->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
		// validate user input
		if (!CanClose())return;
		EndModal(wxID_CANCEL);
		Destroy();
	});

	sizer->Add(button_sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10);

	SetSizer(sizer);
	sizer->Fit(this);
	sizer->SetSizeHints(this);
}

// Called from the constructor.
// Create a panel for a rectangular / circular / custom bed shape.
ConfigOptionsGroupShp LambdaObjectDialog::init_modificator_options_page(const wxString& title){
    if (!m_type_name.IsEmpty() && m_type_name != title)
        return nullptr;

    auto panel = m_type_name.IsEmpty() ? new wxPanel(m_modificator_options_book) : m_panel;

	ConfigOptionsGroupShp optgroup;
	optgroup = std::make_shared<ConfigOptionsGroup>(panel, _(L("Add")) + " " +title + " " +dots);
	optgroup->label_width = 100;

	m_optgroups.push_back(optgroup);

    if (m_type_name.IsEmpty()) {
        panel->SetSizerAndFit(optgroup->sizer);
        m_modificator_options_book->AddPage(panel, title);
    }
    else
        panel->SetSizer(optgroup->sizer);

	return optgroup;
}


} //namespace GUI
} //namespace Slic3r