<commit_before>/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Source:       FGExternalForce.cpp
 Author:       <NAME>, <NAME>
 Date started: 9/21/07

 ------------- Copyright (C) 2007  <NAME> (<EMAIL>) -------------

 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your option) any later
 version.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 details.

 You should have received a copy of the GNU Lesser General Public License along with
 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 Place - Suite 330, Boston, MA  02111-1307, USA.

 Further information about the GNU Lesser General Public License can also be found on
 the world wide web at http://www.gnu.org.

 HISTORY
--------------------------------------------------------------------------------
9/21/07  JB   Created

<external_reactions>

    <!-- Interface properties, a.k.a. property declarations -->
    <property> ... </property>
      
    <force name="name" frame="BODY|LOCAL|WIND">
      
      <function> ... </function>

      <location unit="units"> <!-- location -->
        <x> value </x>
        <y> value </y>
        <z> value </z>
      </location>
      <direction> <!-- optional for initial direction vector -->
        <x> value </x>
        <y> value </y>
        <z> value </z>
      </direction>
    </force>

</external_reactions>

*/

#include "FGExternalForce.h"
#include "input_output/FGXMLElement.h"
#include <iostream>

using namespace std;

namespace JSBSim {

IDENT(IdSrc,"$Id: FGExternalForce.cpp,v 1.15 2014/11/25 01:44:17 dpculp Exp $");
IDENT(IdHdr,ID_EXTERNALFORCE);

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FGExternalForce::FGExternalForce(FGFDMExec *FDMExec, Element *el, int index)
  : FGForce(FDMExec)
{
  Element* location_element=0;
  Element* direction_element=0;
  Element* function_element=0;
  string sFrame;
  string BasePropertyName;
  FGColumnVector3 location;
  Magnitude_Function = 0;
  magnitude = 0.0;
  azimuth = 0.0;

  FGPropertyManager* PropertyManager = fdmex->GetPropertyManager();
  Name = el->GetAttributeValue("name");
  BasePropertyName = "external_reactions/" + Name;

  // The value sent to the sim through the external_forces/{force name}/magnitude
  // property will be multiplied against the unit vector, which can come in
  // initially in the direction vector. The frame in which the vector is defined
  // is specified with the frame attribute. The vector is normalized to magnitude 1.

  function_element = el->FindElement("function");
  if (function_element) {
    Magnitude_Function = new FGFunction(PropertyManager, function_element);
  } else {
    PropertyManager->Tie( BasePropertyName + "/magnitude",(FGExternalForce*)this, &FGExternalForce::GetMagnitude, &FGExternalForce::SetMagnitude);
  }


  // Set frame (from FGForce).
  sFrame = el->GetAttributeValue("frame");
  if (sFrame.empty()) {
    cerr << "No frame specified for external force, \"" << Name << "\"." << endl;
    cerr << "Frame set to Body" << endl;
    ttype = tNone;
  } else if (sFrame == "BODY") {
    ttype = tNone;
  } else if (sFrame == "LOCAL") {
    ttype = tLocalBody;
    PropertyManager->Tie( BasePropertyName + "/azimuth", (FGExternalForce*)this, &FGExternalForce::GetAzimuth, &FGExternalForce::SetAzimuth);
  } else if (sFrame == "WIND") {
    ttype = tWindBody;
  } else {
    cerr << "Invalid frame specified for external force, \"" << Name << "\"." << endl;
    cerr << "Frame set to Body" << endl;
    ttype = tNone;
  }
  PropertyManager->Tie( BasePropertyName + "/x", (FGExternalForce*)this, &FGExternalForce::GetX, &FGExternalForce::SetX);
  PropertyManager->Tie( BasePropertyName + "/y", (FGExternalForce*)this, &FGExternalForce::GetY, &FGExternalForce::SetY);
  PropertyManager->Tie( BasePropertyName + "/z", (FGExternalForce*)this, &FGExternalForce::GetZ, &FGExternalForce::SetZ);

  location_element = el->FindElement("location");
  if (!location_element) {
    cerr << "No location element specified in force object." << endl;
  } else {
    location = location_element->FindElementTripletConvertTo("IN");
    SetLocation(location);
  }
  PropertyManager->Tie( BasePropertyName + "/locx", (FGExternalForce*)this, &FGExternalForce::GetLocX, &FGExternalForce::SetLocX);
  PropertyManager->Tie( BasePropertyName + "/locy", (FGExternalForce*)this, &FGExternalForce::GetLocY, &FGExternalForce::SetLocY);
  PropertyManager->Tie( BasePropertyName + "/locz", (FGExternalForce*)this, &FGExternalForce::GetLocZ, &FGExternalForce::SetLocZ);

  direction_element = el->FindElement("direction");
  if (!direction_element) {
    cerr << "No direction element specified in force object. Default is (0,0,0)." << endl;
  } else {
    vDirection = direction_element->FindElementTripletConvertTo("IN");
    vDirection.Normalize();
  }

  Debug(0);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<commit_msg>Renamed the location properties to include unit.<commit_after>/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Source:       FGExternalForce.cpp
 Author:       <NAME>, <NAME>
 Date started: 9/21/07

 ------------- Copyright (C) 2007  <NAME> (<EMAIL>) -------------

 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your option) any later
 version.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 details.

