- FeaturePtr aLastFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theDoc->object(
- ModelAPI_Feature::group(), theDoc->size(ModelAPI_Feature::group()) - 1));
- theDoc->setCurrentFeature(aLastFeature, false);
+ FeaturePtr aLast = std::dynamic_pointer_cast<Model_Document>(theDoc)->lastFeature();
+ // if last is nested into something else, make this something else as last:
+ // otherwise it will look like edition of sub-element, so, the main will be disabled
+ if (aLast.get()) {
+ CompositeFeaturePtr aMain = ModelAPI_Tools::compositeOwner(aLast);
+ while(aMain.get()) {
+ aLast = aMain;
+ aMain = ModelAPI_Tools::compositeOwner(aLast);
+ }
+ }
+ theDoc->setCurrentFeature(aLast, false);