+/// makes the last feature in the document as the current
+static void makeCurrentLast(std::shared_ptr<ModelAPI_Document> theDoc) {
+ if (theDoc.get()) {
+ FeaturePtr aLast = std::dynamic_pointer_cast<Model_Document>(theDoc)->lastFeature();
+ // if last is nested into something else, make this something else as last:
+ // otherwise it will look like edition of sub-element, so, the main will be disabled
+ if (aLast.get()) {
+ CompositeFeaturePtr aMain = ModelAPI_Tools::compositeOwner(aLast);
+ while(aMain.get()) {
+ aLast = aMain;
+ aMain = ModelAPI_Tools::compositeOwner(aLast);
+ }
+ }
+ theDoc->setCurrentFeature(aLast, false);
+ }
+}
+
+void Model_Session::setActiveDocument(
+ std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal)
+{
+ if (myCurrentDoc != theDoc) {
+ if (myCurrentDoc.get())
+ myCurrentDoc->setActive(false);
+ if (theDoc.get())
+ theDoc->setActive(true);
+
+ std::shared_ptr<ModelAPI_Document> aPrevious = myCurrentDoc;
+ myCurrentDoc = theDoc;
+ if (theDoc.get() && theSendSignal) {
+ // this must be before the synchronisation call because features in PartSet lower than this
+ // part feature must be disabled and don't recomputed anymore (issue 1156,
+ // translation feature is failed on activation of Part 2)
+ if (isOperation()) { // do it only in transaction, not on opening of document
+ DocumentPtr aRoot = moduleDocument();
+ if (myCurrentDoc != aRoot) {
+ FeaturePtr aPartFeat = ModelAPI_Tools::findPartFeature(aRoot, myCurrentDoc);
+ if (aPartFeat.get()) {
+ aRoot->setCurrentFeature(aPartFeat, false);
+ }
+ }
+ }
+ // syncronize the document: it may be just opened or opened but removed before
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(theDoc);
+ if (aDoc.get()) {
+ bool aWasChecked = myCheckTransactions;
+ setCheckTransactions(false);
+ TDF_LabelList anEmptyUpdated;
+ aDoc->objects()->synchronizeFeatures(anEmptyUpdated, true, true, false, true);
+ if (aWasChecked)
+ setCheckTransactions(true);
+ }
+ static std::shared_ptr<Events_Message> aMsg(
+ new Events_Message(Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)));
+ Events_Loop::loop()->send(aMsg);
+ }
+ // make the current state correct and synchronised in the module and sub-documents
+ if (isOperation()) { // do it only in transaction, not on opening of document
+ if (myCurrentDoc == moduleDocument()) {
+ // make the current feature the latest in root, in previous root current become also last
+ makeCurrentLast(aPrevious);
+ makeCurrentLast(myCurrentDoc);
+ } else {
+ // make the current feature the latest in sub, root current feature becomes this sub
+ makeCurrentLast(myCurrentDoc);
+ }
+ }
+ }
+}
+
+std::list<std::shared_ptr<ModelAPI_Document> > Model_Session::allOpenedDocuments()