if(!N.IsNull())
cout << "String = " << TCollection_AsciiString(N->Get(), '?').ToCString() << endl;
#endif
- TCollection_AsciiString s(N->Get(),'?');
- di << s.ToCString();
+ di << N->Get();
return 0;
}
di << "DDataStd_SetName : Error\n";
#ifndef _Resource_FormatType_HeaderFile
#define _Resource_FormatType_HeaderFile
-
-//! List of non ASCII format types which may be
-//! converted into the Unicode 16 bits format type.
-//! Use the functions provided by the
-//! Resource_Unicode class to convert a string
+//! List of non ASCII format types which may be converted into the Unicode 16 bits format type.
+//! Use the functions provided by the Resource_Unicode class to convert a string
//! from one of these non ASCII format to Unicode, and vice versa.
enum Resource_FormatType
{
-Resource_SJIS,
-Resource_EUC,
-Resource_ANSI,
-Resource_GB
+ Resource_FormatType_SJIS, //!< SJIS (Shift Japanese Industrial Standards) encoding
+ Resource_FormatType_EUC, //!< EUC (Extended Unix Code) multi-byte encoding primarily for Japanese, Korean, and simplified Chinese
+ Resource_FormatType_ANSI, //!< ANSI encoding (pass through without conversion)
+ Resource_FormatType_GB, //!< GB (Guobiao) encoding for Simplified Chinese
+ Resource_FormatType_UTF8, //!< multi-byte UTF-8 encoding
+ Resource_FormatType_SystemLocale, //!< active system-defined locale; this value is strongly NOT recommended to use
+
+ // old aliases
+ Resource_SJIS = Resource_FormatType_SJIS,
+ Resource_EUC = Resource_FormatType_EUC,
+ Resource_ANSI = Resource_FormatType_ANSI,
+ Resource_GB = Resource_FormatType_GB,
};
#endif // _Resource_FormatType_HeaderFile
Resource_Unicode::GetFormat();
}
-void Resource_Unicode::ConvertFormatToUnicode(const Standard_CString fromstr,
- TCollection_ExtendedString& tostr)
+void Resource_Unicode::ConvertFormatToUnicode (const Resource_FormatType theFormat,
+ const Standard_CString theFromStr,
+ TCollection_ExtendedString& theToStr)
{
- Resource_FormatType theform = Resource_Unicode::GetFormat();
- switch (theform) {
- case Resource_SJIS :
+ switch (theFormat)
+ {
+ case Resource_FormatType_SJIS:
{
- ConvertSJISToUnicode(fromstr,tostr);
+ ConvertSJISToUnicode (theFromStr, theToStr);
break;
}
- case Resource_EUC :
+ case Resource_FormatType_EUC:
{
- ConvertEUCToUnicode(fromstr,tostr);
+ ConvertEUCToUnicode(theFromStr, theToStr);
break;
}
- case Resource_GB :
+ case Resource_FormatType_GB:
{
- ConvertGBToUnicode(fromstr,tostr);
+ ConvertGBToUnicode(theFromStr, theToStr);
break;
}
- case Resource_ANSI :
+ case Resource_FormatType_ANSI:
+ case Resource_FormatType_UTF8:
{
- ConvertANSIToUnicode(fromstr,tostr);
+ theToStr = TCollection_ExtendedString (theFromStr, theFormat == Resource_FormatType_UTF8);
+ break;
+ }
+ case Resource_FormatType_SystemLocale:
+ {
+ NCollection_Utf16String aString;
+ aString.FromLocale (theFromStr);
+ theToStr = TCollection_ExtendedString (aString.ToCString());
break;
}
}
}
-Standard_Boolean Resource_Unicode::ConvertUnicodeToFormat(const TCollection_ExtendedString& fromstr,
- Standard_PCharacter& tostr,
- const Standard_Integer maxsize)
+Standard_Boolean Resource_Unicode::ConvertUnicodeToFormat(const Resource_FormatType theFormat,
+ const TCollection_ExtendedString& theFromStr,
+ Standard_PCharacter& theToStr,
+ const Standard_Integer theMaxSize)
{
- Resource_FormatType theform = Resource_Unicode::GetFormat();
- switch (theform) {
- case Resource_SJIS :
+ switch (theFormat)
+ {
+ case Resource_FormatType_SJIS:
{
- return ConvertUnicodeToSJIS(fromstr,tostr,maxsize);
+ return ConvertUnicodeToSJIS (theFromStr, theToStr, theMaxSize);
}
- case Resource_EUC :
+ case Resource_FormatType_EUC:
{
- return ConvertUnicodeToEUC(fromstr,tostr,maxsize);
+ return ConvertUnicodeToEUC (theFromStr, theToStr, theMaxSize);
}
- case Resource_GB :
+ case Resource_FormatType_GB:
{
- return ConvertUnicodeToGB(fromstr,tostr,maxsize);
+ return ConvertUnicodeToGB (theFromStr, theToStr, theMaxSize);
}
- case Resource_ANSI :
+ case Resource_FormatType_ANSI:
{
- return ConvertUnicodeToANSI(fromstr,tostr,maxsize);
+ return ConvertUnicodeToANSI (theFromStr, theToStr, theMaxSize);
+ }
+ case Resource_FormatType_UTF8:
+ {
+ if (theMaxSize < theFromStr.LengthOfCString())
+ {
+ return Standard_False;
+ }
+ theFromStr.ToUTF8CString (theToStr);
+ return Standard_True;
+ }
+ case Resource_FormatType_SystemLocale:
+ {
+ const NCollection_Utf16String aString (theFromStr.ToExtString());
+ return aString.ToLocale (theToStr, theMaxSize);
}
}
return Standard_False;
}
-
//! in Resource Manager "CharSet"
Standard_EXPORT static void ReadFormat();
- //! Converts the non-ASCII C string fromstr to the
- //! Unicode string of extended characters tostr.
- //! fromstr is translated according to the format
- //! (either ANSI, EUC, GB or SJIS) returned by the function GetFormat.
- Standard_EXPORT static void ConvertFormatToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
+ //! Converts the non-ASCII C string (as specified by GetFormat()) to the Unicode string of extended characters.
+ static void ConvertFormatToUnicode (const Standard_CString theFromStr,
+ TCollection_ExtendedString& theToStr)
+ {
+ return ConvertFormatToUnicode (Resource_Unicode::GetFormat(), theFromStr, theToStr);
+ }
+
+ //! Converts the non-ASCII C string in specified format to the Unicode string of extended characters.
+ //! @param theFormat [in] source encoding
+ //! @param theFromStr [in] text to convert
+ //! @param theToStr [out] destination string
+ Standard_EXPORT static void ConvertFormatToUnicode (const Resource_FormatType theFormat,
+ const Standard_CString theFromStr,
+ TCollection_ExtendedString& theToStr);
+
+ //! Converts the Unicode string of extended characters to the non-ASCII string according to specified format.
+ //! You need more than twice the length of the source string to complete the conversion.
+ //! The function returns true if conversion is complete, i.e. the maximum number of characters is not reached before the end of conversion.
+ //! @param theFormat [in] destination encoding
+ //! @param theFromStr [in] text to convert
+ //! @param theToStr [out] destination buffer
+ //! @param theMaxSize [in] destination buffer length
+ Standard_EXPORT static Standard_Boolean ConvertUnicodeToFormat (const Resource_FormatType theFormat,
+ const TCollection_ExtendedString& theFromStr,
+ Standard_PCharacter& theToStr,
+ const Standard_Integer theMaxSize);
+
+ //! Converts the Unicode string of extended characters to the non-ASCII string according to the format returned by the function GetFormat.
+ //! @param theFromStr [in] text to convert
+ //! @param theToStr [out] destination buffer
+ //! @param theMaxSize [in] destination buffer length
+ static Standard_Boolean ConvertUnicodeToFormat (const TCollection_ExtendedString& theFromStr,
+ Standard_PCharacter& theToStr,
+ const Standard_Integer theMaxSize)
+ {
+ return ConvertUnicodeToFormat (Resource_Unicode::GetFormat(), theFromStr, theToStr, theMaxSize);
+ }
- //! Converts the Unicode string of extended
- //! characters fromstr to the non-ASCII C string
- //! tostr according to the format (either ANSI, EUC,
- //! GB or SJIS) returned by the function GetFormat.
- //! maxsize limits the size of the string tostr to a
- //! maximum number of characters. You need more
- //! than twice the length of the string fromstr to
- //! complete the conversion.
- //! The function returns true if conversion is
- //! complete, i.e. the maximum number of characters
- //! maxsize is not reached by tostr before the end
- //! of conversion of fromstr.
- Standard_EXPORT static Standard_Boolean ConvertUnicodeToFormat (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
-
-
-
-
-protected:
-
-
-
-
-
-private:
-
-
-
-
-
};
-
-
-
-
-
-
#endif // _Resource_Unicode_HeaderFile
Interface_Static::Init ("stepcaf", "read.stepcaf.subshapes.name", '&', "eval On"); // 1
Interface_Static::SetIVal("read.stepcaf.subshapes.name", 0); // Disabled by default
+ // STEP file encoding for names translation
+ // Note: the numbers should be consistent with Resource_FormatType enumeration
+ Interface_Static::Init ("step", "read.stepcaf.codepage", 'e', "");
+ Interface_Static::Init ("step", "read.stepcaf.codepage", '&', "enum 0");
+ Interface_Static::Init ("step", "read.stepcaf.codepage", '&', "eval SJIS"); // Resource_FormatType_SJIS
+ Interface_Static::Init ("step", "read.stepcaf.codepage", '&', "eval EUC"); // Resource_FormatType_EUC
+ Interface_Static::Init ("step", "read.stepcaf.codepage", '&', "eval ANSI"); // Resource_FormatType_ANSI
+ Interface_Static::Init ("step", "read.stepcaf.codepage", '&', "eval GB"); // Resource_FormatType_GB
+ Interface_Static::Init ("step", "read.stepcaf.codepage", '&', "eval UTF8"); // Resource_FormatType_UTF8
+ Interface_Static::Init ("step", "read.stepcaf.codepage", '&', "eval SystemLocale"); // Resource_FormatType_SystemLocale
+ Interface_Static::SetCVal ("read.stepcaf.codepage", "UTF8");
+
return Standard_True;
}
#include <Transfer_ActorOfTransientProcess.hxx>
#include <Bnd_Box.hxx>
#include <BRepBndLib.hxx>
+#include <Resource_Unicode.hxx>
// skl 21.08.2003 for reading G&DT
//#include <StepRepr_CompoundItemDefinition.hxx>
//purpose :
//=======================================================================
-STEPCAFControl_Reader::STEPCAFControl_Reader() :
+STEPCAFControl_Reader::STEPCAFControl_Reader()
+: mySourceCodePage (Resource_FormatType_UTF8),
myColorMode(Standard_True),
myNameMode(Standard_True),
myLayerMode(Standard_True),
myViewMode(Standard_True)
{
STEPCAFControl_Controller::Init();
+ mySourceCodePage = (Resource_FormatType )Interface_Static::IVal ("read.stepcaf.codepage");
}
//=======================================================================
STEPCAFControl_Reader::STEPCAFControl_Reader(const Handle(XSControl_WorkSession)& WS,
- const Standard_Boolean scratch) :
+ const Standard_Boolean scratch)
+: mySourceCodePage (Resource_FormatType_UTF8),
myColorMode(Standard_True),
myNameMode(Standard_True),
myLayerMode(Standard_True),
myViewMode(Standard_True)
{
STEPCAFControl_Controller::Init();
+ mySourceCodePage = (Resource_FormatType )Interface_Static::IVal ("read.stepcaf.codepage");
Init(WS, scratch);
}
myFiles.Clear();
}
+//=======================================================================
+//function : convertName
+//purpose :
+//=======================================================================
+TCollection_ExtendedString STEPCAFControl_Reader::convertName (const TCollection_AsciiString& theName) const
+{
+ TCollection_ExtendedString aName;
+ Resource_Unicode::ConvertFormatToUnicode (mySourceCodePage, theName.ToCString(), aName);
+ return aName;
+}
//=======================================================================
//function : ReadFile
// find proper label
L = FindInstance(NAUO, STool, Tool, ShapeLabelMap);
if (L.IsNull()) continue;
- TCollection_ExtendedString str(name->String());
+
+ TCollection_ExtendedString str = convertName (name->String());
TDataStd_Name::Set(L, str);
}
name = new TCollection_HAsciiString;
L = GetLabelFromPD(PD, STool, TP, PDFileMap, ShapeLabelMap);
if (L.IsNull()) continue;
- TCollection_ExtendedString str(name->String());
+ TCollection_ExtendedString str = convertName (name->String());
TDataStd_Name::Set(L, str);
}
// set a name to the document
- //TCollection_ExtendedString str ( name->String() );
+ //TCollection_ExtendedString str = convertName (name->String());
//TDataStd_Name::Set ( L, str );
}
#ifndef _STEPCAFControl_Reader_HeaderFile
#define _STEPCAFControl_Reader_HeaderFile
-#include <Standard.hxx>
-#include <Standard_DefineAlloc.hxx>
-#include <Standard_Handle.hxx>
-
+#include <Resource_FormatType.hxx>
#include <STEPControl_Reader.hxx>
-#include <Standard_Boolean.hxx>
#include <IFSelect_ReturnStatus.hxx>
-#include <Standard_CString.hxx>
-#include <Standard_Integer.hxx>
#include <TDF_LabelSequence.hxx>
#include <TopTools_MapOfShape.hxx>
#include <STEPCAFControl_DataMapOfShapePD.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <XCAFDimTolObjects_DatumModifiersSequence.hxx>
#include <XCAFDimTolObjects_DatumModifWithValue.hxx>
+
class XSControl_WorkSession;
class TDocStd_Document;
class TCollection_AsciiString;
Standard_EXPORT void SetNameMode (const Standard_Boolean namemode);
Standard_EXPORT Standard_Boolean GetNameMode() const;
-
+
+ //! Return the encoding of STEP file for converting names into UNICODE.
+ //! Initialized from "read.stepcaf.codepage" variable by constructor, which is Resource_UTF8 by default.
+ Resource_FormatType SourceCodePage() const { return mySourceCodePage; }
+
+ //! Return the encoding of STEP file for converting names into UNICODE.
+ void SetSourceCodePage (Resource_FormatType theCode) { mySourceCodePage = theCode; }
+
//! Set LayerMode for indicate read Layers or not.
Standard_EXPORT void SetLayerMode (const Standard_Boolean layermode);
//! are skipped.
Standard_EXPORT void ExpandShell (const Handle(StepShape_ConnectedFaceSet)& theShell, TDF_Label& theLab, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
-
-
+ //! Convert name into UNICODE text.
+ Standard_EXPORT virtual TCollection_ExtendedString convertName (const TCollection_AsciiString& theName) const;
private:
STEPControl_Reader myReader;
NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles;
+ Resource_FormatType mySourceCodePage;
Standard_Boolean myColorMode;
Standard_Boolean myNameMode;
Standard_Boolean myLayerMode;
};
-
-
-
-
-
-
#endif // _STEPCAFControl_Reader_HeaderFile
static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if ( argc <3 ) {
- di << "Use: " << argv[0] << " Doc filename [mode]: read STEP file to a document\n";
- return 0;
- }
-
DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller());
if (ctl.IsNull()) XSDRAW::SetNorm("STEP");
+ Standard_CString aDocName = NULL;
+ TCollection_AsciiString aFilePath, aModeStr;
+ for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
+ {
+ TCollection_AsciiString anArgCase (argv[anArgIter]);
+ anArgCase.LowerCase();
+ if (aDocName == NULL)
+ {
+ aDocName = argv[anArgIter];
+ }
+ else if (aFilePath.IsEmpty())
+ {
+ aFilePath = argv[anArgIter];
+ }
+ else if (aModeStr.IsEmpty())
+ {
+ aModeStr = argv[anArgIter];
+ }
+ else
+ {
+ std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
+ return 1;
+ }
+ }
+
TCollection_AsciiString fnom, rnom;
- Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "STEP", fnom, rnom);
+ Standard_Boolean modfic = XSDRAW::FileAndVar (aFilePath.ToCString(), aDocName, "STEP", fnom, rnom);
if (modfic) di << " File STEP to read : " << fnom.ToCString() << "\n";
else di << " Model taken from the session : " << fnom.ToCString() << "\n";
// di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom<<"\n";
STEPCAFControl_Reader reader ( XSDRAW::Session(),modfic);
-
- if (argc == 4) {
+ if (!aModeStr.IsEmpty())
+ {
Standard_Boolean mode = Standard_True;
- for ( Standard_Integer i = 0; argv[3][i] ; i++ )
- switch (argv[3][i]) {
- case '-' : mode = Standard_False; break;
- case '+' : mode = Standard_True; break;
- case 'c' : reader.SetColorMode (mode); break;
- case 'n' : reader.SetNameMode (mode); break;
- case 'l' : reader.SetLayerMode (mode); break;
- case 'v' : reader.SetPropsMode (mode); break;
+ for (Standard_Integer i = 1; aModeStr.Value (i); ++i)
+ {
+ switch (aModeStr.Value (i))
+ {
+ case '-' : mode = Standard_False; break;
+ case '+' : mode = Standard_True; break;
+ case 'c' : reader.SetColorMode (mode); break;
+ case 'n' : reader.SetNameMode (mode); break;
+ case 'l' : reader.SetLayerMode (mode); break;
+ case 'v' : reader.SetPropsMode (mode); break;
+ default:
+ {
+ std::cout << "Syntax error at '" << aModeStr << "'\n";
+ return 1;
+ }
}
+ }
}
IFSelect_ReturnStatus readstat = IFSelect_RetVoid;
}
Handle(TDocStd_Document) doc;
- if (!DDocStd::GetDocument(argv[1],doc,Standard_False)) {
+ if (!DDocStd::GetDocument (aDocName, doc, Standard_False))
+ {
Handle(TDocStd_Application) A = DDocStd::GetApplication();
- A->NewDocument("BinXCAF",doc);
- TDataStd_Name::Set(doc->GetData()->Root(),argv[1]);
- Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
- Draw::Set(argv[1],DD);
-// di << "Document saved with name " << argv[1];
+ A->NewDocument("BinXCAF",doc);
+ TDataStd_Name::Set(doc->GetData()->Root(), aDocName);
+ Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
+ Draw::Set (aDocName, DD);
+// di << "Document saved with name " << aDocName;
}
if ( ! reader.Transfer ( doc ) ) {
di << "Cannot read any relevant data from the STEP file\n";
return 1;
}
- Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
- Draw::Set(argv[1],DD);
- di << "Document saved with name " << argv[1];
+ Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
+ Draw::Set (aDocName, DD);
+ di << "Document saved with name " << aDocName;
NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> DicFile = reader.ExternFiles();
FillDicWS( DicFile );
AddWS ( fnom , XSDRAW::Session() );
-
+
return 0;
}
di.Add("ReadIges" , "Doc filename: Read IGES file to DECAF document" ,__FILE__, ReadIges, g);
di.Add("WriteIges" , "Doc filename: Write DECAF document to IGES file" ,__FILE__, WriteIges, g);
- di.Add("ReadStep" , "Doc filename: Read STEP file to DECAF document" ,__FILE__, ReadStep, g);
+ di.Add("ReadStep" ,
+ "Doc filename [mode]"
+ "\n\t\t: Read STEP file to a document.",
+ __FILE__, ReadStep, g);
di.Add("WriteStep" , "Doc filename [mode=a [multifile_prefix] [label]]: Write DECAF document to STEP file" ,__FILE__, WriteStep, g);
di.Add("XFileList","Print list of files that was transfered by the last transfer" ,__FILE__, GetDicWSList , g);
set BugNumber OCC23251
-ReadStep D [locate_data_file OCC23251-dm1-oc-214.stp] res
+ReadStep D [locate_data_file OCC23251-dm1-oc-214.stp]
pload DCAF
-ReadStep D [locate_data_file OCC23251-dm1-oc-214.stp] res
+ReadStep D [locate_data_file OCC23251-dm1-oc-214.stp]
set dump_info [ XDumpDF D ]
--- /dev/null
+puts "================"
+puts "0030694: Data Exchange - support non-standard GB2312-encoded STEP files"
+puts ""
+puts "Test case:"
+puts "1) Creates a temporary STEP file-template using WriteStep."
+puts "2) Reads generated template and replaces @tmp_name@ entity in it with Simplified Chinese characters using Tcl."
+puts "3) Generates 2 STEP files in UTF-8 and GB2312 encodings (converted by Tcl)."
+puts "4) Reads generated files using StepRead and validates entity name."
+puts "================"
+puts ""
+
+proc fileToString { thePath } {
+ set aFile [open "$thePath" r]
+ set aText [read $aFile [file size "$thePath"]]
+ close $aFile
+ return $aText
+}
+
+proc fileFromString { thePath theContent theCodePage } {
+ set aFile [open "$thePath" w]
+ fconfigure $aFile -translation lf -encoding "$theCodePage"
+ puts $aFile $theContent
+ close $aFile
+}
+
+pload XDE OCAF MODELING VISUALIZATION
+set aTmpNameTmpl "@tmp_name@"
+set aTmpFileTmpl "${imagedir}/${casename}-tmp.stp"
+set aTmpFileUtf8 "${imagedir}/${casename}-tmp-utf8.stp"
+set aTmpFileGb "${imagedir}/${casename}-tmp-gb.stp"
+# 国标
+set aName [encoding convertfrom unicode "\xFD\x56\x07\x68"]
+box b 1 2 3
+catch { Close A }
+catch { Close T }
+catch { Close U }
+catch { Close G }
+XNewDoc T
+XAddShape T b 0
+XSetColor T b 1 0 0
+SetName T 0:1:1:1 "$aTmpNameTmpl"
+GetName T 0:1:1:1
+WriteStep T "$aTmpFileTmpl"
+
+regsub -all -- $aTmpNameTmpl [fileToString "$aTmpFileTmpl"] "$aName" aContent
+fileFromString "$aTmpFileUtf8" "$aContent" "utf-8"
+fileFromString "$aTmpFileGb" "$aContent" "gb2312"
+
+param read.stepcaf.codepage UTF8
+ReadStep U "$aTmpFileUtf8"
+ReadStep A "$aTmpFileGb"
+param read.stepcaf.codepage GB
+ReadStep G "$aTmpFileGb"
+
+if { [GetName U 0:1:1:1] != "$aName" } { puts "Error: unable to read UTF-8 STEP" }
+if { [GetName G 0:1:1:1] != "$aName" } { puts "Error: unable to read gb2312 STEP" }
+if { [GetName A 0:1:1:1] == "$aName" } { puts "Error: broken test case" }