本文整理汇总了C++中SimpleXMLTransfer类的典型用法代码示例。如果您正苦于以下问题:C++ SimpleXMLTransfer类的具体用法?C++ SimpleXMLTransfer怎么用?C++ SimpleXMLTransfer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleXMLTransfer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Robot
void Robots::AddRobot(std::string robotfilename)
{
Robot* robot = new Robot();
//
robot->fi = new ModRobotInterface();
robot->fi->loadAirplane(robotfilename.c_str(), (FDMEnviroment*)0, (SimpleXMLTransfer*)0);
if (robot->fi->robot)
{
SimpleXMLTransfer* header = robot->fi->robot->GetHeader();
std::string filename = FileSysTools::getDataPath(header->getString("airplane.file"));
SimpleXMLTransfer* xml = new SimpleXMLTransfer(filename);
XMLModelFile::SetGraphics(xml, header->getInt("airplane.graphics"));
SimpleXMLTransfer* graphics = XMLModelFile::getGraphics(xml);
//
robot->vis_id = Video::new_visualization("objects/" + graphics->attribute("model"),
"textures",
CRRCMath::Vector3(), // todo
xml);
list.push_back(robot);
}
}
示例2: printf
void T_AxisMapper::init(SimpleXMLTransfer* cfgfile, std::string childname)
{
#if DEBUG_TX_INTERFACE > 0
printf("T_AxisMapper::init(cfg, child)\n");
printf(" <-- %s\n", childname.c_str());
#endif
SimpleXMLTransfer* inter;
SimpleXMLTransfer* bindings;
SimpleXMLTransfer* group;
SimpleXMLTransfer* item;
child_in_cfg = childname;
// try to load config
try
{
inter = cfgfile->getChild(childname, true);
bindings = inter->getChild("bindings", true);
group = bindings->getChild("axes", true);
for (int i = T_AxisMapper::AILERON; i <= T_AxisMapper::PITCH; i++)
{
int default_axis = -1;
float default_polarity = 1.0;
// special handling for some default values
if (i == T_AxisMapper::AILERON)
{
default_axis = 0;
}
else if (i == T_AxisMapper::ELEVATOR)
{
default_axis = 1;
if (iface->inputMethod() != T_TX_Interface::eIM_joystick)
{
default_polarity = -1.0;
}
}
item = group->getChild(Global::inputDev->AxisStringsXML[i], true);
c_func[i] = item->attributeAsInt("axis", default_axis);
c_inv[i] = item->attributeAsDouble("polarity", default_polarity);
}
std::string radio =
strU(bindings->attribute("radio_type", RadioTypeStrings[CUSTOM]));
for (int n=0; n < NR_OF_RADIO_TYPES; n++)
{
if (radio.compare(strU(RadioTypeStrings[n])) == 0)
{
setRadioType(n);
}
}
}
catch (XMLException e)
{
fprintf(stderr, "*** T_AxisMapper: XMLException: %s\n", e.what());
}
}
示例3: SimpleXMLTransfer
void Power::Propeller::ReloadParams(SimpleXMLTransfer* xml)
{
Gearing::ReloadParams(xml);
SimpleXMLTransfer* prop;
bool fExtern = true;
if (xml->indexOfAttribute("filename") >= 0)
{
prop = new SimpleXMLTransfer(FileSysTools::getDataPath("models/propeller/" + xml->getString("filename") + ".xml", true));
}
else
{
prop = xml;
fExtern = false;
}
// Der Sturz wird in jedem Fall aus der Modelldatei gelesen, ansonsten muss man ja eine
// Propellerdatei fuer jeden Sturz extra haben.
CalcDownthrust(xml);
D = prop->getDouble("D");
H = prop->getDouble("H");
J = prop->getDouble("J");
omega_fold = prop->attributeAsDouble("n_fold", -1)*2*M_PI;
std::cout << " Propeller: D=" << D << " m, H=" << H << " m, J=" << J << " kg m^2";
if (fExtern)
delete prop;
}
示例4: sin
void Power::Propeller::CalcDownthrust(SimpleXMLTransfer* xml)
{
int idx = xml->indexOfChild("pos");
if (idx < 0)
{
dirThrust = CRRCMath::Vector3(1, 0, 0);
mulForce = CRRCMath::Vector3(1, 0, 0);
mulMoment = CRRCMath::Vector3(0, 0, 0);
}
else
{
SimpleXMLTransfer* sxtpos = xml->getChildAt(idx);
double downthrust = M_PI * sxtpos->getDouble("downthrust", 0) / 180;
dirThrust = CRRCMath::Vector3(cos(downthrust), 0, sin(downthrust));
CRRCMath::Vector3 pos = CRRCMath::Vector3(sxtpos->getDouble("x", 0),
0,
sxtpos->getDouble("z", 0));
CRRCMath::Vector3 dirForce = pos * (1/pos.length());
// Split thrust vector into a part parallel to dirForce and a part parallel to dirMoment:
// dirThrust = a * dirForce + b * dirMoment
// After simplifying all this (and using the variable expressions above) the solution boils down to:
double a = sin(downthrust) * dirForce.r[2] + cos(downthrust) * dirForce.r[0];
double b = cos(downthrust) * dirForce.r[2] - sin(downthrust) * dirForce.r[0];
mulForce = dirForce * a;
mulMoment = CRRCMath::Vector3(0, b * pos.length(), 0);
}
mulForce.print("mulForce=", ", ");
mulMoment.print("mulMoment=", "\n");
}
示例5: CalcDownthrust
void Power::Propeller::ReloadParams_automagic(SimpleXMLTransfer* xml)
{
SimpleXMLTransfer* p = xml->getChild("battery.shaft.propeller");
D = p->getDouble("D");
H = p->getDouble("H");
J = p->getDouble("J");
double F = xml->getDouble("F");
double V = xml->getDouble("V");
// Der Sturz wird in jedem Fall aus der Modelldatei gelesen, ansonsten muss man ja eine
// Propellerdatei fuer jeden Sturz extra haben.
CalcDownthrust(p);
{
// Calculate rotational speed and torque needed:
// F = M_PI * 0.25 * D*D * RHO * (V_X + filter.val/2) * filter.val * ETA_PROP;
// F = M_PI * 0.25 * D*D * RHO * (V + (Hn-V)/2) * (Hn-V) * ETA_PROP;
// F = M_PI * 0.25 * D*D * RHO * (V/2 + Hn/2) * (Hn-V) * ETA_PROP;
double n = sqrt( (8*F/(M_PI*D*D*RHO*ETA_PROP)) + V*V)/H;
double M = F * (V + (V + H*n)/2) / (2*M_PI*n) * i;
// Save these values so the engine can adjust itself to them:
p->setAttribute("automagic.n_P", doubleToString(n));
p->setAttribute("automagic.M_P", doubleToString(M));
}
omega_fold = p->attributeAsDouble("n_fold", -1)*2*M_PI;
}
示例6: initAnimations
/** \brief Add animations to a model
*
* This method reads animation description tags from a model file
* and tries to add the corresponding animations to the 3D model.
*
* \todo Right now there's only one type of animation: movable control
* surfaces. Therefore this method receives a pointer to the control
* input class. If animations are added that need a different kind of
* input for their update() method, we need to decide how to pass all
* this stuff to initAnimations().
*
* \param model_file XML model description file
* \param model scenegraph of the 3D model
*/
void initAnimations(SimpleXMLTransfer *model_file, ssgEntity* model)
{
SimpleXMLTransfer *animations = model_file->getChild("animations", true);
int num_anims = animations->getChildCount();
std::cout << "initAnimations: found " << num_anims << " children" << std::endl;
for (int i = 0; i < num_anims; i++)
{
SimpleXMLTransfer *animation = animations->getChildAt(i);
createAnimation(animation, model);
}
}
示例7: putBackIntoCfg
void T_TX_InterfaceSerPIC::putBackIntoCfg (SimpleXMLTransfer *config)/*{{{*/
{
#if DEBUG_TX_INTERFACE > 0
std::cout << "T_TX_InterfaceSerPIC::putBackIntoCfg(SimpleXMLTransfer *config)" << std::endl;
#endif
// Store the port settings
T_TX_InterfaceSerial::putBackIntoCfg(config);
// Store additional settings
SimpleXMLTransfer *port = config->getChild(getXmlChildName() + ".port", true);
port->setAttributeOverwrite ("sync", ucSyncByte);
port->setAttributeOverwrite ("button_channel", iSPIC_ButtonChannel);
}
示例8: if
Power::Shaft::Shaft(SimpleXMLTransfer* xml)
{
for (int n=0; n<xml->getChildCount(); n++)
{
SimpleXMLTransfer* it = xml->getChildAt(n);
Gearing* s = (Gearing*)0;
if (it->getName().compare("engine") == 0)
s = new Engine_DCM();
else if (it->getName().compare("propeller") == 0)
s = new Propeller();
else if (it->getName().compare("simplethrust") == 0)
s = new SimpleThrust();
if (s != (Gearing*)0)
gear.push_back(s);
}
}
示例9: printf
CRRCAirplaneV2::CRRCAirplaneV2(SimpleXMLTransfer* xml)
{
printf("CRRCAirplaneV2(xml)\n");
// initialize the airplane's sound
initSound(xml);
// initialize the visual representation
// first collect all relevant information from the model file
std::string s;
s = XMLModelFile::getGraphics(xml)->getString("model");
// Offset of center of gravity
CRRCMath::Vector3 pCG;
pCG = CRRCMath::Vector3(0, 0, 0);
if (xml->indexOfChild("CG") >= 0)
{
SimpleXMLTransfer* i;
i = xml->getChild("CG");
pCG.r[0] = i->attributeAsDouble("x", 0);
pCG.r[1] = i->attributeAsDouble("y", 0);
pCG.r[2] = i->attributeAsDouble("z", 0);
if (i->attributeAsInt("units") == 1)
pCG *= M_TO_FT;
}
// plib automatically loads the texture file, but it does not know which directory to use.
// where is the object file?
std::string of = FileSysTools::getDataPath("objects/" + s);
// compile and set relative texture path
std::string tp = of.substr(0, of.length()-s.length()-1-7) + "textures";
lVisID = Video::new_visualization(of, tp, pCG, xml);
if (lVisID == INVALID_AIRPLANE_VISUALIZATION)
{
std::string msg = "Unable to open airplane model file \"";
msg += s;
msg += "\"\nspecified in \"";
msg += xml->getSourceDescr();
msg += "\"";
throw std::runtime_error(msg);
}
}
示例10: cleanup
/**
* Load the airplane specified in configfile. Throw a
* std::runtime_error on failure.
*/
void Aircraft::load(SimpleXMLTransfer *configfile, FDMEnviroment* fdmEnvironment)
{
cleanup();
fdmInterface = new ModFDMInterface();
std::string filename = configfile->getString("airplane.file", "models/allegro.xml");
filename = air_to_xml_file_load(filename);
try
{
SimpleXMLTransfer* xml = new SimpleXMLTransfer(filename);
SimpleXMLTransfer* ap = configfile->getChild("airplane");
// Here we copy graphics and config preferences from crrcsim's config file
// into the in-memory-copy of the airplane. This is because an airplane file
// should not be altered by user preferences.
XMLModelFile::SetGraphics(xml, ap->attributeAsInt("graphics", 0));
XMLModelFile::SetConfig (xml, ap->attributeAsInt("config", 0));
fdmInterface->loadAirplane(xml, fdmEnvironment, configfile);
if (configfile->getInt("video.enabled", 1))
{
model_ = new CRRCAirplaneLaRCSimSSG(xml, scene);
}
getFDM()->registerAnimations(getModel()->getAnimations());
delete xml;
}
catch (XMLException e)
{
std::string msg = "Error opening airplane specification file: ";
msg += filename;
msg += ": ";
msg += e.what();
throw std::runtime_error(msg);
}
if (getFDM() == NULL)
{
throw std::runtime_error("Unable to load airplane specification file.");
}
}
示例11: setRts
/**
* Initialize the interface.
*
* The base class handles all hardware initialization for us, so we only
* have to set up the correct control line states to power the interface.
*/
int T_TX_InterfaceSerPIC::init (SimpleXMLTransfer *config)
{
#if DEBUG_TX_INTERFACE > 0
std::cout << "T_TX_InterfaceSerPIC::init ()\n";
#endif
int ret = T_TX_InterfaceSerial::init (config);
if (ret == 0)
{
// initialized successfully, now turn on the power supply for the
// interface hardware (careful, could throw an exception)
try
{
setRts (true);
setDtr (false);
}
catch (CharDevice::ConfigureDeviceException e)
{
setErrMsg ("Setting Rts/Dtr states failed.");
cerr << "Serial interface initialization: " << getErrMsg () << endl;
ret = 1;
}
int default_sync_byte = DEFAULT_SYNC_BYTE_19200;
int default_button_channel = DEFAULT_BUTTON_CHANNEL_19200;
if (T_TX_InterfaceSerial::getBaudRate() == 9600)
{
default_sync_byte = DEFAULT_SYNC_BYTE_9600;
default_button_channel = DEFAULT_BUTTON_CHANNEL_9600;
}
// read sync and button byte settings from config file
SimpleXMLTransfer *port = config->getChild(getXmlChildName() + ".port", true);
ucSyncByte = port->attributeAsInt("sync", default_sync_byte);
iSPIC_ButtonChannel = port->attributeAsInt("button_channel", default_button_channel);
#if DEBUG_TX_INTERFACE > 0
std::cout << " Configured sync byte: 0x" << std::hex << int(ucSyncByte) << std::dec;
std::cout << ", " << std::string((iSPIC_ButtonChannel == 0) ? "no" : "has") << " button channel";
std::cout << std::endl;
#endif
}
return ret;
}
示例12:
void Power::Shaft::ReloadParams(SimpleXMLTransfer* xml)
{
int nChildCnt = 0;
double J_ges;
fBrake = (xml->attributeAsInt("brake", 1) != 0);
J_ges = xml->attributeAsDouble("J", 0);
std::cout << " Shaft: J=" << J_ges << " kg m^2\n";
for (int n=0; n<xml->getChildCount(); n++)
{
SimpleXMLTransfer* it = xml->getChildAt(n);
if (it->getName().compare("engine") == 0 ||
it->getName().compare("propeller") == 0 ||
it->getName().compare("simplethrust") == 0
)
{
gear[nChildCnt]->ReloadParams(it);
J_ges += gear[nChildCnt++]->getJ();
}
}
J_inv = 1/J_ges;
}
示例13: CRRCAnimation
/**
* Create a CRRCControlSurfaceAnimation object
*
* Initialize the animation from an
* <animation type="ControlSurface"> tag
*/
CRRCControlSurfaceAnimation::CRRCControlSurfaceAnimation(SimpleXMLTransfer *xml)
: CRRCAnimation(new ssgTransform()), fallback_data(0.0f),
eventAdapter(this, &CRRCControlSurfaceAnimation::axisValueCallback, Event::Input),
aileron(0.0f), elevator(0.0f), rudder(0.0f), throttle(0.0f),
spoiler(0.0f), flap(0.0f), retract(0.0f), pitch(0.0f)
{
bool failed = false;
// evaluate <object> tag
SimpleXMLTransfer *map = xml->getChild("object", true);
symbolic_name = map->getString("name", "no_name_set");
max_angle = (float)(map->getDouble("max_angle", 0.0) * SG_RADIANS_TO_DEGREES);
abs_max_angle = (float)fabs((double)max_angle);
// find hinges and evaluate all <control> tags
int num_controls = 0;
int num_hinges = 0;
for (int i = 0; i < xml->getChildCount(); i++)
{
SimpleXMLTransfer *child = xml->getChildAt(i);
if (child->getName() == "hinge")
{
// found a <hinge> child
sgVec3 pos;
pos[SG_X] = (float)(-1 * child->getDouble("y", 0.0));
pos[SG_Y] = (float)(-1 * child->getDouble("x", 0.0));
pos[SG_Z] = (float)(-1 * child->getDouble("z", 0.0));
if (num_hinges == 0)
{
sgCopyVec3(hinge_1, pos);
}
else if (num_hinges == 1)
{
sgCopyVec3(hinge_2, pos);
}
num_hinges++;
}
else if (child->getName() == "control")
{
// found a <control> child
// The "*2" factor for each gain value scales the control input
// values from -0.5...+0.5 to -1.0...+1.0. This saves one
// float multiplication per mapping in the runtime update() routine.
std::string mapping = child->getString("mapping", "NOTHING");
float gain = (float)child->getDouble("gain", 1.0);
if (mapping == "ELEVATOR")
{
datasource.push_back(&elevator);
source_gain.push_back(gain * 2);
num_controls++;
}
else if (mapping == "AILERON")
{
datasource.push_back(&aileron);
source_gain.push_back(gain * 2);
num_controls++;
}
else if (mapping == "THROTTLE")
{
datasource.push_back(&throttle);
source_gain.push_back(gain * 2);
num_controls++;
}
else if (mapping == "RUDDER")
{
datasource.push_back(&rudder);
source_gain.push_back(gain * 2);
num_controls++;
}
else if (mapping == "FLAP")
{
datasource.push_back(&flap);
source_gain.push_back(gain * 2);
num_controls++;
}
else if (mapping == "SPOILER")
{
datasource.push_back(&spoiler);
source_gain.push_back(gain * 2);
num_controls++;
}
else if (mapping == "RETRACT")
{
datasource.push_back(&retract);
source_gain.push_back(gain * 2);
num_controls++;
}
else if (mapping == "PITCH")
{
datasource.push_back(&pitch);
source_gain.push_back(gain * 2);
num_controls++;
}
else
//.........这里部分代码省略.........
示例14: initAnimations
/** \brief Add animations to a model
*
* This method reads animation description tags from a model file
* and tries to add the corresponding animations to the 3D model.
*
* \todo Right now there's only one type of animation: movable control
* surfaces. Therefore this method receives a pointer to the control
* input class. If animations are added that need a different kind of
* input for their update() method, we need to decide how to pass all
* this stuff to initAnimations().
*
* \param model_file XML model description file
* \param model scenegraph of the 3D model
* \param fInputs pointer to the control input class
* \param anim_list list of all created CRRCAnimation objects
*/
void initAnimations(SimpleXMLTransfer *model_file, ssgEntity* model,
TSimInputs *fInput, std::vector<CRRCAnimation*>& anim_list)
{
SimpleXMLTransfer *animations = model_file->getChild("animations", true);
int num_anims = animations->getChildCount();
fprintf(stdout, "initAnimations: found %d children\n", num_anims);
for (int i = 0; i < num_anims; i++)
{
SimpleXMLTransfer *animation = animations->getChildAt(i);
ssgEntity *node;
if (animation->getName() != "animation")
{
fprintf(stderr, "initAnimations: invalid child <%s>\n", animation->getName().c_str());
}
else
{
std::string node_name = animation->getString("object.name", "default");
std::string type = animation->getString("type", "default");
node = SSGUtil::findNamedNode(model, node_name.c_str());
if (node != NULL)
{
CRRCAnimation *anim = NULL;
printf("initAnimations: found animation node %s, type %s\n",
node_name.c_str(), type.c_str());
if (type == "ControlSurface")
{
anim = new CRRCControlSurfaceAnimation(animation, fInput);
}
else
{
fprintf(stderr, "initAnimations: unknown animation type '%s'\n", type.c_str());
}
if (anim != NULL)
{
if (anim->getBranch() == NULL)
{
fprintf(stderr, "initAnimations: defunct animation class (animation branch is <NULL>)\n");
exit(0);
}
else
{
SSGUtil::spliceBranch(anim->getBranch(), node);
anim->init();
anim->setName("Animation");
anim->getBranch()->setUserData(anim);
anim->getBranch()->setTravCallback(SSG_CALLBACK_PRETRAV, animation_callback);
anim_list.push_back(anim);
}
}
}
else
{
fprintf(stderr, "initAnimations: node '%s' not found in 3D model\n", node_name.c_str());
}
}
}
}
示例15: XMLException
void CRRC_AirplaneSim_MCopter01::LoadFromXML(SimpleXMLTransfer* xml, int nVerbosity)
{
if (xml->getString("type").compare("mcopter01") != 0 ||
xml->getInt("version") != 1)
{
throw XMLException("file is not for mcopter01");
}
SimpleXMLTransfer* i;
SimpleXMLTransfer* cfg = XMLModelFile::getConfig(xml);
{
double to_slug;
double to_slug_ft_ft;
i = cfg->getChild("mass_inertia");
switch (i->getInt("units"))
{
case 0:
to_slug = 1;
to_slug_ft_ft = 1;
break;
case 1:
to_slug = KG_TO_SLUG;
to_slug_ft_ft = KG_M_M_TO_SLUG_FT_FT;
break;
default:
{
throw std::runtime_error("Unknown units in mass_inertia");
}
break;
}
Mass = i->getDouble("Mass") * to_slug;
I_xx = i->getDouble("I_xx") * to_slug_ft_ft;
I_yy = i->getDouble("I_yy") * to_slug_ft_ft;
I_zz = i->getDouble("I_zz") * to_slug_ft_ft;
I_xz = i->getDouble("I_xz") * to_slug_ft_ft;
}
{
speed_damp = cfg->getDouble("aero.speed.damp");
roll_damp1 = cfg->getDouble("aero.roll.damp1", 0);
yaw_damp1 = cfg->getDouble("aero.yaw.damp1", 0);
roll_damp2 = cfg->getDouble("aero.roll.damp2", 0);
yaw_damp2 = cfg->getDouble("aero.yaw.damp2", 0);
yaw_dist = cfg->getDouble("aero.yaw.dist", 0);
roll_dist = cfg->getDouble("aero.roll.dist", 0);
pitch_dist = cfg->getDouble("aero.pitch.dist", roll_dist);
// The ground effect parameters should be quite independent of the helicopter
// parameters...shouldn't they? However, they can be adjusted.
dGEDistMul = xml->getDouble("GroundEffect.dist.mul", 1.5);
{
double tau = xml->getDouble("Disturbance.tau_filter", 0.2);
dist_t_init = xml->getDouble("Disturbance.time", 0.2);
filt_rnd_yaw.SetTau(tau);
filt_rnd_roll.SetTau(tau);
filt_rnd_pitch.SetTau(tau);
}
}
wheels.init(xml, 0);
dRotorRadius = wheels.getWingspan()*0.5;
dRotorZ = wheels.getZHigh();
wheels.init(xml, 0);
dRotorRadius = wheels.getWingspan()*0.5;
dRotorZ = wheels.getZHigh();
props.clear();
i = cfg->getChild("aero.props");
for (int n=0; n<i->getChildCount(); n++)
props.push_back(Propdata(i->getChildAt(n)));
if (power.size() == 0)
{
for (unsigned int n=0; n<props.size(); n++)
power.push_back(new Power::Power(cfg, nVerbosity));
dURef = 0.7 * cfg->getDouble("power.battery.U_0");
}
else
{
for (unsigned int n=0; n<power.size(); n++)
power[n]->ReloadParams(cfg, nVerbosity);
}
controllers.clear();
Controller::LoadList(cfg->getChild("controllers"), controllers);
}