]> OCCT Git - occt.git/commitdiff
0033813: Data Exchange - Implementing common logic for scaling during Write procedure
authoranv <anv@opencascade.com>
Wed, 28 Aug 2024 03:23:16 +0000 (04:23 +0100)
committerdpasukhi <dpasukhi@opencascade.com>
Thu, 26 Sep 2024 11:28:15 +0000 (11:28 +0000)
Implementation of common logic for OCCT formats.

24 files changed:
src/DE/DE_ConfigurationNode.hxx
src/DE/DE_Wrapper.cxx
src/DEBRepCascade/DEBRepCascade_Provider.cxx
src/DEXCAFCascade/DEXCAFCascade_Provider.cxx
src/IGESCAFControl/IGESCAFControl_ConfigurationNode.cxx
src/IGESCAFControl/IGESCAFControl_ConfigurationNode.hxx
src/IGESCAFControl/IGESCAFControl_Provider.cxx
src/IGESCAFControl/IGESCAFControl_Writer.cxx
src/IGESCAFControl/IGESCAFControl_Writer.hxx
src/IGESData/IGESData_BasicEditor.cxx
src/IGESData/IGESData_BasicEditor.hxx
src/RWGltf/RWGltf_Provider.cxx
src/RWObj/RWObj_Provider.cxx
src/RWPly/RWPly_Provider.cxx
src/RWStl/RWStl_Provider.cxx
src/STEPCAFControl/STEPCAFControl_Provider.cxx
src/Vrml/Vrml_Provider.cxx
tests/de_wrapper/configuration/A3
tests/de_wrapper/configuration/A4
tests/de_wrapper/gltf/A6
tests/de_wrapper/iges/A6
tests/de_wrapper/obj/A6
tests/de_wrapper/step/A6
tests/de_wrapper/vrml/A6

index 45b653338f10cfabc6eb8ce2802b218aa697e48a..d424dc92fa2f4340dc8b058db3d753754c4b5cf2 100644 (file)
@@ -154,7 +154,8 @@ public:
   //!< 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:
index 7a9531d490c8934df1877560dd37843cbc687f05..54ced338db7accff1c06270ee5448a512e4c901c 100644 (file)
@@ -290,6 +290,7 @@ Standard_Boolean DE_Wrapper::Load(const Handle(DE_ConfigurationContext)& theReso
                                   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);
@@ -372,8 +373,10 @@ TCollection_AsciiString DE_Wrapper::Save(const Standard_Boolean theIsRecursive,
     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);
index 200540e35ed2d4dc4ce148b28e57343ee6444acb..6af321edc972916cd55d8502e8c6deffa3641346 100644 (file)
@@ -110,6 +110,13 @@ bool DEBRepCascade_Provider::Write(const TCollection_AsciiString& thePath,
     return false;
   }
 
