1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
|
/**************************************************/
/* projet_config : routines de trace du cartouche */
/**************************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#define CONFIG_VERSION 1
#define FORCE_LOCAL_CONFIG TRUE
/*********************************************************************/
static bool ReCreatePrjConfig(const wxString & local_config_filename,
const wxString & GroupName, bool ForceUseLocalConfig)
/*********************************************************************/
/* Cree ou recree la configuration locale de kicad (filename.pro)
initialise:
g_Prj_Config
g_Prj_Config_LocalFilename
g_Prj_Default_Config_FullFilename
return:
TRUE si config locale
FALSE si default config
*/
{
// free old config
if ( g_Prj_Config ) delete g_Prj_Config;
g_Prj_Config = NULL;
// Init local Config filename
if ( local_config_filename.IsEmpty() ) g_Prj_Config_LocalFilename = wxT("kicad");
else g_Prj_Config_LocalFilename = local_config_filename;
ChangeFileNameExt( g_Prj_Config_LocalFilename, g_Prj_Config_Filename_ext );
// Init local config filename
if ( ForceUseLocalConfig || wxFileExists(g_Prj_Config_LocalFilename) )
{
g_Prj_Default_Config_FullFilename.Empty();
g_Prj_Config = new wxFileConfig(wxEmptyString, wxEmptyString,
g_Prj_Config_LocalFilename, wxEmptyString,
wxCONFIG_USE_RELATIVE_PATH);
g_Prj_Config->DontCreateOnDemand();
if ( ForceUseLocalConfig ) return TRUE;
// Test de la bonne version du fichier (ou groupe) de configuration
int version = -1, def_version = 0;
g_Prj_Config->SetPath(GroupName);
version = g_Prj_Config->Read( wxT("version"), def_version);
g_Prj_Config->SetPath(UNIX_STRING_DIR_SEP);
if ( version > 0 ) return TRUE;
else delete g_Prj_Config; // Version incorrecte
}
// Fichier local non trouve ou invalide
g_Prj_Config_LocalFilename.Empty();
g_Prj_Default_Config_FullFilename =
ReturnKicadDatasPath() +
wxT("template/kicad") +
g_Prj_Config_Filename_ext;
// Recreate new config
g_Prj_Config = new wxFileConfig(wxEmptyString, wxEmptyString,
wxEmptyString, g_Prj_Default_Config_FullFilename,
wxCONFIG_USE_RELATIVE_PATH);
g_Prj_Config->DontCreateOnDemand();
return FALSE;
}
/***************************************************************************************/
void WinEDA_App::WriteProjectConfig(const wxString & local_config_filename,
const wxString & GroupName, PARAM_CFG_BASE ** List)
/***************************************************************************************/
/* enregistrement de la config "projet"*/
{
const PARAM_CFG_BASE * pt_cfg;
wxString msg;
ReCreatePrjConfig(local_config_filename, GroupName,
FORCE_LOCAL_CONFIG);
/* Write date ( surtout pour eviter bug de wxFileConfig
qui se trompe de rubrique si declaration [xx] en premiere ligne
(en fait si groupe vide) */
g_Prj_Config->SetPath(UNIX_STRING_DIR_SEP);
msg = DateAndTime();
g_Prj_Config->Write( wxT("update"), msg);
msg = GetAppName();
g_Prj_Config->Write( wxT("last_client"), msg);
/* ecriture de la configuration */
g_Prj_Config->DeleteGroup(GroupName); // Erase all datas
g_Prj_Config->Flush();
g_Prj_Config->SetPath(GroupName);
g_Prj_Config->Write( wxT("version"), CONFIG_VERSION);
g_Prj_Config->SetPath(UNIX_STRING_DIR_SEP);
for( ; *List != NULL ; List++)
{
pt_cfg = *List;
if ( pt_cfg->m_Group ) g_Prj_Config->SetPath(pt_cfg->m_Group);
else g_Prj_Config->SetPath(GroupName);
switch( pt_cfg->m_Type )
{
case PARAM_INT:
#undef PTCFG
#define PTCFG ((PARAM_CFG_INT *)pt_cfg)
if (PTCFG->m_Pt_param == NULL) break;
if ( pt_cfg->m_Setup)
m_EDA_Config->Write(pt_cfg->m_Ident, *PTCFG->m_Pt_param);
else
g_Prj_Config->Write(pt_cfg->m_Ident, *PTCFG->m_Pt_param);
break;
case PARAM_SETCOLOR:
#undef PTCFG
#define PTCFG ((PARAM_CFG_SETCOLOR *)pt_cfg)
if (PTCFG->m_Pt_param == NULL) break;
if ( pt_cfg->m_Setup)
m_EDA_Config->Write(pt_cfg->m_Ident, *PTCFG->m_Pt_param);
else
g_Prj_Config->Write(pt_cfg->m_Ident, *PTCFG->m_Pt_param);
break;
case PARAM_DOUBLE:
#undef PTCFG
#define PTCFG ((PARAM_CFG_DOUBLE *)pt_cfg)
if (PTCFG->m_Pt_param == NULL) break;
if ( pt_cfg->m_Setup)
m_EDA_Config->Write(pt_cfg->m_Ident, *PTCFG->m_Pt_param);
else
g_Prj_Config->Write(pt_cfg->m_Ident, *PTCFG->m_Pt_param);
break;
case PARAM_BOOL:
#undef PTCFG
#define PTCFG ((PARAM_CFG_BOOL *)pt_cfg)
if (PTCFG->m_Pt_param == NULL) break;
if ( pt_cfg->m_Setup)
m_EDA_Config->Write(pt_cfg->m_Ident, (int)*PTCFG->m_Pt_param);
else
g_Prj_Config->Write(pt_cfg->m_Ident, (int)*PTCFG->m_Pt_param);
break;
case PARAM_WXSTRING:
#undef PTCFG
#define PTCFG ((PARAM_CFG_WXSTRING *)pt_cfg)
if (PTCFG->m_Pt_param == NULL) break;
if ( pt_cfg->m_Setup)
m_EDA_Config->Write(pt_cfg->m_Ident, *PTCFG->m_Pt_param);
else
g_Prj_Config->Write(pt_cfg->m_Ident, *PTCFG->m_Pt_param);
break;
case PARAM_LIBNAME_LIST:
{
#undef PTCFG
#define PTCFG ((PARAM_CFG_LIBNAME_LIST *)pt_cfg)
if (PTCFG->m_Pt_param == NULL) break;
wxArrayString * libname_list = PTCFG->m_Pt_param;
if ( libname_list == NULL ) break;
unsigned indexlib = 0;
wxString cle_config;
for ( ; indexlib < libname_list->GetCount(); indexlib++ )
{
cle_config = pt_cfg->m_Ident;
// We use indexlib+1 because first lib name is LibName1
cle_config << (indexlib+1);
g_Prj_Config->Write(cle_config, libname_list->Item(indexlib));
}
break;
}
case PARAM_COMMAND_ERASE: // Erase all datas
if ( pt_cfg->m_Ident )
{
m_EDA_Config->DeleteGroup(pt_cfg->m_Ident);
g_Prj_Config->DeleteGroup(pt_cfg->m_Ident);
}
break;
}
}
g_Prj_Config->SetPath(UNIX_STRING_DIR_SEP);
delete g_Prj_Config;
g_Prj_Config = NULL;
}
/***************************************************************************************/
bool WinEDA_App::ReadProjectConfig(const wxString & local_config_filename,
const wxString & GroupName, PARAM_CFG_BASE ** List,
bool Load_Only_if_New)
/***************************************************************************************/
/* Lecture de la config "projet"
*** si Load_Only_if_New == TRUE, elle n'est lue que si elle
*** est differente de la config actuelle (dates differentes)
return:
TRUE si lue.
Met a jour en plus:
EDA_Appl->m_CurrentOptionFileDateAndTime
EDA_Appl->m_CurrentOptionFile
*/
{
const PARAM_CFG_BASE * pt_cfg;
wxString timestamp;
if ( List == NULL )return FALSE;
ReCreatePrjConfig(local_config_filename, GroupName, FALSE);
g_Prj_Config->SetPath(UNIX_STRING_DIR_SEP);
timestamp = g_Prj_Config->Read( wxT("update") );
if ( Load_Only_if_New && ( !timestamp.IsEmpty() ) &&
(timestamp == EDA_Appl->m_CurrentOptionFileDateAndTime) )
{
return FALSE;
}
EDA_Appl->m_CurrentOptionFileDateAndTime = timestamp;
if ( ! g_Prj_Default_Config_FullFilename.IsEmpty() )
EDA_Appl->m_CurrentOptionFile = g_Prj_Default_Config_FullFilename;
else
{
if ( wxPathOnly(g_Prj_Config_LocalFilename).IsEmpty() )
EDA_Appl->m_CurrentOptionFile =
wxGetCwd() + STRING_DIR_SEP + g_Prj_Config_LocalFilename;
else
EDA_Appl->m_CurrentOptionFile = g_Prj_Config_LocalFilename;
}
for( ; *List != NULL ; List++)
{
pt_cfg = *List;
if ( pt_cfg->m_Group ) g_Prj_Config->SetPath(pt_cfg->m_Group);
else g_Prj_Config->SetPath(GroupName);
switch( pt_cfg->m_Type )
{
case PARAM_INT:
{
#undef PTCFG
#define PTCFG ((PARAM_CFG_INT *)pt_cfg)
int itmp;
if ( pt_cfg->m_Setup)
itmp = m_EDA_Config->Read(pt_cfg->m_Ident, PTCFG->m_Default );
else
itmp = g_Prj_Config->Read(pt_cfg->m_Ident, PTCFG->m_Default );
if( (itmp < PTCFG->m_Min) || (itmp > PTCFG->m_Max) )
itmp = PTCFG->m_Default;
*PTCFG->m_Pt_param = itmp;
break;
}
case PARAM_SETCOLOR:
{
#undef PTCFG
#define PTCFG ((PARAM_CFG_SETCOLOR *)pt_cfg)
int itmp;
if ( pt_cfg->m_Setup)
itmp = m_EDA_Config->Read(pt_cfg->m_Ident, PTCFG->m_Default );
else
itmp = g_Prj_Config->Read(pt_cfg->m_Ident, PTCFG->m_Default );
if( (itmp < 0) || (itmp > MAX_COLOR) )
itmp = PTCFG->m_Default;
*PTCFG->m_Pt_param = itmp;
break;
}
case PARAM_DOUBLE:
{
#undef PTCFG
#define PTCFG ((PARAM_CFG_DOUBLE *)pt_cfg)
double ftmp = 0; wxString msg;
if ( pt_cfg->m_Setup)
msg = m_EDA_Config->Read(pt_cfg->m_Ident, wxT("") );
else
msg = g_Prj_Config->Read(pt_cfg->m_Ident, wxT("") );
if ( msg.IsEmpty() ) ftmp = PTCFG->m_Default;
else
{
msg.ToDouble(&ftmp);
if( (ftmp < PTCFG->m_Min) || (ftmp > PTCFG->m_Max) )
ftmp = PTCFG->m_Default;
}
*PTCFG->m_Pt_param = ftmp;
break;
}
case PARAM_BOOL:
{
#undef PTCFG
#define PTCFG ((PARAM_CFG_BOOL *)pt_cfg)
int itmp;
if ( pt_cfg->m_Setup)
itmp = m_EDA_Config->Read(pt_cfg->m_Ident, PTCFG->m_Default );
else
itmp = g_Prj_Config->Read(pt_cfg->m_Ident, PTCFG->m_Default );
*PTCFG->m_Pt_param = itmp ? TRUE : FALSE;
break;
}
case PARAM_WXSTRING:
{
#undef PTCFG
#define PTCFG ((PARAM_CFG_WXSTRING *)pt_cfg)
if (PTCFG->m_Pt_param == NULL) break;
if ( pt_cfg->m_Setup)
*PTCFG->m_Pt_param = m_EDA_Config->Read(pt_cfg->m_Ident );
else
*PTCFG->m_Pt_param = g_Prj_Config->Read(pt_cfg->m_Ident );
break;
}
case PARAM_LIBNAME_LIST:
{
#undef PTCFG
#define PTCFG ((PARAM_CFG_LIBNAME_LIST *)pt_cfg)
int indexlib = 1; // We start indexlib to 1 because first lib name is LibName1
wxString libname, id_lib;
wxArrayString * libname_list = PTCFG->m_Pt_param;
while ( 1 )
{
id_lib = pt_cfg->m_Ident; id_lib << indexlib; indexlib++;
libname = g_Prj_Config->Read(id_lib, wxT("") );
if( libname.IsEmpty() ) break;
libname_list->Add(libname);
}
break;
}
case PARAM_COMMAND_ERASE:
break;
}
}
delete g_Prj_Config;
g_Prj_Config = NULL;
return TRUE;
}
/**************************************************************/
/* Constructeurs des descripteurs de structs de configuration */
/**************************************************************/
PARAM_CFG_BASE::PARAM_CFG_BASE(const wxChar * ident, const paramcfg_id type,
const wxChar * group)
{
m_Ident = ident;
m_Type = type;
m_Group = group;
m_Setup = FALSE;
}
PARAM_CFG_INT::PARAM_CFG_INT(const wxChar * ident, int * ptparam,
int default_val, int min, int max,
const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_INT, group)
{
m_Pt_param = ptparam;
m_Default = default_val;
m_Min = min;
m_Max = max;
}
PARAM_CFG_INT::PARAM_CFG_INT(bool Insetup, const wxChar * ident, int * ptparam,
int default_val, int min, int max,
const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_INT, group)
{
m_Pt_param = ptparam;
m_Default = default_val;
m_Min = min;
m_Max = max;
m_Setup = Insetup;
}
PARAM_CFG_SETCOLOR::PARAM_CFG_SETCOLOR(const wxChar * ident, int * ptparam,
int default_val, const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_SETCOLOR, group)
{
m_Pt_param = ptparam;
m_Default = default_val;
}
PARAM_CFG_SETCOLOR::PARAM_CFG_SETCOLOR(bool Insetup, const wxChar * ident, int * ptparam,
int default_val, const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_SETCOLOR, group)
{
m_Pt_param = ptparam;
m_Default = default_val;
m_Setup = Insetup;
}
PARAM_CFG_DOUBLE::PARAM_CFG_DOUBLE(const wxChar * ident, double * ptparam,
double default_val, double min , double max,
const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_DOUBLE, group)
{
m_Pt_param = ptparam;
m_Default = default_val;
m_Min = min;
m_Max = max;
}
PARAM_CFG_DOUBLE::PARAM_CFG_DOUBLE(bool Insetup, const wxChar * ident, double * ptparam,
double default_val, double min , double max,
const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_DOUBLE, group)
{
m_Pt_param = ptparam;
m_Default = default_val;
m_Min = min;
m_Max = max;
m_Setup = Insetup;
}
PARAM_CFG_BOOL::PARAM_CFG_BOOL(const wxChar * ident, bool * ptparam,
int default_val, const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_BOOL, group)
{
m_Pt_param = ptparam;
m_Default = default_val ? TRUE : FALSE;
}
PARAM_CFG_BOOL::PARAM_CFG_BOOL(bool Insetup, const wxChar * ident, bool * ptparam,
int default_val, const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_BOOL, group)
{
m_Pt_param = ptparam;
m_Default = default_val ? TRUE : FALSE;
m_Setup = Insetup;
}
PARAM_CFG_WXSTRING::PARAM_CFG_WXSTRING(const wxChar * ident,
wxString * ptparam, const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_WXSTRING, group)
{
m_Pt_param = ptparam;
}
PARAM_CFG_WXSTRING::PARAM_CFG_WXSTRING(bool Insetup, const wxChar * ident,
wxString * ptparam, const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_WXSTRING, group)
{
m_Pt_param = ptparam;
m_Setup = Insetup;
}
PARAM_CFG_LIBNAME_LIST::PARAM_CFG_LIBNAME_LIST(const wxChar * ident,
wxArrayString * ptparam, const wxChar * group)
: PARAM_CFG_BASE(ident, PARAM_LIBNAME_LIST, group)
{
m_Pt_param = ptparam;
}
|