]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implementation of automatic validators registration (defined in XML)
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 21 Jul 2014 13:16:53 +0000 (17:16 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Mon, 21 Jul 2014 13:16:53 +0000 (17:16 +0400)
src/Config/Config_ValidatorMessage.cpp
src/Config/Config_ValidatorMessage.h
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/plugin-Construction.xml
src/Model/Model_PluginManager.cpp
src/Model/Model_Validator.cpp

index a5ac9699b21977b29bc7ae24775a8abf9b738608..b70511796daa17c7e5c8f15e551299b723d8c72c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Config_ValidatorMessage.cpp
  *
- *  Created on: 08 èþëÿ 2014 ã.
+ *  Created on: 08 Jul 2014 ã.
  *      Author: sbh
  */
 
index 21bbf24752bb4ec9861134852cc2f5b3a1e006b1..f43c351b00fc23d6b8670752765829af852c71de 100644 (file)
@@ -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<std::string>& parameters() const;
   CONFIG_EXPORT bool isValid() const;
 
index 4f632cbc3f6591dfaec33af35c02571aa6a36920..bbcc6cfdcf2c28913f2a286352c7569026061715 100644 (file)
@@ -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
               )
index 0918dc9cda6e82bd48fb23a400b314ce95c1c888..381a3e656f587e26e70adc2ccce395ff44fc1d49 100644 (file)
@@ -2,11 +2,11 @@
   <workbench id="Construction">
     <group id="Basic">
       <feature id="Point" title="Point" tooltip="Create a new point" icon=":icons/point.png">
-        <validator id="test" parameters="x,y,z"/>
+        <!-- validator id="test" parameters="x,y,z"/ -->
         <source path="point_widget.xml"/>
       </feature>
       <feature id="Axis" title="Axis" tooltip="Create a new axis" icon=":icons/axis.png" keysequence="" internal="true">
-        <validator id="inside" parameters="a,b"/
+        <!-- validator id="inside" parameters="a,b"/ --
       </feature>
       <feature id="Plane" title="Plane" tooltip="Create a new plane" icon=":icons/plane.png" keysequence="" internal="true"/>
     </group>
index 1dabf19905e5e56a0bdf0a2c8bd6619de891b3ed..cd262dcc7c626f2e62c3a537bb6f635cd04a3592 100644 (file)
@@ -13,6 +13,7 @@
 #include <Events_Loop.h>
 #include <Events_Error.h>
 #include <Config_FeatureMessage.h>
+#include <Config_ValidatorMessage.h>
 #include <Config_ModuleReader.h>
 
 #include <TDF_CopyTool.hxx>
@@ -107,17 +108,19 @@ Model_PluginManager::Model_PluginManager()
   ModelAPI_PluginManager::setPluginManager(boost::shared_ptr<ModelAPI_PluginManager>(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<const Config_FeatureMessage*>(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<const Config_ValidatorMessage*>(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");
index 3f6e1c6caabbeb90b5bccd67bcdaedba39b7ea1d..771ea6c34bd461fdcf5899b88d8b9aece6736d89 100644 (file)
@@ -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<ModelAPI_Validator*, list<string> >(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;
   }
 }