-
Notifications
You must be signed in to change notification settings - Fork 7
/
NL_projection_and_synapse.h
244 lines (208 loc) · 9.13 KB
/
NL_projection_and_synapse.h
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
/***************************************************************************
** **
** 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/. **
** **
****************************************************************************
** Authors: Alex Cope, Seb James **
** Website/Contact: http://bimpa.group.shef.ac.uk/ **
****************************************************************************/
#ifndef PROJECTIONS_H
#define PROJECTIONS_H
#include "globalHeader.h"
#include "NL_systemobject.h"
// DIRECTION DEFINES
#define HORIZ 0
#define VERT 1
struct bezierCurve {
QPointF C1;
QPointF C2;
QPointF end;
};
enum cPointType {
C1,
C2,
p_end
};
struct cPoint {
bool start;
int ind; // A control point is in a curve. This is the index in projection::curves of the relevant curve.
cPointType type;
};
// A synapse's parent is a projection, a pointer to the parent is held
// in proj.
class synapse : public systemObject
{
public:
synapse() {isVisualised=false;}
synapse(QSharedPointer <projection> proj, projectObject * data, bool dontAddInputs = false);
synapse(QSharedPointer <projection> proj, nl_rootdata * data, bool dontAddInputs = false);
~synapse();
QSharedPointer<ComponentInstance> postSynapseCmpt;
QSharedPointer<ComponentInstance> weightUpdateCmpt;
connection *connectionType; // refactor to conn
/*!
* A label for the connection type. Filled with the connection
* generator, as read from the metadata.xml (For example, the
* connectivity may be defined by a pythonscript_connection, even
* though this->connectionType is a csv_connection after
* generation).
*/
QString connectionTypeStr;
bool isVisualised;
/*!
* This is the parent projection.
*/
QSharedPointer <projection> proj;
QString getName();
QString getWeightUpdateName();
QString getPostSynapseName();
int getSynapseIndex();
virtual void delAll(nl_rootdata *);
QSharedPointer < systemObject > newFromExisting(QMap <systemObject *, QSharedPointer <systemObject> > &);
void remapSharedPointers(QMap <systemObject *, QSharedPointer <systemObject> >);
/*!
* This copies the pointers to source and destination populations
* in the parent project proj down into the connection.
*/
void passDownSrcAndDst (void);
private:
/*!
* Get the index of this synapse.
*/
int getIndex (void);
};
// A projection contains synapses.
class projection : public systemObject
{
public:
projection();
/*!
* This reads the projection from XML. Don't confuse it with
* read_inputs_from_xml, which is called AFTER readFromXML. Could
* be refactored to readSelfFromXML with read_inputs_from_xml
* being refactored to readMyInputsFromXML.
*/
void readFromXML(QDomElement &e, QDomDocument * , QDomDocument * meta, projectObject *data, QSharedPointer<projection>);
virtual ~projection();
QVector < bezierCurve > curves;
QPointF start;
bool is_clicked(float, float,float);
virtual void add_curves();
QSharedPointer <population> destination; // Refactor to dstPop to match other QSharedPointer<population> attributes in other classes.
QSharedPointer <population> source; // Refactor to srcPop.
QVector <QSharedPointer <synapse> > synapses;
int currTarg;
QString getName();
virtual void remove(nl_rootdata *);
virtual void delAll(nl_rootdata *);
virtual void delAll(projectObject *);
void move(float,float);
void connect(QSharedPointer<projection> in);
void disconnect();
void setStyle(drawStyle style);
drawStyle style();
virtual void draw(QPainter *painter, float GLscale, float viewX, float viewY, int width, int height, QImage , drawStyle style);
void drawInputs(QPainter *painter, float GLscale, float viewX, float viewY, int width, int height, QImage, drawStyle style);
void drawHandles(QPainter *painter, float GLscale, float viewX, float viewY, int width, int height);
void moveEdge(int, float, float);
virtual void write_model_meta_xml(QXmlStreamWriter* xmlOut);
/*!
* Reads the projection's inputs from xml. This is called (from
* within projectObject::loadNetwork) AFTER the projection itself
* has be read in using projection::readFromXML.
*/
void read_inputs_from_xml(QDomElement &e, QDomDocument * meta, projectObject *data, QSharedPointer<projection>);
void print();
QPointF findBoxEdge(QSharedPointer <population> pop, float xGL, float yGL);
void setAutoHandles(QSharedPointer <population> pop1, QSharedPointer <population>pop2, QPointF end);
void animate(QSharedPointer<systemObject> movingObj, QPointF delta, QSharedPointer<projection> thisSharedPointer);
virtual void moveSelectedControlPoint(float xGL, float yGL);
bool selectControlPoint(float xGL, float yGL, float GLscale);
bool deleteControlPoint(float xGL, float yGL, float GLscale);
void insertControlPoint(float xGL, float yGL, float GLscale);
QPointF currentLocation();
QPointF selectedControlPointLocation();
virtual void setLocationOffsetRelTo(float x, float y)
{
locationOffset = this->start - QPointF(x,y);
}
QSharedPointer < systemObject > newFromExisting(QMap<systemObject *, QSharedPointer<systemObject> > &);
void remapSharedPointers(QMap <systemObject *, QSharedPointer <systemObject> >);
trans tempTrans;
void setupTrans(float GLscale, float viewX, float viewY, int width, int height);
QPointF transformPoint(QPointF point);
QPainterPath makeIntersectionLine(int first, int last);
QVector < QSharedPointer<genericInput> > disconnectedInputs;
// If true, show projection label.
bool showLabel;
protected:
cPoint selectedControlPoint;
private:
/*!
* Part of readFromXML. projectObject* data is passed so that
* data->getCursorPos() can be used to offset the positions if
* necessary.
*/
void readAnnotationXML (QDomElement& e, projectObject* data);
/*!
* Part of readFromXML.
*/
void readSynapsesXML (QDomElement& e, projectObject* data,
QSharedPointer<projection> thisSharedPointer);
/*!
* Sub-called by readSynapsesXML.
*/
QSharedPointer<synapse> readSingleSynapseXML (projectObject* data,
QSharedPointer<projection> thisSharedPointer,
QDomNodeList& colList, int synNum);
/*!
* Return true if there is more than one synapse and the synapses
* do not all share the same connectivity pattern.
*/
bool multipleConnTypes(void);
/*!
* Draw the projection label. Arguments are all variables from
* projections::draw.
*/
void drawLabel (QPainter* painter, QPen& linePen, QPen& pointerLinePen, QPen& labelPen,
const float GLscale, const float scale);
/*!
* produce an arrow head.
*/
QPolygonF makeArrowHead (QPainterPath& path, const float GLscale);
/*!
* Using this->curves, find a suitable label position for the
* projection label. Place the label on the outside edge of the
* curve. syn is the synapse number and influences the label
* position. The scale is also used. Startline pos is the
* position at which a "pointer line" from the label text to the
* object of the label should begin.
*/
QPointF getLabelPos (QFont& f, int syn, const QString& tstr, const float scale,
QPointF& startLinePos);
/*!
* Get a location on a cubic bezier curve. t is the position on
* the curve and must be in range 0 to 1. curveIndex is the index
* into this->curves.
*/
QPointF getBezierPos (int curveIndex, float t);
int srcPos;
int dstPos;
drawStyle projDrawStyle;
};
#endif // PROJECTIONS_H