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 <b>Object Browser</b>.
|
||||
|
||||
\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
|
||||
|
@ -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 <VAR>ImportTranslators()</VAR> 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);
|
||||
|
@ -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 = "<<aUnitName.ToCString()<<endl;
|
||||
SetErrorCode(aUnitName);
|
||||
|
@ -651,7 +651,7 @@ bool GEOMToolsGUI::Import()
|
||||
CORBA::String_var aUnits = aInsOp->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) {
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 ("");
|
||||
|
Loading…
Reference in New Issue
Block a user