#include <TDF_RelocationTable.hxx>
#include <TDF_ClosureTool.hxx>
-using namespace std;
-
-#include <iostream>
-
static Model_Session* myImpl = new Model_Session();
// t oredirect all calls to the root document
return ROOT_DOC->redoList();
}
-FeaturePtr Model_Session::createFeature(string theFeatureID, Model_Document* theDocOwner)
+FeaturePtr Model_Session::createFeature(std::string theFeatureID, Model_Document* theDocOwner)
{
if (this != myImpl) {
return myImpl->createFeature(theFeatureID, theDocOwner);
}
return aCreated;
} else {
- Events_InfoMessage("Model_Session","Can not load plugin '%1'").arg(myCurrentPluginName).send();
+ Events_InfoMessage("Model_Session",
+ "Can not load plugin '%1'").arg(myCurrentPluginName).send();
}
} else {
- Events_InfoMessage("Model_Session","Feature '%1' not found in any plugin").arg(theFeatureID).send();
+ Events_InfoMessage("Model_Session",
+ "Feature '%1' not found in any plugin").arg(theFeatureID).send();
}
return FeaturePtr(); // return nothing
Handle(Model_Application) anApp = Model_Application::getApplication();
bool aFirstCall = !anApp->hasRoot();
if (aFirstCall) {
- // to be sure that plugins are loaded, even before the first "createFeature" call (in unit tests)
+ // to be sure that plugins are loaded,
+ // even before the first "createFeature" call (in unit tests)
LoadPluginsInfo();
// creation of the root document is always outside of the transaction, so, avoid checking it
setCheckTransactions(false);
std::list<std::shared_ptr<ModelAPI_Document> > Model_Session::allOpenedDocuments()
{
- list<std::shared_ptr<ModelAPI_Document> > aResult;
+ std::list<std::shared_ptr<ModelAPI_Document> > aResult;
aResult.push_back(moduleDocument());
// add subs recursively
- list<std::shared_ptr<ModelAPI_Document> >::iterator aDoc = aResult.begin();
+ std::list<std::shared_ptr<ModelAPI_Document> >::iterator aDoc = aResult.begin();
for(; aDoc != aResult.end(); aDoc++) {
DocumentPtr anAPIDoc = *aDoc;
std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(anAPIDoc);
ModelAPI_Session::setSession(std::shared_ptr<ModelAPI_Session>(this));
// register the configuration reading listener
Events_Loop* aLoop = Events_Loop::loop();
- static const Events_ID kFeatureEvent =
+ static const Events_ID kFeatureEvent =
Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
aLoop->registerListener(this, kFeatureEvent);
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED), 0, true);
void Model_Session::processEvent(const std::shared_ptr<Events_Message>& theMessage)
{
- static const Events_ID kFeatureEvent =
+ static const Events_ID kFeatureEvent =
Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
static const Events_ID kValidatorEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
if (theMessage->eventID() == kFeatureEvent) {
- const std::shared_ptr<Config_FeatureMessage> aMsg =
+ const std::shared_ptr<Config_FeatureMessage> aMsg =
std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
if (aMsg) {
-// std::cout << "Feature: " << aMsg->id() << std::endl;
-
// process the plugin info, load plugin
if (myPlugins.find(aMsg->id()) == myPlugins.end()) {
myPlugins[aMsg->id()] = std::pair<std::string, std::string>(
aMsg->pluginLibrary(), aMsg->documentKind());
}
} else {
- const std::shared_ptr<Config_AttributeMessage> aMsgAttr =
+ const std::shared_ptr<Config_AttributeMessage> aMsgAttr =
std::dynamic_pointer_cast<Config_AttributeMessage>(theMessage);
if (aMsgAttr) {
-// std::cout << "Feature: " << aMsgAttr->featureId()
-// << ", Attribute: " << aMsgAttr->attributeId() << std::endl;
-
if (!aMsgAttr->isObligatory()) {
validators()->registerNotObligatory(aMsgAttr->featureId(), aMsgAttr->attributeId());
- } else {
- std::cout << "F: " << aMsgAttr->featureId()
- << ", V: Model_FeatureValidator"
- << ", A: " << aMsgAttr->attributeId()
- << std::endl;
}
if(aMsgAttr->isConcealment()) {
validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId());
}
- if (!aMsgAttr->caseId().empty()) {
- validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(),
- aMsgAttr->switchId(), aMsgAttr->caseId());
+ const std::list<std::pair<std::string, std::string> >& aCases = aMsgAttr->getCases();
+ if (!aCases.empty()) {
+ validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(), aCases);
}
}
}
// plugins information was started to load, so, it will be loaded
myPluginsInfoLoaded = true;
} else if (theMessage->eventID() == kValidatorEvent) {
-
- static bool done = false;
- if (!done) {
- std::set<std::string> aPlugins;
- for (auto it = myPlugins.begin(); it != myPlugins.end(); ++it) {
- std::string aPluginName = it->second.first;
- aPlugins.insert(aPluginName);
- }
-
- for (auto it = aPlugins.begin(); it != aPlugins.end(); ++it) {
- myCurrentPluginName = *it;
- Config_ModuleReader::loadPlugin(*it);
- }
-
- done = true;
- }
-
- std::shared_ptr<Config_ValidatorMessage> aMsg =
+ std::shared_ptr<Config_ValidatorMessage> aMsg =
std::dynamic_pointer_cast<Config_ValidatorMessage>(theMessage);
if (aMsg) {
if (aMsg->attributeId().empty()) { // feature validator
-
- std::cout << "F: " << aMsg->featureId()
- << ", V: " << aMsg->validatorId() << std::endl;
-
validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->parameters());
} else { // attribute validator
-
- std::cout << "F: " << aMsg->featureId()
- << ", A: " << aMsg->attributeId()
- << ", V: " << aMsg->validatorId() << std::endl;
-
validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->attributeId(),
aMsg->parameters());
}
}
} else { // create/update/delete
if (myCheckTransactions && !isOperation())
- Events_InfoMessage("Model_Session", "Modification of data structure outside of the transaction").send();
+ Events_InfoMessage("Model_Session",
+ "Modification of data structure outside of the transaction").send();
// if part is deleted, make the root as the current document (on undo of Parts creations)
static const Events_ID kDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
if (theMessage->eventID() == kDeletedEvent) {
std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleted =
std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
- if (aDeleted &&
+ if (aDeleted &&
aDeleted->groups().find(ModelAPI_ResultPart::group()) != aDeleted->groups().end())
{
// check that the current feature of the session is still the active Part (even disabled)
{
return ROOT_DOC->transactionID();
}
+
+void Model_Session::forceLoadPlugin(const std::string& thePluginName)
+{
+ // load all information about plugins, features and attributes
+ LoadPluginsInfo();
+
+ // store name of current plugin for further restoring,
+ // because forceLoadPlugin may be called while loading another plugin
+ std::string aCurrentPluginName = myCurrentPluginName;
+
+ myCurrentPluginName = thePluginName;
+ if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
+ // load plugin library if not yet done
+ Config_ModuleReader::loadPlugin(myCurrentPluginName);
+ }
+
+ // restore current plugin
+ myCurrentPluginName = aCurrentPluginName;
+}