if (aConstruction->isInfinite()) {
// 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(aSelLab);
aBuilder.Generated(aConstruction->shape()->impl<TopoDS_Shape>());
+ std::string anInfinitiveName = contextName(aConstruction);
+ TDataStd_Name::Set(aSelLab, anInfinitiveName.c_str());
+ std::dynamic_pointer_cast<Model_Document>(owner()->document())
+ ->addNamingName(aSelLab, anInfinitiveName.c_str());
+ */
}
} else if (theContext->groupName() == ModelAPI_ResultPart::group()) {
aSelLab.ForgetAllAttributes(true);
if (aContext.get() && aContext->shape().get()) {
TopoDS_Shape aContextShape = aContext->shape()->impl<TopoDS_Shape>();
if (aSelector.solve(aContextShape)) {
+ TopoDS_Shape aSelectorShape = aSelector.value();
GeomShapePtr aShapeToBeSelected(new GeomAPI_Shape);
- aShapeToBeSelected->setImpl<TopoDS_Shape>(new TopoDS_Shape(aSelector.value()));
+ aShapeToBeSelected->setImpl<TopoDS_Shape>(new TopoDS_Shape(aSelectorShape));
+ // make the context result the latest existing
+ aContext = newestContext(aContext, aShapeToBeSelected);
if (aCenterType != NOT_CENTER) {
if (!aShapeToBeSelected->isEdge())
continue;
}
}
- /* to find the latest lower result that keeps given shape
+ if (aCont.get()) {
+ theContext = std::dynamic_pointer_cast<Model_Data>(aCont->data())->label();
+ }
+ return true;
+}
+
+bool Model_AttributeSelection::isLater(
+ const TDF_Label theResult1, const TDF_Label theResult2) const
+{
+ std::shared_ptr<Model_Document> aDoc = myRestoreDocument.get() ? myRestoreDocument :
+ std::dynamic_pointer_cast<Model_Document>(owner()->document());
+ FeaturePtr aFeat1 = aDoc->featureByLab(theResult1);
+ if (!aFeat1.get())
+ return false;
+ FeaturePtr aFeat2 = aDoc->featureByLab(theResult2);
+ if (!aFeat2.get())
+ return false;
+ return aDoc->isLaterByDep(aFeat1, aFeat2);
+}
+
+ResultPtr Model_AttributeSelection::newestContext(
+ const ResultPtr theCurrent, const GeomShapePtr theValue)
+{
+ ResultPtr aResult = theCurrent;
+ GeomShapePtr aSelectedShape = theValue.get() ? theValue : theCurrent->shape();
+ std::shared_ptr<Model_Document> aDoc =
+ std::dynamic_pointer_cast<Model_Document>(owner()->document());
bool aFindNewContext = true;
- while(aFindNewContext && aCont.get()) {
+ while (aFindNewContext && aResult.get()) {
aFindNewContext = false;
// try to find the last context to find the up to date shape
- TopoDS_Shape aConShape = aCont->shape()->impl<TopoDS_Shape>();
+ TopoDS_Shape aConShape = aResult->shape()->impl<TopoDS_Shape>();
Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aConShape, selectionLabel());
if (!aNS.IsNull()) {
aNS = TNaming_Tool::CurrentNamedShape(aNS);
- if (!aNS.IsNull() && isOlderThanMe(aNS->Label())) { // scope check is for 2228
+ if (!aNS.IsNull() && isLater(selectionLabel(), aNS->Label()) &&
+ isLater(aNS->Label(), std::dynamic_pointer_cast<Model_Data>(aResult->data())->label())) {
TDF_Label aLab = aNS->Label();
- if (aLab.Depth() % 2 == 0)
- aLab = aLab.Father();
- ObjectPtr anObj = aDoc->objects()->object(aLab);
- while (!anObj.get() && aLab.Depth() > 5) {
- aLab = aLab.Father().Father();
- anObj = aDoc->objects()->object(aLab);
- }
-
- if (anObj.get()) {
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
- if (aRes) {
- aCont = aRes;
+ ResultPtr aRes = aDoc->resultByLab(aLab);
+ if (aRes.get()) {
+ if (aRes->shape()->isSubShape(aSelectedShape)) {
+ aResult = aRes;
aFindNewContext = true;
+ continue;
}
}
}
- } else if (aCont->groupName() == ModelAPI_ResultBody::group()) {
+ }
+ if (aResult->groupName() == ModelAPI_ResultBody::group()) {
// try to search newer context by the concealment references
// take references to all results: root one, any sub
std::list<ResultPtr> allRes;
ResultPtr aCompContext;
- if (aCont->groupName() == ModelAPI_ResultBody::group()) {
- ResultBodyPtr aCompBody = ModelAPI_Tools::bodyOwner(aCont, true);
- if (aCompBody.get()) {
- ModelAPI_Tools::allSubs(aCompBody, allRes);
- allRes.push_back(aCompBody);
- aCompContext = aCompBody;
- }
+ ResultBodyPtr aCompBody = ModelAPI_Tools::bodyOwner(aResult, true);
+ if (aCompBody.get()) {
+ ModelAPI_Tools::allSubs(aCompBody, allRes);
+ allRes.push_back(aCompBody);
+ aCompContext = aCompBody;
}
if (allRes.empty())
- allRes.push_back(aCont);
+ allRes.push_back(aResult);
- for(std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
+ for (std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
ResultPtr aResCont = *aSub;
ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResCont);
if (aResBody.get() && aResBody->numberOfSubs() > 0 && aResBody != aCompContext)
continue; // only lower and higher level subs are counted
const std::set<AttributePtr>& aRefs = aResCont->data()->refsToMe();
std::set<AttributePtr>::const_iterator aRef = aRefs.begin();
- for(; !aFindNewContext && aRef != aRefs.end(); aRef++) {
+ for (; !aFindNewContext && aRef != aRefs.end(); aRef++) {
if (!aRef->get() || !(*aRef)->owner().get())
continue;
// concealed attribute only
std::list<ResultPtr> aRefFeatResults;
ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults);
std::list<ResultPtr>::iterator aRefResIter = aRefFeatResults.begin();
- for(; aRefResIter != aRefFeatResults.end(); aRefResIter++) {
+ for (; aRefResIter != aRefFeatResults.end(); aRefResIter++) {
ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRefResIter);
if (aBody.get() && aBody->numberOfSubs() == 0) // add only lower level subs
aResults.push_back(aBody);
}
std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = aResults.begin();
- for(; aResIter != aResults.end(); aResIter++) {
+ for (; aResIter != aResults.end(); aResIter++) {
if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
continue;
GeomShapePtr aShape = (*aResIter)->shape();
- GeomShapePtr aSelectedShape =
- aShapeToBeSelected.get() ? aShapeToBeSelected : aCont->shape();
if (aShape.get() && aShape->isSubShape(aSelectedShape, false)) {
- aCont = *aResIter; // found new context (produced from this) with same subshape
+ aResult = *aResIter; // found new context (produced from this) with same subshape
aFindNewContext = true; // continue searching futher
break;
}
}
}
// if compsolid is context, try to take sub-solid as context: like in GUI and scripts
- ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aCont);
+ ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
if (aComp && aComp->numberOfSubs()) {
std::list<ResultPtr> allSubs;
ModelAPI_Tools::allSubs(aComp, allSubs);
for (; aS != allSubs.end(); aS++) {
ResultBodyPtr aSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aS);
if (aSub && aSub->numberOfSubs() == 0 && aSub->shape().get() &&
- aSub->shape()->isSubShape(aShapeToBeSelected)) {
- aCont = aSub;
+ aSub->shape()->isSubShape(aSelectedShape)) {
+ aResult = aSub;
break;
}
}
}
- */
- if (aCont.get()) {
- theContext = std::dynamic_pointer_cast<Model_Data>(aCont->data())->label();
- }
- return true;
-}
-
-bool Model_AttributeSelection::isLater(
- const TDF_Label theResult1, const TDF_Label theResult2) const
-{
- std::shared_ptr<Model_Document> aDoc = myRestoreDocument.get() ? myRestoreDocument :
- std::dynamic_pointer_cast<Model_Document>(owner()->document());
- FeaturePtr aFeat1 = aDoc->featureByLab(theResult1);
- if (!aFeat1.get())
- return false;
- FeaturePtr aFeat2 = aDoc->featureByLab(theResult2);
- if (!aFeat2.get())
- return false;
- return aDoc->isLaterByDep(aFeat1, aFeat2);
+ return aResult;
}