bool Model_Document::canUndo()
{
- if (myDoc->GetAvailableUndos() > 0 && (myNestedNum.empty() || *myNestedNum.rbegin() != 0) &&
- !myTransactions.empty() /* for omitting the first useless transaction */)
+ // issue 406 : if transaction is opened, but nothing to undo behind, can not undo
+ int aCurrentNum = isOperation() ? 1 : 0;
+ if (myDoc->GetAvailableUndos() > 0 &&
+ (myNestedNum.empty() || *myNestedNum.rbegin() - aCurrentNum > 0) && // there is something to undo in nested
+ myTransactions.size() - aCurrentNum > 0 /* for omitting the first useless transaction */)
return true;
// check other subs contains operation that can be undoed
const std::set<std::string> aSubs = subDocuments(true);
myObjs.UnBind(aFeatureLabel);
else
return; // not found feature => do not remove
+
+ // checking that the sub-element of composite feature is removed: if yes, inform the owner
+ std::set<std::shared_ptr<ModelAPI_Feature> > aRefs;
+ refsToFeature(theFeature, aRefs, false);
+ std::set<std::shared_ptr<ModelAPI_Feature> >::iterator aRefIter = aRefs.begin();
+ for(; aRefIter != aRefs.end(); aRefIter++) {
+ std::shared_ptr<ModelAPI_CompositeFeature> aComposite =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aRefIter);
+ if (aComposite.get()) {
+ aComposite->removeFeature(theFeature);
+ }
+ }
+
// erase fields
theFeature->erase();
+ static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP);
// erase all attributes under the label of feature
aFeatureLabel.ForgetAllAttributes();
// remove it from the references array
if (theFeature->isInHistory()) {
RemoveFromRefArray(featuresLabel(), aFeatureLabel);
}
+ // event: feature is deleted
+ ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
}
- // event: feature is deleted
- ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
}
FeaturePtr Model_Document::feature(TDF_Label& theLabel) const
thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
}
- /// removes also all sub-sketch elements
- SKETCHPLUGIN_EXPORT virtual void erase()
- {
- /*SketchPlugin_Sketch* aSketch = sketch();
- if (aSketch)
- aSketch->removeFeature(this);
- */
- ModelAPI_Feature::erase();
- }
-
/// Returns the sketch of this feature
SketchPlugin_Sketch* sketch();
protected:
return aNew;
}
-void SketchPlugin_Sketch::removeFeature(ModelAPI_Feature* theFeature)
+void SketchPlugin_Sketch::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
{
if (!data().get()) // sketch is already removed (case on undo of sketch), sync is not needed
return;
bool aHasEmtpyFeature = false;
for(; aSubIt != aLastIt && !isRemoved; aSubIt++) {
std::shared_ptr<ModelAPI_Feature> aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aSubIt);
- if (aFeature.get() != NULL && aFeature.get() == theFeature) {
+ if (aFeature.get() != NULL && aFeature == theFeature) {
data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(aFeature);
isRemoved = true;
}
/// appends a feature to the sketch sub-elements container
SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
- /// appends a feature from the sketch sub-elements container
- SKETCHPLUGIN_EXPORT virtual void removeFeature(ModelAPI_Feature* theFeature);
+ /// Just to synchronise the container of sub-features
+ virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
/// Returns the number of sub-elements
SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;