ExtrusionEntityCollection.xsp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. %module{Slic3r::XS};
  2. %{
  3. #include <xsinit.h>
  4. #include "libslic3r/ExtrusionEntityCollection.hpp"
  5. %}
  6. %name{Slic3r::ExtrusionPath::Collection} class ExtrusionEntityCollection {
  7. %name{_new} ExtrusionEntityCollection();
  8. ~ExtrusionEntityCollection();
  9. Clone<ExtrusionEntityCollection> clone()
  10. %code{% RETVAL = THIS->clone(); %};
  11. void reverse();
  12. void clear();
  13. ExtrusionEntityCollection* chained_path(bool no_reverse, ExtrusionRole role = erMixed)
  14. %code{%
  15. RETVAL = new ExtrusionEntityCollection();
  16. THIS->chained_path(RETVAL, no_reverse, role);
  17. %};
  18. ExtrusionEntityCollection* chained_path_from(Point* start_near, bool no_reverse, ExtrusionRole role = erMixed)
  19. %code{%
  20. RETVAL = new ExtrusionEntityCollection();
  21. THIS->chained_path_from(*start_near, RETVAL, no_reverse, role);
  22. %};
  23. Clone<Point> first_point();
  24. Clone<Point> last_point();
  25. int count()
  26. %code{% RETVAL = THIS->entities.size(); %};
  27. int items_count()
  28. %code{% RETVAL = THIS->items_count(); %};
  29. ExtrusionEntityCollection* flatten()
  30. %code{%
  31. RETVAL = new ExtrusionEntityCollection();
  32. THIS->flatten(RETVAL);
  33. %};
  34. double min_mm3_per_mm();
  35. bool empty()
  36. %code{% RETVAL = THIS->entities.empty(); %};
  37. std::vector<size_t> orig_indices()
  38. %code{% RETVAL = THIS->orig_indices; %};
  39. Polygons polygons_covered_by_width();
  40. Polygons polygons_covered_by_spacing();
  41. %{
  42. SV*
  43. ExtrusionEntityCollection::arrayref()
  44. CODE:
  45. AV* av = newAV();
  46. av_fill(av, THIS->entities.size()-1);
  47. int i = 0;
  48. for (ExtrusionEntitiesPtr::iterator it = THIS->entities.begin(); it != THIS->entities.end(); ++it) {
  49. SV* sv = newSV(0);
  50. // return our item by reference
  51. if (ExtrusionPath* path = dynamic_cast<ExtrusionPath*>(*it)) {
  52. sv_setref_pv( sv, perl_class_name_ref(path), path );
  53. } else if (ExtrusionMultiPath* multipath = dynamic_cast<ExtrusionMultiPath*>(*it)) {
  54. sv_setref_pv( sv, perl_class_name_ref(multipath), multipath );
  55. } else if (ExtrusionLoop* loop = dynamic_cast<ExtrusionLoop*>(*it)) {
  56. sv_setref_pv( sv, perl_class_name_ref(loop), loop );
  57. } else if (ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(*it)) {
  58. sv_setref_pv( sv, perl_class_name_ref(collection), collection );
  59. } else {
  60. croak("Unexpected type in ExtrusionEntityCollection");
  61. }
  62. av_store(av, i++, sv);
  63. }
  64. RETVAL = newRV_noinc((SV*)av);
  65. OUTPUT:
  66. RETVAL
  67. void
  68. ExtrusionEntityCollection::append(...)
  69. CODE:
  70. for (unsigned int i = 1; i < items; i++) {
  71. if(!sv_isobject( ST(i) ) || (SvTYPE(SvRV( ST(i) )) != SVt_PVMG)) {
  72. croak("Argument %d is not object", i);
  73. }
  74. ExtrusionEntity* entity = (ExtrusionEntity *)SvIV((SV*)SvRV( ST(i) ));
  75. // append COPIES
  76. if (ExtrusionPath* path = dynamic_cast<ExtrusionPath*>(entity)) {
  77. THIS->entities.push_back( new ExtrusionPath(*path) );
  78. } else if (ExtrusionMultiPath* multipath = dynamic_cast<ExtrusionMultiPath*>(entity)) {
  79. THIS->entities.push_back( new ExtrusionMultiPath(*multipath) );
  80. } else if (ExtrusionLoop* loop = dynamic_cast<ExtrusionLoop*>(entity)) {
  81. THIS->entities.push_back( new ExtrusionLoop(*loop) );
  82. } else if(ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(entity)) {
  83. THIS->entities.push_back( collection->clone() );
  84. } else {
  85. croak("Argument %d is of unknown type", i);
  86. }
  87. }
  88. bool
  89. ExtrusionEntityCollection::no_sort(...)
  90. CODE:
  91. if (items > 1) {
  92. THIS->no_sort = SvTRUE(ST(1));
  93. }
  94. RETVAL = THIS->no_sort;
  95. OUTPUT:
  96. RETVAL
  97. %}
  98. };