- }
- }
- // store the selected as primitive
- registerSubShape(aLab, aSubShape, 0, aMyDoc, isSelectionMode, anOrientations, aSubNames, aRefs);
- return anIndex - 1;
-}
-
-std::shared_ptr<GeomAPI_Shape> Model_ResultConstruction::shape(const int theIndex,
- const std::shared_ptr<ModelAPI_Document> theExtDoc)
-{
- std::shared_ptr<GeomAPI_Shape> aResult;
- if (theIndex == 0)
- return aResult; // the whole shape, so, NULL
-
- bool isExt;
- TDF_Label aLab = startLabel(theExtDoc, isExt).FindChild(theIndex + 1);
- if (!aLab.IsNull()) { // index is not bad
- Handle(TNaming_NamedShape) aSelection;
- if (aLab.FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
- TopoDS_Shape aSelShape = aSelection->Get();
- if (aSelShape.IsNull())
- return aResult; // shape equal to context => null
- aResult = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
- aResult->setImpl(new TopoDS_Shape(aSelShape));
- }
- }
-
- return aResult;
-}
-
-bool Model_ResultConstruction::update(const int theIndex,
- const std::shared_ptr<ModelAPI_Document> theExtDoc, bool& theModified)
-{
- theModified = false;
- bool anExt;
- TDF_Label aLab = startLabel(theExtDoc, anExt).FindChild(theIndex + 1, Standard_True);
- if (theIndex == 0 || aLab.IsAttribute(kFULL_RESULT_ID)) { // full for external same as index == 0
- // it is just reference to construction, not sub-shape
- // if there is a sketch, the sketch-naming must be updated
- if (!isInfinite()) {
- // update all faces named by the whole result
- bool aRes = true;
- Handle(TDataStd_IntegerArray) anArray;
- if (aLab.FindAttribute(TDataStd_IntegerArray::GetID(), anArray)) {
- for(int anIndex = 0; anIndex <= anArray->Upper(); anIndex++) {
- if (!update(anArray->Value(anIndex), theExtDoc, theModified))
- aRes = false;
- }
- }
- return aRes;
- } else {
- // For correct naming selection, put the shape into the naming structure.
- // It seems sub-shapes are not needed: only this shape is (and can be ) selected.
- TNaming_Builder aBuilder(aLab);
- aBuilder.Generated(shape()->impl<TopoDS_Shape>());
- }
- return shape() && !shape()->isNull();
- }
- // construction: identification by the results indexes, recompute faces and
- // take the face that more close by the indexes
- ResultPtr aThisPtr = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
- FeaturePtr aContextFeature = document()->feature(aThisPtr);
-
- // sketch sub-element
- if (std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature).get())
- {
- // update the referenced object if it is sub
- Handle(TDF_Reference) aRef;
- if (aLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
- int aFaceIndex = aRef->Get().Tag();
- // don't check selection ,since face may disappear, but the shape stays correct
- Model_ResultConstruction::update(aFaceIndex, theExtDoc, theModified);
- }
- // getting a type of selected shape
- Handle(TDataStd_Integer) aTypeAttr;
- if (!aLab.FindAttribute(TDataStd_Integer::GetID(), aTypeAttr)) {
- return false;
- }
- TopAbs_ShapeEnum aShapeType = (TopAbs_ShapeEnum)(aTypeAttr->Get());
- // selected indexes will be needed in each "if"
- Handle(TDataStd_IntPackedMap) aSubIds;
- std::shared_ptr<GeomAPI_Shape> aNewSelected;
- bool aNoIndexes =
- !aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0;
- // for now working only with composite features
- CompositeFeaturePtr aComposite =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
- if (!aComposite.get() || aComposite->numberOfSubs() == 0) {
- return false;
- }