Skip to content

Commit

Permalink
better handling of animation files
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich committed Oct 19, 2016
1 parent d605fc7 commit bdfb2da
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 149 deletions.
57 changes: 34 additions & 23 deletions OMEdit/OMEditGUI/Animation/AnimationUtil.h
Expand Up @@ -44,29 +44,29 @@

enum class VisType
{
NONE = 0,
FMU = 1,
FMU_REMOTE = 2,
MAT = 3,
MAT_REMOTE = 4
NONE = 0,
FMU = 1,
FMU_REMOTE = 2,
MAT = 3,
MAT_REMOTE = 4
};

/*!
* \brief isFMU
* checks of the file is of type FMU
*/
inline bool isFMU(const std::string& fileIn){
std::size_t fmu = fileIn.find(".fmu");
return (fmu != std::string::npos);
std::size_t fmu = fileIn.find(".fmu");
return (fmu != std::string::npos);
}

/*!
* \brief isMAT
* checks of the file is of type mat
*/
inline bool isMAT(const std::string& fileIn){
std::size_t mat = fileIn.find(".mat");
return (mat != std::string::npos);
std::size_t mat = fileIn.find(".mat");
return (mat != std::string::npos);
}

/*!
Expand All @@ -76,11 +76,11 @@ inline bool isMAT(const std::string& fileIn){
inline std::string assembleXMLFileName(const std::string& modelFile, const std::string& path){
int signsOff(0);
if (isFMU(modelFile))
signsOff = 4;
signsOff = 4;
else if (isMAT(modelFile))
signsOff = 8;
signsOff = 8;
else{
// todo: Handle this case.
// todo: Handle this case.
}
// Cut off prefix [fmu|mat]
std::string fileName = modelFile.substr(0, modelFile.length() - signsOff);
Expand All @@ -92,36 +92,47 @@ inline std::string assembleXMLFileName(const std::string& modelFile, const std::
/*! \brief Checks if the file is accessible. */
inline bool fileExists(const std::string& file)
{
struct stat buffer;
return (stat(file.c_str(), &buffer) == 0);
struct stat buffer;
return (stat(file.c_str(), &buffer) == 0);
}

/*!
* \brief checkForXMLFile
* checks if the xml file is available
*/
inline bool checkForXMLFile(const std::string& modelFile, const std::string& path){
// Cut off prefix [fmu|mat]
std::string xmlFileName = assembleXMLFileName(modelFile, path);
return fileExists(xmlFileName);
// Cut off prefix [fmu|mat]
std::string xmlFileName = assembleXMLFileName(modelFile, path);
return fileExists(xmlFileName);
}

/*! \brief Checks if the type is a cad file
*/
inline bool isCADType(const std::string& typeName)
{
return (typeName.size() >= 12 && std::string(typeName.begin(), typeName.begin() + 11) == "modelica://");
return (typeName.size() >= 12 && std::string(typeName.begin(), typeName.begin() + 11) == "modelica://");
}


inline bool dxfFileType(const std::string& typeName)
{
return typeName.substr(typeName.size()-3) == std::string("dxf");
}


inline bool stlFileType(const std::string& typeName)
{
return typeName.substr(typeName.size()-3) == std::string("stl");
}


/*! \brief Get file name of the cad file
*/
inline std::string extractCADFilename(const std::string& s)
{
std::string fileKey = "modelica://";
std::string s2 = s.substr(fileKey.length(), s.length());
int pos = s2.find("/");
return s2.substr(pos + 1, s.length());
std::string fileKey = "modelica://";
std::string s2 = s.substr(fileKey.length(), s.length());
return s2;
}


#endif //ANIMATIONUTIL_H
50 changes: 26 additions & 24 deletions OMEdit/OMEditGUI/Animation/Shapes.cpp
Expand Up @@ -57,12 +57,13 @@ std::string ShapeObjectAttribute::getValueString() const


