mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-20 23:31:13 -06:00
Finish porting Print classes to XS
This commit is contained in:
parent
ba8148f4ad
commit
3f6360ee8f
10 changed files with 78 additions and 87 deletions
|
@ -62,21 +62,14 @@ PrintRegion::print()
|
|||
return this->_print;
|
||||
}
|
||||
|
||||
PrintConfig &
|
||||
PrintRegion::print_config()
|
||||
{
|
||||
return this->_print->config;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(PrintRegion, "Print::Region");
|
||||
#endif
|
||||
|
||||
|
||||
PrintObject::PrintObject(Print* print, int id, ModelObject* model_object,
|
||||
PrintObject::PrintObject(Print* print, ModelObject* model_object,
|
||||
const BoundingBoxf3 &modobj_bbox)
|
||||
: _print(print),
|
||||
_id(id),
|
||||
_model_object(model_object)
|
||||
{
|
||||
region_volumes.resize(this->_print->regions.size());
|
||||
|
@ -110,12 +103,6 @@ PrintObject::print()
|
|||
return this->_print;
|
||||
}
|
||||
|
||||
int
|
||||
PrintObject::id()
|
||||
{
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
ModelObject*
|
||||
PrintObject::model_object()
|
||||
{
|
||||
|
@ -164,9 +151,8 @@ void
|
|||
PrintObject::delete_layer(int idx)
|
||||
{
|
||||
LayerPtrs::iterator i = this->layers.begin() + idx;
|
||||
Layer* item = *i;
|
||||
delete *i;
|
||||
this->layers.erase(i);
|
||||
delete item;
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@ -201,9 +187,8 @@ void
|
|||
PrintObject::delete_support_layer(int idx)
|
||||
{
|
||||
SupportLayerPtrs::iterator i = this->support_layers.begin() + idx;
|
||||
SupportLayer* item = *i;
|
||||
delete *i;
|
||||
this->support_layers.erase(i);
|
||||
delete item;
|
||||
}
|
||||
|
||||
|
||||
|
@ -237,7 +222,7 @@ Print::clear_objects()
|
|||
}
|
||||
|
||||
PrintObject*
|
||||
Print::get_object(int idx)
|
||||
Print::get_object(size_t idx)
|
||||
{
|
||||
return objects.at(idx);
|
||||
}
|
||||
|
@ -246,33 +231,30 @@ PrintObject*
|
|||
Print::add_object(ModelObject *model_object,
|
||||
const BoundingBoxf3 &modobj_bbox)
|
||||
{
|
||||
PrintObject *object = new PrintObject(this,
|
||||
this->objects.size(), model_object, modobj_bbox);
|
||||
PrintObject *object = new PrintObject(this, model_object, modobj_bbox);
|
||||
objects.push_back(object);
|
||||
return object;
|
||||
}
|
||||
|
||||
PrintObject*
|
||||
Print::set_new_object(size_t idx, ModelObject *model_object,
|
||||
const BoundingBoxf3 &modobj_bbox)
|
||||
Print::set_new_object(size_t idx, ModelObject *model_object, const BoundingBoxf3 &modobj_bbox)
|
||||
{
|
||||
if (idx < 0 || idx >= this->objects.size()) throw "bad idx";
|
||||
|
||||
PrintObjectPtrs::iterator old_it = this->objects.begin() + idx;
|
||||
delete *old_it;
|
||||
|
||||
PrintObject *object = new PrintObject(this, idx, model_object, modobj_bbox);
|
||||
PrintObject *object = new PrintObject(this, model_object, modobj_bbox);
|
||||
this->objects[idx] = object;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
Print::delete_object(int idx)
|
||||
Print::delete_object(size_t idx)
|
||||
{
|
||||
PrintObjectPtrs::iterator i = this->objects.begin() + idx;
|
||||
PrintObject* item = *i;
|
||||
delete *i;
|
||||
this->objects.erase(i);
|
||||
delete item;
|
||||
|
||||
// TODO: purge unused regions
|
||||
|
||||
|
@ -288,7 +270,7 @@ Print::clear_regions()
|
|||
}
|
||||
|
||||
PrintRegion*
|
||||
Print::get_region(int idx)
|
||||
Print::get_region(size_t idx)
|
||||
{
|
||||
return regions.at(idx);
|
||||
}
|
||||
|
@ -302,12 +284,11 @@ Print::add_region()
|
|||
}
|
||||
|
||||
void
|
||||
Print::delete_region(int idx)
|
||||
Print::delete_region(size_t idx)
|
||||
{
|
||||
PrintRegionPtrs::iterator i = this->regions.begin() + idx;
|
||||
PrintRegion* item = *i;
|
||||
delete *i;
|
||||
this->regions.erase(i);
|
||||
delete item;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@ class PrintState
|
|||
void invalidate_all();
|
||||
};
|
||||
|
||||
// TODO: make stuff private
|
||||
|
||||
// A PrintRegion object represents a group of volumes to print
|
||||
// sharing the same config (including the same assigned extruder(s))
|
||||
class PrintRegion
|
||||
|
@ -48,13 +46,12 @@ class PrintRegion
|
|||
PrintRegionConfig config;
|
||||
|
||||
Print* print();
|
||||
PrintConfig &print_config();
|
||||
|
||||
private:
|
||||
Print* _print;
|
||||
|
||||
PrintRegion(Print* print);
|
||||
virtual ~PrintRegion();
|
||||
~PrintRegion();
|
||||
};
|
||||
|
||||
|
||||
|
@ -87,10 +84,8 @@ class PrintObject
|
|||
SupportLayerPtrs support_layers;
|
||||
// TODO: Fill* fill_maker => (is => 'lazy');
|
||||
PrintState _state;
|
||||
|
||||
|
||||
|
||||
Print* print();
|
||||
int id();
|
||||
ModelObject* model_object();
|
||||
|
||||
// adds region_id, too, if necessary
|
||||
|
@ -99,27 +94,23 @@ class PrintObject
|
|||
size_t layer_count();
|
||||
void clear_layers();
|
||||
Layer* get_layer(int idx);
|
||||
Layer* add_layer(int id, coordf_t height, coordf_t print_z,
|
||||
coordf_t slice_z);
|
||||
Layer* add_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z);
|
||||
void delete_layer(int idx);
|
||||
|
||||
size_t support_layer_count();
|
||||
void clear_support_layers();
|
||||
SupportLayer* get_support_layer(int idx);
|
||||
SupportLayer* add_support_layer(int id, coordf_t height, coordf_t print_z,
|
||||
coordf_t slice_z);
|
||||
SupportLayer* add_support_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z);
|
||||
void delete_support_layer(int idx);
|
||||
|
||||
private:
|
||||
Print* _print;
|
||||
int _id;
|
||||
ModelObject* _model_object;
|
||||
|
||||
// TODO: call model_object->get_bounding_box() instead of accepting
|
||||
// parameter
|
||||
PrintObject(Print* print, int id, ModelObject* model_object,
|
||||
const BoundingBoxf3 &modobj_bbox);
|
||||
virtual ~PrintObject();
|
||||
PrintObject(Print* print, ModelObject* model_object, const BoundingBoxf3 &modobj_bbox);
|
||||
~PrintObject();
|
||||
};
|
||||
|
||||
typedef std::vector<PrintObject*> PrintObjectPtrs;
|
||||
|
@ -135,33 +126,29 @@ class Print
|
|||
PrintRegionPtrs regions;
|
||||
PlaceholderParser placeholder_parser;
|
||||
// TODO: status_cb
|
||||
double total_used_filament;
|
||||
double total_extruded_volume;
|
||||
double total_used_filament, total_extruded_volume;
|
||||
PrintState _state;
|
||||
|
||||
// ordered collection of extrusion paths to build skirt loops
|
||||
ExtrusionEntityCollection skirt;
|
||||
|
||||
// ordered collection of extrusion paths to build a brim
|
||||
ExtrusionEntityCollection brim;
|
||||
// ordered collections of extrusion paths to build skirt loops and brim
|
||||
ExtrusionEntityCollection skirt, brim;
|
||||
|
||||
Print();
|
||||
virtual ~Print();
|
||||
|
||||
~Print();
|
||||
|
||||
// methods for handling objects
|
||||
void clear_objects();
|
||||
PrintObject* get_object(int idx);
|
||||
PrintObject* add_object(ModelObject *model_object,
|
||||
const BoundingBoxf3 &modobj_bbox);
|
||||
PrintObject* set_new_object(size_t idx, ModelObject *model_object,
|
||||
const BoundingBoxf3 &modobj_bbox);
|
||||
void delete_object(int idx);
|
||||
PrintObject* get_object(size_t idx);
|
||||
PrintObject* add_object(ModelObject *model_object, const BoundingBoxf3 &modobj_bbox);
|
||||
PrintObject* set_new_object(size_t idx, ModelObject *model_object, const BoundingBoxf3 &modobj_bbox);
|
||||
void delete_object(size_t idx);
|
||||
|
||||
PrintRegion* get_region(int idx);
|
||||
// methods for handling regions
|
||||
PrintRegion* get_region(size_t idx);
|
||||
PrintRegion* add_region();
|
||||
|
||||
private:
|
||||
void clear_regions();
|
||||
void delete_region(int idx);
|
||||
void delete_region(size_t idx);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
18
xs/t/20_print.t
Normal file
18
xs/t/20_print.t
Normal file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 5;
|
||||
|
||||
{
|
||||
my $print = Slic3r::Print->_new;
|
||||
isa_ok $print, 'Slic3r::Print';
|
||||
isa_ok $print->config, 'Slic3r::Config::Print::Ref';
|
||||
isa_ok $print->default_object_config, 'Slic3r::Config::PrintObject::Ref';
|
||||
isa_ok $print->default_region_config, 'Slic3r::Config::PrintRegion::Ref';
|
||||
isa_ok $print->placeholder_parser, 'Slic3r::GCode::PlaceholderParser::Ref';
|
||||
}
|
||||
|
||||
__END__
|
|
@ -48,8 +48,6 @@ _constant()
|
|||
Ref<PrintRegionConfig> config()
|
||||
%code%{ RETVAL = &THIS->config; %};
|
||||
Ref<Print> print();
|
||||
Ref<PrintConfig> print_config()
|
||||
%code%{ RETVAL = &THIS->print_config(); %};
|
||||
};
|
||||
|
||||
|
||||
|
@ -66,7 +64,6 @@ _constant()
|
|||
%code%{ RETVAL = THIS->print()->regions.size(); %};
|
||||
|
||||
Ref<Print> print();
|
||||
int id();
|
||||
Ref<ModelObject> model_object();
|
||||
Ref<PrintObjectConfig> config()
|
||||
%code%{ RETVAL = &THIS->config; %};
|
||||
|
@ -104,6 +101,9 @@ _constant()
|
|||
Ref<SupportLayer> add_support_layer(int id, coordf_t height, coordf_t print_z,
|
||||
coordf_t slice_z);
|
||||
void delete_support_layer(int idx);
|
||||
|
||||
int ptr()
|
||||
%code%{ RETVAL = (int)(intptr_t)THIS; %};
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue