libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moMathFunctionIndex.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moMathFunctionIndex.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 "moMathFunctionIndex.h"
33 
34 MOint moMathFunctionIndex::Add(moText p_name, moMathManager* p_math_man) // Returns the index of the newly added texture.
35 {
36  MOint moid = p_math_man->AddFunction(p_name, false);
37  if (-1 < moid) return Add(p_math_man->GetFunction(moid));
38  else return -1;
39 }
40 
42 {
43  MOint idx;
44  m_functions_array.Add(p_tex);
45  idx = m_functions_array.Count() - 1;
46  moText msg;
47  #ifdef _DEBUG
48  msg = moText("Function loaded: ");
49  msg += m_functions_array[idx]->GetExpression();
50  MODebug2->Log(msg);
51  #endif
52  return idx;
53 }
54 
55 
57 {
58  if (ValidIndex(p_idx)) return m_functions_array[p_idx];
59  return NULL;
60 }
61 
63 {
64  if ( p_idx < m_functions_array.Count()) return true;
65  else
66  {
67  moText text;
68  text = moText("Error(moMathFunctionIndex): the index: ");
69  text += IntToStr(p_idx);
70  text += moText(" does not exists.");
71  MODebug2->Error(text);
72  return false;
73  }
74 }
75 
76 MOuint moMathFunctionIndex::LoadFunctions(moConfig* p_cfg, moMathManager* p_math_man, MOuint p_param_idx, MOuint p_subvalue_idx)
77 {
78  if (p_cfg!=NULL) m_pConfig = p_cfg; else return MO_ERROR;
79  m_ParamIndex.index = p_param_idx;
80  m_SubValueIndex = p_subvalue_idx;
81 
82  MOint moid;
83  MOint idx = -1;
84  MOuint nFunctions = m_pConfig->GetParam(p_param_idx).GetValuesCount();
85  MOuint nSubValues;
86  moMathFunction *pfunc;
87 
88  p_cfg->SetCurrentParamIndex(m_ParamIndex.index);
89  p_cfg->FirstValue();
90  for (MOuint i = 0; i < nFunctions; i++)
91  {
92  nSubValues = p_cfg->GetParam().GetValue(i).GetSubValueCount();
93  moText txt = "";
94  moValueType vt;
95 
96  vt = p_cfg->GetParam().GetValue(i).GetSubValue(p_subvalue_idx).GetType();
97  if ( vt==MO_VALUE_FUNCTION ) {
98  txt = p_cfg->GetParam().GetValue(i).GetSubValue(p_subvalue_idx).Text();
99  } else {
100  txt = FloatToStr(p_cfg->GetParam().GetValue(i).GetSubValue(p_subvalue_idx).Float());
101  }
102  moid = p_math_man->AddFunction( txt, false);
103  if (-1 < moid)
104  {
105  idx++;
106  pfunc = p_math_man->GetFunction(moid);
107  m_functions_array.Add(pfunc);
108  #ifdef _DEBUG
109  moText msg;
110  msg = moText("Function loaded: ");
111  msg += pfunc->GetExpression();
112  MODebug2->Log(msg);
113  #endif
114  }
115  p_cfg->NextValue();
116  }
117  return m_functions_array.Count();
118 }
119 
120 
122  if (p_value_index == MO_SELECTED)
123  p_value_index = m_pConfig->GetParams().Get(m_ParamIndex.index).GetIndexValue();
124  return (m_pConfig !=NULL ? GetFunction( p_value_index ) : NULL);
125 
126 }
127 
void Error(moText p_text)
Anuncia y registra un error.
Definition: moAbstract.cpp:79
moParams & GetParams()
Devuelve el puntero al arreglo de parámetros.
Definition: moConfig.cpp:977
moValueBase & GetSubValue(MOint p_indexsubvalue=0)
Definition: moValue.h:539
bool NextValue()
Selecciona el próximo valor del parámetro actual.
Definition: moConfig.cpp:1545
LIBMOLDEO_API moText0 FloatToStr(double a)
Definition: moText.cpp:1134
#define MOboolean
Definition: moTypes.h:385
MOlong index
Definition: moParam.h:124
MOint Add(moText p_name, moMathManager *p_math_man)
#define MO_ERROR
Definition: moTypes.h:377
clase de para manejar textos
Definition: moText.h:75
MOboolean ValidIndex(MOuint p_idx)
void Log(moText p_text)
Escribe un mensaje en el archivo de registro (log)
Definition: moAbstract.cpp:123
moMathFunction * Fun(MOint p_value_index=MO_SELECTED)
MOfloat Float() const
Definition: moValue.cpp:835
moText0 moText
Definition: moText.h:291
#define MOint
Definition: moTypes.h:388
moMathFunction * GetFunction(MOuint p_idx)
moMathFunction * GetFunction(MOuint p_idx)
static moDebug * MODebug2
Clase de impresión de errores para depuración
Definition: moAbstract.h:225
moText Text()
Definition: moValue.cpp:539
MOint AddFunction(const moText &p_expr, MOboolean p_force_new=false, moMoldeoObject *p_pMOB=NULL)
#define MO_SELECTED
Definition: moConfig.h:44
moValue & GetValue(MOint i=-1)
Definition: moParam.cpp:1204
moParam & GetParam(MOint p_paramindex=-1)
Devuelve el parámetro por índice.
Definition: moConfig.cpp:984
#define MOuint
Definition: moTypes.h:387
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
bool SetCurrentParamIndex(int)
Selecciona el parámetro por el índice.
Definition: moConfig.cpp:1497
MOuint GetSubValueCount()
Definition: moValue.h:545
MOuint GetValuesCount() const
Definition: moParam.cpp:1065
moValueType GetType() const
Devuelve el tipo de valor ,esta función se implementa sólo como atajo a ciertos datos de la definición ...
Definition: moValue.cpp:1498
moMathFunction
bool FirstValue()
Selecciona el primer valor del parámetro actual.
Definition: moConfig.cpp:1532
virtual moText & GetExpression()
moValueType
Definition: moValue.h:300
almacena la configuración de los parámetros de un objeto en un archivo XML
Definition: moConfig.h:193