JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGModelLoader.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGModelLoader.cpp
4 Author: Bertrand Coconnier
5 Date started: 12/14/13
6 Purpose: Read and manage XML data for models definition
7
8 ------------- Copyright (C) 2013 Bertrand Coconnier -------------
9
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
13 version.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18 details.
19
20 You should have received a copy of the GNU Lesser General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 Further information about the GNU Lesser General Public License can also be found on
25 the world wide web at http://www.gnu.org.
26
27FUNCTIONAL DESCRIPTION
28--------------------------------------------------------------------------------
29This is the place where the XML data is loaded in memory for an access during
30the models initialization.
31
32HISTORY
33--------------------------------------------------------------------------------
3412/14/13 BC Created
35
36%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37INCLUDES
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40#include "FGFDMExec.h"
41#include "FGModelLoader.h"
42#include "FGXMLFileRead.h"
43#include "models/FGModel.h"
44#include "input_output/FGLog.h"
45
46using namespace std;
47
48namespace JSBSim {
49
50/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51CLASS IMPLEMENTATION
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54Element_ptr FGModelLoader::Open(Element *el)
55{
56 Element_ptr document = el;
57 string fname = el->GetAttributeValue("file");
58
59 if (!fname.empty()) {
60 FGXMLFileRead XMLFileRead;
61 SGPath path(SGPath::fromUtf8(fname.c_str()));
62
63 if (path.isRelative())
64 path = model->FindFullPathName(path);
65
66 if (CachedFiles.find(path.utf8Str()) != CachedFiles.end())
67 document = CachedFiles[path.utf8Str()];
68 else {
69 document = XMLFileRead.LoadXMLDocument(path);
70 if (document == 0L) {
71 FGXMLLogging log(el, LogLevel::ERROR);
72 log << "Could not open file: " << fname << endl;
73 return NULL;
74 }
75 CachedFiles[path.utf8Str()] = document;
76 }
77
78 if (document->GetName() != el->GetName()) {
79 document->SetParent(el);
80 el->AddChildElement(document);
81 }
82 }
83
84 return document;
85}
86
87//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89SGPath CheckPathName(const SGPath& path, const SGPath& filename) {
90 SGPath fullName = path/filename.utf8Str();
91
92 if (fullName.extension() != "xml")
93 fullName.concat(".xml");
94
95 return fullName.exists() ? fullName : SGPath();
96}
97}
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71