mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-13 02:00:35 +05:00
Mantis issue 0021511: EDF 2153 GEOM: Choose to take units into account or not when importing a STEP file
This commit is contained in:
parent
19973ebc85
commit
368a824418
Binary file not shown.
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 10 KiB |
@ -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 module and its contents (geometrical object) will be displayed in
|
||||||
the <b>Object Browser</b>.
|
the <b>Object Browser</b>.
|
||||||
|
|
||||||
\note If the selected file is in IGES format and the length is not
|
\note If the selected file is in IGES or in STEP format and the length
|
||||||
expressed in meters, it will be suggested to scale the model into the
|
is not expressed in meters, it will be asked to take or not these
|
||||||
metric system (see the picture below). This feature can be helpful if
|
units into account (see the picture below). This feature can be
|
||||||
some wrong units have been written to the IGES file by a
|
helpful if some wrong units have been written to the IGES file by a
|
||||||
3rd-party software.
|
3rd-party software.
|
||||||
|
|
||||||
\image html iges_unit.png
|
\image html iges_unit.png
|
||||||
|
@ -3289,8 +3289,9 @@ module GEOM
|
|||||||
* \param theFileName The file, containing the shape.
|
* \param theFileName The file, containing the shape.
|
||||||
* \param theFormatName Specify format for the file reading.
|
* \param theFormatName Specify format for the file reading.
|
||||||
* Available formats can be obtained with <VAR>ImportTranslators()</VAR> method.
|
* Available formats can be obtained with <VAR>ImportTranslators()</VAR> method.
|
||||||
* If format 'IGES_SCALE' is used instead 'IGES' length unit will be
|
* If format 'IGES_SCALE' is used instead of 'IGES' or
|
||||||
* set to 'meter' and result model will be scaled.
|
* 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.
|
* \return New GEOM_Object, containing the imported shape.
|
||||||
*/
|
*/
|
||||||
GEOM_Object ImportFile (in string theFileName, in string theFormatName);
|
GEOM_Object ImportFile (in string theFileName, in string theFormatName);
|
||||||
|
@ -246,9 +246,22 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Make a Python command
|
//Make a Python command
|
||||||
if( theFormatName != "IGES_UNIT" ) {
|
if (theFormatName != "IGES_UNIT") {
|
||||||
GEOM::TPythonDump(aFunction) << result << " = geompy.ImportFile(\""
|
GEOM::TPythonDump pd (aFunction);
|
||||||
<< theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
|
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);
|
SetErrorCode(OK);
|
||||||
@ -260,9 +273,9 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
|
|||||||
gp_Pnt P = BRep_Tool::Pnt(V);
|
gp_Pnt P = BRep_Tool::Pnt(V);
|
||||||
double scale = P.X();
|
double scale = P.X();
|
||||||
TCollection_AsciiString aUnitName = "UNIT_M";
|
TCollection_AsciiString aUnitName = "UNIT_M";
|
||||||
if( fabs(scale-0.01) < 1.e-6 )
|
if (fabs(scale-0.01) < 1.e-6)
|
||||||
aUnitName = "UNIT_CM";
|
aUnitName = "UNIT_CM";
|
||||||
else if( fabs(scale-0.001) < 1.e-6 )
|
else if (fabs(scale-0.001) < 1.e-6)
|
||||||
aUnitName = "UNIT_MM";
|
aUnitName = "UNIT_MM";
|
||||||
//cout<<"IIO: aUnitName = "<<aUnitName.ToCString()<<endl;
|
//cout<<"IIO: aUnitName = "<<aUnitName.ToCString()<<endl;
|
||||||
SetErrorCode(aUnitName);
|
SetErrorCode(aUnitName);
|
||||||
|
@ -651,7 +651,7 @@ bool GEOMToolsGUI::Import()
|
|||||||
CORBA::String_var aUnits = aInsOp->ReadValue(fileN, fileT, "LEN_UNITS");
|
CORBA::String_var aUnits = aInsOp->ReadValue(fileN, fileT, "LEN_UNITS");
|
||||||
TCollection_AsciiString aUnitsStr (aUnits.in());
|
TCollection_AsciiString aUnitsStr (aUnits.in());
|
||||||
bool needConvert = true;
|
bool needConvert = true;
|
||||||
if (aUnitsStr.IsEmpty() || aUnitsStr == "UNIT_M")
|
if (aUnitsStr.IsEmpty() || aUnitsStr == "M")
|
||||||
needConvert = false;
|
needConvert = false;
|
||||||
|
|
||||||
if (needConvert) {
|
if (needConvert) {
|
||||||
|
@ -78,16 +78,25 @@ def TestExportImport (geompy, shape):
|
|||||||
# Import
|
# Import
|
||||||
Import = geompy.ImportFile(fileExportImport, "BREP")
|
Import = geompy.ImportFile(fileExportImport, "BREP")
|
||||||
|
|
||||||
id_Import = geompy.addToStudy(Import, "Import")
|
geompy.addToStudy(Import, "Import")
|
||||||
|
|
||||||
# ImportBREP, ImportIGES, ImportSTEP
|
# ImportBREP, ImportIGES, ImportSTEP
|
||||||
ImportBREP = geompy.ImportBREP(fileExportImportBREP)
|
ImportBREP = geompy.ImportBREP(fileExportImportBREP)
|
||||||
ImportIGES = geompy.ImportIGES(fileExportImportIGES)
|
ImportIGES = geompy.ImportIGES(fileExportImportIGES)
|
||||||
ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
|
ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
|
||||||
|
|
||||||
id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
|
geompy.addToStudy(ImportBREP, "ImportBREP")
|
||||||
id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
|
geompy.addToStudy(ImportIGES, "ImportIGES")
|
||||||
id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
|
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
|
# Remove files for Export/Import testing
|
||||||
os.remove(fileExportImport)
|
os.remove(fileExportImport)
|
||||||
|
@ -7321,12 +7321,13 @@ class geompyDC(GEOM._objref_GEOM_Gen):
|
|||||||
# @param theFileName The file, containing the shape.
|
# @param theFileName The file, containing the shape.
|
||||||
# @param theFormatName Specify format for the file reading.
|
# @param theFormatName Specify format for the file reading.
|
||||||
# Available formats can be obtained with InsertOp.ImportTranslators() method.
|
# Available formats can be obtained with InsertOp.ImportTranslators() method.
|
||||||
# If format 'IGES_SCALE' is used instead 'IGES' length unit will be
|
# If format 'IGES_SCALE' is used instead of 'IGES' or
|
||||||
# set to 'meter' and result model will be scaled.
|
# 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.
|
# @return New GEOM.GEOM_Object, containing the imported shape.
|
||||||
#
|
#
|
||||||
# @ref swig_Import_Export "Example"
|
# @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
|
Import a shape from the BREP or IGES or STEP file
|
||||||
(depends on given format) with given name.
|
(depends on given format) with given name.
|
||||||
@ -7334,9 +7335,10 @@ class geompyDC(GEOM._objref_GEOM_Gen):
|
|||||||
Parameters:
|
Parameters:
|
||||||
theFileName The file, containing the shape.
|
theFileName The file, containing the shape.
|
||||||
theFormatName Specify format for the file reading.
|
theFormatName Specify format for the file reading.
|
||||||
Available formats can be obtained with geompy.InsertOp.ImportTranslators() method.
|
Available formats can be obtained with geompy.InsertOp.ImportTranslators() method.
|
||||||
If format 'IGES_SCALE' is used instead 'IGES' length unit will be
|
If format 'IGES_SCALE' is used instead of 'IGES' or
|
||||||
set to 'meter' and result model will be scaled.
|
format 'STEP_SCALE' is used instead of 'STEP',
|
||||||
|
length unit will be set to 'meter' and result model will be scaled.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
New GEOM.GEOM_Object, containing the imported shape.
|
New GEOM.GEOM_Object, containing the imported shape.
|
||||||
@ -7347,7 +7349,7 @@ class geompyDC(GEOM._objref_GEOM_Gen):
|
|||||||
return anObj
|
return anObj
|
||||||
|
|
||||||
## Deprecated analog of ImportFile()
|
## Deprecated analog of ImportFile()
|
||||||
def Import(self,theFileName, theFormatName):
|
def Import(self, theFileName, theFormatName):
|
||||||
"""
|
"""
|
||||||
Deprecated analog of geompy.ImportFile
|
Deprecated analog of geompy.ImportFile
|
||||||
"""
|
"""
|
||||||
@ -7359,7 +7361,7 @@ class geompyDC(GEOM._objref_GEOM_Gen):
|
|||||||
## Shortcut to ImportFile() for BREP format
|
## Shortcut to ImportFile() for BREP format
|
||||||
#
|
#
|
||||||
# @ref swig_Import_Export "Example"
|
# @ref swig_Import_Export "Example"
|
||||||
def ImportBREP(self,theFileName):
|
def ImportBREP(self, theFileName):
|
||||||
"""
|
"""
|
||||||
geompy.ImportFile(...) function for BREP format
|
geompy.ImportFile(...) function for BREP format
|
||||||
"""
|
"""
|
||||||
@ -7367,49 +7369,67 @@ class geompyDC(GEOM._objref_GEOM_Gen):
|
|||||||
return self.ImportFile(theFileName, "BREP")
|
return self.ImportFile(theFileName, "BREP")
|
||||||
|
|
||||||
## Shortcut to ImportFile() for IGES format
|
## 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"
|
# @ref swig_Import_Export "Example"
|
||||||
def ImportIGES(self,theFileName):
|
def ImportIGES(self, theFileName, doScale = False):
|
||||||
"""
|
"""
|
||||||
geompy.ImportFile(...) function for IGES format
|
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
|
# Example: see GEOM_TestOthers.py
|
||||||
|
if doScale:
|
||||||
|
return self.ImportFile(theFileName, "IGES_SCALE")
|
||||||
return self.ImportFile(theFileName, "IGES")
|
return self.ImportFile(theFileName, "IGES")
|
||||||
|
|
||||||
## Return length unit from given IGES file
|
## 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"
|
# @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
|
# Example: see GEOM_TestOthers.py
|
||||||
anObj = self.InsertOp.ImportFile(theFileName, "IGES_UNIT")
|
aUnitName = self.InsertOp.ReadValue(theFileName, "IGES", "LEN_UNITS")
|
||||||
#RaiseIfFailed("Import", self.InsertOp)
|
return aUnitName
|
||||||
# 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
|
|
||||||
|
|
||||||
## Shortcut to ImportFile() for STEP format
|
## Shortcut to ImportFile() for STEP format
|
||||||
#
|
#
|
||||||
# @ref swig_Import_Export "Example"
|
# @ref swig_Import_Export "Example"
|
||||||
def ImportSTEP(self,theFileName):
|
def ImportSTEP(self, theFileName, doScale = False):
|
||||||
"""
|
"""
|
||||||
geompy.ImportFile(...) function for STEP format
|
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
|
# Example: see GEOM_TestOthers.py
|
||||||
|
if doScale:
|
||||||
|
return self.ImportFile(theFileName, "STEP_SCALE")
|
||||||
return self.ImportFile(theFileName, "STEP")
|
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).
|
## 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 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.
|
# @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.
|
# Available formats can be obtained with InsertOp.ImportTranslators() method.
|
||||||
#
|
#
|
||||||
# @ref swig_Import_Export "Example"
|
# @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.
|
Export the given shape into a file with given name.
|
||||||
|
|
||||||
|
@ -108,10 +108,10 @@ extern "C"
|
|||||||
if (!aModel.IsNull()) {
|
if (!aModel.IsNull()) {
|
||||||
aValue = aModel->GlobalSection().UnitName();
|
aValue = aModel->GlobalSection().UnitName();
|
||||||
|
|
||||||
if (!aValue.IsNull()) {
|
//if (!aValue.IsNull()) {
|
||||||
Handle(TCollection_HAsciiString) aPrefix = new TCollection_HAsciiString ("UNIT_");
|
// Handle(TCollection_HAsciiString) aPrefix = new TCollection_HAsciiString ("UNIT_");
|
||||||
aValue->Prepend(aPrefix);
|
// aValue->Prepend(aPrefix);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -124,13 +124,13 @@ extern "C"
|
|||||||
if (anUnitLengthNames.Length() > 0) {
|
if (anUnitLengthNames.Length() > 0) {
|
||||||
TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
|
TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
|
||||||
if (aLenUnits == "millimetre")
|
if (aLenUnits == "millimetre")
|
||||||
aValue = new TCollection_HAsciiString ("UNIT_MM");
|
aValue = new TCollection_HAsciiString ("MM");
|
||||||
else if (aLenUnits == "centimetre")
|
else if (aLenUnits == "centimetre")
|
||||||
aValue = new TCollection_HAsciiString ("UNIT_CM");
|
aValue = new TCollection_HAsciiString ("CM");
|
||||||
else if (aLenUnits == "metre")
|
else if (aLenUnits == "metre")
|
||||||
aValue = new TCollection_HAsciiString ("UNIT_M");
|
aValue = new TCollection_HAsciiString ("M");
|
||||||
else if (aLenUnits == "INCH")
|
else if (aLenUnits == "INCH")
|
||||||
aValue = new TCollection_HAsciiString ("UNIT_INCH");
|
aValue = new TCollection_HAsciiString ("INCH");
|
||||||
// TODO
|
// TODO
|
||||||
//else if (aLenUnits == "")
|
//else if (aLenUnits == "")
|
||||||
// aValue = new TCollection_HAsciiString ("");
|
// aValue = new TCollection_HAsciiString ("");
|
||||||
|
Loading…
Reference in New Issue
Block a user