Salome HOME
Correction of icon
[modules/shaper.git] / src / PartSet / PartSet_Validators.cpp
index 9bda4c9dc7d73c819ccda6ebf63127aea5f3296b..b246046d509408010fc3d474693d38225ed23082 100644 (file)
 #include <GeomAdaptor_Curve.hxx>
 #include <GeomAbs_CurveType.hxx>
 #include <ModuleBase_ISelection.h>
+#include <ModuleBase_WidgetShapeSelector.h>
 
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Object.h>
 
 #include <SketchPlugin_Sketch.h>
@@ -117,7 +119,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
 
   // 1. check whether the object of the attribute is not among the feature attributes
   // find the attribute's object
-  ObjectPtr anObject = getObject(theAttribute);
+  ObjectPtr anObject =  ModuleBase_WidgetShapeSelector::getObject(theAttribute);
 
   // check whether the object is not among other feature attributes
   if (anObject.get() != NULL) {
@@ -130,7 +132,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
       // the function parameter attribute should be skipped
       if (anAttr.get() == NULL || anAttr->id() == theAttribute->id())
         continue;
-      ObjectPtr aCurObject = getObject(anAttr);
+      ObjectPtr aCurObject =  ModuleBase_WidgetShapeSelector::getObject(anAttr);
       if (aCurObject  && aCurObject == anObject)
         return false;
     }
@@ -154,6 +156,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
       return true;
     }
   }
+  return true;
 }
 
 bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr& theAttribute) const
@@ -186,30 +189,44 @@ bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr&
   return true;
 }
 
-ObjectPtr PartSet_DifferentObjectsValidator::getObject(const AttributePtr& theAttribute) const
+bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
+                                            const std::list<std::string>& theArguments) const
 {
-  ObjectPtr anObject;
-  std::string anAttrType = theAttribute->attributeType();
-  if (anAttrType == ModelAPI_AttributeRefAttr::type()) {
-    AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-    if (anAttr != NULL && anAttr->isObject())
-      anObject = anAttr->object();
+  bool isSketchEntities = true;
+  std::set<std::string> anEntityKinds;
+  std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+  for (; anIt != aLast; anIt++) {
+    anEntityKinds.insert(*anIt);
   }
-  if (anAttrType == ModelAPI_AttributeSelection::type()) {
-    AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
-    if (anAttr != NULL && anAttr->isInitialized())
-      anObject = anAttr->context();
+
+  std::string anAttributeType = theAttribute->attributeType();
+  if (anAttributeType == ModelAPI_AttributeSelectionList::type()) {
+    AttributeSelectionListPtr aSelectionListAttr = 
+                      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    // it filters only selection list attributes
+    std::string aType = aSelectionListAttr->selectionType().c_str();
+    // all context objects should be sketch entities
+    int aSize = aSelectionListAttr->size();
+    for (int i = 0; i < aSelectionListAttr->size() && isSketchEntities; i++) {
+      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+      ObjectPtr anObject = aSelectAttr->context();
+      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+      isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+    }
   }
-  if (anAttrType == ModelAPI_AttributeReference::type()) {
-    AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
-    if (anAttr.get() != NULL && anAttr->isInitialized())
-      anObject = anAttr->value();
+  if (anAttributeType == ModelAPI_AttributeRefAttr::type()) {
+    std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
+                     std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+    isSketchEntities = false;
+    if (aRef->isObject()) {
+      ObjectPtr anObject = aRef->object();
+      if (anObject.get() != NULL) {
+        FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+        if (aFeature.get() != NULL)
+          isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+      }
+    }
   }
-  return anObject;
-}
 
-bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const
-{
-  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-  return aFeature->getKind() == SketchPlugin_Sketch::ID();
+  return isSketchEntities;
 }