return myLoadedByDemand.find(theID) != myLoadedByDemand.end();
}
+//=======================================================================
+void Model_Application::removeUselessDocuments(
+ std::list<std::shared_ptr<ModelAPI_Document> > theUsedDocs)
+{
+ std::map<std::string, std::shared_ptr<Model_Document> >::iterator aDoc = myDocs.begin();
+ while(aDoc != myDocs.end()) {
+ bool aFound = false;
+ std::list<std::shared_ptr<ModelAPI_Document> >::iterator aUsed = theUsedDocs.begin();
+ for(; !aFound && aUsed != theUsedDocs.end(); aUsed++) {
+ aFound = aDoc->second == *aUsed;
+ }
+ if (!aFound) { // remove the useless
+ aDoc->second->close();
+ aDoc = myDocs.erase(aDoc);
+ } else {
+ aDoc++;
+ }
+ }
+}
+
//=======================================================================
Model_Application::Model_Application()
{
void setLoadByDemand(std::string theID);
//! Returns true if specified document must be loaded by demand
bool isLoadByDemand(std::string theID);
+ //! Closes and removes the documents that are not loaded by demand and
+ //! not in the given list
+ void removeUselessDocuments(std::list<std::shared_ptr<ModelAPI_Document> > theUsedDocs);
public:
// Redefined OCAF methods
std::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::attr()
{
ObjectPtr anObj = object();
- if (anObj) {
+ if (anObj && anObj->data()) {
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(anObj->data());
return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString());
}
for (; aLabIter.More(); aLabIter.Next()) {
TDF_Label aFLabel = aLabIter.Value()->Label();
FeaturePtr aFeature = feature(aFLabel);
- const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
- for (; aRIter != aResults.cend(); aRIter++) {
- if ((*aRIter)->groupName() != ModelAPI_ResultPart::group()) continue;
- if ((*aRIter)->isInHistory()) {
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRIter);
- if (aPart && (!theActivatedOnly || aPart->isActivated()))
- aResult.insert(aPart->data()->name());
+ if (aFeature.get()) { // if document is closed the feature may be not in myObjs map
+ const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for (; aRIter != aResults.cend(); aRIter++) {
+ if ((*aRIter)->groupName() != ModelAPI_ResultPart::group()) continue;
+ if ((*aRIter)->isInHistory()) {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRIter);
+ if (aPart && (!theActivatedOnly || aPart->isActivated()))
+ aResult.insert(aPart->data()->name());
+ }
}
}
}
static std::shared_ptr<Events_Message> aStartedMsg
(new Events_Message(Events_Loop::eventByName("StartOperation")));
Events_Loop::loop()->send(aStartedMsg);
+ // remove all useless documents that has been closed: on start of operation undo/redo is cleared
+ std::list<std::shared_ptr<ModelAPI_Document> > aUsedDocs = allOpenedDocuments();
+ Model_Application::getApplication()->removeUselessDocuments(aUsedDocs);
}
void Model_Session::finishOperation()