- FeaturePtr aFeature = ModelAPI_Feature::feature(mySelectedObject);
- if (aFeature) {
- std::shared_ptr<SketchPlugin_Feature> aSPFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
- if ((!aSPFeature) && (!myShape->isNull())) {
- ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl<TopoDS_Shape>(),
- mySelectedObject, mySketch);
- if (aObj) {
- PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;
- that->mySelectedObject = aObj;
- } else
- return false;
+ if (myExternalObject.get()) {
+ DocumentPtr aDoc = myExternalObject->document();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
+ if (aFeature.get() != NULL) {
+ // 1. check whether the external object can be deleted
+ // It should not be deleted if there are references to the object from other features,
+ // which are not the sketch or a rigid constraints.
+ std::set<FeaturePtr> aRefFeatures;
+ aFeature->document()->refsToFeature(aFeature, aRefFeatures, false);
+ std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
+ aLast = aRefFeatures.end();
+ bool aReferenceExist = false;
+ CompositeFeaturePtr aSketch = sketch();
+ for (; anIt != aLast && !aReferenceExist; anIt++) {
+ FeaturePtr aFeature = (*anIt);
+ aReferenceExist = aFeature != aSketch &&
+ aFeature->getKind() != SketchPlugin_ConstraintRigid::ID();
+ }
+ if (aReferenceExist)
+ return;
+
+ // 2. delete external object
+ QObjectPtrList anObjects;
+ anObjects.append(aFeature);
+ // the external feature should be removed with all references, sketch feature should be ignored
+ std::set<FeaturePtr> anIgnoredFeatures;
+ anIgnoredFeatures.insert(sketch());
+ XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);