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()
MapHandlerGen* Surface_Import_Plugin::importMeshFromFile(const QString& nameOfFile)
{
QString fileName = SCHNApps::noBackSlash(nameOfFile);
QFileInfo fi(fileName);
if(fi.exists())
{
MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 2);
MapHandlerGen* mhg = m_schnapps->addMap(SCHNApps::forceASCII(fi.baseName()), 2);
if(mhg)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
PFP2::MAP* map = mh->getMap();
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++)
{
......@@ -83,9 +84,7 @@ MapHandlerGen* Surface_Import_Plugin::importImageFromFile(const QString& nameOfF
QFileInfo fi(fileName);
if(fi.exists())
{
pythonRecording("importImageFromFile", fi.baseName(), fileName);
MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 2);
MapHandlerGen* mhg = m_schnapps->addMap(SCHNApps::forceASCII(fi.baseName()), 2);
if(mhg)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
......@@ -122,6 +121,7 @@ MapHandlerGen* Surface_Import_Plugin::importImageFromFile(const QString& nameOfF
mh->registerAttribute(color);
}
pythonRecording("importImageFromFile", mhg->getName(), fileName);
return mhg;
}
else
......
......@@ -89,11 +89,23 @@ inline T pyR_stringify(T v)
template <>
inline QString pyR_stringify(QString 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>
void Plugin::pythonRecording(QString slotName, QString returned, T1 param1)
{
......
......@@ -415,6 +415,12 @@ public:
/// replace \ by / in file path for window
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:
void cameraAdded(Camera* camera);
......
......@@ -1084,6 +1084,25 @@ QString SCHNApps::noBackSlash(const QString& name)
#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)
{
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