Salome HOME
0023351: [CEA 1955] Crash if filling has only one edge
[modules/geom.git] / src / STEPPlugin / STEPPlugin_ExportDriver.cxx
index 8f5f0db18ca296283bd5fe79cb4015af3fcb97df..c6bfe8580339a82f98f8f6fed457af4a48c878b0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2014-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,7 @@
 // internal includes
 #include "STEPPlugin_ExportDriver.hxx"
 #include "STEPPlugin_IExport.hxx"
+#include "STEPPlugin_IOperations.hxx"
 
 // KERNEL includes
 #include <utilities.h>
@@ -57,7 +58,7 @@ STEPPlugin_ExportDriver::STEPPlugin_ExportDriver()
 //function : Execute
 //purpose  :
 //=======================================================================
-Standard_Integer STEPPlugin_ExportDriver::Execute( TFunction_Logbook& log ) const
+Standard_Integer STEPPlugin_ExportDriver::Execute(LOGBOOK& log) const
 {
   if (Label().IsNull()) return 0;
   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
@@ -74,6 +75,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());
 
@@ -86,7 +124,7 @@ Standard_Integer STEPPlugin_ExportDriver::Execute( TFunction_Logbook& log ) cons
     //VRV: OCC 4.0 migration
     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
@@ -104,15 +142,6 @@ Standard_Integer STEPPlugin_ExportDriver::Execute( TFunction_Logbook& log ) cons
   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
@@ -125,5 +154,4 @@ GetCreationInformation( std::string&             theOperationName,
   return false;
 }
 
-IMPLEMENT_STANDARD_HANDLE( STEPPlugin_ExportDriver,GEOM_BaseDriver );
-IMPLEMENT_STANDARD_RTTIEXT( STEPPlugin_ExportDriver,GEOM_BaseDriver );
+OCCT_IMPLEMENT_STANDARD_RTTIEXT( STEPPlugin_ExportDriver,GEOM_BaseDriver );