ExtrusionEntityCollection.xsp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. %code{% THIS->entities.clear(); %};
  14. ExtrusionEntityCollection* chained_path(bool no_reverse)
  15. %code{%
  16. RETVAL = new ExtrusionEntityCollection();
  17. THIS->chained_path(RETVAL, no_reverse);
  18. %};
  19. ExtrusionEntityCollection* chained_path_from(Point* start_near, bool no_reverse)
  20. %code{%
  21. RETVAL = new ExtrusionEntityCollection();
  22. THIS->chained_path_from(*start_near, RETVAL, no_reverse);
  23. %};
  24. Clone<Point> first_point();
  25. Clone<Point> last_point();
  26. int count()
  27. %code{% RETVAL = THIS->entities.size(); %};
  28. int items_count()
  29. %code{% RETVAL = THIS->items_count(); %};
  30. ExtrusionEntityCollection* flatten()
  31. %code{%
  32. RETVAL = new ExtrusionEntityCollection();
  33. THIS->flatten(RETVAL);
  34. %};
  35. double min_mm3_per_mm();
  36. bool empty()
  37. %code{% RETVAL = THIS->entities.empty(); %};
  38. std::vector<size_t> orig_indices()
  39. %code{% RETVAL = THIS->orig_indices; %};
  40. Polygons grow();
  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 (ExtrusionLoop* loop = dynamic_cast<ExtrusionLoop*>(*it)) {
  54. sv_setref_pv( sv, perl_class_name_ref(loop), loop );
  55. } else if (ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(*it)) {
  56. sv_setref_pv( sv, perl_class_name_ref(collection), collection );
  57. } else {
  58. croak("Unexpected type in ExtrusionEntityCollection");
  59. }
  60. av_store(av, i++, sv);
  61. }
  62. RETVAL = newRV_noinc((SV*)av);
  63. OUTPUT:
  64. RETVAL
  65. void
  66. ExtrusionEntityCollection::append(...)
  67. CODE:
  68. for (unsigned int i = 1; i < items; i++) {
  69. if(!sv_isobject( ST(i) ) || (SvTYPE(SvRV( ST(i) )) != SVt_PVMG)) {
  70. croak("Argument %d is not object", i);
  71. }
  72. ExtrusionEntity* entity = (ExtrusionEntity *)SvIV((SV*)SvRV( ST(i) ));
  73. // append COPIES
  74. if (ExtrusionPath* path = dynamic_cast<ExtrusionPath*>(entity)) {
  75. THIS->entities.push_back( new ExtrusionPath(*path) );
  76. } else if (ExtrusionLoop* loop = dynamic_cast<ExtrusionLoop*>(entity)) {
  77. THIS->entities.push_back( new ExtrusionLoop(*loop) );
  78. } else if(ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(entity)) {
  79. THIS->entities.push_back( collection->clone() );
  80. } else {
  81. croak("Argument %d is of unknown type", i);
  82. }
  83. }
  84. bool
  85. ExtrusionEntityCollection::no_sort(...)
  86. CODE:
  87. if (items > 1) {
  88. THIS->no_sort = SvTRUE(ST(1));
  89. }
  90. RETVAL = THIS->no_sort;
  91. OUTPUT:
  92. RETVAL
  93. ExtrusionEntityCollection*
  94. ExtrusionEntityCollection::chained_path_indices(bool no_reverse)
  95. CODE:
  96. RETVAL = new ExtrusionEntityCollection();
  97. THIS->chained_path(RETVAL, no_reverse, &RETVAL->orig_indices);
  98. OUTPUT:
  99. RETVAL
  100. %}
  101. };