 You should have received a copy of the GNU Lesser General Public License along with
 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 Place - Suite 330, Boston, MA  02111-1307, USA.

 Further information about the GNU Lesser General Public License can also be found on
 the world wide web at http://www.gnu.org.

 HISTORY
--------------------------------------------------------------------------------
9/21/07  JB   Created

<external_reactions>

    <!-- Interface properties, a.k.a. property declarations -->
    <property> ... </property>
      
    <force name="name" frame="BODY|LOCAL|WIND">
      
      <function> ... </function>

      <location unit="units"> <!-- location -->
        <x> value </x>
        <y> value </y>
        <z> value </z>
      </location>
      <direction> <!-- optional for initial direction vector -->
        <x> value </x>
        <y> value </y>
        <z> value </z>
      </direction>
    </force>

</external_reactions>

*/

#include "FGExternalForce.h"
#include "input_output/FGXMLElement.h"
#include <iostream>

using namespace std;

namespace JSBSim {

IDENT(IdSrc,"$Id: FGExternalForce.cpp,v 1.16 2014/12/18 09:56:05 andgi Exp $");
IDENT(IdHdr,ID_EXTERNALFORCE);

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FGExternalForce::FGExternalForce(FGFDMExec *FDMExec, Element *el, int index)
  : FGForce(FDMExec)
{
  Element* location_element=0;
  Element* direction_element=0;
  Element* function_element=0;
  string sFrame;
  string BasePropertyName;
  FGColumnVector3 location;
  Magnitude_Function = 0;
  magnitude = 0.0;
  azimuth = 0.0;

  FGPropertyManager* PropertyManager = fdmex->GetPropertyManager();
  Name = el->GetAttributeValue("name");
  BasePropertyName = "external_reactions/" + Name;

  // The value sent to the sim through the external_forces/{force name}/magnitude
  // property will be multiplied against the unit vector, which can come in
  // initially in the direction vector. The frame in which the vector is defined
  // is specified with the frame attribute. The vector is normalized to magnitude 1.

  function_element = el->FindElement("function");
  if (function_element) {
    Magnitude_Function = new FGFunction(PropertyManager, function_element);
  } else {
    PropertyManager->Tie( BasePropertyName + "/magnitude",(FGExternalForce*)this, &FGExternalForce::GetMagnitude, &FGExternalForce::SetMagnitude);
  }


  // Set frame (from FGForce).
  sFrame = el->GetAttributeValue("frame");
  if (sFrame.empty()) {
    cerr << "No frame specified for external force, \"" << Name << "\"." << endl;
    cerr << "Frame set to Body" << endl;
    ttype = tNone;
  } else if (sFrame == "BODY") {
    ttype = tNone;
  } else if (sFrame == "LOCAL") {
    ttype = tLocalBody;
    PropertyManager->Tie( BasePropertyName + "/azimuth", (FGExternalForce*)this, &FGExternalForce::GetAzimuth, &FGExternalForce::SetAzimuth);
  } else if (sFrame == "WIND") {
    ttype = tWindBody;
  } else {
    cerr << "Invalid frame specified for external force, \"" << Name << "\"." << endl;
    cerr << "Frame set to Body" << endl;
    ttype = tNone;
  }
  PropertyManager->Tie( BasePropertyName + "/x", (FGExternalForce*)this, &FGExternalForce::GetX, &FGExternalForce::SetX);
  PropertyManager->Tie( BasePropertyName + "/y", (FGExternalForce*)this, &FGExternalForce::GetY, &FGExternalForce::SetY);
  PropertyManager->Tie( BasePropertyName + "/z", (FGExternalForce*)this, &FGExternalForce::GetZ, &FGExternalForce::SetZ);

  location_element = el->FindElement("location");
  if (!location_element) {
    cerr << "No location element specified in force object." << endl;
  } else {
    location = location_element->FindElementTripletConvertTo("IN");
    SetLocation(location);
  }
  PropertyManager->Tie( BasePropertyName + "/location-x-in", (FGExternalForce*)this, &FGExternalForce::GetLocX, &FGExternalForce::SetLocX);
  PropertyManager->Tie( BasePropertyName + "/location-y-in", (FGExternalForce*)this, &FGExternalForce::GetLocY, &FGExternalForce::SetLocY);
  PropertyManager->Tie( BasePropertyName + "/location-z-in", (FGExternalForce*)this, &FGExternalForce::GetLocZ, &FGExternalForce::SetLocZ);

  direction_element = el->FindElement("direction");
  if (!direction_element) {
    cerr << "No direction element specified in force object. Default is (0,0,0)." << endl;
  } else {
    vDirection = direction_element->FindElementTripletConvertTo("IN");
    vDirection.Normalize();
  }

  Debug(0);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{'fraction_non_alphanumeric': 0.18323532157192196, 'fraction_numerical': 0.011201344161299356, 'mean_word_length': 3.8217821782178216, 'pattern_counts': {'":': 0, '<': 131, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4799108', 'n_tokens_mistral': 3251, 'n_tokens_neox': 3014, 'n_words': 912}