+  Handle(DEBRepCascade_ConfigurationNode) aNode = Handle(DEBRepCascade_ConfigurationNode)::DownCast(GetNode());
+  if (aNode->GlobalParameters.LengthUnit != 1.0)
+  {
+    Message::SendWarning() << "Warning in the DEBRepCascade_Provider during writing the file " <<
+      thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling";
+  }
+
   if (aLabels.Length() == 1)
   {
     aShape = aSTool->GetShape(aLabels.Value(1));
@@ -223,6 +230,11 @@ bool DEBRepCascade_Provider::Write(const TCollection_AsciiString& thePath,
     return false;
   }
   Handle(DEBRepCascade_ConfigurationNode) aNode = Handle(DEBRepCascade_ConfigurationNode)::DownCast(GetNode());
+  if (aNode->GlobalParameters.LengthUnit != 1.0)
+  {
+    Message::SendWarning() << "Warning in the DEBRepCascade_Provider during writing the file " <<
+      thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling";
+  }
   if (aNode->InternalParameters.WriteBinary)
   {
     if (aNode->InternalParameters.WriteVersionBin > static_cast<BinTools_FormatVersion>(BinTools_FormatVersion_UPPER) ||
index cef6ceb014f02ecfd669a96313436c24e4916247..6b8908580c2ae6b7d52116e29a14b760c842ee3f 100644 (file)
@@ -145,6 +145,14 @@ bool DEXCAFCascade_Provider::Write(const TCollection_AsciiString& thePath,
 {
   Handle(TDocStd_Application) anApp = new TDocStd_Application();
   BinXCAFDrivers::DefineFormat(anApp);
+
+  Handle(DEXCAFCascade_ConfigurationNode) aNode = Handle(DEXCAFCascade_ConfigurationNode)::DownCast(GetNode());
+  if (aNode->GlobalParameters.LengthUnit != 1.0)
+  {
+    Message::SendWarning() << "Warning in the DEXCAFCascade_Provider during writing the file " <<
+      thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling";
+  }
+
   PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull;
   if (!thePath.IsEmpty())
   {
index dff11a3de1496a346159c049e2503629c0370b2e..3a4217e703ad3bfbd8a59bde3c7f639e1354470a 100644 (file)
@@ -96,8 +96,6 @@ bool IGESCAFControl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext
     theResource->IntegerVal("write.brep.mode", InternalParameters.WriteBRepMode, aScope);
   InternalParameters.WriteConvertSurfaceMode = (WriteMode_ConvertSurface)
     theResource->IntegerVal("write.convertsurface.mode", InternalParameters.WriteConvertSurfaceMode, aScope);
-  InternalParameters.WriteUnit = (UnitsMethods_LengthUnit)
-    theResource->IntegerVal("write.unit", InternalParameters.WriteUnit, aScope);
   InternalParameters.WriteHeaderAuthor =
     theResource->StringVal("write.header.author", InternalParameters.WriteHeaderAuthor, aScope);
   InternalParameters.WriteHeaderCompany =
@@ -272,14 +270,6 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const
   aResult += aScope + "write.convertsurface.mode :\t " + InternalParameters.WriteConvertSurfaceMode + "\n";
   aResult += "!\n";
 
-  aResult += "!\n";
-  aResult += "!Allows choosing the unit. The default unit for Open CASCADE Technology is \"MM\" (millimeter).";
-  aResult += "You can choose to write a file into any unit accepted by IGES\n";
-  aResult += "!Default value: MM(2). Available values: \"INCH\"(1), \"MM\"(2), \"??\"(3), \"FT\"(4), \"MI\"(5), ";
-  aResult += "\"M\"(6), \"KM\"(7), \"MIL\"(8), \"UM\"(9), \"CM\"(10), \"UIN\"(11)\n";
-  aResult += aScope + "write.unit :\t " + InternalParameters.WriteUnit + "\n";
-  aResult += "!\n";
-
   aResult += "!\n";
   aResult += "!Gives the name of the author of the file\n";
   aResult += "!Default value: {System name of the user}. Available values: <string>\n";
index c3eafca60ba8e94b6e8fd5a50be64cc139ecc4cc..7549e13238f0f84c00e5eb7a695827c8acf4cf93 100644 (file)
@@ -157,7 +157,6 @@ public:
     // Write
     WriteMode_BRep WriteBRepMode = WriteMode_BRep_Faces; //<! Flag to define entities type to write
     WriteMode_ConvertSurface WriteConvertSurfaceMode = WriteMode_ConvertSurface_Off; //<! Flag to convert surface to elementary
-    UnitsMethods_LengthUnit WriteUnit = UnitsMethods_LengthUnit_Millimeter; //<! Define unit to write IGES file
     TCollection_AsciiString WriteHeaderAuthor; //<! Name of the author of the file
     TCollection_AsciiString WriteHeaderCompany; //<! Name of the sending company
     TCollection_AsciiString WriteHeaderProduct; //<! Name of the sending product
index d2ec791127090a8046cd29905e29a64cf24e5a2c..a766f73c99363e28bff0543c81b04cccac8f29df 100644 (file)
@@ -90,7 +90,6 @@ void IGESCAFControl_Provider::initStatic(const Handle(DE_ConfigurationNode)& the
 
   myOldValues.WriteBRepMode = (IGESCAFControl_ConfigurationNode::WriteMode_BRep)Interface_Static::IVal("write.iges.brep.mode");
   myOldValues.WriteConvertSurfaceMode = (IGESCAFControl_ConfigurationNode::WriteMode_ConvertSurface)Interface_Static::IVal("write.convertsurface.mode");
-  myOldValues.WriteUnit = (UnitsMethods_LengthUnit)Interface_Static::IVal("write.iges.unit");
   myOldValues.WriteHeaderAuthor = Interface_Static::CVal("write.iges.header.author");
   myOldValues.WriteHeaderCompany = Interface_Static::CVal("write.iges.header.company");
   myOldValues.WriteHeaderProduct = Interface_Static::CVal("write.iges.header.product");
@@ -135,7 +134,6 @@ void IGESCAFControl_Provider::setStatic(const IGESCAFControl_ConfigurationNode::
 
   Interface_Static::SetIVal("write.iges.brep.mode", theParameter.WriteBRepMode);
   Interface_Static::SetIVal("write.convertsurface.mode", theParameter.WriteConvertSurfaceMode);
-  Interface_Static::SetIVal("write.iges.unit", theParameter.WriteUnit);
   Interface_Static::SetCVal("write.iges.header.author", theParameter.WriteHeaderAuthor.ToCString());
   Interface_Static::SetCVal("write.iges.header.company", theParameter.WriteHeaderCompany.ToCString());
   Interface_Static::SetCVal("write.iges.header.product", theParameter.WriteHeaderProduct.ToCString());
@@ -232,8 +230,26 @@ bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
   Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
   personizeWS(theWS);
   initStatic(aNode);
-  XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter);
-  IGESCAFControl_Writer aWriter(theWS);
+  Standard_Integer aFlag = IGESData_BasicEditor::GetFlagByValue(aNode->GlobalParameters.LengthUnit);
+  IGESCAFControl_Writer aWriter(theWS, (aFlag > 0) ? IGESData_BasicEditor::UnitFlagName(aFlag) : "MM");
+  IGESData_GlobalSection aGS = aWriter.Model()->GlobalSection();
+  Standard_Real aScaleFactorMM = 1.;
+  Standard_Boolean aHasUnits = XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter);
+  if (aHasUnits)
+  {
+    aGS.SetCascadeUnit(aScaleFactorMM);
+  }
+  else
+  {
+    aGS.SetCascadeUnit(aNode->GlobalParameters.SystemUnit);
+    Message::SendWarning() << "Warning in the IGESCAFControl_Provider during writing the file " <<
+      thePath << "\t: The document has no information on Units. Using global parameter as initial Unit.";
+  }
+  if (aFlag == 0)
+  {
+    aGS.SetScale(aNode->GlobalParameters.LengthUnit);
+  }
+  aWriter.Model()->SetGlobalSection(aGS);
   aWriter.SetColorMode(aNode->InternalParameters.WriteColor);
   aWriter.SetNameMode(aNode->InternalParameters.WriteName);
   aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer);
@@ -342,10 +358,16 @@ bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
   }
   Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
   initStatic(aNode);
-  TCollection_AsciiString aUnit(UnitsMethods::DumpLengthUnit(aNode->InternalParameters.WriteUnit));
-  aUnit.UpperCase();
-  IGESControl_Writer aWriter(aUnit.ToCString(),
-                             aNode->InternalParameters.WriteBRepMode);
+  Standard_Integer aFlag = IGESData_BasicEditor::GetFlagByValue(aNode->GlobalParameters.LengthUnit);
+  IGESControl_Writer aWriter((aFlag > 0) ? IGESData_BasicEditor::UnitFlagName(aFlag) : "MM",
+    aNode->InternalParameters.WriteBRepMode);
+  IGESData_GlobalSection aGS = aWriter.Model()->GlobalSection();
+  aGS.SetCascadeUnit(aNode->GlobalParameters.SystemUnit);
+  if (!aFlag)
+  {
+    aGS.SetScale(aNode->GlobalParameters.LengthUnit);
+  }
+  aWriter.Model()->SetGlobalSection(aGS);
   Standard_Boolean aIsOk = aWriter.AddShape(theShape);
   if (!aIsOk)
   {
index 53059072c5a5ec1733674eda43d343f49a1dc452..70677b193e6c8c341b86905504afd603cc52a16a 100644 (file)
@@ -134,6 +134,23 @@ IGESCAFControl_Writer::IGESCAFControl_Writer (const Handle(XSControl_WorkSession
 //  SetWS (WS,scratch); // this should be the only required command here
 }
 
+//=======================================================================
+//function : IGESCAFControl_Writer
+//purpose  : 
+//=======================================================================
+
+IGESCAFControl_Writer::IGESCAFControl_Writer(const Handle(XSControl_WorkSession)& WS,
+                                             const Standard_CString theUnit)
+  :IGESControl_Writer(theUnit)
+{
+
+  WS->SetModel(Model());
+  WS->SetMapWriter(TransferProcess());
+  myColorMode = Standard_True;
+  myNameMode = Standard_True;
+  myLayerMode = Standard_True;
+}
+
 //=======================================================================
 //function : Transfer
 //purpose  : 
index 3e4a9e0b523d668b3d0a693fd19bf976b4a7db0d..56d6fe4a937082ec8e30bf44d607a0a78b12020d 100644 (file)
@@ -65,6 +65,11 @@ public:
   //! Creates a reader tool and attaches it to an already existing Session
   //! Clears the session if it was not yet set for IGES
   Standard_EXPORT IGESCAFControl_Writer(const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
+
+  //! Creates a reader tool and attaches it to an already existing Session
+  //! Clears the session if it was not yet set for IGES
+  //! Sets target Unit for the writing process.
+  Standard_EXPORT IGESCAFControl_Writer(const Handle(XSControl_WorkSession)& theWS, const Standard_CString theUnit);
   
   //! Transfers a document to a IGES model
   //! Returns True if translation is OK
index d7b7bebd15a123e3fa95294c4045b8bf0b5994c0..a4fc2787149c50e6680ada14cb461070952dd971 100644 (file)
@@ -92,17 +92,27 @@ void IGESData_BasicEditor::Init (const Handle(IGESData_IGESModel)& model, const
   //#73 rln 10.03.99 S4135: "read.scale.unit" does not affect GlobalSection
   //if (Interface_Static::IVal("read.scale.unit") == 1) vmm = vmm * 1000.;
 // vmm est exprime en MILLIMETRES
-  if (vmm >=      25.       && vmm <=      26.      ) return SetUnitFlag(1);
-  if (vmm >=       0.9      && vmm <=       1.1     ) return SetUnitFlag(2);
-  if (vmm >=     300.       && vmm <=     310.      ) return SetUnitFlag(4);
-  if (vmm >= 1600000.       && vmm <= 1620000.      ) return SetUnitFlag(5);
-  if (vmm >=     990.       && vmm <=    1010.      ) return SetUnitFlag(6);
-  if (vmm >=  990000.       && vmm <= 1010000.      ) return SetUnitFlag(7);
-  if (vmm >=       0.025    && vmm <=       0.026   ) return SetUnitFlag(8);
-  if (vmm >=       0.0009   && vmm <=       0.0011  ) return SetUnitFlag(9);
-  if (vmm >=       9.       && vmm <=      11.      ) return SetUnitFlag(10);
-  if (vmm >=       0.000025 && vmm <=       0.000026) return SetUnitFlag(11);
-  return Standard_False;
+  Standard_Integer aFlag = GetFlagByValue(vmm);
+  return (aFlag > 0) ? SetUnitFlag(aFlag) : Standard_False;
+}
+
+//=======================================================================
+//function : GetFlagByValue
+//purpose  : 
+//=======================================================================
+Standard_Integer IGESData_BasicEditor::GetFlagByValue(const Standard_Real theValue)
+{
+  if (theValue >= 25. && theValue <= 26.) return 1;
+  if (theValue >= 0.9 && theValue <= 1.1) return 2;
+  if (theValue >= 300. && theValue <= 310.) return 4;
+  if (theValue >= 1600000. && theValue <= 1620000.) return 5;
+  if (theValue >= 990. && theValue <= 1010.) return 6;
+  if (theValue >= 990000. && theValue <= 1010000.) return 7;
+  if (theValue >= 0.025 && theValue <= 0.026) return 8;
+  if (theValue >= 0.0009 && theValue <= 0.0011) return 9;
+  if (theValue >= 9. && theValue <= 11.) return 10;
+  if (theValue >= 0.000025 && theValue <= 0.000026) return 11;
+  return 0;
 }
 
 //=======================================================================
index 563b8c2b498363c7ef65d83d9d8c5fedd279f234..dbf7384bcbbac2364b6881892d60b40092651147 100644 (file)
@@ -131,6 +131,10 @@ public:
   //! Returns the maximum allowed value for Drafting Flag
   Standard_EXPORT static Standard_Integer DraftingMax();
 
+  //! Returns Flag corresponding to the scaling theValue.
+  //! Returns 0 if there's no such flag.
+  Standard_EXPORT static Standard_Integer GetFlagByValue(const Standard_Real theValue);
+
 
 
 
index 1331011aeb5ba336e82117c6d84275e23863dcf3..eeadfba355e58257e59a7e7bae5dd3b9d7a41ea7 100644 (file)
@@ -140,9 +140,20 @@ bool RWGltf_Provider::Write(const TCollection_AsciiString& thePath,
   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;
index 90435cbd2179b8d51605e879775e9d61805e9a10..aa6d9865207c62db4d250b4e6e663f5a93c2410e 100644 (file)
@@ -131,9 +131,19 @@ bool RWObj_Provider::Write(const TCollection_AsciiString& thePath,
   }
 
   RWMesh_CoordinateSystemConverter aConverter;
-  aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
+  Standard_Real aScaleFactorMM = 1.;
+  if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter))
+  {
+    aConverter.SetInputLengthUnit(aScaleFactorMM / 1000.);
+  }
+  else
+  {
+    aConverter.SetInputLengthUnit(aNode->GlobalParameters.SystemUnit / 1000.);
+    Message::SendWarning() << "Warning in the RWObj_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);
+  aConverter.SetOutputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000.);
   aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.FileCS);
 
   RWObj_CafWriter aWriter(thePath);
index 1f81de5bbc3f25604bb80f89f0fc9d81e747074f..bdabd37376e637373df0d647b2b43ef2989117b8 100644 (file)
@@ -89,9 +89,19 @@ bool RWPly_Provider::Write(const TCollection_AsciiString& thePath,
     aFileInfo.Add("Comments", aNode->InternalParameters.WriteComment);
   }
   RWMesh_CoordinateSystemConverter aConverter;
-  aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
+  Standard_Real aScaleFactorM = 1.;
+  if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorM))
+  {
+    aConverter.SetInputLengthUnit(aScaleFactorM);
+  }
+  else
+  {
+    aConverter.SetInputLengthUnit(aNode->GlobalParameters.SystemUnit / 1000.);
+    Message::SendWarning() << "Warning in the RWPly_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);
+  aConverter.SetOutputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000.);
   aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.FileCS);
 
   RWPly_CafWriter aPlyCtx(thePath);
index 8f862530b45877ed4a20464e2e0401f5163e8783..302c9b661dd4d4469e312512d8d11de4d32ae535 100644 (file)
@@ -110,6 +110,13 @@ bool RWStl_Provider::Write(const TCollection_AsciiString& thePath,
     return false;
   }
 
+  Handle(RWStl_ConfigurationNode) aNode = Handle(RWStl_ConfigurationNode)::DownCast(GetNode());
+  if (aNode->GlobalParameters.LengthUnit != 1.0)
+  {
+    Message::SendWarning() << "Warning in the RWStl_Provider during writing the file " <<
+      thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling";
+  }
+
   if (aLabels.Length() == 1)
   {
     aShape = aSTool->GetShape(aLabels.Value(1));
@@ -220,6 +227,11 @@ bool RWStl_Provider::Write(const TCollection_AsciiString& thePath,
     return false;
   }
   Handle(RWStl_ConfigurationNode) aNode = Handle(RWStl_ConfigurationNode)::DownCast(GetNode());
+  if (aNode->GlobalParameters.LengthUnit != 1.0)
+  {
+    Message::SendWarning() << "Warning in the RWStl_Provider during writing the file " <<
+      thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling";
+  }
 
   StlAPI_Writer aWriter;
   aWriter.ASCIIMode() = aNode->InternalParameters.WriteAscii;
index 969c54d220e114a3284907c359308210f97fe43d..354212e60cbd2d5982d211c9249ffb29e84fde34 100644 (file)
@@ -110,10 +110,6 @@ bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
     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);
@@ -124,9 +120,22 @@ bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
   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 " <<
@@ -242,9 +251,20 @@ bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
   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)
   {
index 005af99a69310d026753651b4d95a753c4c50dfa..39527456dc7d4837dfa66f479f06ab5a726d7e2d 100644 (file)
@@ -131,8 +131,19 @@ bool Vrml_Provider::Write(const TCollection_AsciiString& thePath,
 
   VrmlAPI_Writer aWriter;
   aWriter.SetRepresentation(static_cast<VrmlAPI_RepresentationOfShape>(aNode->InternalParameters.WriteRepresentationType));
-  Standard_Real aScaleFactorM = aNode->GlobalParameters.LengthUnit;
-  if (!aWriter.WriteDoc(theDocument, thePath.ToCString(), aScaleFactorM))
+  Standard_Real aScaling = 1.;
+  Standard_Real aScaleFactorMM = 1.;
+  if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter))
+  {
+    aScaling = aScaleFactorMM / aNode->GlobalParameters.LengthUnit;
+  }
+  else
+  {
+    aScaling = aNode->GlobalParameters.SystemUnit / aNode->GlobalParameters.LengthUnit;
+    Message::SendWarning() << "Warning in the Vrml_Provider during writing the file " <<
+      thePath << "\t: The document has no information on Units. Using global parameter as initial Unit.";
+  }
+  if (!aWriter.WriteDoc(theDocument, thePath.ToCString(), aScaling))
   {
     Message::SendFail() << "Error in the Vrml_Provider during wtiting the file " <<
       thePath << "\t: File was not written";
index 61f2db99ce62abb699ab06c102eaff9f3c9d7a95..babb2a3cfa181a823472e00109b9b942ca66f820 100644 (file)
@@ -15,6 +15,7 @@ global.priority.XCAF :   OCC
 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
index e760e2d5465757cece03cf484d0a97ffc62eb7f8..3fb307dd904e4b0101bf85581e9f2ab05a3e71e3 100644 (file)
@@ -15,6 +15,7 @@ global.priority.XCAF :   OCC
 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
index ea78ba1bf1b8cddca68670f1b05470f57576fa05..7ea6cfcdab2290f6917200ecc84a1943e9262768 100644 (file)
@@ -20,15 +20,7 @@ if [catch {ReadGltf D0 $filename} catch_result] {
 }
 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"
@@ -50,41 +42,49 @@ if [catch {readfile S3 $write_path} catch_result] {
     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"
@@ -96,7 +96,7 @@ if [catch {ReadFile D7 $write_path -conf "global.general.length.unit : 1000 "} c
 }
 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
index 8f8563f3a9012f315674a533aa79f2cbd7e96fad..d41ed02628da814546b8b49cb845511278437f62 100644 (file)
@@ -28,7 +28,7 @@ if [catch {ReadIges D1 $filename } catch_result] {
 }
 XGetOneShape S1 D1
 
-if [catch {WriteFile D0 $write_path -conf "provider.IGES.write.iges.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"
@@ -50,7 +50,7 @@ if [catch {readfile S3 $write_path} catch_result] {
     puts "OK : Reading is correct"
 }
 
-if [catch {WriteFile D1 $write_path -conf "provider.IGES.write.iges.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"
@@ -72,7 +72,7 @@ if [catch {readfile S5 $write_path} catch_result] {
     puts "OK : Reading is correct"
 }
 
-if [catch {WriteFile D0 $write_path -conf "provider.IGES.write.iges.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"
@@ -84,7 +84,7 @@ if [catch {ReadFile D6 $write_path -conf "global.general.length.unit : 1 "} catc
 }
 XGetOneShape S6 D6
 
-if [catch {writefile S1 $write_path -conf "provider.IGES.write.iges.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"
@@ -96,7 +96,7 @@ if [catch {ReadFile D7 $write_path -conf "global.general.length.unit : 0.0254 "}
 }
 XGetOneShape S7 D7
 
-array set areas {0 11995.4 1 0.0119954 2 47916.8 3 11979.2 4 0.0479168 5 0.0119792 6 47916.8 7 18.5678}
+array set areas {0 11995.4 1 0.0119954 2 11979.2 3 11979.2 4 11979.2 5 0.0119792 6 11979.2 7 18.5678}
 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
index 975a597efa4d23235a4ba34d7de2d0fcdb7f7a82..02f94f35c38337ca66c7f34e5e92b11fb9d3a51a 100644 (file)
@@ -28,12 +28,12 @@ if [catch {ReadObj D1 $filename -fileUnit mm } catch_result] {
 }
 XGetOneShape S1 D1
 
-if [catch {WriteFile D0 $write_path -conf "provider.OBJ.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"
 }
-if [catch {readfile S2 $write_path} catch_result] {
+if [catch {readfile S2 $write_path -conf "provider.OBJ.OCC.file.length.unit : 0.001 "} catch_result] {
     puts "Error : Problem with reading file"
 } else {
     puts "OK : Reading is correct"
@@ -44,18 +44,18 @@ if [catch {writefile S0 $write_path} catch_result] {
 } else {
     puts "OK : Writing is correct"
 }
-if [catch {readfile S3 $write_path} catch_result] {
+if [catch {readfile S3 $write_path  -conf "provider.OBJ.OCC.file.length.unit : 0.001 "} catch_result] {
     puts "Error : Problem with reading file"
 } else {
     puts "OK : Reading is correct"
 }
 
-if [catch {WriteFile D1 $write_path -conf "provider.OBJ.OCC.file.length.unit : 1 "} 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 S4 $write_path -conf "global.general.length.unit : 1000 "} catch_result] {
+if [catch {readfile S4 $write_path -conf "global.general.length.unit : 1000 \n provider.OBJ.OCC.file.length.unit : 1"} catch_result] {
     puts "Error : Problem with reading file"
 } else {
     puts "OK : Reading is correct"
@@ -66,13 +66,13 @@ if [catch {writefile S1 $write_path} catch_result] {
 } else {
     puts "OK : Writing is correct"
 }
-if [catch {readfile S5 $write_path} catch_result] {
+if [catch {readfile S5 $write_path -conf "provider.OBJ.OCC.file.length.unit : 0.001 "} 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 D0 $write_path -conf "global.general.length.unit : 1 "} catch_result] {
     puts "Error : Problem with writing file"
 } else {
     puts "OK : Writing is correct"
@@ -84,12 +84,12 @@ if [catch {ReadFile D6 $write_path -conf "global.general.length.unit : 1 "} catc
 }
 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 "} catch_result] {
     puts "Error : Problem with writing file"
 } else {
     puts "OK : Writing is correct"
 }
-if [catch {ReadFile D7 $write_path -conf "global.general.length.unit : 1000 "} catch_result] {
+if [catch {ReadFile D7 $write_path -conf "global.general.length.unit : 1000 \n provider.OBJ.OCC.file.length.unit : 1"} catch_result] {
     puts "Error : Problem with reading file"
 } else {
     puts "OK : Reading is correct"
index e7943453a5ee08faf008b63abff653d0ca51c83e..d74af7fef72832d27b1dc695b07b5d454e116582 100644 (file)
@@ -30,7 +30,7 @@ XGetOneShape S1 D1
 
 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"
@@ -41,7 +41,7 @@ if [catch {readfile S2 $write_path } catch_result] {
     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"
@@ -52,7 +52,7 @@ if [catch {readfile S3 $write_path} catch_result] {
     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"
@@ -74,7 +74,7 @@ if [catch {readfile S5 $write_path} catch_result] {
     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"
@@ -86,7 +86,7 @@ if [catch {ReadFile D6 $write_path -conf "global.general.length.unit : 1 "} catc
 }
 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"
@@ -98,7 +98,7 @@ if [catch {ReadFile D7 $write_path -conf "global.general.length.unit : 0.0254"}
 }
 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
index 449b313526703aac02c247992c8fad433e006df1..38501aa6fa24252f0bd4057bc5b5c6ca4ed60372 100644 (file)
@@ -98,7 +98,7 @@ if [catch {ReadFile D7 $write_path -conf "provider.VRML.OCC.read.file.unit : 0.0
 }
 XGetOneShape S7 D7
 
-array set areas {0 5.3415e+06 1 5.3415 2 5.3415e+06 3 5.3415e+06 4 5.3415 5 5.3415 6 5.3415e+06 7 5.3415e-06}
+array set areas {0 5.3415e+06 1 5.3415 2 5.3415e+06 3 5.3415e+06 4 5.3415e+06 5 5.3415 6 5.3415e+06 7 5.3415e-06}
 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