source: cpp/frams/neuro/neurolibparam.cpp @ 197

Last change on this file since 197 was 197, checked in by Maciej Komosinski, 7 years ago

GDK used by developers since 1999, distributed on the web since 2002

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include <ctype.h>
6#include "neurolibparam.h"
7#include <frams/neuro/neurolibrary.h>
8
9NeuroLibParam::NeuroLibParam(const char* gr, const char* name, const char* pref)
10        :mygroup(gr),myname(name),myprefix(pref)
11{
12anode=NeuroLibrary::staticlibrary.classes.l_add.add(
13        STATRICKCALLBACK(this,&NeuroLibParam::neuroclassAdded,0));
14dnode=NeuroLibrary::staticlibrary.classes.l_postdel.add(
15        STATRICKCALLBACK(this,&NeuroLibParam::neuroclassRemoved,0));
16}
17
18NeuroLibParam::~NeuroLibParam()
19{
20NeuroLibrary::staticlibrary.classes.l_add.removeNode(anode);// remove(anode) tez powinno byc ok - do sprawdzenia
21NeuroLibrary::staticlibrary.classes.l_postdel.removeNode(dnode);
22}
23
24void NeuroLibParam::neuroclassAdded(void* data,long i)
25{onadd.action(i);}
26void NeuroLibParam::neuroclassRemoved(void* data,long i)
27{ondelete.action(i);}
28
29static bool isGoodName(const SString& name)
30{
31for(int i=0;i<name.len();i++)
32        if (!isalnum(name[i])) return false;
33return true;
34}
35
36const char *NeuroLibParam::id(int i)
37{
38static SString t;
39if (i>=Neuro::getClassCount()) return 0;
40t=myprefix;
41SString n=Neuro::getClass(i)->getName();
42if (isGoodName(n))
43        t+=n;
44else
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        }
53return t;
54}
55
56const char *NeuroLibParam::name(int i)
57{
58static SString t;
59t=Neuro::getClass(i)->getLongName();
60t+=" ("; t+=Neuro::getClassName(i); t+=")";
61return t;
62}
63
64const char *NeuroLibParam::help(int i)
65{
66static SString t;
67t=Neuro::getClass(i)->getSummary();
68return t;
69}
70
71int NeuroLibParam::grmember(int gi,int n)
72{
73return (gi==0)?
74        ((n>=getPropCount())?-9999:n)
75        :
76        -9999;
77}
78
Note: See TracBrowser for help on using the repository browser.