{
std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
if (aNew) {
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aNew)->setSketch(this);
+ // the sketch cannot be specified for the macro-features defined in python
+ // like SketchRectangle, so we need to check the type of new feature
+ std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aNew);
+ if (aSketchFeature)
+ aSketchFeature->setSketch(this);
data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(aNew);
}
// set as current also after it becomes sub to set correctly enabled for other sketch subs
{
if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed
return;
- // to keep the persistent sub-elements indexing, do not remove elements from list,
- // but substitute by nulls
- reflist(SketchPlugin_Sketch::FEATURES_ID())->substitute(theFeature, ObjectPtr());
+ AttributeRefListPtr aList = reflist(SketchPlugin_Sketch::FEATURES_ID());
+ // if the object is last, remove it from the list (needed to skip empty transaction on edit of sketch feature)
+ if (aList->object(aList->size(true) - 1, true) == theFeature) {
+ aList->remove(theFeature);
+ } else {
+ // to keep the persistent sub-elements indexing, do not remove elements from list,
+ // but substitute by nulls
+ aList->substitute(theFeature, ObjectPtr());
+ }
}
int SketchPlugin_Sketch::numberOfSubs(bool forTree) const
}
FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeature,
- SketchPlugin_Sketch* theSketch)
+ SketchPlugin_Sketch* theSketch,
+ const bool theIsCopy)
{
FeaturePtr aNewFeature = theSketch->addFeature(theFeature->getKind());
// addFeature generates a unique name for the feature, it caches the name
// as a name for the feature, the generated unique name is set
aNewFeature->data()->setName(aUniqueFeatureName);
// text expressions could block setValue of some attributes
- clearExpressions(aNewFeature);
+ SketchPlugin_Tools::clearExpressions(aNewFeature);
+ // Set copy attribute
+ AttributeBooleanPtr anAttr = aNewFeature->data()->boolean(SketchPlugin_SketchEntity::COPY_ID());
+ if(anAttr.get()) {
+ anAttr->setValue(theIsCopy);
+ }
return aNewFeature;
}