From: mpv Date: Mon, 5 Dec 2016 11:35:32 +0000 (+0300) Subject: Import fields from XAO format: file the selection list by all the shape types since... X-Git-Tag: V_2.6.0~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3c68ce2850e804d694b366b77c309a29957e9a4d;p=modules%2Fshaper.git Import fields from XAO format: file the selection list by all the shape types since fields in XAO have no functionality for the partial selection. --- diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index 2d8c81bb2..17a02d85e 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -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( + 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); diff --git a/src/ExchangePlugin/Test/TestImport.py b/src/ExchangePlugin/Test/TestImport.py index 6db7bf32d..63e364baa 100644 --- a/src/ExchangePlugin/Test/TestImport.py +++ b/src/ExchangePlugin/Test/TestImport.py @@ -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 #========================================================================= diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 8472939eb..9d3694bf1 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -28,6 +28,7 @@ #include #include +#include // for std::transform #define MY_SHAPE implPtr() @@ -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(); diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 6c6e9a954..ccb1153d3 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -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;