00001 #include "SIGEL_Robot/SIG_Material.h"
00002
00003 namespace SIGEL_Robot {
00004
00005 SIG_Material::SIG_Material (SIG_Robot *par, QString n)
00006 : parent (par),
00007 name (n),
00008 elasticity (1.0),
00009 density (1.0),
00010 friction (),
00011 colour (1.0, 1.0, 1.0)
00012 {
00013 }
00014
00015 SIG_Material::SIG_Material (SIG_Robot *par, QTextStream & tx)
00016 : parent (par)
00017 {
00018 QString tmpstr;
00019 int zahl;
00020
00021
00022 tx >> name
00023 >> elasticity
00024 >> density;
00025
00026 tx >> zahl;
00027 for (int i = 0; i < zahl; i++) {
00028 QString fname;
00029 DL_Scalar fval;
00030 SIG_Material *fother;
00031
00032 tx >> fname;
00033 tx >> fval;
00034
00035 if (fother = parent->lookupMaterial (fname))
00036 setFrictionValue (fother, fval);
00037 }
00038 colour = SIG_Robot::streamToVector (tx);
00039 }
00040
00041 SIG_Material::~SIG_Material (void)
00042 {
00043 friction.setAutoDelete (TRUE);
00044 }
00045
00046 QString SIG_Material::getName (void) const
00047 {
00048 return name;
00049 }
00050
00051 void SIG_Material::setDensity (DL_Scalar dens)
00052 {
00053 density = dens;
00054 }
00055
00056 DL_Scalar SIG_Material::getDensity (void) const
00057 {
00058 return density;
00059 }
00060
00061 void SIG_Material::setElasticity (DL_Scalar elas)
00062 {
00063 elasticity = elas;
00064 }
00065
00066 DL_Scalar SIG_Material::getElasticity (void) const
00067 {
00068 return elasticity;
00069 }
00070
00071 void SIG_Material::setColour (DL_vector col)
00072 {
00073 colour = col;
00074 }
00075
00076 DL_vector SIG_Material::getColour (void) const
00077 {
00078 return colour;
00079 }
00080
00081 void SIG_Material::setFrictionValue (SIG_Material *otherObj,
00082 DL_Scalar fricval,
00083 bool negotiate = true)
00084 {
00085 QListIterator<FrictionValue> li (friction);
00086 while (li.current ()) {
00087 if (li.current ()->otherSide == otherObj) {
00088 li.current ()->value = fricval;
00089 break;
00090 }
00091 ++li;
00092 }
00093
00094 if (!li.current ()) {
00095 FrictionValue *fv = new FrictionValue;
00096 fv->otherSide = otherObj;
00097 fv->value = fricval;
00098 friction.append (fv);
00099 }
00100
00101 if ((negotiate) && (otherObj != this))
00102 otherObj->setFrictionValue (this, fricval, false);
00103 }
00104
00105 DL_Scalar SIG_Material::getFrictionValue (SIG_Material *otherObj) const
00106 {
00107 QListIterator<FrictionValue> li (friction);
00108 while (li.current ()) {
00109 if (li.current ()->otherSide == otherObj)
00110 return li.current ()->value;
00111 ++li;
00112 }
00113 return 0.6;
00114 }
00115
00116 void SIG_Material::writeToFileTransfer (QTextStream & tx) const
00117 {
00118 QListIterator<FrictionValue> li (friction);
00119
00120 tx << "Material" << ' '
00121 << getName () << ' '
00122 << elasticity << ' '
00123 << density << ' '
00124 << friction.count () << ' ';
00125 while (li.current ()) {
00126 FrictionValue *fv = li.current ();
00127 tx << fv->otherSide->getName () << ' '
00128 << fv->value << ' ';
00129 ++li;
00130 }
00131 SIG_Robot::vectorToStream (tx, colour);
00132 tx << '\n';
00133 }
00134 }