forked from Conedy/Conedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addNewNode.py
783 lines (548 loc) · 21.8 KB
/
addNewNode.py
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
#
# Conedy is a scientific tool which allows numerical integration of dynamical networks.
#
# Copyright (C) 2011 Alexander Rothkegel, Henning Dickten, Ferdinand Stolz, Justus Schwabedahl
#
# This file is part of conedy.
#
# Conedy 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/>
#!/usr/bin/python
# -*- coding: utf8 -*-
#TODO: addNewNode.py shouldn't be mad about upper case parameter names ?
import os
import sys
import ConfigParser
import re
def cleanString(stringIn):
"Erstellt einen CamelCaseString und entfernt alle Leerzeichen."
return stringIn.title().replace(" ", "").replace("-","_").strip("_").rstrip("_")
def underline(stringIn):
print stringIn
print len(stringIn)*"-"
class NodeEditor:
className = ""
nodeInfo = ""
params = []
events = []
functions = [ "getWeightedSum()", "getCouplingSum()", "getWeighedInSum()" ]
dgl = []
upkeep = []
period = []
doku = []
dim = 0
numParam = 0
shortDescription = "short description ..."
longDescription = "long description ..."
type = ""
staticEdges = 0
staticEdgeType = ""
staticEdgeBlueprint = ""
staticTargetNodeType = ""
fileNameOut = ""
# def __init__ (self):
def readConsole(self,inName="", inDim=-1, type = "", events = [],inNumParam=-1, params = [], dgl = [], doku = [], staticEdges = 0, staticEdgeType = "", staticTargetNodeType= "", inFileNameOut=""):
"Klasse zum Erstellen neues Nodes in Conedy"
self.events = events
self.params = params
self.doku = doku
# Klassenname einlesen
if (inName == ""):
temp = raw_input("Please enter new nodename: ")
print "\n"
else:
temp = inName
self.className = temp
self.nodeInfo = "_" + self.className + "_"
# Integrator enlesen
if (type == ""):
temp = raw_input("Please choose an nodeType (type) from the following list\n\todeNode, sde, stdOdeIntegrator, pco, pcoDelay , map: ")
print "\n"
self.type = temp
else:
self.type = type
# Dimension des Oszillators abfragen
while (inDim <= 0):
inDim = int(raw_input("Please enter dimension of oszillator ( >= 1 ): "))
print "\n"
self.dim = inDim
# Anzahl der Parameter abfragen
while (inNumParam < 0):
inNumParam = int(raw_input("Please enter number of dynamic parameters: ( >= 0 ): "))
print "\n"
self.numParam = inNumParam
# Parameter abfragen
if (static == 1):
self.static = 1
self.staticEdgeType = staticEdgeType
self.staticTargetNodeType = staticTargetNodeType
while len(self.params) < self.numParam:
self.addNewParam(len(self.params)+1)
print "\n"
# DGL abfragen
if (dgl == []):
underline("Dynamic of %s dim. oszillator:" % self.dim)
print "\n"
print "AVAILABLE FUNCTIONS:\n"
for f in self.functions:
print f
print "\n"
print "AVAILABLE PARAMETERS:\n"
for p in self.params:
print p[0] + "()\t",
print "\n\n"
if (len(self.params) > 0):
print "EXAMPLE: dxdt[0] = %s()*x[0] + x[1]**2 + CS - WS*x[0]\n\n" % self.params[0][0]
else:
print "EXAMPLE: dxdt[0] = 1/2*x[0] + x[1]**2 + CS - WS*x[0]\n\n"
if self.type == "stdOdeIntegrator":
for d in range(self.dim):
temp = "dxdt[" + str(d) + "] = "
self.dgl.append(temp + raw_input(temp))
elif self.type =="mapNode":
for d in range(self.dim):
temp = "xprime[" + str(d) + "] = "
self.dgl.append(temp + raw_input(temp))
else:
raise Exception('spam', 'eggs')
else:
self.dgl = dgl
# Rest der Eingabe ist Doku
if (self.doku == []):
temp = raw_input("Doku:")
self.doku.append(temp)
while temp != "":
temp = raw_input("Doku:") # TODO hier waere es viel sinnvoller auf EOF zu ueberpruefen. Leider weiss ich grad nicht, wie das geht.
self.doku.append(temp)
def addNewParam(self, pNum):
"Fuegt den n.ten Parameter hinzu"
paramName = raw_input("Please enter %i. parameter name: " % pNum)
paramName = cleanString(paramName)
paramName = paramName[0].lower() + paramName[1:]
paramDefault = float( raw_input("Please enter default value of \"%s\": " % paramName) )
self.params.append( (paramName, paramDefault) )
def writeHeaderFile(self):
"writes the header file"
try:
fin = open(".countAddedNodes" , 'r')
theString = fin.readline()
self.numberAddedNodes = int(theString)
fin.close()
except:
self.numberAddedNodes = 0
self.numberAddedNodes = self.numberAddedNodes + 1
fileNameOut = self.nodeInfo[1:-1]
fout = open("generated" + self.className + ".h", 'w')
# Header schreiben
fout.write("#ifndef %s_h\n#define %s_h %s_h\n\n#include <math.h>\n\n" % (fileNameOut, fileNameOut, fileNameOut))
fout.write("#include \"baseType.h\"\n")
fout.write("#include \"sdeNode.h\"\n")
fout.write("#include <boost/function.hpp>\n\n")
# Integrator festlegen
fout.write("// Integrator waehlen\n#include \"%s.h\"\n\n" % self.type)
# Beschreibung
fout.write("namespace conedy\n{\n")
if (self.numberAddedNodes < 10):
fout.write("const networkElementType " + self.nodeInfo + "= 10" + str(self.numberAddedNodes) + ";\n")
else:
fout.write("const networkElementType " + self.nodeInfo + "= 1" + str(self.numberAddedNodes) + ";\n")
fout.write("/**\n * \\brief %s\n" % self.shortDescription)
for d in self.doku:
fout.write(" * " +d)
fout.write(" *\n * %s\n *\n" % self.longDescription )
fout.write(" *\n")
fout.write(" * Usage (conedy):\n")
fout.write(" * n.addNode< " + self.className + "( ")
i = 1
for p in self.params:
fout.write(str(p[1]))
if (i < len(self.params)):
fout.write(", ")
i+=1
del i
fout.write(" ) >();\n")
fout.write(" * \n")
# Parameter beschreiben
for p in self.params:
fout.write(" * \\param " + p[0] + "() \tdefault Value: " + str(p[1]) + ",\tadd description here ...\n")
fout.write(" *\n **/\n")
# Klasse erstellen
fout.write("class %s : public %s" %( self.className, self.type))
if (len (self.events) > 0): # derive from eventHandler if events are specified
fout.write(", public eventHandler\n")
fout.write("\n\t{\n")
fout.write("\tprivate:\n")
# Parameter erstellen
fout.write("\t\t//! Inlinefunktionen zur einfacheren Verwaltung der %i Parameter\n" % len(self.params))
i = 0
if self.type == "pco":
i = 2
elif self.type =="pcoDelay":
i = 3
for p in self.params:
fout.write("\t\tinline baseType %s() { return params<baseType>::getParams(%i); }\n" % ( p[0], i) )
i+=1
fout.write("\t\t\n")
fout.write("\tpublic:\n")
if (self.period != ""):
dyn = self.period #replace all parameter by the inline functions
for p in self.params:
dyn = re.sub ("\\b" + p[0] + "\\b", p[0] + "()", dyn)
self.period = dyn
if (self.type == "pco" or self.type != "pcoDelay"):
fout.write("\t\t baseType period (); \n")
if (self.upkeep != ""):
dyn = self.upkeep #replace all parameter by the inline functions
for p in self.params:
dyn = re.sub ("\\b" + p[0] + "\\b", p[0] + "()", dyn)
self.upkeep = dyn
if (self.type != "pco" and self.type != "pcoDelay"):
fout.write ("\t\tvirtual bool requiresUpkeep() { return true;}\n")
fout.write ("\t\tvirtual void upkeep (); \n")
if (len (self.events) > 0):
fout.write("\t\tvirtual unsigned int numberOfEvents() const { return %i;}\n" % len(self.events))
fout.write("\t\tvirtual baseType callBack ( unsigned int eventSignature ); \n")
fout.write("\t virtual ~%s ();" % self.className)
fout.write("\t %s ( const %s &b); " %(self.className, self.className))
fout.write("\t\t//! Konstruktor ohne Parameter\n")
fout.write("\t\t%s() : %s(%s, %i) {}\n" % (self.className, self.type, self.nodeInfo, self.dim) )
fout.write("\t\t\n")
fout.write("\t\t//! Liefert die Dimension der Node zurueck\n")
fout.write("\t\tvirtual const unsigned int dimension() const { return %i;}\n" % self.dim)
fout.write("\t\t\n")
if self.type == "stdOdeIntegrator":
fout.write("\t\t//! Interface for ODE \n")
fout.write("\t\tvirtual void operator() (const baseType x[], baseType dydx[]);\n")
fout.write("\t\t\n")
elif self.type =="pco":
fout.write("\t\t//! Interface for pco\n")
fout.write("\t\tvirtual baseType phaseResponse(baseType coupling, baseType phi);\n")
fout.write("\t\t\n")
elif self.type =="pcoDelay":
fout.write("\t\t//! Interface for pco\n")
fout.write("\t\tvirtual baseType phaseResponse(baseType coupling, baseType phi);\n")
fout.write("\t\t\n")
elif self.type =="mapNode":
fout.write("\t\t//! Interface for mapNode\n")
fout.write("\t\tvirtual void operator() (baseType xprime [], baseType x[]);\n")
fout.write("\t\t\n")
elif self.type =="sde":
fout.write("\t\t//! Interface for SDE\n")
fout.write("virtual void operator()(baseType x[], baseType dxdt[], baseType s[], baseType dsdx[]);\n")
fout.write("\t\t\n")
elif self.type == "ode":
fout.write("\t\t//! Interface for ODE \n")
fout.write("\t\tvirtual void operator() (const baseType x[], baseType dydx[]);\n")
fout.write("\t\t\n")
else:
raise Exception('unknown type')
fout.write("\t\t//! Inlinefunktion fuer die NodeInfo\n")
fout.write("\t\tvirtual const nodeInfo getNodeInfo() { nodeInfo n = {%s,_dynNode_ | _%s_,\"%s\" }; return n; }\n" % (self.nodeInfo, self.type, fileNameOut))
fout.write("\t\t\n")
fout.write("\t\t//! Reserviert Speicherplatz fuer die Nodeparameter\n")
fout.write("\t\tstatic void registerStandardValues(); \n")
fout.write("\t\t\n")
fout.write("\t};\n")
fout.write("}// Ende Namespace conedy\n")
fout.write("\n")
fout.write("#endif\n")
fout.close()
del fout
def writeCppFile (self):
#
# .cpp schreiben
#
fileNameOut = self.nodeInfo[1:-1]
fout = open("generated" + self.className + ".cpp", 'w')
fout.write("#include \"generated%s.h\"" % self.className)
fout.write("\n")
fout.write("namespace conedy\n")
fout.write("{\n")
if len (self.events) > 0:
fout.write("\t baseType %s::callBack ( unsigned int eventSignature) { \n" % self.className)
counter = 0
fout.write ("\t baseType nextEvent;\n ")
for ev in self.events:
fout.write("\t\t if (eventSignature == %i) { \n" % counter)
fout.write(ev[1])
fout.write("\t\t return nextEvent; \n")
fout.write("\t\t } \n")
fout.write("\t }\n")
fout.write("\t %s::~%s (){ \n" % (self.className, self.className))
fout.write("\t\t for (unsigned int i =0; i < numberOfEvents(); i++) eventHandler::unregisterCallBack(i); \n")
fout.write("\t } \n")
fout.write("\t %s::%s ( const %s &b) : %s (b), eventHandler (b) {\n" %(self.className, self.className, self.className, self.type))
fout.write("\t\t for (unsigned int i =0; i < numberOfEvents(); i++) eventHandler::registerCallBack(i, time);} \n ")
if (self.upkeep != ""):
fout.write ("\t void %s::upkeep()" % self.className)
fout.write ("\t{\n")
fout.write(self.upkeep)
fout.write ("\t}\n")
if (self.period != ""):
fout.write ("\t baseType %s::period()" % self.className)
fout.write ("\t{\n")
fout.write(self.period)
fout.write ("\t}\n")
dyn = self.dgl #replace all parameter by the inline functions
for p in self.params:
dyn = re.sub ("\\b" + p[0] + "\\b", p[0] + "()", dyn)
self.dgl = dyn
if self.type == "stdOdeIntegrator":
fout.write("\t//! DGL von %s\n" % self.className)
fout.write("\tvoid %s::operator()(const baseType x[], baseType dxdt[]) \n" % self.className)
fout.write("\t{\n")
fout.write(self.dgl)
fout.write("\t}\n")
fout.write("\n")
elif self.type == "sde":
fout.write("\t//! DGL von %s\n" % self.className)
fout.write("\t void %s::operator()(baseType x[], baseType dxdt[], baseType s[], baseType dsdx[]) \n" %self.className)
fout.write("\t{\n")
fout.write(self.dgl)
fout.write("\t}\n")
fout.write("\n")
elif self.type =="pco":
fout.write("\t//! phaseResponseCurve von %s\n" % self.className)
fout.write("\tbaseType %s::phaseResponse(baseType coupling, baseType phase) \n" % self.className)
fout.write("\t{\n")
fout.write("\t baseType delta = 0;")
fout.write(self.dgl)
fout.write("\treturn delta;")
fout.write("\t}\n")
fout.write("\n")
elif self.type =="pcoDelay":
fout.write("\t//! phaseResponseCurve von %s\n" % self.className)
fout.write("\tbaseType %s::phaseResponse(baseType coupling, baseType phase) \n" % self.className)
fout.write("\t{\n")
fout.write("\t baseType delta = 0;")
fout.write(self.dgl)
fout.write("\treturn delta;")
fout.write("\t}\n")
fout.write("\n")
elif self.type =="mapNode":
fout.write("\t//! Map von %s\n" % self.className)
fout.write("\tvoid %s::operator()(baseType xprime[], baseType x[]) \n" % self.className)
fout.write("\t{\n")
fout.write(self.dgl)
fout.write("\t}\n")
fout.write("\n")
elif self.type == "ode":
fout.write("\t//! DGL von %s\n" % self.className)
fout.write("\tvoid %s::operator()(const baseType x[], baseType dxdt[]) \n" % self.className)
fout.write("\t{\n")
fout.write(self.dgl)
fout.write("\t}\n")
fout.write("\n")
else:
raise Exception('unknown type')
fout.write("\t//! Reserviert Speicherplatz fuer die %i Nodeparameter\n" % len(self.params) )
fout.write("\tvoid %s::registerStandardValues() \n" % self.className)
fout.write("\t{\n")
i = 0
if self.type =="pco":
fout.write("\t\tparams<baseType>::registerStandard( %s, \"%s_noiseFrequency\",0,params<baseType>::getStandardParameter (_pcoBase_, 0));\n" % (self.nodeInfo, fileNameOut))
fout.write("\t\tparams<baseType>::registerStandard( %s, \"%s_noiseIntensity\",1,params<baseType>::getStandardParameter (_pcoBase_, 1));\n" % (self.nodeInfo, fileNameOut))
i = 2
if self.type =="pcoDelay":
fout.write("\t\tparams<baseType>::registerStandard( %s, \"%s_noiseFrequency\",0,params<baseType>::getStandardParameter (_pcoBase_, 0));\n" % (self.nodeInfo, fileNameOut))
fout.write("\t\tparams<baseType>::registerStandard( %s, \"%s_noiseIntensity\",1,params<baseType>::getStandardParameter (_pcoBase_, 1));\n" % (self.nodeInfo, fileNameOut))
fout.write("\t\tparams<baseType>::registerStandard( %s, \"%s_timeDelay\",2,params<baseType>::getStandardParameter (_pcoDelay_, 2));\n" % (self.nodeInfo, fileNameOut))
i = 3
for p in self.params:
fout.write("\t\tparams<baseType>::registerStandard( %s, \"%s_%s\",%i,%.16f);\n" % (self.nodeInfo, fileNameOut, p[0], i, p[1]) )
i += 1
del i
fout.write("\t}\n")
fout.write("\t\n")
fout.write("}\n\n")
fout.close()
del fout
fout = open(".countAddedNodes" , 'w')
fout.write(str(self.numberAddedNodes)+"\n")
fout.close()
def addNodeToConedy(self, fileNameOut=""):
"Fuegt die Node in den Dateien generatedNodes.cpp, networkConstants.h, fullNetwork.h, Scanner.ll, Parser.yy, ... ein"
if (fileNameOut == ""):
fileNameOut = self.nodeInfo[1:-1]
print "including " + fileNameOut
#
# generatedNodes.cpp
#
#
# generatedNodes.cpp
#
fout = open ("generatedNodes.cpp", 'a')
fout.write ("#include \"generated%s.cpp\"\n" % self.className)
fout.close()
del fout
#
# generatedRegisterStandards.h
#
fout = open ("generatedRegisterStandards.h", 'a')
fout.write("%s::registerStandardValues();\n" % self.className)
fout.close()
del fout
if (n.type == "mapNode"):
n.type = "map"
#
# neuroPython.cpp
#
fout = open ("generatedNeuroPython.cpp", 'a')
if self.static == 0:
fout.write("class_< nodeVirtualEdges<%s> , bases<nodeBlueprint> > (\"%s\", reinterpret_cast<const char *>(__addedNodes_%s_%s) ) // added by addNewNodes.py \n" %(self.className, fileNameOut, self.type,self.className))
fout.write(". def (\"__init__\", make_constructor (nodeFactory%i < nodeVirtualEdges <%s> > )); // added by addNewNodes.py\n" % (len(self.params), self.className)) #adding constructor with different parameters
elif self.static == 1:
self.staticEdgeType = self.staticEdgeType.replace ("_","<")
hierachy = self.staticEdgeType.count ("<")
self.staticEdgeType += ("<")
self.staticEdgeBlueprint = self.staticEdgeType + (" edgeVirtual")
self.staticEdgeType = self.staticEdgeType + (" edge")
for i in range (0, hierachy):
self.staticEdgeType += (">")
self.staticEdgeBlueprint += (">")
fout.write("class_< nodeTemplateEdges< %s > , %s > , %s >, bases<nodeBlueprint> > (\"%s\", reinterpret_cast<const char *>(__addedNodes_%s_%s) ) // added by addNewNodes.py\n" %(self.staticEdgeType, self.staticEdgeBlueprint,self.className, fileNameOut, self.type, self.className))
fout.write(". def (\"__init__\", make_constructor (nodeFactory%i < nodeTemplateEdges <%s >, %s > , %s > > )); // added by addNewNodes.py\n" %( len(self.params), self.staticEdgeType, self.staticEdgeBlueprint, self.className)) #adding constructor with different parameters
fout.close()
del fout
#
# write documentation
#
fout = open("testing/addedNodes/" + self.type + "/" + self.className + ".rst", 'w')
# fout.write(self.className +"\n")
# fout.write("------------------------------------------\n\n")
for d in self.doku:
fout.write(d)
fout.write("\n\nDGL of %s\n" % self.className)
fout.write("------------------------------------------\n\n")
if (self.type == "pco" or self.type == "pcoDelay"):
fout.write("::\n")
fout.write(self.dgl.replace("\n","\n\n\t"))
else:
#write documentation in math modus ???
# fout.write(".. math::\n\t")
# fout.write(self.dgl.lstrip().replace("\n","\\\\\n\t"))#. replace("=","&="))
fout.write("::\n")
fout.write(self.dgl.replace("\n","\n\n\t"))
fout.write ("\n\n")
fout.write("Parameter of %s\n" % self.className)
fout.write("-----------------------------------------\n\n")
fout.write ("\n\n")
for p in self.params:
fout.write("- %s_%s \t\t = %.16f; \n" % (self.className, p[0], p[1]) )
fout.write("\n")
#write test scripts
fout = open("testing/addedNodes/" + self.type +"/" + self.className + ".py", 'w')
fout.write("import conedy as ns\n\n")
fout.write("net = ns.network()\n\n")
fout.write("net.addNode(ns.%s())" % fileNameOut)
fout.close()
fout = open("testing/addedNodes/" + self.type +"/expected/sum_" + self.className + ".py", 'w')
fout.write("00000 0 output/"+self.className +".py.err\n")
fout.write("00000 0 output/"+self.className +".py.out\n")
fout.close()
fout = open("testing/addedNodes/" + self.type +"/" + self.className + ".co", 'w')
fout.write("network net;\n\n")
fout.write("net.addNode(%s()); \n\n" % fileNameOut)
fout.close()
fout = open("testing/addedNodes/" + self.type +"/expected/sum_" + self.className + ".co", 'w')
fout.write("00000 0 output/"+self.className +".co.err\n")
fout.write("00000 0 output/"+self.className +".co.out\n")
fout.close()
#
# generatedFullNetwork.h bearbeiten
#
fout = open("generatedFullNetwork.h", 'a')
fout.write("#include \"generated%s.h\"\n" % self.className)
fout.close()
del fout
#
# generatedAddNewNodes.yy
#
fout = open("generatedAddNewNode.yy", 'a')
if (self.static == 0):
fout.write("\t\t| %s { nodeBlueprint *n = new nodeVirtualEdges< %s >(); $$ = new constantCommand<nodeBlueprint*>(n); }\n" % (self.className.upper(), self.className))
if (self.static ==1):
fout.write("\t\t| %s { nodeBlueprint *n = new nodeTemplateEdges< %s > , %s > , %s >(); $$ = new constantCommand<nodeBlueprint*>(n); }\n" % (self.className.upper(), self.staticEdgeType, self.staticEdgeBlueprint, self.className))
fout.close()
del fout
#
# generatedAddNewNodesTokens.yy
#
fout = open("generatedAddNewNodeTokens.yy", 'a')
fout.write("%token " + self.className.upper() + "\n")
fout.close()
del fout
fout = open("Scanner.ll.generated", 'a')
fout.write("%s\t\t\t{ return(ParserBase::%s); } // added by addNewNodes.py \n" % (fileNameOut, self.className.upper()))
fout.close()
del fout
# MAINFUNCTION
if (len(sys.argv) < 2):
print "give filename with node-description as argument."
exit()
else:
config = ConfigParser.RawConfigParser()
config.read(sys.argv[1])
for className in config.sections():
n= NodeEditor()
n.params = []
n.events = []
n.dgl = []
try:
numberEvents = config.getint(className, 'events')
for i in range (1,numberEvents+1 ):
n.events.append( (i, config.get(className, 'event' + str(i))))
except:
n.events = []
for i in range (1,config.getint(className, 'parameter')+ 1):
n.params.append( (config.get(className, 'parametername' + str(i)) , config.getfloat(className, 'defaultvalue' + str(i))) )
#staticEdges = 1 is not really needed
# try:
# n.static = config.getboolean(className, 'staticEdges')
# except:
# n.static = 0
try:
n.staticEdgeType = config.get(className, 'staticEdgeType')
n.static = 1
except:
n.staticEdgeType = ""
n.static = 0
try:
n.staticTargetNodeType = config.get(className, 'staticTargetNodeType')
except:
n.staticTargetNodeType = ""
n.className = className
n.nodeInfo = "_" + n.className + "_"
n.dim = config.getint(className, 'dimension')
n.parameter = config.getint(className, 'parameter')
n.type = config.get(className, 'type')
if (n.type == "map"):
n.type = "mapNode"
n.dgl = config.get(className, 'dynamics')
try:
n.documentation = config.get(className, 'dokumentation')
except:
n.documentation = []
n.nodeInfo = "_" + n.className + "_"
try:
n.period = config.get(className, 'period')
except:
n.period = ""
try:
n.upkeep = config.get(className, 'upkeep')
except:
n.upkeep = ""
n.writeHeaderFile()
n.writeCppFile()
n.addNodeToConedy()
del (n)