Salome HOME
Add Model_AttributeSelection::setId()
authorspo <sergey.pokhodenko@opencascade.com>
Wed, 25 Nov 2015 10:41:24 +0000 (13:41 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Wed, 22 Jun 2016 11:06:01 +0000 (14:06 +0300)
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h

index c672ed47effb8b8299b90ef0563f4d561777d219..92b91327c230a0cf7f2133ec39424b2241d4575b 100644 (file)
@@ -977,3 +977,41 @@ int Model_AttributeSelection::Id()
   }
   return anID;
 }
+
+void Model_AttributeSelection::setId(int theID)
+{
+  const ResultPtr& aContext = context();
+  std::shared_ptr<GeomAPI_Shape> aSelection;
+
+  std::shared_ptr<GeomAPI_Shape> aContextShape = aContext->shape();
+  // support for compsolids:
+  if (aContext.get() && ModelAPI_Tools::compSolidOwner(aContext).get())
+    aContextShape = ModelAPI_Tools::compSolidOwner(aContext)->shape();
+
+  TopoDS_Shape aMainShape = aContextShape->impl<TopoDS_Shape>();
+  // searching for the latest main shape
+  if (theID > 0 &&
+      aContextShape && !aContextShape->isNull())
+  {
+    std::shared_ptr<Model_Document> aDoc =
+      std::dynamic_pointer_cast<Model_Document>(aContext->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(aContext, aSelection);
+}
+
index 5c7d3c358a0494fefab375d32faa667e71178dce..1f3c4594570754cab0c5af149c814f32f499c9d6 100644 (file)
@@ -58,6 +58,10 @@ public:
   /// will be possible from SMESH module of SALOME.
   MODEL_EXPORT virtual int Id();
 
+  /// Defines the sub-shape by Id
+  /// NOTE: This method is opposite to Id() method.
+  MODEL_EXPORT virtual void setId(int theID);
+
   /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
   MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName);