Salome HOME
Issue #2593: CEA 2018-2 Geometrical Naming
[modules/shaper.git] / src / GeomValidators / GeomValidators_ShapeType.cpp
index afb7dd0c93eb2c6a5bb6eefa2965bd750a5b698b..a7638e7be7ad0e30441d7577daaf2a8b0ab9109a 100755 (executable)
@@ -22,6 +22,7 @@
 #include "GeomValidators_Tools.h"
 
 #include <GeomAPI_Curve.h>
+#include <GeomAPI_ShapeIterator.h>
 #include <GeomDataAPI_Point2D.h>
 
 #include <ModelAPI_Result.h>
@@ -130,18 +131,27 @@ bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     GeomShapePtr aShape = anAttr->value();
     if (aShape.get())
-      aValid = isValidShape(aShape, theShapeType, theError);
+      aValid = isValidShape(aShape, theShapeType, anAttr->isGeometricalSelection(), theError);
     else {
       if (anAttr->context().get())
-        aValid = isValidObject(anAttr->context(), theShapeType, theError);
+        aValid = isValidObject(anAttr->context(),
+                               theShapeType,
+                               anAttr->isGeometricalSelection(),
+                               theError);
       else
-        aValid = isValidObject(anAttr->contextFeature(), theShapeType, theError);
+        aValid = isValidObject(anAttr->contextFeature(),
+                               theShapeType,
+                               anAttr->isGeometricalSelection(),
+                               theError);
     }
   }
   else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
     AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
     if (anAttr->isObject()) {
-      aValid = isValidObject(anAttr->object(), theShapeType, theError);
+      aValid = isValidObject(anAttr->object(),
+                             theShapeType,
+                             false,
+                             theError);
     }
     else if (theShapeType == Vertex) {
       AttributePtr aRefAttr = anAttr->attr();
@@ -162,7 +172,7 @@ bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute
   else if (anAttributeType == ModelAPI_AttributeReference::typeId()) {
     AttributeReferencePtr anAttr =
                               std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
-    aValid = isValidObject(anAttr->value(), theShapeType, theError);
+    aValid = isValidObject(anAttr->value(), theShapeType, false, theError);
   }
   else if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
     AttributeSelectionListPtr aListAttr =
@@ -190,6 +200,7 @@ bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute
 
 bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject,
                                              const TypeOfShape theShapeType,
+                                             const bool theIsGeometricalSelection,
                                              Events_InfoMessage& theError) const
 {
   bool aValid = true;
@@ -214,7 +225,7 @@ bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject,
         aValid = false;
         theError = "The result is empty";
       } else {
-        aValid = isValidShape(aResult->shape(), theShapeType, theError);
+        aValid = isValidShape(aResult->shape(), theShapeType, theIsGeometricalSelection, theError);
       }
     } else {
       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
@@ -231,6 +242,7 @@ bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject,
 
 bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape,
                                             const TypeOfShape theShapeType,
+                                            const bool theIsGeometricalSelection,
                                             Events_InfoMessage& theError) const
 {
   bool aValid = true;
@@ -247,9 +259,21 @@ bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape,
     case Edge:
       aValid = theShape->isEdge();
       break;
-    case Line:
-      aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isLine();
+    case Line: {
+      if (theIsGeometricalSelection && theShape->isCompound()) {
+        aValid = true;
+        for (GeomAPI_ShapeIterator anIt(theShape); anIt.more(); anIt.next()) {
+          if (!anIt.current()->isEdge() || !GeomAPI_Curve(anIt.current()).isLine()) {
+            aValid = false;
+            break;
+          }
+        }
+      }
+      else {
+        aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isLine();
+      }
       break;
+    }
     case Circle:
       aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isCircle();
       break;