-
Notifications
You must be signed in to change notification settings - Fork 7
/
SC_network_layer_rootlayout.cpp
1882 lines (1552 loc) · 72.8 KB
/
SC_network_layer_rootlayout.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-2014 Alex Cope, Paul Richmond, Seb James **
** **
** 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 "SC_network_layer_rootlayout.h"
#include "SC_projectobject.h"
#include "filteroutundoredoevents.h"
/*
Alex Cope 2012
The RootLayout class is the base layout for the sidebar which
holds the properties of the currently selected item, and allows
them to be set and modified.
*/
nl_rootlayout::nl_rootlayout(nl_rootdata * data, QWidget *parent) :
QVBoxLayout(parent)
{
//this->title = new QLabel("");
this->setSpacing(10);
initModelHeader(data);
initPopulationHeader(data);
initProjectionHeader(data);
initInputHeader(data);
initTabBox(data);
initTabBoxPopulation(data);
initTabBoxProjection(data);
initFinish(data);
// init state
emit hideHeader();
// configure model panel
//QSettings settings;
//emit setModelName(settings.value("model/model_name", "err").toString());
// show model panel
emit showModel();
}
nl_rootlayout::~nl_rootlayout() {
// remove all widgets / layouts
clearOld();
}
// add the stuff that we want
void nl_rootlayout::initModelHeader(nl_rootdata * data) {
// create model name dialog
QString model_name = data->currProject->name;
QFormLayout * titleLayout = new QFormLayout();
QLineEdit * name = new QLineEdit;
name->installEventFilter(new FilterOutUndoRedoEvents);
name->setText(model_name);
titleLayout->addRow("Model name", name);
this->addLayout(titleLayout);
// connect to update model name
connect(name,SIGNAL(editingFinished()), this, SLOT(modelNameChanged()));
// connect for hide
connect(this, SIGNAL(hideHeader()), name, SLOT(hide()));
connect(this, SIGNAL(hideHeader()), titleLayout->itemAt(0)->widget(), SLOT(hide()));
// connect for show
connect(this, SIGNAL(showModel()), name, SLOT(show()));
connect(this, SIGNAL(showModel()), titleLayout->itemAt(0)->widget(), SLOT(show()));
// connect for change
connect(this, SIGNAL(setModelName(QString)), name, SLOT(setText(QString)));
}
// add the stuff that we want
void nl_rootlayout::initPopulationHeader(nl_rootdata * data) {
////// TITLE
// add title display
QHBoxLayout * titleLayout = new QHBoxLayout();
QString titleString = "<u><b>temp</b></u>";
QLabel *title = new QLabel(titleString);
titleLayout->addWidget(title);
QPushButton * titleRename = new QPushButton("Rename");
titleRename->setFixedWidth(80);
titleLayout->addWidget(titleRename);
// add title rename (hidden)
QHBoxLayout * renameLayout = new QHBoxLayout();
QLineEdit * renameBox = new QLineEdit();
renameBox->setText("temp");
renameBox->hide();
renameLayout->addWidget(renameBox);
QPushButton * renameDone = new QPushButton("Done");
renameDone->setFixedWidth(80);
renameDone->hide();
renameLayout->addWidget(renameDone);
// pointers to set the names to the final name
renameDone->setProperty("ptrTitle", qVariantFromValue((void *) title));
renameBox->setProperty("ptrTitle", qVariantFromValue((void *) title));
renameDone->setProperty("ptrRename", qVariantFromValue((void *) renameBox));
renameBox->setProperty("ptrRename", qVariantFromValue((void *) renameBox));
// connect up for hiding / showing
connect(titleRename, SIGNAL(clicked()), title, SLOT(hide()));
connect(titleRename, SIGNAL(clicked()), titleRename, SLOT(hide()));
connect(titleRename, SIGNAL(clicked()), renameBox, SLOT(show()));
connect(titleRename, SIGNAL(clicked()), renameDone, SLOT(show()));
connect(titleRename, SIGNAL(clicked()), renameBox, SLOT(setFocus()));
connect(titleRename, SIGNAL(clicked()), renameBox, SLOT(selectAll()));
connect(renameDone, SIGNAL(clicked()), title, SLOT(show()));
connect(renameDone, SIGNAL(clicked()), titleRename, SLOT(show()));
connect(renameDone, SIGNAL(clicked()), renameBox, SLOT(hide()));
connect(renameDone, SIGNAL(clicked()), renameDone, SLOT(hide()));
connect(renameDone, SIGNAL(clicked()), titleRename, SLOT(setFocus()));
connect(renameBox, SIGNAL(editingFinished()), title, SLOT(show()));
connect(renameBox, SIGNAL(editingFinished()), titleRename, SLOT(show()));
connect(renameBox, SIGNAL(editingFinished()), renameBox, SLOT(hide()));
connect(renameBox, SIGNAL(editingFinished()), renameDone, SLOT(hide()));
connect(renameBox, SIGNAL(editingFinished()), titleRename, SLOT(setFocus()));
// connect to stuff that does things!
connect(renameBox, SIGNAL(editingFinished()), data, SLOT(renamePopulation()));
connect(renameDone, SIGNAL(clicked()), data, SLOT(renamePopulation()));
// connect for hide
connect(this, SIGNAL(hideHeader()), title, SLOT(hide()));
connect(this, SIGNAL(hideHeader()), titleRename, SLOT(hide()));
connect(this, SIGNAL(hideHeader()), renameBox, SLOT(hide()));
connect(this, SIGNAL(hideHeader()), renameDone, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showPopulation()), title, SLOT(show()));
connect(this, SIGNAL(showPopulation()), titleRename, SLOT(show()));
connect(this, SIGNAL(showSpikeSource()), title, SLOT(show()));
connect(this, SIGNAL(showSpikeSource()), titleRename, SLOT(show()));
// connect for update of pop name
connect(this, SIGNAL(setPopulationTitle(QString)), title, SLOT(setText(QString)));
connect(this, SIGNAL(setPopulationName(QString)), renameBox, SLOT(setText(QString)));
// add to layout
this->addLayout(titleLayout);
this->addLayout(renameLayout);
////// SIZE
QHBoxLayout * tempBox = new QHBoxLayout();
this->addLayout(tempBox);
QLabel * sizeLabel = new QLabel("Population size");
QLabel * SSsizeLabel = new QLabel("No. spike trains");
tempBox->addWidget(sizeLabel);
tempBox->addWidget(SSsizeLabel);
QSpinBox *sizeSpin = new QSpinBox;
sizeSpin->setFocusPolicy(Qt::StrongFocus);
sizeSpin->installEventFilter(new FilterOutUndoRedoEvents);
sizeSpin->setRange(1, 2000000);
sizeSpin->setSingleStep(1);
sizeSpin->setValue(0);
tempBox->addWidget(sizeSpin);
// connect to update size
connect(sizeSpin, SIGNAL(valueChanged(int)), data, SLOT (setSize()));
// connect for hide
connect(this, SIGNAL(hideHeader()), sizeSpin, SLOT(hide()));
connect(this, SIGNAL(hideHeader()), sizeLabel, SLOT(hide()));
connect(this, SIGNAL(hideHeader()), SSsizeLabel, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showPopulation()), sizeSpin, SLOT(show()));
connect(this, SIGNAL(showPopulation()), sizeLabel, SLOT(show()));
connect(this, SIGNAL(showSpikeSource()), sizeSpin, SLOT(show()));
connect(this, SIGNAL(showSpikeSource()), SSsizeLabel, SLOT(show()));
// connect for update of pop size
connect(this, SIGNAL(setPopulationSize(int)), sizeSpin, SLOT(setValue(int)));
////// COLOUR
QHBoxLayout * colourBox = new QHBoxLayout();
this->addLayout(colourBox);
QLabel * colourLabel = new QLabel("Colour");
colourBox->addWidget(colourLabel);
QPushButton * colourButton = new QPushButton("Select");
colourBox->addWidget(colourButton);
connect(colourButton, SIGNAL(clicked()), data, SLOT (selectColour()));
// connect for hide
connect(this, SIGNAL(hideHeader()), colourButton, SLOT(hide()));
connect(this, SIGNAL(hideHeader()), colourLabel, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showPopulation()), colourButton, SLOT(show()));
connect(this, SIGNAL(showPopulation()), colourLabel, SLOT(show()));
////// SPIKE SOURCE
QLabel * ssLabel = new QLabel("<b>Configure Spike Sources in the Experiment</b>");
this->addWidget(ssLabel);
// connect for hide
connect(this, SIGNAL(hideHeader()), ssLabel, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showSpikeSource()), ssLabel, SLOT(show()));
}
// add the stuff that we want
void nl_rootlayout::initProjectionHeader(nl_rootdata * data) {
// TITLE /////////
QHBoxLayout * titleLayout = new QHBoxLayout();
QLabel *title = new QLabel("temp");
titleLayout->addWidget(title);
this->addLayout(titleLayout);
// connect for hide
connect(this, SIGNAL(hideHeader()), title, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showProjection()), title, SLOT(show()));
// connect for name update
connect(this, SIGNAL(setProjectionName(QString)), title, SLOT(setText(QString)));
// DRAW STYLE ///////
QGroupBox * styleGroup = new QGroupBox("Draw style");
this->addWidget(styleGroup);
QGridLayout * drawStyleLayout = new QGridLayout();
styleGroup->setLayout(drawStyleLayout);
this->exc = new QRadioButton("Excitatory");
this->exc->setChecked(true);
this->exc->setProperty("style",standardDrawStyleExcitatory);
drawStyleLayout->addWidget(this->exc, 0, 0);
this->inh = new QRadioButton("Inhibitory");
drawStyleLayout->addWidget(this->inh, 0, 1);
this->inh->setProperty("style",standardDrawStyle);
//drawStyleLayout->addStretch();
this->showLabel = new QCheckBox ("Show projection label");
this->showLabel->setProperty("action","togglelabel");
drawStyleLayout->addWidget(showLabel, 1, 0);
// connect for hide
connect(this, SIGNAL(hideHeader()), styleGroup, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showProjection()), styleGroup, SLOT(show()));
// connect radios
connect(exc, SIGNAL(pressed()), data, SLOT(updateDrawStyle()));
connect(inh, SIGNAL(pressed()), data, SLOT(updateDrawStyle()));
connect(this->showLabel, SIGNAL(stateChanged(int)), data, SLOT(updateDrawStyle()));
// SYNAPSES /////////
// add layout
QHBoxLayout * synLayout = new QHBoxLayout();
synLayout->setSpacing(0);
this->addLayout(synLayout);
// creat name - we need to reference this as a ptr - so put it here
QLabel *syn = new QLabel("temp");
syn->setAlignment(Qt::AlignHCenter);
// connect for hide
connect(this, SIGNAL(hideHeader()), syn, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showProjection()), syn, SLOT(show()));
// connect for set name
connect(this, SIGNAL(setProjectionSynapseName(QString)), syn, SLOT(setText(QString)));
// add navigation through synapses - left
QPushButton * left = new QPushButton("<");
left->setMaximumWidth(50);
left->setProperty("direction", "left");
synLayout->addWidget(left);
// connect for hide
connect(this, SIGNAL(hideHeader()), left, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showProjection()), left, SLOT(show()));
// connect to change synapse
connect(left, SIGNAL(clicked()), data, SLOT (changeSynapse()));
synLayout->addStretch();
// add the name
synLayout->addWidget(syn);
synLayout->addStretch();
// add navigation through synapses - right
QPushButton * right = new QPushButton(">");
right->setMaximumWidth(50);
right->setProperty("direction", "right");
synLayout->addWidget(right);
// connect for hide
connect(this, SIGNAL(hideHeader()), right, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showProjection()), right, SLOT(show()));
// connect to change synapse
connect(right, SIGNAL(clicked()), data, SLOT (changeSynapse()));
// remove Synapse
QPushButton * rem = new QPushButton("-");
rem->setMaximumWidth(50);
rem->setProperty("direction", "rem");
synLayout->addWidget(rem);
// connect for hide
connect(this, SIGNAL(hideHeader()), rem, SLOT(hide()));
// connect for show
connect(this, SIGNAL(setProjectionSynapseMinusOn()), rem, SLOT(show()));
// connect to change synapse
connect(rem, SIGNAL(clicked()), data, SLOT (changeSynapse()));
// add Synapse
QPushButton * add = new QPushButton("+");
add->setMaximumWidth(50);
add->setProperty("direction", "add");
synLayout->addWidget(add);
// connect for hide
connect(this, SIGNAL(hideHeader()), add, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showProjection()), add, SLOT(show()));
// connect to change synapse
connect(add, SIGNAL(clicked()), data, SLOT (changeSynapse()));
}
// add the stuff that we want
void nl_rootlayout::initInputHeader(nl_rootdata * data) {
// TITLE ///////////////
QHBoxLayout * titleLayout = new QHBoxLayout();
QLabel *title = new QLabel("temp");
titleLayout->addWidget(title);
this->addLayout(titleLayout);
// connect for hide
connect(this, SIGNAL(hideHeader()), title, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showInput()), title, SLOT(show()));
// connect for set title
connect(this, SIGNAL(setInputName(QString)), title, SLOT(setText(QString)));
QHBoxLayout * inputLay = new QHBoxLayout;
inputSrcName = new QLabel();
inputLay->addWidget(inputSrcName);
// connect for hide
connect(this, SIGNAL(hideHeader()), inputSrcName, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showInput()), inputSrcName, SLOT(show()));
////// PORT COMBOBOX
inputPortSelection = new QComboBox;
inputPortSelection->setMaximumWidth(200);
inputPortSelection->setProperty("type", "portMatches");
// connect for hide
connect(this, SIGNAL(hideHeader()), inputPortSelection, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showInput()), inputPortSelection, SLOT(show()));
// connect for function
connect(inputPortSelection, SIGNAL(currentIndexChanged(QString)), data, SLOT(updatePortMap(QString)));
inputLay->addWidget(inputPortSelection);
this->addLayout(inputLay);
// CONNECTION COMBOBOX
inputConnectionComboBox = this->addDropBox(this, "Connectivity", "input");
// connect for hide
connect(this, SIGNAL(hideHeader()), inputConnectionComboBox, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showInput()), inputConnectionComboBox, SLOT(show()));
}
// add the stuff that we want
void nl_rootlayout::initTabBox(nl_rootdata *) {
tabs = new QTabWidget;
tabs->setProperty("header","true");
this->addWidget(tabs);
tab1 = new QFrame;
tab1->setContentsMargins(0,0,0,0);
tabs->addTab(tab1, "temp");
QVBoxLayout * layout1 = new QVBoxLayout;
layout1->addStretch();
tab1->setLayout(layout1);
tab2 = new QFrame;
tab2->setContentsMargins(0,0,0,0);
tabs->addTab(tab2, "temp2");
QVBoxLayout * layout2 = new QVBoxLayout;
layout2->addStretch();
tab2->setLayout(layout2);
tab3 = new QFrame;
tab3->setContentsMargins(0,0,0,0);
tabs->addTab(tab3, "temp3");
QVBoxLayout * layout3 = new QVBoxLayout;
layout3->addStretch();
tab3->setLayout(layout3);
// connect for hide
connect(this, SIGNAL(hideHeader()), tabs, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showPopulation()), tabs, SLOT(show()));
connect(this, SIGNAL(showProjection()), tabs, SLOT(show()));
}
// add the stuff that we want
void nl_rootlayout::initTabBoxPopulation(nl_rootdata *) {
////// LAYOUT
CHECK_CAST(qobject_cast<QVBoxLayout *> (tab2->layout()));
layoutComboBox = this->addDropBox((QVBoxLayout *) tab2->layout(), "Layout", "layout");
// connect for configure
connect(this, SIGNAL(setLayoutType(int)), layoutComboBox, SLOT(setCurrentIndex(int)));
// connect for hide
connect(this, SIGNAL(hideHeader()), layoutComboBox, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showPopulation()), layoutComboBox, SLOT(show()));
////// TYPE
CHECK_CAST(qobject_cast<QVBoxLayout *> (tab1->layout()));
neuronComboBox = this->addDropBox((QVBoxLayout *) tab1->layout(),"Neuron type", "neuron");
// connect for configure
connect(this, SIGNAL(setNeuronType(int)), neuronComboBox, SLOT(setCurrentIndex(int)));
// connect for hide
connect(this, SIGNAL(hideHeader()), neuronComboBox, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showPopulation()), neuronComboBox, SLOT(show()));
}
// add the stuff that we want
void nl_rootlayout::initTabBoxProjection(nl_rootdata * ) {
////// WU TYPE
CHECK_CAST(qobject_cast<QVBoxLayout *> (tab1->layout()));
weightUpdateComboBox = this->addDropBox((QVBoxLayout *) tab1->layout(),"Weight Update", "weight_update");
this->weightUpdateTitle = new QLabel("<b>WeightUpdate name:</b>");
((QVBoxLayout *)tab1->layout())->insertWidget(tab1->layout()->count()-1, this->weightUpdateTitle);
// connect for configure
connect(this, SIGNAL(setWeightUpdateType(int)), weightUpdateComboBox, SLOT(setCurrentIndex(int)));
// connect for hide
connect(this, SIGNAL(hideHeader()), weightUpdateComboBox, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showProjection()), weightUpdateComboBox, SLOT(show()));
////// PSP
CHECK_CAST(qobject_cast<QVBoxLayout *> (tab2->layout()));
postSynapseComboBox = this->addDropBox((QVBoxLayout *) tab2->layout(),"Post-synapse", "postsynapse");
this->postSynapseTitle = new QLabel("<b>PostSynapse name:</b>");
tab2->layout()->addWidget(this->postSynapseTitle);
// connect for configure
connect(this, SIGNAL(setPostSynapseType(int)), postSynapseComboBox, SLOT(setCurrentIndex(int)));
// connect for hide
connect(this, SIGNAL(hideHeader()), postSynapseComboBox, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showProjection()), postSynapseComboBox, SLOT(show()));
////// CONNECTION
CHECK_CAST(qobject_cast<QVBoxLayout *> (tab3->layout()));
connectionComboBox = this->addDropBox((QVBoxLayout *) tab3->layout(),"Connectivity", "conn");
// connect for configure
connect(this, SIGNAL(setConnectionType(int)), connectionComboBox, SLOT(setCurrentIndex(int)));
// connect for hide
connect(this, SIGNAL(hideHeader()), connectionComboBox, SLOT(hide()));
// connect for show
connect(this, SIGNAL(showProjection()), connectionComboBox, SLOT(show()));
}
void nl_rootlayout::initFinish(nl_rootdata * data) {
// add copy / paste buttons
for (int i = 0; i < 2; ++i) {
// select tab
QVBoxLayout * tabLayout;
if (i == 0) {
CHECK_CAST(qobject_cast<QVBoxLayout *> (tab1->layout()));
tabLayout = (QVBoxLayout *) tab1->layout();
} else {
CHECK_CAST(qobject_cast<QVBoxLayout *> (tab2->layout()));
tabLayout = (QVBoxLayout *) tab2->layout();
}
// layout
QHBoxLayout * cp = new QHBoxLayout();
tabLayout->insertLayout(tabLayout->count() - 2, cp);
QPushButton * copy = new QPushButton("Copy");
// set what the source is
if (i == 0) {
copy->setProperty("source", "tab1");
}
if (i == 1) {
copy->setProperty("source", "tab2");
}
copy->setMaximumWidth(60);
QPushButton * paste = new QPushButton("Paste");
// set what the source is
if (i == 0) {
paste->setProperty("source", "tab1");
}
if (i == 1) {
paste->setProperty("source", "tab2");
}
paste->setMaximumWidth(60);
// tooltips
copy->setToolTip("Copy Parameters and State Variables");
paste->setToolTip("Paste Parameters and State Variables");
// if no data hide paste
if (data->clipboardCData == NULL) {
paste->setEnabled(false);
}
// add to layout
QLabel * propLabel = new QLabel("<b>Properties</b>");
cp->addWidget(propLabel);
cp->addStretch();
cp->addWidget(copy);
cp->addWidget(paste);
// link to hide / show
if (i == 0) {
connect(this, SIGNAL(showTab0CopyPaste()), copy, SLOT(show()));
connect(this, SIGNAL(showTab0CopyPaste()), paste, SLOT(show()));
connect(this, SIGNAL(showTab0CopyPaste()), propLabel, SLOT(show()));
}
if (i == 1) {
connect(this, SIGNAL(showTab1CopyPaste()), copy, SLOT(show()));
connect(this, SIGNAL(showTab1CopyPaste()), paste, SLOT(show()));
connect(this, SIGNAL(showTab1CopyPaste()), propLabel, SLOT(show()));
}
connect(this, SIGNAL(hideHeader()), copy, SLOT(hide()));
connect(this, SIGNAL(hideHeader()), paste, SLOT(hide()));
connect(this, SIGNAL(hideHeader()), propLabel, SLOT(hide()));
// link to enable paste:
connect(this, SIGNAL(allowPaste(bool)), paste, SLOT(setEnabled(bool)));
// link up
connect(copy, SIGNAL(clicked()), data, SLOT(copyParsToClipboard()));
connect(paste, SIGNAL(clicked()), data, SLOT(pasteParsFromClipboard()));
}
// initial update of the lists
updateLayoutList(data);
updateComponentLists(data);
// and add the stretch
this->addStretch();
}
void nl_rootlayout::updateLayoutList(nl_rootdata * data) {
// upadte the layout list
layoutComboBox->clear();
// we don't want to set stuff while this occurs
layoutComboBox->disconnect(data);
for (int i = 0; i < data->catalogLayout.size(); ++i) {
layoutComboBox->addItem(data->catalogLayout[i]->name);
}
connect(layoutComboBox, SIGNAL(activated(int)), data, SLOT(updateComponentType(int)));
}
void nl_rootlayout::updateComponentLists(nl_rootdata * data) {
// update the component lists
// we don't want to set stuff while this occurs
neuronComboBox->disconnect(data);
weightUpdateComboBox->disconnect(data);
postSynapseComboBox->disconnect(data);
// neuron
neuronComboBox->clear();
for (int i = 0; i < data->catalogNrn.size(); ++i) {
if (!(data->catalogNrn[i]->name == "none")) {
neuronComboBox->addItem(data->catalogNrn[i]->name);
} else {
neuronComboBox->addItem("-select component-");
}
}
QModelIndex ind = neuronComboBox->model()->index(0,0);
neuronComboBox->model()->setData(ind, QVariant(0), Qt::UserRole-1);
// weightupdate
weightUpdateComboBox->clear();
for (int i = 0; i < data->catalogWU.size(); ++i) {
if (!(data->catalogWU[i]->name == "none"))
weightUpdateComboBox->addItem(data->catalogWU[i]->name);
else
weightUpdateComboBox->addItem("-select component-");
}
ind = weightUpdateComboBox->model()->index(0,0);
weightUpdateComboBox->model()->setData(ind, QVariant(0), Qt::UserRole-1);
// postsynapse
postSynapseComboBox->clear();
for (int i = 0; i < data->catalogPS.size(); ++i) {
if (!(data->catalogPS[i]->name == "none"))
postSynapseComboBox->addItem(data->catalogPS[i]->name);
else
postSynapseComboBox->addItem("-select component-");
}
ind = postSynapseComboBox->model()->index(0,0);
postSynapseComboBox->model()->setData(ind, QVariant(0), Qt::UserRole-1);
connect(neuronComboBox, SIGNAL(activated(int)), data, SLOT(updateComponentType(int)));
connect(weightUpdateComboBox, SIGNAL(activated(int)), data, SLOT(updateComponentType(int)));
connect(postSynapseComboBox, SIGNAL(activated(int)), data, SLOT(updateComponentType(int)));
}
void nl_rootlayout::modelNameChanged() {
CHECK_CAST(qobject_cast<QLineEdit *> (sender()));
QString model_name = ((QLineEdit *) sender())->text();
emit setCaption(model_name);
}
void nl_rootlayout::recursiveDeleteLater(QLayout * parentLayout) {
QLayoutItem * item;
while (parentLayout->count() > 0) {
item = parentLayout->takeAt(0);
if (item->widget()) {
item->widget()->hide();
forDeleting.push_back(item->widget());
item->widget()->disconnect((QObject *)0);
}
if (item->layout())
recursiveDeleteLater(item->layout());
delete item;
}
parentLayout->deleteLater();
}
void nl_rootlayout::clearOld() {
// loop while items remain
while (this->count() > 0)
{
// remove and return first item
QLayoutItem *item = this->takeAt(0);
// if item is a widget
if (item->widget() != 0) {
item->widget()->hide();
forDeleting.push_back(item->widget());
item->widget()->disconnect((QObject *)0);
}
// if item is a spacer deleting causes a segfault
else if (item->spacerItem() != 0) {
//delete item->spacerItem();
}
// if item is a layout recursively delete contents
else if (item->layout() != 0) {
recursiveDeleteLater(item->layout());
}
delete item;
}
}
void nl_rootlayout::updatePanel(nl_rootdata* data)
{
// update libraries
updateLayoutList(data);
updateComponentLists(data);
// if we are not on view 1 do not update...
if (!this->parentWidget()->isVisible()) {
return;
}
// hide everything
emit hideHeader();
// find if there is only one selection, if not then clear all
if (data->selList.size() != 1) {
// configure model panel
emit setModelName(data->currProject->name);
data->setCaptionOut(data->currProject->name);
// remove input properties
emit deleteProperties();
// show model panel
emit showModel();
} else {
lastObject = data->selList[0];
// find what the selected item is...
if (data->selList[0]->type == populationObject) {
QSharedPointer<population> pop = qSharedPointerDynamicCast<population> (data->selList[0]);
this->popSelected(pop, data);
} else if (data->selList[0]->type == projectionObject) {
QSharedPointer<projection> proj = qSharedPointerDynamicCast<projection> (data->selList[0]);
if (proj.isNull()) {
DBG() << "Pointer is null!";
}
this->projSelected(proj, data);
} else if (data->selList[0]->type == inputObject) {
this->inSelected(qSharedPointerDynamicCast<genericInput> (data->selList[0]), data);
}
}
}
void nl_rootlayout::popSelected(QSharedPointer <population> &pop, nl_rootdata* data) {
if (pop->neuronTypeName.compare("noPop") == 0)
return;
// spikesource has none of this info
if (pop->isSpikeSource) {
emit showSpikeSource();
emit setPopulationName(pop->name);
emit setPopulationTitle("<u><b>" + pop->name + "</b></u>");
emit setPopulationSize(pop->numNeurons);
return;
}
// configure
emit showPopulation();
emit setPopulationName(pop->name);
emit setPopulationTitle("<u><b>" + pop->name + "</b></u>");
emit setPopulationSize(pop->numNeurons);
for (int i = 0; i < data->catalogNrn.size(); ++i) {
if (pop->neuronType->component == data->catalogNrn[i]) {
emit setNeuronType(i);
}
}
// if no data hide paste
emit allowPaste(data->clipboardCData != NULL);
// set tab
if (tabs->currentIndex() > 1) {
tabs->setCurrentIndex(0);
}
if (tabs->count() == 3) {
tabs->removeTab(2);
}
tabs->setTabText(0, "Neuron Body");
tabs->setTabText(1, "Layout");
emit deleteProperties();
drawParamsLayout(data);
}
void nl_rootlayout::projSelected(QSharedPointer <projection> &proj, nl_rootdata* data) {
// configure
emit showProjection();
emit setProjectionName("<u><b>" + proj->getName() + "</b></u>");
// Copy current projection into rootdata so it's accessible in csv_connection::drawLayout
data->currentlySelectedProjection = proj;
// make sure we are not off the end due to deletes
while (proj->currTarg >= 0 && proj->currTarg > proj->synapses.size()-1) {
proj->currTarg--;
}
if (proj->currTarg == -1) {
return;
}
// check the drawstyle
if (proj->style() == standardDrawStyle) {
inh->setChecked(true);
} else {
exc->setChecked(true);
}
// Check the show label checkbox
if (proj->showLabel) {
this->showLabel->setCheckState(Qt::Checked);
} else {
this->showLabel->setCheckState(Qt::Unchecked);
}
// Synapse
emit setProjectionSynapseName("Synapse " + QString::number(proj->currTarg));
if (proj->synapses.size() > 1) {
emit setProjectionSynapseMinusOn();
}
// if no data hide paste
emit allowPaste(data->clipboardCData != NULL);
if (tabs->count() < 3) {
tabs->addTab(tab3, "Connectivity");
}
tabs->setTabText(0, "Weight Update");
tabs->setTabText(1, "PostSynapse");
tabs->setTabText(2, "Connectivity");
// set comboboxes
for (int i = 0; i < data->catalogWU.size(); ++i) {
if (proj->synapses[proj->currTarg]->weightUpdateCmpt->component == data->catalogWU[i]) {
emit setWeightUpdateType(i);
}
}
for (int i = 0; i < data->catalogPS.size(); ++i) {
if (proj->synapses[proj->currTarg]->postSynapseCmpt->component == data->catalogPS[i]) {
emit setPostSynapseType(i);
}
}
connectionComboBox->disconnect(data);
connectionComboBox->clear();
connectionComboBox->setProperty("ptr", qVariantFromValue((void *) proj->synapses[proj->currTarg].data()));
connectionComboBox->addItem("All to All");
connectionComboBox->addItem("One to One");
// disable 1-2-1 if src and dst pops not the same size
if (proj->source->numNeurons != proj->destination->numNeurons) {
QModelIndex ind = connectionComboBox->model()->index(1,0);
connectionComboBox->model()->setData(ind, QVariant(0), Qt::UserRole-1);
}
connectionComboBox->addItem("Fixed Probability");
connectionComboBox->addItem("Explicit List");
QSettings settings;
// add python scripts
settings.beginGroup("pythonscripts");
QStringList scripts = settings.childKeys();
connectionComboBox->addItems(scripts);
settings.endGroup();
connectionComboBox->setCurrentIndex(proj->synapses[proj->currTarg]->connectionType->getIndex());
connect(connectionComboBox, SIGNAL(activated(int)), data, SLOT(updateComponentType(int)));
emit deleteProperties();
drawParamsLayout(data);
}
// Draws the input panel.
void nl_rootlayout::inSelected(QSharedPointer<genericInput> in, nl_rootdata* data)
{
emit showInput();
emit setInputName("<u><b>" + in->getName() + "</b></u>");
emit deleteProperties();
data->currentlySelectedProjection = in;
QString XMLname = in->srcCmpt->getXMLName() + " to " + in->dstCmpt->getXMLName();
inputSrcName->setToolTip(XMLname);
// shorten if too long (tooltip will have full name)
if (XMLname.size() > 12) {
XMLname.resize(10);
XMLname.append("...");
} else {
// make label consistent size
XMLname.insert(13, " ");
}
inputSrcName->setText(XMLname);
// add port options
QStringList portPairs;
for (int i = 0; i < in->dstCmpt->inputs.size(); ++i) {
if (in == in->dstCmpt->inputs[i]) {
portPairs = in->dstCmpt->getPortMatches(i, false);
}
}
QString currPortPair = in->srcPort + "->" + in->dstPort;
inputPortSelection->setProperty("ptr", qVariantFromValue((void *) in.data()));
inputPortSelection->disconnect(data);
inputPortSelection->clear();
for (int p = 0; p < portPairs.size(); ++p) {
inputPortSelection->addItem(portPairs.at(p));
if (currPortPair == portPairs.at(p)) {
inputPortSelection->setCurrentIndex(inputPortSelection->count()-1);
}
}
if (portPairs.size() == 0) {
inputPortSelection->setDisabled(true);
// make sure we don't have gibberish loaded in
in->srcPort.clear();
in->dstPort.clear();
} else {
// in case we were previously disabled
inputPortSelection->setDisabled(false);
}
connect(inputPortSelection, SIGNAL(currentIndexChanged(QString)), data, SLOT(updatePortMap(QString)));
// configure connectivity dropdown
inputConnectionComboBox->disconnect(data);
inputConnectionComboBox->clear();
inputConnectionComboBox->setProperty("ptr", qVariantFromValue((void *) in.data()));
inputConnectionComboBox->addItem("All to All");
inputConnectionComboBox->addItem("One to One");
inputConnectionComboBox->addItem("Fixed Probability");
inputConnectionComboBox->addItem("Explicit List");
if (in->srcCmpt->owner->type == populationObject && in->dstCmpt->owner->type == populationObject) {
// add python scripts
QSettings settings;
settings.beginGroup("pythonscripts");
QStringList scripts = settings.childKeys();
inputConnectionComboBox->addItems(scripts);
settings.endGroup();
}
inputConnectionComboBox->setCurrentIndex(in->conn->getIndex());
connect(inputConnectionComboBox, SIGNAL(activated(int)), data, SLOT(updateComponentType(int)));
QFormLayout * varLayout = new QFormLayout;
// add to delete props
connect(this, SIGNAL(deleteProperties()), varLayout, SLOT(deleteLater()));
// other connectivity:
switch (in->conn->type) {
case AlltoAll: