forked from CoppeliaRobotics/simUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.cpp
1382 lines (1218 loc) · 45.5 KB
/
plugin.cpp
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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/foreach.hpp>
#include <QVector>
#include <QThread>
#include <QSlider>
#include <QLineEdit>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QPushButton>
#include <QCheckBox>
#include <QRadioButton>
#include <QWidget>
#include <QLabel>
#include <QGroupBox>
#include <QComboBox>
#include <QDialog>
#include "tinyxml2.h"
#include "v_repPlusPlus/Plugin.h"
#include "plugin.h"
#include "debug.h"
#include "config.h"
#include "stubs.h"
#include "Proxy.h"
#include "UIFunctions.h"
#include "UIProxy.h"
#include "widgets/all.h"
#ifdef ENABLE_SIGNAL_SPY
#include "signal_spy.h"
#endif
void msgBox(SScriptCallBack *p, const char *cmd, msgBox_in *in, msgBox_out *out)
{
DEBUG_OUT << "[enter]" << std::endl;
int result;
// this function is called also from the C API: always run it in the correct thread
if(QThread::currentThreadId() == UI_THREAD)
UIProxy::getInstance()->onMsgBox(in->type, in->buttons, in->title, in->message, &result);
else
UIFunctions::getInstance()->msgBox(in->type, in->buttons, in->title, in->message, &result);
out->result = result;
DEBUG_OUT << "[leave]" << std::endl;
}
void fileDialog(SScriptCallBack *p, const char *cmd, fileDialog_in *in, fileDialog_out *out)
{
DEBUG_OUT << "[enter]" << std::endl;
std::vector<std::string> result;
// this function is called also from the C API: always run it in the correct thread
if(QThread::currentThreadId() == UI_THREAD)
UIProxy::getInstance()->onFileDialog(in->type, in->title, in->startPath, in->initName, in->extName, in->ext, in->native, &result);
else
UIFunctions::getInstance()->fileDialog(in->type, in->title, in->startPath, in->initName, in->extName, in->ext, in->native, &result);
for(auto x : result) out->result.push_back(x);
DEBUG_OUT << "[leave]" << std::endl;
}
void create(SScriptCallBack *p, const char *cmd, create_in *in, create_out *out)
{
ASSERT_THREAD(!UI);
DEBUG_OUT << "[enter]" << std::endl;
tinyxml2::XMLDocument xmldoc;
tinyxml2::XMLError error = xmldoc.Parse(in->xml.c_str(), in->xml.size());
if(error != tinyxml2::XML_NO_ERROR)
{
simSetLastError(cmd, "XML parse error");
return;
}
tinyxml2::XMLElement *rootElement = xmldoc.FirstChildElement();
std::map<int, Widget*> widgets;
Window *window = new Window;
try
{
window->parse(widgets, rootElement);
}
catch(std::exception& ex)
{
simSetLastError(cmd, ex.what());
delete window;
return;
}
// determine wether the Proxy object should be destroyed at simulation end
bool destroy = false;
int scriptProperty;
int objectHandle;
simGetScriptProperty(p->scriptID, &scriptProperty, &objectHandle);
int scriptType = (scriptProperty | sim_scripttype_threaded) - sim_scripttype_threaded;
if(scriptType == sim_scripttype_mainscript || scriptType == sim_scripttype_childscript)
destroy = true;
int sceneID = simGetInt32ParameterE(sim_intparam_scene_unique_id);
DEBUG_OUT << "Creating a new Proxy object... (destroy at simulation end = " << (destroy ? "true" : "false") << ")" << std::endl;
Proxy *proxy = new Proxy(destroy, sceneID, p->scriptID, window, widgets);
out->uiHandle = proxy->getHandle();
DEBUG_OUT << "Proxy " << proxy->getHandle() << " created in scene " << sceneID << std::endl;
DEBUG_OUT << "call UIFunctions::create() (will emit the create(Proxy*) signal)..." << std::endl;
UIFunctions::getInstance()->create(proxy); // connected to UIProxy, which
// will run code for creating Qt widgets in the UI thread
DEBUG_OUT << "[leave]" << std::endl;
}
void destroy(SScriptCallBack *p, const char *cmd, destroy_in *in, destroy_out *out)
{
ASSERT_THREAD(!UI);
DEBUG_OUT << "[enter]" << std::endl;
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
DEBUG_OUT << "invalid ui handle: " << in->handle << std::endl;
simSetLastError(cmd, "invalid ui handle");
return;
}
DEBUG_OUT << "call UIFunctions::destroy() (will emit the destroy(Proxy*) signal)..." << std::endl;
UIFunctions::getInstance()->destroy(proxy); // will also delete proxy
DEBUG_OUT << "[leave]" << std::endl;
}
Widget* getWidget(int handle, int id)
{
Widget *widget = Widget::byId(handle, id);
if(!widget)
{
std::stringstream ss;
ss << "invalid widget id: " << id;
throw std::runtime_error(ss.str());
}
return widget;
}
template<typename T>
T* getWidget(int handle, int id, const char *cmd, const char *widget_type_name)
{
T *twidget = dynamic_cast<T*>(getWidget(handle, id));
if(!twidget)
{
std::stringstream ss;
ss << "invalid widget type. expected " << widget_type_name << " (in function getWidget())";
throw std::runtime_error(ss.str());
}
return twidget;
}
template<typename T>
T* getQWidget(int handle, int id, const char *cmd, const char *widget_type_name)
{
Widget *widget = getWidget<Widget>(handle, id, cmd, widget_type_name);
T *qwidget = dynamic_cast<T*>(widget->getQWidget());
if(!qwidget)
{
std::stringstream ss;
ss << "invalid widget type. expected " << widget_type_name << " (in function getQWidget())";
throw std::runtime_error(ss.str());
}
return qwidget;
}
void setStyleSheet(SScriptCallBack *p, const char *cmd, setStyleSheet_in *in, setStyleSheet_out *out)
{
ASSERT_THREAD(!UI);
Widget *widget = getWidget(in->handle, in->id);
UIFunctions::getInstance()->setStyleSheet(widget, in->styleSheet);
}
void setButtonText(SScriptCallBack *p, const char *cmd, setButtonText_in *in, setButtonText_out *out)
{
#if WIDGET_BUTTON
ASSERT_THREAD(!UI);
Button *button = getWidget<Button>(in->handle, in->id, cmd, "button");
UIFunctions::getInstance()->setButtonText(button, in->text);
#endif
}
void setButtonPressed(SScriptCallBack *p, const char *cmd, setButtonPressed_in *in, setButtonPressed_out *out)
{
#if WIDGET_BUTTON
ASSERT_THREAD(!UI);
Button *button = getWidget<Button>(in->handle, in->id, cmd, "button");
UIFunctions::getInstance()->setButtonPressed(button, in->pressed);
#endif
}
void getSliderValue(SScriptCallBack *p, const char *cmd, getSliderValue_in *in, getSliderValue_out *out)
{
#if WIDGET_HSLIDER || WIDGET_VSLIDER
Slider *slider = getWidget<Slider>(in->handle, in->id, cmd, "slider");
out->value = slider->getValue();
#endif
}
void setSliderValue(SScriptCallBack *p, const char *cmd, setSliderValue_in *in, setSliderValue_out *out)
{
#if WIDGET_HSLIDER || WIDGET_VSLIDER
ASSERT_THREAD(!UI);
Slider *slider = getWidget<Slider>(in->handle, in->id, cmd, "slider");
UIFunctions::getInstance()->setSliderValue(slider, in->value, in->suppressEvents);
#endif
}
void getEditValue(SScriptCallBack *p, const char *cmd, getEditValue_in *in, getEditValue_out *out)
{
#if WIDGET_EDIT
Edit *edit = getWidget<Edit>(in->handle, in->id, cmd, "edit");
out->value = edit->getValue();
#endif
}
void setEditValue(SScriptCallBack *p, const char *cmd, setEditValue_in *in, setEditValue_out *out)
{
#if WIDGET_EDIT
ASSERT_THREAD(!UI);
Edit *edit = getWidget<Edit>(in->handle, in->id, cmd, "edit");
UIFunctions::getInstance()->setEditValue(edit, in->value, in->suppressEvents);
#endif
}
void getSpinboxValue(SScriptCallBack *p, const char *cmd, getSpinboxValue_in *in, getSpinboxValue_out *out)
{
#if WIDGET_SPINBOX
Spinbox *spinbox = getWidget<Spinbox>(in->handle, in->id, cmd, "spinbox");
out->value = spinbox->getValue();
#endif
}
void setSpinboxValue(SScriptCallBack *p, const char *cmd, setSpinboxValue_in *in, setSpinboxValue_out *out)
{
#if WIDGET_SPINBOX
ASSERT_THREAD(!UI);
Spinbox *spinbox = getWidget<Spinbox>(in->handle, in->id, cmd, "spinbox");
UIFunctions::getInstance()->setSpinboxValue(spinbox, in->value, in->suppressEvents);
#endif
}
void getCheckboxValue(SScriptCallBack *p, const char *cmd, getCheckboxValue_in *in, getCheckboxValue_out *out)
{
#if WIDGET_CHECKBOX
Checkbox *checkbox = getWidget<Checkbox>(in->handle, in->id, cmd, "checkbox");
out->value = checkbox->convertValueToInt(checkbox->getValue());
#endif
}
void setCheckboxValue(SScriptCallBack *p, const char *cmd, setCheckboxValue_in *in, setCheckboxValue_out *out)
{
#if WIDGET_CHECKBOX
ASSERT_THREAD(!UI);
Checkbox *checkbox = getWidget<Checkbox>(in->handle, in->id, cmd, "checkbox");
Qt::CheckState value = checkbox->convertValueFromInt(in->value);
UIFunctions::getInstance()->setCheckboxValue(checkbox, value, in->suppressEvents);
#endif
}
void getRadiobuttonValue(SScriptCallBack *p, const char *cmd, getRadiobuttonValue_in *in, getRadiobuttonValue_out *out)
{
#if WIDGET_RADIOBUTTON
Radiobutton *radiobutton = getWidget<Radiobutton>(in->handle, in->id, cmd, "radiobutton");
out->value = radiobutton->convertValueToInt(radiobutton->getValue());
#endif
}
void setRadiobuttonValue(SScriptCallBack *p, const char *cmd, setRadiobuttonValue_in *in, setRadiobuttonValue_out *out)
{
#if WIDGET_RADIOBUTTON
ASSERT_THREAD(!UI);
Radiobutton *radiobutton = getWidget<Radiobutton>(in->handle, in->id, cmd, "radiobutton");
bool value = radiobutton->convertValueFromInt(in->value);
UIFunctions::getInstance()->setRadiobuttonValue(radiobutton, value, in->suppressEvents);
#endif
}
void getLabelText(SScriptCallBack *p, const char *cmd, getLabelText_in *in, getLabelText_out *out)
{
#if WIDGET_LABEL
Label *label = getWidget<Label>(in->handle, in->id, cmd, "label");
out->text = label->getText();
#endif
}
void setLabelText(SScriptCallBack *p, const char *cmd, setLabelText_in *in, setLabelText_out *out)
{
#if WIDGET_LABEL
ASSERT_THREAD(!UI);
Label *label = getWidget<Label>(in->handle, in->id, cmd, "label");
UIFunctions::getInstance()->setLabelText(label, in->text, in->suppressEvents);
#endif
}
void insertComboboxItem(SScriptCallBack *p, const char *cmd, insertComboboxItem_in *in, insertComboboxItem_out *out)
{
#if WIDGET_COMBOBOX
ASSERT_THREAD(!UI);
Combobox *combobox = getWidget<Combobox>(in->handle, in->id, cmd, "combobox");
UIFunctions::getInstance()->insertComboboxItem(combobox, in->index, in->text, in->suppressEvents);
#endif
}
void removeComboboxItem(SScriptCallBack *p, const char *cmd, removeComboboxItem_in *in, removeComboboxItem_out *out)
{
#if WIDGET_COMBOBOX
ASSERT_THREAD(!UI);
Combobox *combobox = getWidget<Combobox>(in->handle, in->id, cmd, "combobox");
UIFunctions::getInstance()->removeComboboxItem(combobox, in->index, in->suppressEvents);
#endif
}
void getComboboxItemCount(SScriptCallBack *p, const char *cmd, getComboboxItemCount_in *in, getComboboxItemCount_out *out)
{
#if WIDGET_COMBOBOX
Combobox *combobox = getWidget<Combobox>(in->handle, in->id, cmd, "combobox");
out->count = combobox->count();
#endif
}
void getComboboxItemText(SScriptCallBack *p, const char *cmd, getComboboxItemText_in *in, getComboboxItemText_out *out)
{
#if WIDGET_COMBOBOX
Combobox *combobox = getWidget<Combobox>(in->handle, in->id, cmd, "combobox");
out->text = combobox->itemText(in->index);
#endif
}
void getComboboxItems(SScriptCallBack *p, const char *cmd, getComboboxItems_in *in, getComboboxItems_out *out)
{
#if WIDGET_COMBOBOX
Combobox *combobox = getWidget<Combobox>(in->handle, in->id, cmd, "combobox");
out->items = combobox->getItems();
#endif
}
void setComboboxItems(SScriptCallBack *p, const char *cmd, setComboboxItems_in *in, setComboboxItems_out *out)
{
#if WIDGET_COMBOBOX
ASSERT_THREAD(!UI);
Combobox *combobox = getWidget<Combobox>(in->handle, in->id, cmd, "combobox");
UIFunctions::getInstance()->setComboboxItems(combobox, in->items, in->index, in->suppressEvents);
#endif
}
void setComboboxSelectedIndex(SScriptCallBack *p, const char *cmd, setComboboxSelectedIndex_in *in, setComboboxSelectedIndex_out *out)
{
#if WIDGET_COMBOBOX
ASSERT_THREAD(!UI);
Combobox *combobox = getWidget<Combobox>(in->handle, in->id, cmd, "combobox");
UIFunctions::getInstance()->setComboboxSelectedIndex(combobox, in->index, in->suppressEvents);
#endif
}
void getComboboxSelectedIndex(SScriptCallBack *p, const char *cmd, getComboboxSelectedIndex_in *in, getComboboxSelectedIndex_out *out)
{
#if WIDGET_COMBOBOX
ASSERT_THREAD(!UI);
Combobox *combobox = getWidget<Combobox>(in->handle, in->id, cmd, "combobox");
out->index = combobox->getSelectedIndex();
#endif
}
void hide(SScriptCallBack *p, const char *cmd, hide_in *in, hide_out *out)
{
ASSERT_THREAD(!UI);
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
UIFunctions::getInstance()->hideWindow(proxy->getWidget());
}
void show(SScriptCallBack *p, const char *cmd, show_in *in, show_out *out)
{
ASSERT_THREAD(!UI);
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
UIFunctions::getInstance()->showWindow(proxy->getWidget());
}
void isVisible(SScriptCallBack *p, const char *cmd, isVisible_in *in, isVisible_out *out)
{
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
out->visibility = proxy->getWidget()->getQWidget()->isVisible();
}
void getPosition(SScriptCallBack *p, const char *cmd, getPosition_in *in, getPosition_out *out)
{
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
QWidget *window = proxy->getWidget()->getQWidget();
out->x = window->x();
out->y = window->y();
}
void setPosition(SScriptCallBack *p, const char *cmd, setPosition_in *in, setPosition_out *out)
{
ASSERT_THREAD(!UI);
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
Window *window = proxy->getWidget();
UIFunctions::getInstance()->setPosition(window, in->x, in->y);
}
void getSize(SScriptCallBack *p, const char *cmd, getSize_in *in, getSize_out *out)
{
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
QWidget *window = proxy->getWidget()->getQWidget();
out->w = window->width();
out->h = window->height();
}
void setSize(SScriptCallBack *p, const char *cmd, setSize_in *in, setSize_out *out)
{
ASSERT_THREAD(!UI);
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
Window *window = proxy->getWidget();
UIFunctions::getInstance()->setSize(window, in->w, in->h);
}
void getTitle(SScriptCallBack *p, const char *cmd, getTitle_in *in, getTitle_out *out)
{
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
QWidget *window = proxy->getWidget()->getQWidget();
out->title = static_cast<QDialog*>(window)->windowTitle().toStdString();
}
void setTitle(SScriptCallBack *p, const char *cmd, setTitle_in *in, setTitle_out *out)
{
ASSERT_THREAD(!UI);
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
Window *window = proxy->getWidget();
UIFunctions::getInstance()->setTitle(window, in->title);
}
void setImageData(SScriptCallBack *p, const char *cmd, setImageData_in *in, setImageData_out *out)
{
#if WIDGET_IMAGE
ASSERT_THREAD(!UI);
Image *imageWidget = dynamic_cast<Image*>(Widget::byId(in->handle, in->id));
if(!imageWidget)
{
std::stringstream ss;
ss << "invalid image widget id: " << in->id;
throw std::runtime_error(ss.str());
}
int bpp = 3; // bytes per pixel
int sz = in->width * in->height * bpp;
if(in->data.size() != sz)
{
std::stringstream ss;
ss << "bad image size. expected: " << sz << ". got: " << in->data.size() << ".";
throw std::runtime_error(ss.str());
}
simChar *img = simCreateBufferE(sz);
std::memcpy(img, in->data.c_str(), sz);
simInt resolution[2] = {in->width, in->height};
simTransformImage((simUChar *)img, resolution, 4, NULL, NULL, NULL);
UIFunctions::getInstance()->setImage(imageWidget, img, in->width, in->height);
#endif
}
void setEnabled(SScriptCallBack *p, const char *cmd, setEnabled_in *in, setEnabled_out *out)
{
ASSERT_THREAD(!UI);
Widget *widget = Widget::byId(in->handle, in->id);
if(!widget)
{
std::stringstream ss;
ss << "invalid widget id: " << in->id;
throw std::runtime_error(ss.str());
}
UIFunctions::getInstance()->setEnabled(widget, in->enabled);
}
void getCurrentTab(SScriptCallBack *p, const char *cmd, getCurrentTab_in *in, getCurrentTab_out *out)
{
#if WIDGET_TABS
QTabWidget *tabs = getQWidget<QTabWidget>(in->handle, in->id, cmd, "tabs");
out->index = tabs->currentIndex();
#endif
}
void setCurrentTab(SScriptCallBack *p, const char *cmd, setCurrentTab_in *in, setCurrentTab_out *out)
{
#if WIDGET_TABS
ASSERT_THREAD(!UI);
Tabs *tabs = getWidget<Tabs>(in->handle, in->id, cmd, "tabs");
UIFunctions::getInstance()->setCurrentTab(tabs, in->index, in->suppressEvents);
#endif
}
void getWidgetVisibility(SScriptCallBack *p, const char *cmd, getWidgetVisibility_in *in, getWidgetVisibility_out *out)
{
QWidget *widget = getQWidget<QWidget>(in->handle, in->id, cmd, "widget");
out->visibility = widget->isVisible();
}
void setWidgetVisibility(SScriptCallBack *p, const char *cmd, setWidgetVisibility_in *in, setWidgetVisibility_out *out)
{
ASSERT_THREAD(!UI);
Widget *widget = Widget::byId(in->handle, in->id);
if(!widget)
{
std::stringstream ss;
ss << "invalid widget id: " << in->id;
throw std::runtime_error(ss.str());
}
UIFunctions::getInstance()->setWidgetVisibility(widget, in->visibility);
}
void getCurrentEditWidget(SScriptCallBack *p, const char *cmd, getCurrentEditWidget_in *in, getCurrentEditWidget_out *out)
{
#if WIDGET_EDIT
Proxy *proxy = Proxy::byHandle(in->handle);
if(!proxy)
{
simSetLastError(cmd, "invalid ui handle");
return;
}
QWidget *window = proxy->getWidget()->getQWidget();
QLineEdit* qedit = NULL;
QList<QLineEdit*> wl = window->findChildren<QLineEdit*>(QString());
for(int i = 0; i < wl.size(); i++)
{
if(wl[i]->selectedText().size() > 0)
{
qedit = wl[i];
break;
}
}
Widget *edit = Widget::byQWidget(qedit);
if(edit)
out->id = edit->getId();
#endif
}
void setCurrentEditWidget(SScriptCallBack *p, const char *cmd, setCurrentEditWidget_in *in, setCurrentEditWidget_out *out)
{
#if WIDGET_EDIT
if(in->id == -1) return;
Edit *edit = getWidget<Edit>(in->handle, in->id, cmd, "edit");
QLineEdit *qedit = static_cast<QLineEdit*>(edit->getQWidget());
qedit->setFocus();
qedit->selectAll();
#endif
}
void replot(SScriptCallBack *p, const char *cmd, replot_in *in, replot_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->replot(plot);
#endif
}
void addCurve(SScriptCallBack *p, const char *cmd, addCurve_in *in, addCurve_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
plot->curveNameMustNotExist(in->name);
UIFunctions::getInstance()->addCurve(plot, in->type, in->name, in->color, in->style, &in->options);
#endif
}
void addCurveTimePoints(SScriptCallBack *p, const char *cmd, addCurveTimePoints_in *in, addCurveTimePoints_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
QCPAbstractPlottable *curve = plot->curveNameMustExist(in->name)->second;
plot->curveMustBeTime(curve);
UIFunctions::getInstance()->addCurveTimePoints(plot, in->name, in->x, in->y);
#endif
}
void addCurveXYPoints(SScriptCallBack *p, const char *cmd, addCurveXYPoints_in *in, addCurveXYPoints_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
QCPAbstractPlottable *curve = plot->curveNameMustExist(in->name)->second;
plot->curveMustBeXY(curve);
UIFunctions::getInstance()->addCurveXYPoints(plot, in->name, in->t, in->x, in->y);
#endif
}
void clearCurve(SScriptCallBack *p, const char *cmd, clearCurve_in *in, clearCurve_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
plot->curveNameMustExist(in->name);
UIFunctions::getInstance()->clearCurve(plot, in->name);
#endif
}
void removeCurve(SScriptCallBack *p, const char *cmd, removeCurve_in *in, removeCurve_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
plot->curveNameMustExist(in->name);
UIFunctions::getInstance()->removeCurve(plot, in->name);
#endif
}
void setPlotRanges(SScriptCallBack *p, const char *cmd, setPlotRanges_in *in, setPlotRanges_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->setPlotRanges(plot, in->xmin, in->xmax, in->ymin, in->ymax);
#endif
}
void setPlotXRange(SScriptCallBack *p, const char *cmd, setPlotXRange_in *in, setPlotXRange_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->setPlotXRange(plot, in->xmin, in->xmax);
#endif
}
void setPlotYRange(SScriptCallBack *p, const char *cmd, setPlotYRange_in *in, setPlotYRange_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->setPlotYRange(plot, in->ymin, in->ymax);
#endif
}
void growPlotRanges(SScriptCallBack *p, const char *cmd, growPlotRanges_in *in, growPlotRanges_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->growPlotRanges(plot, in->xmin, in->xmax, in->ymin, in->ymax);
#endif
}
void growPlotXRange(SScriptCallBack *p, const char *cmd, growPlotXRange_in *in, growPlotXRange_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->growPlotXRange(plot, in->xmin, in->xmax);
#endif
}
void growPlotYRange(SScriptCallBack *p, const char *cmd, growPlotYRange_in *in, growPlotYRange_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->growPlotYRange(plot, in->ymin, in->ymax);
#endif
}
void setPlotLabels(SScriptCallBack *p, const char *cmd, setPlotLabels_in *in, setPlotLabels_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->setPlotLabels(plot, in->x, in->y);
#endif
}
void setPlotXLabel(SScriptCallBack *p, const char *cmd, setPlotXLabel_in *in, setPlotXLabel_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->setPlotXLabel(plot, in->label);
#endif
}
void setPlotYLabel(SScriptCallBack *p, const char *cmd, setPlotYLabel_in *in, setPlotYLabel_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->setPlotYLabel(plot, in->label);
#endif
}
void rescaleAxes(SScriptCallBack *p, const char *cmd, rescaleAxes_in *in, rescaleAxes_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
plot->curveNameMustExist(in->name);
UIFunctions::getInstance()->rescaleAxes(plot, in->name, in->onlyEnlargeX, in->onlyEnlargeY);
#endif
}
void rescaleAxesAll(SScriptCallBack *p, const char *cmd, rescaleAxesAll_in *in, rescaleAxesAll_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->rescaleAxesAll(plot, in->onlyEnlargeX, in->onlyEnlargeY);
#endif
}
void setMouseOptions(SScriptCallBack *p, const char *cmd, setMouseOptions_in *in, setMouseOptions_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->setMouseOptions(plot, in->panX, in->panY, in->zoomX, in->zoomY);
#endif
}
void setLegendVisibility(SScriptCallBack *p, const char *cmd, setLegendVisibility_in *in, setLegendVisibility_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
UIFunctions::getInstance()->setLegendVisibility(plot, in->visible);
#endif
}
void getCurveData(SScriptCallBack *p, const char *cmd, getCurveData_in *in, getCurveData_out *out)
{
#if WIDGET_PLOT
Plot *plot = getWidget<Plot>(in->handle, in->id, cmd, "plot");
plot->getCurveData(in->name, out->x, out->x, out->y);
#endif
}
void clearTable(SScriptCallBack *p, const char *cmd, clearTable_in *in, clearTable_out *out)
{
#if WIDGET_TABLE
Table *table = getWidget<Table>(in->handle, in->id, cmd, "table");
UIFunctions::getInstance()->clearTable(table, in->suppressEvents);
#endif
}
void setRowCount(SScriptCallBack *p, const char *cmd, setRowCount_in *in, setRowCount_out *out)
{
#if WIDGET_TABLE
Table *table = getWidget<Table>(in->handle, in->id, cmd, "table");
UIFunctions::getInstance()->setRowCount(table, in->count, in->suppressEvents);
#endif
}
void setColumnCount(SScriptCallBack *p, const char *cmd, setColumnCount_in *in, setColumnCount_out *out)
{
Widget *widget = getWidget(in->handle, in->id);
#if WIDGET_TABLE
if(Table *table = dynamic_cast<Table*>(widget))
{
UIFunctions::getInstance()->setColumnCountTable(table, in->count, in->suppressEvents);
return;
}
#endif
#if WIDGET_TREE
if(Tree *tree = dynamic_cast<Tree*>(widget))
{
UIFunctions::getInstance()->setColumnCountTree(tree, in->count, in->suppressEvents);
return;
}
#endif
#if WIDGET_TABLE && WIDGET_TREE
throw std::runtime_error("invalid widget type. expected table or tree.");
#elif WIDGET_TABLE
throw std::runtime_error("invalid widget type. expected table.");
#elif WIDGET_TREE
throw std::runtime_error("invalid widget type. expected tree.");
#endif
}
void setItem(SScriptCallBack *p, const char *cmd, setItem_in *in, setItem_out *out)
{
#if WIDGET_TABLE
Table *table = getWidget<Table>(in->handle, in->id, cmd, "table");
UIFunctions::getInstance()->setItem(table, in->row, in->column, in->text, in->suppressEvents);
#endif
}
void setItemImage(SScriptCallBack *p, const char *cmd, setItemImage_in *in, setItemImage_out *out)
{
#if WIDGET_TABLE
Table *table = getWidget<Table>(in->handle, in->id, cmd, "table");
UIFunctions::getInstance()->setItemImage(table, in->row, in->column, in->data, in->width, in->height, in->suppressEvents);
#endif
}
void getRowCount(SScriptCallBack *p, const char *cmd, getRowCount_in *in, getRowCount_out *out)
{
#if WIDGET_TABLE
Table *table = getWidget<Table>(in->handle, in->id, cmd, "table");
out->count = table->getRowCount();
#endif
}
void getColumnCount(SScriptCallBack *p, const char *cmd, getColumnCount_in *in, getColumnCount_out *out)
{
Widget *widget = getWidget(in->handle, in->id);
#if WIDGET_TABLE
if(Table *table = dynamic_cast<Table*>(widget))
{
out->count = table->getColumnCount();
return;
}
#endif
#if WIDGET_TREE
if(Tree *tree = dynamic_cast<Tree*>(widget))
{
out->count = tree->getColumnCount();
return;
}
#endif
#if WIDGET_TABLE && WIDGET_TREE
throw std::runtime_error("invalid widget type. expected table or tree.");
#elif WIDGET_TABLE
throw std::runtime_error("invalid widget type. expected table.");
#elif WIDGET_TREE
throw std::runtime_error("invalid widget type. expected tree.");
#endif
}
void getItem(SScriptCallBack *p, const char *cmd, getItem_in *in, getItem_out *out)
{
#if WIDGET_TABLE
Table *table = getWidget<Table>(in->handle, in->id, cmd, "table");
out->text = table->getItem(in->row, in->column);
#endif
}
void setRowHeaderText(SScriptCallBack *p, const char *cmd, setRowHeaderText_in *in, setRowHeaderText_out *out)
{
#if WIDGET_TABLE
Table *table = getWidget<Table>(in->handle, in->id, cmd, "table");
UIFunctions::getInstance()->setRowHeaderText(table, in->row, in->text);
#endif
}
void setColumnHeaderText(SScriptCallBack *p, const char *cmd, setColumnHeaderText_in *in, setColumnHeaderText_out *out)
{
Widget *widget = getWidget(in->handle, in->id);
#if WIDGET_TABLE
if(Table *table = dynamic_cast<Table*>(widget))
{
UIFunctions::getInstance()->setColumnHeaderTextTable(table, in->column, in->text);
return;
}
#endif
#if WIDGET_TREE
if(Tree *tree = dynamic_cast<Tree*>(widget))
{
UIFunctions::getInstance()->setColumnHeaderTextTree(tree, in->column, in->text);
return;
}
#endif
#if WIDGET_TABLE && WIDGET_TREE
throw std::runtime_error("invalid widget type. expected table or tree.");
#elif WIDGET_TABLE
throw std::runtime_error("invalid widget type. expected table.");
#elif WIDGET_TREE
throw std::runtime_error("invalid widget type. expected tree.");
#endif
}
void setItemEditable(SScriptCallBack *p, const char *cmd, setItemEditable_in *in, setItemEditable_out *out)
{
#if WIDGET_TABLE
Table *table = getWidget<Table>(in->handle, in->id, cmd, "table");
UIFunctions::getInstance()->setItemEditable(table, in->row, in->column, in->editable);
#endif
}
void saveState(SScriptCallBack *p, const char *cmd, saveState_in *in, saveState_out *out)
{
Widget *widget = getWidget(in->handle, in->id);
#if WIDGET_TABLE
if(Table *table = dynamic_cast<Table*>(widget))
{
out->state = table->saveState();
return;
}
#endif
#if WIDGET_TREE
if(Tree *tree = dynamic_cast<Tree*>(widget))
{
out->state = tree->saveState();
return;
}
#endif
#if WIDGET_TABLE && WIDGET_TREE
throw std::runtime_error("invalid widget type. expected table or tree.");
#elif WIDGET_TABLE
throw std::runtime_error("invalid widget type. expected table.");
#elif WIDGET_TREE
throw std::runtime_error("invalid widget type. expected tree.");
#endif
}
void restoreState(SScriptCallBack *p, const char *cmd, restoreState_in *in, restoreState_out *out)
{
Widget *widget = getWidget(in->handle, in->id);
#if WIDGET_TABLE
if(Table *table = dynamic_cast<Table*>(widget))
{
UIFunctions::getInstance()->restoreStateTable(table, in->state);
return;
}
#endif
#if WIDGET_TREE
if(Tree *tree = dynamic_cast<Tree*>(widget))
{
UIFunctions::getInstance()->restoreStateTree(tree, in->state);
return;
}
#endif
#if WIDGET_TABLE && WIDGET_TREE
throw std::runtime_error("invalid widget type. expected table or tree.");
#elif WIDGET_TABLE
throw std::runtime_error("invalid widget type. expected table.");
#elif WIDGET_TREE
throw std::runtime_error("invalid widget type. expected tree.");
#endif
}
void setRowHeight(SScriptCallBack *p, const char *cmd, setRowHeight_in *in, setRowHeight_out *out)
{
#if WIDGET_TABLE
Table *table = getWidget<Table>(in->handle, in->id, cmd, "table");
UIFunctions::getInstance()->setRowHeight(table, in->row, in->min_size, in->max_size);
#endif
}
void setColumnWidth(SScriptCallBack *p, const char *cmd, setColumnWidth_in *in, setColumnWidth_out *out)
{
Widget *widget = getWidget(in->handle, in->id);
#if WIDGET_TABLE
if(Table *table = dynamic_cast<Table*>(widget))
{
UIFunctions::getInstance()->setColumnWidthTable(table, in->column, in->min_size, in->max_size);
return;
}
#endif
#if WIDGET_TREE
if(Tree *tree = dynamic_cast<Tree*>(widget))
{
UIFunctions::getInstance()->setColumnWidthTree(tree, in->column, in->min_size, in->max_size);
return;
}
#endif
#if WIDGET_TABLE && WIDGET_TREE