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

SimpleTab.pm « GUI « Slic3r « lib - github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 888ff0e9ba40b7f129cc53104920662342991f4e (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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
package Slic3r::GUI::SimpleTab;
use strict;
use warnings;
use utf8;

use File::Basename qw(basename);
use List::Util qw(first);
use Wx qw(:bookctrl :dialog :keycode :icon :id :misc :panel :sizer :window :systemsettings);
use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN);
use base 'Wx::ScrolledWindow';

sub new {
    my $class = shift;
    my ($parent, %params) = @_;
    my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
    
    $self->SetScrollbars(1, 1, 1, 1);
    
    $self->{config} = Slic3r::Config->new;
    $self->{optgroups} = [];
    
    $self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
    $self->SetSizer($self->{vsizer});
    $self->build;
    $self->_update;
    
    {
        my $label = Wx::StaticText->new($self, -1, "Want more options? Switch to the Expert Mode.", wxDefaultPosition, wxDefaultSize);
        $label->SetFont(Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
        $self->{vsizer}->Add($label, 0, wxEXPAND | wxALL, 10);
    }
    
    return $self;
}

sub init_config_options {
    my ($self, @opt_keys) = @_;
    $self->{config}->apply(Slic3r::Config->new_from_defaults(@opt_keys));
}

sub new_optgroup {
    my ($self, $title, %params) = @_;
    
    my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
        parent          => $self,
        title           => $title,
        config          => $self->{config},
        label_width     => $params{label_width} // 200,
        on_change       => sub { $self->_on_value_change(@_) },
    );
    
    push @{$self->{optgroups}}, $optgroup;
    $self->{vsizer}->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10);
    
    return $optgroup;
}

sub load_config_file {
    my $self = shift;
    my ($file) = @_;
    
    my $config = Slic3r::Config->load($file);
    $self->load_config($config);
}

sub load_config {
    my $self = shift;
    my ($config) = @_;
    
    foreach my $opt_key (@{$self->{config}->get_keys}) {
        next unless $config->has($opt_key);
        $self->{config}->set($opt_key, $config->get($opt_key));
    }
    $_->reload_config for @{$self->{optgroups}};
    $self->_update;
}

sub load_presets {}

sub is_dirty { 0 }
sub config { $_[0]->{config}->clone }
sub _update {}

sub on_value_change {
    my ($self, $cb) = @_;
    $self->{on_value_change} = $cb;
}

sub on_presets_changed {}

# propagate event to the parent
sub _on_value_change {
    my $self = shift;
    
    $self->{on_value_change}->(@_) if $self->{on_value_change};
    $self->_update;
}

sub get_field {
    my ($self, $opt_key, $opt_index) = @_;
    
    foreach my $optgroup (@{ $self->{optgroups} }) {
        my $field = $optgroup->get_fieldc($opt_key, $opt_index);
        return $field if defined $field;
    }
    return undef;
}

package Slic3r::GUI::SimpleTab::Print;
use base 'Slic3r::GUI::SimpleTab';

use Wx qw(:sizer);

sub name { 'print' }
sub title { 'Print Settings' }

sub build {
    my $self = shift;
    
    $self->init_config_options(qw(
        layer_height perimeters top_solid_layers bottom_solid_layers 
        fill_density fill_pattern external_fill_pattern
        support_material support_material_spacing raft_layers
        support_material_contact_distance dont_support_bridges
        perimeter_speed infill_speed travel_speed
        brim_width
        xy_size_compensation
    ));
    
    {
        my $optgroup = $self->new_optgroup('General');
        $optgroup->append_single_option_line('layer_height');
        $optgroup->append_single_option_line('perimeters');
        
        my $line = Slic3r::GUI::OptionsGroup::Line->new(
            label => 'Solid layers',
        );
        $line->append_option($optgroup->get_option('top_solid_layers'));
        $line->append_option($optgroup->get_option('bottom_solid_layers'));
        $optgroup->append_line($line);
    }
    
    {
        my $optgroup = $self->new_optgroup('Infill');
        $optgroup->append_single_option_line('fill_density');
        $optgroup->append_single_option_line('fill_pattern');
        $optgroup->append_single_option_line('external_fill_pattern');
    }
    
    {
        my $optgroup = $self->new_optgroup('Support material');
        $optgroup->append_single_option_line('support_material');
        $optgroup->append_single_option_line('support_material_spacing');
        $optgroup->append_single_option_line('support_material_contact_distance');
        $optgroup->append_single_option_line('dont_support_bridges');
        $optgroup->append_single_option_line('raft_layers');
    }
    
    {
        my $optgroup = $self->new_optgroup('Speed');
        $optgroup->append_single_option_line('perimeter_speed');
        $optgroup->append_single_option_line('infill_speed');
        $optgroup->append_single_option_line('travel_speed');
    }
    
    {
        my $optgroup = $self->new_optgroup('Brim');
        $optgroup->append_single_option_line('brim_width');
    }
    
    {
        my $optgroup = $self->new_optgroup('Other');
        $optgroup->append_single_option_line('xy_size_compensation');
    }
}

