Remove the deleted feature from the list of sketch sub-elements.
void Model_AttributeRefList::remove(ObjectPtr theObject)
{
- std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
- myRef->Remove(aData->label().Father());
-
+ std::shared_ptr<Model_Data> aData;
+ if (theObject.get() != NULL) {
+ aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
+ myRef->Remove(aData->label().Father());
+ }
+ else { // in case of empty object remove, the first empty object is removed from the list
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+ owner()->document());
+ if (aDoc) {
+ const TDF_LabelList& aList = myRef->List();
+ for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
+ ObjectPtr anObj = aDoc->object(aLIter.Value());
+ if (anObj.get() == NULL) {
+ myRef->Remove(aLIter.Value());
+ break;
+ }
+ }
+ }
+ }
owner()->data()->sendAttributeUpdated(this);
}
std::shared_ptr<Model_Data> aData =
std::dynamic_pointer_cast<Model_Data>(theFeature->data());
if (aData && !aData->refsToMe().empty()) {
- theRefs.insert(theFeature);
+ const std::set<AttributePtr>& aRefs = aData->refsToMe();
+ std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin(), aRefLast = aRefs.end();
+ for(; aRefIt != aRefLast; aRefIt++) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
+ if (aFeature.get() != NULL)
+ theRefs.insert(aFeature);
+ }
}
if (!theRefs.empty() && isSendError) {
aCurrentOp->abort();
}
}
+ // sketch feature should be skipped, only sub-features can be removed
+ // when sketch operation is active
+ CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
ModuleBase_ISelection* aSel = aConnector->selection();
QObjectPtrList aSelectedObj = aSel->selectedPresentations();
aLast = aRefFeatures.end();
for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = (*anIt);
- std::string aFName = aFeature->data()->name().c_str();
- std::string aName = (*anIt)->name().c_str();
+ if (aFeature == aSketch)
+ continue;
aRefNames.append((*anIt)->name().c_str());
}
- QString aNames = aRefNames.join(", ");
-
- QMainWindow* aDesktop = aWorkshop->desktop();
- QMessageBox::StandardButton aRes = QMessageBox::warning(
- aDesktop, tr("Delete features"),
- QString(tr("Selected features are used in the following features: %1.\
-These features will be deleted also. Would you like to continue?")).arg(aNames),
- QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
- if (aRes != QMessageBox::Yes)
- return;
+ if (!aRefNames.empty()) {
+ QString aNames = aRefNames.join(", ");
+
+ QMainWindow* aDesktop = aWorkshop->desktop();
+ QMessageBox::StandardButton aRes = QMessageBox::warning(
+ aDesktop, tr("Delete features"),
+ QString(tr("Selected features are used in the following features: %1.\
+ These features will be deleted also. Would you like to continue?")).arg(aNames),
+ QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
+ if (aRes != QMessageBox::Yes)
+ return;
+ }
}
SessionPtr aMgr = ModelAPI_Session::get();
aLast = aRefFeatures.end();
for (; anIt != aLast; anIt++) {
FeaturePtr aRefFeature = (*anIt);
- DocumentPtr aDoc = aRefFeature->document();
- aDoc->removeFeature(aRefFeature);
- }
+ if (aRefFeature == aSketch)
+ continue;
+ aRefFeature->document()->removeFeature(aRefFeature);
+ }
foreach (ObjectPtr aObj, aSelectedObj)
{
mySketch = 0;
}
+void SketchPlugin_Feature::erase()
+{
+ SketchPlugin_Sketch* aSketch = sketch();
+ if (aSketch)
+ aSketch->removeFeature(this);
+
+ ModelAPI_Feature::erase();
+}
+
SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
{
if (!mySketch) {
// thePrs->setPointMarker(6, 2.);
}
+ /// removes also all sub-sketch elements
+ SKETCHPLUGIN_EXPORT virtual void erase();
+
/// Returns the sketch of this feature
SketchPlugin_Sketch* sketch();
protected:
return aNew;
}
+void SketchPlugin_Sketch::removeFeature(ModelAPI_Feature* theFeature)
+{
+ list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
+ list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
+ bool isRemoved = 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) {
+ data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(aFeature);
+ isRemoved = true;
+ }
+ }
+ // if the object is not found in the sketch sub-elements, that means that the object is removed already.
+ // Find the first empty element and remove it
+ if (!isRemoved)
+ data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(NULL);
+}
+
int SketchPlugin_Sketch::numberOfSubs() const
{
return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size();
/// removes also all sub-sketch elements
SKETCHPLUGIN_EXPORT virtual void erase();
+ /// 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);
+
/// Returns the number of sub-elements
SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;