1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Model_Session.h>
21 #include <ModelAPI_Feature.h>
22 #include <ModelAPI_Plugin.h>
23 #include <Model_Data.h>
24 #include <Model_Document.h>
25 #include <Model_Objects.h>
26 #include <Model_Application.h>
27 #include <Model_Events.h>
28 #include <Model_Validator.h>
29 #include <Model_FiltersFactory.h>
30 #include <ModelAPI_Events.h>
31 #include <Events_Loop.h>
32 #include <Events_InfoMessage.h>
33 #include <Config_FeatureMessage.h>
34 #include <Config_AttributeMessage.h>
35 #include <Config_ValidatorMessage.h>
36 #include <Config_ModuleReader.h>
37 #include <Config_ValidatorReader.h>
38 #include <Config_PluginMessage.h>
40 #include <ModelAPI_CompositeFeature.h>
41 #include <ModelAPI_ResultPart.h>
42 #include <ModelAPI_Tools.h>
44 #include <TDF_ChildIDIterator.hxx>
45 #include <TDF_CopyTool.hxx>
46 #include <TDF_DataSet.hxx>
47 #include <TDF_RelocationTable.hxx>
48 #include <TDF_ClosureTool.hxx>
50 #include <TNaming_Builder.hxx>
51 #include <TNaming_Iterator.hxx>
52 #include <TNaming_NamedShape.hxx>
54 #include <TopoDS_Shape.hxx>
56 static Model_Session* myImpl = new Model_Session();
58 // to redirect all calls to the root document
59 #define ROOT_DOC std::dynamic_pointer_cast<Model_Document>(moduleDocument())
61 bool Model_Session::load(const char* theFileName)
63 bool aRes = ROOT_DOC->load(theFileName, "root", ROOT_DOC);
67 bool Model_Session::save(const char* theFileName, std::list<std::string>& theResults)
69 return ROOT_DOC->save(theFileName, "root", theResults);
72 void Model_Session::closeAll()
74 Model_Application::getApplication()->deleteAllDocuments();
75 static const Events_ID aDocChangeEvent = Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED);
77 static std::shared_ptr<Events_Message> aMsg(new Events_Message(aDocChangeEvent));
78 Events_Loop::loop()->send(aMsg);
79 Events_Loop::loop()->flush(aDocChangeEvent);
82 void Model_Session::startOperation(const std::string& theId, const bool theAttachedToNested)
84 myOperationAttachedToNext.push_back(theAttachedToNested);
85 ROOT_DOC->startOperation();
86 ROOT_DOC->operationId(theId);
87 static std::shared_ptr<Events_Message> aStartedMsg
88 (new Events_Message(Events_Loop::eventByName("StartOperation")));
89 Events_Loop::loop()->send(aStartedMsg);
90 // remove all useless documents that has been closed: on start of operation undo/redo is cleared
91 // MPV: this code is dangerous now because it may close the document that is activated right now
92 // but not in the list of the opened documents yet (create, delete, undo, activate Part)
93 // later this must be updated by correct usage of uniques IDs of documents, not names of results
94 //std::list<std::shared_ptr<ModelAPI_Document> > aUsedDocs = allOpenedDocuments();
95 //Model_Application::getApplication()->removeUselessDocuments(aUsedDocs);
98 void Model_Session::finishOperation()
100 setCheckTransactions(false);
101 ROOT_DOC->finishOperation();
102 if (!myOperationAttachedToNext.empty()) {
103 while (myOperationAttachedToNext.back()) {
104 // with nested, the first transaction can not be attached
105 ROOT_DOC->finishOperation();
106 myOperationAttachedToNext.pop_back();
108 myOperationAttachedToNext.pop_back();
110 setCheckTransactions(true);
113 void Model_Session::abortOperation()
115 setCheckTransactions(false);
116 ROOT_DOC->abortOperation();
117 if (!myOperationAttachedToNext.empty()) {
118 while (myOperationAttachedToNext.back()) {
119 // with nested, the first transaction can not be attached
120 ROOT_DOC->abortOperation();
121 myOperationAttachedToNext.pop_back();
123 myOperationAttachedToNext.pop_back();
125 setCheckTransactions(true);
126 // here the update mechanism may work after abort, so, suppress the warnings about
127 // modifications outside of the transactions
128 bool aWasCheck = myCheckTransactions;
129 myCheckTransactions = false;
130 static std::shared_ptr<Events_Message> anAbortMsg
131 (new Events_Message(Events_Loop::eventByName("AbortOperation")));
132 Events_Loop::loop()->send(anAbortMsg);
133 myCheckTransactions = true;
134 myCheckTransactions = aWasCheck;
137 bool Model_Session::isOperation()
139 return ROOT_DOC->isOperation();
142 bool Model_Session::isModified()
144 return ROOT_DOC->isModified();
147 bool Model_Session::canUndo()
149 return ROOT_DOC->canUndo();
152 void Model_Session::undo()
154 setCheckTransactions(false);
156 setCheckTransactions(true);
159 bool Model_Session::canRedo()
161 return ROOT_DOC->canRedo();
164 void Model_Session::redo()
166 setCheckTransactions(false);
168 setCheckTransactions(true);
171 //! Returns stack of performed operations
172 std::list<std::string> Model_Session::undoList()
174 return ROOT_DOC->undoList();
176 //! Returns stack of rolled back operations
177 std::list<std::string> Model_Session::redoList()
179 return ROOT_DOC->redoList();
182 bool Model_Session::checkLicense(const std::string& thePluginName)
184 return getPlugin(thePluginName);
187 ModelAPI_Plugin* Model_Session::getPlugin(const std::string& thePluginName)
189 if (myPluginObjs.find(thePluginName) == myPluginObjs.end()) {
190 // before load the used plugins
191 if (myUsePlugins.find(thePluginName) != myUsePlugins.end()) {
192 std::string aUse = myUsePlugins[thePluginName];
193 std::stringstream aUseStream(aUse);
194 std::string aPluginName;
195 while (std::getline(aUseStream, aPluginName, ',')) {
196 if (myPluginObjs.find(aPluginName) == myPluginObjs.end())
197 getPlugin(aPluginName);
200 // load plugin library if not yet done
201 Config_ModuleReader::loadPlugin(thePluginName);
203 if (myPluginObjs.find(thePluginName) == myPluginObjs.end()) {
204 Events_InfoMessage("Model_Session", "Can not load plugin '%1'").arg(thePluginName).send();
207 return myPluginObjs[thePluginName];
210 FeaturePtr Model_Session::createFeature(std::string theFeatureID, Model_Document* theDocOwner)
212 if (this != myImpl) {
213 return myImpl->createFeature(theFeatureID, theDocOwner);
216 // load all information about plugins, features and attributes
219 if (myPlugins.find(theFeatureID) != myPlugins.end()) {
220 std::pair<std::string, std::string>& aPlugin = myPlugins[theFeatureID]; // plugin and doc kind
221 if (!aPlugin.second.empty() && aPlugin.second != theDocOwner->kind()) {
222 Events_InfoMessage("Model_Session",
223 "Feature '%1' can be created only in document '%2' by the XML definition")
224 .arg(theFeatureID).arg(aPlugin.second).send();
227 ModelAPI_Plugin* aPluginObj = getPlugin(aPlugin.first);
229 FeaturePtr aCreated = aPluginObj->createFeature(theFeatureID);
231 Events_InfoMessage("Model_Session", "Can not initialize feature '%1' in plugin '%2'")
232 .arg(theFeatureID).arg(aPlugin.first).send();
236 Events_InfoMessage("Model_Session", "Can not load plugin '%1'").arg(aPlugin.first).send();
239 Events_InfoMessage("Model_Session",
240 "Feature '%1' not found in any plugin").arg(theFeatureID).send();
243 return FeaturePtr(); // return nothing
246 std::shared_ptr<ModelAPI_Document> Model_Session::moduleDocument()
248 Handle(Model_Application) anApp = Model_Application::getApplication();
249 bool aFirstCall = !anApp->hasRoot();
251 // to be sure that plugins are loaded,
252 // even before the first "createFeature" call (in unit tests)
255 // creation of the root document is always outside of the transaction, so, avoid checking it
256 setCheckTransactions(false);
257 anApp->createDocument(0); // 0 is a root ID
258 // creation of the root document is always outside of the transaction, so, avoid checking it
259 setCheckTransactions(true);
260 if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id())) {
261 myCurrentDoc = moduleDocument();
262 static std::shared_ptr<Events_Message> aMsg(
263 new Events_Message(Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)));
264 Events_Loop::loop()->send(aMsg);
267 return anApp->rootDocument();
270 std::shared_ptr<ModelAPI_Document> Model_Session::document(int theDocID)
272 return std::shared_ptr<ModelAPI_Document>(
273 Model_Application::getApplication()->document(theDocID));
276 bool Model_Session::hasModuleDocument()
278 return Model_Application::getApplication()->hasRoot();
281 std::shared_ptr<ModelAPI_Document> Model_Session::activeDocument()
283 if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id())) {
284 return moduleDocument();
289 /// makes the last feature in the document as the current
290 static void makeCurrentLast(std::shared_ptr<ModelAPI_Document> theDoc) {
292 FeaturePtr aLast = std::dynamic_pointer_cast<Model_Document>(theDoc)->lastFeature();
293 // if last is nested into something else, make this something else as last:
294 // otherwise it will look like edition of sub-element, so, the main will be disabled
296 CompositeFeaturePtr aMain = ModelAPI_Tools::compositeOwner(aLast);
299 aMain = ModelAPI_Tools::compositeOwner(aLast);
302 theDoc->setCurrentFeature(aLast, false);
306 void Model_Session::setActiveDocument(
307 std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal)
309 if (myCurrentDoc != theDoc) {
310 if (myCurrentDoc.get())
311 myCurrentDoc->setActive(false);
313 theDoc->setActive(true);
315 std::shared_ptr<ModelAPI_Document> aPrevious = myCurrentDoc;
316 myCurrentDoc = theDoc;
317 if (theDoc.get() && theSendSignal) {
318 // this must be before the synchronization call because features in PartSet lower than this
319 // part feature must be disabled and don't recomputed anymore (issue 1156,
320 // translation feature is failed on activation of Part 2)
321 if (isOperation()) { // do it only in transaction, not on opening of document
322 DocumentPtr aRoot = moduleDocument();
323 if (myCurrentDoc != aRoot) {
324 FeaturePtr aPartFeat = ModelAPI_Tools::findPartFeature(aRoot, myCurrentDoc);
325 if (aPartFeat.get()) {
326 aRoot->setCurrentFeature(aPartFeat, false);
330 // synchronize the document: it may be just opened or opened but removed before
331 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(theDoc);
333 bool aWasChecked = myCheckTransactions;
334 setCheckTransactions(false);
335 TDF_LabelList anEmptyUpdated;
336 aDoc->objects()->synchronizeFeatures(anEmptyUpdated, true, true, false, true);
338 setCheckTransactions(true);
340 static std::shared_ptr<Events_Message> aMsg(
341 new Events_Message(Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)));
342 Events_Loop::loop()->send(aMsg);
344 // make the current state correct and synchronized in the module and sub-documents
345 if (isOperation()) { // do it only in transaction, not on opening of document
346 if (myCurrentDoc == moduleDocument()) {
347 // make the current feature the latest in root, in previous root current become also last
348 makeCurrentLast(aPrevious);
349 makeCurrentLast(myCurrentDoc);
351 // make the current feature the latest in sub, root current feature becomes this sub
352 makeCurrentLast(myCurrentDoc);
358 std::list<std::shared_ptr<ModelAPI_Document> > Model_Session::allOpenedDocuments()
360 std::list<std::shared_ptr<ModelAPI_Document> > aResult;
361 aResult.push_back(moduleDocument());
362 // add subs recursively
363 std::list<std::shared_ptr<ModelAPI_Document> >::iterator aDocIt = aResult.begin();
364 for(; aDocIt != aResult.end(); aDocIt++) {
365 DocumentPtr anAPIDoc = *aDocIt;
366 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(anAPIDoc);
368 const std::set<int> aSubs = aDoc->subDocuments();
369 std::set<int>::const_iterator aSubIter = aSubs.cbegin();
370 for(; aSubIter != aSubs.cend(); aSubIter++) {
371 aResult.push_back(Model_Application::getApplication()->document(*aSubIter));
378 bool Model_Session::isLoadByDemand(const std::wstring theDocID, const int theDocIndex)
380 return Model_Application::getApplication()->isLoadByDemand(theDocID, theDocIndex);
383 std::shared_ptr<ModelAPI_Document> Model_Session::copy(
384 std::shared_ptr<ModelAPI_Document> theSource, const int theDestID)
386 std::shared_ptr<Model_Document> aNew = Model_Application::getApplication()->document(theDestID);
387 // make a copy of all labels
388 TDF_Label aSourceRoot = std::dynamic_pointer_cast<Model_Document>(theSource)->document()->Main()
390 TDF_Label aTargetRoot = aNew->document()->Main().Father();
391 Handle(TDF_DataSet) aDS = new TDF_DataSet;
392 aDS->AddLabel(aSourceRoot);
393 TDF_ClosureTool::Closure(aDS);
394 Handle(TDF_RelocationTable) aRT = new TDF_RelocationTable(Standard_True);
395 aRT->SetRelocation(aSourceRoot, aTargetRoot);
396 TDF_CopyTool::Copy(aDS, aRT);
398 // TODO: remove after fix in OCCT.
399 // All named shapes are stored in reversed order, so to fix this we reverse them back.
400 for(TDF_ChildIDIterator aChildIter(aTargetRoot, TNaming_NamedShape::GetID(), true);
403 Handle(TNaming_NamedShape) aNamedShape =
404 Handle(TNaming_NamedShape)::DownCast(aChildIter.Value());
405 if (aNamedShape.IsNull()) {
409 TopoDS_Shape aShape = aNamedShape->Get();
410 if(aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND) {
414 TNaming_Evolution anEvol = aNamedShape->Evolution();
415 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> > aShapePairs; // to store old and new shapes
416 for(TNaming_Iterator anIter(aNamedShape); anIter.More(); anIter.Next()) {
417 aShapePairs.push_back(
418 std::pair<TopoDS_Shape, TopoDS_Shape>(anIter.OldShape(), anIter.NewShape()));
421 // Add in reverse order.
422 TDF_Label aLabel = aNamedShape->Label();
423 TNaming_Builder aBuilder(aLabel);
424 for(std::list<std::pair<TopoDS_Shape, TopoDS_Shape> >::iterator aPairsIter =
426 aPairsIter != aShapePairs.end();
428 if (anEvol == TNaming_GENERATED) {
429 aBuilder.Generated(aPairsIter->first, aPairsIter->second);
430 } else if (anEvol == TNaming_MODIFY) {
431 aBuilder.Modify(aPairsIter->first, aPairsIter->second);
432 } else if (anEvol == TNaming_DELETE) {
433 aBuilder.Delete(aPairsIter->first);
434 } else if (anEvol == TNaming_PRIMITIVE) {
435 aBuilder.Generated(aPairsIter->second);
436 } else if (anEvol == TNaming_SELECTED) {
437 aBuilder.Select(aPairsIter->second, aPairsIter->first);
442 TDF_LabelList anEmptyUpdated;
443 aNew->objects()->synchronizeFeatures(anEmptyUpdated, true, true, true, true);
447 Model_Session::Model_Session()
449 myPluginsInfoLoaded = false;
450 myCheckTransactions = true;
451 ModelAPI_Session::setSession(std::shared_ptr<ModelAPI_Session>(this));
452 // register the configuration reading listener
453 Events_Loop* aLoop = Events_Loop::loop();
454 static const Events_ID kFeatureEvent =
455 Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
456 aLoop->registerListener(this, kFeatureEvent);
457 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED), 0, true);
458 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED), 0, true);
459 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED), 0, true);
460 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED));
461 aLoop->registerListener(this, Events_Loop::eventByName(Config_PluginMessage::EVENT_ID()));
464 void Model_Session::processEvent(const std::shared_ptr<Events_Message>& theMessage)
466 static const Events_ID kFeatureEvent =
467 Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
468 static const Events_ID kValidatorEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
469 static const Events_ID kPluginEvent = Events_Loop::eventByName(Config_PluginMessage::EVENT_ID());
470 if (theMessage->eventID() == kFeatureEvent) {
471 const std::shared_ptr<Config_FeatureMessage> aMsg =
472 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
475 // process the plugin info, load plugin
476 if (myPlugins.find(aMsg->id()) == myPlugins.end()) {
477 myPlugins[aMsg->id()] = std::pair<std::string, std::string>(
478 aMsg->pluginLibrary(), aMsg->documentKind());
481 const std::shared_ptr<Config_AttributeMessage> aMsgAttr =
482 std::dynamic_pointer_cast<Config_AttributeMessage>(theMessage);
485 if (!aMsgAttr->isObligatory()) {
486 validators()->registerNotObligatory(aMsgAttr->featureId(), aMsgAttr->attributeId());
488 if(aMsgAttr->isConcealment()) {
489 validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId());
491 if(aMsgAttr->isMainArgument()) {
492 validators()->registerMainArgument(aMsgAttr->featureId(), aMsgAttr->attributeId());
494 const std::list<std::pair<std::string, std::string> >& aCases = aMsgAttr->getCases();
495 if (!aCases.empty()) {
496 validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(), aCases);
498 if (aMsgAttr->isGeometricalSelection()) {
499 validators()->registerGeometricalSelection(aMsgAttr->featureId(),
500 aMsgAttr->attributeId());
504 // plugins information was started to load, so, it will be loaded
505 myPluginsInfoLoaded = true;
506 } else if (theMessage->eventID() == kValidatorEvent) {
507 std::shared_ptr<Config_ValidatorMessage> aMsg =
508 std::dynamic_pointer_cast<Config_ValidatorMessage>(theMessage);
510 if (aMsg->attributeId().empty()) { // feature validator
511 validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->parameters());
512 } else { // attribute validator
513 validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->attributeId(),
517 } else if (theMessage->eventID() == kPluginEvent) { // plugin is started to load
518 std::shared_ptr<Config_PluginMessage> aMsg =
519 std::dynamic_pointer_cast<Config_PluginMessage>(theMessage);
521 myCurrentPluginName = aMsg->pluginId();
522 if (!aMsg->uses().empty()) {
523 myUsePlugins[myCurrentPluginName] = aMsg->uses();
526 } else { // create/update/delete
527 if (myCheckTransactions && !isOperation()) {
528 // check it is done in real opened document: 2958
529 bool aIsActual = true;
530 static const Events_ID kDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
531 if (theMessage->eventID() == kDeletedEvent) {
533 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleted =
534 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
535 std::list<std::shared_ptr<ModelAPI_Document> > allOpened =
536 Model_Session::allOpenedDocuments();
537 std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator
538 aGIter = aDeleted->groups().cbegin();
539 for (; !aIsActual && aGIter != aDeleted->groups().cend(); aGIter++) {
540 std::list<std::shared_ptr<ModelAPI_Document> >::iterator anOpened = allOpened.begin();
541 for(; anOpened != allOpened.end(); anOpened++) {
542 if (aGIter->first == *anOpened) {
551 Events_InfoMessage("Model_Session",
552 "Modification of data structure outside of the transaction").send();
554 // if part is deleted, make the root as the current document (on undo of Parts creations)
555 static const Events_ID kDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
556 if (theMessage->eventID() == kDeletedEvent) {
557 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleted =
558 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
560 std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator
561 aGIter = aDeleted->groups().cbegin();
562 for (; aGIter != aDeleted->groups().cend(); aGIter++) {
563 if (aGIter->second == ModelAPI_ResultPart::group())
566 if (aGIter != aDeleted->groups().cend())
568 // check that the current feature of the session is still the active Part (even disabled)
570 FeaturePtr aCurrentPart = moduleDocument()->currentFeature(true);
571 if (aCurrentPart.get()) {
572 const std::list<std::shared_ptr<ModelAPI_Result> >& aResList = aCurrentPart->results();
573 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResList.begin();
574 for(; !aFound && aRes != aResList.end(); aRes++) {
575 ResultPartPtr aPRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
576 if (aPRes.get() && aPRes->isActivated() && aPRes->partDoc() == activeDocument()) {
582 if (!aFound) { // if not, the part was removed, so activate the module document
583 if (myCurrentDoc.get())
584 setActiveDocument(moduleDocument());
591 void Model_Session::LoadPluginsInfo()
593 if (myPluginsInfoLoaded) // nothing to do
595 // Read plugins information from XML files
596 Config_ModuleReader aModuleReader(Config_FeatureMessage::MODEL_EVENT());
597 aModuleReader.readAll();
598 std::set<std::string> aFiles = aModuleReader.modulePluginFiles();
599 std::set<std::string>::iterator it = aFiles.begin();
600 for ( ; it != aFiles.end(); it++ ) {
601 Config_ValidatorReader aValidatorReader (*it);
602 aValidatorReader.readAll();
607 void Model_Session::registerPlugin(ModelAPI_Plugin* thePlugin)
609 myPluginObjs[myCurrentPluginName] = thePlugin;
610 static Events_ID EVENT_LOAD = Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED);
611 ModelAPI_EventCreator::get()->sendUpdated(ObjectPtr(), EVENT_LOAD, false);
612 // If the plugin has an ability to process GUI events, register it
613 Events_Listener* aListener = dynamic_cast<Events_Listener*>(thePlugin);
615 Events_Loop* aLoop = Events_Loop::loop();
616 static Events_ID aStateRequestEventId =
617 Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
618 aLoop->registerListener(aListener, aStateRequestEventId);
622 ModelAPI_ValidatorsFactory* Model_Session::validators()
624 static Model_ValidatorsFactory* aFactory = new Model_ValidatorsFactory;
628 ModelAPI_FiltersFactory* Model_Session::filters()
630 static Model_FiltersFactory* aFactory = new Model_FiltersFactory;
634 int Model_Session::transactionID()
636 return ROOT_DOC->transactionID();
639 bool Model_Session::isAutoUpdateBlocked()
641 Handle(Model_Application) anApp = Model_Application::getApplication();
642 if (!anApp->hasRoot()) // when document is not yet created, do not create it by such simple call
644 return !ROOT_DOC->autoRecomutationState();
647 void Model_Session::blockAutoUpdate(const bool theBlock)
649 bool aCurrentState = isAutoUpdateBlocked();
650 if (aCurrentState != theBlock) {
651 // if there is no operation, start it to avoid modifications outside of transaction
652 bool isOperation = this->isOperation();
654 startOperation("Auto update");
655 ROOT_DOC->setAutoRecomutationState(!theBlock);
656 static Events_Loop* aLoop = Events_Loop::loop();
658 static const Events_ID kAutoOff = aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_DISABLE);
659 std::shared_ptr<Events_Message> aMsg(new Events_Message(kAutoOff));
662 // if there is no operation, start it to avoid modifications outside of transaction
663 isOperation = this->isOperation();
665 startOperation("Auto update enabling");
666 static const Events_ID kAutoOn = aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_ENABLE);
667 std::shared_ptr<Events_Message> aMsg(new Events_Message(kAutoOn));
672 // append this transaction to the previous one: don't need this separated operation in list
673 ROOT_DOC->appendTransactionToPrevious();