1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0031382: Data Exchange - BinXCAF should preserve length unit information

Possibility for adding LengthUnit info to XCAF document using special class XCAFDoc_LenghtUnit and XCAFDoc_LenghtUnitTool is implemented.
Package UnitsMethods is split: geom methods were placed to new file GeomConvert_Units which is in the toolkit TKXSBase, internal step scale factors was placed to StepData.
Updated UnitMethods to convert scale factor to different unit types.
Now, XSAlgo::XSAlgo_AlgoContainer is used to update unit info from static interface values.
New Draw command "XSetLengthUnit" and "XGetLengthUnit" for set or get XDE attribute.
Upgraded tests for STEP, IGES, OBJ, glTF, VRML formats to check area regressing with used unit.
Upgraded tests\de test cases to use any units in the "loop back" algorithms.
This commit is contained in:
dpasukhi
2020-11-10 07:52:30 +03:00
committed by bugmaster
parent 9592ae247b
commit da80ff68f1
106 changed files with 2258 additions and 662 deletions

View File

@@ -74,6 +74,8 @@
#include <VrmlData_ShapeConvert.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWIGES.hxx>
#include <XSDRAWSTEP.hxx>
@@ -179,7 +181,6 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
{
TCollection_AsciiString aDestName, aFilePath;
Standard_Boolean toUseExistingDoc = Standard_False;
Standard_Real aSystemUnitFactor = UnitsMethods::GetCasCadeLengthUnit() * 0.001;
Standard_Boolean toListExternalFiles = Standard_False;
Standard_Boolean isParallel = Standard_False;
Standard_Boolean isDoublePrec = Standard_False;
@@ -306,9 +307,14 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
return 1;
}
}
Standard_Real aScaleFactorM = 1.;
if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter))
{
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
}
RWGltf_CafReader aReader;
aReader.SetSystemLengthUnit (aSystemUnitFactor);
aReader.SetSystemLengthUnit (aScaleFactorM);
aReader.SetSystemCoordinateSystem (RWMesh_CoordinateSystem_Zup);
aReader.SetDocument (aDoc);
aReader.SetParallel (isParallel);
@@ -504,8 +510,12 @@ static Standard_Integer WriteGltf (Draw_Interpretor& theDI,
TCollection_AsciiString anExt = aGltfFilePath;
anExt.LowerCase();
const Standard_Real aSystemUnitFactor = UnitsMethods::GetCasCadeLengthUnit() * 0.001;
Standard_Real aScaleFactorM = 1.;
if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter))
{
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
}
RWGltf_CafWriter aWriter (aGltfFilePath, anExt.EndsWith (".glb"));
aWriter.SetTransformationFormat (aTrsfFormat);
@@ -515,7 +525,7 @@ static Standard_Integer WriteGltf (Draw_Interpretor& theDI,
aWriter.SetToEmbedTexturesInGlb (toEmbedTexturesInGlb);
aWriter.SetMergeFaces (toMergeFaces);
aWriter.SetSplitIndices16 (toSplitIndices16);
aWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit (aSystemUnitFactor);
aWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit (aScaleFactorM);
aWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem (aSystemCoordSys);
aWriter.Perform (aDoc, aFileInfo, aProgress->Start());
return 0;
@@ -742,10 +752,16 @@ static Standard_Integer ReadObj (Draw_Interpretor& theDI,
return 1;
}
}
Standard_Real aScaleFactorM = 1.;
if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter))
{
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
}
RWObj_CafReader aReader;
aReader.SetSinglePrecision (isSinglePrecision);
aReader.SetSystemLengthUnit (UnitsMethods::GetCasCadeLengthUnit() * 0.001);
aReader.SetSystemLengthUnit (aScaleFactorM);
aReader.SetSystemCoordinateSystem (aResultCoordSys);
aReader.SetFileLengthUnit (aFileUnitFactor);
aReader.SetFileCoordinateSystem (aFileCoordSys);
@@ -982,8 +998,8 @@ static Standard_Integer loadvrml
}
VrmlData_Scene aScene;
Standard_Real anOCCUnit = UnitsMethods::GetCasCadeLengthUnit();
aScene.SetLinearScale(1000. / anOCCUnit);
Standard_Real anOCCUnitMM = UnitsMethods::GetCasCadeLengthUnit();
aScene.SetLinearScale(1000. / anOCCUnitMM);
aScene.SetVrmlDir (aVrmlDir);
aScene << aStream;