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

3D.pm « Plater « GUI « Slic3r « lib - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6fa46030a43a692aaac830623b4ccd17d33dafef (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
package Slic3r::GUI::Plater::3D;
use strict;
use warnings;
use utf8;

use List::Util qw();
use Slic3r::Geometry qw();
use Slic3r::Geometry::Clipper qw();
use Wx qw(:misc :pen :brush :sizer :font :cursor wxTAB_TRAVERSAL);
use Wx::Event qw();
use base qw(Slic3r::GUI::3DScene Class::Accessor);

sub new {
    my $class = shift;
    my ($parent, $objects, $model, $print, $config) = @_;
    
    my $self = $class->SUPER::new($parent);
    $self->enable_picking(1);
    $self->enable_moving(1);
    $self->select_by('object');
    $self->drag_by('instance');
    
    $self->{objects}            = $objects;
    $self->{model}              = $model;
    $self->{print}              = $print;
    $self->{config}             = $config;
    $self->{on_select_object}   = sub {};
    $self->{on_instances_moved} = sub {};
    $self->{on_wipe_tower_moved} = sub {};
    
    $self->on_select(sub {
        my ($volume_idx) = @_;
        $self->{on_select_object}->(($volume_idx == -1) ? undef : $self->volumes->[$volume_idx]->object_idx)
            if ($self->{on_select_object});
    });
    $self->on_move(sub {
        my @volume_idxs = @_;
        
        my %done = ();  # prevent moving instances twice
        my $object_moved;
        my $wipe_tower_moved;
        foreach my $volume_idx (@volume_idxs) {
            my $volume = $self->volumes->[$volume_idx];
            my $obj_idx = $volume->object_idx;
            my $instance_idx = $volume->instance_idx;
            next if $done{"${obj_idx}_${instance_idx}"};
            $done{"${obj_idx}_${instance_idx}"} = 1;
            if ($obj_idx < 1000) {
                # Move a regular object.
                my $model_object = $self->{model}->get_object($obj_idx);
                $model_object
                    ->instances->[$instance_idx]
                    ->offset
                    ->translate($volume->origin->x, $volume->origin->y); #))
                $model_object->invalidate_bounding_box;
                $object_moved = 1;
            } elsif ($obj_idx == 1000) {
                # Move a wipe tower proxy.
                $wipe_tower_moved = $volume->origin;
            }
        }
        
        $self->{on_instances_moved}->()
            if $object_moved && $self->{on_instances_moved};
        $self->{on_wipe_tower_moved}->($wipe_tower_moved)
            if $wipe_tower_moved && $self->{on_wipe_tower_moved};
    });
    
    return $self;
}

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

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

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

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

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

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

sub reload_scene {
    my ($self, $force) = @_;

    $self->reset_objects;
    $self->update_bed_size;

    if (! $self->IsShown && ! $force) {
        $self->{reload_delayed} = 1;
        return;
    }

    $self->{reload_delayed} = 0;

    foreach my $obj_idx (0..$#{$self->{model}->objects}) {
        my @volume_idxs = $self->load_object($self->{model}, $self->{print}, $obj_idx);
        if ($self->{objects}[$obj_idx]->selected) {
            $self->select_volume($_) for @volume_idxs;
        }
    }
    if (defined $self->{config}->nozzle_diameter) {
        # Should the wipe tower be visualized?
        my $extruders_count = scalar @{ $self->{config}->nozzle_diameter };
        # Height of a print.
        my $height = $self->{model}->bounding_box->z_max;
        # Show at least a slab.
        $height = 10 if $height < 10;
        if ($extruders_count > 1 && $self->{config}->single_extruder_multi_material && $self->{config}->wipe_tower &&
            ! $self->{config}->complete_objects) {
            $self->volumes->load_wipe_tower_preview(1000, 
                $self->{config}->wipe_tower_x, $self->{config}->wipe_tower_y, 
                $self->{config}->wipe_tower_width, $self->{config}->wipe_tower_per_color_wipe * ($extruders_count - 1),
                $self->{model}->bounding_box->z_max, $self->UseVBOs);
        }
    }
}

sub update_bed_size {
    my ($self) = @_;
    $self->set_bed_shape($self->{config}->bed_shape);
}

# Called by the Platter wxNotebook when this page is activated.
sub OnActivate {
    my ($self) = @_;
    $self->reload_scene(1) if ($self->{reload_delayed});
}

1;