Commit f831db2e authored by Sylvain Thery's avatar Sylvain Thery

schnapps: resolve pb of accent in path

parent ab151030
...@@ -33,19 +33,20 @@ bool Surface_Import_Plugin::enable() ...@@ -33,19 +33,20 @@ bool Surface_Import_Plugin::enable()
MapHandlerGen* Surface_Import_Plugin::importMeshFromFile(const QString& nameOfFile) MapHandlerGen* Surface_Import_Plugin::importMeshFromFile(const QString& nameOfFile)
{ {
QString fileName = SCHNApps::noBackSlash(nameOfFile); QString fileName = SCHNApps::noBackSlash(nameOfFile);
QFileInfo fi(fileName); QFileInfo fi(fileName);
if(fi.exists()) if(fi.exists())
{ {
MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 2); MapHandlerGen* mhg = m_schnapps->addMap(SCHNApps::forceASCII(fi.baseName()), 2);
if(mhg) if(mhg)
{ {
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg); MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
PFP2::MAP* map = mh->getMap(); PFP2::MAP* map = mh->getMap();
std::vector<std::string> attrNames; std::vector<std::string> attrNames;
Algo::Surface::Import::importMesh<PFP2>(*map, fileName.toStdString(), attrNames); Algo::Surface::Import::importMesh<PFP2>(*map, SCHNApps::niceStdString(fileName), attrNames);
for (unsigned int orbit = VERTEX; orbit <= VOLUME; orbit++) for (unsigned int orbit = VERTEX; orbit <= VOLUME; orbit++)
{ {
...@@ -83,9 +84,7 @@ MapHandlerGen* Surface_Import_Plugin::importImageFromFile(const QString& nameOfF ...@@ -83,9 +84,7 @@ MapHandlerGen* Surface_Import_Plugin::importImageFromFile(const QString& nameOfF
QFileInfo fi(fileName); QFileInfo fi(fileName);
if(fi.exists()) if(fi.exists())
{ {
pythonRecording("importImageFromFile", fi.baseName(), fileName); MapHandlerGen* mhg = m_schnapps->addMap(SCHNApps::forceASCII(fi.baseName()), 2);
MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 2);
if(mhg) if(mhg)
{ {
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg); MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
...@@ -122,6 +121,7 @@ MapHandlerGen* Surface_Import_Plugin::importImageFromFile(const QString& nameOfF ...@@ -122,6 +121,7 @@ MapHandlerGen* Surface_Import_Plugin::importImageFromFile(const QString& nameOfF
mh->registerAttribute(color); mh->registerAttribute(color);
} }
pythonRecording("importImageFromFile", mhg->getName(), fileName);
return mhg; return mhg;
} }
else else
......
...@@ -89,9 +89,21 @@ inline T pyR_stringify(T v) ...@@ -89,9 +89,21 @@ inline T pyR_stringify(T v)
template <> template <>
inline QString pyR_stringify(QString v) inline QString pyR_stringify(QString v)
{ {
return "\"" + v + "\""; // test if v containe non ascii char
} bool needDecode = false;
int i = 0;
while (!needDecode && (i < v.size()))
{
if (v[i].unicode()>127)
needDecode = true;
++i;
}
if (needDecode)
return "\"" + v + "\".decode('latin-1')";
else
return "\"" + v + "\"";
}
template <typename T1> template <typename T1>
......
...@@ -415,6 +415,12 @@ public: ...@@ -415,6 +415,12 @@ public:
/// replace \ by / in file path for window /// replace \ by / in file path for window
static QString noBackSlash(const QString& name); static QString noBackSlash(const QString& name);
/// transform QString in std::string with
static std::string niceStdString(const QString& qstr);
/// force QString contain to be ascii (non ascii char are replaced by '_')
static QString forceASCII(const QString& qstr);
signals: signals:
void cameraAdded(Camera* camera); void cameraAdded(Camera* camera);
......
...@@ -1084,6 +1084,25 @@ QString SCHNApps::noBackSlash(const QString& name) ...@@ -1084,6 +1084,25 @@ QString SCHNApps::noBackSlash(const QString& name)
#endif #endif
} }
std::string SCHNApps::niceStdString(const QString& qstr)
{
return std::string(qstr.toLocal8Bit().data());
}
QString SCHNApps::forceASCII(const QString& qstr)
{
QString str(qstr);
for (QString::iterator it = str.begin(); it != str.end(); ++it)
{
if (it->unicode() > 127)
*it = '_';
}
return str;
}
void SCHNApps::setPythonPath(const QString& path) void SCHNApps::setPythonPath(const QString& path)
{ {
m_pyPathFile = SCHNApps::noBackSlash(path); m_pyPathFile = SCHNApps::noBackSlash(path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment