From ae9f4b64cacf0df612944b3694a3bdfa5f1f29cf Mon Sep 17 00:00:00 2001 From: abv Date: Wed, 14 Oct 2020 09:14:04 +0300 Subject: [PATCH] 0031851: Data Exchange, STEP - enable Unicode symbols in STEP export Class STEPCAFControl_Writer is corrected to avoid replacing non-Ascii symbols by question marks, and spaces by underscores, on export to STEP. Related: DRAW commands dealing with strings in OCAF documents are corrected to pass Unicode symbols as UTF-8. Off-topic: code saving names of external STEP files in XDE and fetching them back is corrected to preserve Unicode symbols as UTF-8. Added test bugs xde bug31851 Test de step_4 E7 corrected (no more replacement of spaces by underscores in names of layers) --- src/DDF/DDF_Browser.cxx | 4 +-- src/DDataStd/DDataStd_BasicCommands.cxx | 28 ++++++++------------ src/DDataStd/DDataStd_NameCommands.cxx | 2 +- src/DDataStd/DDataStd_TreeBrowser.cxx | 6 ++--- src/DDocStd/DDocStd_ApplicationCommands.cxx | 28 +++++--------------- src/DDocStd/DDocStd_DocumentCommands.cxx | 2 +- src/DDocStd/DDocStd_MTMCommands.cxx | 9 +++---- src/STEPCAFControl/STEPCAFControl_Writer.cxx | 7 +++-- src/XCAFDoc/XCAFDoc_ShapeTool.cxx | 2 +- src/XDEDRAW/XDEDRAW.cxx | 17 +++++------- src/XDEDRAW/XDEDRAW_Layers.cxx | 9 +++---- src/XDEDRAW/XDEDRAW_Props.cxx | 6 ++--- tests/bugs/xde/bug31851 | 19 +++++++++++++ tests/de/step_4/E7 | 2 +- 14 files changed, 62 insertions(+), 79 deletions(-) create mode 100644 tests/bugs/xde/bug31851 diff --git a/src/DDF/DDF_Browser.cxx b/src/DDF/DDF_Browser.cxx index 6d7ddb1b59..d9ee57b68a 100644 --- a/src/DDF/DDF_Browser.cxx +++ b/src/DDF/DDF_Browser.cxx @@ -131,7 +131,7 @@ TCollection_AsciiString DDF_Browser::OpenRoot() const list.AssignCat("\""); if (root.FindAttribute(TDataStd_Name::GetID(),name)) { - TCollection_AsciiString tmpStr(name->Get(),'?'); + TCollection_AsciiString tmpStr(name->Get()); tmpStr.ChangeAll(' ','_'); list.AssignCat(tmpStr); } @@ -178,7 +178,7 @@ TCollection_AsciiString DDF_Browser::OpenLabel(const TDF_Label& aLab) const list.AssignCat("\""); if (itr.Value().FindAttribute(TDataStd_Name::GetID(),name)) { - TCollection_AsciiString tmpStr(name->Get(),'?'); + TCollection_AsciiString tmpStr(name->Get()); tmpStr.ChangeAll(' ','_'); list.AssignCat(tmpStr); } diff --git a/src/DDataStd/DDataStd_BasicCommands.cxx b/src/DDataStd/DDataStd_BasicCommands.cxx index 69476a3797..6816f6a587 100644 --- a/src/DDataStd/DDataStd_BasicCommands.cxx +++ b/src/DDataStd/DDataStd_BasicCommands.cxx @@ -342,8 +342,7 @@ static Standard_Integer DDataStd_GetComment (Draw_Interpretor& di, if (!DDF::GetDF(arg[1],DF)) return 1; Handle(TDataStd_Comment) A; if (!DDF::Find(DF,arg[2],TDataStd_Comment::GetID(),A)) return 1; - TCollection_AsciiString s(A->Get(),'?'); - di << A->Get().ToExtString(); + di << A->Get(); return 0; } di << "DDataStd_GetComment : Error\n"; @@ -1298,8 +1297,7 @@ static Standard_Integer DDataStd_GetExtStringArray (Draw_Interpretor& di, } for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){ - TCollection_AsciiString anAsciiString(A->Value(i),'?'); - di << anAsciiString.ToCString(); + di << A->Value(i); if(iUpper()) di<<" "; } @@ -3411,9 +3409,8 @@ static Standard_Integer DDataStd_GetNDIntegers (Draw_Interpretor& di, TColStd_DataMapIteratorOfDataMapOfStringInteger itr(aMap); for (; itr.More(); itr.Next()){ TCollection_ExtendedString aKey(itr.Key()); - TCollection_AsciiString aStr(aKey,'?'); Standard_Integer aValue = itr.Value(); - di << "Key = " << aStr.ToCString() << " Value = " << aValue << "\n"; + di << "Key = " << aKey << " Value = " << aValue << "\n"; } return 0; @@ -3529,9 +3526,8 @@ static Standard_Integer DDataStd_GetNDReals (Draw_Interpretor& di, TDataStd_DataMapIteratorOfDataMapOfStringReal itr(aMap); for (; itr.More(); itr.Next()){ TCollection_ExtendedString aKey(itr.Key()); - TCollection_AsciiString aStr(aKey,'?'); Standard_Real aValue = itr.Value(); - di << "Key = " << aStr.ToCString() << " Value = " << aValue << "\n"; + di << "Key = " << aKey << " Value = " << aValue << "\n"; } return 0; } @@ -3704,7 +3700,7 @@ static Standard_Integer DDataStd_GetNDString (Draw_Interpretor& di, } else { - TCollection_AsciiString aValue (anAtt->GetString(arg[3]), '?'); + TCollection_AsciiString aValue (anAtt->GetString(arg[3])); std::cout << "Key = " << arg[3] << " Value = " << aValue.ToCString() << std::endl; if(nb == 5) Draw::Set(arg[4], aValue.ToCString()); @@ -3782,12 +3778,12 @@ static Standard_Integer DDataStd_GetNDBytes (Draw_Interpretor& di, anAtt->LoadDeferredData(); const TDataStd_DataMapOfStringByte& aMap = anAtt->GetBytesContainer(); TDataStd_DataMapIteratorOfDataMapOfStringByte itr(aMap); - for (; itr.More(); itr.Next()){ + for (; itr.More(); itr.Next()) + { TCollection_ExtendedString aKey(itr.Key()); - TCollection_AsciiString aStr(aKey,'?'); Standard_Byte aValue = itr.Value(); - std::cout << "Key = " << aStr.ToCString() << " Value = " <Label().FindAttribute(TDataStd_Name::GetID(),name)) { - TCollection_AsciiString tmpStr(name->Get(),'?'); - tmpStr.ChangeAll(' ','_'); - aList.AssignCat(tmpStr); + aList.AssignCat(name->Get()); } aList.AssignCat("\""); // Dynamic type. -2 aList.AssignCat(TDF_BrowserSeparator2); TCollection_ExtendedString ext; if (TDF::ProgIDFromGUID(aTreeNode->ID(), ext)) - aList.AssignCat(TCollection_AsciiString(ext,'?')); + aList.AssignCat(ext); else aList.AssignCat(aTreeNode->DynamicType()->Name()); // Executable or Forgotten? -3 // aList.AssignCat(TDF_BrowserSeparator2); diff --git a/src/DDocStd/DDocStd_ApplicationCommands.cxx b/src/DDocStd/DDocStd_ApplicationCommands.cxx index a60867c9bc..0e0291b057 100644 --- a/src/DDocStd/DDocStd_ApplicationCommands.cxx +++ b/src/DDocStd/DDocStd_ApplicationCommands.cxx @@ -65,12 +65,8 @@ static Standard_Integer DDocStd_ListDocuments (Draw_Interpretor& di, A->GetDocument(i,D); di <<"document " << i; if (D->IsSaved()) { - TCollection_AsciiString GetNameAsciiString(D->GetName().ToExtString(),'?'); - TCollection_AsciiString GetPathAsciiString(D->GetPath().ToExtString(),'?'); - //std::cout << " name : " << D->GetName(); - //std::cout << " path : " << D->GetPath(); - di << " name : " << GetNameAsciiString.ToCString(); - di << " path : " << GetPathAsciiString.ToCString(); + di << " name : " << D->GetName(); + di << " path : " << D->GetPath(); } else di << " not saved"; di << "\n"; @@ -428,18 +424,10 @@ static Standard_Integer DDocStd_Path (Draw_Interpretor& di, { if (nb == 2) { TDocStd_PathParser path (a[1]); - //std::cout << "Trek : " << path.Trek() << std::endl; - //std::cout << "Name : " << path.Name() << std::endl; - //std::cout << "Extension : " << path.Extension() << std::endl; - //std::cout << "Path : " << path.Path() << std::endl; - TCollection_AsciiString TrekAsciiString(path.Trek().ToExtString(),'?'); - TCollection_AsciiString NameAsciiString(path.Name().ToExtString(),'?'); - TCollection_AsciiString ExtensionAsciiString(path.Extension().ToExtString(),'?'); - TCollection_AsciiString PathAsciiString(path.Path().ToExtString(),'?'); - di << "Trek : " << TrekAsciiString.ToCString() << "\n"; - di << "Name : " << NameAsciiString.ToCString() << "\n"; - di << "Extension : " << ExtensionAsciiString.ToCString() << "\n"; - di << "Path : " << PathAsciiString.ToCString() << "\n"; + di << "Trek : " << path.Trek() << "\n"; + di << "Name : " << path.Name() << "\n"; + di << "Extension : " << path.Extension() << "\n"; + di << "Path : " << path.Path() << "\n"; return 0; } di << "DDocStd_Path : Error\n"; @@ -484,9 +472,7 @@ static Standard_Integer DDocStd_PrintComments (Draw_Interpretor& di, for (int i = 1; i <= comments.Length(); i++) { - //std::cout << comments(i) << std::endl; - TCollection_AsciiString commentAsciiString(comments(i).ToExtString(),'?'); - di << commentAsciiString.ToCString() << "\n"; + di << comments(i) << "\n"; } return 0; diff --git a/src/DDocStd/DDocStd_DocumentCommands.cxx b/src/DDocStd/DDocStd_DocumentCommands.cxx index 4e16dc7332..078df02299 100644 --- a/src/DDocStd/DDocStd_DocumentCommands.cxx +++ b/src/DDocStd/DDocStd_DocumentCommands.cxx @@ -311,7 +311,7 @@ static Standard_Integer DDocStd_DumpDocument (Draw_Interpretor& di, di << "\n"; // document name if (D->IsSaved()) - di << "DOCUMENT : " << TCollection_AsciiString(D->GetName(),'?').ToCString(); + di << "DOCUMENT : " << D->GetName(); else di << "DOCUMENT : not saved"; di << "\n"; diff --git a/src/DDocStd/DDocStd_MTMCommands.cxx b/src/DDocStd/DDocStd_MTMCommands.cxx index 9703ba8a2a..03b56a0ec8 100644 --- a/src/DDocStd/DDocStd_MTMCommands.cxx +++ b/src/DDocStd/DDocStd_MTMCommands.cxx @@ -266,20 +266,17 @@ static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) { Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att ); - TCollection_AsciiString str ( val->Get(), '?' ); - di << str.ToCString(); + di << val->Get(); } else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) { Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att ); - TCollection_AsciiString str ( val->Get(), '?' ); - di << str.ToCString(); + di << val->Get(); } else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) { Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att ); - TCollection_AsciiString str ( val->Get(), '?' ); - di << str.ToCString(); + di << val->Get(); } else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) { diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index 1625c4ac53..a988be2806 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -258,11 +258,10 @@ static Standard_Boolean GetLabelName (const TDF_Label &L, Handle(TCollection_HAs TCollection_ExtendedString name = N->Get(); if ( name.Length() <=0 ) return Standard_False; - // set name, converting it to Ascii and removing spaces - TCollection_AsciiString buf ( name, '?' ); + // set name, removing spaces around it + TCollection_AsciiString buf(name); buf.LeftAdjust(); buf.RightAdjust(); - buf.ChangeAll(' ','_'); str->AssignCat ( buf.ToCString() ); return Standard_True; } @@ -2385,7 +2384,7 @@ Handle(StepRepr_ShapeAspect) STEPCAFControl_Writer::WriteShapeAspect (const Hand Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(); Handle(TDataStd_Name) aNameAttr; if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) { - aName = new TCollection_HAsciiString(TCollection_AsciiString(aNameAttr->Get(), '?')); + aName = new TCollection_HAsciiString(TCollection_AsciiString(aNameAttr->Get())); Standard_Integer aFirstSpace = aName->Search(" "); if (aFirstSpace != -1) aName = aName->SubString(aFirstSpace + 1, aName->Length()); diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx index 5cade76b76..2bc4807259 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx @@ -1416,7 +1416,7 @@ void XCAFDoc_ShapeTool::GetExternRefs(const TDF_Label& L, if(tmplbl.FindAttribute(TDataStd_Name::GetID(),TDN)) { TCollection_ExtendedString extstr = TDN->Get(); Handle(TCollection_HAsciiString) str = - new TCollection_HAsciiString(TCollection_AsciiString(extstr, '?')); + new TCollection_HAsciiString(TCollection_AsciiString(extstr)); SHAS.Append(str); } } diff --git a/src/XDEDRAW/XDEDRAW.cxx b/src/XDEDRAW/XDEDRAW.cxx index 9a230840fd..7f577ce167 100644 --- a/src/XDEDRAW/XDEDRAW.cxx +++ b/src/XDEDRAW/XDEDRAW.cxx @@ -287,8 +287,7 @@ static void StatAssembly(const TDF_Label L, if(L.FindAttribute(TDataStd_Name::GetID(), Name)) { NbShapesWithName++; if(PrintStructMode) { - TCollection_AsciiString AsciiStringName(Name->Get(),'?'); - di<<" "<Get() << " has attributes: "; } } else { @@ -359,7 +358,7 @@ static void StatAssembly(const TDF_Label L, if(PrintStructMode) { di<<"Layer("; for(Standard_Integer i=1; i<=aLayerS->Length(); i++) { - TCollection_AsciiString Entry2(aLayerS->Value(i),'?'); + TCollection_AsciiString Entry2(aLayerS->Value(i)); if(i==1) di<<"\""<GetLayer(aLabel, layerName); - TCollection_AsciiString Entry(layerName,'?'); - di<<"\""<IsKind(STANDARD_TYPE(TDataStd_Name)) ) { Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att ); - TCollection_AsciiString str ( val->Get(), '?' ); - di << str.ToCString(); + di << val->Get(); } else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) { Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att ); - TCollection_AsciiString str ( val->Get(), '?' ); - di << str.ToCString(); + di << val->Get(); } else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) { Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att ); - TCollection_AsciiString str ( val->Get(), '?' ); - di << str.ToCString(); + di << val->Get(); } else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) { Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att ); diff --git a/src/XDEDRAW/XDEDRAW_Layers.cxx b/src/XDEDRAW/XDEDRAW_Layers.cxx index 14afe28804..ac308f8b65 100644 --- a/src/XDEDRAW/XDEDRAW_Layers.cxx +++ b/src/XDEDRAW/XDEDRAW_Layers.cxx @@ -150,8 +150,7 @@ static Standard_Integer getLayers (Draw_Interpretor& di, Standard_Integer argc, Standard_Integer i = 1; if (!aLayerS.IsNull() && aLayerS->Length()!=0) for (; i <= aLayerS->Length(); i++) { - TCollection_AsciiString Entry(aLayerS->Value(i),'?'); - di << "\"" << Entry.ToCString() << "\" "; + di << "\"" << aLayerS->Value(i) << "\" "; } return 0; } @@ -200,8 +199,7 @@ static Standard_Integer getOneLayer (Draw_Interpretor& di, Standard_Integer argc if ( !aLabel.IsNull() ) { TCollection_ExtendedString layerName; localLayerTool->GetLayer(aLabel, layerName); - TCollection_AsciiString Entry(layerName,'?'); - di << "\"" << Entry.ToCString() <<"\""; + di << "\"" << layerName <<"\""; } return 0; } @@ -260,8 +258,7 @@ static Standard_Integer getAllLayers (Draw_Interpretor& di, Standard_Integer arg TDF_Label L = aLabs.Value(i); if ( !L.IsNull() ) { localLayerTool->GetLayer(L, layerName); - TCollection_AsciiString Entry(layerName,'?'); - di << "\"" << Entry.ToCString() <<"\""; + di << "\"" << layerName <<"\""; di << " "; } } diff --git a/src/XDEDRAW/XDEDRAW_Props.cxx b/src/XDEDRAW/XDEDRAW_Props.cxx index dcb270c575..859bef8fd2 100644 --- a/src/XDEDRAW/XDEDRAW_Props.cxx +++ b/src/XDEDRAW/XDEDRAW_Props.cxx @@ -546,8 +546,7 @@ static Standard_Integer CheckProps (Draw_Interpretor& di, Standard_Integer argc, di << string1; Handle(TDataStd_Name) N; if ( aLabel.FindAttribute ( TDataStd_Name::GetID(), N ) && ! wholeDoc ) { - TCollection_AsciiString name(N->Get(), '?'); - di << " \"" << name.ToCString() << "\""; + di << " \"" << N->Get() << "\""; } if ( ! wholeDoc ) di << "\n"; @@ -676,8 +675,7 @@ static Standard_Integer CheckProps (Draw_Interpretor& di, Standard_Integer argc, if ( wholeDoc ) { if ( ! N.IsNull() ) { - TCollection_AsciiString name(N->Get(),'?'); - di << " \"" << name.ToCString() << "\""; + di << " \"" << N->Get() << "\""; } di << "\n"; } diff --git a/tests/bugs/xde/bug31851 b/tests/bugs/xde/bug31851 new file mode 100644 index 0000000000..2c2bd582df --- /dev/null +++ b/tests/bugs/xde/bug31851 @@ -0,0 +1,19 @@ +puts "# ==============================================================================" +puts "# 0031851: Data Exchange, STEP - enable Unicode symbols in STEP export" +puts "# ==============================================================================" + +pload OCAF XDE MODELING + +puts "# Generate XDE document with a solid having name encoded in Japanese" +set name "\u30DC\u30C3\u30AF\u30B9" ;# "box" +box box 10 10 10 +NewDocument D XCAF +SetName D [XAddShape D box] $name + +WriteStep D $imagedir/${casename}.stp +ReadStep T $imagedir/${casename}.stp + +set result [GetName T 0:1:1:1] +if { $result != $name } { + puts "Error: name has been lost on conversion" +} diff --git a/tests/de/step_4/E7 b/tests/de/step_4/E7 index 9b456fa899..a2d51b255c 100644 --- a/tests/de/step_4/E7 +++ b/tests/de/step_4/E7 @@ -13,6 +13,6 @@ PROPS : Centroid = 0 ( 0 ) Volume = 0 ( 0 ) Area = 0 ( 0 ) NCOLORS : NColors = 15 ( 15 ) COLORS : Colors = CYAN4 DARKOLIVEGREEN1 DARKSLATEGRAY1 GAINSBORO LIGHTSLATEBLUE MATRAGRAY MEDIUMSPRINGGREEN PURPLE PURPLE SKYBLUE1 SKYBLUE1 SPRINGGREEN2 SPRINGGREEN4 STEELBLUE VIOLET ( CYAN4 DARKOLIVEGREEN1 DARKSLATEGRAY1 GAINSBORO LIGHTSLATEBLUE MATRAGRAY MEDIUMSPRINGGREEN PURPLE PURPLE SKYBLUE1 SKYBLUE1 SPRINGGREEN2 SPRINGGREEN4 STEELBLUE VIOLET ) NLAYERS : NLayers = 17 ( 17 ) -LAYERS : Layers = 072498_01A|MODEL 072498_01B|MODEL 082399_02|Model 082399_03|MODEL 082399_04A|MODEL 082399_04B|MODEL 082399_05|MODEL 082399_06|MODEL 082399_07|MODEL 082499_03|MODEL 082599_02|Model 082599_03A|Model 082599_03B|Model 082699_01|MODEL LE_Diode|Model Optics_Housing|MODEL Phototransistor|Model ( 072498_01A|MODEL 072498_01B|MODEL 082399_02|Model 082399_03|MODEL 082399_04A|MODEL 082399_04B|MODEL 082399_05|MODEL 082399_06|MODEL 082399_07|MODEL 082499_03|MODEL 082599_02|Model 082599_03A|Model 082599_03B|Model 082699_01|MODEL {LE Diode|Model} {Optics Housing|MODEL} Phototransistor|Model ) +LAYERS : Layers = 072498_01A|MODEL 072498_01B|MODEL 082399_02|Model 082399_03|MODEL 082399_04A|MODEL 082399_04B|MODEL 082399_05|MODEL 082399_06|MODEL 082399_07|MODEL 082499_03|MODEL 082599_02|Model 082599_03A|Model 082599_03B|Model 082699_01|MODEL {LE Diode|Model} {Optics Housing|MODEL} Phototransistor|Model ( 072498_01A|MODEL 072498_01B|MODEL 082399_02|Model 082399_03|MODEL 082399_04A|MODEL 082399_04B|MODEL 082399_05|MODEL 082399_06|MODEL 082399_07|MODEL 082499_03|MODEL 082599_02|Model 082599_03A|Model 082599_03B|Model 082699_01|MODEL {LE Diode|Model} {Optics Housing|MODEL} Phototransistor|Model ) } -- 2.20.1