]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Import fields from XAO format: file the selection list by all the shape types since...
authormpv <mpv@opencascade.com>
Mon, 5 Dec 2016 11:35:32 +0000 (14:35 +0300)
committermpv <mpv@opencascade.com>
Mon, 5 Dec 2016 11:35:50 +0000 (14:35 +0300)
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/ExchangePlugin/Test/TestImport.py
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h

index 2d8c81bb229a9b30aa2ef31fc677f46331de0d90..17a02d85e78b378fc753a46d90dea9007a6d3688 100644 (file)
@@ -19,6 +19,7 @@
 #include <GeomAlgoAPI_XAOImport.h>
 
 #include <GeomAPI_Shape.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeSelectionList.h>
@@ -213,6 +214,30 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
     std::string aSelectionType =
       ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
     aSelectionList->setSelectionType(aSelectionType);
+    // limitation: now in XAO fields are related to everything, so, iterate all sub-shapes to fill
+    int aCountSelected = aXaoField->countElements();
+    int aResults = document()->size(ModelAPI_ResultBody::group());
+    for(int a = 0; a < aResults && aCountSelected; a++) {
+      ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(
+        document()->object(ModelAPI_ResultBody::group(), a));
+      if (!aBody.get())
+        continue;
+      // check that only results that were created before this field are used
+      FeaturePtr aResultFeature = document()->feature(aBody);
+      if (!aResultFeature.get())
+        continue;
+      GeomShapePtr aShape = aBody->shape();
+      if (!aShape.get() || aShape->isNull())
+        continue;
+      GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::shapeTypeByStr(aSelectionType));
+      for(; anExp.more(); anExp.next()) {
+        aSelectionList->append(aBody, anExp.current());
+        aCountSelected--;
+        if (aCountSelected == 0)
+          break;
+      }
+    }
+
     // conversion of type
     XAO::Type aFieldType = aXaoField->getType();
     std::string aTypeString = XAO::XaoUtils::fieldTypeToString(aFieldType);
index 6db7bf32d40816b769434e1386a907390de1e60a..63e364baa38ef2a41d66c11c2ff6ca61724c0895 100644 (file)
@@ -64,7 +64,8 @@ def testImportXAO():
     assert modelAPI_ResultBody(anImportFeature.firstResult())
     assert anImportFeature.firstResult().data().name() == "mygeom_1"
     aCompositeFeature = featureToCompositeFeature(anImportFeature)
-    assert aCompositeFeature.numberOfSubs(False) == 2
+    # Two groups and one field
+    assert aCompositeFeature.numberOfSubs(False) == 3
 
     aFeature1 = aCompositeFeature.subFeature(0, False)
     assert aFeature1.getKind() == "Group"
@@ -86,6 +87,16 @@ def testImportXAO():
     print aSelectionList.value(1).namingName("")
     assert aSelectionList.value(1).namingName("") == "mygeom_1/Shape2"
 
+    aFeature3 = aCompositeFeature.subFeature(2, False)
+    assert aFeature3.getKind() == "Field"
+    assert aFeature3.name() == "color"
+    assert aFeature3.intArray("stamps").size() == 2
+    assert aFeature3.tables("values").rows() == 2
+    assert aFeature3.tables("values").columns() == 3
+    assert aFeature3.tables("values").tables() == 2
+    assert aFeature3.tables("values").type() == 1 # integer
+    assert aFeature3.selectionList("selected").size() == 1
+
 if __name__ == '__main__':
 #=========================================================================
 # Create a shape imported from BREP
@@ -105,7 +116,7 @@ if __name__ == '__main__':
 #=========================================================================
 # Create a shape imported from XAO
 #=========================================================================
-    #testImportXAO()
+    testImportXAO()
 #=========================================================================
 # End of test
 #=========================================================================
index 8472939eb4dfe94be5c337db7adbe5cd47a85d20..9d3694bf1c114d8524cc8e8ede5786a5722e767c 100644 (file)
@@ -28,6 +28,7 @@
 #include <NCollection_List.hxx>
 
 #include <sstream>
+#include <algorithm> // for std::transform
 
 #define MY_SHAPE implPtr<TopoDS_Shape>()
 
@@ -283,6 +284,28 @@ GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const
   return aST;
 }
 
+GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeTypeByStr(std::string theType)
+{
+  std::transform(theType.begin(), theType.end(), theType.begin(), ::toupper);
+  if (theType == "COMPOUND")
+    return COMPOUND;
+  if (theType == "COMPSOLID")
+    return COMPSOLID;
+  if (theType == "SOLID")
+    return SOLID;
+  if (theType == "SHELL")
+    return SHELL;
+  if (theType == "FACE")
+    return FACE;
+  if (theType == "WIRE")
+    return WIRE;
+  if (theType == "EDGE")
+    return EDGE;
+  if (theType == "VERTEX")
+    return VERTEX;
+  return SHAPE; // default
+}
+
 std::string GeomAPI_Shape::shapeTypeStr() const
 {
   ShapeType aShapeType = shapeType();
index 6c6e9a95416873b5559e43ee23f03482b2bf9e81..ccb1153d33c57809a7bf76c3f337ee64ba3200b1 100644 (file)
@@ -90,6 +90,9 @@ public:
   GEOMAPI_EXPORT
   virtual ShapeType shapeType() const;
 
+  /// Returns the type enumeration by the string-type
+  GEOMAPI_EXPORT static ShapeType shapeTypeByStr(std::string theType);
+
   /// \return the shape type as string.
   GEOMAPI_EXPORT
   virtual std::string shapeTypeStr() const;