Salome HOME
Fix compilation error (conflict of OK name between OCCT Plate_Plate.hxx and GEOM...
[modules/geom.git] / src / STEPPlugin / STEPPlugin_ExportDriver.cxx
index 8f5f0db18ca296283bd5fe79cb4015af3fcb97df..fa7492ea1a13dcea85cadcf5802f3c4227e3779c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2014-2024  CEA, EDF, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // internal includes
 #include "STEPPlugin_ExportDriver.hxx"
 #include "STEPPlugin_IExport.hxx"
+#include "STEPPlugin_IOperations.hxx"
 
 // KERNEL includes
 #include <utilities.h>
 #include <Basics_Utils.hxx>
+#include <Basics_OCCTVersion.hxx>
 
 // GEOM includes
 #include "GEOM_Function.hxx"
@@ -31,6 +33,8 @@
 // OOCT includes
 #include <IFSelect_ReturnStatus.hxx>
 #include <STEPControl_Writer.hxx>
+#include <StepData_StepModel.hxx>
+#include <UnitsMethods.hxx>
 #include <Interface_Static.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TopoDS_Shape.hxx>
@@ -57,7 +61,7 @@ STEPPlugin_ExportDriver::STEPPlugin_ExportDriver()
 //function : Execute
 //purpose  :
 //=======================================================================
-Standard_Integer STEPPlugin_ExportDriver::Execute( TFunction_Logbook& log ) const
+Standard_Integer STEPPlugin_ExportDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
 {
   if (Label().IsNull()) return 0;
   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
@@ -74,6 +78,43 @@ Standard_Integer STEPPlugin_ExportDriver::Execute( TFunction_Logbook& log ) cons
   aFunction->SetValue( aShape );
 
   TCollection_AsciiString aFileName = aData.GetFileName();
+  Standard_Integer        anUnit    = aData.GetUnit();
+  TCollection_AsciiString aWriteUnit;
+
+  switch (anUnit) {
+  case STEPPlugin_IOperations::LengthUnit_Inch:
+    aWriteUnit = "INCH";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Millimeter:
+    aWriteUnit = "MM";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Foot:
+    aWriteUnit = "FT";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Mile:
+    aWriteUnit = "MI";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Meter:
+    aWriteUnit = "M";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Kilometer:
+    aWriteUnit = "KM";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Milliinch:
+    aWriteUnit = "MIL";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Micrometer:
+    aWriteUnit = "UM";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Centimeter:
+    aWriteUnit = "CM";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Microinch:
+    aWriteUnit = "UIN";
+    break;
+  default:
+    return 0;
+  }
 
   MESSAGE("Export STEP into file " << aFileName.ToCString());
 
@@ -82,14 +123,30 @@ Standard_Integer STEPPlugin_ExportDriver::Execute( TFunction_Logbook& log ) cons
     // Set "C" numeric locale to save numbers correctly
     Kernel_Utils::Localizer loc;
 
-    IFSelect_ReturnStatus status ;
-    //VRV: OCC 4.0 migration
+#if OCC_VERSION_LARGE < 0x07070000
+    STEPControl_Writer aWriter;
+    Interface_Static::SetCVal("xstep.cascade.unit","M");
+    Interface_Static::SetCVal("write.step.unit", aWriteUnit.ToCString());
+    Interface_Static::SetIVal("write.step.nonmanifold", 1);
+#elif OCC_VERSION_LARGE < 0x07080000
+    STEPControl_Writer aWriterTmp;
+    Interface_Static::SetCVal("xstep.cascade.unit","M");
+    Interface_Static::SetCVal("write.step.unit", aWriteUnit.ToCString());
+    Interface_Static::SetIVal("write.step.nonmanifold", 1);
+    STEPControl_Writer aWriter;
+#else
     STEPControl_Writer aWriter;
     Interface_Static::SetCVal("xstep.cascade.unit","M");
-    Interface_Static::SetCVal("write.step.unit", "M");
+    Interface_Static::SetCVal("write.step.unit", aWriteUnit.ToCString());
     Interface_Static::SetIVal("write.step.nonmanifold", 1);
-    status = aWriter.Transfer( aShape, STEPControl_AsIs );
-    //VRV: OCC 4.0 migration
+    Handle(StepData_StepModel) aModel = aWriter.Model();
+    aModel->InternalParameters.InitFromStatic();
+    Standard_Integer aWriteUnitInt = Interface_Static::IVal("write.step.unit");
+    Standard_Real aWriteUnitReal = UnitsMethods::GetLengthFactorValue(aWriteUnitInt);
+    aModel->SetWriteLengthUnit(aWriteUnitReal);
+#endif
+
+    IFSelect_ReturnStatus status = aWriter.Transfer( aShape, STEPControl_AsIs );
     if( status == IFSelect_RetDone )
       status = aWriter.Write( aFileName.ToCString() );
 
@@ -97,33 +154,23 @@ Standard_Integer STEPPlugin_ExportDriver::Execute( TFunction_Logbook& log ) cons
     if( status == IFSelect_RetDone )
       return 1;
   }
-  catch (Standard_Failure)
+  catch (Standard_Failure&)
   {
-      //THROW_SALOME_CORBA_EXCEPTION("Exception catched in STEPExport", SALOME::BAD_PARAM);
+    //THROW_SALOME_CORBA_EXCEPTION("Exception caught in STEPExport", SALOME::BAD_PARAM);
   }
   return 0;
 }
 
-//=======================================================================
-//function : MustExecute
-//purpose  :
-//=======================================================================
-Standard_Boolean STEPPlugin_ExportDriver::MustExecute( const TFunction_Logbook& ) const
-{
-  return Standard_True;
-}
-
 //================================================================================
 /*!
  * \brief Returns a name of creation operation and names and values of creation parameters
  */
 //================================================================================
 bool STEPPlugin_ExportDriver::
-GetCreationInformation( std::string&             theOperationName,
-                        std::vector<GEOM_Param>& theParams )
+GetCreationInformation( std::string&             /*theOperationName*/,
+                        std::vector<GEOM_Param>& /*theParams*/ )
 {
   return false;
 }
 
-IMPLEMENT_STANDARD_HANDLE( STEPPlugin_ExportDriver,GEOM_BaseDriver );
-IMPLEMENT_STANDARD_RTTIEXT( STEPPlugin_ExportDriver,GEOM_BaseDriver );
+IMPLEMENT_STANDARD_RTTIEXT( STEPPlugin_ExportDriver,GEOM_BaseDriver )