createHistory(theGroupID);
if (theGroupID == ModelAPI_Feature::group()) { // searching among features (in history or not)
std::list<std::shared_ptr<ModelAPI_Feature> > allObjs = allFeatures();
- std::list<std::shared_ptr<ModelAPI_Feature> >::iterator anObjIter = allObjs.begin();
- for(; anObjIter != allObjs.end(); anObjIter++) {
+ // from the end to find the latest result with such name
+ std::list<std::shared_ptr<ModelAPI_Feature> >::reverse_iterator anObjIter = allObjs.rbegin();
+ for(; anObjIter != allObjs.rend(); anObjIter++) {
if ((*anObjIter)->data()->name() == theName)
return *anObjIter;
}
} else { // searching among results (concealed or not)
std::list<std::shared_ptr<ModelAPI_Feature> > allObjs = allFeatures();
- std::list<std::shared_ptr<ModelAPI_Feature> >::iterator anObjIter = allObjs.begin();
- for(; anObjIter != allObjs.end(); anObjIter++) {
+ // from the end to find the latest result with such name
+ std::list<std::shared_ptr<ModelAPI_Feature> >::reverse_iterator anObjIter = allObjs.rbegin();
+ for(; anObjIter != allObjs.rend(); anObjIter++) {
std::list<ResultPtr> allRes;
ModelAPI_Tools::allResults(*anObjIter, allRes);
for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
const std::shared_ptr<ModelAPI_Result>& theResult)
{
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theResult->data());
- if (aData.get()) {
+ if (aData.get() && aData->isValid()) {
TDF_Label aFeatureLab = aData->label().Father().Father().Father();
FeaturePtr aFeature = feature(aFeatureLab);
while(!aFeature.get() && aFeatureLab.Depth() > 1) { // this may be sub-result of result
if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) {
aNewBody = createBody(theFeature->data(), aResIndex);
} else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
- std::shared_ptr<ModelAPI_ResultPart> aNewP = createPart(theFeature->data(), aResIndex);
- theFeature->setResult(aNewP, aResIndex);
- if (!aNewP->partDoc().get())
- // create the part result: it is better to restore the previous result if it is possible
- theFeature->execute();
+ if (aResIndex <= theFeature->results().size()) { // to avoid crash if previous execute
+ // for index = 0 erases result
+ std::shared_ptr<ModelAPI_ResultPart> aNewP = createPart(theFeature->data(), aResIndex);
+ theFeature->setResult(aNewP, aResIndex);
+ if (!aNewP->partDoc().get())
+ // create the part result: it is better to restore the previous result if possible
+ theFeature->execute();
+ }
} else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) {
ResultConstructionPtr aConstr = createConstruction(theFeature->data(), aResIndex);
if (!aConstr->updateShape())