Skip to content

Commit

Permalink
Even more conversion to the new logging system.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoconni committed Aug 25, 2024
1 parent 5a4b02a commit 3a36e78
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 52 deletions.
32 changes: 18 additions & 14 deletions src/models/FGAircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#include "FGAircraft.h"
#include "FGFDMExec.h"
#include "input_output/FGXMLElement.h"
#include "input_output/FGLog.h"

using namespace std;

Expand Down Expand Up @@ -222,23 +224,25 @@ void FGAircraft::Debug(int from)

if (debug_lvl & 1) { // Standard console startup message output
if (from == 2) { // Loading
cout << endl << " Aircraft Metrics:" << endl;
cout << " WingArea: " << WingArea << endl;
cout << " WingSpan: " << WingSpan << endl;
cout << " Incidence: " << WingIncidence << endl;
cout << " Chord: " << cbar << endl;
cout << " H. Tail Area: " << HTailArea << endl;
cout << " H. Tail Arm: " << HTailArm << endl;
cout << " V. Tail Area: " << VTailArea << endl;
cout << " V. Tail Arm: " << VTailArm << endl;
cout << " Eyepoint (x, y, z): " << vXYZep << endl;
cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
cout << " Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
FGLogging log(FDMExec->GetLogger(), LogLevel::DEBUG);
log << endl << " Aircraft Metrics:" << endl << fixed;
log << " WingArea: " << WingArea << endl;
log << " WingSpan: " << WingSpan << endl;
log << " Incidence: " << WingIncidence << endl;
log << " Chord: " << cbar << endl;
log << " H. Tail Area: " << HTailArea << endl;
log << " H. Tail Arm: " << HTailArm << endl;
log << " V. Tail Area: " << VTailArea << endl;
log << " V. Tail Arm: " << VTailArm << endl;
log << " Eyepoint (x, y, z): " << vXYZep << endl;
log << " Ref Pt (x, y, z): " << vXYZrp << endl;
log << " Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
if (from == 0) cout << "Instantiated: FGAircraft" << endl;
if (from == 1) cout << "Destroyed: FGAircraft" << endl;
FGLogging log(FDMExec->GetLogger(), LogLevel::DEBUG);
if (from == 0) log << "Instantiated: FGAircraft" << endl;
if (from == 1) log << "Destroyed: FGAircraft" << endl;
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
}
Expand Down
15 changes: 9 additions & 6 deletions src/models/FGBuoyantForces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ INCLUDES
#include "FGFDMExec.h"
#include "FGBuoyantForces.h"
#include "input_output/FGXMLElement.h"
#include "input_output/FGLog.h"

using namespace std;

Expand Down Expand Up @@ -126,7 +127,7 @@ bool FGBuoyantForces::Load(Element *document)
Cells.push_back(new FGGasCell(FDMExec, gas_cell_element, Cells.size(), in));
gas_cell_element = document->FindNextElement("gas_cell");
}

PostLoad(document, FDMExec);

