source: cpp/gdk/neuroclsobject.cpp @ 68

Last change on this file since 68 was 68, checked in by Maciej Komosinski, 13 years ago

added missing sources; updated sources for compatibility with vs2008 and added project files

File size: 3.5 KB
Line 
1// This file is a part of the Framsticks GDK library.
2// Copyright (C) 2002-2011  Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include "neuroclsobject.h"
6#include "neurolibrary.h"
7#include "paramvmobj.h"
8
9#define FIELDSTRUCT NeuroClassExt
10ParamEntry neuroclass_paramtab[]=
11{
12{"NeuroClass",1,10,"NeuroClass","The static NeuroClass object refers to class selected in the NeuroClassLibrary."},
13{"name",0,0,"Class name","s",FIELD(name),},
14{"longname",0,0,"Long, human readable name","s",FIELD(longname),},
15{"description",0,0,"Long description","s",FIELD(description),},
16{"prefinputs",0,0,"Preferred number of inputs","d",FIELD(prefinputs),},
17{"prefoutput",0,0,"Provides output","d 0 1",FIELD(prefoutput),},
18{"preflocation",0,0,"Preferred body location","d 0 2 ~None~Part~Joint",FIELD(preflocation),},
19{"visualhints",0,0,"Visual hints","d",FIELD(visualhints),},
20{"glyph",0,0,"Glyph vector data","s",GETSET(glyph),},
21{"properties",0,0,"Interface object connected with neuron class properties","o Interface",GETONLY(props),},
22{"summary",0,0,"Summary","s",GETONLY(summary),"Textual summary of all features",},
23{0,0,0,},
24};
25#undef FIELDSTRUCT
26
27static Param static_neuroclassparam(neuroclass_paramtab);
28
29void NeuroClassExt::makeStaticObject(ExtValue *ret,NeuroClass *cl)
30{
31if (cl)
32        *ret=ExtObject(&static_neuroclassparam,cl);
33else
34        ret->setEmpty();
35}
36
37#define FIELDSTRUCT NeuroClassLibObject
38ParamEntry neuroclasslib_paramtab[]=
39{
40{"NeuroClassLibrary",1,4,"NeuroClassLibrary","Set of Neuron classes. You can access the selected class in the static NeuroClass object.",},
41{"count",0,0,"class count","d",GETONLY(count),},
42{"class",0,0,"current class","d",SETFIELD(current),"0 ... count-1"},
43{"findClass",0,0,"select class by name","p(s class name)",PROCEDURE(p_findclass),},
44{"getClass",0,0,"get class object by name","p NeuroClass(s class name)",PROCEDURE(p_getclass),},
45{0,0,0,},
46};
47#undef FIELDSTRUCT
48
49/////////////////////
50
51NeuroClassLibObject::NeuroClassLibObject():
52        param(neuroclasslib_paramtab,this),
53        classparam(neuroclass_paramtab),
54        current(0)
55{
56selectClass(-1);
57}
58
59void NeuroClassLibObject::selectClass(int i)
60{
61if (i >= lib().getClassCount()) i=-1;
62if (current!=i)
63        {
64        current=i;
65        classparam.select((i>=0)?lib().getClass(i):&invalid);
66        }
67}
68
69int NeuroClassLibObject::set_current(PARAMSETARGS)
70{
71selectClass(arg->getInt());
72return PSET_CHANGED;
73}
74
75void NeuroClassLibObject::p_findclass(PARAMPROCARGS)
76{
77selectClass(lib().findClassIndex(args->getString()));
78}
79
80void NeuroClassLibObject::p_getclass(PARAMPROCARGS)
81{
82int i=lib().findClassIndex(args->getString());
83NeuroClassExt::makeStaticObject(ret,(i>=0)?lib().getClass(i):0);
84}
85
86int* NeuroClassLibObject::convertVectorData(const SString& s)
87{
88SList t;
89int pos=0;
90SString n;
91while(s.getNextToken(pos,n,','))
92        t+=(void*)atol((const char*)n);
93int *ret;
94if (!t.size()) return 0;
95ret=new int[t.size()];
96for (int i=0;i<t.size();i++)
97        ret[i]=(long)t(i);
98return ret;
99}
100
101int NeuroClassExt::set_glyph(PARAMSETARGS)
102{
103setSymbolGlyph(NeuroClassLibObject::convertVectorData(arg->getString()));
104return PSET_CHANGED;
105}
106
107void NeuroClassExt::get_glyph(PARAMGETARGS)
108{
109SString txt;
110if (vectordata)
111        {
112        int *d=vectordata;
113        int len=*(d++);
114        txt+=SString::valueOf(len);
115        for (;len>0;len--)
116                {
117                txt+=',';
118                txt+=SString::valueOf(*(d++));
119                }
120        }
121ret->setString(txt);
122}
123
124void NeuroClassExt::get_props(PARAMGETARGS)
125{
126static Param par;
127par=getProperties();
128ret->setObject(ParamVMObj::makeObject(&par));
129}
Note: See TracBrowser for help on using the repository browser.