XCAFDoc_DocumentTool::SetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter) doesn't work

Hello,

I need to change the default units(mm) of STEP/IGES/BREP into m. But it did not work. The version of OCC is 7.6. The following is my code.

TopoDS_Shape shape = TopoDS_Shape();
Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF");
IGESCAFControl_Reader aReader;
Handle(XSControl_WorkSession) WS = aReader.WS();
XSControl_Reader XS;
XS.SetWS(WS);
Interface_Static::SetIVal("read.iges.ideas", 1);
Interface_Static::SetIVal("read.iges.nonmanifold", 1);
IFSelect_ReturnStatus stat = aReader.ReadFile(filename.ToCString());
switch (stat) {
    case IFSelect_RetVoid: {
        return false;
    }
    case IFSelect_RetDone: {
        break;
    }
    case IFSelect_RetError: {
        return false;
    }
    case IFSelect_RetFail: {
        return false;
    }
    default: {
        return false;
    }
}
aReader.SetReadVisible(Standard_True);
aReader.PrintCheckLoad(Standard_True, IFSelect_GeneralInfo);
//XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
if (!aReader.Transfer(aDoc)) {
    return false;
}
aReader.PrintCheckTransfer(Standard_True, IFSelect_GeneralInfo);
XS.TransferRoots();
shape = XS.OneShape();
GProp_GProps aProps;
BRepGProp::VolumeProperties(shape, aProps);
Standard_Real aVolume = aProps.Mass();
cout << "aVolume 1: " << aVolume << endl;
BRepGProp::SurfaceProperties(shape, aProps, 0.001);
Standard_Real anArea = aProps.Mass();
cout << "anArea 1: " << anArea << endl;

Handle(IGESData_IGESModel) aModel = Handle(IGESData_IGESModel)::DownCast(XS.Model());
Standard_Real aScaleFactorM;
if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter)) {
    XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
    aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit();
    // Sets length unit to the document
    XCAFDoc_DocumentTool::SetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter);
}
aModel->ChangeGlobalSection().SetCascadeUnit(aScaleFactorM);
XS.TransferRoots();
int num = XS.NbShapes();
if (num <= 0) {
    return false;
}
cout << "aScaleFactorM: " << aScaleFactorM << endl;

shape = XS.OneShape();
GProp_GProps aProps2;
BRepGProp::VolumeProperties(shape, aProps2);
Standard_Real aVolume2 = aProps2.Mass();
cout << "aVolume 2: " << aVolume2 << endl;
BRepGProp::SurfaceProperties(shape, aProps2, 0.001);
Standard_Real anArea2 = aProps2.Mass();
cout << "anArea 2: " << anArea2 << endl;
li hanming's picture

The result of aVolume and anArea are all the same with units change.
Please help!