[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
| 2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
| 3 | // See LICENSE.txt for details. |
---|
[138] | 4 | |
---|
| 5 | #include <ctype.h> |
---|
| 6 | #include "neurolibparam.h" |
---|
| 7 | #include <frams/neuro/neurolibrary.h> |
---|
| 8 | |
---|
| 9 | NeuroLibParam::NeuroLibParam(const char* gr, const char* name, const char* pref) |
---|
| 10 | :mygroup(gr),myname(name),myprefix(pref) |
---|
| 11 | { |
---|
| 12 | anode=NeuroLibrary::staticlibrary.classes.l_add.add( |
---|
| 13 | STATRICKCALLBACK(this,&NeuroLibParam::neuroclassAdded,0)); |
---|
| 14 | dnode=NeuroLibrary::staticlibrary.classes.l_postdel.add( |
---|
| 15 | STATRICKCALLBACK(this,&NeuroLibParam::neuroclassRemoved,0)); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | NeuroLibParam::~NeuroLibParam() |
---|
| 19 | { |
---|
| 20 | NeuroLibrary::staticlibrary.classes.l_add.removeNode(anode);// remove(anode) tez powinno byc ok - do sprawdzenia |
---|
| 21 | NeuroLibrary::staticlibrary.classes.l_postdel.removeNode(dnode); |
---|
| 22 | } |
---|
| 23 | |
---|
[247] | 24 | void NeuroLibParam::neuroclassAdded(void* data,intptr_t i) |
---|
[138] | 25 | {onadd.action(i);} |
---|
[247] | 26 | void NeuroLibParam::neuroclassRemoved(void* data,intptr_t i) |
---|
[138] | 27 | {ondelete.action(i);} |
---|
| 28 | |
---|
| 29 | static bool isGoodName(const SString& name) |
---|
| 30 | { |
---|
| 31 | for(int i=0;i<name.len();i++) |
---|
| 32 | if (!isalnum(name[i])) return false; |
---|
| 33 | return true; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | const char *NeuroLibParam::id(int i) |
---|
| 37 | { |
---|
| 38 | static SString t; |
---|
| 39 | if (i>=Neuro::getClassCount()) return 0; |
---|
| 40 | t=myprefix; |
---|
| 41 | SString n=Neuro::getClass(i)->getName(); |
---|
| 42 | if (isGoodName(n)) |
---|
| 43 | t+=n; |
---|
| 44 | else |
---|
| 45 | {//jezeli w nazwie klasy neuronu sa "dziwne" znaki to zamiast tego uzywamy long name |
---|
| 46 | // * -> Constant, | -> Bend_muscle, @ -> Rotation_muscle |
---|
| 47 | n=Neuro::getClass(i)->getLongName(); |
---|
| 48 | for(char* p=n.directWrite();*p;p++) |
---|
| 49 | if (*p==' ') *p='_'; |
---|
| 50 | n.endWrite(); |
---|
| 51 | t+=n; |
---|
| 52 | } |
---|
[348] | 53 | return t.c_str(); |
---|
[138] | 54 | } |
---|
| 55 | |
---|
| 56 | const char *NeuroLibParam::name(int i) |
---|
| 57 | { |
---|
| 58 | static SString t; |
---|
| 59 | t=Neuro::getClass(i)->getLongName(); |
---|
| 60 | t+=" ("; t+=Neuro::getClassName(i); t+=")"; |
---|
[348] | 61 | return t.c_str(); |
---|
[138] | 62 | } |
---|
| 63 | |
---|
| 64 | const char *NeuroLibParam::help(int i) |
---|
| 65 | { |
---|
| 66 | static SString t; |
---|
| 67 | t=Neuro::getClass(i)->getSummary(); |
---|
[348] | 68 | return t.c_str(); |
---|
[138] | 69 | } |
---|
| 70 | |
---|
| 71 | int NeuroLibParam::grmember(int gi,int n) |
---|
| 72 | { |
---|
| 73 | return (gi==0)? |
---|
| 74 | ((n>=getPropCount())?-9999:n) |
---|
| 75 | : |
---|
| 76 | -9999; |
---|
| 77 | } |
---|
| 78 | |
---|