Store object and volume names in the new 'name' property instead of relying on material id

This commit is contained in:
Alessandro Ranellucci 2014-07-12 11:20:57 +02:00
parent f590bbb430
commit aacc01a56f
10 changed files with 50 additions and 24 deletions

View File

@ -56,6 +56,9 @@ sub write_file {
foreach my $opt_key (@{$config->get_keys}) {
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{ <vertices>\n};
@ -81,12 +84,15 @@ sub write_file {
foreach my $volume (@{ $object->volumes }) {
my $vertices_offset = shift @vertices_offset;
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;
foreach my $opt_key (@{$config->get_keys}) {
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) {
printf $fh qq{ <metadata type=\"slic3r.modifier\">1</metadata>\n};
}

View File

@ -114,6 +114,10 @@ sub end_element {
} elsif ($opt_key eq 'modifier' && $self->{_volume}) {
$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}) {
$self->{_material}->set_attribute($self->{_metadata_type}, $value);
}

View File

@ -25,11 +25,9 @@ sub read_file {
my $model = Slic3r::Model->new;
my $material_id = basename($file);
$model->set_material($material_id);
my $object = $model->add_object;
my $volume = $object->add_volume(mesh => $mesh, material_id => $material_id);
my $basename = basename($file);
my $object = $model->add_object(input_file => $file, name => $basename);
my $volume = $object->add_volume(mesh => $mesh, name => $basename);
return $model;
}

View File

@ -16,10 +16,9 @@ sub read_file {
my $model = Slic3r::Model->new;
my $material_id = basename($file);
$model->set_material($material_id);
my $object = $model->add_object;
my $volume = $object->add_volume(mesh => $mesh, material_id => $material_id);
my $basename = basename($file);
my $object = $model->add_object(input_file => $file, name => $basename);
my $volume = $object->add_volume(mesh => $mesh, name => $basename);
return $model;
}

View File

@ -109,13 +109,8 @@ sub reload_tree {
foreach my $volume_id (0..$#{$object->volumes}) {
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 $itemId = $tree->AppendItem($rootId, $material_name, $icon);
my $itemId = $tree->AppendItem($rootId, $volume->name || $volume_id, $icon);
$tree->SetPlData($itemId, {
type => 'volume',
volume_id => $volume_id,
@ -158,7 +153,7 @@ sub selection_changed {
}
$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} ];
$config = $volume->config;
$self->{staticbox}->SetLabel('Part Settings');
@ -208,6 +203,7 @@ sub on_btn_load {
foreach my $volume (@{$object->volumes}) {
my $new_volume = $self->{model_object}->add_volume($volume);
$new_volume->set_modifier($is_modifier);
$new_volume->set_name(basename($input_file));
# apply the same translation we applied to the object
$new_volume->mesh->translate(@{$self->{model_object}->origin_translation}, 0);

View File

@ -40,6 +40,8 @@ sub 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})
if defined $args{input_file};
$new_object->config->apply($args{config})
@ -271,7 +273,9 @@ sub split_meshes {
);
$new_object->add_volume(
mesh => $mesh,
name => $volume->name,
material_id => $volume->material_id,
config => $volume->config,
);
# add one instance per original instance
@ -325,8 +329,7 @@ sub add_volume {
$new_volume = $self->_add_volume_clone($volume);
# TODO: material_id can't be undef.
if (defined $volume->material_id) {
if ($volume->material_id ne '') {
# merge material attributes and config (should we rename materials in case of duplicates?)
if (my $material = $volume->object->model->get_material($volume->material_id)) {
my %attributes = %{ $material->attributes };
@ -342,13 +345,17 @@ sub add_volume {
$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})
if defined $args{material_id};
$new_volume->set_modifier($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
$self->model->set_material($new_volume->material_id);
}
@ -607,16 +614,20 @@ sub cut {
if ($upper_mesh->facets_count > 0) {
$upper->add_volume(
name => $volume->name,
material_id => $volume->material_id,
mesh => $upper_mesh,
modifier => $volume->modifier,
config => $volume->config,
);
}
if ($lower_mesh->facets_count > 0) {
$lower->add_volume(
name => $volume->name,
material_id => $volume->material_id,
mesh => $lower_mesh,
modifier => $volume->modifier,
config => $volume->config,
);
}
}

View File

@ -97,7 +97,7 @@ sub apply_config {
$model_object_config->normalize;
$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;
$material_config->normalize;
$new->apply_dynamic($material_config);
@ -190,7 +190,7 @@ sub add_model_object {
$config->apply_dynamic($object_config);
$config->apply_dynamic($volume->config);
if (defined $volume->material_id) {
if ($volume->material_id ne '') {
my $material_config = $volume->material->config->clone;
$material_config->normalize;
$config->apply_dynamic($material_config);
@ -1045,7 +1045,7 @@ sub auto_assign_extruders {
my $extruders = scalar @{ $self->config->nozzle_diameter };
foreach my $i (0..$#{$model_object->volumes}) {
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 $config = $material->config;
my $extruder_id = $i + 1;

View File

@ -186,6 +186,7 @@ ModelObject::ModelObject(Model *model)
ModelObject::ModelObject(Model *model, const ModelObject &other)
: model(model),
name(other.name),
input_file(other.input_file),
instances(),
volumes(),
@ -321,7 +322,8 @@ ModelVolume::ModelVolume(ModelObject* object, const TriangleMesh &mesh)
{}
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());
}

View File

@ -87,6 +87,7 @@ class ModelObject
{
friend class Model;
public:
std::string name;
std::string input_file;
ModelInstancePtrs instances;
ModelVolumePtrs volumes;
@ -138,6 +139,7 @@ class ModelVolume
{
friend class ModelObject;
public:
std::string name;
TriangleMesh mesh;
DynamicPrintConfig config;
bool modifier;

View File

@ -136,6 +136,10 @@ ModelMaterial::attributes()
int instances_count()
%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()
%code%{ RETVAL = THIS->input_file; %};
void set_input_file(std::string value)
@ -162,6 +166,10 @@ ModelMaterial::attributes()
Ref<ModelObject> 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();
void set_material_id(t_model_material_id material_id)
%code%{ THIS->material_id(material_id); %};