]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/STEPPlugin/STEPPlugin_IOperations.cxx
Salome HOME
updated copyright message
[modules/geom.git] / src / STEPPlugin / STEPPlugin_IOperations.cxx
index 86d1055e38d050200e17630832dde2ed70840fce..026cfbf84bf6eef432eff05a8c4ccfddd2300246 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2014-2023  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
@@ -25,6 +25,7 @@
 #include "STEPPlugin_IImport.hxx"
 
 // KERNEL includes
+#include <Basics_DirUtils.hxx>
 #include <utilities.h>
 
 // GEOM includes
@@ -38,8 +39,8 @@
  *  Constructor
  */
 //=============================================================================
-STEPPlugin_IOperations::STEPPlugin_IOperations( GEOM_Engine* theEngine, int theDocID )
-: GEOMImpl_IBaseIEOperations( theEngine, theDocID )
+STEPPlugin_IOperations::STEPPlugin_IOperations( GEOM_Engine* theEngine )
+: GEOMImpl_IBaseIEOperations( theEngine )
 {
   MESSAGE( "STEPPlugin_IOperations::STEPPlugin_IOperations" );
 }
@@ -54,18 +55,66 @@ STEPPlugin_IOperations::~STEPPlugin_IOperations()
   MESSAGE( "STEPPlugin_IOperations::~STEPPlugin_IOperations" );
 }
 
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+static GEOM::TPythonDump& operator<<
+          (GEOM::TPythonDump                        &theDump,
+           const STEPPlugin_IOperations::LengthUnit  theState)
+{
+  switch (theState) {
+  case STEPPlugin_IOperations::LengthUnit_Inch:
+    theDump << "GEOM.LU_INCH";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Millimeter:
+    theDump << "GEOM.LU_MILLIMETER";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Foot:
+    theDump << "GEOM.LU_FOOT";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Mile:
+    theDump << "GEOM.LU_MILE";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Meter:
+    theDump << "GEOM.LU_METER";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Kilometer:
+    theDump << "GEOM.LU_KILOMETER";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Milliinch:
+    theDump << "GEOM.LU_MILLIINCH";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Micrometer:
+    theDump << "GEOM.LU_MICROMETER";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Centimeter:
+    theDump << "GEOM.LU_CENTIMETER";
+    break;
+  case STEPPlugin_IOperations::LengthUnit_Microinch:
+    theDump << "GEOM.LU_MICROINCH";
+    break;
+  default:
+    break;
+  }
+
+  return theDump;
+}
+
 //=============================================================================
 /*!
  *  ExportSTEP
  *  Export a shape to STEP format
  *  \param theOriginal The shape to export
  *  \param theFileName The name of the file to exported
- *  \param theIsASCII The format of the exported file (ASCII or Binary)
- *  \param theDeflection The deflection of the shape to exported
+ *  \param theUnit the length unit
  */
 //=============================================================================
-void STEPPlugin_IOperations::ExportSTEP( const Handle(GEOM_Object)      theOriginal,
-                                        const TCollection_AsciiString& theFileName )
+void STEPPlugin_IOperations::ExportSTEP
+                    (const Handle(GEOM_Object)      theOriginal,
+                     const TCollection_AsciiString &theFileName,
+                     const LengthUnit               theUnit)
 {
   SetErrorCode(KO);
   if( theOriginal.IsNull() ) return;
@@ -74,7 +123,7 @@ void STEPPlugin_IOperations::ExportSTEP( const Handle(GEOM_Object)      theOrigi
   if( aRefFunction.IsNull() ) return;  //There is no function which creates an object to be exported
 
   //Add a new result object
-  Handle(GEOM_Object) result = GetEngine()->AddObject( GetDocID(), GEOM_IMPORT);
+  Handle(GEOM_Object) result = GetEngine()->AddObject( GEOM_IMPORT);
 
   //Add an Export function
   Handle(GEOM_Function) aFunction = result->AddFunction( STEPPlugin_ExportDriver::GetID(), EXPORT_SHAPE );
@@ -87,6 +136,7 @@ void STEPPlugin_IOperations::ExportSTEP( const Handle(GEOM_Object)      theOrigi
   STEPPlugin_IExport aCI( aFunction );
   aCI.SetOriginal( aRefFunction );
   aCI.SetFileName( theFileName );
+  aCI.SetUnit( theUnit );
 
   //Perform the Export
   try {
@@ -96,15 +146,15 @@ void STEPPlugin_IOperations::ExportSTEP( const Handle(GEOM_Object)      theOrigi
       return;
     }
   }
-  catch( Standard_Failure ) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    SetErrorCode( aFail->GetMessageString() );
+  catch( Standard_Failure& aFail ) {
+    SetErrorCode( aFail.GetMessageString() );
     return;
   }
 
   //Make a Python command
+  std::string convFileName = Kernel_Utils::BackSlashToSlash(theFileName.ToCString());
   GEOM::TPythonDump(aFunction) << "geompy.ExportSTEP(" << theOriginal << ", \""
-    << theFileName.ToCString() << "\" )";
+    << convFileName.c_str() << "\", " << theUnit << " )";
 
   SetErrorCode(OK);
 }
@@ -118,14 +168,15 @@ void STEPPlugin_IOperations::ExportSTEP( const Handle(GEOM_Object)      theOrigi
  */
 //=============================================================================
 Handle(TColStd_HSequenceOfTransient)
-STEPPlugin_IOperations::ImportSTEP( const TCollection_AsciiString& theFileName,
-                                   const bool theIsIgnoreUnits )
+STEPPlugin_IOperations::ImportSTEP(const TCollection_AsciiString& theFileName,
+                                   const bool theIsIgnoreUnits,
+                                   const bool IsCreateAssemblies)
 {
   SetErrorCode(KO);
   if( theFileName.IsEmpty() ) return NULL;
 
   //Add a new result object
-  Handle(GEOM_Object) anImported = GetEngine()->AddObject( GetDocID(), GEOM_IMPORT );
+  Handle(GEOM_Object) anImported = GetEngine()->AddObject( GEOM_IMPORT );
 
   //Add an Import function
   Handle(GEOM_Function) aFunction =
@@ -139,6 +190,7 @@ STEPPlugin_IOperations::ImportSTEP( const TCollection_AsciiString& theFileName,
   STEPPlugin_IImport aCI( aFunction );
   aCI.SetFileName( theFileName );
   aCI.SetIsIgnoreUnits( theIsIgnoreUnits );
+  aCI.SetIsCreateAssemblies( IsCreateAssemblies );
 
   //Perform the Import
   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
@@ -151,21 +203,21 @@ STEPPlugin_IOperations::ImportSTEP( const TCollection_AsciiString& theFileName,
     }
     aSeq->Append(anImported);
 
-    // Greate material groups.
+    // Create material groups.
     MakeMaterialGroups( anImported, aSeq );
   }
-  catch( Standard_Failure ) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    SetErrorCode( aFail->GetMessageString() );
+  catch( Standard_Failure& aFail ) {
+    SetErrorCode( aFail.GetMessageString() );
     return NULL;
   }
 
   //Make a Python command
   GEOM::TPythonDump pd (aFunction);
-  if( theIsIgnoreUnits )
-    pd << aSeq << " = geompy.ImportSTEP(\"" << theFileName.ToCString() << "\", True)";
-  else
-    pd << aSeq << " = geompy.ImportSTEP(\"" << theFileName.ToCString() << "\")";
+  std::string convFileName =  Kernel_Utils::BackSlashToSlash( theFileName.ToCString() );
+  pd << aSeq << " = geompy.ImportSTEP(\"" << convFileName.c_str() << "\", ";
+  pd << (theIsIgnoreUnits ? "True" : "False");
+  pd << ", " << (IsCreateAssemblies ? "True" : "False");
+  pd << ")";
   SetErrorCode(OK);
 
   return aSeq;