Wed, 02/08/2023 - 11:49
Hello,
My code here:
Handle(TDocStd_Document) m_Document = ReadSTEPToDocument(fileloc);
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(m_Document->Main());
TDF_LabelSequence aRootLabels;
aShapeTool->GetFreeShapes(aRootLabels);
TDF_Label labelMain;
std::vector<TDF_Label> vecShapelabels;
for (TDF_LabelSequence::Iterator aRootIter(aRootLabels); aRootIter.More(); aRootIter.Next())
{
const TDF_Label& aRootLabel = aRootIter.Value();
if (XCAFDoc_ShapeTool::IsAssembly(aRootLabel))
{
if (labelMain.IsNull())
{
labelMain = aRootLabel;
}
}
GetAssemblyShapes(aRootLabel, vecShapelabels);
#if 1
for (auto it_ls = vecShapelabels.begin(); it_ls != vecShapelabels.end(); ++it_ls)
{
TopoDS_Shape aRootShape;
if (XCAFDoc_ShapeTool::GetShape(*it_ls, aRootShape))
{
aShMap.Add(aRootShape);
}
TCollection_ExtendedString asName;
Handle_TDataStd_Name attrName;
if (it_ls->FindAttribute(TDataStd_Name::GetID(), attrName)) {
asName = attrName->Get();
}
string str=TCollection_AsciiString(asName).ToCString();
}
#endif
This program can running but sometimes the "asName" and "str" will get wrong name like "ǰФͥ" ,how do i fix it ?
Wed, 02/08/2023 - 12:14
Hello,
String "str" can work with pure ASCII symbols. You need to specify locale and convert them to needed local, if it possible (using OCCT API or
std::codecvt
).Or you can use special container according TCollection_ExtendedString:
Best regards, Dmitrii.
Fri, 02/10/2023 - 12:42
Thanks,
I’m trying to change encoding of "str",but it still error name and became chinese error name or another error name. Do you have anothor suggestion?
Thanks again.
Fri, 02/10/2023 - 13:06
How exactly do you use this
std::string
later and check if it's name is wrong or correct? What is the origin file, may you share a sample? How names are displayed in CAD Assistant?Fri, 02/10/2023 - 13:36
You import Step file. So, can you check the locale of this file?
If step file written in UTF we read it just converting to the Unicode. But if it written by special locale or use special coding for non ASCII symbols you need to setting import process before reading.
The param for changing reading from some locales - "read.step.codepage".
If it is possible please share any entity with Chinese symbol. "#1234 = PRODUCT ("...",...)" All supported locales you can see in "occt/src/Resource/Resource_FormatType.hxx". Default value - Resource_FormatType_UTF8. Also you can disable conversion, using Resource_FormatType_ANSI and convert string after in your environmental.
Best regards, Dmitrii.
Mon, 02/13/2023 - 11:57
thanks,
This resource encoding is ISO-8859,Does OCCT not support this encoding?
Mon, 02/13/2023 - 12:34
You may see the list of built-in code page converters in Resource_FileType enumeration:
STEP standard doesn't support these code pages - symbols should be encoded in UTF-8 or via special format. As such, you'll need passing non-standard code page to OCCT explicitly.
Mon, 02/13/2023 - 13:15
You means change source .STEP file first. And then loading that ?
Mon, 02/13/2023 - 13:49
Hello,
you can change parameter for converting names from STEP file.
Best regards, Dmitrii.
Tue, 02/14/2023 - 11:35
hi,
It's still wrong name.I can get right name when i use "SystemLocale" on Windows,but get nothing on Linux.how to set GB2312 encoding with SetCVal? How to convert TCollection_ExtendedString to std:string without TCollection_AsciiString?
Thanks very much.
Mon, 02/13/2023 - 14:08
By the way, your file uses GB2312 code page.
Tue, 02/14/2023 - 05:53
thanks,
so,How to set gb2312 encoding from SetCval("read.step.codepage","xxx").Them all return false when I try to use "GBK" or "GB2312" ,can I only use "SystemLocale" to get right name?
Tue, 02/14/2023 - 14:20
Hello,
please try the next code:
You can see the numbers for all locales below(copied from "occt\occt\src\STEPControl\STEPControl_Controller.cxx"):
Best regards, Dmitrii.
Tue, 02/14/2023 - 15:04
Thanks very much!
I think i fix this now,and another question is convert TCollection_ExtendedString to std:string without TCollection_AsciiString.
Thanks again.
Tue, 02/14/2023 - 16:26
Hello,
You try to convert from 16bit to 8 bit. So, you need to make some conversion. TCollection_AsciiString helps with it action.
But of course, you can do it directly using the code from constructor:
Best regards, Dmitrii.