[68] | 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
|
---|
| 10 | ParamEntry 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 |
|
---|
| 27 | static Param static_neuroclassparam(neuroclass_paramtab);
|
---|
| 28 |
|
---|
| 29 | void NeuroClassExt::makeStaticObject(ExtValue *ret,NeuroClass *cl)
|
---|
| 30 | {
|
---|
| 31 | if (cl)
|
---|
| 32 | *ret=ExtObject(&static_neuroclassparam,cl);
|
---|
| 33 | else
|
---|
| 34 | ret->setEmpty();
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | #define FIELDSTRUCT NeuroClassLibObject
|
---|
| 38 | ParamEntry 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 |
|
---|
| 51 | NeuroClassLibObject::NeuroClassLibObject():
|
---|
| 52 | param(neuroclasslib_paramtab,this),
|
---|
| 53 | classparam(neuroclass_paramtab),
|
---|
| 54 | current(0)
|
---|
| 55 | {
|
---|
| 56 | selectClass(-1);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | void NeuroClassLibObject::selectClass(int i)
|
---|
| 60 | {
|
---|
| 61 | if (i >= lib().getClassCount()) i=-1;
|
---|
| 62 | if (current!=i)
|
---|
| 63 | {
|
---|
| 64 | current=i;
|
---|
| 65 | classparam.select((i>=0)?lib().getClass(i):&invalid);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | int NeuroClassLibObject::set_current(PARAMSETARGS)
|
---|
| 70 | {
|
---|
| 71 | selectClass(arg->getInt());
|
---|
| 72 | return PSET_CHANGED;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | void NeuroClassLibObject::p_findclass(PARAMPROCARGS)
|
---|
| 76 | {
|
---|
| 77 | selectClass(lib().findClassIndex(args->getString()));
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | void NeuroClassLibObject::p_getclass(PARAMPROCARGS)
|
---|
| 81 | {
|
---|
| 82 | int i=lib().findClassIndex(args->getString());
|
---|
| 83 | NeuroClassExt::makeStaticObject(ret,(i>=0)?lib().getClass(i):0);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | int* NeuroClassLibObject::convertVectorData(const SString& s)
|
---|
| 87 | {
|
---|
| 88 | SList t;
|
---|
| 89 | int pos=0;
|
---|
| 90 | SString n;
|
---|
| 91 | while(s.getNextToken(pos,n,','))
|
---|
| 92 | t+=(void*)atol((const char*)n);
|
---|
| 93 | int *ret;
|
---|
| 94 | if (!t.size()) return 0;
|
---|
| 95 | ret=new int[t.size()];
|
---|
| 96 | for (int i=0;i<t.size();i++)
|
---|
| 97 | ret[i]=(long)t(i);
|
---|
| 98 | return ret;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | int NeuroClassExt::set_glyph(PARAMSETARGS)
|
---|
| 102 | {
|
---|
| 103 | setSymbolGlyph(NeuroClassLibObject::convertVectorData(arg->getString()));
|
---|
| 104 | return PSET_CHANGED;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | void NeuroClassExt::get_glyph(PARAMGETARGS)
|
---|
| 108 | {
|
---|
| 109 | SString txt;
|
---|
| 110 | if (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 | }
|
---|
| 121 | ret->setString(txt);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | void NeuroClassExt::get_props(PARAMGETARGS)
|
---|
| 125 | {
|
---|
| 126 | static Param par;
|
---|
| 127 | par=getProperties();
|
---|
| 128 | ret->setObject(ParamVMObj::makeObject(&par));
|
---|
| 129 | }
|
---|