From: mpv Date: Mon, 21 Jul 2014 13:16:53 +0000 (+0400) Subject: Implementation of automatic validators registration (defined in XML) X-Git-Tag: V_0.4.4~164^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4d039f66eee7d59886d9635d58c7b6d4a9031acc;p=modules%2Fshaper.git Implementation of automatic validators registration (defined in XML) --- diff --git a/src/Config/Config_ValidatorMessage.cpp b/src/Config/Config_ValidatorMessage.cpp index a5ac9699b..b70511796 100644 --- a/src/Config/Config_ValidatorMessage.cpp +++ b/src/Config/Config_ValidatorMessage.cpp @@ -1,7 +1,7 @@ /* * Config_ValidatorMessage.cpp * - * Created on: 08 èþëÿ 2014 ã. + * Created on: 08 Jul 2014 ã. * Author: sbh */ diff --git a/src/Config/Config_ValidatorMessage.h b/src/Config/Config_ValidatorMessage.h index 21bbf2475..f43c351b0 100644 --- a/src/Config/Config_ValidatorMessage.h +++ b/src/Config/Config_ValidatorMessage.h @@ -1,7 +1,7 @@ /* * Config_ValidatorMessage.h * - * Created on: 08 èþëÿ 2014 ã. + * Created on: 08 Jul 2014 ã. * Author: sbh */ @@ -31,8 +31,8 @@ public: //CONFIG_EXPORT static const char* UID() const; CONFIG_EXPORT const std::string& validatorId() const; - const std::string& featureId() const; - const std::string& attributeId() const; + CONFIG_EXPORT const std::string& featureId() const; + CONFIG_EXPORT const std::string& attributeId() const; CONFIG_EXPORT const std::list& parameters() const; CONFIG_EXPORT bool isValid() const; diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index 4f632cbc3..bbcc6cfdc 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -12,23 +12,24 @@ SET(PROJECT_SOURCES ConstructionPlugin_Point.cpp ) +SET(XML_RESOURCES + plugin-Construction.xml + point_widget.xml +) + ADD_DEFINITIONS(-DCONSTRUCTIONPLUGIN_EXPORTS ${BOOST_DEFINITIONS}) -ADD_LIBRARY(ConstructionPlugin SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +ADD_LIBRARY(ConstructionPlugin SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES}) TARGET_LINK_LIBRARIES(ConstructionPlugin ${PROJECT_LIBRARIES} ModelAPI GeomAPI GeomAlgoAPI) +INSTALL(TARGETS ConstructionPlugin DESTINATION plugins) +INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) + INCLUDE_DIRECTORIES( ../ModelAPI ../GeomAPI ../GeomAlgoAPI ) -SET(XML_RESOURCES - plugin-Construction.xml - point_widget.xml -) - -INSTALL(TARGETS ConstructionPlugin DESTINATION plugins) -INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) ADD_UNIT_TESTS(TestPointName.py ) diff --git a/src/ConstructionPlugin/plugin-Construction.xml b/src/ConstructionPlugin/plugin-Construction.xml index 0918dc9cd..381a3e656 100644 --- a/src/ConstructionPlugin/plugin-Construction.xml +++ b/src/ConstructionPlugin/plugin-Construction.xml @@ -2,11 +2,11 @@ - + - + diff --git a/src/Model/Model_PluginManager.cpp b/src/Model/Model_PluginManager.cpp index 1dabf1990..cd262dcc7 100644 --- a/src/Model/Model_PluginManager.cpp +++ b/src/Model/Model_PluginManager.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -107,17 +108,19 @@ Model_PluginManager::Model_PluginManager() ModelAPI_PluginManager::setPluginManager(boost::shared_ptr(this)); // register the configuration reading listener Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID FeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent"); - aLoop->registerListener(this, FeatureEvent); + static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent"); + aLoop->registerListener(this, kFeatureEvent); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED)); } void Model_PluginManager::processEvent(const Events_Message* theMessage) { - static Events_ID FeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent"); - if (theMessage->eventID() == FeatureEvent) { + static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent"); + static const Events_ID kValidatorEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED); + if (theMessage->eventID() == kFeatureEvent) { const Config_FeatureMessage* aMsg = dynamic_cast(theMessage); if (aMsg) { @@ -128,6 +131,16 @@ void Model_PluginManager::processEvent(const Events_Message* theMessage) } // plugins information was started to load, so, it will be loaded myPluginsInfoLoaded = true; + } else if (theMessage->eventID() == kValidatorEvent) { + const Config_ValidatorMessage* aMsg = dynamic_cast(theMessage); + if (aMsg) { + if (aMsg->attributeId().empty()) { // feature validator + validators()->assignValidator(aMsg->validatorId(), aMsg->featureId()); + } else { // attribute validator + validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), + aMsg->attributeId(), aMsg->parameters()); + } + } } else { // create/update/delete if (myCheckTransactions && !rootDocument()->isOperation()) Events_Error::send("Modification of data structure outside of the transaction"); diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index 3f6e1c6ca..771ea6c34 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -28,8 +28,9 @@ void Model_ValidatorsFactory::assignValidator(const string& theID, const string& isError = true; } if (myFeatures.find(theFeatureID) != myFeatures.end()) { - Events_Error::send( - string("Validator for feature ") + theFeatureID + " is already registered"); + // TODO: it is called many times now because of not-optimized XML reader + //Events_Error::send( + // string("Validator for feature ") + theFeatureID + " is already registered"); isError = true; } if (!isError) @@ -62,9 +63,10 @@ void Model_ValidatorsFactory::assignValidator(const string& theID, pair >(aVal->second, theArguments); } } else { - Events_Error::send( - string("Validator ") + theID + " for feature " + theFeatureID + - "attribute " + theAttrID + " is already registered"); + // TODO: it is called many times now because of not-optimized XML reader + //Events_Error::send( + // string("Validator ") + theID + " for feature " + theFeatureID + + // "attribute " + theAttrID + " is already registered"); isError = true; } }