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
}
}
+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;
/// \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);
/// \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;
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