libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Amigas 'defines' Grupos Páginas
moMathManager.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moMathManager.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28  Andrés Colubri
29 
30 *******************************************************************************/
31 
32 #include "moMathManager.h"
33 
34 #include "moMathVector3.h"
35 
37 
38 
40 {
43 
44  SetName("Math Manager");
45  SetLabelName("Math Manager");
46 }
47 
49 {
50  Finish();
51 }
52 
54 {
55  m_functions.Init(0, NULL);
56 
57  return true;
58 }
59 
61 {
62  for(MOuint i =0; i<m_functions.Count(); i++) {
63  moMathFunction* pfunc = m_functions[i];
64  if (pfunc) {
65  pfunc->Finish();
66  delete pfunc;
67  m_functions.Set(i,NULL);
68  }
69  }
70  m_functions.Finish();
71 
72  return true;
73 }
74 
76 {
77  return m_functions[p_idx];
78 }
79 
80 
82 {
83  moMathFunction* pfun;
84  for (MOuint i = 0; i < m_functions.Count(); i++)
85  {
86  pfun = m_functions[i];
87  if ((pfun != NULL) && (!stricmp(pfun->GetExpression(), moText(p_expr)))) return i;
88  }
89  return -1;
90 }
91 
92 MOint moMathManager::AddFunction(const moText& p_expr, MOboolean p_force_new, moMoldeoObject* p_pMOB )
93 {
94 
95  MOint idx = -1;
96 
97  if ( p_expr.Length() == 0 )
98  return idx;
99 
100  if (!p_force_new)
101  {
102  idx = GetFunctionIdx(p_expr);
103  if (-1 < idx) return idx; // La función ya existe.
104  }
105 
106  moMathFunction* p_math_fun;
107  moParserFunction* p_parser_fun; // Función de parseado.
108 
109  p_math_fun = BuiltInMathFunctionFactory(p_expr);
110  if (p_math_fun == NULL)
111  {
112  p_parser_fun = new moParserFunction();
113 
114  p_math_fun = (moMathFunction*)p_parser_fun;
115  }
116 
117  if (p_math_fun != NULL)
118  {
119  bool res = p_math_fun->Init( p_expr, p_pMOB );
120  if (res)
121  {
122  m_functions.Add(p_math_fun);
123  //double check = p_math_fun->Eval(0);
124  return m_functions.Count() - 1;
125  }
126  else
127  {
128  delete p_math_fun;
129  return -1;
130  }
131  }
132  else return -1;
133 }
134 
135 
136 double moMathManager::EvalFunction(MOuint p_idx, double x0)
137 {
138  if (ValidFunction(p_idx))
139  return m_functions[p_idx]->Eval(x0);
140  else return 0;
141 }
142 
143 double moMathManager::EvalFunction(MOuint p_idx, double x0, double x1)
144 {
145  if (ValidFunction(p_idx)) return m_functions[p_idx]->Eval(x0, x1);
146  else return 0;
147 }
148 
149 double moMathManager::EvalFunction(MOuint p_idx, double x0, double x1, double x2)
150 {
151  if (ValidFunction(p_idx)) return m_functions[p_idx]->Eval(x0, x1, x2);
152  else return 0;
153 }
154 
156 {
157  if (ValidFunction(p_idx)) m_functions[p_idx]->SetParameters(s0);
158 }
159 
160 void moMathManager::SetFunctionParam(MOuint p_idx, double s0, double s1)
161 {
162  if (ValidFunction(p_idx)) m_functions[p_idx]->SetParameters(s0, s1);
163 }
164 
165 void moMathManager::SetFunctionParam(MOuint p_idx, double s0, double s1, double s2)
166 {
167  if (ValidFunction(p_idx)) m_functions[p_idx]->SetParameters(s0, s1, s2);
168 }
169 
virtual MOboolean Finish()
void SetName(const moText &p_name)
void SetFunctionParam(MOuint p_idx, double s0)
#define MOboolean
Definition: moTypes.h:385
virtual MOboolean Init(const moText &p_Expression, moMoldeoObject *p_pMOB=NULL)
void SetResourceType(moResourceType p_restype)
moMathFunction * BuiltInMathFunctionFactory(const moText &p_expr)
clase de para manejar textos
Definition: moText.h:75
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
Definition: moTypes.h:532
MOint GetFunctionIdx(const moText &p_expr)
moTypes MOint moText moParamIndex moParamReference int iRow int int i int i
Definition: all_f.js:18
moText0 moText
Definition: moText.h:291
#define MOint
Definition: moTypes.h:388
Clase Base para Objetos Moldeo ( moEffect, moIODevice, moResource, moConsole )
double EvalFunction(MOuint p_idx, double x0)
MOuint Length() const
Definition: moText.cpp:347
void SetLabelName(const moText &p_labelname)
moMathFunction * GetFunction(MOuint p_idx)
static moMathd * mathfd
MOint AddFunction(const moText &p_expr, MOboolean p_force_new=false, moMoldeoObject *p_pMOB=NULL)
MOboolean ValidFunction(MOuint p_idx)
virtual MOboolean Init()
virtual MOboolean Finish()
#define MOuint
Definition: moTypes.h:387
moMathFunctionArray m_functions
moMath< double > moMathd
Definition: moMath.h:850
moMathFunction
virtual ~moMathManager()
void SetType(moMoldeoObjectType p_type)
virtual moText & GetExpression()