Implementation for Gltf and STEP formats.
//!< Internal parameters for transfer process
struct DE_SectionGlobal
{
- Standard_Real LengthUnit = 1.0; //!< Scale length unit value from MM, default 1.0 (MM)
+ Standard_Real LengthUnit = 1.0; //!< Target Unit (scaling based on MM) for the transfer process, default 1.0 (MM)
+ Standard_Real SystemUnit = 1.0; //!< System Unit (scaling based on MM) to be used when initial unit is unknown, default 1.0 (MM)
} GlobalParameters;
private:
const Standard_Boolean theIsRecursive)
{
GlobalParameters.LengthUnit = theResource->RealVal("general.length.unit", GlobalParameters.LengthUnit, THE_CONFIGURATION_SCOPE());
+ GlobalParameters.SystemUnit = theResource->RealVal("general.system.unit", GlobalParameters.SystemUnit, THE_CONFIGURATION_SCOPE());
if (theIsRecursive)
{
for (DE_ConfigurationFormatMap::Iterator aFormatIter(myConfiguration);
aResult += "\n";
}
aResult += "!Global parameters. Used for all providers\n";
- aResult += "!Length scale unit value. Should be more the 0. Default value: 1.0(MM)\n";
+ aResult += "!Length scale unit value. Should be more than 0. Default value: 1.0(MM)\n";
aResult += THE_CONFIGURATION_SCOPE() + ".general.length.unit :\t " + GlobalParameters.LengthUnit + "\n";
+ aResult += "!System unit value. Should be more than 0. Default value: 1.0(MM)\n";
+ aResult += THE_CONFIGURATION_SCOPE() + ".general.system.unit :\t " + GlobalParameters.SystemUnit + "\n";
if (theIsRecursive)
{
for (DE_ConfigurationFormatMap::Iterator aFormatIter(myConfiguration);
Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode());
RWMesh_CoordinateSystemConverter aConverter;
- aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
+ Standard_Real aScaleFactorM = 1.;
+ if (!XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorM))
+ {
+ aConverter.SetInputLengthUnit(aNode->GlobalParameters.SystemUnit / 1000.);
+ Message::SendWarning() << "Warning in the RWGltf_Provider during writing the file " <<
+ thePath << "\t: The document has no information on Units. Using global parameter as initial Unit.";
+ }
aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS);
- aConverter.SetOutputLengthUnit(aNode->InternalParameters.FileLengthUnit);
+ if (aNode->GlobalParameters.LengthUnit != 1000.)
+ {
+ Message::SendWarning() << "Warning in the RWGltf_Provider during writing the file " <<
+ thePath << "\t: Target format doesn't support custom units. Model will be scaled to Meters";
+ }
+ aConverter.SetOutputLengthUnit(1.); // gltf units always Meters
aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.FileCS);
TColStd_IndexedDataMapOfStringString aFileInfo;
return false;
}
Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
-
- XCAFDoc_DocumentTool::SetLengthUnit(theDocument,
- UnitsMethods::GetLengthUnitScale(aNode->InternalParameters.WriteUnit,
- UnitsMethods_LengthUnit_Millimeter), UnitsMethods_LengthUnit_Millimeter);
personizeWS(theWS);
STEPCAFControl_Writer aWriter;
aWriter.Init(theWS);
aWriter.SetNameMode(aNode->InternalParameters.WriteName);
aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer);
aWriter.SetPropsMode(aNode->InternalParameters.WriteProps);
-
- TDF_Label aLabel;
StepData_ConfParameters aParams;
+ Standard_Real aScaleFactorMM = 1.;
+ if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter))
+ {
+ aModel->SetLocalLengthUnit(aScaleFactorMM);
+ }
+ else
+ {
+ aModel->SetLocalLengthUnit(aNode->GlobalParameters.SystemUnit);
+ Message::SendWarning() << "Warning in the STEPCAFControl_Provider during writing the file " <<
+ thePath << "\t: The document has no information on Units. Using global parameter as initial Unit.";
+ }
+ UnitsMethods_LengthUnit aTargetUnit = UnitsMethods::GetLengthUnitByFactorValue(aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter);
+ aParams.WriteUnit = aTargetUnit;
+ aModel->SetWriteLengthUnit(aNode->GlobalParameters.LengthUnit);
+ TDF_Label aLabel;
if (!aWriter.Transfer(theDocument, aParams, aMode, 0, theProgress))
{
Message::SendFail() << "Error in the STEPCAFControl_Provider during writing the file " <<
STEPControl_Writer aWriter;
aWriter.SetWS(theWS);
IFSelect_ReturnStatus aWritestat = IFSelect_RetVoid;
- Handle(StepData_StepModel) aModel = aWriter.Model();
- aModel->SetWriteLengthUnit(UnitsMethods::GetLengthUnitScale(aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter));
+ Handle(StepData_StepModel) aModel = aWriter.Model();;
StepData_ConfParameters aParams;
+ aModel->SetLocalLengthUnit(aNode->GlobalParameters.SystemUnit);
+ UnitsMethods_LengthUnit aTargetUnit = UnitsMethods::GetLengthUnitByFactorValue(aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter);
+ aParams.WriteUnit = aTargetUnit;
+ if (aTargetUnit == UnitsMethods_LengthUnit_Undefined)
+ {
+ aModel->SetWriteLengthUnit(1.0);
+ Message::SendWarning() << "Custom units are not supported by STEP format, but LengthUnit global parameter doesn't fit any predefined unit. Units will be scaled to Millimeters";
+ }
+ else
+ {
+ aModel->SetWriteLengthUnit(aNode->GlobalParameters.LengthUnit);
+ }
aWritestat = aWriter.Transfer(theShape, aNode->InternalParameters.WriteModelType, aParams, true, theProgress);
if (aWritestat != IFSelect_RetDone)
{
global.priority.IGES : OCC
global.priority.PLY : OCC
global.general.length.unit : 1
+global.general.system.unit : 1
provider.STEP.OCC.read.iges.bspline.continuity : 1
provider.STEP.OCC.read.precision.mode : 0
provider.STEP.OCC.read.precision.val : 0.0001
global.priority.IGES : OCC
global.priority.PLY : OCC
global.general.length.unit : 1
+global.general.system.unit : 1
provider.STEP.OCC.read.iges.bspline.continuity : 1
provider.STEP.OCC.read.precision.mode : 0
provider.STEP.OCC.read.precision.val : 0.0001
}
XGetOneShape S0 D0
-param xstep.cascade.unit M
-if [catch {ReadGltf D1 $filename} catch_result] {
- puts "Error : Problem with reading file"
-} else {
- puts "OK : Reading is correct"
-}
-XGetOneShape S1 D1
-
-if [catch {WriteFile D0 $write_path -conf "provider.GLTF.OCC.file.length.unit : 0.001 "} catch_result] {
+if [catch {WriteFile D0 $write_path -conf "global.general.length.unit : 1 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
puts "OK : Reading is correct"
}
-if [catch {WriteFile D1 $write_path -conf "provider.GLTF.OCC.file.length.unit : 1 "} catch_result] {
+if [catch {WriteFile D0 $write_path -conf "global.general.length.unit : 1 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
-if [catch {readfile S4 $write_path -conf "global.general.length.unit : 1000 "} catch_result] {
+if [catch {ReadFile D6 $write_path -conf "global.general.length.unit : 1 "} catch_result] {
+ puts "Error : Problem with reading file"
+} else {
+ puts "OK : Reading is correct"
+}
+XGetOneShape S6 D6
+
+param xstep.cascade.unit M
+if [catch {ReadGltf D1 $filename} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
+XGetOneShape S1 D1
-if [catch {writefile S1 $write_path} catch_result] {
+if [catch {WriteFile D1 $write_path -conf "global.general.length.unit : 1000 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
-if [catch {readfile S5 $write_path} catch_result] {
+if [catch {readfile S4 $write_path -conf "global.general.length.unit : 1000 "} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
-if [catch {WriteFile D0 $write_path -conf "provider.GLTF.OCC.file.length.unit : 0.001 "} catch_result] {
+if [catch {writefile S1 $write_path -conf "global.general.system.unit : 1000 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
-if [catch {ReadFile D6 $write_path -conf "global.general.length.unit : 1 "} catch_result] {
+if [catch {readfile S5 $write_path} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
-XGetOneShape S6 D6
-if [catch {writefile S1 $write_path -conf "provider.GLTF.OCC.file.length.unit : 1 "} catch_result] {
+if [catch {writefile S1 $write_path -conf "global.general.length.unit : 1000 \n global.general.system.unit : 1000 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
XGetOneShape S7 D7
-array set areas {0 3.18785e+06 1 3.18785 2 3.18785e+06 3 3.18785e+06 4 3.18785 5 3.18785 6 3.18785e+06 7 3.18785e-06}
+array set areas {0 3.18785e+06 1 3.18785 2 3.18785e+06 3 3.18785e+06 4 3.18785 5 3.18785e+06 6 3.18785e+06 7 3.18785}
array set results {0 S0 1 S1 2 S2 3 S3 4 S4 5 S5 6 S6 7 S7}
for { set anind 0} { $anind < 8 } { incr anind } {
checkprops $results($anind) -s $areas($anind) -eps 1e-2
param xstep.cascade.unit MM
-if [catch {WriteFile D0 $write_path -conf "provider.STEP.write.step.unit : 1 "} catch_result] {
+if [catch {WriteFile D0 $write_path -conf "global.general.length.unit : 25.4 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
puts "OK : Reading is correct"
}
-if [catch {writefile S0 $write_path } catch_result] {
+if [catch {writefile S0 $write_path -conf "global.general.system.unit : 1 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
puts "OK : Reading is correct"
}
-if [catch {WriteFile D1 $write_path -conf "provider.STEP.write.step.unit : 6 "} catch_result] {
+if [catch {WriteFile D1 $write_path -conf "global.general.length.unit : 1000 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
puts "OK : Reading is correct"
}
-if [catch {WriteFile D0 $write_path -conf "provider.STEP.write.step.unit : 2 "} catch_result] {
+if [catch {WriteFile D0 $write_path -conf "global.general.length.unit : 1 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
XGetOneShape S6 D6
-if [catch {writefile S1 $write_path -conf "provider.STEP.write.step.unit : 1 "} catch_result] {
+if [catch {writefile S1 $write_path -conf "global.general.length.unit : 25.4 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
XGetOneShape S7 D7
-array set areas {0 2.52381e+06 1 2.52381 2 2.52381e+06 3 2.52381e+06 4 2.52381 5 2.52381 6 2.52381e+06 7 3911.92}
+array set areas {0 2.52381e+06 1 2.52381 2 2.52381e+06 3 2.52381e+06 4 2.52381e+06 5 2.52381 6 2.52381e+06 7 3911.92}
array set results {0 S0 1 S1 2 S2 3 S3 4 S4 5 S5 6 S6 7 S7}
for { set anind 0} { $anind < 8 } { incr anind } {
checkprops $results($anind) -s $areas($anind) -eps 1e-2