Changeset e757cda7 in OpenModelica


Ignore:
Timestamp:
2023-03-27T11:28:24+02:00 (13 months ago)
Author:
anotheruserofgithub <96748782+anotheruserofgithub@…>
Children:
7aafc15
Parents:
ee088cb
git-author:
anotheruserofgithub <96748782+anotheruserofgithub@…> (03/23/23 09:18:12)
git-committer:
anotheruserofgithub <96748782+anotheruserofgithub@…> (03/27/23 11:28:24)
Message:

Clean up functions for CAD file checks

Location:
OMEdit/OMEditLIB/Animation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • OMEdit/OMEditLIB/Animation/AnimationUtil.h

    ree088cb re757cda7  
    3636#define ANIMATIONUTIL_H
    3737
     38#include <QFileInfo>
    3839#include <QString>
    39 #include <QRegExp>
    40 #include <QFileInfo>
    4140
    42 #include <QOpenGLContext> // must be included before OSG headers
    43 
    44 #include <sys/stat.h>
    4541#include <string>
    46 #include <osg/Vec3>
    4742
    4843#include "MainWindow.h"
     
    126121}
    127122
    128 /*! \brief Checks if the type is a cad file
     123/*!
     124 * \brief Gets the filename of the CAD file
    129125 */
    130 inline bool isCADType(const std::string& typeName)
     126inline std::string extractCADFilename(const std::string& typeName)
    131127{
    132   return ((typeName.size() >= 12 && std::string(typeName.begin(), typeName.begin() + 11) == "modelica://")
    133           || (typeName.size() >= 8 && std::string(typeName.begin(), typeName.begin() + 7) == "file://"));
    134 }
    135 
    136 
    137 inline bool dxfFileType(const std::string& typeName)
    138 {
    139   return typeName.substr(typeName.size()-3) == std::string("dxf");
    140 }
    141 
    142 inline bool stlFileType(const std::string& typeName)
    143 {
    144   return typeName.substr(typeName.size()-3) == std::string("stl");
    145 }
    146 
    147 inline bool objFileType(const std::string& typeName)
    148 {
    149   return typeName.substr(typeName.size()-3) == std::string("obj");
    150 }
    151 
    152 inline bool tdsFileType(const std::string& typeName)
    153 {
    154   return typeName.substr(typeName.size()-3) == std::string("3ds");
    155 }
    156 
    157 
    158 /*! \brief Get file name of the cad file
    159  */
    160 inline std::string extractCADFilename(const std::string& s)
    161 {
    162   QString str(s.c_str());
     128  QString str(typeName.c_str());
    163129  if (str.startsWith("modelica://")) {
    164130    const QString absoluteFileName = MainWindow::instance()->getOMCProxy()->uriToFilename(str);
    165131    return absoluteFileName.toStdString();
    166132  } else {
    167     std::string fileKey = "file://";
    168     std::string s2 = s.substr(fileKey.length(), s.length());
    169     return s2;
     133    const std::string fileKey = "file://";
     134    return typeName.substr(fileKey.length(), typeName.length());
    170135  }
     136}
     137
     138/*!
     139 * \brief Checks if the type is a CAD file
     140 */
     141inline bool isCADFile(const std::string& typeName)
     142{
     143  return ((typeName.size() >= 12 && std::string(typeName.begin(), typeName.begin() + 11) == "modelica://") ||
     144          (typeName.size() >=  8 && std::string(typeName.begin(), typeName.begin() +  7) == "file://"));
     145}
     146
     147inline bool isDXFFile(const std::string& fileName)
     148{
     149  return fileName.substr(fileName.size() - 3) == "dxf";
     150}
     151
     152inline bool isSTLFile(const std::string& fileName)
     153{
     154  return fileName.substr(fileName.size() - 3) == "stl";
     155}
     156
     157inline bool isOBJFile(const std::string& fileName)
     158{
     159  return fileName.substr(fileName.size() - 3) == "obj";
     160}
     161
     162inline bool is3DSFile(const std::string& fileName)
     163{
     164  return fileName.substr(fileName.size() - 3) == "3ds";
    171165}
    172166
     
    176170}
    177171
    178 
    179172#endif //ANIMATIONUTIL_H
  • OMEdit/OMEditLIB/Animation/Visualization.cpp

    ree088cb re757cda7  
    318318    shape._type = std::string(expNode->value());
    319319
    320     if (isCADType(shape._type))
     320    if (isCADFile(shape._type))
    321321    {
    322322      shape._fileName = extractCADFilename(shape._type);
     
    329329      }
    330330
    331       if (dxfFileType(shape._fileName)) {
     331      if (isDXFFile(shape._fileName)) {
    332332        shape._type = "dxf";
    333       } else if (stlFileType(shape._fileName)) {
     333      } else if (isSTLFile(shape._fileName)) {
    334334        shape._type = "stl";
    335       } else if (objFileType(shape._fileName)) {
     335      } else if (isOBJFile(shape._fileName)) {
    336336        shape._type = "obj";
    337       } else if (tdsFileType(shape._fileName)) {
     337      } else if (is3DSFile(shape._fileName)) {
    338338        shape._type = "3ds";
    339339      }
Note: See TracChangeset for help on using the changeset viewer.