ShapeObject::ShapeObject()
: _id("noID"),
_type("box"),
_length(ShapeObjectAttribute(0.1)),
_width(ShapeObjectAttribute(0.1)),
_height(ShapeObjectAttribute(0.1)),
_specCoeff(ShapeObjectAttribute(0.7)),
: _id("noID"),
_type("box"),
_fileName("noFile"),
_length(ShapeObjectAttribute(0.1)),
_width(ShapeObjectAttribute(0.1)),
_height(ShapeObjectAttribute(0.1)),
_specCoeff(ShapeObjectAttribute(0.7)),
_mat(osg::Matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)),
_extra(ShapeObjectAttribute(0.0))
{
Expand Down Expand Up @@ -94,24 +95,25 @@ ShapeObject::ShapeObject()

void ShapeObject::dumpVisAttributes() const
{
std::cout << "id " << _id << std::endl;
std::cout << "type " << _type << std::endl;
std::cout << "length " << _length.getValueString() << std::endl;
std::cout << "width " << _width.getValueString() << std::endl;
std::cout << "height " << _height.getValueString() << std::endl;
std::cout << "lDir " << _lDir[0].getValueString() << ", " << _lDir[1].getValueString() << ", " << _lDir[2].getValueString() << ", " << std::endl;
std::cout << "wDir " << _wDir[0].getValueString() << ", " << _wDir[1].getValueString() << ", " << _wDir[2].getValueString() << ", " << std::endl;
std::cout << "r " << _r[0].getValueString() << ", " << _r[1].getValueString() << ", " << _r[2].getValueString() << ", " << std::endl;
std::cout << "r_shape " << _rShape[0].getValueString() << ", " << _rShape[1].getValueString() << ", " << _rShape[2].getValueString() << ", " << std::endl;
std::cout << "T0 " << _T[0].getValueString() << ", " << _T[1].getValueString() << ", " << _T[2].getValueString() << ", " << std::endl;
std::cout << " " << _T[3].getValueString() << ", " << _T[4].getValueString() << ", " << _T[5].getValueString() << ", " << std::endl;
std::cout << " " << _T[6].getValueString() << ", " << _T[7].getValueString() << ", " << _T[8].getValueString() << ", " << std::endl;
std::cout << "color " << _color[0].getValueString() << ", " << _color[1].getValueString() << ", " << _color[2].getValueString() << ", " << std::endl;
std::cout << "mat " << _mat(0, 0) << ", " << _mat(0, 1) << ", " << _mat(0, 2) << ", " << _mat(0, 3) << std::endl;
std::cout << " " << _mat(1, 0) << ", " << _mat(1, 1) << ", " << _mat(1, 2) << ", " << _mat(1, 3) << std::endl;
std::cout << " " << _mat(2, 0) << ", " << _mat(2, 1) << ", " << _mat(2, 2) << ", " << _mat(2, 3) << std::endl;
std::cout << " " << _mat(3, 0) << ", " << _mat(3, 1) << ", " << _mat(3, 2) << ", " << _mat(3, 3) << std::endl;
std::cout << "extra " << _extra.getValueString() << std::endl;
std::cout << "id " << _id << std::endl;
std::cout << "type " << _type << std::endl;
std::cout << "fileName " << _fileName << std::endl;
std::cout << "length " << _length.getValueString() << std::endl;
std::cout << "width " << _width.getValueString() << std::endl;
std::cout << "height " << _height.getValueString() << std::endl;
std::cout << "lDir " << _lDir[0].getValueString() << ", " << _lDir[1].getValueString() << ", " << _lDir[2].getValueString() << ", " << std::endl;
std::cout << "wDir " << _wDir[0].getValueString() << ", " << _wDir[1].getValueString() << ", " << _wDir[2].getValueString() << ", " << std::endl;
std::cout << "r " << _r[0].getValueString() << ", " << _r[1].getValueString() << ", " << _r[2].getValueString() << ", " << std::endl;
std::cout << "r_shape " << _rShape[0].getValueString() << ", " << _rShape[1].getValueString() << ", " << _rShape[2].getValueString() << ", " << std::endl;
std::cout << "T0 " << _T[0].getValueString() << ", " << _T[1].getValueString() << ", " << _T[2].getValueString() << ", " << std::endl;
std::cout << " " << _T[3].getValueString() << ", " << _T[4].getValueString() << ", " << _T[5].getValueString() << ", " << std::endl;
std::cout << " " << _T[6].getValueString() << ", " << _T[7].getValueString() << ", " << _T[8].getValueString() << ", " << std::endl;
std::cout << "color " << _color[0].getValueString() << ", " << _color[1].getValueString() << ", " << _color[2].getValueString() << ", " << std::endl;
std::cout << "mat " << _mat(0, 0) << ", " << _mat(0, 1) << ", " << _mat(0, 2) << ", " << _mat(0, 3) << std::endl;
std::cout << " " << _mat(1, 0) << ", " << _mat(1, 1) << ", " << _mat(1, 2) << ", " << _mat(1, 3) << std::endl;
std::cout << " " << _mat(2, 0) << ", " << _mat(2, 1) << ", " << _mat(2, 2) << ", " << _mat(2, 3) << std::endl;
std::cout << " " << _mat(3, 0) << ", " << _mat(3, 1) << ", " << _mat(3, 2) << ", " << _mat(3, 3) << std::endl;
std::cout << "extra " << _extra.getValueString() << std::endl;

}

Expand Down
29 changes: 15 additions & 14 deletions OMEdit/OMEditGUI/Animation/Shapes.h
Expand Up @@ -68,20 +68,21 @@ class ShapeObject
void dumpVisAttributes() const;
//void fetchVisAttributes(rapidxml::xml_node<>* node, ModelicaMatReader matReader,/* fmi1_import_t* fmu,*/ double time, bool useFMU);
public:
std::string _id;
std::string _type;
ShapeObjectAttribute _length;
ShapeObjectAttribute _width;
ShapeObjectAttribute _height;
ShapeObjectAttribute _r[3];
ShapeObjectAttribute _rShape[3];
ShapeObjectAttribute _lDir[3];
ShapeObjectAttribute _wDir[3];
ShapeObjectAttribute _color[3];
ShapeObjectAttribute _T[9];
ShapeObjectAttribute _specCoeff;
osg::Matrix _mat;
ShapeObjectAttribute _extra;
std::string _id;
std::string _type;
std::string _fileName;
ShapeObjectAttribute _length;
ShapeObjectAttribute _width;
ShapeObjectAttribute _height;
ShapeObjectAttribute _r[3];
ShapeObjectAttribute _rShape[3];
ShapeObjectAttribute _lDir[3];
ShapeObjectAttribute _wDir[3];
ShapeObjectAttribute _color[3];
ShapeObjectAttribute _T[9];
ShapeObjectAttribute _specCoeff;
osg::Matrix _mat;
ShapeObjectAttribute _extra;
};

struct rAndT
Expand Down

0 comments on commit bdfb2da

Please sign in to comment.