Store object and volume names in the new 'name' property instead of relying on material id
This commit is contained in:
parent
f590bbb430
commit
aacc01a56f
@ -56,6 +56,9 @@ sub write_file {
|
|||||||
foreach my $opt_key (@{$config->get_keys}) {
|
foreach my $opt_key (@{$config->get_keys}) {
|
||||||
printf $fh qq{ <metadata type=\"slic3r.%s\">%s</metadata>\n}, $opt_key, $config->serialize($opt_key);
|
printf $fh qq{ <metadata type=\"slic3r.%s\">%s</metadata>\n}, $opt_key, $config->serialize($opt_key);
|
||||||
}
|
}
|
||||||
|
if ($object->name) {
|
||||||
|
printf $fh qq{ <metadata type=\"name\">%s</metadata>\n}, $object->name;
|
||||||
|
}
|
||||||
|
|
||||||
printf $fh qq{ <mesh>\n};
|
printf $fh qq{ <mesh>\n};
|
||||||
printf $fh qq{ <vertices>\n};
|
printf $fh qq{ <vertices>\n};
|
||||||
@ -81,12 +84,15 @@ sub write_file {
|
|||||||
foreach my $volume (@{ $object->volumes }) {
|
foreach my $volume (@{ $object->volumes }) {
|
||||||
my $vertices_offset = shift @vertices_offset;
|
my $vertices_offset = shift @vertices_offset;
|
||||||
printf $fh qq{ <volume%s>\n},
|
printf $fh qq{ <volume%s>\n},
|
||||||
(!defined $volume->material_id) ? '' : (sprintf ' materialid="%s"', $volume->material_id);
|
($volume->material_id eq '') ? '' : (sprintf ' materialid="%s"', $volume->material_id);
|
||||||
|
|
||||||
my $config = $volume->config;
|
my $config = $volume->config;
|
||||||
foreach my $opt_key (@{$config->get_keys}) {
|
foreach my $opt_key (@{$config->get_keys}) {
|
||||||
printf $fh qq{ <metadata type=\"slic3r.%s\">%s</metadata>\n}, $opt_key, $config->serialize($opt_key);
|
printf $fh qq{ <metadata type=\"slic3r.%s\">%s</metadata>\n}, $opt_key, $config->serialize($opt_key);
|
||||||
}
|
}
|
||||||
|
if ($volume->name) {
|
||||||
|
printf $fh qq{ <metadata type=\"name\">%s</metadata>\n}, $volume->name;
|
||||||
|
}
|
||||||
if ($volume->modifier) {
|
if ($volume->modifier) {
|
||||||
printf $fh qq{ <metadata type=\"slic3r.modifier\">1</metadata>\n};
|
printf $fh qq{ <metadata type=\"slic3r.modifier\">1</metadata>\n};
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,10 @@ sub end_element {
|
|||||||
} elsif ($opt_key eq 'modifier' && $self->{_volume}) {
|
} elsif ($opt_key eq 'modifier' && $self->{_volume}) {
|
||||||
$self->{_volume}->set_modifier($value);
|
$self->{_volume}->set_modifier($value);
|
||||||
}
|
}
|
||||||
|
} elsif ($self->{_metadata_type} eq 'name' && $self->{_volume}) {
|
||||||
|
$self->{_volume}->set_name($value);
|
||||||
|
} elsif ($self->{_metadata_type} eq 'name' && $self->{_object}) {
|
||||||
|
$self->{_object}->set_name($value);
|
||||||
} elsif ($self->{_material}) {
|
} elsif ($self->{_material}) {
|
||||||
$self->{_material}->set_attribute($self->{_metadata_type}, $value);
|
$self->{_material}->set_attribute($self->{_metadata_type}, $value);
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,9 @@ sub read_file {
|
|||||||
|
|
||||||
my $model = Slic3r::Model->new;
|
my $model = Slic3r::Model->new;
|
||||||
|
|
||||||
my $material_id = basename($file);
|
my $basename = basename($file);
|
||||||
$model->set_material($material_id);
|
my $object = $model->add_object(input_file => $file, name => $basename);
|
||||||
|
my $volume = $object->add_volume(mesh => $mesh, name => $basename);
|
||||||
my $object = $model->add_object;
|
|
||||||
my $volume = $object->add_volume(mesh => $mesh, material_id => $material_id);
|
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,10 +16,9 @@ sub read_file {
|
|||||||
|
|
||||||
my $model = Slic3r::Model->new;
|
my $model = Slic3r::Model->new;
|
||||||
|
|
||||||
my $material_id = basename($file);
|
my $basename = basename($file);
|
||||||
$model->set_material($material_id);
|
my $object = $model->add_object(input_file => $file, name => $basename);
|
||||||
my $object = $model->add_object;
|
my $volume = $object->add_volume(mesh => $mesh, name => $basename);
|
||||||
my $volume = $object->add_volume(mesh => $mesh, material_id => $material_id);
|
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,13 +109,8 @@ sub reload_tree {
|
|||||||
foreach my $volume_id (0..$#{$object->volumes}) {
|
foreach my $volume_id (0..$#{$object->volumes}) {
|
||||||
my $volume = $object->volumes->[$volume_id];
|
my $volume = $object->volumes->[$volume_id];
|
||||||
|
|
||||||
my $material_id = $volume->material_id // '_';
|
|
||||||
my $material_name = $material_id eq '_'
|
|
||||||
? sprintf("Part #%d", $volume_id+1)
|
|
||||||
: $object->model->get_material_name($material_id);
|
|
||||||
|
|
||||||
my $icon = $volume->modifier ? ICON_MODIFIERMESH : ICON_SOLIDMESH;
|
my $icon = $volume->modifier ? ICON_MODIFIERMESH : ICON_SOLIDMESH;
|
||||||
my $itemId = $tree->AppendItem($rootId, $material_name, $icon);
|
my $itemId = $tree->AppendItem($rootId, $volume->name || $volume_id, $icon);
|
||||||
$tree->SetPlData($itemId, {
|
$tree->SetPlData($itemId, {
|
||||||
type => 'volume',
|
type => 'volume',
|
||||||
volume_id => $volume_id,
|
volume_id => $volume_id,
|
||||||
@ -158,7 +153,7 @@ sub selection_changed {
|
|||||||
}
|
}
|
||||||
$self->{btn_delete}->Enable;
|
$self->{btn_delete}->Enable;
|
||||||
|
|
||||||
# attach volume material config to settings panel
|
# attach volume config to settings panel
|
||||||
my $volume = $self->{model_object}->volumes->[ $itemData->{volume_id} ];
|
my $volume = $self->{model_object}->volumes->[ $itemData->{volume_id} ];
|
||||||
$config = $volume->config;
|
$config = $volume->config;
|
||||||
$self->{staticbox}->SetLabel('Part Settings');
|
$self->{staticbox}->SetLabel('Part Settings');
|
||||||
@ -208,6 +203,7 @@ sub on_btn_load {
|
|||||||
foreach my $volume (@{$object->volumes}) {
|
foreach my $volume (@{$object->volumes}) {
|
||||||
my $new_volume = $self->{model_object}->add_volume($volume);
|
my $new_volume = $self->{model_object}->add_volume($volume);
|
||||||
$new_volume->set_modifier($is_modifier);
|
$new_volume->set_modifier($is_modifier);
|
||||||
|
$new_volume->set_name(basename($input_file));
|
||||||
|
|
||||||
# apply the same translation we applied to the object
|
# apply the same translation we applied to the object
|
||||||
$new_volume->mesh->translate(@{$self->{model_object}->origin_translation}, 0);
|
$new_volume->mesh->translate(@{$self->{model_object}->origin_translation}, 0);
|
||||||
|
@ -40,6 +40,8 @@ sub add_object {
|
|||||||
|
|
||||||
my $new_object = $self->_add_object;
|
my $new_object = $self->_add_object;
|
||||||
|
|
||||||
|
$new_object->set_name($args{name})
|
||||||
|
if defined $args{name};
|
||||||
$new_object->set_input_file($args{input_file})
|
$new_object->set_input_file($args{input_file})
|
||||||
if defined $args{input_file};
|
if defined $args{input_file};
|
||||||
$new_object->config->apply($args{config})
|
$new_object->config->apply($args{config})
|
||||||
@ -271,7 +273,9 @@ sub split_meshes {
|
|||||||
);
|
);
|
||||||
$new_object->add_volume(
|
$new_object->add_volume(
|
||||||
mesh => $mesh,
|
mesh => $mesh,
|
||||||
|
name => $volume->name,
|
||||||
material_id => $volume->material_id,
|
material_id => $volume->material_id,
|
||||||
|
config => $volume->config,
|
||||||
);
|
);
|
||||||
|
|
||||||
# add one instance per original instance
|
# add one instance per original instance
|
||||||
@ -325,8 +329,7 @@ sub add_volume {
|
|||||||
|
|
||||||
$new_volume = $self->_add_volume_clone($volume);
|
$new_volume = $self->_add_volume_clone($volume);
|
||||||
|
|
||||||
# TODO: material_id can't be undef.
|
if ($volume->material_id ne '') {
|
||||||
if (defined $volume->material_id) {
|
|
||||||
# merge material attributes and config (should we rename materials in case of duplicates?)
|
# merge material attributes and config (should we rename materials in case of duplicates?)
|
||||||
if (my $material = $volume->object->model->get_material($volume->material_id)) {
|
if (my $material = $volume->object->model->get_material($volume->material_id)) {
|
||||||
my %attributes = %{ $material->attributes };
|
my %attributes = %{ $material->attributes };
|
||||||
@ -342,13 +345,17 @@ sub add_volume {
|
|||||||
|
|
||||||
$new_volume = $self->_add_volume($args{mesh});
|
$new_volume = $self->_add_volume($args{mesh});
|
||||||
|
|
||||||
|
$new_volume->set_name($args{name})
|
||||||
|
if defined $args{name};
|
||||||
$new_volume->set_material_id($args{material_id})
|
$new_volume->set_material_id($args{material_id})
|
||||||
if defined $args{material_id};
|
if defined $args{material_id};
|
||||||
$new_volume->set_modifier($args{modifier})
|
$new_volume->set_modifier($args{modifier})
|
||||||
if defined $args{modifier};
|
if defined $args{modifier};
|
||||||
|
$new_volume->config->apply($args{config})
|
||||||
|
if defined $args{config};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined $new_volume->material_id && !defined $self->model->get_material($new_volume->material_id)) {
|
if ($new_volume->material_id ne '' && !defined $self->model->get_material($new_volume->material_id)) {
|
||||||
# TODO: this should be a trigger on Volume::material_id
|
# TODO: this should be a trigger on Volume::material_id
|
||||||
$self->model->set_material($new_volume->material_id);
|
$self->model->set_material($new_volume->material_id);
|
||||||
}
|
}
|
||||||
@ -607,16 +614,20 @@ sub cut {
|
|||||||
|
|
||||||
if ($upper_mesh->facets_count > 0) {
|
if ($upper_mesh->facets_count > 0) {
|
||||||
$upper->add_volume(
|
$upper->add_volume(
|
||||||
|
name => $volume->name,
|
||||||
material_id => $volume->material_id,
|
material_id => $volume->material_id,
|
||||||
mesh => $upper_mesh,
|
mesh => $upper_mesh,
|
||||||
modifier => $volume->modifier,
|
modifier => $volume->modifier,
|
||||||
|
config => $volume->config,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($lower_mesh->facets_count > 0) {
|
if ($lower_mesh->facets_count > 0) {
|
||||||
$lower->add_volume(
|
$lower->add_volume(
|
||||||
|
name => $volume->name,
|
||||||
material_id => $volume->material_id,
|
material_id => $volume->material_id,
|
||||||
mesh => $lower_mesh,
|
mesh => $lower_mesh,
|
||||||
modifier => $volume->modifier,
|
modifier => $volume->modifier,
|
||||||
|
config => $volume->config,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ sub apply_config {
|
|||||||
$model_object_config->normalize;
|
$model_object_config->normalize;
|
||||||
$new->apply_dynamic($model_object_config);
|
$new->apply_dynamic($model_object_config);
|
||||||
}
|
}
|
||||||
if (defined $volume->material_id) {
|
if ($volume->material_id ne '') {
|
||||||
my $material_config = $object->model_object->model->get_material($volume->material_id)->config->clone;
|
my $material_config = $object->model_object->model->get_material($volume->material_id)->config->clone;
|
||||||
$material_config->normalize;
|
$material_config->normalize;
|
||||||
$new->apply_dynamic($material_config);
|
$new->apply_dynamic($material_config);
|
||||||
@ -190,7 +190,7 @@ sub add_model_object {
|
|||||||
$config->apply_dynamic($object_config);
|
$config->apply_dynamic($object_config);
|
||||||
$config->apply_dynamic($volume->config);
|
$config->apply_dynamic($volume->config);
|
||||||
|
|
||||||
if (defined $volume->material_id) {
|
if ($volume->material_id ne '') {
|
||||||
my $material_config = $volume->material->config->clone;
|
my $material_config = $volume->material->config->clone;
|
||||||
$material_config->normalize;
|
$material_config->normalize;
|
||||||
$config->apply_dynamic($material_config);
|
$config->apply_dynamic($material_config);
|
||||||
@ -1045,7 +1045,7 @@ sub auto_assign_extruders {
|
|||||||
my $extruders = scalar @{ $self->config->nozzle_diameter };
|
my $extruders = scalar @{ $self->config->nozzle_diameter };
|
||||||
foreach my $i (0..$#{$model_object->volumes}) {
|
foreach my $i (0..$#{$model_object->volumes}) {
|
||||||
my $volume = $model_object->volumes->[$i];
|
my $volume = $model_object->volumes->[$i];
|
||||||
if (defined $volume->material_id) {
|
if ($volume->material_id ne '') {
|
||||||
my $material = $model_object->model->get_material($volume->material_id);
|
my $material = $model_object->model->get_material($volume->material_id);
|
||||||
my $config = $material->config;
|
my $config = $material->config;
|
||||||
my $extruder_id = $i + 1;
|
my $extruder_id = $i + 1;
|
||||||
|
@ -186,6 +186,7 @@ ModelObject::ModelObject(Model *model)
|
|||||||
|
|
||||||
ModelObject::ModelObject(Model *model, const ModelObject &other)
|
ModelObject::ModelObject(Model *model, const ModelObject &other)
|
||||||
: model(model),
|
: model(model),
|
||||||
|
name(other.name),
|
||||||
input_file(other.input_file),
|
input_file(other.input_file),
|
||||||
instances(),
|
instances(),
|
||||||
volumes(),
|
volumes(),
|
||||||
@ -321,7 +322,8 @@ ModelVolume::ModelVolume(ModelObject* object, const TriangleMesh &mesh)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
ModelVolume::ModelVolume(ModelObject* object, const ModelVolume &other)
|
ModelVolume::ModelVolume(ModelObject* object, const ModelVolume &other)
|
||||||
: object(object), mesh(other.mesh), config(other.config), modifier(other.modifier)
|
: object(object), name(other.name), mesh(other.mesh), config(other.config),
|
||||||
|
modifier(other.modifier)
|
||||||
{
|
{
|
||||||
this->material_id(other.material_id());
|
this->material_id(other.material_id());
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,7 @@ class ModelObject
|
|||||||
{
|
{
|
||||||
friend class Model;
|
friend class Model;
|
||||||
public:
|
public:
|
||||||
|
std::string name;
|
||||||
std::string input_file;
|
std::string input_file;
|
||||||
ModelInstancePtrs instances;
|
ModelInstancePtrs instances;
|
||||||
ModelVolumePtrs volumes;
|
ModelVolumePtrs volumes;
|
||||||
@ -138,6 +139,7 @@ class ModelVolume
|
|||||||
{
|
{
|
||||||
friend class ModelObject;
|
friend class ModelObject;
|
||||||
public:
|
public:
|
||||||
|
std::string name;
|
||||||
TriangleMesh mesh;
|
TriangleMesh mesh;
|
||||||
DynamicPrintConfig config;
|
DynamicPrintConfig config;
|
||||||
bool modifier;
|
bool modifier;
|
||||||
|
@ -136,6 +136,10 @@ ModelMaterial::attributes()
|
|||||||
int instances_count()
|
int instances_count()
|
||||||
%code%{ RETVAL = THIS->instances.size(); %};
|
%code%{ RETVAL = THIS->instances.size(); %};
|
||||||
|
|
||||||
|
std::string name()
|
||||||
|
%code%{ RETVAL = THIS->name; %};
|
||||||
|
void set_name(std::string value)
|
||||||
|
%code%{ THIS->name = value; %};
|
||||||
std::string input_file()
|
std::string input_file()
|
||||||
%code%{ RETVAL = THIS->input_file; %};
|
%code%{ RETVAL = THIS->input_file; %};
|
||||||
void set_input_file(std::string value)
|
void set_input_file(std::string value)
|
||||||
@ -162,6 +166,10 @@ ModelMaterial::attributes()
|
|||||||
Ref<ModelObject> object()
|
Ref<ModelObject> object()
|
||||||
%code%{ RETVAL = THIS->get_object(); %};
|
%code%{ RETVAL = THIS->get_object(); %};
|
||||||
|
|
||||||
|
std::string name()
|
||||||
|
%code%{ RETVAL = THIS->name; %};
|
||||||
|
void set_name(std::string value)
|
||||||
|
%code%{ THIS->name = value; %};
|
||||||
t_model_material_id material_id();
|
t_model_material_id material_id();
|
||||||
void set_material_id(t_model_material_id material_id)
|
void set_material_id(t_model_material_id material_id)
|
||||||
%code%{ THIS->material_id(material_id); %};
|
%code%{ THIS->material_id(material_id); %};
|
||||||
|
Loading…
Reference in New Issue
Block a user