00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdgeorges.h"
00027 #include "nel/georges/georges_loader.h"
00028
00029 #include "nel/misc/path.h"
00030 #include "nel/georges/form_body_elt_atom.h"
00031 #include "nel/georges/form_body_elt_struct.h"
00032 #include "nel/georges/form_body_elt_list.h"
00033 #include "nel/georges/mold_elt_type.h"
00034
00035 namespace NLGEORGES
00036 {
00037
00039
00041
00042 bool CLoader::_Initialized = false;
00043
00044 CLoader::CLoader()
00045 {
00046 ml.SetLoader( this );
00047 if (!CLoader::_Initialized)
00048 {
00049 NLMISC::IClassable *p = NLMISC::CClassRegistry::create("CFormBodyElt");
00050 if(p == NULL)
00051 {
00052 NLMISC_REGISTER_CLASS (CFormBodyElt);
00053 }
00054 else
00055 delete p;
00056 p = NLMISC::CClassRegistry::create("CFormBodyEltAtom");
00057 if(p == NULL)
00058 {
00059 NLMISC_REGISTER_CLASS (CFormBodyEltAtom);
00060 }
00061 else
00062 delete p;
00063 p = NLMISC::CClassRegistry::create("CFormBodyEltList");
00064 if(p == NULL)
00065 {
00066 NLMISC_REGISTER_CLASS (CFormBodyEltList);
00067 }
00068 else
00069 delete p;
00070 p = NLMISC::CClassRegistry::create("CFormBodyEltStruct");
00071 if(p == NULL)
00072 {
00073 NLMISC_REGISTER_CLASS (CFormBodyEltStruct);
00074 }
00075 else
00076 delete p;
00077 CLoader::_Initialized = true;
00078 }
00079 }
00080
00081 CLoader::~CLoader()
00082 {
00083 }
00084
00085 void CLoader::LoadForm( CForm& _f, const CStringEx& _sxfullname )
00086 {
00087 fl.LoadForm( _f, _sxfullname );
00088 }
00089
00090 void CLoader::LoadForm( CForm& _f, const CStringEx& _sxfullname, const CStringEx& _sxdate )
00091 {
00092 fl.LoadForm( _f, _sxfullname, _sxdate );
00093 }
00094
00095 void CLoader::LoadSearchForm( CForm& _f, const CStringEx& _sxfilename )
00096 {
00097 fl.LoadForm( _f, WhereIsForm( _sxfilename ) );
00098 }
00099
00100 void CLoader::LoadSearchForm( CForm& _f, const CStringEx& _sxfilename, const CStringEx& _sxdate )
00101 {
00102 fl.LoadForm( _f, WhereIsForm( _sxfilename ), _sxdate );
00103 }
00104
00105 void CLoader::SaveForm( CForm& _f, const CStringEx& _sxfullname )
00106 {
00107 fl.SaveForm( _f, _sxfullname );
00108 }
00109
00110 CMoldElt* CLoader::LoadMold( const CStringEx &_sxfilename )
00111 {
00112 return( ml.LoadMold( _sxfilename ) );
00113 }
00114
00115 CMoldElt* CLoader::LoadMold( const CStringEx &_sxfilename, const CStringEx &_sxdate )
00116 {
00117 return( ml.LoadMold( _sxfilename, _sxdate ) );
00118 }
00119
00120 void CLoader::SetWorkDirectory( const CStringEx &_sxworkdirectory )
00121 {
00122 if( sxworkdirectory != _sxworkdirectory )
00123 {
00124 sxworkdirectory = _sxworkdirectory;
00125 NLMISC::CPath::removeAllAlternativeSearchPath();
00126 NLMISC::CPath::addSearchPath( sxworkdirectory, true, true );
00127 NLMISC::CPath::addSearchPath( sxrootdirectory, true, true );
00128 }
00129 }
00130
00131 void CLoader::SetRootDirectory( const CStringEx &_sxrootdirectory )
00132 {
00133 if( sxrootdirectory != _sxrootdirectory )
00134 {
00135 sxrootdirectory = _sxrootdirectory;
00136 NLMISC::CPath::removeAllAlternativeSearchPath();
00137 NLMISC::CPath::addSearchPath( sxworkdirectory, true, true );
00138 NLMISC::CPath::addSearchPath( sxrootdirectory, true, true );
00139 }
00140 }
00141
00142 CStringEx CLoader::GetWorkDirectory() const
00143 {
00144 return( sxworkdirectory );
00145 }
00146
00147 CStringEx CLoader::GetRootDirectory() const
00148 {
00149 return( sxrootdirectory );
00150 }
00151
00152 CStringEx CLoader::WhereIsDfnTyp( const CStringEx &_sxfilename )
00153 {
00154 return( NLMISC::CPath::lookup( _sxfilename, false ) );
00155 }
00156
00157 CStringEx CLoader::WhereIsForm( const CStringEx &_sxfilename )
00158 {
00159 return( NLMISC::CPath::lookup( _sxfilename, false ) );
00160 }
00161
00162 void CLoader::MakeDfn( const CStringEx &_sxfullname, const std::vector< std::pair< CStringEx, CStringEx > >* const _pvdefine )
00163 {
00164 CFormFile pff;
00165 CForm f;
00166
00167 CFormBodyEltStruct* pbody = f.GetBody();
00168 CFormBodyEltAtom* pfbea;
00169
00170 if( ( _pvdefine )&&( !_pvdefine->empty() ) )
00171 for( std::vector< std::pair< CStringEx, CStringEx > >::const_iterator it = _pvdefine->begin(); it != _pvdefine->end(); ++it )
00172 {
00173 pfbea = new CFormBodyEltAtom;
00174 pfbea->SetName( it->first );
00175 pfbea->SetValue( it->second );
00176 pbody->AddElt( pfbea );
00177 }
00178
00179 pff.SetForm( f );
00180 pff.Save( _sxfullname );
00181 }
00182
00183 void CLoader::MakeTyp( const CStringEx &_sxfullname, const CStringEx &_sxtype, const CStringEx &_sxformula, const CStringEx &_sxenum, const CStringEx &_sxlow, const CStringEx &_sxhigh, const CStringEx &_sxdefault, const std::vector< std::pair< CStringEx, CStringEx > >* const _pvpredef , const std::vector< std::pair< CStringEx, CStringEx > >* const _pvparent )
00184 {
00185 CFormFile pff;
00186 CForm f;
00187
00188 CFormBodyEltStruct* pbody = f.GetBody();
00189 CFormBodyEltAtom* pfbea;
00190 CFormBodyEltList* pfbel;
00191 CFormBodyEltStruct* pfbes;
00192
00193 pfbea = new CFormBodyEltAtom;
00194 pfbea->SetName( "Type" );
00195 pfbea->SetValue( _sxtype );
00196 pbody->AddElt( pfbea );
00197
00198 pfbea = new CFormBodyEltAtom;
00199 pfbea->SetName( "Enum" );
00200 pfbea->SetValue( _sxenum );
00201 pbody->AddElt( pfbea );
00202
00203 pfbea = new CFormBodyEltAtom;
00204 pfbea->SetName( "Formula" );
00205 pfbea->SetValue( _sxformula );
00206 pbody->AddElt( pfbea );
00207
00208 pfbea = new CFormBodyEltAtom;
00209 pfbea->SetName( "Lowlimit" );
00210 pfbea->SetValue( _sxlow );
00211 pbody->AddElt( pfbea );
00212
00213 pfbea = new CFormBodyEltAtom;
00214 pfbea->SetName( "Highlimit" );
00215 pfbea->SetValue( _sxhigh );
00216 pbody->AddElt( pfbea );
00217
00218 pfbea = new CFormBodyEltAtom;
00219 pfbea->SetName( "DefaultValue" );
00220 pfbea->SetValue( _sxdefault );
00221 pbody->AddElt( pfbea );
00222
00223 CStringEx sx;
00224
00225 if( ( _pvpredef )&&( !_pvpredef->empty() ) )
00226 {
00227 pfbel = new CFormBodyEltList;
00228 pfbel->SetName( "Predef" );
00229 int i = 0;
00230 for( std::vector< std::pair< CStringEx, CStringEx > >::const_iterator it = _pvpredef->begin(); it != _pvpredef->end(); ++it )
00231 {
00232 pfbes = new CFormBodyEltStruct;
00233 sx.format( "#%d", i++ );
00234 pfbes->SetName( sx );
00235 pfbel->AddElt( pfbes );
00236
00237 pfbea = new CFormBodyEltAtom;
00238 pfbea->SetName( "Designation" );
00239 pfbea->SetValue( it->first );
00240 pfbes->AddElt( pfbea );
00241
00242 pfbea = new CFormBodyEltAtom;
00243 pfbea->SetName( "Substitute" );
00244 pfbea->SetValue( it->second );
00245 pfbes->AddElt( pfbea );
00246 }
00247 pbody->AddElt( pfbel );
00248 }
00249
00250 if( ( _pvparent )&&( !_pvparent->empty() ) )
00251 {
00252 pfbel = new CFormBodyEltList;
00253 pfbel->SetName( "Parents" );
00254 int i = 0;
00255 for( std::vector< std::pair< CStringEx, CStringEx > >::const_iterator it = _pvparent->begin(); it != _pvparent->end(); ++it )
00256 {
00257 pfbes = new CFormBodyEltStruct;
00258 sx.format( "#%d", i++ );
00259 pfbes->SetName( sx );
00260 pfbel->AddElt( pfbes );
00261
00262 pfbea = new CFormBodyEltAtom;
00263 pfbea->SetName( "Activity" );
00264 pfbea->SetValue( it->first );
00265 pfbes->AddElt( pfbea );
00266
00267 pfbea = new CFormBodyEltAtom;
00268 pfbea->SetName( "Filename" );
00269 pfbea->SetValue( it->second );
00270 pfbes->AddElt( pfbea );
00271 }
00272 pbody->AddElt( pfbel );
00273 }
00274
00275 pff.SetForm( f );
00276 pff.Save( _sxfullname );
00277 }
00278
00279 void CLoader::SetTypPredef( const CStringEx &_sxfilename, const std::vector< CStringEx >& _pvsx )
00280 {
00281 CMoldElt*pme = LoadMold( _sxfilename );
00282 CMoldEltType* pmet = dynamic_cast< CMoldEltType* >( pme );
00283 pmet->SetTypPredef( _pvsx );
00284 pmet->Save();
00285 }
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 }