40 #include "FGJSBBase.h" 41 #include "FGModelLoader.h" 42 #include "FGXMLFileRead.h" 43 #include "models/FGModel.h" 49 IDENT(IdSrc,
"$Id: FGModelLoader.cpp,v 1.4 2017/02/25 14:23:18 bcoconni Exp $");
50 IDENT(IdHdr, ID_MODELLOADER);
56 Element_ptr FGModelLoader::Open(Element *el)
58 Element_ptr document = el;
59 string fname = el->GetAttributeValue(
"file");
62 FGXMLFileRead XMLFileRead;
63 SGPath path(SGPath::fromLocal8Bit(fname.c_str()));
65 if (path.isRelative())
66 path = model->FindFullPathName(path);
68 if (CachedFiles.find(path.utf8Str()) != CachedFiles.end())
69 document = CachedFiles[path.utf8Str()];
71 document = XMLFileRead.LoadXMLDocument(path);
73 cerr << endl << el->ReadFrom()
74 <<
"Could not open file: " << path << endl;
77 CachedFiles[path.utf8Str()] = document;
80 if (document->GetName() != el->GetName()) {
81 document->SetParent(el);
82 el->AddChildElement(document);
89 SGPath CheckPathName(
const SGPath& path,
const SGPath& filename) {
90 SGPath fullName = path/filename.utf8Str();
92 if (fullName.extension().empty())
93 fullName.concat(
".xml");
95 return fullName.exists() ? fullName : SGPath();