-
-
Notifications
You must be signed in to change notification settings - Fork 441
Expand file tree
/
Copy pathInteractor.java
More file actions
611 lines (531 loc) · 18.2 KB
/
Copy pathInteractor.java
File metadata and controls
611 lines (531 loc) · 18.2 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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
package app.f3d.F3D;
import java.util.List;
public class Interactor {
/** Thrown when adding a command or binding that already exists. */
public static class AlreadyExistsException extends F3DException {
public AlreadyExistsException(String message) { super(message); }
}
/** Thrown when removing a command or binding that does not exist. */
public static class DoesNotExistException extends F3DException {
public DoesNotExistException(String message) { super(message); }
}
/** Thrown when a triggered command fails at runtime. */
public static class CommandRuntimeException extends F3DException {
public CommandRuntimeException(String message) { super(message); }
}
/** Thrown when a command is invoked with invalid arguments. */
public static class InvalidArgsException extends F3DException {
public InvalidArgsException(String message) { super(message); }
}
private long mNativeAddress;
public enum ModifierKeys {
ANY,
NONE,
CTRL,
SHIFT,
CTRL_SHIFT
}
public enum BindingType {
CYCLIC,
NUMERICAL,
TOGGLE,
OTHER
}
public enum MouseButton {
LEFT,
RIGHT,
MIDDLE
}
public enum WheelDirection {
FORWARD,
BACKWARD,
LEFT,
RIGHT
}
public enum InputAction {
PRESS,
RELEASE
}
public enum InputModifier {
NONE,
CTRL,
SHIFT,
CTRL_SHIFT
}
public enum AnimationDirection {
FORWARD(0),
BACKWARD(1);
private final int value;
AnimationDirection(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static AnimationDirection fromValue(int value) {
for (AnimationDirection dir : AnimationDirection.values()) {
if (dir.value == value) {
return dir;
}
}
throw new IllegalArgumentException("Invalid AnimationDirection value: " + value);
}
}
public static class InteractionBind implements Comparable<InteractionBind> {
public ModifierKeys mod;
public String inter;
public InteractionBind() {
this.mod = ModifierKeys.NONE;
this.inter = "";
}
public InteractionBind(ModifierKeys mod, String inter) {
this.mod = mod;
this.inter = inter;
}
public String format() {
switch (mod) {
case CTRL_SHIFT:
return "Ctrl+Shift+" + inter;
case CTRL:
return "Ctrl+" + inter;
case SHIFT:
return "Shift+" + inter;
case ANY:
return "Any+" + inter;
default:
return inter;
}
}
public static InteractionBind parse(String str) {
InteractionBind bind = new InteractionBind();
int plusIndex = str.lastIndexOf('+');
if (plusIndex == -1) {
bind.inter = str;
} else {
bind.inter = str.substring(plusIndex + 1);
String modStr = str.substring(0, plusIndex);
if (modStr.equals("Ctrl+Shift")) {
bind.mod = ModifierKeys.CTRL_SHIFT;
} else if (modStr.equals("Shift")) {
bind.mod = ModifierKeys.SHIFT;
} else if (modStr.equals("Ctrl")) {
bind.mod = ModifierKeys.CTRL;
} else if (modStr.equals("Any")) {
bind.mod = ModifierKeys.ANY;
} else if (modStr.equals("None")) {
bind.mod = ModifierKeys.NONE;
}
}
return bind;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
InteractionBind other = (InteractionBind) obj;
return mod == other.mod && inter.equals(other.inter);
}
@Override
public int compareTo(InteractionBind other) {
if (mod != other.mod) {
return mod.compareTo(other.mod);
}
return inter.compareTo(other.inter);
}
}
public static class BindingDocumentation {
public String documentation;
public String currentValue;
public BindingDocumentation(String documentation, String currentValue) {
this.documentation = documentation;
this.currentValue = currentValue;
}
}
public static class InteractorState {
public double animationTime;
}
public interface EventLoopCallback {
void execute(InteractorState state);
}
/**
* Notification callback.
* Return false to prevent standard notification from being displayed, true to allow it.
* Arguments are the description, value, bindings, and duration of the notification.
*/
public interface NotificationCallback {
boolean execute(String desc, String value, String bind, double duration);
}
public interface CommandCallback {
void execute(List<String> args);
}
Interactor(long nativeAddress) {
mNativeAddress = nativeAddress;
}
/**
* Remove all existing commands and add all default commands.
*
* @return this interactor for method chaining
*/
public native Interactor initCommands();
/**
* Add a command to be called using triggerCommand.
*
* @param action action name for the command
* @param callback callback to execute when command is triggered
* @return this interactor for method chaining
*/
public native Interactor addCommand(String action, CommandCallback callback);
/**
* Remove a command for provided action.
*
* @param action action name to remove
* @return this interactor for method chaining
*/
public native Interactor removeCommand(String action);
/**
* Return a list containing all currently defined actions of commands.
*
* @return list of command actions
*/
public native List<String> getCommandActions();
/**
* Trigger provided command.
*
* @param command command string to execute
* @param keepComments if true, comments with # are supported
* @return true if command succeeded, false otherwise
*/
public native boolean triggerCommand(String command, boolean keepComments);
/**
* Trigger provided command with keepComments enabled.
*
* @param command command string to execute
* @return true if command succeeded, false otherwise
*/
public boolean triggerCommand(String command) {
return triggerCommand(command, true);
}
/**
* Remove all existing interaction commands and add all default bindings.
*
* @return this interactor for method chaining
*/
public native Interactor initBindings();
/**
* Add binding to trigger commands for a specific bind.
*
* @param bind interaction bind (key combination)
* @param commands list of commands to trigger
* @param group optional group name for organization
* @param type optional binding type
* @param notify notify when the binding is triggered
* @param repeat repeatedly apply binding when holding down key
* @return this interactor for method chaining
*/
private native Interactor addBindingCommands(InteractionBind bind, List<String> commands, String group, BindingType type, boolean notify, boolean repeat);
/**
* Add binding to trigger commands for a specific bind.
*
* @param bind interaction bind (key combination)
* @param commands list of commands to trigger
* @param group optional group name for organization
* @param type optional binding type
* @param notify notify when the binding is triggered
* @param repeat repeatedly apply binding when holding down key
* @return this interactor for method chaining
*/
public Interactor addBinding(InteractionBind bind, List<String> commands, String group, BindingType type, boolean notify, boolean repeat) {
return addBindingCommands(bind, commands, group, type, notify, repeat);
}
/**
* Add binding to trigger commands for a specific bind with default group and type.
*
* @param bind interaction bind (key combination)
* @param commands list of commands to trigger
* @return this interactor for method chaining
*/
public Interactor addBinding(InteractionBind bind, List<String> commands) {
return addBindingCommands(bind, commands, "", BindingType.OTHER, true, false);
}
/**
* Add binding to trigger a single command for a specific bind.
*
* @param bind interaction bind (key combination)
* @param command command to trigger
* @param group optional group name for organization
* @param type optional binding type
* @param notify notify when the binding is triggered
* @param repeat repeatedly apply binding when holding down key
* @return this interactor for method chaining
*/
private native Interactor addBindingCommand(InteractionBind bind, String command, String group, BindingType type, boolean notify, boolean repeat);
/**
* Add binding to trigger a single command for a specific bind.
*
* @param bind interaction bind (key combination)
* @param command command to trigger
* @param group optional group name for organization
* @param type optional binding type
* @param notify notify when the binding is triggered
* @param repeat repeatedly apply binding when holding down key
* @return this interactor for method chaining
*/
public Interactor addBinding(InteractionBind bind, String command, String group, BindingType type, boolean notify, boolean repeat) {
return addBindingCommand(bind, command, group, type, notify, repeat);
}
/**
* Add binding to trigger a single command for a specific bind with default group and type.
*
* @param bind interaction bind (key combination)
* @param command command to trigger
* @return this interactor for method chaining
*/
public Interactor addBinding(InteractionBind bind, String command) {
return addBindingCommand(bind, command, "", BindingType.OTHER, true, false);
}
/**
* Remove binding corresponding to provided bind.
*
* @param bind binding to remove
* @return this interactor for method chaining
*/
public native Interactor removeBinding(InteractionBind bind);
/**
* Return a vector of available bind groups, in order of addition.
*
* @return list of bind group names
*/
public native List<String> getBindGroups();
/**
* Return a vector of bind for the specified group, in order of addition.
*
* @param group group name
* @return list of binds for the group
*/
public native List<InteractionBind> getBindsForGroup(String group);
/**
* Return a vector of all binds, in order of addition.
*
* @return list of all binds
*/
public native List<InteractionBind> getBinds();
/**
* Get documentation for a binding.
*
* @param bind binding to get documentation for
* @return documentation pair (description, current value)
*/
public native BindingDocumentation getBindingDocumentation(InteractionBind bind);
/**
* Get the type of a binding.
*
* @param bind binding to get type for
* @return binding type
*/
public native BindingType getBindingType(InteractionBind bind);
/**
* Toggle animation state.
*
* @param direction animation direction
* @return this interactor for method chaining
*/
public native Interactor toggleAnimation(AnimationDirection direction);
/**
* Toggle animation state with default forward direction.
*
* @return this interactor for method chaining
*/
public Interactor toggleAnimation() {
return toggleAnimation(AnimationDirection.FORWARD);
}
/**
* Start animation.
*
* @param direction animation direction
* @return this interactor for method chaining
*/
public native Interactor startAnimation(AnimationDirection direction);
/**
* Start animation with default forward direction.
*
* @return this interactor for method chaining
*/
public Interactor startAnimation() {
return startAnimation(AnimationDirection.FORWARD);
}
/**
* Stop animation.
*
* @return this interactor for method chaining
*/
public native Interactor stopAnimation();
/**
* Check if animation is playing.
*
* @return true if playing, false otherwise
*/
public native boolean isPlayingAnimation();
/**
* Get the current animation direction.
*
* @return animation direction
*/
public native AnimationDirection getAnimationDirection();
/**
* Enable camera movement.
*
* @return this interactor for method chaining
*/
public native Interactor enableCameraMovement();
/**
* Disable camera movement.
*
* @return this interactor for method chaining
*/
public native Interactor disableCameraMovement();
/**
* Trigger a modifier update.
*
* @param mod modifier state
* @return this interactor for method chaining
*/
public native Interactor triggerModUpdate(InputModifier mod);
/**
* Trigger a mouse button event.
*
* @param action press or release action
* @param button mouse button
* @return this interactor for method chaining
*/
public native Interactor triggerMouseButton(InputAction action, MouseButton button);
/**
* Trigger a mouse new position event.
*
* @param xpos x position in pixels
* @param ypos y position in pixels
* @return this interactor for method chaining
*/
public native Interactor triggerMousePosition(double xpos, double ypos);
/**
* Trigger a mouse wheel event.
*
* @param direction wheel direction
* @return this interactor for method chaining
*/
public native Interactor triggerMouseWheel(WheelDirection direction);
/**
* Trigger a keyboard key event.
*
* @param action press or release action
* @param keySym key symbol (e.g., "A", "Left", "Space")
* @return this interactor for method chaining
*/
public native Interactor triggerKeyboardKey(InputAction action, String keySym);
/**
* Trigger a text character input event.
*
* @param codepoint Unicode codepoint
* @return this interactor for method chaining
*/
public native Interactor triggerTextCharacter(int codepoint);
/**
* Manually trigger the event loop.
*
* @param deltaTime time delta in seconds (must be positive)
* @return this interactor for method chaining
*/
public native Interactor triggerEventLoop(double deltaTime);
/**
* Set the event loop user callback called automatically on each event loop iteration.
*
* @param callback callback to be called on each event loop iteration
* @return this interactor for method chaining
*/
public native Interactor setEventLoopUserCallback(EventLoopCallback callback);
/**
* Set notification callback. If null, only standard notifications will be displayed.
*/
public native Interactor setNotificationCallback(NotificationCallback callback);
/**
* Play a VTK interaction file.
*
* @param file path to interaction file
* @param deltaTime time delta in seconds
* @return true on success, false otherwise
*/
public native boolean playInteraction(String file, double deltaTime);
/**
* Play a VTK interaction file with default deltaTime.
*
* @param file path to interaction file
* @return true on success, false otherwise
*/
public boolean playInteraction(String file) {
return playInteraction(file, 1.0 / 30);
}
/**
* Start interaction and record it in a VTK interaction file.
*
* @param file path to save interaction file
* @return true on success, false otherwise
*/
public native boolean recordInteraction(String file);
/**
* Start the interactor event loop.
*
* @param deltaTime time delta in seconds (must be positive)
* @return this interactor for method chaining
*/
public native Interactor start(double deltaTime);
/**
* Start the interactor event loop with default deltaTime.
*
* @return this interactor for method chaining
*/
public Interactor start() {
return start(1.0 / 30);
}
/**
* Stop the interactor.
*
* @return this interactor for method chaining
*/
public native Interactor stop();
/**
* Request a render to be done on the next event loop.
*
* @return this interactor for method chaining
*/
public native Interactor requestRender();
/**
* Request the interactor to stop on the next event loop.
*
* @return this interactor for method chaining
*/
public native Interactor requestStop();
/**
* Trigger a single text line notification with text desc for duration seconds.
*
* @param desc Text description
* @param value Text value
* @param duration Duration of notification in seconds
*/
public native Interactor triggerNotification(String desc, String value, double duration);
/**
* Trigger a notification with default duration.
*
* @param desc Text description
* @param value Text value
*/
public Interactor triggerNotification(String desc, String value) {
return triggerNotification(desc, value, 3.0);
}
/**
* Trigger a notification with default value and duration.
*
* @param desc Text description
*/
public Interactor triggerNotification(String desc) {
return triggerNotification(desc, "");
}
}