]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
IMP 0021511: EDF 2153 GEOM: Choose to take units into account or not when importing...
authorjfa <jfa@opencascade.com>
Wed, 22 Aug 2012 06:42:18 +0000 (06:42 +0000)
committerjfa <jfa@opencascade.com>
Wed, 22 Aug 2012 06:42:18 +0000 (06:42 +0000)
idl/GEOM_Gen.idl
src/GEOMImpl/GEOMImpl_IInsertOperations.cxx
src/GEOMImpl/GEOMImpl_IInsertOperations.hxx
src/GEOMImpl/GEOMImpl_ImportDriver.cxx
src/GEOMImpl/GEOMImpl_ImportDriver.hxx
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOM_I/GEOM_IInsertOperations_i.cc
src/GEOM_I/GEOM_IInsertOperations_i.hh
src/IGESImport/IGESImport.cxx
src/STEPImport/STEPImport.cxx

index 209ac2bd3971a378b3594a402df5cd16cc2e7555..7ff4315f802cc2fab5945a556a75415851a16476 100644 (file)
@@ -3211,6 +3211,17 @@ module GEOM
      */
     GEOM_Object ImportFile (in string theFileName, in string theFormatName);
 
+    /*!
+     *  \brief Read a value of parameter from a file, containing a shape.
+     *  \param theFileName The file, containing the shape.
+     *  \param theFormatName Specify format for the file reading.
+     *         Available formats can be obtained with <VAR>ImportTranslators()</VAR> method.
+     *  \param theParameterName Specify the parameter. For example, pass "LEN_UNITS"
+     *                          to obtain length units, in which the file is written.
+     *  \return Value of requested parameter in form of text string.
+     */
+    string ReadValue (in string theFileName, in string theFormatName, in string theParameterName);
+
     /*!
      *  \brief Get the supported import formats and corresponding patterns for File dialog.
      *  \param theFormats Output. List of formats, available for import.
index 3bb7cec61dc5e56692cc7e122fdd179449a9da66..2a83dd58de47f54c4b43d3ac11d040c41cb8b378 100644 (file)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #include <Standard_Stream.hxx>
 
 
 //=============================================================================
 /*!
- *   constructor:
+ *  constructor
  */
 //=============================================================================
