00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include <new>
00047
00048 #include "ColorParameterSet.h"
00049
00050 #include <stdio.h>
00051 #include <string.h>
00052 #include <string>
00053
00054
00055
00056
00057
00058
00059
00060
00061 CColorParameterSet::CColorParameterSet()
00062 {
00063 m_nColors = (int) eNumberOfColors;
00064
00065 m_ppParameters = new int*[m_nColors];
00066 for (int i = 0; i < m_nColors; i++)
00067 {
00068 m_ppParameters[i] = new int[6];
00069
00070 for (int j = 0; j < 6; j++)
00071 m_ppParameters[i][j] = 0;
00072 }
00073
00074 SetColorParameters(eSkin, 1, 16, 20, 128, 25, 255);
00075 SetColorParameters(eYellow, 40, 26, 36, 255, 25, 255);
00076 SetColorParameters(eOrange, 21, 15, 128, 255, 25, 255);
00077 SetColorParameters(eRed, 0, 10, 140, 255, 25, 255);
00078 SetColorParameters(eBlue, 113, 13, 149, 255, 25, 255);
00079 SetColorParameters(eGreen, 65, 20, 100, 255, 25, 255);
00080 SetColorParameters(eWhite, 90, 90, 0, 120, 200, 255);
00081 }
00082
00083 CColorParameterSet::~CColorParameterSet()
00084 {
00085 for (int i = 0; i < m_nColors; i++)
00086 delete [] m_ppParameters[i];
00087
00088 delete [] m_ppParameters;
00089 }
00090
00091
00092
00093
00094
00095
00096 CColorParameterSet::CColorParameterSet(const CColorParameterSet &colorParameterSet)
00097 {
00098 m_nColors = colorParameterSet.m_nColors;
00099
00100 m_ppParameters = new int*[m_nColors];
00101
00102 for (int i = 0; i < m_nColors; i++)
00103 {
00104 m_ppParameters[i] = new int[6];
00105
00106 m_ppParameters[i][0] = colorParameterSet.m_ppParameters[i][0];
00107 m_ppParameters[i][1] = colorParameterSet.m_ppParameters[i][1];
00108 m_ppParameters[i][2] = colorParameterSet.m_ppParameters[i][2];
00109 m_ppParameters[i][3] = colorParameterSet.m_ppParameters[i][3];
00110 m_ppParameters[i][4] = colorParameterSet.m_ppParameters[i][4];
00111 m_ppParameters[i][5] = colorParameterSet.m_ppParameters[i][5];
00112 }
00113 }
00114
00115
00116
00117
00118
00119
00120 CColorParameterSet& CColorParameterSet::operator=(const CColorParameterSet &colorParameterSet)
00121 {
00122 if (this == &colorParameterSet)
00123 return *this;
00124
00125 int i;
00126
00127 for (i = 0; i < m_nColors; i++)
00128 delete [] m_ppParameters[i];
00129
00130 delete [] m_ppParameters;
00131
00132
00133 m_nColors = colorParameterSet.m_nColors;
00134
00135 m_ppParameters = new int*[m_nColors];
00136
00137 for (i = 0; i < m_nColors; i++)
00138 {
00139 m_ppParameters[i] = new int[6];
00140
00141 m_ppParameters[i][0] = colorParameterSet.m_ppParameters[i][0];
00142 m_ppParameters[i][1] = colorParameterSet.m_ppParameters[i][1];
00143 m_ppParameters[i][2] = colorParameterSet.m_ppParameters[i][2];
00144 m_ppParameters[i][3] = colorParameterSet.m_ppParameters[i][3];
00145 m_ppParameters[i][4] = colorParameterSet.m_ppParameters[i][4];
00146 m_ppParameters[i][5] = colorParameterSet.m_ppParameters[i][5];
00147 }
00148
00149 return *this;
00150 }
00151
00152 void CColorParameterSet::SetColorParameters(ObjectColor color, int par1, int par2, int par3, int par4, int par5, int par6)
00153 {
00154 const int nIndex = (int) color;
00155
00156 if (nIndex < 0 || nIndex >= m_nColors)
00157 {
00158 printf("error: tried to assign color '%i' with enum out of range (m_nColors = %i)\n", nIndex, m_nColors);
00159 return;
00160 }
00161
00162 m_ppParameters[nIndex][0] = par1;
00163 m_ppParameters[nIndex][1] = par2;
00164 m_ppParameters[nIndex][2] = par3;
00165 m_ppParameters[nIndex][3] = par4;
00166 m_ppParameters[nIndex][4] = par5;
00167 m_ppParameters[nIndex][5] = par6;
00168 }
00169
00170 const int* CColorParameterSet::GetColorParameters(ObjectColor color) const
00171 {
00172 const int nIndex = (int) color;
00173
00174 if (nIndex < 0 || nIndex >= m_nColors)
00175 {
00176 printf("error: tried to retrieve color '%i' with enum out of range (m_nColors = %i)\n", nIndex, m_nColors);
00177 return 0;
00178 }
00179
00180 return m_ppParameters[nIndex];
00181 }
00182
00183 ObjectColor CColorParameterSet::Translate(const char *pColorName)
00184 {
00185 if (strcmp(pColorName, "skin") == 0) return eSkin;
00186 else if (strcmp(pColorName, "yellow") == 0) return eYellow;
00187 else if (strcmp(pColorName, "yellow2") == 0) return eYellow2;
00188 else if (strcmp(pColorName, "yellow3") == 0) return eYellow3;
00189 else if (strcmp(pColorName, "orange") == 0) return eOrange;
00190 else if (strcmp(pColorName, "orange2") == 0) return eOrange2;
00191 else if (strcmp(pColorName, "orange3") == 0) return eOrange3;
00192 else if (strcmp(pColorName, "red") == 0) return eRed;
00193 else if (strcmp(pColorName, "red2") == 0) return eRed2;
00194 else if (strcmp(pColorName, "red3") == 0) return eRed3;
00195 else if (strcmp(pColorName, "blue") == 0) return eBlue;
00196 else if (strcmp(pColorName, "blue2") == 0) return eBlue2;
00197 else if (strcmp(pColorName, "blue3") == 0) return eBlue3;
00198 else if (strcmp(pColorName, "green") == 0) return eGreen;
00199 else if (strcmp(pColorName, "green2") == 0) return eGreen2;
00200 else if (strcmp(pColorName, "green3") == 0) return eGreen3;
00201 else if (strcmp(pColorName, "white") == 0) return eWhite;
00202 else if (strcmp(pColorName, "none") == 0) return eNone;
00203 else if (strcmp(pColorName, "colored") == 0) return eColored;
00204 else return eNone;
00205 }
00206
00207 void CColorParameterSet::Translate(ObjectColor color, std::string &sName)
00208 {
00209 switch (color)
00210 {
00211 case eSkin: sName = "skin"; break;
00212 case eYellow: sName = "yellow"; break;
00213 case eYellow2: sName = "yellow2"; break;
00214 case eYellow3: sName = "yellow3"; break;
00215 case eOrange: sName = "orange"; break;
00216 case eOrange2: sName = "orange2"; break;
00217 case eOrange3: sName = "orange3"; break;
00218 case eRed: sName = "red"; break;
00219 case eRed2: sName = "red2"; break;
00220 case eRed3: sName = "red3"; break;
00221 case eBlue: sName = "blue"; break;
00222 case eBlue2: sName = "blue2"; break;
00223 case eBlue3: sName = "blue3"; break;
00224 case eGreen: sName = "green"; break;
00225 case eGreen2: sName = "green2"; break;
00226 case eGreen3: sName = "green3"; break;
00227 case eWhite: sName = "white"; break;
00228 case eNone: sName = "none"; break;
00229 case eColored: sName = "colored"; break;
00230 default: sName = ""; printf("error: (internal error) color %i not handled\n", (int) color); break;
00231 }
00232 }
00233
00234
00235 bool CColorParameterSet::LoadFromFile(const char *pFileName)
00236 {
00237 FILE *f = fopen(pFileName, "r");
00238 if (!f)
00239 return false;
00240
00241 char colorName[100];
00242 int par1, par2, par3, par4, par5, par6;
00243 int **pp = m_ppParameters;
00244
00245 while (true)
00246 {
00247 if (fscanf(f, "%s%i%i%i%i%i%i", colorName, &par1, &par2, &par3, &par4, &par5, &par6) == EOF)
00248 break;
00249
00250 ObjectColor color = Translate(colorName);
00251
00252 if (color < eNone || color >= eNumberOfColors)
00253 {
00254 printf("error: color name '%s' is not handled\n", colorName);
00255 }
00256 else
00257 {
00258 const int nIndex = (int) color;
00259
00260 pp[nIndex][0] = par1;
00261 pp[nIndex][1] = par2;
00262 pp[nIndex][2] = par3;
00263 pp[nIndex][3] = par4;
00264 pp[nIndex][4] = par5;
00265 pp[nIndex][5] = par6;
00266 }
00267 }
00268
00269 fclose(f);
00270
00271 return true;
00272 }
00273
00274 bool CColorParameterSet::SaveToFile(const char *pFileName)
00275 {
00276 FILE *f = fopen(pFileName, "w");
00277 if (!f)
00278 return false;
00279
00280 int **pp = m_ppParameters;
00281
00282 for (int i = 0; i < m_nColors; i++)
00283 {
00284 ObjectColor c = (ObjectColor) i;
00285 std::string sName;
00286 Translate(c, sName);
00287 fprintf(f, "%s %i %i %i %i %i %i\n", sName.c_str(), pp[c][0], pp[c][1], pp[c][2], pp[c][3], pp[c][4], pp[c][5]);
00288 }
00289
00290 fclose(f);
00291
00292 return true;
00293 }