sub _update {
    my ($self) = @_;
    
    my $config = $self->{config};
    
    my $have_perimeters = $config->perimeters > 0;
    $self->get_field($_)->toggle($have_perimeters)
        for qw(perimeter_speed);
    
    my $have_infill = $config->fill_density > 0;
    my $have_solid_infill = $config->top_solid_layers > 0 || $config->bottom_solid_layers > 0;
    $self->get_field($_)->toggle($have_infill)
        for qw(fill_pattern);
    $self->get_field($_)->toggle($have_solid_infill)
        for qw(external_fill_pattern);
    $self->get_field($_)->toggle($have_infill || $have_solid_infill)
        for qw(infill_speed);
    
    my $have_support_material = $config->support_material || $config->raft_layers > 0;
    $self->get_field($_)->toggle($have_support_material)
        for qw(support_material_spacing dont_support_bridges
            support_material_contact_distance);
}

package Slic3r::GUI::SimpleTab::Filament;
use base 'Slic3r::GUI::SimpleTab';

sub name { 'filament' }
sub title { 'Filament Settings' }

sub build {
    my $self = shift;
    
    $self->init_config_options(qw(
        filament_diameter extrusion_multiplier
        temperature first_layer_temperature bed_temperature first_layer_bed_temperature
    ));
    
    {
        my $optgroup = $self->new_optgroup('Filament');
        $optgroup->append_single_option_line('filament_diameter', 0);
        $optgroup->append_single_option_line('extrusion_multiplier', 0);
    }
    
    {
        my $optgroup = $self->new_optgroup('Temperature (°C)');
        
        {
            my $line = Slic3r::GUI::OptionsGroup::Line->new(
                label => 'Extruder',
            );
            $line->append_option($optgroup->get_option('first_layer_temperature', 0));
            $line->append_option($optgroup->get_option('temperature', 0));
            $optgroup->append_line($line);
        }
        
        {
            my $line = Slic3r::GUI::OptionsGroup::Line->new(
                label => 'Bed',
            );
            $line->append_option($optgroup->get_option('first_layer_bed_temperature'));
            $line->append_option($optgroup->get_option('bed_temperature'));
            $optgroup->append_line($line);
        }
    }
}

package Slic3r::GUI::SimpleTab::Printer;
use base 'Slic3r::GUI::SimpleTab';
use Wx qw(:sizer :button :bitmap :misc :id);
use Wx::Event qw(EVT_BUTTON);

sub name { 'printer' }
sub title { 'Printer Settings' }

sub build {
    my $self = shift;
    
    $self->init_config_options(qw(
        bed_shape
        z_offset
        gcode_flavor
        nozzle_diameter
        retract_length retract_lift wipe
        start_gcode
        end_gcode
    ));
    
    {
        my $bed_shape_widget = sub {
            my ($parent) = @_;
        
            my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
            $btn->SetFont($Slic3r::GUI::small_font);
            if ($Slic3r::GUI::have_button_icons) {
                $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG));
            }
        
            my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
            $sizer->Add($btn);
        
            EVT_BUTTON($self, $btn, sub {
                my $dlg = Slic3r::GUI::BedShapeDialog->new($self, $self->{config}->bed_shape);
                if ($dlg->ShowModal == wxID_OK) {
                    my $value = $dlg->GetValue;
                    $self->{config}->set('bed_shape', $value);
                    $self->_on_value_change('bed_shape', $value);
                }
            });
        
            return $sizer;
        };
    
        my $optgroup = $self->new_optgroup('Size and coordinates');
        my $line = Slic3r::GUI::OptionsGroup::Line->new(
            label       => 'Bed shape',
            widget      => $bed_shape_widget,
        );
        $optgroup->append_line($line);
        $optgroup->append_single_option_line('z_offset');
    }
    
    {
        my $optgroup = $self->new_optgroup('Firmware');
        $optgroup->append_single_option_line('gcode_flavor');
    }
    
    {
        my $optgroup = $self->new_optgroup('Extruder');
        $optgroup->append_single_option_line('nozzle_diameter', 0);
    }
    
    {
        my $optgroup = $self->new_optgroup('Retraction');
        $optgroup->append_single_option_line('retract_length', 0);
        $optgroup->append_single_option_line('retract_lift', 0);
        $optgroup->append_single_option_line('wipe', 0);
    }
    
    {
        my $optgroup = $self->new_optgroup('Start G-code',
            label_width => 0,
        );
        my $option = $optgroup->get_option('start_gcode');
        $option->full_width(1);
        $option->height(150);
        $optgroup->append_single_option_line($option);
    }
    
    {
        my $optgroup = $self->new_optgroup('End G-code',
            label_width => 0,
        );
        my $option = $optgroup->get_option('end_gcode');
        $option->full_width(1);
        $option->height(150);
        $optgroup->append_single_option_line($option);
    }
}

sub _update {
    my ($self) = @_;
    
    my $config = $self->{config};
    
    my $have_retraction = $config->retract_length->[0] > 0;
    $self->get_field($_, 0)->toggle($have_retraction)
        for qw(retract_lift wipe);
}

1;