]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Case-specific attributes validation implementation
authormpv <mpv@opencascade.com>
Fri, 27 Feb 2015 14:22:47 +0000 (17:22 +0300)
committermpv <mpv@opencascade.com>
Fri, 27 Feb 2015 14:22:47 +0000 (17:22 +0300)
src/Model/Model_FeatureValidator.cpp
src/Model/Model_Session.cpp
src/Model/Model_Validator.cpp
src/Model/Model_Validator.h
src/ModelAPI/ModelAPI_Validator.h

index b3b1b821687f13ebdadaed93bc9ed4772fde4f02..a809abe461a5d1653edcd6a4e8e5b3af2c817858 100644 (file)
@@ -5,10 +5,12 @@
 // Author:      Vitaly SMETANNIKOV
 
 #include <Model_FeatureValidator.h>
+#include <Model_Validator.h>
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Session.h>
 
 #include <list>
 #include <memory>
@@ -16,6 +18,9 @@
 bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
   const std::list<std::string>& theArguments) const
 {
+  static Model_ValidatorsFactory* aValidators = 
+    static_cast<Model_ValidatorsFactory*>(ModelAPI_Session::get()->validators());
+
   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   // "Action" features has no data, but still valid. e.g "Remove Part"  
   if (!aData) {
@@ -28,6 +33,8 @@ bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& th
   std::list<std::string>::iterator it = aLtAttributes.begin();
   for (; it != aLtAttributes.end(); it++) {
     AttributePtr anAttr = aData->attribute(*it);
+    if (!aValidators->isCase(theFeature, anAttr->id()))
+      continue; // this attribute is not participated in the current case
     if (!anAttr->isInitialized()) { // attribute is not initialized
       std::map<std::string, std::set<std::string> >::const_iterator aFeatureFind = 
         myNotObligatory.find(theFeature->getKind());
index 8b81240a2bcc185126d3b6f582bce8cdc9059396..1791c3ad604bff088905e8da1e7ad73c0b23d156 100644 (file)
@@ -299,7 +299,10 @@ void Model_Session::processEvent(const std::shared_ptr<Events_Message>& theMessa
         if(aMsgAttr->isConcealment()) {
           validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId());
         }
-        
+        if (!aMsgAttr->caseId().empty()) {
+          validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(),
+            aMsgAttr->switchId(), aMsgAttr->caseId());
+        }
       }
     }
     // plugins information was started to load, so, it will be loaded
index c2c994da9cd65dc1b194115c8250aa524760ae1c..9875f74274a9af41843c9140761b3273f224734d 100644 (file)
@@ -10,6 +10,7 @@
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_AttributeString.h>
 #include <Events_Error.h>
 
 void Model_ValidatorsFactory::registerValidator(const std::string& theID,
@@ -260,3 +261,34 @@ bool Model_ValidatorsFactory::isConcealed(std::string theFeature, std::string th
   std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
   return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end();
 }
+
+void Model_ValidatorsFactory::registerCase(std::string theFeature, std::string theAttribute,
+    std::string theSwitchId, std::string theCaseId)
+{
+  std::map<std::string, std::map<std::string, std::pair<std::string, std::string> > >::iterator 
+    aFindFeature = myCases.find(theFeature);
+  if (aFindFeature == myCases.end()) {
+    myCases[theFeature] = std::map<std::string, std::pair<std::string, std::string> >();
+    aFindFeature = myCases.find(theFeature);
+  }
+  (aFindFeature->second)[theAttribute] = std::pair<std::string, std::string>(theSwitchId, theCaseId);
+}
+
+bool Model_ValidatorsFactory::isCase(
+  FeaturePtr theFeature, std::string theAttribute)
+{
+  std::map<std::string, std::map<std::string, std::pair<std::string, std::string> > >::iterator 
+    aFindFeature = myCases.find(theFeature->getKind());
+  if (aFindFeature != myCases.end()) {
+    std::map<std::string, std::pair<std::string, std::string> >::iterator
+      aFindAttr = aFindFeature->second.find(theAttribute);
+    if (aFindAttr != aFindFeature->second.end()) {
+      // the the switch-attribute that contains the case value
+      AttributeStringPtr aSwitch = theFeature->string(aFindAttr->second.first);
+      if (aSwitch.get()) {
+        return aSwitch->value() == aFindAttr->second.second; // the second is the case identifier
+      }
+    }
+  }
+  return true; // if no additional conditions, this attribute is the case to be validated
+}
index 4747c534ba87a7711b7ae1125058ff2ab35e1131..b3324c45862a0703a711823bd145063cbb681c92 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <Model.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_Feature.h>
 #include <map>
 #include <set>
 
@@ -37,6 +38,10 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
   /// Stores the registered attributes that leads to the concealment of referenced objects in 
   /// data tree. Map from feature kind to set of attribute IDs.
   std::map<std::string, std::set<std::string> > myConcealed;
+  /// Stores the registered attributes must be checked only if the particular case is activated
+  /// Map from feature kind to map of attribute IDs to pair 
+  // (switchId (ID of the attribute) and case Id (possible values of the switch attribute))
+  std::map<std::string, std::map<std::string, std::pair<std::string, std::string> > > myCases;
 
  public:
   /// Registers the instance of the validator by the ID
@@ -88,6 +93,14 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
   /// Returns true that it was registered that attribute conceals the referenced result
   virtual bool isConcealed(std::string theFeature, std::string theAttribute);
 
+  /// register the case-attribute (\a myCases set definition)
+  virtual void registerCase(std::string theFeature, std::string theAttribute,
+    std::string theSwitchId, std::string theCaseId);
+
+  /// Returns true if the attribute must be checked (the case is selected)
+  virtual bool isCase(FeaturePtr theFeature, std::string theAttribute);
+
+
 protected:
   /// Adds the defualt validators that are usefull for all features.
   void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators,
index 1c7d0fecb549113e0040d730380984a0bc276c8e..42662b10d4e6adfd7db9ccdae6992a6bee9427df 100644 (file)
@@ -95,6 +95,10 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
   /// Returns true that it was registered that attribute conceals the referenced result
   virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
 
+  /// Register the case-attribute: this attribute is checked only if its case is selected
+  virtual void registerCase(std::string theFeature, std::string theAttribute,
+    std::string theSwitchId, std::string theCaseId) = 0;
+
  protected:
   /// Get instance from Session
   ModelAPI_ValidatorsFactory()