if (!NoneDefined) {
Expand Down Expand Up @@ -165,15 +166,15 @@ const FGColumnVector3& FGBuoyantForces::GetGasMassMoment(void)
const FGMatrix33& FGBuoyantForces::GetGasMassInertia(void)
{
size_t size = Cells.size();

if (size == 0) return gasCellJ;

gasCellJ.InitMatrix();

for (unsigned int i=0; i < size; i++) {
gasCellJ += Cells[i]->GetInertia();
}

return gasCellJ;
}

Expand Down Expand Up @@ -281,12 +282,14 @@ void FGBuoyantForces::Debug(int from)

if (debug_lvl & 1) { // Standard console startup message output
if (from == 2) { // Loader
cout << endl << " Buoyant Forces: " << endl;
FGLogging log(FDMExec->GetLogger(), LogLevel::DEBUG);
log << endl << " Buoyant Forces: " << endl;
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
if (from == 0) cout << "Instantiated: FGBuoyantForces" << endl;
if (from == 1) cout << "Destroyed: FGBuoyantForces" << endl;
FGLogging log(FDMExec->GetLogger(), LogLevel::DEBUG);
if (from == 0) log << "Instantiated: FGBuoyantForces" << endl;
if (from == 1) log << "Destroyed: FGBuoyantForces" << endl;
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
}
Expand Down
53 changes: 28 additions & 25 deletions src/models/FGExternalForce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
<!-- Interface properties, a.k.a. property declarations -->
<property> ... </property>
<force name="name" frame="BODY|LOCAL|WIND">
<function> ... </function>
<location unit="units"> <!-- location -->
Expand Down Expand Up @@ -66,6 +66,7 @@
#include "FGFDMExec.h"
#include "FGExternalForce.h"
#include "input_output/FGXMLElement.h"
#include "input_output/FGLog.h"

using namespace std;

Expand All @@ -92,10 +93,10 @@ FGParameter* FGExternalForce::bind(Element *el, const string& magName,
// Set frame (from FGForce).
string sFrame = el->GetAttributeValue("frame");
if (sFrame.empty()) {
cerr << el->ReadFrom()
<< "No frame specified for external " << el->GetName() << ", \""
<< Name << "\"." << endl
<< "Frame set to Body" << endl;
FGXMLLogging log(fdmex->GetLogger(), el, LogLevel::WARN);
log << "No frame specified for external " << el->GetName() << ", \""
<< Name << "\"." << endl
<< "Frame set to Body" << endl;
ttype = tNone;
} else if (sFrame == "BODY") {
ttype = tNone;
Expand All @@ -106,18 +107,18 @@ FGParameter* FGExternalForce::bind(Element *el, const string& magName,
} else if (sFrame == "INERTIAL") {
ttype = tInertialBody;
} else {
cerr << el->ReadFrom()
<< "Invalid frame specified for external " << el->GetName() << ", \""
<< Name << "\"." << endl
<< "Frame set to Body" << endl;
FGXMLLogging log(fdmex->GetLogger(), el, LogLevel::WARN);
log << "Invalid frame specified for external " << el->GetName() << ", \""
<< Name << "\"." << endl
<< "Frame set to Body" << endl;
ttype = tNone;
}

Element* direction_element = el->FindElement("direction");
if (!direction_element) {
cerr << el->ReadFrom()
<< "No direction element specified in " << el->GetName()
<< " object. Default is (0,0,0)." << endl;
FGXMLLogging log(fdmex->GetLogger(), el, LogLevel::WARN);
log << "No direction element specified in " << el->GetName()
<< " object. Default is (0,0,0)." << endl;
} else {
FGColumnVector3 direction = direction_element->FindElementTripletConvertTo("IN");
direction.Normalize();
Expand Down Expand Up @@ -154,8 +155,8 @@ void FGExternalForce::setForce(Element *el)

Element* location_element = el->FindElement("location");
if (!location_element) {
cerr << el->ReadFrom()
<< "No location element specified in force object." << endl;
FGXMLLogging log(fdmex->GetLogger(), el, LogLevel::WARN);
log << "No location element specified in force object." << endl;
} else {
FGColumnVector3 location = location_element->FindElementTripletConvertTo("IN");
SetLocation(location);
Expand Down Expand Up @@ -229,30 +230,32 @@ void FGExternalForce::Debug(int from)

if (debug_lvl & 1) { // Standard console startup message output
if (from == 0) { // Constructor
cout << " " << Name << endl;
cout << " Frame: ";
FGLogging log(fdmex->GetLogger(), LogLevel::DEBUG);
log << " " << Name << endl;
log << " Frame: ";
switch(ttype) {
case tNone:
cout << "BODY";
log << "BODY";
break;
case tLocalBody:
cout << "LOCAL";
log << "LOCAL";
break;
case tWindBody:
cout << "WIND";
log << "WIND";
break;
case tInertialBody:
cout << "INERTIAL";
log << "INERTIAL";
break;
default:
cout << "ERROR/UNKNOWN";
log << "ERROR/UNKNOWN";
}
cout << endl << " Location: (" << vXYZn(eX) << ", " << vXYZn(eY) << ", " << vXYZn(eZ) << ")" << endl;
log << endl << " Location: (" << vXYZn(eX) << ", " << vXYZn(eY) << ", " << vXYZn(eZ) << ")" << endl;
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
if (from == 0) cout << "Instantiated: FGExternalForce" << endl;
if (from == 1) cout << "Destroyed: FGExternalForce" << endl;
FGLogging log(fdmex->GetLogger(), LogLevel::DEBUG);
if (from == 0) log << "Instantiated: FGExternalForce" << endl;
if (from == 1) log << "Destroyed: FGExternalForce" << endl;
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
}
Expand Down
15 changes: 8 additions & 7 deletions src/models/FGFCSChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ CLASS DOCUMENTATION
/** Represents a <channel> in a control system definition.
The <channel> may be defined within a <system>, <autopilot> or <flight_control>
element. Channels are a way to group sets of components that perform
a specific purpose or algorithm.
a specific purpose or algorithm.
Created within a <system> tag, the channel is defined as follows
<channel name="name" [execute="property"] [execrate="rate"]>
name is the name of the channel - in the old way this would also be used to bind elements
execute [optional] is the property that defines when to execute this channel; an on/off switch
execrate [optional] is the rate at which the channel should execute.
execrate [optional] is the rate at which the channel should execute.
A value of 0 or 1 will execute the channel every frame, a value of 2
every other frame (half rate), a value of 4 is every 4th frame (quarter rate)
*/
Expand Down Expand Up @@ -97,11 +97,12 @@ class FGFCSChannel {
size_t GetNumComponents() {return FCSComponents.size();}
/// Retrieves a specific component.
FGFCSComponent* GetComponent(unsigned int i) {
if (i >= GetNumComponents()) {
std::cerr << "Tried to get nonexistent component" << std::endl;
return 0;
} else {
if (i < GetNumComponents()) {
return FCSComponents[i];
} else {
FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::ERROR);
log << "Tried to get nonexistent component" << std::endl;
return nullptr;
}
}
/// Reset the components that can be reset
Expand Down Expand Up @@ -131,7 +132,7 @@ class FGFCSChannel {
// channel will be run at rate 1 if trimming, or when the next execrate
// frame is reached
if (fcs->GetTrimStatus() || ExecFrameCountSinceLastRun >= ExecRate) {
for (unsigned int i=0; i<FCSComponents.size(); i++)
for (unsigned int i=0; i<FCSComponents.size(); i++)
FCSComponents[i]->Run();
}
}
Expand Down

0 comments on commit 3a36e78

Please sign in to comment.