Salome HOME
Merge branch 'Filters_Development_2' of https://codev-tuleap.cea.fr/plugins/git/salom...
[modules/shaper.git] / src / Model / Model_Session.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
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_Filter.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>
39
40 #include <ModelAPI_CompositeFeature.h>
41 #include <ModelAPI_ResultPart.h>
42 #include <ModelAPI_Tools.h>
43
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>
49
50 #include <TNaming_Builder.hxx>
51 #include <TNaming_Iterator.hxx>
52 #include <TNaming_NamedShape.hxx>
53
54 #include <TopoDS_Shape.hxx>
55
56 static Model_Session* myImpl = new Model_Session();
57
58 // to redirect all calls to the root document
59 #define ROOT_DOC std::dynamic_pointer_cast<Model_Document>(moduleDocument())
60
61 bool Model_Session::load(const char* theFileName)
62 {
63   bool aRes = ROOT_DOC->load(theFileName, "root", ROOT_DOC);
64   return aRes;
65 }
66
67 bool Model_Session::save(const char* theFileName, std::list<std::string>& theResults)
68 {
69   return ROOT_DOC->save(theFileName, "root", theResults);
70 }
71
72 void Model_Session::closeAll()
73 {
74   Model_Application::getApplication()->deleteAllDocuments();
75   static const Events_ID aDocChangeEvent = Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED);
76   static std::shared_ptr<Events_Message> aMsg(new Events_Message(aDocChangeEvent));
77   Events_Loop::loop()->send(aMsg);
78   Events_Loop::loop()->flush(aDocChangeEvent);
79 }
80
81 void Model_Session::startOperation(const std::string& theId, const bool theAttachedToNested)
82 {
83   myOperationAttachedToNext.push_back(theAttachedToNested);
84   ROOT_DOC->startOperation();
85   ROOT_DOC->operationId(theId);
86   static std::shared_ptr<Events_Message> aStartedMsg
87     (new Events_Message(Events_Loop::eventByName("StartOperation")));
88   Events_Loop::loop()->send(aStartedMsg);
89   // remove all useless documents that has been closed: on start of operation undo/redo is cleared
90   // MPV: this code is dangerous now because it may close the document that is activated right now
91   // but not in the list of the opened documents yet (create, delete, undo, activate Part)
92   // later this must be updated by correct usage of uniques IDs of documents, not names of results
93   //std::list<std::shared_ptr<ModelAPI_Document> > aUsedDocs = allOpenedDocuments();
94   //Model_Application::getApplication()->removeUselessDocuments(aUsedDocs);
95 }
96
97 void Model_Session::finishOperation()
98 {
99   setCheckTransactions(false);
100   ROOT_DOC->finishOperation();
101   while(myOperationAttachedToNext.back()) { // with nested, the first transaction can not be attached
102     ROOT_DOC->finishOperation();
103     myOperationAttachedToNext.pop_back();
104   }
105   myOperationAttachedToNext.pop_back();
106   setCheckTransactions(true);
107 }
108
109 void Model_Session::abortOperation()
110 {
111   setCheckTransactions(false);
112   ROOT_DOC->abortOperation();
113   while(myOperationAttachedToNext.back()) { // with nested, the first transaction can not be attached
114     ROOT_DOC->abortOperation();
115     myOperationAttachedToNext.pop_back();
116   }
117   myOperationAttachedToNext.pop_back();
118   setCheckTransactions(true);
119   // here the update mechanism may work after abort, so, suppress the warnings about
120   // modifications outside of the transactions
121   bool aWasCheck = myCheckTransactions;
122   myCheckTransactions = false;
123   static std::shared_ptr<Events_Message> anAbortMsg
124     (new Events_Message(Events_Loop::eventByName("AbortOperation")));
125   Events_Loop::loop()->send(anAbortMsg);
126   myCheckTransactions = true;
127   myCheckTransactions = aWasCheck;
128 }
129
130 bool Model_Session::isOperation()
131 {
132   return ROOT_DOC->isOperation();
133 }
134
135 bool Model_Session::isModified()
136 {
137   return ROOT_DOC->isModified();
138 }
139
140 bool Model_Session::canUndo()
141 {
142   return ROOT_DOC->canUndo();
143 }
144
145 void Model_Session::undo()
146 {
147   setCheckTransactions(false);
148   ROOT_DOC->undo();
149   setCheckTransactions(true);
150 }
151
152 bool Model_Session::canRedo()
153 {
154   return ROOT_DOC->canRedo();
155 }
156
157 void Model_Session::redo()
158 {
159   setCheckTransactions(false);
160   ROOT_DOC->redo();
161   setCheckTransactions(true);
162 }
163
164 //! Returns stack of performed operations
165 std::list<std::string> Model_Session::undoList()
166 {
167   return ROOT_DOC->undoList();
168 }
169 //! Returns stack of rolled back operations
170 std::list<std::string> Model_Session::redoList()
171 {
172   return ROOT_DOC->redoList();
173 }
174
175 ModelAPI_Plugin* Model_Session::getPlugin(const std::string& thePluginName)
176 {
177   if (myPluginObjs.find(thePluginName) == myPluginObjs.end()) {
178     // before load the used plugins
179     if (myUsePlugins.find(thePluginName) != myUsePlugins.end()) {
180       std::string aUse = myUsePlugins[thePluginName];
181       std::stringstream aUseStream(aUse);
182       std::string aPluginName;
183       while (std::getline(aUseStream, aPluginName, ',')) {
184         if (myPluginObjs.find(aPluginName) == myPluginObjs.end())
185           getPlugin(aPluginName);
186       }
187     }
188     // load plugin library if not yet done
189     Config_ModuleReader::loadPlugin(thePluginName);
190   }
191   if (myPluginObjs.find(thePluginName) == myPluginObjs.end()) {
192     Events_InfoMessage("Model_Session", "Can not load plugin '%1'").arg(thePluginName).send();
193     return NULL;
194   }
195   return myPluginObjs[thePluginName];
196 }
197
198 FeaturePtr Model_Session::createFeature(std::string theFeatureID, Model_Document* theDocOwner)
199 {
200   if (this != myImpl) {
201     return myImpl->createFeature(theFeatureID, theDocOwner);
202   }
203
204   // load all information about plugins, features and attributes
205   LoadPluginsInfo();
206
207   if (myPlugins.find(theFeatureID) != myPlugins.end()) {
208     std::pair<std::string, std::string>& aPlugin = myPlugins[theFeatureID]; // plugin and doc kind
209     if (!aPlugin.second.empty() && aPlugin.second != theDocOwner->kind()) {
210       Events_InfoMessage("Model_Session",
211         "Feature '%1' can be created only in document '%2' by the XML definition")
212         .arg(theFeatureID).arg(aPlugin.second).send();
213       return FeaturePtr();
214     }
215     ModelAPI_Plugin* aPluginObj = getPlugin(aPlugin.first);
216     if (aPluginObj) {
217       FeaturePtr aCreated = aPluginObj->createFeature(theFeatureID);
218       if (!aCreated) {
219         Events_InfoMessage("Model_Session", "Can not initialize feature '%1' in plugin '%2'")
220           .arg(theFeatureID).arg(aPlugin.first).send();
221       }
222       return aCreated;
223     } else {
224       Events_InfoMessage("Model_Session", "Can not load plugin '%1'").arg(aPlugin.first).send();
225     }
226   } else {
227     Events_InfoMessage("Model_Session",
228       "Feature '%1' not found in any plugin").arg(theFeatureID).send();
229   }
230
231   return FeaturePtr();  // return nothing
232 }
233
234 std::shared_ptr<ModelAPI_Document> Model_Session::moduleDocument()
235 {
236   Handle(Model_Application) anApp = Model_Application::getApplication();
237   bool aFirstCall = !anApp->hasRoot();
238   if (aFirstCall) {
239     // to be sure that plugins are loaded,
240     // even before the first "createFeature" call (in unit tests)
241
242     LoadPluginsInfo();
243     // creation of the root document is always outside of the transaction, so, avoid checking it
244     setCheckTransactions(false);
245     anApp->createDocument(0); // 0 is a root ID
246     // creation of the root document is always outside of the transaction, so, avoid checking it
247     setCheckTransactions(true);
248   }
249   return anApp->rootDocument();
250 }
251
252 std::shared_ptr<ModelAPI_Document> Model_Session::document(int theDocID)
253 {
254   return std::shared_ptr<ModelAPI_Document>(
255       Model_Application::getApplication()->document(theDocID));
256 }
257
258 bool Model_Session::hasModuleDocument()
259 {
260   return Model_Application::getApplication()->hasRoot();
261 }
262
263 std::shared_ptr<ModelAPI_Document> Model_Session::activeDocument()
264 {
265   if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id()))
266     myCurrentDoc = moduleDocument();
267   return myCurrentDoc;
268 }
269
270 /// makes the last feature in the document as the current
271 static void makeCurrentLast(std::shared_ptr<ModelAPI_Document> theDoc) {
272   if (theDoc.get()) {
273     FeaturePtr aLast = std::dynamic_pointer_cast<Model_Document>(theDoc)->lastFeature();
274     // if last is nested into something else, make this something else as last:
275     // otherwise it will look like edition of sub-element, so, the main will be disabled
276     if (aLast.get()) {
277       CompositeFeaturePtr aMain = ModelAPI_Tools::compositeOwner(aLast);
278       while(aMain.get()) {
279         aLast = aMain;
280         aMain = ModelAPI_Tools::compositeOwner(aLast);
281       }
282     }
283     theDoc->setCurrentFeature(aLast, false);
284   }
285 }
286
287 void Model_Session::setActiveDocument(
288   std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal)
289 {
290   if (myCurrentDoc != theDoc) {
291     if (myCurrentDoc.get())
292       myCurrentDoc->setActive(false);
293     if (theDoc.get())
294       theDoc->setActive(true);
295
296     std::shared_ptr<ModelAPI_Document> aPrevious = myCurrentDoc;
297     myCurrentDoc = theDoc;
298     if (theDoc.get() && theSendSignal) {
299       // this must be before the synchronization call because features in PartSet lower than this
300       // part feature must be disabled and don't recomputed anymore (issue 1156,
301       // translation feature is failed on activation of Part 2)
302       if (isOperation()) { // do it only in transaction, not on opening of document
303         DocumentPtr aRoot = moduleDocument();
304         if (myCurrentDoc != aRoot) {
305           FeaturePtr aPartFeat = ModelAPI_Tools::findPartFeature(aRoot, myCurrentDoc);
306           if (aPartFeat.get()) {
307             aRoot->setCurrentFeature(aPartFeat, false);
308           }
309         }
310       }
311       // synchronize the document: it may be just opened or opened but removed before
312       std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(theDoc);
313       if (aDoc.get()) {
314         bool aWasChecked = myCheckTransactions;
315         setCheckTransactions(false);
316         TDF_LabelList anEmptyUpdated;
317         aDoc->objects()->synchronizeFeatures(anEmptyUpdated, true, true, false, true);
318         if (aWasChecked)
319             setCheckTransactions(true);
320       }
321       static std::shared_ptr<Events_Message> aMsg(
322           new Events_Message(Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)));
323       Events_Loop::loop()->send(aMsg);
324     }
325     // make the current state correct and synchronized in the module and sub-documents
326     if (isOperation()) { // do it only in transaction, not on opening of document
327       if (myCurrentDoc == moduleDocument()) {
328         // make the current feature the latest in root, in previous root current become also last
329         makeCurrentLast(aPrevious);
330         makeCurrentLast(myCurrentDoc);
331       } else {
332         // make the current feature the latest in sub, root current feature becomes this sub
333         makeCurrentLast(myCurrentDoc);
334       }
335     }
336   }
337 }
338
339 std::list<std::shared_ptr<ModelAPI_Document> > Model_Session::allOpenedDocuments()
340 {
341   std::list<std::shared_ptr<ModelAPI_Document> > aResult;
342   aResult.push_back(moduleDocument());
343   // add subs recursively
344   std::list<std::shared_ptr<ModelAPI_Document> >::iterator aDoc = aResult.begin();
345   for(; aDoc != aResult.end(); aDoc++) {
346     DocumentPtr anAPIDoc = *aDoc;
347     std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(anAPIDoc);
348     if (aDoc) {
349       const std::set<int> aSubs = aDoc->subDocuments();
350       std::set<int>::const_iterator aSubIter = aSubs.cbegin();
351       for(; aSubIter != aSubs.cend(); aSubIter++) {
352         aResult.push_back(Model_Application::getApplication()->document(*aSubIter));
353       }
354     }
355   }
356   return aResult;
357 }
358
359 bool Model_Session::isLoadByDemand(const std::string theDocID, const int theDocIndex)
360 {
361   return Model_Application::getApplication()->isLoadByDemand(theDocID, theDocIndex);
362 }
363
364 std::shared_ptr<ModelAPI_Document> Model_Session::copy(
365     std::shared_ptr<ModelAPI_Document> theSource, const int theDestID)
366 {
367   std::shared_ptr<Model_Document> aNew = Model_Application::getApplication()->document(theDestID);
368   // make a copy of all labels
369   TDF_Label aSourceRoot = std::dynamic_pointer_cast<Model_Document>(theSource)->document()->Main()
370       .Father();
371   TDF_Label aTargetRoot = aNew->document()->Main().Father();
372   Handle(TDF_DataSet) aDS = new TDF_DataSet;
373   aDS->AddLabel(aSourceRoot);
374   TDF_ClosureTool::Closure(aDS);
375   Handle(TDF_RelocationTable) aRT = new TDF_RelocationTable(Standard_True);
376   aRT->SetRelocation(aSourceRoot, aTargetRoot);
377   TDF_CopyTool::Copy(aDS, aRT);
378
379   // TODO: remove after fix in OCCT.
380   // All named shapes are stored in reversed order, so to fix this we reverse them back.
381   for(TDF_ChildIDIterator aChildIter(aTargetRoot, TNaming_NamedShape::GetID(), true);
382       aChildIter.More();
383       aChildIter.Next()) {
384     Handle(TNaming_NamedShape) aNamedShape =
385       Handle(TNaming_NamedShape)::DownCast(aChildIter.Value());
386     if (aNamedShape.IsNull()) {
387       continue;
388     }
389
390     TopoDS_Shape aShape = aNamedShape->Get();
391     if(aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND) {
392       continue;
393     }
394
395     TNaming_Evolution anEvol = aNamedShape->Evolution();
396     std::list<std::pair<TopoDS_Shape, TopoDS_Shape> > aShapePairs; // to store old and new shapes
397     for(TNaming_Iterator anIter(aNamedShape); anIter.More(); anIter.Next()) {
398       aShapePairs.push_back(
399         std::pair<TopoDS_Shape, TopoDS_Shape>(anIter.OldShape(), anIter.NewShape()));
400     }
401
402     // Add in reverse order.
403     TDF_Label aLabel = aNamedShape->Label();
404     TNaming_Builder aBuilder(aLabel);
405     for(std::list<std::pair<TopoDS_Shape, TopoDS_Shape> >::iterator aPairsIter =
406           aShapePairs.begin();
407         aPairsIter != aShapePairs.end();
408         aPairsIter++) {
409       if (anEvol == TNaming_GENERATED) {
410         aBuilder.Generated(aPairsIter->first, aPairsIter->second);
411       } else if (anEvol == TNaming_MODIFY) {
412         aBuilder.Modify(aPairsIter->first, aPairsIter->second);
413       } else if (anEvol == TNaming_DELETE) {
414         aBuilder.Delete(aPairsIter->first);
415       } else if (anEvol == TNaming_PRIMITIVE) {
416         aBuilder.Generated(aPairsIter->second);
417       } else if (anEvol == TNaming_SELECTED) {
418         aBuilder.Select(aPairsIter->second, aPairsIter->first);
419       }
420     }
421   }
422
423   TDF_LabelList anEmptyUpdated;
424   aNew->objects()->synchronizeFeatures(anEmptyUpdated, true, true, true, true);
425   return aNew;
426 }
427
428 Model_Session::Model_Session()
429 {
430   myPluginsInfoLoaded = false;
431   myCheckTransactions = true;
432   ModelAPI_Session::setSession(std::shared_ptr<ModelAPI_Session>(this));
433   // register the configuration reading listener
434   Events_Loop* aLoop = Events_Loop::loop();
435   static const Events_ID kFeatureEvent =
436     Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
437   aLoop->registerListener(this, kFeatureEvent);
438   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED), 0, true);
439   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED), 0, true);
440   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED), 0, true);
441   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED));
442   aLoop->registerListener(this, Events_Loop::eventByName(Config_PluginMessage::EVENT_ID()));
443 }
444
445 void Model_Session::processEvent(const std::shared_ptr<Events_Message>& theMessage)
446 {
447   static const Events_ID kFeatureEvent =
448     Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
449   static const Events_ID kValidatorEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
450   static const Events_ID kPluginEvent = Events_Loop::eventByName(Config_PluginMessage::EVENT_ID());
451   if (theMessage->eventID() == kFeatureEvent) {
452     const std::shared_ptr<Config_FeatureMessage> aMsg =
453       std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
454     if (aMsg) {
455
456       // process the plugin info, load plugin
457       if (myPlugins.find(aMsg->id()) == myPlugins.end()) {
458         myPlugins[aMsg->id()] = std::pair<std::string, std::string>(
459           aMsg->pluginLibrary(), aMsg->documentKind());
460       }
461     } else {
462       const std::shared_ptr<Config_AttributeMessage> aMsgAttr =
463         std::dynamic_pointer_cast<Config_AttributeMessage>(theMessage);
464       if (aMsgAttr) {
465
466         if (!aMsgAttr->isObligatory()) {
467           validators()->registerNotObligatory(aMsgAttr->featureId(), aMsgAttr->attributeId());
468         }
469         if(aMsgAttr->isConcealment()) {
470           validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId());
471         }
472         if(aMsgAttr->isMainArgument()) {
473           validators()->registerMainArgument(aMsgAttr->featureId(), aMsgAttr->attributeId());
474         }
475         const std::list<std::pair<std::string, std::string> >& aCases = aMsgAttr->getCases();
476         if (!aCases.empty()) {
477           validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(), aCases);
478         }
479         if (aMsgAttr->isGeometricalSelection()) {
480           validators()->registerGeometricalSelection(aMsgAttr->featureId(),
481                                                      aMsgAttr->attributeId());
482         }
483       }
484     }
485     // plugins information was started to load, so, it will be loaded
486     myPluginsInfoLoaded = true;
487   } else if (theMessage->eventID() == kValidatorEvent) {
488     std::shared_ptr<Config_ValidatorMessage> aMsg =
489       std::dynamic_pointer_cast<Config_ValidatorMessage>(theMessage);
490     if (aMsg) {
491       if (aMsg->attributeId().empty()) {  // feature validator
492         validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->parameters());
493       } else {  // attribute validator
494         validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->attributeId(),
495                                       aMsg->parameters());
496       }
497     }
498   } else if (theMessage->eventID() == kPluginEvent) { // plugin is started to load
499     std::shared_ptr<Config_PluginMessage> aMsg =
500       std::dynamic_pointer_cast<Config_PluginMessage>(theMessage);
501     if (aMsg.get()) {
502       myCurrentPluginName = aMsg->pluginId();
503       if (!aMsg->uses().empty()) {
504         myUsePlugins[myCurrentPluginName] = aMsg->uses();
505       }
506     }
507   } else {  // create/update/delete
508     if (myCheckTransactions && !isOperation())
509       Events_InfoMessage("Model_Session",
510         "Modification of data structure outside of the transaction").send();
511     // if part is deleted, make the root as the current document (on undo of Parts creations)
512     static const Events_ID kDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
513     if (theMessage->eventID() == kDeletedEvent) {
514       std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleted =
515         std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
516
517       std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator
518         aGIter = aDeleted->groups().cbegin();
519       for (; aGIter != aDeleted->groups().cend(); aGIter++) {
520         if (aGIter->second == ModelAPI_ResultPart::group())
521           break;
522       }
523       if (aGIter != aDeleted->groups().cend())
524       {
525          // check that the current feature of the session is still the active Part (even disabled)
526         bool aFound = false;
527         FeaturePtr aCurrentPart = moduleDocument()->currentFeature(true);
528         if (aCurrentPart.get()) {
529           const std::list<std::shared_ptr<ModelAPI_Result> >& aResList = aCurrentPart->results();
530           std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResList.begin();
531           for(; !aFound && aRes != aResList.end(); aRes++) {
532             ResultPartPtr aPRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
533             if (aPRes.get() && aPRes->isActivated() && aPRes->partDoc() == activeDocument()) {
534               aFound = true;
535
536             }
537           }
538         }
539         if (!aFound) { // if not, the part was removed, so activate the module document
540           if (myCurrentDoc.get())
541             setActiveDocument(moduleDocument());
542         }
543       }
544     }
545   }
546 }
547
548 void Model_Session::LoadPluginsInfo()
549 {
550   if (myPluginsInfoLoaded)  // nothing to do
551     return;
552   // Read plugins information from XML files
553   Config_ModuleReader aModuleReader(Config_FeatureMessage::MODEL_EVENT());
554   aModuleReader.readAll();
555   std::set<std::string> aFiles = aModuleReader.modulePluginFiles();
556   std::set<std::string>::iterator it = aFiles.begin();
557   for ( ; it != aFiles.end(); it++ ) {
558     Config_ValidatorReader aValidatorReader (*it);
559     aValidatorReader.readAll();
560   };
561
562 }
563
564 void Model_Session::registerPlugin(ModelAPI_Plugin* thePlugin)
565 {
566   myPluginObjs[myCurrentPluginName] = thePlugin;
567   static Events_ID EVENT_LOAD = Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED);
568   ModelAPI_EventCreator::get()->sendUpdated(ObjectPtr(), EVENT_LOAD, false);
569   // If the plugin has an ability to process GUI events, register it
570   Events_Listener* aListener = dynamic_cast<Events_Listener*>(thePlugin);
571   if (aListener) {
572     Events_Loop* aLoop = Events_Loop::loop();
573     static Events_ID aStateRequestEventId =
574         Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
575     aLoop->registerListener(aListener, aStateRequestEventId);
576   }
577 }
578
579 ModelAPI_ValidatorsFactory* Model_Session::validators()
580 {
581   static Model_ValidatorsFactory* aFactory = new Model_ValidatorsFactory;
582   return aFactory;
583 }
584
585 ModelAPI_FiltersFactory* Model_Session::filters()
586 {
587   static Model_FiltersFactory* aFactory = new Model_FiltersFactory;
588   return aFactory;
589 }
590
591 int Model_Session::transactionID()
592 {
593   return ROOT_DOC->transactionID();
594 }
595
596 bool Model_Session::isAutoUpdateBlocked()
597 {
598   Handle(Model_Application) anApp = Model_Application::getApplication();
599   if (!anApp->hasRoot()) // when document is not yet created, do not create it by such simple call
600     return false;
601   return !ROOT_DOC->autoRecomutationState();
602 }
603
604 void Model_Session::blockAutoUpdate(const bool theBlock)
605 {
606   bool aCurrentState = isAutoUpdateBlocked();
607   if (aCurrentState != theBlock) {
608     // if there is no operation, start it to avoid modifications outside of transaction
609     bool isOperation = this->isOperation();
610     if (!isOperation)
611       startOperation("Auto update");
612     ROOT_DOC->setAutoRecomutationState(!theBlock);
613     static Events_Loop* aLoop = Events_Loop::loop();
614     if (theBlock) {
615       static const Events_ID kAutoOff = aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_DISABLE);
616       std::shared_ptr<Events_Message> aMsg(new Events_Message(kAutoOff));
617       aLoop->send(aMsg);
618     } else {
619       // if there is no operation, start it to avoid modifications outside of transaction
620       bool isOperation = this->isOperation();
621       if (!isOperation)
622         startOperation("Auto update enabling");
623       static const Events_ID kAutoOn = aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_ENABLE);
624       std::shared_ptr<Events_Message> aMsg(new Events_Message(kAutoOn));
625       aLoop->send(aMsg);
626     }
627     if (!isOperation) {
628       finishOperation();
629       // append this transaction to the previous one: don't need this separated operation in list
630       ROOT_DOC->appendTransactionToPrevious();
631     }
632   }
633 }