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