siren2 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +21 -0
  6. data/README.md +36 -0
  7. data/Rakefile +18 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/ext/siren2/extconf.rb +66 -0
  11. data/ext/siren2/inc/bndbox.h +51 -0
  12. data/ext/siren2/inc/bo.h +20 -0
  13. data/ext/siren2/inc/brep.h +17 -0
  14. data/ext/siren2/inc/common.h +98 -0
  15. data/ext/siren2/inc/curve.h +65 -0
  16. data/ext/siren2/inc/curve/bscurve.h +22 -0
  17. data/ext/siren2/inc/curve/bzcurve.h +17 -0
  18. data/ext/siren2/inc/curve/circle.h +29 -0
  19. data/ext/siren2/inc/curve/ellipse.h +15 -0
  20. data/ext/siren2/inc/curve/hyperbola.h +15 -0
  21. data/ext/siren2/inc/curve/line.h +17 -0
  22. data/ext/siren2/inc/curve/offsetcurve.h +15 -0
  23. data/ext/siren2/inc/curve/parabola.h +15 -0
  24. data/ext/siren2/inc/filler.h +26 -0
  25. data/ext/siren2/inc/heal.h +19 -0
  26. data/ext/siren2/inc/io/iges.h +19 -0
  27. data/ext/siren2/inc/io/step.h +18 -0
  28. data/ext/siren2/inc/io/stl.h +13 -0
  29. data/ext/siren2/inc/offset.h +35 -0
  30. data/ext/siren2/inc/shape.h +140 -0
  31. data/ext/siren2/inc/shape/chunk.h +26 -0
  32. data/ext/siren2/inc/shape/compound.h +22 -0
  33. data/ext/siren2/inc/shape/edge.h +50 -0
  34. data/ext/siren2/inc/shape/face.h +67 -0
  35. data/ext/siren2/inc/shape/shell.h +21 -0
  36. data/ext/siren2/inc/shape/solid.h +41 -0
  37. data/ext/siren2/inc/shape/vertex.h +23 -0
  38. data/ext/siren2/inc/shape/wire.h +31 -0
  39. data/ext/siren2/inc/siren.h +39 -0
  40. data/ext/siren2/inc/surface/dummy +0 -0
  41. data/ext/siren2/inc/topalgo.h +52 -0
  42. data/ext/siren2/inc/trans.h +48 -0
  43. data/ext/siren2/inc/vec.h +65 -0
  44. data/ext/siren2/src/bndbox.cpp +343 -0
  45. data/ext/siren2/src/bo.cpp +66 -0
  46. data/ext/siren2/src/brep.cpp +69 -0
  47. data/ext/siren2/src/common.cpp +18 -0
  48. data/ext/siren2/src/curve.cpp +75 -0
  49. data/ext/siren2/src/curve/bscurve.cpp +118 -0
  50. data/ext/siren2/src/curve/bzcurve.cpp +55 -0
  51. data/ext/siren2/src/curve/circle.cpp +146 -0
  52. data/ext/siren2/src/curve/ellipse.cpp +17 -0
  53. data/ext/siren2/src/curve/hyperbola.cpp +17 -0
  54. data/ext/siren2/src/curve/line.cpp +24 -0
  55. data/ext/siren2/src/curve/offsetcurve.cpp +17 -0
  56. data/ext/siren2/src/curve/parabola.cpp +17 -0
  57. data/ext/siren2/src/filler.cpp +191 -0
  58. data/ext/siren2/src/heal.cpp +92 -0
  59. data/ext/siren2/src/io/iges.cpp +85 -0
  60. data/ext/siren2/src/io/step.cpp +47 -0
  61. data/ext/siren2/src/io/stl.cpp +22 -0
  62. data/ext/siren2/src/offset.cpp +256 -0
  63. data/ext/siren2/src/shape.cpp +617 -0
  64. data/ext/siren2/src/shape/chunk.cpp +65 -0
  65. data/ext/siren2/src/shape/compound.cpp +96 -0
  66. data/ext/siren2/src/shape/edge.cpp +254 -0
  67. data/ext/siren2/src/shape/face.cpp +366 -0
  68. data/ext/siren2/src/shape/shell.cpp +41 -0
  69. data/ext/siren2/src/shape/solid.cpp +256 -0
  70. data/ext/siren2/src/shape/vertex.cpp +68 -0
  71. data/ext/siren2/src/shape/wire.cpp +100 -0
  72. data/ext/siren2/src/siren.cpp +80 -0
  73. data/ext/siren2/src/surface/dummy +0 -0
  74. data/ext/siren2/src/topalgo.cpp +246 -0
  75. data/ext/siren2/src/trans.cpp +330 -0
  76. data/ext/siren2/src/vec.cpp +454 -0
  77. data/lib/io/dxf.rb +68 -0
  78. data/lib/io/plot.rb +38 -0
  79. data/lib/io/ply.rb +57 -0
  80. data/lib/io/stl.rb +35 -0
  81. data/lib/io/svg.rb +44 -0
  82. data/lib/kernel/array.rb +133 -0
  83. data/lib/kernel/float.rb +15 -0
  84. data/lib/shape.rb +157 -0
  85. data/lib/shape/compound.rb +11 -0
  86. data/lib/shape/edge.rb +15 -0
  87. data/lib/shape/face.rb +7 -0
  88. data/lib/shape/shell.rb +21 -0
  89. data/lib/shape/solid.rb +10 -0
  90. data/lib/shape/vertex.rb +7 -0
  91. data/lib/shape/wire.rb +14 -0
  92. data/lib/shapes.rb +52 -0
  93. data/lib/siren.rb +166 -0
  94. data/lib/siren2/version.rb +3 -0
  95. data/lib/vec.rb +81 -0
  96. data/siren2.gemspec +28 -0
  97. metadata +195 -0
