-
Notifications
You must be signed in to change notification settings - Fork 7
/
SC_layout_editpreviewdialog.cpp
175 lines (140 loc) · 7.23 KB
/
SC_layout_editpreviewdialog.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
/***************************************************************************
** **
** 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_layout_editpreviewdialog.h"
layoutEditPreviewDialog::layoutEditPreviewDialog(QSharedPointer<NineMLLayout> inSrcNineMLLayout, glConnectionWidget * glConn, QWidget *parent) :
QDialog(parent)
{
srcNineMLLayout = inSrcNineMLLayout;
glView = glConn;
QObject::connect(this, SIGNAL(drawLayout(QVector <loc>)), glView, SLOT(drawLocations(QVector <loc>)));
this->setModal(true);
this->setMinimumSize(200, 400);
this->setWindowTitle("Preview layout");
//this->setWindowIcon();
// add the main layout
this->setLayout(new QVBoxLayout);
this->layout()->setContentsMargins(0,0,0,0);
// make the dialog scrollable
this->layout()->addWidget(new QScrollArea);
QWidget * content = new QWidget;
((QScrollArea *) this->layout()->itemAt(0)->widget())->setWidget(content);
((QScrollArea *) this->layout()->itemAt(0)->widget())->setWidgetResizable(true);
content->setLayout(new QFormLayout);
QFormLayout * contentLayout = (QFormLayout *) content->layout();
QSpinBox * numNeurons = new QSpinBox;
numNeurons->setRange(1, 20000000);
numNeurons->setProperty("name", "numNeurons");
numNeurons->setValue(99.0);
QObject::connect(numNeurons, SIGNAL(valueChanged(QString)), this, SLOT(reDraw(QString)));
contentLayout->addRow("Number of neurons:", numNeurons);
// start adding the items
if (srcNineMLLayout->ParameterList.size() > 1) {
contentLayout->addRow("<b>Parameters</b>", new QLabel(""));
}
// add the parameters
for (int i = 0; i < srcNineMLLayout->ParameterList.size(); ++i) {
if (srcNineMLLayout->ParameterList[i]->name != "numNeurons") {
// add to main layout
QDoubleSpinBox * value = new QDoubleSpinBox;
value->setRange(-200000, 200000);
value->setSingleStep(0.1);
value->setDecimals(3);
value->setValue(1.0);
value->setProperty("name", srcNineMLLayout->ParameterList[i]->name);
QObject::connect(value, SIGNAL(valueChanged(QString)), this, SLOT(reDraw(QString)));
contentLayout->addRow(srcNineMLLayout->ParameterList[i]->name + ":", value);
}
}
if (srcNineMLLayout->StateVariableList.size() > 3) {
contentLayout->addRow("<b>State variables</b>", new QLabel(""));
}
// add the state vars
for (int i = 0; i < srcNineMLLayout->StateVariableList.size(); ++i) {
if (srcNineMLLayout->StateVariableList[i]->name != "x" && srcNineMLLayout->StateVariableList[i]->name != "y" && srcNineMLLayout->StateVariableList[i]->name != "z") {
// add to main layout
QDoubleSpinBox * value = new QDoubleSpinBox;
value->setRange(-200000, 200000);
value->setSingleStep(0.1);
value->setDecimals(3);
value->setValue(1.0);
value->setProperty("name", srcNineMLLayout->StateVariableList[i]->name);
QObject::connect(value, SIGNAL(valueChanged(QString)), this, SLOT(reDraw(QString)));
contentLayout->addRow(srcNineMLLayout->StateVariableList[i]->name + ":", value);
}
}
contentLayoutRef = contentLayout;
// force a redraw!
numNeurons->setValue(100.0);
}
void layoutEditPreviewDialog::reDraw(QString) {
// create a new layoutData from the layout:
QSharedPointer<NineMLLayoutData> data = QSharedPointer<NineMLLayoutData> (new NineMLLayoutData(srcNineMLLayout));
// populate from the spinboxes:
for (int i = 0; i < data->ParameterList.size(); ++i) {
for (int j = 0; j < (int) contentLayoutRef->count(); ++j) {
if (contentLayoutRef->itemAt(j)->widget()) {
QString clsName = "QDoubleSpinBox";
if (clsName.contains(contentLayoutRef->itemAt(j)->widget()->metaObject()->className())) {
if (contentLayoutRef->itemAt(j)->widget()->property("name").toString() == data->ParameterList[i]->name) {
data->ParameterList[i]->value[0] = ((QDoubleSpinBox *) contentLayoutRef->itemAt(j)->widget())->value();
}
}
}
}
}
for (int i = 0; i < data->StateVariableList.size(); ++i) {
for (int j = 0; j < (int) contentLayoutRef->count(); ++j) {
if (contentLayoutRef->itemAt(j)->widget()) {
QString clsName = "QDoubleSpinBox";
if (clsName.contains(contentLayoutRef->itemAt(j)->widget()->metaObject()->className())) {
if (contentLayoutRef->itemAt(j)->widget()->property("name").toString() == data->StateVariableList[i]->name) {
data->StateVariableList[i]->value[0] = ((QDoubleSpinBox *) contentLayoutRef->itemAt(j)->widget())->value();
}
}
}
}
}
int numNeurons = 0;
for (int j = 0; j < (int) contentLayoutRef->count(); ++j) {
if (contentLayoutRef->itemAt(j)->widget()) {
QString clsName = "QSpinBox";
if (clsName.contains(contentLayoutRef->itemAt(j)->widget()->metaObject()->className())) {
numNeurons = ((QSpinBox *) contentLayoutRef->itemAt(j)->widget())->value();
}
}
}
// ok, data is filled in, now to get the locations
QVector <loc> locations;
QString err;
data->generateLayout(numNeurons, &locations, err);
if (err.size() == 0) {
emit drawLayout(locations);
} else
{
emit drawLayout(locations);
QMessageBox msgBox;
msgBox.setText(err);
msgBox.exec();
}
}