]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Correction of tests execution: ModelAPI_TestSaveOpen2 and ExchangePlugin_TestImport
authormpv <mpv@opencascade.com>
Wed, 12 Dec 2018 11:59:29 +0000 (14:59 +0300)
committermpv <mpv@opencascade.com>
Wed, 12 Dec 2018 11:59:29 +0000 (14:59 +0300)
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/ModelAPI/ModelAPI_AttributeSelection.h
src/ModelAPI/Test/TestSaveOpen2.py

index c40bffec08ca63303a6f9917e3f0247e48d31ce6..b6464f07fdcc1cd92ab469b9992b3354f8f0eed9 100644 (file)
@@ -201,6 +201,13 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
     aSelectionList->setSelectionType(aSelectionType);
     for (int anElementIndex = 0; anElementIndex < aXaoGroup->count(); ++anElementIndex) {
       aSelectionList->append(aResultBody, GeomShapePtr());
+      // complex conversion of element index to reference id
+      int anElementID = aXaoGroup->get(anElementIndex);
+      std::string aReferenceString =
+        aXaoGeometry->getElementReference(aXaoGroup->getDimension(), anElementID);
+      int aReferenceID = XAO::XaoUtils::stringToInt(aReferenceString);
+
+      aSelectionList->value(anElementIndex)->setId(aReferenceID);
     }
   }
   // Create new fields
index e088c9a4410490ac5915599341e3f92dd0403538..d8d4df6fe41ea1f4bdf19f52ead7af8a372f217f 100644 (file)
@@ -1020,6 +1020,43 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType,
   }
 }
 
+void Model_AttributeSelection::setId(int theID)
+{
+  std::shared_ptr<GeomAPI_Shape> aSelection;
+
+  ResultPtr aContextRes = context();
+  // support for compsolids:
+  while(ModelAPI_Tools::bodyOwner(aContextRes).get()) {
+    aContextRes = ModelAPI_Tools::bodyOwner(aContextRes);
+  }
+  std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
+
+  TopoDS_Shape aMainShape = aContext->impl<TopoDS_Shape>();
+  // searching for the latest main shape
+  if (theID > 0 && aContext && !aContext->isNull())
+  {
+    std::shared_ptr<Model_Document> aDoc =
+      std::dynamic_pointer_cast<Model_Document>(aContextRes->document());
+    if (aDoc.get()) {
+      Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aMainShape, aDoc->generalLabel());
+      if (!aNS.IsNull()) {
+        aMainShape = TNaming_Tool::CurrentShape(aNS);
+      }
+    }
+
+    TopTools_IndexedMapOfShape aSubShapesMap;
+    TopExp::MapShapes(aMainShape, aSubShapesMap);
+    const TopoDS_Shape& aSelShape = aSubShapesMap.FindKey(theID);
+
+    std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
+    aResult->setImpl(new TopoDS_Shape(aSelShape));
+
+    aSelection = aResult;
+  }
+
+  setValue(aContextRes, aSelection);
+}
+
 std::string Model_AttributeSelection::contextName(const ResultPtr& theContext) const
 {
   std::string aResult;
index 6c8d66d73fcf9e65e41d5827169d3c11a76b0b56..66bbc59ffe752a9c586ead66858d4037a428479d 100644 (file)
@@ -100,6 +100,9 @@ public:
   /// \param theDefaultValue a name, which is returned if the naming name can not be obtained
   MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = "");
 
+  /// Defines the sub-shape by Id
+  MODEL_EXPORT virtual void setId(int theID);
+
   /// Selects (i.e. creates Naming data structure) of sub-shape specified by textual name
   MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
                                            const std::string& theSubShapeName);
index a1df51888ac19a4eed87bd1a993119a9906a5a30..5f77111976e8644a6b918201726d092d45bb009d 100644 (file)
@@ -95,6 +95,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
   /// \param theDefaultValue a value, which is used if the naming name can not be obtained
   virtual std::string namingName(const std::string& theDefaultValue = "") = 0;
 
+  /// Defines an id of the selection
+  virtual void setId(int theID) = 0;
+
   /// Selects sub-shape by the textual Name
   virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName) = 0;
 
index 133ba146c83f6569772dcdc233e740730333d990..b2e6cc9288be130a7c00019f1076607bdda380bd 100644 (file)
@@ -65,9 +65,7 @@ aFieldFeature = aPartDoc.objectByName("Features", "Field_1")
 aFieldResult = modelAPI_ResultField(objectToFeature(aFieldFeature).results()[0])
 assert(aFieldResult.textLine(0) == "5")
 aSession.setActiveDocument(partSet, True)
+model.do()
 aTranslation = objectToFeature(partSet.objectByName("Features", "Translation_1"))
 partSet.setCurrentFeature(aTranslation, True)
 model.end()
-
-# check the translation feature has a correct result
-assert(not aTranslation.firstResult().shape().isNull())
\ No newline at end of file