-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_interface.sh
More file actions
executable file
·553 lines (468 loc) · 18.8 KB
/
generate_interface.sh
File metadata and controls
executable file
·553 lines (468 loc) · 18.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
#!/bin/bash
# Target file
INTERFACE_FILE="neoapi.i"
# SDK Path (default to Baumer_neoAPI_1.5.0_lin_x86_64_cpp if not provided)
SDK_PATH="${1:-Baumer_neoAPI_1.5.0_lin_x86_64_cpp}"
if [ ! -d "$SDK_PATH" ]; then
echo "Error: SDK path $SDK_PATH does not exist."
exit 1
fi
INCLUDE_DIR="$SDK_PATH/include/neoapi"
echo "Generating $INTERFACE_FILE (Adding CamBase Extensions and Collection Support)..."
cat <<EOF > "$INTERFACE_FILE"
%module(directors="1") neoapi_csharp
%{
#include "neoapi/neoapi.hpp"
using namespace NeoAPI;
%}
// Handle export macro
#define NEOAPI_CPP_DECL
// Standard templates
%include <std_string.i>
%include <std_vector.i>
%include <stdint.i>
// Enable SWIG Directors for callback classes
%feature("director") NeoAPI::NeoEventCallback;
%feature("director") NeoAPI::NeoImageCallback;
%feature("director") NeoAPI::NeoTraceCallback;
// Enable naturalvar for feature types
%feature("naturalvar") NeoAPI::BaseFeature;
%feature("naturalvar") NeoAPI::IntegerFeature;
%feature("naturalvar") NeoAPI::DoubleFeature;
%feature("naturalvar") NeoAPI::StringFeature;
%feature("naturalvar") NeoAPI::BoolFeature;
%feature("naturalvar") NeoAPI::CommandFeature;
%feature("naturalvar") NeoAPI::EnumerationFeature;
// Nodefaultctor for feature types
%nodefaultctor NeoAPI::BaseFeature;
%nodefaultctor NeoAPI::IntegerFeature;
%nodefaultctor NeoAPI::DoubleFeature;
%nodefaultctor NeoAPI::StringFeature;
%nodefaultctor NeoAPI::BoolFeature;
%nodefaultctor NeoAPI::CommandFeature;
%nodefaultctor NeoAPI::EnumerationFeature;
%nodefaultctor NeoAPI::Feature;
%nodefaultctor NeoAPI::FeatureList;
// Global Renames
%rename(GetIsConnected) NeoAPI::CamBase::IsConnected;
%rename(GetIsStreaming) NeoAPI::CamBase::IsStreaming;
%rename(_Connect) NeoAPI::CamBase::Connect;
%rename(_Disconnect) NeoAPI::CamBase::Disconnect;
%rename(Getf) NeoAPI::CamBase::f;
%rename(Getf) NeoAPI::Cam::f;
%rename(GetIsConnectable) NeoAPI::CamInfo::IsConnectable;
// Feature Renames - Applying correctly to NeoAPI namespace
%rename(GetIsReadable) NeoAPI::BaseFeature::IsReadable;
%rename(GetIsWritable) NeoAPI::BaseFeature::IsWritable;
%rename(GetIsAvailable) NeoAPI::BaseFeature::IsAvailable;
// Rename IsSelector for Derived classes where it works
%rename(GetIsSelector) IsSelector;
%rename(GetIsDone) NeoAPI::CommandFeature::IsDone;
// Iterator Renames
%rename(GetFeature) NeoAPI::FeatureListIterator::operator*;
%rename(operator_increment) NeoAPI::FeatureListIterator::operator++;
%rename(op_Equal) NeoAPI::FeatureListIterator::operator==;
%rename(op_NotEqual) NeoAPI::FeatureListIterator::operator!=;
// Ensure Getf and friends are explicitly defined in CamBase if not already
%extend NeoAPI::CamBase {
// Note: If f() only exists in Cam in this version, we'll need to handle it.
// But since we want it in the base class property f, we'll try to extend it.
}
// Explicitly extend CommandFeature for IsDone
%extend NeoAPI::CommandFeature {
bool GetIsDone() {
return \$self->IsDone();
}
}
// Extend CPixelFormat to have a Get method returning PixelFormat enum
%extend NeoAPI::CPixelFormat {
NeoAPI::PixelFormat Get() {
return (NeoAPI::PixelFormat)(*(\$self));
}
void Set(NeoAPI::PixelFormat value) {
*(\$self) = value;
}
}
// Typemap for injecting C# code
%typemap(cscode) NeoAPI::CamBase %{
public bool IsConnected { get { return GetIsConnected(); } }
public bool IsStreaming { get { return GetIsStreaming(); } }
public static string LibraryVersion { get { return GetLibraryVersion(); } }
public void EnableImageCallback() { EnableImageCallback(ImageCallback); }
public void EnablePnPEventCallback() { EnablePnPEventCallback(PnPEventCallback); }
protected NeoImageCallbackHandler image_callback_ = new NeoImageCallbackHandler();
public NeoImageCallbackHandler ImageCallback { get { return image_callback_; } }
protected NeoEventCallbackHandler pnp_event_callback_ = new NeoEventCallbackHandler();
public NeoEventCallbackHandler PnPEventCallback { get { return pnp_event_callback_; } }
protected System.Collections.Generic.Dictionary<string, NeoEventCallbackHandler> device_event_callbacks_ = new System.Collections.Generic.Dictionary<string, NeoEventCallbackHandler>();
public NeoEventCallbackHandler DeviceEventCallback { get { if(!device_event_callbacks_.ContainsKey("")) {device_event_callbacks_[""] = new NeoEventCallbackHandler();} return device_event_callbacks_[""]; } }
public void EnableEventCallback(string name = "") { if(!device_event_callbacks_.ContainsKey(name)) {device_event_callbacks_[name] = new NeoEventCallbackHandler();} EnableEventCallback(device_event_callbacks_[name], new NeoString(name)); }
private object parentReference;
internal void addReference(object parent) {
parentReference = parent;
}
public virtual CamBase Connect(NeoString identifier) {
CamBase ret = _Connect(identifier);
if (neoapi_csharpPINVOKE.SWIGPendingException.Pending) throw neoapi_csharpPINVOKE.SWIGPendingException.Retrieve();
ret.addReference(this);
return ret;
}
public virtual CamBase Connect() {
CamBase ret = _Connect();
if (neoapi_csharpPINVOKE.SWIGPendingException.Pending) throw neoapi_csharpPINVOKE.SWIGPendingException.Retrieve();
ret.addReference(this);
return ret;
}
public virtual CamBase Disconnect() {
CamBase ret = _Disconnect();
if (neoapi_csharpPINVOKE.SWIGPendingException.Pending) throw neoapi_csharpPINVOKE.SWIGPendingException.Retrieve();
ret.addReference(this);
return ret;
}
// Fallback property f if Getf exists in derived Cam
public FeatureAccess f {
get {
if (this is Cam cam) return cam.Getf();
throw new System.NotImplementedException("FeatureAccess is only available on Cam instance");
}
}
public System.Collections.Generic.List<string> AvailableChunks {
get {
var result = new System.Collections.Generic.List<string>();
var list = GetAvailableChunks();
uint sz = list.size();
for (uint i = 0; i < sz; ++i) result.Add(list.GetAt(i).ToString());
return result;
}
}
public System.Collections.Generic.List<string> AvailableEvents {
get {
var result = new System.Collections.Generic.List<string>();
var list = GetAvailableEvents();
uint sz = list.size();
for (uint i = 0; i < sz; ++i) result.Add(list.GetAt(i).ToString());
return result;
}
}
public System.Collections.Generic.List<string> EnabledEvents {
get {
var result = new System.Collections.Generic.List<string>();
var list = GetEnabledEvents();
uint sz = list.size();
for (uint i = 0; i < sz; ++i) result.Add(list.GetAt(i).ToString());
return result;
}
}
%}
%typemap(cscode) NeoAPI::CamInfo %{
public string Id { get { return GetId(); } }
public string ModelName { get { return GetModelName(); } }
public string SerialNumber { get { return GetSerialNumber(); } }
public string TLType { get { return GetTLType(); } }
public string VendorName { get { return GetVendorName(); } }
public string USB3VisionGUID { get { return GetUSB3VisionGUID(); } }
public string USBPortID { get { return GetUSBPortID(); } }
public string GevIpAddress { get { return GetGevIpAddress(); } }
public string GevSubnetMask { get { return GetGevSubnetMask(); } }
public string GevGateway { get { return GetGevGateway(); } }
public string GevMACAddress { get { return GetGevMACAddress(); } }
public bool IsConnectable { get { return GetIsConnectable(); } }
%}
// Rename methods to avoid name conflicts with properties
%rename(GetIsEmpty) NeoAPI::Image::IsEmpty;
%rename(GetIsLastImage) NeoAPI::Image::IsLastImage;
%rename(_GetAvailablePixelFormats) NeoAPI::Image::GetAvailablePixelFormats;
%rename(_GetChunkList) NeoAPI::Image::GetChunkList;
%rename(_IsSegmentShared) NeoAPI::ImageInfo::IsSegmentShared;
// Ergonomic properties and methods for ImageInfo
%typemap(cscode) NeoAPI::ImageInfo %{
/// <summary>
/// The height of the image in pixel, returns zero as long the image is not filled with data
/// </summary>
public ulong Height { get { return GetHeight(); } }
/// <summary>
/// The y offset in pixel
/// </summary>
public ulong YOffset { get { return GetYOffset(); } }
/// <summary>
/// The number of extra bytes transmitted at the end of the image
/// </summary>
public ulong YPadding { get { return GetYPadding(); } }
/// <summary>
/// The width of the image in pixel, returns zero as long the image is not filled with data
/// </summary>
public ulong Width { get { return GetWidth(); } }
/// <summary>
/// The x offset in pixel
/// </summary>
public ulong XOffset { get { return GetXOffset(); } }
/// <summary>
/// The the number of extra bytes transmitted at the end of each line
/// </summary>
public ulong XPadding { get { return GetXPadding(); } }
/// <summary>
/// The pixelformat of the image, returns an empty string as long the image is not filled with data
/// </summary>
public string PixelFormat { get { return GetPixelFormat(); } }
/// <summary>
/// Get the whole size of the image in bytes
/// </summary>
public ulong Size { get { return GetSize(); } }
/// <summary>
/// The group id of the image
/// </summary>
public ulong GroupID { get { return GetGroupID(); } }
/// <summary>
/// The source id of the image
/// </summary>
public ulong SourceID { get { return GetSourceID(); } }
/// <summary>
/// The region id of the image
/// </summary>
public ulong RegionID { get { return GetRegionID(); } }
/// <summary>
/// give information if the memory segment in a buffer is shared with other components
/// </summary>
public bool IsSegmentShared { get { return _IsSegmentShared(); } }
/// <summary>
/// The image data offset related to the begin of the memory segment in the buffer
/// </summary>
public ulong SegmentOffset { get { return GetSegmentOffset(); } }
/// <summary>
/// The whole size of the memory segment in the buffer
/// </summary>
public ulong SegmentSize { get { return GetSegmentSize(); } }
/// <summary>
/// The index of the memory segment in the buffer
/// </summary>
public uint SegmentIndex { get { return GetSegmentIndex(); } }
/// <summary>
/// Get compression method of the image
/// </summary>
public NeoImageCompression Compression { get { return GetCompression(); } }
%}
// Ergonomic properties and methods for Image
%typemap(cscode) NeoAPI::Image %{
/// <summary>
/// Check if the image is empty or filled with data
/// </summary>
public bool IsEmpty { get { return GetIsEmpty(); } }
/// <summary>
/// gives information if this image is the last image in a buffer
/// </summary>
public bool IsLastImage { get { return GetIsLastImage(); } }
/// <summary>
/// Get the Index of the image inside the buffer, returns zero as long the image is not filled with data
/// </summary>
public ulong ImageIndex { get { return GetImageIndex(); } }
/// <summary>
/// Get the ID of the buffer, returns zero as long the image is not filled with data
/// </summary>
public ulong BufferID { get { return GetBufferID(); } }
/// <summary>
/// Get the timestamp of the image, returns zero as long the image is not filled with data
/// </summary>
public ulong Timestamp { get { return GetTimestamp(); } }
/// <summary>
/// Get a pointer to the image data, returns nullptr as long as the image is not filled with data.
/// </summary>
public global::System.IntPtr ImageData {
get {
return neoapi_csharpPINVOKE.Image_GetImageData(swigCPtr);
}
}
/// <summary>
/// Get a list with available PixelFormats for Convert
/// </summary>
/// <returns>list of available PixelFormats</returns>
public System.Collections.Generic.List<string> GetAvailablePixelFormats() {
System.Collections.Generic.List<string> result = new System.Collections.Generic.List<string>();
NeoStringList list = _GetAvailablePixelFormats();
uint sz = list.size();
for (uint i = 0; i < sz; ++i) result.Add(list.GetAt(i));
return result;
}
/// <summary>
/// Get a list of all available chunk features of the image
/// </summary>
/// <returns>A list of available chunk features</returns>
public System.Collections.Generic.Dictionary<string, Feature> GetChunkList() {
System.Collections.Generic.Dictionary<string, Feature> result = new System.Collections.Generic.Dictionary<string, Feature>();
FeatureList list = _GetChunkList();
foreach (Feature f in list) {
result.Add(f.GetName(), f);
}
return result;
}
/// <summary>
/// Get access to a object inherited by NeoAPI.BufferBase and used by this image.
/// </summary>
/// <returns>UserBuffer object</returns>
protected BufferBase user_buffer_ = null;
public T GetUserBuffer<T>() where T : class {
return user_buffer_ as T;
}
private object parentReference;
internal void addReference(object parent) {
parentReference = parent;
}
%}
%typemap(cscode) NeoAPI::CamInfoList %{
protected System.Collections.Generic.List<CamInfo> cam_info_list_ = null;
public System.Collections.ObjectModel.ReadOnlyCollection<CamInfo> List
{
get
{
if(cam_info_list_ == null) {
cam_info_list_ = new System.Collections.Generic.List<CamInfo>();
uint list_size = size();
for (uint index = 0; index < list_size; index++)
{
cam_info_list_.Add(IndexToCamInfo(index));
}
}
return cam_info_list_.AsReadOnly();
}
}
public System.Collections.Generic.IEnumerator<CamInfo> GetEnumerator()
{
return List.GetEnumerator();
}
public CamInfo this[int index]
{
get { return List[index]; }
}
%}
// NeoString support
%typemap(cscode) NeoAPI::NeoString %{
public override string ToString() {
return c_str();
}
public static implicit operator string(NeoString s) {
return s?.c_str();
}
public static implicit operator NeoString(string s) {
return new NeoString(s);
}
%}
// Feature Feature Properties
%typemap(cscode) NeoAPI::BaseFeature %{
public bool IsReadable { get { return GetIsReadable(); } }
public bool IsWritable { get { return GetIsWritable(); } }
public bool IsAvailable { get { return GetIsAvailable(); } }
// IsSelector removed from BaseFeature to avoid issues
public string Name { get { return GetName(); } }
public string DisplayName { get { return GetDisplayName(); } }
public string Description { get { return GetDescription(); } }
public string ToolTip { get { return GetToolTip(); } }
public string Visibility { get { return GetVisibility(); } }
public string Interface { get { return GetInterface(); } }
%}
%typemap(cscode) NeoAPI::DoubleFeature %{
public double Value { get { return Get(); } set { Set(value); } }
public double Min { get { return GetMin(); } }
public double Max { get { return GetMax(); } }
public double Inc { get { return GetInc(); } }
public ulong Precision { get { return GetPrecision(); } }
public string ValueString { get { return GetString(); } }
public string Unit { get { return GetUnit(); } }
public string Representation { get { return GetRepresentation(); } }
%}
%typemap(cscode) NeoAPI::IntegerFeature %{
public long Value { get { return Get(); } set { Set(value); } }
public long Min { get { return GetMin(); } }
public long Max { get { return GetMax(); } }
public long Inc { get { return GetInc(); } }
public string ValueString { get { return GetString(); } }
public string Unit { get { return GetUnit(); } }
public string Representation { get { return GetRepresentation(); } }
public bool IsSelector { get { return GetIsSelector(); } }
%}
%typemap(cscode) NeoAPI::BoolFeature %{
public bool Value { get { return Get(); } set { Set(value); } }
public string ValueString { get { return GetString(); } }
%}
%typemap(cscode) NeoAPI::StringFeature %{
public string Value { get { return GetString(); } set { SetString(value); } }
public long MaxStringLength { get { return GetMaxStringLength(); } }
%}
%typemap(cscode) NeoAPI::EnumerationFeature %{
public long ValueInt { get { return GetInt(); } set { SetInt(value); } }
public string ValueString { get { return GetString(); } set { SetString(value); } }
public FeatureList EnumValueList { get { return GetEnumValueList(); } }
public bool IsSelector { get { return GetIsSelector(); } }
%}
%typemap(cscode) NeoAPI::CommandFeature %{
public bool IsDone { get { return GetIsDone(); } }
%}
%typemap(cscode) NeoAPI::CPixelFormat %{
public PixelFormat Value { get { return Get(); } set { Set(value); } }
%}
%typemap(csinterfaces) NeoAPI::FeatureList "global::System.Collections.Generic.IEnumerable<Feature>, global::System.Collections.IEnumerable";
%typemap(cscode) NeoAPI::FeatureList %{
public System.Collections.Generic.IEnumerator<Feature> GetEnumerator() {
for (FeatureListIterator it = begin(); !it.op_Equal(end()); it.operator_increment()) {
yield return it.GetFeature();
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
%}
// Extensions
%extend NeoAPI::CamInfoList {
NeoAPI::CamInfo IndexToCamInfo(uint32_t index) {
return (*\$self)[(size_t)index];
}
}
%extend NeoAPI::NeoStringList {
NeoAPI::NeoString GetAt(uint32_t index) {
return (*\$self)[(size_t)index];
}
}
// Inclusions
%include "neoapi/neoapi_common.hpp"
%include "neoapi/neoapi_feature.hpp"
%include "neoapi/neoapi_image_info.hpp"
%include "neoapi/neoapi_image.hpp"
%include "neoapi/neoapi_event.hpp"
%include "neoapi/neoapi_featureaccess.hpp"
%include "neoapi/neoapi_trace.hpp"
%include "neoapi/neoapi_camera.hpp"
%include "neoapi/neoapi_camera_info.hpp"
%include "neoapi/neoapi_image_converter.hpp"
%include "neoapi/neoapi.hpp"
EOF
# Create the extra event handler classes
echo "Generating extra_handlers.cs..."
cat <<EOF > extra_handlers.cs
namespace NeoAPI_Linux {
public class ImageEventArgs : System.EventArgs {
public Image Image { get; set; }
}
public class NeoImageCallbackHandler : NeoImageCallback {
public override void ImageCallback(Image image) {
System.EventHandler<ImageEventArgs> handler = Handler;
if (handler != null) {
ImageEventArgs args = new ImageEventArgs();
args.Image = image;
handler(this, args);
}
}
public event System.EventHandler<ImageEventArgs> Handler;
}
public class NeoEventEventArgs : System.EventArgs {
public NeoEvent Event { get; set; }
}
public class NeoEventCallbackHandler : NeoEventCallback {
public override void EventCallback(NeoEvent neoevent) {
System.EventHandler<NeoEventEventArgs> handler = Handler;
if (handler != null) {
NeoEventEventArgs args = new NeoEventEventArgs();
args.Event = neoevent;
handler(this, args);
}
}
public event System.EventHandler<NeoEventEventArgs> Handler;
}
}
EOF
echo "Done! $INTERFACE_FILE and extra_handlers.cs have been generated."