- QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
- for (; anIt != aLast; anIt++) {
- ObjectPtr anObject = *anIt;
- if (anObject.get()) {
- DocumentPtr aDoc = anObject->document();
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- if (aFeature.get() != NULL) {
- 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(theSketch);
- // the current feature should be ignored, because it can use the external feature in the
- // attributes and, therefore have a references to it. So, the delete functionality tries
- // to delete this feature. Test case is creation of a constraint on external point,
- // use in this control after an external point, the point of the sketch.
- anIgnoredFeatures.insert(theFeature);
- XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
+ std::shared_ptr<SketchPlugin_Feature> aSPFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+ // there is no a sketch feature is selected, but the shape exists,
+ // try to create an exernal object
+ // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
+ if (aSPFeature.get() == NULL) {
+ ObjectPtr anExternalObject = ObjectPtr();
+ GeomShapePtr anExternalShape = GeomShapePtr();
+ if (useExternal()) {
+ if (canCreateExternal()) {
+ GeomShapePtr aShape = theShape;
+ if (!aShape.get()) {
+ ResultPtr aResult = theWorkshop->selection()->getResult(thePrs);
+ if (aResult.get())
+ aShape = aResult->shape();
+ }
+ if (aShape.get() != NULL && !aShape->isNull())
+ anExternalObject =
+ externalObject(theObject, aShape, theSketch, isInValidate);
+ }
+ else { /// use objects of found selection
+ anExternalObject = theObject;
+ anExternalShape = theShape;