Salome HOME
Mantis issue 0021511: EDF 2153 GEOM: Choose to take units into account or not when...
authorjfa <jfa@opencascade.com>
Thu, 1 Nov 2012 08:24:37 +0000 (08:24 +0000)
committerjfa <jfa@opencascade.com>
Thu, 1 Nov 2012 08:24:37 +0000 (08:24 +0000)
doc/salome/gui/GEOM/images/iges_unit.png
doc/salome/gui/GEOM/input/import_export.doc
idl/GEOM_Gen.idl
src/GEOMImpl/GEOMImpl_IInsertOperations.cxx
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOM_SWIG/GEOM_TestOthers.py
src/GEOM_SWIG/geompyDC.py
src/IGESImport/IGESImport.cxx
src/STEPImport/STEPImport.cxx

index 60aba603ad83270687dedd20473e3b4036efca92..cb74fb319fb952aabef33c434e827b0b76a211e5 100644 (file)
Binary files a/doc/salome/gui/GEOM/images/iges_unit.png and b/doc/salome/gui/GEOM/images/iges_unit.png differ
index 70537f934099ab3604a7b66d07c5240aeca73364..7946987aa2988ccdd57ad1367e6a3d0fb3024a0c 100644 (file)
@@ -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
index 9c6896aad104cb100c4ca54e697b7972f4742746..4a05f783b470c25d4d37790b04443f54f6562624 100644 (file)
@@ -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);
index 6aca179a16df948dceb84bef357fbb02f605fd3b..4fecfbca9deeea85fbc54815c2a649dfa388237e 100644 (file)
@@ -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);
index e83523ea45ccb293a993aaefb74d1b14fdc07b74..ab7c57662e83193b343f70a3fb7147b2017e9398 100644 (file)
@@ -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) {
index 4db5841a03f34dd6952e6f494f8c20dd6bdad194..4f85d818335a910992bba877cce56b2223ad065f 100644 (file)
@@ -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)
index 8833a4de9353673d05f8ddb7460e6038e1f96f62..1fb5f2560b4814730fd4e7ad8499b6705498a21a 100644 (file)
@@ -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.
 
index e9c73ac4a2569d319a6fc57b6c43ad6dca374c53..3eba471083b4dc0dfa027e06af350932b8187a88 100644 (file)
@@ -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 {
index 8a4015043f8879e06f4262a3627e4a27abdc1fc4..9b5f1e9966faf2f22a21c312d1a6489de27f751e 100644 (file)
@@ -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 ("");