@@ -0,0 +1,343 @@
1
+ #include "bndbox.h"
2
+
3
+ VALUE sr_cBndBox;
4
+
5
+ Bnd_Box* siren_bndbox_get(VALUE obj)
6
+ {
7
+ Bnd_Box* m;
8
+ Data_Get_Struct(obj, Bnd_Box, m);
9
+ return m;
10
+ }
11
+
12
+ static VALUE siren_bndbox_allocate(VALUE klass)
13
+ {
14
+ void* p = ruby_xmalloc(sizeof(Bnd_Box));
15
+ new(p) Bnd_Box();
16
+ return Data_Wrap_Struct(klass, NULL, siren_bndbox_final, p);
17
+ }
18
+
19
+ bool siren_bndbox_install()
20
+ {
21
+ sr_cBndBox = rb_define_class_under(sr_mSiren, "BndBox", rb_cObject);
22
+ rb_define_alloc_func(sr_cBndBox, siren_bndbox_allocate);
23
+ rb_define_method(sr_cBndBox, "initialize", RUBY_METHOD_FUNC(siren_bndbox_init), -1);
24
+ rb_define_method(sr_cBndBox, "inspect", RUBY_METHOD_FUNC(siren_bndbox_to_s), -1);
25
+ rb_define_method(sr_cBndBox, "to_s", RUBY_METHOD_FUNC(siren_bndbox_to_s), -1);
26
+ rb_define_method(sr_cBndBox, "min", RUBY_METHOD_FUNC(siren_bndbox_min), -1);
27
+ rb_define_method(sr_cBndBox, "max", RUBY_METHOD_FUNC(siren_bndbox_max), -1);
28
+ rb_define_method(sr_cBndBox, "add", RUBY_METHOD_FUNC(siren_bndbox_add), -1);
29
+ rb_define_method(sr_cBndBox, "out?", RUBY_METHOD_FUNC(siren_bndbox_is_out), -1);
30
+ rb_define_method(sr_cBndBox, "center", RUBY_METHOD_FUNC(siren_bndbox_center), -1);
31
+ rb_define_method(sr_cBndBox, "xsize", RUBY_METHOD_FUNC(siren_bndbox_xsize), -1);
32
+ rb_define_method(sr_cBndBox, "ysize", RUBY_METHOD_FUNC(siren_bndbox_ysize), -1);
33
+ rb_define_method(sr_cBndBox, "zsize", RUBY_METHOD_FUNC(siren_bndbox_zsize), -1);
34
+ rb_define_method(sr_cBndBox, "void?", RUBY_METHOD_FUNC(siren_bndbox_is_void), -1);
35
+ rb_define_method(sr_cBndBox, "whole?", RUBY_METHOD_FUNC(siren_bndbox_is_whole), -1);
36
+ rb_define_method(sr_cBndBox, "void!", RUBY_METHOD_FUNC(siren_bndbox_void_bang), -1);
37
+ rb_define_method(sr_cBndBox, "whole!", RUBY_METHOD_FUNC(siren_bndbox_whole_bang), -1);
38
+ rb_define_method(sr_cBndBox, "xthin?", RUBY_METHOD_FUNC(siren_bndbox_is_xthin), -1);
39
+ rb_define_method(sr_cBndBox, "ythin?", RUBY_METHOD_FUNC(siren_bndbox_is_ythin), -1);
40
+ rb_define_method(sr_cBndBox, "zthin?", RUBY_METHOD_FUNC(siren_bndbox_is_zthin), -1);
41
+ rb_define_method(sr_cBndBox, "openxmin?", RUBY_METHOD_FUNC(siren_bndbox_is_openxmin), -1);
42
+ rb_define_method(sr_cBndBox, "openxmax?", RUBY_METHOD_FUNC(siren_bndbox_is_openxmax), -1);
43
+ rb_define_method(sr_cBndBox, "openymin?", RUBY_METHOD_FUNC(siren_bndbox_is_openymin), -1);
44
+ rb_define_method(sr_cBndBox, "openymax?", RUBY_METHOD_FUNC(siren_bndbox_is_openymax), -1);
45
+ rb_define_method(sr_cBndBox, "openzmin?", RUBY_METHOD_FUNC(siren_bndbox_is_openzmin), -1);
46
+ rb_define_method(sr_cBndBox, "openzmax?", RUBY_METHOD_FUNC(siren_bndbox_is_openzmax), -1);
47
+ rb_define_method(sr_cBndBox, "openxmin!", RUBY_METHOD_FUNC(siren_bndbox_openxmin_bang), -1);
48
+ rb_define_method(sr_cBndBox, "openxmax!", RUBY_METHOD_FUNC(siren_bndbox_openxmax_bang), -1);
49
+ rb_define_method(sr_cBndBox, "openymin!", RUBY_METHOD_FUNC(siren_bndbox_openymin_bang), -1);
50
+ rb_define_method(sr_cBndBox, "openymax!", RUBY_METHOD_FUNC(siren_bndbox_openymax_bang), -1);
51
+ rb_define_method(sr_cBndBox, "openzmin!", RUBY_METHOD_FUNC(siren_bndbox_openzmin_bang), -1);
52
+ rb_define_method(sr_cBndBox, "openzmax!", RUBY_METHOD_FUNC(siren_bndbox_openzmax_bang), -1);
53
+ rb_define_method(sr_cBndBox, "gap", RUBY_METHOD_FUNC(siren_bndbox_get_gap), -1);
54
+ rb_define_method(sr_cBndBox, "gap=", RUBY_METHOD_FUNC(siren_bndbox_set_gap), -1);
55
+ rb_define_method(sr_cBndBox, "dist", RUBY_METHOD_FUNC(siren_bndbox_dist), -1);
56
+ rb_define_method(sr_cBndBox, "square", RUBY_METHOD_FUNC(siren_bndbox_square), -1);
57
+ return true;
58
+ }
59
+
60
+ VALUE siren_bndbox_init(int argc, VALUE* argv, VALUE self)
61
+ {
62
+ return self;
63
+ }
64
+
65
+ void siren_bndbox_final(void* p)
66
+ {
67
+ Bnd_Box* pp = static_cast<Bnd_Box*>(p);
68
+ ruby_xfree(pp);
69
+ }
70
+
71
+ VALUE siren_bndbox_to_s(int argc, VALUE* argv, VALUE self)
72
+ {
73
+ Bnd_Box* b = siren_bndbox_get(self);
74
+ char str[128];
75
+ if (b->IsVoid()) {
76
+ snprintf(str, sizeof(str), "#<BndBox:0x%x (void)>", -1 /* (unsigned int)(uintptr_t)rb_cptr(self) */);
77
+ }
78
+ else {
79
+ Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
80
+ b->Get(xmin, ymin, zmin, xmax, ymax, zmax);
81
+ const int s = 16;
82
+ char sxmin[s]; char sxmax[s];
83
+ char symin[s]; char symax[s];
84
+ char szmin[s]; char szmax[s];
85
+ b->IsOpenXmin() ? snprintf(sxmin, s, "%s", "inf") : snprintf(sxmin, s, "%f", xmin);
86
+ b->IsOpenXmax() ? snprintf(sxmax, s, "%s", "inf") : snprintf(sxmax, s, "%f", xmax);
87
+ b->IsOpenYmin() ? snprintf(symin, s, "%s", "inf") : snprintf(symin, s, "%f", ymin);
88
+ b->IsOpenYmax() ? snprintf(symax, s, "%s", "inf") : snprintf(symax, s, "%f", ymax);
89
+ b->IsOpenZmin() ? snprintf(szmin, s, "%s", "inf") : snprintf(szmin, s, "%f", zmin);
90
+ b->IsOpenZmax() ? snprintf(szmax, s, "%s", "inf") : snprintf(szmax, s, "%f", zmax);
91
+ snprintf(str, sizeof(str),
92
+ "#<BndBox:0x%x xmin=%s, ymin=%s, zmin=%s, xmax=%s, ymax=%s, zmax=%s>",
93
+ -1,
94
+ // (unsigned int)(uintptr_t)rb_cptr(self),
95
+ sxmin, symin, szmin, sxmax, symax, szmax);
96
+ }
97
+ return rb_str_new_cstr(str);
98
+ }
99
+
100
+ VALUE siren_bndbox_min(int argc, VALUE* argv, VALUE self)
101
+ {
102
+ Bnd_Box* b = siren_bndbox_get(self);
103
+ if (b->IsVoid()) {
104
+ return Qnil;
105
+ }
106
+ return siren_pnt_to_ary(b->CornerMin());
107
+ }
108
+
109
+ VALUE siren_bndbox_max(int argc, VALUE* argv, VALUE self)
110
+ {
111
+ Bnd_Box* b = siren_bndbox_get(self);
112
+ if (b->IsVoid()) {
113
+ return Qnil;
114
+ }
115
+ return siren_pnt_to_ary(b->CornerMax());
116
+ }
117
+
118
+ VALUE siren_bndbox_add(int argc, VALUE* argv, VALUE self)
119
+ {
120
+ VALUE obj;
121
+ rb_scan_args(argc, argv, "1", &obj);
122
+
123
+ Bnd_Box* b = siren_bndbox_get(self);
124
+
125
+ /*
126
+ if (siren_is_shape(obj)) {
127
+ TopoDS_Shape* s = siren_shape_get(obj);
128
+ BRepBndLib::Add(*s, *b);
129
+ }
130
+ else if (siren_is_bndbox(obj)) {
131
+ */
132
+ Bnd_Box* bb = siren_bndbox_get(obj);
133
+ b->Add(*bb);
134
+ /*
135
+ }
136
+ else if (RB_TYPE_P(obj, T_ARRAY)) {
137
+ b->Add(siren_ary_to_pnt(obj));
138
+ }
139
+ */
140
+
141
+ return Qnil;
142
+ }
143
+
144
+ VALUE siren_bndbox_is_out(int argc, VALUE* argv, VALUE self)
145
+ {
146
+ VALUE other;
147
+ rb_scan_args(argc, argv, "1", &other);
148
+ Bnd_Box* b = siren_bndbox_get(self);
149
+ return b->IsOut(*siren_bndbox_get(other)) == Standard_True ? Qtrue : Qfalse;
150
+ }
151
+
152
+ VALUE siren_bndbox_center(int argc, VALUE* argv, VALUE self)
153
+ {
154
+ Bnd_Box* b = siren_bndbox_get(self);
155
+ if (b->IsVoid()) {
156
+ return Qnil;
157
+ }
158
+ Standard_Real xmin, ymin, zmin;
159
+ Standard_Real xmax, ymax, zmax;
160
+ b->Get(xmin, ymin, zmin, xmax, ymax, zmax);
161
+ return siren_pnt_new((xmax - xmin) / 2.0, (ymax - ymin) / 2.0, (zmax - zmin) / 2.0);
162
+ }
163
+
164
+ VALUE siren_bndbox_xsize(int argc, VALUE* argv, VALUE self)
165
+ {
166
+ Bnd_Box* b = siren_bndbox_get(self);
167
+ if (b->IsVoid()) {
168
+ return Qnil;
169
+ }
170
+ Standard_Real xmin, ymin, zmin;
171
+ Standard_Real xmax, ymax, zmax;
172
+ b->Get(xmin, ymin, zmin, xmax, ymax, zmax);
173
+ return DBL2NUM(xmax - xmin);
174
+ }
175
+
176
+ VALUE siren_bndbox_ysize(int argc, VALUE* argv, VALUE self)
177
+ {
178
+ Bnd_Box* b = siren_bndbox_get(self);
179
+ if (b->IsVoid()) {
180
+ return Qnil;
181
+ }
182
+ Standard_Real xmin, ymin, zmin;
183
+ Standard_Real xmax, ymax, zmax;
184
+ b->Get(xmin, ymin, zmin, xmax, ymax, zmax);
185
+ return DBL2NUM(ymax - ymin);
186
+ }
187
+
188
+ VALUE siren_bndbox_zsize(int argc, VALUE* argv, VALUE self)
189
+ {
190
+ Bnd_Box* b = siren_bndbox_get(self);
191
+ if (b->IsVoid()) {
192
+ return Qnil;
193
+ }
194
+ Standard_Real xmin, ymin, zmin;
195
+ Standard_Real xmax, ymax, zmax;
196
+ b->Get(xmin, ymin, zmin, xmax, ymax, zmax);
197
+ return DBL2NUM(zmax - zmin);
198
+ }
199
+
200
+ VALUE siren_bndbox_is_void(int argc, VALUE* argv, VALUE self)
201
+ {
202
+ return siren_bndbox_get(self)->IsVoid() ? Qtrue : Qfalse;
203
+ }
204
+
205
+ VALUE siren_bndbox_is_whole(int argc, VALUE* argv, VALUE self)
206
+ {
207
+ return siren_bndbox_get(self)->IsWhole() ? Qtrue : Qfalse;
208
+ }
209
+
210
+ VALUE siren_bndbox_void_bang(int argc, VALUE* argv, VALUE self)
211
+ {
212
+ siren_bndbox_get(self)->SetVoid();
213
+ return Qnil;
214
+ }
215
+
216
+ VALUE siren_bndbox_whole_bang(int argc, VALUE* argv, VALUE self)
217
+ {
218
+ siren_bndbox_get(self)->SetWhole();
219
+ return Qnil;
220
+ }
221
+
222
+ VALUE siren_bndbox_is_xthin(int argc, VALUE* argv, VALUE self)
223
+ {
224
+ VALUE tol;
225
+ rb_scan_args(argc, argv, "01", &tol);
226
+ Bnd_Box* b = siren_bndbox_get(self);
227
+ return b->IsXThin(argc ? tol : 0.0) ? Qtrue : Qfalse;
228
+ }
229
+
230
+ VALUE siren_bndbox_is_ythin(int argc, VALUE* argv, VALUE self)
231
+ {
232
+ VALUE tol;
233
+ rb_scan_args(argc, argv, "01", &tol);
234
+ Bnd_Box* b = siren_bndbox_get(self);
235
+ return b->IsYThin(argc ? tol : 0.0) ? Qtrue : Qfalse;
236
+ }
237
+
238
+ VALUE siren_bndbox_is_zthin(int argc, VALUE* argv, VALUE self)
239
+ {
240
+ VALUE tol;
241
+ rb_scan_args(argc, argv, "01", &tol);
242
+ Bnd_Box* b = siren_bndbox_get(self);
243
+ return b->IsZThin(argc ? tol : 0.0) ? Qtrue : Qfalse;
244
+ }
245
+
246
+ VALUE siren_bndbox_is_openxmin(int argc, VALUE* argv, VALUE self)
247
+ {
248
+ return siren_bndbox_get(self)->IsOpenXmin() ? Qtrue : Qfalse;
249
+ }
250
+
251
+ VALUE siren_bndbox_is_openxmax(int argc, VALUE* argv, VALUE self)
252
+ {
253
+ return siren_bndbox_get(self)->IsOpenXmax() ? Qtrue : Qfalse;
254
+ }
255
+
256
+ VALUE siren_bndbox_is_openymin(int argc, VALUE* argv, VALUE self)
257
+ {
258
+ return siren_bndbox_get(self)->IsOpenYmin() ? Qtrue : Qfalse;
259
+ }
260
+
261
+ VALUE siren_bndbox_is_openymax(int argc, VALUE* argv, VALUE self)
262
+ {
263
+ return siren_bndbox_get(self)->IsOpenYmax() ? Qtrue : Qfalse;
264
+ }
265
+
266
+ VALUE siren_bndbox_is_openzmin(int argc, VALUE* argv, VALUE self)
267
+ {
268
+ return siren_bndbox_get(self)->IsOpenZmin() ? Qtrue : Qfalse;
269
+ }
270
+
271
+ VALUE siren_bndbox_is_openzmax(int argc, VALUE* argv, VALUE self)
272
+ {
273
+ return siren_bndbox_get(self)->IsOpenZmax() ? Qtrue : Qfalse;
274
+ }
275
+
276
+ VALUE siren_bndbox_openxmin_bang(int argc, VALUE* argv, VALUE self)
277
+ {
278
+ siren_bndbox_get(self)->OpenXmin();
279
+ return Qnil;
280
+ }
281
+
282
+ VALUE siren_bndbox_openxmax_bang(int argc, VALUE* argv, VALUE self)
283
+ {
284
+ siren_bndbox_get(self)->OpenXmax();
285
+ return Qnil;
286
+ }
287
+
288
+ VALUE siren_bndbox_openymin_bang(int argc, VALUE* argv, VALUE self)
289
+ {
290
+ siren_bndbox_get(self)->OpenYmin();
291
+ return Qnil;
292
+ }
293
+
294
+ VALUE siren_bndbox_openymax_bang(int argc, VALUE* argv, VALUE self)
295
+ {
296
+ siren_bndbox_get(self)->OpenYmax();
297
+ return Qnil;
298
+ }
299
+
300
+ VALUE siren_bndbox_openzmin_bang(int argc, VALUE* argv, VALUE self)
301
+ {
302
+ siren_bndbox_get(self)->OpenZmin();
303
+ return Qnil;
304
+ }
305
+
306
+ VALUE siren_bndbox_openzmax_bang(int argc, VALUE* argv, VALUE self)
307
+ {
308
+ siren_bndbox_get(self)->OpenZmax();
309
+ return Qnil;
310
+ }
311
+
312
+ VALUE siren_bndbox_set_gap(int argc, VALUE* argv, VALUE self)
313
+ {
314
+ VALUE tol;
315
+ rb_scan_args(argc, argv, "1", &tol);
316
+ siren_bndbox_get(self)->SetGap(tol);
317
+ return Qnil;
318
+ }
319
+
320
+ VALUE siren_bndbox_get_gap(int argc, VALUE* argv, VALUE self)
321
+ {
322
+ Standard_Real tol = siren_bndbox_get(self)->GetGap();
323
+ return DBL2NUM(tol);
324
+ }
325
+
326
+ VALUE siren_bndbox_dist(int argc, VALUE* argv, VALUE self)
327
+ {
328
+ VALUE other;
329
+ rb_scan_args(argc, argv, "1", &other);
330
+ Bnd_Box* b = siren_bndbox_get(self);
331
+ Bnd_Box* bb= siren_bndbox_get(other);
332
+ if (b->IsVoid() || bb->IsVoid()) {
333
+ return Qnil;
334
+ }
335
+ Standard_Real value = b->Distance(*bb);
336
+ return DBL2NUM(value);
337
+ }
338
+
339
+ VALUE siren_bndbox_square(int argc, VALUE* argv, VALUE self)
340
+ {
341
+ Standard_Real value = siren_bndbox_get(self)->SquareExtent();
342
+ return DBL2NUM(value);
343
+ }
@@ -0,0 +1,66 @@
1
+ #include "bo.h"
2
+
3
+ bool siren_bo_install()
4
+ {
5
+ rb_define_method(sr_cShape, "common", RUBY_METHOD_FUNC(siren_bo_common), -1);
6
+ rb_define_method(sr_cShape, "fuse", RUBY_METHOD_FUNC(siren_bo_fuse), -1);
7
+ rb_define_method(sr_cShape, "cut", RUBY_METHOD_FUNC(siren_bo_cut), -1);
8
+ rb_define_method(sr_cShape, "projwire", RUBY_METHOD_FUNC(siren_bo_projwire), -2);
9
+ return true;
10
+ }
11
+
12
+ VALUE siren_bo_common(int argc, VALUE* argv, VALUE self)
13
+ {
14
+ VALUE target;
15
+ rb_scan_args(argc, argv, "1", &target);
16
+ TopoDS_Shape* S1 = siren_shape_get(self);
17
+ TopoDS_Shape* S2 = siren_shape_get(target);
18
+ BRepAlgoAPI_Common api(*S1, *S2);
19
+ api.Build();
20
+ if (api.ErrorStatus()) {
21
+ return Qnil;
22
+ }
23
+ return siren_shape_new(api.Shape());
24
+ }
25
+
26
+ VALUE siren_bo_fuse(int argc, VALUE* argv, VALUE self)
27
+ {
28
+ VALUE target;
29
+ rb_scan_args(argc, argv, "1", &target);
30
+ TopoDS_Shape* S1 = siren_shape_get(self);
31
+ TopoDS_Shape* S2 = siren_shape_get(target);
32
+ BRepAlgoAPI_Fuse api(*S1, *S2);
33
+ api.Build();
34
+ if (api.ErrorStatus()) {
35
+ return Qnil;
36
+ }
37
+ return siren_shape_new(api.Shape());
38
+ }
39
+
40
+ VALUE siren_bo_cut(int argc, VALUE* argv, VALUE self)
41
+ {
42
+ VALUE target;
43
+ rb_scan_args(argc, argv, "1", &target);
44
+ TopoDS_Shape* S1 = siren_shape_get(self);
45
+ TopoDS_Shape* S2 = siren_shape_get(target);
46
+ BRepAlgoAPI_Cut api(*S1, *S2);
47
+ api.Build();
48
+ if (api.ErrorStatus()) {
49
+ return Qnil;
50
+ }
51
+ return siren_shape_new(api.Shape());
52
+ }
53
+
54
+ VALUE siren_bo_projwire(int argc, VALUE* argv, VALUE self)
55
+ {
56
+ VALUE w, v;
57
+ rb_scan_args(argc, argv, "2", &w, &v);
58
+ TopoDS_Shape* wire = siren_shape_get(w);
59
+ TopoDS_Shape* shape = siren_shape_get(self);
60
+ gp_Vec* vec = siren_vec_get(v);
61
+ BRepProj_Projection api(*wire, *shape, *vec);
62
+ if (!api.IsDone()) {
63
+ return Qnil;
64
+ }
65
+ return siren_shape_new(api.Shape());
66
+ }
@@ -0,0 +1,69 @@
1
+ #include "brep.h"
2
+
3
+ bool siren_brep_install()
4
+ {
5
+ #if 0
6
+ // Class method
7
+ rb_define_class_method(sr_mSiren, "save_brep", RUBY_METHOD_FUNC(siren_brep_save), MRB_ARGS_REQ(2));
8
+ rb_define_class_method(sr_mSiren, "load_brep", RUBY_METHOD_FUNC(siren_brep_load), MRB_ARGS_REQ(1));
9
+ rb_define_class_method(sr_mSiren, "dump", RUBY_METHOD_FUNC(siren_brep_dump), MRB_ARGS_REQ(1));
10
+ #endif
11
+ // For mix-in
12
+ rb_define_method(sr_mSiren, "save_brep", RUBY_METHOD_FUNC(siren_brep_save), -1);
13
+ rb_define_method(sr_mSiren, "load_brep", RUBY_METHOD_FUNC(siren_brep_load), -1);
14
+ rb_define_method(sr_cShape, "dump", RUBY_METHOD_FUNC(siren_brep_dump), -1);
15
+ return true;
16
+ }
17
+
18
+ VALUE siren_brep_save(int argc, VALUE* argv, VALUE self)
19
+ {
20
+ VALUE target;
21
+ VALUE path;
22
+ rb_scan_args(argc, argv, "2", &target, &path);
23
+ siren_shape_check(target);
24
+ Check_Type(path, T_STRING);
25
+ if (NUM2INT(rb_funcall(path, rb_intern("size"), 0)) == 0) {
26
+ rb_raise(rb_eArgError, "Specified path has no charactors.");
27
+ }
28
+ TopoDS_Shape* shape = siren_shape_get(target);
29
+ try {
30
+ std::ofstream fst(RSTRING_PTR(path), std::ios_base::out);
31
+ if (fst.good()) {
32
+ BRepTools::Write(*shape, fst);
33
+ }
34
+ }
35
+ catch (...) {
36
+ rb_raise(rb_eIOError, "Failed to save BRep to %s.", RSTRING_PTR(path));
37
+ }
38
+ return Qnil;
39
+ }
40
+
41
+ VALUE siren_brep_load(int argc, VALUE* argv, VALUE self)
42
+ {
43
+ VALUE path;
44
+ rb_scan_args(argc, argv, "1", &path);
45
+ Check_Type(path, T_STRING);
46
+ if (rb_funcall(rb_cFile, rb_intern("exist?"), 1, path) == Qfalse) {
47
+ rb_raise(rb_eIOError, "No such file at %s.", RSTRING_PTR(path));
48
+ }
49
+ BRep_Builder B;
50
+ TopoDS_Shape shape;
51
+ try {
52
+ std::ifstream fst(RSTRING_PTR(path), std::ios_base::in);
53
+ if (fst.good()) {
54
+ BRepTools::Read(shape, fst, B);
55
+ }
56
+ }
57
+ catch (...) {
58
+ rb_raise(rb_eIOError, "Failed to load BRep from %s.", RSTRING_PTR(path));
59
+ }
60
+ return siren_shape_new(shape);
61
+ }
62
+
63
+ VALUE siren_brep_dump(int argc, VALUE* argv, VALUE self)
64
+ {
65
+ VALUE target;
66
+ TopoDS_Shape* shape = siren_shape_get(self);
67
+ BRepTools::Dump(*shape, std::cout);
68
+ return Qnil;
69
+ }