-
 GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, int theDocID)
 : GEOM_IOperations(theEngine, theDocID)
 {
@@ -76,20 +74,17 @@ GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, i
  *  destructor
  */
 //=============================================================================
-
 GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations()
 {
   MESSAGE("GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations");
 }
 
-
-
 //=============================================================================
 /*!
  *  MakeCopy
  */
 //=============================================================================
-Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy(Handle(GEOM_Object) theOriginal)
+Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy (Handle(GEOM_Object) theOriginal)
 {
   SetErrorCode(KO);
 
@@ -231,7 +226,6 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
   aCI.SetFileName(theFileName);
   aCI.SetFormatName(theFormatName);
   aCI.SetPluginName(aLibName);
-  //cout<<"IIO: theFormatName = "<<theFormatName.ToCString()<<endl;
 
   //Perform the Import
   try {
@@ -257,7 +251,8 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
 
   SetErrorCode(OK);
 
-  if( theFormatName == "IGES_UNIT" ) {
+  // OLD CODE: begin
+  if (theFormatName == "IGES_UNIT") {
     TopoDS_Shape S = aFunction->GetValue();
     TopoDS_Vertex V = TopoDS::Vertex(S);
     gp_Pnt P = BRep_Tool::Pnt(V);
@@ -270,10 +265,42 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
     //cout<<"IIO: aUnitName = "<<aUnitName.ToCString()<<endl;
     SetErrorCode(aUnitName);
   }
+  // OLD CODE: end
 
   return result;
 }
 
+//=============================================================================
+/*!
+ *  ReadValue
+ */
+//=============================================================================
+TCollection_AsciiString GEOMImpl_IInsertOperations::ReadValue
+                                 (const TCollection_AsciiString& theFileName,
+                                  const TCollection_AsciiString& theFormatName,
+                                  const TCollection_AsciiString& theParameterName)
+{
+  SetErrorCode(KO);
+
+  TCollection_AsciiString aValue, anError;
+
+  if (theFileName.IsEmpty() || theFormatName.IsEmpty() || theParameterName.IsEmpty()) return aValue;
+
+  Handle(TCollection_HAsciiString) aHLibName;
+  if (!IsSupported(Standard_True, theFormatName.SubString(1,4), aHLibName)) {
+    return aValue;
+  }
+  TCollection_AsciiString aLibName = aHLibName->String();
+
+  aValue = GEOMImpl_ImportDriver::ReadValue(theFileName, aLibName, theParameterName, anError);
+  if (anError.IsEmpty())
+    SetErrorCode(OK);
+  else
+    SetErrorCode(anError.ToCString());
+
+  return aValue;
+}
+
 //=============================================================================
 /*!
  *  ImportTranslators
index e60c22b32847068753773b50edabd11a5e42523c..c59411216a4b0f4c1f78375da48264e2fd866802 100644 (file)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #ifndef _GEOMImpl_IInsertOperations_HXX_
 #define _GEOMImpl_IInsertOperations_HXX_
@@ -55,6 +54,10 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations {
   Standard_EXPORT Handle(GEOM_Object) Import (const TCollection_AsciiString& theFileName,
                                               const TCollection_AsciiString& theFormatType);
 
+  Standard_EXPORT TCollection_AsciiString ReadValue (const TCollection_AsciiString& theFileName,
+                                                     const TCollection_AsciiString& theFormatType,
+                                                     const TCollection_AsciiString& theParameterName);
+
   Standard_EXPORT void Export (const Handle(GEOM_Object)      theOriginal,
                                const TCollection_AsciiString& theFileName,
                                const TCollection_AsciiString& theFormatType);
index ee1495f0e0023c22a0425118868760dedab496f4..748a5a735993b0e7cb6c3204d0a023016353bfc1 100644 (file)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #include <Standard_Stream.hxx>
 
 #include <GEOMImpl_Types.hxx>
 #include <GEOM_Function.hxx>
 
-#include "utilities.h"
-
 #include <TopoDS_Shape.hxx>
 
+#include <TCollection_HAsciiString.hxx>
+
+#include "utilities.h"
+
 #include <Standard_Failure.hxx>
 #include <StdFail_NotDone.hxx>
 
@@ -57,6 +58,10 @@ typedef TopoDS_Shape (*funcPoint)(const TCollection_AsciiString&,
                                   TCollection_AsciiString&,
                                   const TDF_Label&);
 
+typedef Handle(TCollection_HAsciiString) (*pGetValue)(const TCollection_AsciiString&,
+                                                      const TCollection_AsciiString&,
+                                                      TCollection_AsciiString&);
+
 //=======================================================================
 //function : GetID
 //purpose  :
@@ -67,7 +72,6 @@ const Standard_GUID& GEOMImpl_ImportDriver::GetID()
   return aImportDriver;
 }
 
-
 //=======================================================================
 //function : GEOMImpl_ImportDriver
 //purpose  :
@@ -97,6 +101,8 @@ Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const
 
   // load plugin library
   LibHandle anImportLib = LoadLib( aLibName.ToCString() ); //This is workaround of BUG OCC13051
+
+  // Get Import method
   funcPoint fp = 0;
   if ( anImportLib )
     fp = (funcPoint)GetProc( anImportLib, "Import" );
@@ -129,6 +135,53 @@ Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const
   return 1;
 }
 
+//=======================================================================
+//function : ReadValue
+//purpose  :
+//=======================================================================
+TCollection_AsciiString GEOMImpl_ImportDriver::ReadValue(const TCollection_AsciiString& theFileName,
+                                                         const TCollection_AsciiString& theLibName,
+                                                         const TCollection_AsciiString& theParameterName,
+                                                         TCollection_AsciiString& theError)
+{
+  TCollection_AsciiString aValue;
+
+  if (theFileName.IsEmpty() || theLibName.IsEmpty() || theParameterName.IsEmpty())
+    return aValue;
+
+  // load plugin library
+  LibHandle anImportLib = LoadLib(theLibName.ToCString()); //This is workaround of BUG OCC13051
+  if (!anImportLib) {
+    theError = theLibName + " library was not installed";
+    return aValue;
+  }
+
+  // Get GetValue method
+  pGetValue pGV = (pGetValue)GetProc(anImportLib, "GetValue");
+
+  if (!pGV) {
+    theError = theLibName + " library doesn't support GetValue method";
+    return aValue;
+  }
+
+  Handle(TCollection_HAsciiString) aHValue = pGV(theFileName, theParameterName, theError);
+
+  if (aHValue.IsNull()) {
+    if (theError.IsEmpty())
+      theError = theFileName + " doesn't contain requested parameter";
+    return aValue;
+  }
+
+  aValue = aHValue->String();
+
+  // unload plugin library
+  // commented by enk:
+  // the bug was occured: using ACIS Import/Export plugin
+  //UnLoadLib( anImportLib ); //This is workaround of BUG OCC13051
+
+  return aValue;
+}
+
 
 //=======================================================================
 //function :  GEOMImpl_ImportDriver_Type_
index 0c625e05c1354b9f1e98a2dfb6773874804785a6..265e5ac4c2bb7da1a20cd6a236f3d071114c7e63 100644 (file)
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 //  File   : GEOMImpl_ImportDriver.ixx
 //  Module : GEOMImpl
-//
+
 #ifndef _GEOMImpl_ImportDriver_HeaderFile
 #define _GEOMImpl_ImportDriver_HeaderFile
 
@@ -119,6 +118,8 @@ class Handle(GEOMImpl_ImportDriver) : public Handle(TFunction_Driver) {
 #include <Standard_CString.hxx>
 #endif
 
+#include <TCollection_AsciiString.hxx>
+
 class TColStd_SequenceOfExtendedString;
 
 
@@ -148,6 +149,11 @@ Standard_EXPORT Standard_Boolean MustExecute(const TFunction_Logbook&) const { r
 Standard_EXPORT static const Standard_GUID& GetID();
 Standard_EXPORT ~GEOMImpl_ImportDriver() {};
 
+  // Static method
+  Standard_EXPORT static TCollection_AsciiString ReadValue (const TCollection_AsciiString& theFileName,
+                                                            const TCollection_AsciiString& theLibName,
+                                                            const TCollection_AsciiString& theParameterName,
+                                                            TCollection_AsciiString& theError);
 
  // Type management
  //
index f0acaa34f53c272a522b50c09d1671a7284964e9..68d4cefd7c956cbb882b0ece4313a8c9e7ad7f86 100644 (file)
@@ -647,6 +647,42 @@ bool GEOMToolsGUI::Import()
       CORBA::String_var fileN = fileName.toLatin1().constData();
       CORBA::String_var fileT = aCurrentType.toLatin1().constData();
 
+      // jfa 21.08.2012 for mantis issue 21511 (STEP file units)
+      CORBA::String_var aUnits = aInsOp->ReadValue(fileN, fileT, "LEN_UNITS");
+      TCollection_AsciiString aUnitsStr (aUnits.in());
+      bool needConvert = true;
+      if (aUnitsStr.IsEmpty() || aUnitsStr == "UNIT_M")
+        needConvert = false;
+
+      if (needConvert) {
+        if (igesAnswer == SUIT_MessageBox::NoToAll) {
+          // converting for all files is already approved
+          fileT = (aCurrentType + "_SCALE").toLatin1().constData();
+        }
+        else if (igesAnswer != SUIT_MessageBox::YesToAll) {
+          SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No;
+          if (i < fileNames.count() - 1) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
+          igesAnswer = SUIT_MessageBox::question(app->desktop(),
+                                                 "Question",//tr("WRN_WARNING"),
+                                                 tr("GEOM_SCALE_DIMENSIONS"),
+                                                 btns | SUIT_MessageBox::Cancel,
+                                                 SUIT_MessageBox::No);
+          switch (igesAnswer) {
+          case SUIT_MessageBox::Cancel:
+            return false;                // cancel (break) import operation
+          case SUIT_MessageBox::Yes:
+          case SUIT_MessageBox::YesToAll:
+            break;                       // scaling is confirmed
+          case SUIT_MessageBox::No:
+          case SUIT_MessageBox::NoAll:
+            fileT = (aCurrentType + "_SCALE").toLatin1().constData();
+          default:
+            break;                       // scaling is rejected
+          } // switch ( igesAnswer )
+        } // if ( igeAnswer != NoToAll )
+      } // if ( needConvert )
+
+      /*
       // skl 29.05.2009
       if ( aCurrentType == "IGES" ) {
         GEOM::GEOM_Object_var anObj = aInsOp->ImportFile( fileN, "IGES_UNIT" );
@@ -684,6 +720,9 @@ bool GEOMToolsGUI::Import()
         } // if ( needConvert )
       } // if ( aCurrentType == "IGES" )
       else if ( aCurrentType == "ACIS" ) {
+      */
+
+      if ( aCurrentType == "ACIS" ) {
         if ( acisAnswer != SUIT_MessageBox::YesToAll && acisAnswer != SUIT_MessageBox::NoToAll ) {
           SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No;
           if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
@@ -697,6 +736,7 @@ bool GEOMToolsGUI::Import()
         } // if ( acisAnswer != YesToAll && acisAnswer != NoToAll )
       } // else if ( aCurrentType == "ACIS" )
 
+      // IMPORT
       GEOM::GEOM_Object_var anObj = aInsOp->ImportFile( fileN, fileT );
 
       if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
index e27a6876b0fd5a114ef3f703d58c395d3c9303bb..cd1b443fa05ef08f5edaf4b27a682103767e61e1 100644 (file)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #ifdef WNT
 #pragma warning( disable:4786 )
@@ -47,7 +46,7 @@
 
 //=============================================================================
 /*!
- *   constructor:
+ *  constructor
  */
 //=============================================================================
 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
@@ -155,6 +154,32 @@ GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::ImportFile
   return GetObject(anObject);
 }
 
+//=============================================================================
+/*!
+ *  ReadValue
+ */
+//=============================================================================
+char* GEOM_IInsertOperations_i::ReadValue(const char* theFileName,
+                                          const char* theFormatName,
+                                          const char* theParameterName)
+{
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+
+  char* aFileName      = strdup(theFileName);
+  char* aFormatName    = strdup(theFormatName);
+  char* aParameterName = strdup(theParameterName);
+
+  TCollection_AsciiString aUnits = GetOperations()->ReadValue
+    (aFileName, aFormatName, aParameterName);
+
+  free(aFileName);
+  free(aFormatName);
+  free(aParameterName);
+
+  return CORBA::string_dup(aUnits.ToCString());
+}
+
 //=============================================================================
 /*!
  *  ImportTranslators
index a7f8cf1dd7a41a916979660695d63e5f5859030b..82057001671cec5f77d462c4ee5f58b6b9073a5a 100644 (file)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #ifndef _GEOM_IInsertOperations_i_HeaderFile
 #define _GEOM_IInsertOperations_i_HeaderFile
@@ -52,6 +51,10 @@ class GEOM_I_EXPORT GEOM_IInsertOperations_i :
   GEOM::GEOM_Object_ptr ImportFile (const char* theFileName,
                                     const char* theFormatName);
 
+  char* ReadValue (const char* theFileName,
+                   const char* theFormatName,
+                   const char* theParameterName);
+
   void ImportTranslators (GEOM::string_array_out theFormats,
                           GEOM::string_array_out thePatterns);
 
index 43f0e38706e165903e68d87d8d26ccf97edf8de9..e9c73ac4a2569d319a6fc57b6c43ad6dca374c53 100644 (file)
@@ -51,6 +51,8 @@
 #include <BRep_Builder.hxx>
 #include <gp_Pnt.hxx>
 
+#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
+
 #ifdef WNT
  #if defined IGESIMPORT_EXPORTS || defined IGESImport_EXPORTS
   #if defined WIN32
 
 extern "C"
 {
+  IGESIMPORT_EXPORT
+  Handle(TCollection_HAsciiString) GetValue (const TCollection_AsciiString& theFileName,
+                                             const TCollection_AsciiString& theParameterName,
+                                             TCollection_AsciiString&       theError)
+  {
+    Handle(TCollection_HAsciiString) aValue;
+
+    if (theParameterName != "LEN_UNITS") {
+      theError = theParameterName + " parameter reading is not supported by IGES plugin";
+      return aValue;
+    }
+
+    // Set "C" numeric locale to save numbers correctly
+    Kernel_Utils::Localizer loc;
+
+    IGESControl_Reader aReader;
+
+    Interface_Static::SetCVal("xstep.cascade.unit","M");
+
+    try {
+      OCC_CATCH_SIGNALS;
+
+      IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
+      if (status == IFSelect_RetDone) {
+        Handle(IGESData_IGESModel) aModel =
+          Handle(IGESData_IGESModel)::DownCast(aReader.Model());
+        if (!aModel.IsNull()) {
+          aValue = aModel->GlobalSection().UnitName();
+
+          if (!aValue.IsNull()) {
+            Handle(TCollection_HAsciiString) aPrefix = new TCollection_HAsciiString ("UNIT_");
+            aValue->Prepend(aPrefix);
+          }
+        }
+      }
+      else {
+        theError = theFileName + " reading failed";
+      }
+    }
+    catch (Standard_Failure) {
+      Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+      theError = aFail->GetMessageString();
+    }
+
+    return aValue;
+  }
+
 IGESIMPORT_EXPORT
   TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
                        const TCollection_AsciiString& theFormatName,
                        TCollection_AsciiString&       theError,
                        const TDF_Label&               theShapeLabel)
   {
+    TopoDS_Shape aResShape;
+
     // Set "C" numeric locale to save numbers correctly
     Kernel_Utils::Localizer loc;
 
     IGESControl_Reader aReader;
-    TopoDS_Shape aResShape;
+
     Interface_Static::SetCVal("xstep.cascade.unit","M");
+
     try {
+      OCC_CATCH_SIGNALS;
+
       IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
 
       if (status == IFSelect_RetDone) {
 
+        // BEGIN: old code
         if (theFormatName == "IGES_UNIT") {
           Handle(IGESData_IGESModel) aModel =
             Handle(IGESData_IGESModel)::DownCast(aReader.Model());
-          gp_Pnt P(1.0,0.0,0.0);
+          gp_Pnt P (1.0, 0.0, 0.0);
           if (!aModel.IsNull()) {
             Handle(TCollection_HAsciiString) aUnitName =
               aModel->GlobalSection().UnitName();
             if (!aUnitName.IsNull()) {
-              //cout<<"aUnitName = "<<aUnitName->ToCString()<<endl;
-              //cout<<"aUnitFlag = "<<aModel->GlobalSection().UnitFlag()<<endl;
               if (aUnitName->String()=="MM") {
                 P = gp_Pnt(0.001,0.0,0.0);
               }
@@ -111,8 +164,6 @@ IGESIMPORT_EXPORT
                 P = gp_Pnt(0.01,0.0,0.0);
               }
             }
-            //else
-            //  cout << "aUnitName is NULL !!" << endl;
           }
           BRep_Builder B;
           TopoDS_Vertex V;
@@ -120,6 +171,8 @@ IGESIMPORT_EXPORT
           aResShape = V;
           return aResShape;
         }
+        // END: old code
+
         if (theFormatName == "IGES_SCALE") {
           //cout<<"need re-scale a model"<<endl;
           // set UnitFlag to 'meter'
index f3f0c06c10b3342b98d313566f74442b473e684a..8a4015043f8879e06f4262a3627e4a27abdc1fc4 100644 (file)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 //  File:        STEPImport.cxx
 //  Created:     Wed May 19 14:41:10 2004
 #include <Basics_Utils.hxx>
 #include <Basics_OCCTVersion.hxx>
 
-#include <BRep_Builder.hxx>
+#include <TDF_ChildIDIterator.hxx>
+#include <TDF_Label.hxx>
+#include <TDataStd_Name.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+
 #include <IFSelect_ReturnStatus.hxx>
 #include <Interface_InterfaceModel.hxx>
 #include <Interface_Static.hxx>
 #include <StepBasic_ProductDefinitionFormation.hxx>
 #include <StepGeom_GeometricRepresentationItem.hxx>
 #include <StepShape_TopologicalRepresentationItem.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TDF_ChildIDIterator.hxx>
-#include <TDF_Label.hxx>
-#include <TDataStd_Name.hxx>
-#include <TNaming_Builder.hxx>
-#include <TNaming_NamedShape.hxx>
+#include <TransferBRep.hxx>
+#include <Transfer_Binder.hxx>
+#include <Transfer_TransientProcess.hxx>
+#include <XSControl_TransferReader.hxx>
+#include <XSControl_WorkSession.hxx>
+
+#include <BRep_Builder.hxx>
+
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <TopoDS_Shape.hxx>
-#include <TransferBRep.hxx>
-#include <Transfer_Binder.hxx>
-#include <Transfer_TransientProcess.hxx>
-#include <XSControl_TransferReader.hxx>
-#include <XSControl_WorkSession.hxx>
+
+#include <TCollection_AsciiString.hxx>
+#include <TColStd_SequenceOfAsciiString.hxx>
 
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
 extern "C"
 {
+  STEPIMPORT_EXPORT
+  Handle(TCollection_HAsciiString) GetValue (const TCollection_AsciiString& theFileName,
+                                             const TCollection_AsciiString& theParameterName,
+                                             TCollection_AsciiString&       theError)
+  {
+    Handle(TCollection_HAsciiString) aValue;
+
+    if (theParameterName != "LEN_UNITS") {
+      theError = theParameterName + " parameter reading is not supported by STEP plugin";
+      return aValue;
+    }
+
+    // Set "C" numeric locale to save numbers correctly
+    Kernel_Utils::Localizer loc;
+
+    STEPControl_Reader aReader;
+
+    Interface_Static::SetCVal("xstep.cascade.unit","M");
+    Interface_Static::SetIVal("read.step.ideas", 1);
+    Interface_Static::SetIVal("read.step.nonmanifold", 1);
+
+    try {
+#if OCC_VERSION_LARGE > 0x06010000
+      OCC_CATCH_SIGNALS;
+#endif
+      IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
+      if (status == IFSelect_RetDone) {
+        TColStd_SequenceOfAsciiString anUnitLengthNames;
+        TColStd_SequenceOfAsciiString anUnitAngleNames;
+        TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
+        aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames);
+        if (anUnitLengthNames.Length() > 0) {
+          TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
+          if (aLenUnits == "millimetre")
+            aValue = new TCollection_HAsciiString ("UNIT_MM");
+          else if (aLenUnits == "centimetre")
+            aValue = new TCollection_HAsciiString ("UNIT_CM");
+          else if (aLenUnits == "metre")
+            aValue = new TCollection_HAsciiString ("UNIT_M");
+          else if (aLenUnits == "INCH")
+            aValue = new TCollection_HAsciiString ("UNIT_INCH");
+          // TODO
+          //else if (aLenUnits == "")
+          //  aValue = new TCollection_HAsciiString ("");
+
+          // tmp begin
+          //std::cout << "$$$ --- " << anUnitLengthNames.First();
+          //for (int ii = 2; ii <= anUnitLengthNames.Length(); ii++)
+          //  std::cout << ", " << anUnitLengthNames.Value(ii);
+          //std::cout << std::endl;
+          // tmp end
+        }
+      }
+      else {
+        theError = theFileName + " reading failed";
+      }
+    }
+    catch (Standard_Failure) {
+      Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+      theError = aFail->GetMessageString();
+    }
+
+    return aValue;
+  }
+
   STEPIMPORT_EXPORT
   TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
-                       const TCollection_AsciiString& /*theFormatName*/,
+                       const TCollection_AsciiString& theFormatName,
                        TCollection_AsciiString&       theError,
                        const TDF_Label&               theShapeLabel)
   {
-    MESSAGE("Import STEP model from file " << theFileName.ToCString());
+    TopoDS_Shape aResShape;
+
     // Set "C" numeric locale to save numbers correctly
     Kernel_Utils::Localizer loc;
-    TopoDS_Shape aResShape;
-    //VRV: OCC 4.0 migration
+
     STEPControl_Reader aReader;
+
     //VSR: 16/09/09: Convert to METERS
     Interface_Static::SetCVal("xstep.cascade.unit","M");
     Interface_Static::SetIVal("read.step.ideas", 1);
     Interface_Static::SetIVal("read.step.nonmanifold", 1);
-    //VRV: OCC 4.0 migration
-    TopoDS_Compound compound;
+
     BRep_Builder B;
+    TopoDS_Compound compound;
     B.MakeCompound(compound);
+
     try {
-#if OCC_VERSION_LARGE > 0x06010000
       OCC_CATCH_SIGNALS;
-#endif
+
       IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
 
       if (status == IFSelect_RetDone) {
+
+        // Regard or not the model units
+        if (theFormatName == "STEP_SCALE") {
+          // set UnitFlag to units from file
+          TColStd_SequenceOfAsciiString anUnitLengthNames;
+          TColStd_SequenceOfAsciiString anUnitAngleNames;
+          TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
+          aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames);
+          if (anUnitLengthNames.Length() > 0) {
+            TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
+            if (aLenUnits == "millimetre")
+              Interface_Static::SetCVal("xstep.cascade.unit", "MM");
+            else if (aLenUnits == "centimetre")
+              Interface_Static::SetCVal("xstep.cascade.unit", "CM");
+            else if (aLenUnits == "metre")
+              Interface_Static::SetCVal("xstep.cascade.unit", "M");
+            else if (aLenUnits == "INCH")
+              Interface_Static::SetCVal("xstep.cascade.unit", "INCH");
+            else {
+              theError = "The file contains not supported units.";
+              return aResShape;
+            }
+            // TODO
+            //else if (aLenUnits == "")
+            //  Interface_Static::SetCVal("xstep.cascade.unit", "");
+          }
+        }
+        else {
+          //cout<<"need re-scale a model"<<endl;
+          // set UnitFlag to 'meter'
+          Interface_Static::SetCVal("xstep.cascade.unit","M");
+        }
+
         Standard_Boolean failsonly = Standard_False;
         aReader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity);
+
         /* Root transfers */
         Standard_Integer nbr = aReader.NbRootsForTransfer();
         aReader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity);