diff --git a/doc/salome/gui/GEOM/images/iges_unit.png b/doc/salome/gui/GEOM/images/iges_unit.png
index 60aba603a..cb74fb319 100644
Binary files a/doc/salome/gui/GEOM/images/iges_unit.png and b/doc/salome/gui/GEOM/images/iges_unit.png differ
diff --git a/doc/salome/gui/GEOM/input/import_export.doc b/doc/salome/gui/GEOM/input/import_export.doc
index 70537f934..7946987aa 100644
--- a/doc/salome/gui/GEOM/input/import_export.doc
+++ b/doc/salome/gui/GEOM/input/import_export.doc
@@ -22,10 +22,10 @@ Select the required file and click \b Open. Your file will be imported in
the module and its contents (geometrical object) will be displayed in
the Object Browser.
-\note If the selected file is in IGES format and the length is not
-expressed in meters, it will be suggested to scale the model into the
-metric system (see the picture below). This feature can be helpful if
-some wrong units have been written to the IGES file by a
+\note If the selected file is in IGES or in STEP format and the length
+is not expressed in meters, it will be asked to take or not these
+units into account (see the picture below). This feature can be
+helpful if some wrong units have been written to the IGES file by a
3rd-party software.
\image html iges_unit.png
diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl
index 9c6896aad..4a05f783b 100644
--- a/idl/GEOM_Gen.idl
+++ b/idl/GEOM_Gen.idl
@@ -3289,8 +3289,9 @@ module GEOM
* \param theFileName The file, containing the shape.
* \param theFormatName Specify format for the file reading.
* Available formats can be obtained with ImportTranslators() method.
- * If format 'IGES_SCALE' is used instead 'IGES' length unit will be
- * set to 'meter' and result model will be scaled.
+ * If format 'IGES_SCALE' is used instead of 'IGES' or
+ * format 'STEP_SCALE' is used instead of 'STEP',
+ * file length unit will be ignored (set to 'meter') and result model will be scaled.
* \return New GEOM_Object, containing the imported shape.
*/
GEOM_Object ImportFile (in string theFileName, in string theFormatName);
diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx
index 6aca179a1..4fecfbca9 100644
--- a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx
+++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx
@@ -246,9 +246,22 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
}
//Make a Python command
- if( theFormatName != "IGES_UNIT" ) {
- GEOM::TPythonDump(aFunction) << result << " = geompy.ImportFile(\""
- << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
+ if (theFormatName != "IGES_UNIT") {
+ GEOM::TPythonDump pd (aFunction);
+ if (theFormatName == "BREP")
+ pd << result << " = geompy.ImportBREP(\"" << theFileName.ToCString() << "\")";
+ else if (theFormatName == "IGES")
+ pd << result << " = geompy.ImportIGES(\"" << theFileName.ToCString() << "\")";
+ else if (theFormatName == "IGES_SCALE")
+ pd << result << " = geompy.ImportIGES(\"" << theFileName.ToCString() << "\", True)";
+ else if (theFormatName == "STEP")
+ pd << result << " = geompy.ImportSTEP(\"" << theFileName.ToCString() << "\")";
+ else if (theFormatName == "STEP_SCALE")
+ pd << result << " = geompy.ImportSTEP(\"" << theFileName.ToCString() << "\", True)";
+ else {
+ pd << result << " = geompy.ImportFile(\""
+ << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
+ }
}
SetErrorCode(OK);
@@ -260,9 +273,9 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
gp_Pnt P = BRep_Tool::Pnt(V);
double scale = P.X();
TCollection_AsciiString aUnitName = "UNIT_M";
- if( fabs(scale-0.01) < 1.e-6 )
+ if (fabs(scale-0.01) < 1.e-6)
aUnitName = "UNIT_CM";
- else if( fabs(scale-0.001) < 1.e-6 )
+ else if (fabs(scale-0.001) < 1.e-6)
aUnitName = "UNIT_MM";
//cout<<"IIO: aUnitName = "<ReadValue(fileN, fileT, "LEN_UNITS");
TCollection_AsciiString aUnitsStr (aUnits.in());
bool needConvert = true;
- if (aUnitsStr.IsEmpty() || aUnitsStr == "UNIT_M")
+ if (aUnitsStr.IsEmpty() || aUnitsStr == "M")
needConvert = false;
if (needConvert) {
diff --git a/src/GEOM_SWIG/GEOM_TestOthers.py b/src/GEOM_SWIG/GEOM_TestOthers.py
index 4db5841a0..4f85d8183 100644
--- a/src/GEOM_SWIG/GEOM_TestOthers.py
+++ b/src/GEOM_SWIG/GEOM_TestOthers.py
@@ -78,16 +78,25 @@ def TestExportImport (geompy, shape):
# Import
Import = geompy.ImportFile(fileExportImport, "BREP")
- id_Import = geompy.addToStudy(Import, "Import")
+ geompy.addToStudy(Import, "Import")
# ImportBREP, ImportIGES, ImportSTEP
ImportBREP = geompy.ImportBREP(fileExportImportBREP)
ImportIGES = geompy.ImportIGES(fileExportImportIGES)
ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
- id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
- id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
- id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
+ geompy.addToStudy(ImportBREP, "ImportBREP")
+ geompy.addToStudy(ImportIGES, "ImportIGES")
+ geompy.addToStudy(ImportSTEP, "ImportSTEP")
+
+ # GetIGESUnit and GetSTEPUnit
+ if geompy.GetIGESUnit(fileExportImportIGES) != "M":
+ ImportIGES_scaled = geompy.ImportIGES(fileExportImportIGES, True)
+ geompy.addToStudy(ImportIGES_scaled, "ImportIGES_scaled")
+
+ if geompy.GetSTEPUnit(fileExportImportSTEP) != "M":
+ ImportSTEP_scaled = geompy.ImportSTEP(fileExportImportSTEP, True)
+ geompy.addToStudy(ImportSTEP_scaled, "ImportSTEP_scaled")
# Remove files for Export/Import testing
os.remove(fileExportImport)
diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py
index 8833a4de9..1fb5f2560 100644
--- a/src/GEOM_SWIG/geompyDC.py
+++ b/src/GEOM_SWIG/geompyDC.py
@@ -7321,12 +7321,13 @@ class geompyDC(GEOM._objref_GEOM_Gen):
# @param theFileName The file, containing the shape.
# @param theFormatName Specify format for the file reading.
# Available formats can be obtained with InsertOp.ImportTranslators() method.
- # If format 'IGES_SCALE' is used instead 'IGES' length unit will be
- # set to 'meter' and result model will be scaled.
+ # If format 'IGES_SCALE' is used instead of 'IGES' or
+ # format 'STEP_SCALE' is used instead of 'STEP',
+ # length unit will be set to 'meter' and result model will be scaled.
# @return New GEOM.GEOM_Object, containing the imported shape.
#
# @ref swig_Import_Export "Example"
- def ImportFile(self,theFileName, theFormatName):
+ def ImportFile(self, theFileName, theFormatName):
"""
Import a shape from the BREP or IGES or STEP file
(depends on given format) with given name.
@@ -7334,9 +7335,10 @@ class geompyDC(GEOM._objref_GEOM_Gen):
Parameters:
theFileName The file, containing the shape.
theFormatName Specify format for the file reading.
- Available formats can be obtained with geompy.InsertOp.ImportTranslators() method.
- If format 'IGES_SCALE' is used instead 'IGES' length unit will be
- set to 'meter' and result model will be scaled.
+ Available formats can be obtained with geompy.InsertOp.ImportTranslators() method.
+ If format 'IGES_SCALE' is used instead of 'IGES' or
+ format 'STEP_SCALE' is used instead of 'STEP',
+ length unit will be set to 'meter' and result model will be scaled.
Returns:
New GEOM.GEOM_Object, containing the imported shape.
@@ -7347,7 +7349,7 @@ class geompyDC(GEOM._objref_GEOM_Gen):
return anObj
## Deprecated analog of ImportFile()
- def Import(self,theFileName, theFormatName):
+ def Import(self, theFileName, theFormatName):
"""
Deprecated analog of geompy.ImportFile
"""
@@ -7359,7 +7361,7 @@ class geompyDC(GEOM._objref_GEOM_Gen):
## Shortcut to ImportFile() for BREP format
#
# @ref swig_Import_Export "Example"
- def ImportBREP(self,theFileName):
+ def ImportBREP(self, theFileName):
"""
geompy.ImportFile(...) function for BREP format
"""
@@ -7367,49 +7369,67 @@ class geompyDC(GEOM._objref_GEOM_Gen):
return self.ImportFile(theFileName, "BREP")
## Shortcut to ImportFile() for IGES format
+ # @param doScale If True, file length units will be ignored (set to 'meter')
+ # and result model will be scaled.
+ # If False (default), file length units will be taken into account.
#
# @ref swig_Import_Export "Example"
- def ImportIGES(self,theFileName):
+ def ImportIGES(self, theFileName, doScale = False):
"""
geompy.ImportFile(...) function for IGES format
+
+ Parameters:
+ doScale If True, file length units will be ignored (set to 'meter')
+ and result model will be scaled.
+ If False (default), file length units will be taken into account.
"""
# Example: see GEOM_TestOthers.py
+ if doScale:
+ return self.ImportFile(theFileName, "IGES_SCALE")
return self.ImportFile(theFileName, "IGES")
## Return length unit from given IGES file
+ # @param doScale If True, file length units will be ignored (set to 'meter')
+ # and result model will be scaled.
+ # If False (default), file length units will be taken into account.
#
# @ref swig_Import_Export "Example"
- def GetIGESUnit(self,theFileName):
+ def GetIGESUnit(self, theFileName, doScale = False):
"""
- Return length unit from given IGES file
+ Return length units from given IGES file
"""
# Example: see GEOM_TestOthers.py
- anObj = self.InsertOp.ImportFile(theFileName, "IGES_UNIT")
- #RaiseIfFailed("Import", self.InsertOp)
- # recieve name using returned vertex
- UnitName = "M"
- if anObj.GetShapeType() == GEOM.VERTEX:
- vertices = [anObj]
- else:
- vertices = self.SubShapeAll(anObj,ShapeType["VERTEX"])
- if len(vertices)>0:
- p = self.PointCoordinates(vertices[0])
- if abs(p[0]-0.01) < 1.e-6:
- UnitName = "CM"
- elif abs(p[0]-0.001) < 1.e-6:
- UnitName = "MM"
- return UnitName
+ aUnitName = self.InsertOp.ReadValue(theFileName, "IGES", "LEN_UNITS")
+ return aUnitName
## Shortcut to ImportFile() for STEP format
#
# @ref swig_Import_Export "Example"
- def ImportSTEP(self,theFileName):
+ def ImportSTEP(self, theFileName, doScale = False):
"""
geompy.ImportFile(...) function for STEP format
+
+ Parameters:
+ doScale If True, file length units will be ignored (set to 'meter')
+ and result model will be scaled.
+ If False (default), file length units will be taken into account.
"""
# Example: see GEOM_TestOthers.py
+ if doScale:
+ return self.ImportFile(theFileName, "STEP_SCALE")
return self.ImportFile(theFileName, "STEP")
+ ## Return length unit from given IGES or STEP file
+ #
+ # @ref swig_Import_Export "Example"
+ def GetSTEPUnit(self, theFileName):
+ """
+ Return length units from given STEP file
+ """
+ # Example: see GEOM_TestOthers.py
+ aUnitName = self.InsertOp.ReadValue(theFileName, "STEP", "LEN_UNITS")
+ return aUnitName
+
## Read a shape from the binary stream, containing its bounding representation (BRep).
# @note This method will not be dumped to the python script by DumpStudy functionality.
# @note GEOM.GEOM_Object.GetShapeStream() method can be used to obtain the shape's BRep stream.
@@ -7442,7 +7462,7 @@ class geompyDC(GEOM._objref_GEOM_Gen):
# Available formats can be obtained with InsertOp.ImportTranslators() method.
#
# @ref swig_Import_Export "Example"
- def Export(self,theObject, theFileName, theFormatName):
+ def Export(self, theObject, theFileName, theFormatName):
"""
Export the given shape into a file with given name.
diff --git a/src/IGESImport/IGESImport.cxx b/src/IGESImport/IGESImport.cxx
index e9c73ac4a..3eba47108 100644
--- a/src/IGESImport/IGESImport.cxx
+++ b/src/IGESImport/IGESImport.cxx
@@ -108,10 +108,10 @@ extern "C"
if (!aModel.IsNull()) {
aValue = aModel->GlobalSection().UnitName();
- if (!aValue.IsNull()) {
- Handle(TCollection_HAsciiString) aPrefix = new TCollection_HAsciiString ("UNIT_");
- aValue->Prepend(aPrefix);
- }
+ //if (!aValue.IsNull()) {
+ // Handle(TCollection_HAsciiString) aPrefix = new TCollection_HAsciiString ("UNIT_");
+ // aValue->Prepend(aPrefix);
+ //}
}
}
else {
diff --git a/src/STEPImport/STEPImport.cxx b/src/STEPImport/STEPImport.cxx
index 8a4015043..9b5f1e996 100644
--- a/src/STEPImport/STEPImport.cxx
+++ b/src/STEPImport/STEPImport.cxx
@@ -124,13 +124,13 @@ extern "C"
if (anUnitLengthNames.Length() > 0) {
TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
if (aLenUnits == "millimetre")
- aValue = new TCollection_HAsciiString ("UNIT_MM");
+ aValue = new TCollection_HAsciiString ("MM");
else if (aLenUnits == "centimetre")
- aValue = new TCollection_HAsciiString ("UNIT_CM");
+ aValue = new TCollection_HAsciiString ("CM");
else if (aLenUnits == "metre")
- aValue = new TCollection_HAsciiString ("UNIT_M");
+ aValue = new TCollection_HAsciiString ("M");
else if (aLenUnits == "INCH")
- aValue = new TCollection_HAsciiString ("UNIT_INCH");
+ aValue = new TCollection_HAsciiString ("INCH");
// TODO
//else if (aLenUnits == "")
// aValue = new TCollection_HAsciiString ("");