Salome HOME
Issue #1834: Fix length of lines
[modules/shaper.git] / src / Model / Model_Validator.cpp
index 1d420229faaad2c2985c8d6e2163cba9b8337971..0aa279fcb18ad8cf89718d04402dbe309290e4c2 100644 (file)
@@ -13,6 +13,7 @@
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
 #include <Model_Data.h>
 
 #include <Events_InfoMessage.h>
@@ -96,13 +97,15 @@ void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
   addDefaultValidators(theValidators);
 }
 
-void Model_ValidatorsFactory::validators(const std::string& theFeatureID, const std::string& theAttrID,
+void Model_ValidatorsFactory::validators(const std::string& theFeatureID, 
+                                         const std::string& theAttrID,
                                          Validators& theValidators) const
 {
   std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeatureIt = 
       myAttrs.find(theFeatureID);
   if (aFeatureIt != myAttrs.cend()) {
-    std::map<std::string, AttrValidators>::const_iterator anAttrIt = aFeatureIt->second.find(theAttrID);
+    std::map<std::string, AttrValidators>::const_iterator anAttrIt =
+      aFeatureIt->second.find(theAttrID);
     if (anAttrIt != aFeatureIt->second.end()) {
       AttrValidators::const_iterator aValidatorsIt = anAttrIt->second.cbegin();
       for (; aValidatorsIt != anAttrIt->second.cend(); aValidatorsIt++) {
@@ -270,7 +273,8 @@ bool Model_ValidatorsFactory::validate(const std::shared_ptr<ModelAPI_Attribute>
   return true;
 }
 
-void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, std::string theAttribute)
+void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, 
+                                                    std::string theAttribute)
 {
   const static std::string kDefaultId = "Model_FeatureValidator";
   std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
@@ -313,41 +317,104 @@ bool Model_ValidatorsFactory::isConcealed(std::string theFeature, std::string th
   return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end();
 }
 
+void Model_ValidatorsFactory::registerUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
+    std::shared_ptr<ModelAPI_Feature> theCanceledFeat)
+{
+  if (myUnconcealed.find(theUnconcealed) == myUnconcealed.end()) {
+    myUnconcealed[theUnconcealed] = std::list<std::shared_ptr<ModelAPI_Feature> >();
+  }
+  myUnconcealed[theUnconcealed].push_back(theCanceledFeat);
+  std::dynamic_pointer_cast<Model_Data>(theUnconcealed->data())->updateConcealmentFlag();
+}
+
+void Model_ValidatorsFactory::disableUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
+    std::shared_ptr<ModelAPI_Feature> theCanceledFeat)
+{
+  std::map<std::shared_ptr<ModelAPI_Result>, std::list<std::shared_ptr<ModelAPI_Feature> > >
+    ::iterator aResFound = myUnconcealed.find(theUnconcealed);
+  if (aResFound != myUnconcealed.end()) {
+    std::list<std::shared_ptr<ModelAPI_Feature> >::iterator anIter = aResFound->second.begin();
+    for(; anIter != aResFound->second.end(); anIter++) {
+      if (*anIter == theCanceledFeat) {
+        aResFound->second.erase(anIter);
+        std::dynamic_pointer_cast<Model_Data>(theUnconcealed->data())->updateConcealmentFlag();
+        break;
+      }
+    }
+  }
+}
+
+bool Model_ValidatorsFactory::isUnconcealed(std::shared_ptr<ModelAPI_Result> theUnconcealed,
+    std::shared_ptr<ModelAPI_Feature> theCanceledFeat)
+{
+  std::map<std::shared_ptr<ModelAPI_Result>, std::list<std::shared_ptr<ModelAPI_Feature> > >
+    ::iterator aResFound = myUnconcealed.find(theUnconcealed);
+  if (aResFound != myUnconcealed.end()) {
+    std::list<std::shared_ptr<ModelAPI_Feature> >::iterator aFeatIter = aResFound->second.begin();
+    for(; aFeatIter != aResFound->second.end(); aFeatIter++) {
+      if (aFeatIter->get()) {
+        if ((*aFeatIter)->isDisabled()) continue;
+        if (*aFeatIter == theCanceledFeat)
+          return true; // this is exactly canceled
+        if (theCanceledFeat->document()->isLater(*aFeatIter, theCanceledFeat))
+          return true; // if unconcealed feature (from the list) is later than concealed
+      } else
+        return true; // empty attribute means that everything is canceled
+    }
+  }
+  return false;
+}
+
 void Model_ValidatorsFactory::registerCase(std::string theFeature, std::string theAttribute,
-    std::string theSwitchId, std::string theCaseId)
+                            const std::list<std::pair<std::string, std::string> >& theCases)
 {
-  std::map<std::string, std::map<std::string, std::pair<std::string, std::set<std::string> > > >
+  std::map<std::string, std::map<std::string, std::map<std::string, std::set<std::string> > > >
     ::iterator aFindFeature = myCases.find(theFeature);
   if (aFindFeature == myCases.end()) {
-    myCases[theFeature] = std::map<std::string, std::pair<std::string, std::set<std::string> > >();
+    myCases[theFeature] = std::map<std::string, std::map<std::string, std::set<std::string> > >();
     aFindFeature = myCases.find(theFeature);
   }
-  std::map<std::string, std::pair<std::string, std::set<std::string> > >::iterator aFindAttrID =
+  std::map<std::string, std::map<std::string, std::set<std::string> > >::iterator aFindAttrID =
     aFindFeature->second.find(theAttribute);
+
   if (aFindAttrID == aFindFeature->second.end()) {
     aFindFeature->second[theAttribute] =
-      std::pair<std::string, std::set<std::string> >(theSwitchId, std::set<std::string>());
+      std::map<std::string, std::set<std::string> >();
     aFindAttrID = aFindFeature->second.find(theAttribute);
   }
-  aFindAttrID->second.second.insert(theCaseId);
+  std::list<std::pair<std::string, std::string> >::const_iterator aCasesIt = theCases.begin(),
+                                                                       aCasesLast = theCases.end();
+  std::map<std::string, std::set<std::string> > aFindCases = aFindAttrID->second;
+  for (; aCasesIt != aCasesLast; aCasesIt++) {
+    std::pair<std::string, std::string> aCasePair = *aCasesIt;
+    std::string aSwitch = aCasePair.first;
+    if (aFindAttrID->second.find(aSwitch) == aFindAttrID->second.end()) {
+      aFindAttrID->second[aSwitch] = std::set<std::string>();
+    }
+    aFindAttrID->second[aSwitch].insert(aCasePair.second);
+  }
 }
 
 bool Model_ValidatorsFactory::isCase(FeaturePtr theFeature, std::string theAttribute)
 {
-  std::map<std::string, std::map<std::string, std::pair<std::string, std::set<std::string> > > >
+  bool anInCase = true;
+  std::map<std::string, std::map<std::string, std::map<std::string, std::set<std::string> > > >
     ::iterator aFindFeature = myCases.find(theFeature->getKind());
   if (aFindFeature != myCases.end()) {
-    std::map<std::string, std::pair<std::string, std::set<std::string> > >::iterator
+    std::map<std::string, std::map<std::string, std::set<std::string> > >::iterator
       aFindAttrID = aFindFeature->second.find(theAttribute);
     if (aFindAttrID != aFindFeature->second.end()) {
-      // the the switch-attribute that contains the case value
-      AttributeStringPtr aSwitch = theFeature->string(aFindAttrID->second.first);
-      if (aSwitch.get()) {
-         // the second has the case identifier
-        return aFindAttrID->second.second.find(aSwitch->value()) != 
-               aFindAttrID->second.second.end();
+      std::map<std::string, std::set<std::string> >::iterator
+              aCasesIt = aFindAttrID->second.begin(), aCasesLast = aFindAttrID->second.end();
+      for (; aCasesIt != aCasesLast && anInCase; aCasesIt++) {
+        // the the switch-attribute that contains the case value
+        AttributeStringPtr aSwitch = theFeature->string(aCasesIt->first);
+        if (aSwitch.get()) {
+          // the second has the case identifier
+          anInCase =  aCasesIt->second.find(aSwitch->value()) != aCasesIt->second.end();
+        }
       }
     }
   }
-  return true; // if no additional conditions, this attribute is the case to be validated
+  return anInCase; // if no additional conditions, this attribute is the case to be validated
 }