void Model_Objects::eraseAllFeatures()
{
- ModelAPI_EventCreator::get()->sendDeleted(myDoc, ModelAPI_Feature::group());
+ static Events_ID kDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ static const ModelAPI_EventCreator* kCreator = ModelAPI_EventCreator::get();
+ // make all features invalid (like deleted)
+ NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myFeatures);
+ for(; aFIter.More(); aFIter.Next()) {
+ FeaturePtr aFeature = aFIter.Value();
+ std::list<ResultPtr> aResList;
+ ModelAPI_Tools::allResults(aFeature, aResList);
+ std::list<ResultPtr>::iterator aRIter = aResList.begin();
+ for(; aRIter != aResList.end(); aRIter++) {
+ ResultPtr aRes = *aRIter;
+ if (aRes && aRes->data()->isValid()) {
+ kCreator->sendDeleted(myDoc, aRes->groupName());
+ kCreator->sendUpdated(aRes, kDispEvent);
+ aRes->setData(aRes->data()->invalidPtr());
+
+ }
+ }
+ kCreator->sendUpdated(aFeature, kDispEvent);
+ aFeature->setData(aFeature->data()->invalidPtr());
+ }
+ kCreator->sendDeleted(myDoc, ModelAPI_Feature::group());
myFeatures.Clear(); // just remove features without modification of DS
updateHistory(ModelAPI_Feature::group());
}
for(int a = aDoc->size(aBodyGroup) - 1; a >= 0; a--) {
ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(aDoc->object(aBodyGroup, a));
// "object" method filters out disabled and concealed anyway, so don't check
- if (aBody.get() && aBody->shape().get()) {
+ if (aBody.get() && aBody->data()->isValid() && aBody->shape().get()) {
TopoDS_Shape aShape = *(aBody->shape()->implPtr<TopoDS_Shape>());
if (!aShape.IsNull()) {
aBuilder.Add(aResultComp, aShape);
ModelAPI_Feature::~ModelAPI_Feature()
{
- erase();
+ if (data() && data()->isValid())
+ erase();
}
FeaturePtr ModelAPI_Feature::feature(ObjectPtr theObject)
ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
if (aResult.get()) {
DocumentPtr aDoc = aResult->partDoc();
- aDoc->eraseAllFeatures();
+ if (aDoc.get())
+ aDoc->eraseAllFeatures();
}
ModelAPI_Feature::erase();
}
if (aPart.get()) {
FeaturePtr aFeature = aRoot->feature(aPart);
if (aFeature) {
- // do remove
- aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
+ // do remove, but don't do real close (features are erased without persistence changes
+ // document remove may be undoed)
+ // aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
std::set<std::shared_ptr<ModelAPI_Feature> > aRefFeatures;
aRoot->refsToFeature(aFeature, aRefFeatures);
if (aRefFeatures.empty()) {
} else {
// this is an object under sub document root
std::string aType = myXMLReader->subType();
- int aCount = theRow - aNbSubFolders;
- // To check number of objects before using
- if (aSubDoc->size(aType) <= aCount)
- return QModelIndex();
- ObjectPtr aObj = aSubDoc->object(aType, aCount);
+ ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders);
aIndex = objectIndex(aObj);
}
} else {