ExtrusionEntityCollection.xsp 4.1 KB

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