How can opencascade support chinese file path ?

What can I do in order to make opencascade support chinese file path? Opencascade can not open file under chinese file path now .

Marko Knöbl's picture

I had this problem too. In order to work around it in my application I'm creating a temporary directory, then copying the file to that temporary directory and reading it from there.

On Linux I get a file path that looks like this: "/var/my-application-name/import-file.stp" - so it only contains ASCII characters and can be read without any problem.

Note that this workaround will not help if the users are running Windows and have non-ASCII-characters in their username as the temporary path there will be "C:\Users\USERNAME\AppData\Local\Temp\my-application-name".

Hope this helps!

Göran Barz's picture

If you use Windows, you might try to use the short path name, which if I remember correctly only consists of ascii letters:

wstring strStepFile = L"Some Chinese Name.stp"
char strFileName[_MAX_PATH];
wcstombs(strFileName, strStepFile.c_str(), _MAX_PATH);
if (strchr(strFileName, '?') != NULL)
{
wchar_t strShortPath[_MAX_PATH];
::GetShortPathNameW(strStepFile .c_str(), strShortPath,
_MAX_PATH);
wcstombs(strFileName, strShortPath, _MAX_PATH);
}

SunHongLei's picture

Thanks for your help! I have tried you method but it also can not read chinese file path.
I checked opencascade's source file and found that it is the type OSD_Path that can not surpport
chinese characters. Because chinese character is multi-bytes and opencascade read file path with Standard_Character,So it can not read chinese character. I need change opencascade's code if I want
improve the problem.

SunHongLei's picture

It can be setteled by this way : in the file OSD_Path.cxx there is a function named systemname, change the code
for ( i = j = 1; i <= myTrek.UsefullLength() && j <= _MAX_PATH; ++i, ++j )
to
for ( i = j = 1; i <= myTrek.Length() && j <= _MAX_PATH; ++i, ++j )

can rebuild the project,then it is oK!

Weidong LI's picture

Thanks for tips, but I can't see the changes you mentioned?

Could you explain clearly?

liuhuiwei's picture

Convert the path string to UTF8

Weidong LI's picture

It works. Thank you so much!