forked from SpineML/SpineCreator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
experiment.cpp
3440 lines (2946 loc) · 138 KB
/
experiment.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
/***************************************************************************
** **
** This file is part of SpineCreator, an easy to use, GUI for **
** describing spiking neural network models. **
** Copyright (C) 2013 Alex Cope, Paul Richmond **
** **
** This program is free software: you can redistribute it and/or modify **
** it under the terms of the GNU General Public License as published by **
** the Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see http://www.gnu.org/licenses/. **
** **
****************************************************************************
** Author: Alex Cope **
** Website/Contact: http://bimpa.group.shef.ac.uk/ **
****************************************************************************/
#include "experiment.h"
#include "rootdata.h"
#include "projectobject.h"
//#include "stringify.h"
experiment::experiment()
{
QSettings settings;
QString localName = settings.value("versioning/localName", QHostInfo::localHostName()).toString();
version.setVersion(0,0,1,localName);
// defaults
setup.dt = 0.1;
setup.duration = 1;
setup.solver = ForwardEuler;
setup.simType = "BRAHMS";
setup.exptProcedure = SingleRun;
name = "New Experiment";
description = "add a description for the experiment here";
selected = false;
editing = true;
}
experiment::~experiment() {
for (uint i = 0; i < ins.size(); ++i) {
delete ins[i];
}
for (uint i = 0; i < outs.size(); ++i) {
delete outs[i];
}
for (uint i = 0; i < lesions.size(); ++i) {
delete lesions[i];
}
for (uint i = 0; i < changes.size(); ++i) {
delete changes[i];
}
}
experiment::experiment(experiment * /*exptToCopy*/)
{
// add copy constructor here
}
exptBox * experiment::getBox(viewELExptPanelHandler * panel) {
#ifdef Q_OS_MAC
QFont titleFont("Helvetica [Cronyx]", 16);
QFont descFont("Helvetica [Cronyx]", 12);
#else
QFont titleFont("Helvetica [Cronyx]", 14);
QFont descFont("Helvetica [Cronyx]", 8);
#endif
exptBox * box = new exptBox();
QGridLayout * layout = new QGridLayout;
box->setLayout(layout);
layout->setSpacing(0);
this->currBoxPtr = box;
int index = -1;
for (uint i = 0; i < panel->data->experiments.size(); ++i) {
if (panel->data->experiments[i] == this) index = i;
}
if (index == -1) {qDebug() << "experiments.cpp: big error"; exit(-1);}
if (editing)
{
#ifdef Q_OS_MAC
layout->setSpacing(6);
#endif
// set up the experiment editing box
// title
currBoxPtr->setStyleSheet("background-color :rgba(200,200,200,255)");
QRegExp regExp("[A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ][A-Za-z0-9 ]");
QRegExpValidator *validator = new QRegExpValidator(regExp, this);
QLineEdit * editTitle = new QLineEdit;
editTitle->setValidator(validator);
editTitle->setText(name);
editTitle->setMaximumWidth(401);
layout->addWidget(editTitle,0,0,1,1);
// description
QTextEdit * editDesc = new QTextEdit;
editDesc->setMaximumWidth(400);
editDesc->setPlainText(description);
layout->addWidget(editDesc,1,0,2,1);
// done button
QPushButton * done = new QPushButton("Done");
done->setProperty("index", (uint) index);
done->setProperty("title", qVariantFromValue((void *) editTitle));
done->setProperty("desc", qVariantFromValue((void *) editDesc));
QObject::connect(done, SIGNAL(clicked()), panel, SLOT(doneEditExperiment()));
layout->addWidget(done,0,2,1,1);
// cancel button
QPushButton * cancel = new QPushButton("Cancel");
cancel->setProperty("index", (uint) index);
QObject::connect(cancel, SIGNAL(clicked()), panel, SLOT(cancelEditExperiment()));
layout->addWidget(cancel,1,2,1,1);
return box;
}
if (selected)
{
// set up a selected box
currBoxPtr->setStyleSheet("background-color :rgba(0,0,0,40)");
// title
QLabel * nameLabel = new QLabel(name);
nameLabel->setFont(titleFont);
nameLabel->setStyleSheet("background-color :transparent");
nameLabel->setMinimumWidth(200);
layout->addWidget(nameLabel,0,0,1,1);
// dexription
QLabel * descLabel = new QLabel(description);
descLabel->setStyleSheet("background-color :transparent");
descLabel->setMinimumWidth(200);
descLabel->setWordWrap(true);
descLabel->setFont(descFont);
layout->addWidget(descLabel,1,0,2,1);
// a label to make the layout look nice
QLabel * spacerLabel = new QLabel();
spacerLabel->setStyleSheet("background-color :transparent");
layout->addWidget(spacerLabel,1,1,1,2);
// up and down buttons
QPushButton * up = new QPushButton;
up->setMaximumWidth(32);
up->setFlat(true);
up->setIcon(QIcon(":/icons/toolbar/up.png"));
up->setProperty("index", (uint) index);
up->setProperty("type", 1);
layout->addWidget(up,0,2,1,1);
QObject::connect(up, SIGNAL(clicked()), panel, SLOT(moveExperiment()));
QPushButton * down = new QPushButton;
down->setMaximumWidth(32);
down->setFlat(true);
down->setIcon(QIcon(":/icons/toolbar/down.png"));
down->setProperty("index", (uint) index);
down->setProperty("type", 0);
layout->addWidget(down,0,3,1,1);
QObject::connect(down, SIGNAL(clicked()), panel, SLOT(moveExperiment()));
if (index == 0) {
up->setEnabled(false);
}
if (index == (int) panel->data->experiments.size()-1) {
down->setEnabled(false);
}
// edit button
QPushButton * edit = new QPushButton;
edit->setMaximumWidth(32);
//edit->setIconSize(QSize(32,32));
edit->setFlat(true);
edit->setIcon(QIcon(":/icons/toolbar/edit.png"));
edit->setProperty("index", (uint) index);
layout->addWidget(edit,1,3,1,1);
QObject::connect(edit, SIGNAL(clicked()), panel, SLOT(editExperiment()));
// delete button
QPushButton * del = new QPushButton;
del->setMaximumWidth(32);
del->setFlat(true);
del->setIcon(QIcon(":/icons/toolbar/delShad.png"));
del->setProperty("index", (uint) index);
layout->addWidget(del,2,3,1,1);
QObject::connect(del, SIGNAL(clicked()), panel, SLOT(delExperiment()));
}
else
{
// set up an unselected box
currBoxPtr->setStyleSheet("background-color :transparent");
QLabel * nameLabel = new QLabel(name);
layout->addWidget(nameLabel,0,0,1,1);
nameLabel->setFont(titleFont);
QPushButton * up = new QPushButton;
up->setMaximumWidth(32);
up->setFlat(true);
up->setIcon(QIcon(":/icons/toolbar/up.png"));
up->setProperty("index", (uint) index);
up->setProperty("type", 1);
layout->addWidget(up,0,2,1,1);
QObject::connect(up, SIGNAL(clicked()), panel, SLOT(moveExperiment()));
QPushButton * down = new QPushButton;
down->setMaximumWidth(32);
down->setFlat(true);
down->setIcon(QIcon(":/icons/toolbar/down.png"));
down->setProperty("index", (uint) index);
down->setProperty("type", 0);
layout->addWidget(down,0,3,1,1);
QObject::connect(down, SIGNAL(clicked()), panel, SLOT(moveExperiment()));
if (index == 0) {
up->setEnabled(false);
}
if (index == (int) panel->data->experiments.size()-1) {
down->setEnabled(false);
}
}
return box;
}
void experiment::select(vector < experiment * > * experiments) {
// deselect all
for (uint i = 0; i < experiments->size(); ++i) {
(*experiments)[i]->deselect();
(*experiments)[i]->editing = false;
}
// select this experiment
this->selected = true;
}
void experiment::deselect() {
// select this experiment
this->selected = false;
}
void experiment::purgeBadPointer(systemObject * ptr) {
if (ptr->type == populationObject) {
purgeBadPointer(((population *) ptr)->neuronType);
}
if (ptr->type == projectionObject) {
projection * proj = (projection *) ptr;
for (uint i = 0; i < proj->synapses.size(); ++i) {
purgeBadPointer(proj->synapses[i]->postsynapseType);
purgeBadPointer(proj->synapses[i]->weightUpdateType);
}
}
if (ptr->type == inputObject) {
// no components, only need to remove from lesions (AJC 25/09/2012 - actually we are not having generic input lesions, so no need)
}
// lesions
for (uint i = 0; i < lesions.size(); ++i) {
if (lesions[i]->proj == ptr) {
delete lesions[i];
lesions.erase(lesions.begin()+i);
--i;
}
}
}
void experiment::purgeBadPointer(NineMLComponentData * ptr) {
// inputs
for (uint i = 0; i < ins.size(); ++i) {
exptInput * in = ins[i];
// are we using the component?
if (in->target == ptr) {
ins.erase(ins.begin()+i);
delete in;
--i;
}
}
// outputs
for (uint i = 0; i < outs.size(); ++i) {
exptOutput * out = outs[i];
// are we using the component?
if (out->source == ptr) {
outs.erase(outs.begin()+i);
delete out;
--i;
}
}
// pars
for (uint i = 0; i < changes.size(); ++i) {
exptChangeProp * change = changes[i];
// are we using the component?
if (change->component == ptr) {
changes.erase(changes.begin()+i);
delete change;
--i;
}
}
}
void experiment::purgeBadPointer(NineMLComponent * ptr, NineMLComponent * newPtr) {
// inputs
for (uint i = 0; i < ins.size(); ++i) {
exptInput * in = ins[i];
// are we using the component?
if (in->target->component == ptr && in->portName.size() > 0) {
// if so, update
// port
bool portFound = false;
if (in->portIsAnalog) {
for (uint j = 0; j < newPtr->AnalogPortList.size(); ++j)
if (newPtr->AnalogPortList[j]->name == in->portName && (newPtr->AnalogPortList[j]->mode == AnalogRecvPort || newPtr->AnalogPortList[j]->mode == AnalogReducePort)) {
portFound = true;
}
} else {
for (uint j = 0; j < newPtr->EventPortList.size(); ++j)
if (newPtr->EventPortList[j]->name == in->portName && newPtr->EventPortList[j]->mode == EventRecvPort){
portFound = true;
}
for (uint j = 0; j < newPtr->ImpulsePortList.size(); ++j)
if (newPtr->ImpulsePortList[j]->name == in->portName && newPtr->ImpulsePortList[j]->mode == ImpulseRecvPort){
portFound = true;
}
}
// if not found
if (!portFound) {
in->portName = "";
in->set = false;
in->edit = true;
}
// component
in->target->component = newPtr;
}
}
// outputs
for (uint i = 0; i < outs.size(); ++i) {
exptOutput * out = outs[i];
// are we using the component?
if (out->source->component == ptr && out->portName.size() > 0) {
// if so, update
// port
bool portFound = false;
if (out->portIsAnalog) {
for (uint j = 0; j < newPtr->AnalogPortList.size(); ++j)
if (newPtr->AnalogPortList[j]->name == out->portName && newPtr->AnalogPortList[j]->mode == AnalogSendPort) {
portFound = true;
}
} else {
for (uint j = 0; j < newPtr->EventPortList.size(); ++j)
if (newPtr->EventPortList[j]->name == out->portName && newPtr->EventPortList[j]->mode== EventSendPort){
portFound = true;
}
for (uint j = 0; j < newPtr->ImpulsePortList.size(); ++j)
if (newPtr->ImpulsePortList[j]->name == out->portName && newPtr->ImpulsePortList[j]->mode == ImpulseSendPort){
portFound = true;
}
}
// if not found
if (!portFound) {
out->portName = "";
out->set = false;
out->edit = true;
qDebug() << "moo3";
}
// component
out->source->component = newPtr;
}
}
}
void experiment::updateChanges(NineMLComponentData * ptr) {
// par changes
for (uint i = 0; i < changes.size(); ++i) {
exptChangeProp * change = changes[i];
// are we using the component?
if (change->component == ptr) {
// if so, update
// property
bool propFound = false;
for (uint j = 0; j < ptr->ParameterList.size(); ++j)
if (ptr->ParameterList[j]->name == change->par->name) {
propFound = true;
delete change->par;
change->par = new ParameterData(ptr->ParameterList[j]);
}
for (uint j = 0; j < ptr->StateVariableList.size(); ++j)
if (ptr->StateVariableList[j]->name == change->par->name){
propFound = true;
delete change->par;
change->par = new StateVariableData(ptr->StateVariableList[j]);
}
// if not found
if (!propFound) {
change->par = NULL;
change->set = false;
change->edit = true;
}
// component
change->component = ptr;
}
}
}
// ################################## exptBox
exptBox::exptBox( QWidget * parent ):QFrame(parent)
{
this->setStyleSheet("background-color :transparent");
}
void exptBox::mouseReleaseEvent ( QMouseEvent * )
{
emit clicked();
}
// ################################### exptIn
QVBoxLayout * exptInput::drawInput(rootData * data, viewELExptPanelHandler *handler) {
QVBoxLayout * layout = new QVBoxLayout;
bool portsExist = false;
QStringList elementList;
for (uint i = 0; i < data->system.size(); ++i) {
portsExist = false;
for (uint p = 0; p < data->system[i]->neuronType->component->AnalogPortList.size(); ++p) {
if (data->system[i]->neuronType->component->AnalogPortList[p]->mode== AnalogRecvPort \
|| data->system[i]->neuronType->component->AnalogPortList[p]->mode== AnalogReducePort) {
portsExist = true;
break;
}
}
if (!portsExist) {
// if it is a spike source we don't care about the component
if (data->system[i]->isSpikeSource) {
portsExist = true;
}
}
if (portsExist)
elementList << data->system[i]->neuronType->getXMLName();
for (uint j = 0; j < data->system[i]->projections.size(); ++j) {
for (uint k = 0; k < data->system[i]->projections[j]->synapses.size(); ++k) {
portsExist = false;
for (uint p = 0; p < data->system[i]->projections[j]->synapses[k]->weightUpdateType->component->AnalogPortList.size(); ++p) {
if (data->system[i]->projections[j]->synapses[k]->weightUpdateType->component->AnalogPortList[p]->mode== AnalogRecvPort \
|| data->system[i]->projections[j]->synapses[k]->weightUpdateType->component->AnalogPortList[p]->mode== AnalogReducePort) {
portsExist = true;
break;
}
}
/*if (!portsExist) {
for (uint p = 0; p < data->network[i]->projections[j]->synapses[k]->weightUpdateType->component->EventPortList.size(); ++p) {
if (data->network[i]->projections[j]->synapses[k]->weightUpdateType->component->EventPortList[p]->mode== EventRecvPort && (data->network[i]->neuronType->component->name == "SpikeSource")) {
portsExist = true;
break;
}
}
}*/
if (portsExist)
elementList << data->system[i]->projections[j]->synapses[k]->weightUpdateType->getXMLName();
portsExist = false;
for (uint p = 0; p < data->system[i]->projections[j]->synapses[k]->postsynapseType->component->AnalogPortList.size(); ++p) {
if (data->system[i]->projections[j]->synapses[k]->postsynapseType->component->AnalogPortList[p]->mode== AnalogRecvPort \
|| data->system[i]->projections[j]->synapses[k]->postsynapseType->component->AnalogPortList[p]->mode== AnalogReducePort) {
portsExist = true;
break;
}
}
/*if (!portsExist) {
for (uint p = 0; p < data->network[i]->projections[j]->synapses[k]->postsynapseType->component->EventPortList.size(); ++p) {
if (data->network[i]->projections[j]->synapses[k]->postsynapseType->component->EventPortList[p]->mode== EventRecvPort && (data->network[i]->neuronType->component->name == "SpikeSource")) {
portsExist = true;
break;
}
}
}*/
if (portsExist)
elementList << data->system[i]->projections[j]->synapses[k]->postsynapseType->getXMLName();
}
}
}
if (edit) {
// frame to add
QFrame * frame = new QFrame;
#ifndef Q_OS_MAC
frame->setStyleSheet("background-color :rgba(0,0,0,40)");
#endif
layout->addWidget(frame);
frame->setMaximumWidth(380);
frame->setContentsMargins(0,0,0,0);
// new layout to contain name and port boxes
QHBoxLayout * nameAndPort = new QHBoxLayout;
frame->setLayout(new QVBoxLayout);
QVBoxLayout *frameLay = (QVBoxLayout *) frame->layout();
// input name
QLineEdit * nameEdit = new QLineEdit;
nameEdit->setText(this->name);
nameEdit->setProperty("ptr", qVariantFromValue((void *) this));
connect(nameEdit, SIGNAL(editingFinished()), handler, SLOT(setInputName()));
frameLay->addWidget(nameEdit);
frameLay->addLayout(nameAndPort);
frameLay->setContentsMargins(0,0,0,0);
frameLay->setSpacing(0);
nameAndPort->setContentsMargins(0,0,0,0);
nameAndPort->setSpacing(2);
// add Component LineEdit
QLineEdit * lineEdit = new QLineEdit;
if (set) {
lineEdit->setText(this->target->getXMLName());
} else {
lineEdit->setText("Type component name");
}
QCompleter *completer = new QCompleter(elementList, this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
lineEdit->setCompleter(completer);
lineEdit->setMaximumWidth(220);
lineEdit->setProperty("ptr", qVariantFromValue((void *) this));
connect(lineEdit, SIGNAL(editingFinished()), handler, SLOT(setInputComponent()));
nameAndPort->addWidget(lineEdit);
// add port dropdown
QComboBox * portBox = new QComboBox;
portBox->setMaximumWidth(90);
if (set) {
// if broken
if (!data->isValidPointer(this->target)) {
set = false;
return this->drawInput(data, handler);
}
// if spike source
if (this->target->owner->type == populationObject) {
if (((population *) this->target->owner)->isSpikeSource) {
portBox->addItem("spike in");
portBox->setDisabled(true);
// point to dummy event port
portName = "in";
portIsAnalog = false;
}
}
// add
portBox->addItem("AnalogPorts");
int currentRow = 0;
QModelIndex ind = portBox->model()->index(currentRow,0);
portBox->model()->setData(ind, QVariant(0), Qt::UserRole-1);
++currentRow;
for (uint i = 0; i < this->target->component->AnalogPortList.size(); ++i) {
if (this->target->component->AnalogPortList[i]->mode == AnalogRecvPort || this->target->component->AnalogPortList[i]->mode == AnalogReducePort) {
portBox->addItem(this->target->component->AnalogPortList[i]->name, qVariantFromValue((void *) this->target->component->AnalogPortList[i]));
if (portName.size() == 0) {
portBox->setCurrentIndex(1);
this->portName = this->target->component->AnalogPortList[i]->name;
this->portIsAnalog = true;
} else {
if (this->portName == this->target->component->AnalogPortList[i]->name)
portBox->setCurrentIndex(currentRow);
}
++currentRow;
}
}
// not needed with spike sources
/*portBox->addItem("EventPorts");
ind = portBox->model()->index(currentRow,0);
portBox->model()->setData(ind, QVariant(0), Qt::UserRole-1);
for (uint i = 0; i < this->target->component->EventPortList.size(); ++i) {
if (this->target->component->EventPortList[i]->mode == EventRecvPort) {
portBox->addItem(this->target->component->EventPortList[i]->name, qVariantFromValue((void *) this->target->component->EventPortList[i]));
if (!(portBox->currentIndex() == 1)) {
if (port==NULL) {
portBox->setCurrentIndex(2);
this->port = this->target->component->EventPortList[i];
} else {
if (this->port == this->target->component->EventPortList[i])
portBox->setCurrentIndex(currentRow+1);
}
}
++currentRow;
}
}*/
} else {
portBox->setDisabled(true);
}
portBox->setProperty("ptr", qVariantFromValue((void *) this));
nameAndPort->addWidget(portBox);
connect(portBox, SIGNAL(currentIndexChanged(int)), handler, SLOT(setInputPort(int)));
// if input is set, then add the input type section
if (this->set) {
// Type dropdown
QComboBox * type = new QComboBox;
type->setProperty("ptr", qVariantFromValue((void *) this));
type->addItem(exptInLookup::toString(constant), (int) constant); if (this->inType == constant) type->setCurrentIndex(0);
type->addItem(exptInLookup::toString(arrayConstant), (int) arrayConstant); if (this->inType == arrayConstant) type->setCurrentIndex(1);
type->addItem(exptInLookup::toString(timevarying), (int) timevarying); if (this->inType == timevarying) type->setCurrentIndex(2);
type->addItem(exptInLookup::toString(arrayTimevarying), (int) arrayTimevarying); if (this->inType == arrayTimevarying) type->setCurrentIndex(3);
type->addItem(exptInLookup::toString(external), (int) external); if (this->inType == external) type->setCurrentIndex(4);
// spike source only for explicit spike list
if (!this->portIsAnalog)
type->addItem(exptInLookup::toString(spikeList), (int) spikeList); if (this->inType == spikeList) type->setCurrentIndex(5);
QObject ::connect(type, SIGNAL(currentIndexChanged(int)), handler, SLOT(setInputType(int)));
frameLay->addWidget(type);
// rate distribution
if (!this->portIsAnalog) {
QFormLayout * formLay = new QFormLayout;
QComboBox * dist = new QComboBox;
dist->addItem("Regular");
dist->addItem("Poisson");
if (rateDistribution == Regular)
dist->setCurrentIndex(0);
if (rateDistribution == Poisson)
dist->setCurrentIndex(1);
formLay->addRow("Rate distribution:", dist);
frameLay->addLayout(formLay);
dist->setProperty("ptr", qVariantFromValue((void *) this));
QObject ::connect(dist, SIGNAL(currentIndexChanged(int)), handler, SLOT(setInputRateDistributionType(int)));
}
// extra type bits
if (this->inType == constant) {
QFormLayout * formLay = new QFormLayout;
QDoubleSpinBox * spin = new QDoubleSpinBox;
spin->setMaximum(10000.0);
spin->setMinimum(0.0);
spin->setDecimals(6);
spin->setValue(this->params[0]);
frameLay->addLayout(formLay);
if (this->portIsAnalog)
formLay->addRow(" Value:", spin);
else
formLay->addRow(" Rate:", spin);
spin->setProperty("ptr", qVariantFromValue((void *) this));
QObject ::connect(spin, SIGNAL(valueChanged(double)), handler, SLOT(setInputTypeData(double)));
}
if (this->inType == timevarying) {
QGridLayout * gridlay = new QGridLayout;
gridlay->setMargin(0);
frameLay->addLayout(gridlay);
QTableWidget * table = new QTableWidget;
table->setProperty("ptr", qVariantFromValue((void *) this));
table->setItemDelegate(new NTableDelegate(table));
gridlay->addWidget(table,0,0,4,1);
table->setColumnCount(2);
// add items from params
if (params.size()<2) {
params.resize(2);
params[0] = 0;
params[1] = 1;
}
table->setRowCount(qCeil(params.size()/2));
for (uint i = 0; i < params.size(); ++i) {
QTableWidgetItem * item = new QTableWidgetItem;
item->setData(Qt::DisplayRole, params[i]);
table->setItem(qFloor(i/2), i%2, item);
}
// labels for header
QStringList headers;
headers.push_back("Time (ms)");
if (this->portIsAnalog)
headers.push_back("Value");
else
headers.push_back("Rate");
table->setHorizontalHeaderLabels(headers);
table->verticalHeader()->hide();
table->setMaximumWidth(220);
QObject::connect(table, SIGNAL(cellChanged(int,int)), handler, SLOT(setInputParams(int,int)));
// add row
QPushButton * addRow = new QPushButton("Add row");
addRow->setProperty("ptr", qVariantFromValue((void *) this));
gridlay->addWidget(addRow,2,1,1,1);
QObject::connect(addRow, SIGNAL(clicked()), handler, SLOT(setInputAddTVRow()));
// del row
QPushButton * delRow = new QPushButton("Delete row");
delRow->setProperty("ptr", qVariantFromValue((void *) this));
gridlay->addWidget(delRow,3,1,1,1);
QObject::connect(delRow, SIGNAL(clicked()), handler, SLOT(setInputDelTVRow()));
if (params.size() < 3) {
delRow->setDisabled(true);
}
}
if (this->inType == arrayConstant) {
QGridLayout * gridlay = new QGridLayout;
gridlay->setMargin(0);
frameLay->addLayout(gridlay);
QTableWidget * table = new QTableWidget;
table->setProperty("ptr", qVariantFromValue((void *) this));
table->setItemDelegate(new NTableDelegate(table));
gridlay->addWidget(table,0,0,4,1);
int componentSize;
if (this->target->owner->type == populationObject)
componentSize = ((population *) this->target->owner)->numNeurons;
if (this->target->owner->type == projectionObject)
componentSize = ((projection *) this->target->owner)->destination->numNeurons;
table->setColumnCount(1);
table->setRowCount(componentSize);
this->params.resize(componentSize,0);
// add items from params
for (uint i = 0; i < params.size(); ++i) {
QTableWidgetItem * item = new QTableWidgetItem;
item->setData(Qt::DisplayRole, params[i]);
table->setItem(i, 0, item);
}
// fill with values
QDoubleSpinBox * fillValue = new QDoubleSpinBox;
fillValue->setMinimum(-10000.0);
fillValue->setMaximum(10000.0);
fillValue->setDecimals(6);
gridlay->addWidget(fillValue,0,1,1,1);
QPushButton * fill = new QPushButton("Fill");
fill->setToolTip("Fill all indices with the value above");
gridlay->addWidget(fill,1,1,1,1);
fill->setProperty("ptr", qVariantFromValue((void *) this));
fill->setProperty("ptrSpin", qVariantFromValue((void *) fillValue));
QObject::connect(fill, SIGNAL(clicked()), handler, SLOT(fillInputParams()));
// labels for header
QStringList headers;
headers.push_back("Value");
table->setHorizontalHeaderLabels(headers);
table->setMaximumWidth(220);
QObject::connect(table, SIGNAL(cellChanged(int,int)), handler, SLOT(setInputParams(int,int)));
}
if (this->inType == arrayTimevarying) {
QGridLayout * gridlay = new QGridLayout;
gridlay->setMargin(0);
frameLay->addLayout(gridlay);
QTableWidget * table = new QTableWidget;
table->setProperty("ptr", qVariantFromValue((void *) this));
table->setItemDelegate(new NTableDelegate(table));
gridlay->addWidget(table,0,0,4,1);
table->setColumnCount(2);
// add items from params
int index = -1;
int indexIndex = 0;
bool indexFound = false;
for (uint i = 0; i < params.size(); i+=2) {
if (params[i] == -1) {
index = params[i+1];
indexIndex = i;
if (index == currentIndex)
indexFound = true;
continue;
}
if (index == currentIndex) {
table->setRowCount(table->rowCount()+1);
QTableWidgetItem * item = new QTableWidgetItem;
item->setData(Qt::DisplayRole, params[i]);
table->setItem(qFloor((i-indexIndex-2.0)/2.0), (i-indexIndex-2)%2, item);
item = new QTableWidgetItem;
item->setData(Qt::DisplayRole, params[i+1]);
table->setItem(qFloor((i+1-indexIndex-2.0)/2.0), (i+1-indexIndex-2)%2, item);
}
}
// if nothing found then add new
if (!indexFound) {
params.push_back(-1);
params.push_back(currentIndex);
params.push_back(0);
params.push_back(1);
table->setRowCount(1);
QTableWidgetItem * item = new QTableWidgetItem;
item->setData(Qt::DisplayRole, params[params.size()-2]);
table->setItem(0, 0, item);
item = new QTableWidgetItem;
item->setData(Qt::DisplayRole, params[params.size()-1]);
table->setItem(0, 1, item);
}
// labels for header
QStringList headers;
headers.push_back("Time (ms)");
if (this->portIsAnalog)
headers.push_back("Value");
else
headers.push_back("Rate");
table->setHorizontalHeaderLabels(headers);
table->verticalHeader()->hide();
table->setMaximumWidth(220);
QObject::connect(table, SIGNAL(cellChanged(int,int)), handler, SLOT(setInputParams(int,int)));
// index spinbox
QSpinBox * spin = new QSpinBox;
spin->setProperty("ptr", qVariantFromValue((void *) this));
spin->setMinimum(0);
int componentSize;
if (this->target->owner->type == populationObject)
componentSize = ((population *) this->target->owner)->numNeurons;
if (this->target->owner->type == projectionObject)
componentSize = ((projection *) this->target->owner)->destination->numNeurons;
spin->setMaximum(componentSize-1);
spin->setValue(currentIndex);
gridlay->addWidget(spin,0,1,1,1);
QObject::connect(spin, SIGNAL(valueChanged(int)), handler, SLOT(changeInputIndex(int)));
// add row
QPushButton * addRow = new QPushButton("Add row");
addRow->setProperty("ptr", qVariantFromValue((void *) this));
gridlay->addWidget(addRow,2,1,1,1);
QObject::connect(addRow, SIGNAL(clicked()), handler, SLOT(setInputAddTVRow()));
// del row
QPushButton * delRow = new QPushButton("Delete row");
delRow->setProperty("ptr", qVariantFromValue((void *) this));
gridlay->addWidget(delRow,3,1,1,1);
QObject::connect(delRow, SIGNAL(clicked()), handler, SLOT(setInputDelTVRow()));
if (params.size() < 3) {
delRow->setDisabled(true);
}
}
// external object is a bit different!
if (this->inType == external) {
QFormLayout * formlay = new QFormLayout;
formlay->setMargin(0);
frameLay->addLayout(formlay);
// add items from params
// command line
QLineEdit * command = new QLineEdit;
command->setProperty("ptr", qVariantFromValue((void *) this));
command->setProperty("type", "command");
command->setText(externalInput.commandline);
QObject ::connect(command, SIGNAL(editingFinished()), handler, SLOT(setInputExternalData()));
formlay->addRow("Command:", command);
// command line
QSpinBox * port = new QSpinBox;
port->setProperty("ptr", qVariantFromValue((void *) this));
port->setProperty("type", "port");
port->setMinimum(49152);
port->setMaximum(65535);
port->setValue(externalInput.port);
QObject ::connect(port, SIGNAL(valueChanged(int)), handler, SLOT(setInputExternalData()));
formlay->addRow("Port:", port);
// command line
QSpinBox * size = new QSpinBox;
size->setProperty("ptr", qVariantFromValue((void *) this));
size->setProperty("type", "size");
size->setMinimum(1);
size->setMaximum(100000000);
if (this->target->owner->type == populationObject)
this->externalInput.size = ((population *)this->target->owner)->numNeurons;
size->setValue(externalInput.size);
size->setEnabled(false);
QObject ::connect(size, SIGNAL(valueChanged(int)), handler, SLOT(setInputExternalData()));
formlay->addRow("Size:", size);
}
}
// accept all
QPushButton * accept = new QPushButton;
accept->setMaximumWidth(32);
accept->setFlat(true);
accept->setIcon(QIcon(":/icons/toolbar/acptShad.png"));
accept->setProperty("ptr", qVariantFromValue((void *) this));
nameAndPort->addWidget(accept);
if (!set)
accept->setDisabled(true);
QObject::connect(accept, SIGNAL(clicked()), handler, SLOT(acceptInput()));
// delete
QPushButton * del = new QPushButton;
del->setMaximumWidth(32);
del->setFlat(true);
del->setIcon(QIcon(":/icons/toolbar/delShad.png"));
del->setProperty("ptr", qVariantFromValue((void *) this));
nameAndPort->addWidget(del);
QObject::connect(del, SIGNAL(clicked()), handler, SLOT(delInput()));
} else {
// check for badness
if (!data->isValidPointer(this->target)) {
this->set = false;
this->edit = true;
return this->drawInput(data, handler);
}
// new layout to contain name and port boxes
QFrame * frame = new QFrame;
frame->setStyleSheet("background-color :rgba(255,255,255,255)");
layout->addWidget(frame);
QGridLayout * descAndEdit = new QGridLayout;
frame->setLayout(descAndEdit);
// add name
QLabel * name = new QLabel(this->name);
name->setMaximumWidth(200);
name->setWordWrap(true);
descAndEdit->addWidget(name,0,0,1,1);
QFont nameFont("Helvetica [Cronyx]", 12);
name->setFont(nameFont);
// create string:
QString desc;
desc = "Input to component <b>" + this->target->getXMLName() + "</b> port <b>" + this->portName + "</b>.\n";
if (this->inType == constant) {
if (this->portIsAnalog)
desc += "Constant analog input with a value of <b>" + QString::number(this->params[0]) + "</b>.";
else