]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
It provides error messages for validators.
authornds <nds@opencascade.com>
Mon, 7 Sep 2015 12:07:20 +0000 (15:07 +0300)
committernds <nds@opencascade.com>
Mon, 7 Sep 2015 13:20:44 +0000 (16:20 +0300)
21 files changed:
src/ConstructionPlugin/axis_widget.xml
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_ConstructionComposite.cpp
src/GeomValidators/GeomValidators_DifferentShapes.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_DifferentShapes.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Face.cpp
src/GeomValidators/GeomValidators_Finite.cpp
src/GeomValidators/GeomValidators_ShapeType.cpp
src/GeomValidators/GeomValidators_ShapeType.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_ShapeValidator.cpp [deleted file]
src/ModelAPI/ModelAPI_ShapeValidator.h [deleted file]
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_Tools.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationPrs.cpp
src/PartSet/PartSet_OperationPrs.h
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_Validators.h
src/SketchPlugin/SketchPlugin_Validators.cpp

index 72d12f740c90f1aaef7903e33bebf90210e166bf..74284b8d5d8c0f7febd0e09b9324a42cc96aaf15 100644 (file)
@@ -18,7 +18,7 @@
         shape_types="vertex">
         <validator id="GeomValidators_ConstructionComposite"/>
         <validator id="GeomValidators_ShapeType" parameters="vertex"/>
-        <validator id="PartSet_DifferentShapes"/>
+        <validator id="GeomValidators_DifferentShapes"/>
       </shape_selector>
     </box>
     <box id="AxisByCylindricalFaceCase" title="As axis of cylindrical face" icon=":icons/circle.png">
index 6cf5f5379c4a77f981c4ee9b37751065dcfe473b..c23f5aa40d8a63e5b83c73e3e7e66fcfa94c72e8 100644 (file)
@@ -6,6 +6,7 @@ SET(PROJECT_HEADERS
     GeomValidators.h
     GeomValidators_BooleanArguments.h
     GeomValidators_ConstructionComposite.h
+    GeomValidators_DifferentShapes.h
     GeomValidators_Face.h
     GeomValidators_Finite.h
     GeomValidators_Positive.h
@@ -18,6 +19,7 @@ SET(PROJECT_HEADERS
 SET(PROJECT_SOURCES
     GeomValidators_BooleanArguments.cpp
     GeomValidators_ConstructionComposite.cpp
+    GeomValidators_DifferentShapes.cpp
     GeomValidators_Face.cpp
     GeomValidators_Finite.cpp
     GeomValidators_Positive.cpp
index 25e2565eeb2c1e80fd988ddd863e54d1a8a12983..b19719831ce1846d1ba90a5c928e46f00769f1ee 100644 (file)
@@ -10,48 +10,57 @@ bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttrib
                                                    const std::list<std::string>& theArguments,
                                                    std::string& theError) const
 {
-  bool aValid = false;
-  AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-                                                                (theAttribute);
-  if (aSelectionAttr.get() == NULL) {
-    theError = "Is not a selection attribute.";
+  bool aValid = true;
+  if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
+    aValid = false;
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
     return aValid;
   }
 
+  AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+                                                                (theAttribute);
   ResultPtr aResult = aSelectionAttr->context();
-  GeomShapePtr aShape = aSelectionAttr->value();
   // global selection should be ignored, the filter processes only selected sub-shapes
   // that means, that the shape of the context result is equal to the shape value
   ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
-  if (aResult.get() != NULL) {
+  if (!aResult.get()) {
+    aValid = false;
+    theError = "The result is empty";
+  }
+  else {
+    GeomShapePtr aShape = aSelectionAttr->value();
     GeomShapePtr aShapePtr = aResult->shape();
     // it is important to call isEqual of the shape of result.
     // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is 
     // GeomAPI_Shape. It is important to use the realization of the isEqual method from
     // GeomAPI_Vertex class
-    if (aShape.get()) {
-      aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
-    }
-    else {
+    if (!aShape.get()) {
       // an empty shape is used in attribute selection if the shape of the result is equal to
       // the selected shape, so according to the upper condition, the result is true
       aValid = true;
     }
-  }
-  if (!aValid) {
-    ResultConstructionPtr aConstr =
-                            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
-    if (aConstr != NULL) {
-      // it provides selection only on composite features, construction without composite
-      // feature is not selectable
-      FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
-      CompositeFeaturePtr aComposite = 
-                             std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
-      aValid = aComposite && aComposite->numberOfSubs() > 0;
-    }
     else {
-      // non-construction results should be accepted by this filter, e.g. body results
-      aValid = true;
+      if (aShapePtr->isEqual(aShape)) {
+        aValid = true;
+      }
+      else {
+        ResultConstructionPtr aConstr =
+          std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+        if (!aConstr.get()) {
+          // non-construction results should be accepted by this filter, e.g. body results
+          aValid = true;
+        }
+        else {
+          // it provides selection only on composite features, construction without composite
+          // feature is not selectable.
+          FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
+          CompositeFeaturePtr aComposite =
+            std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+          aValid = aComposite && aComposite->numberOfSubs() > 0;
+          if (!aValid)
+            theError = "Uses composite construction feature without sub-features.";
+        }
+      }
     }
   }
   return aValid;
diff --git a/src/GeomValidators/GeomValidators_DifferentShapes.cpp b/src/GeomValidators/GeomValidators_DifferentShapes.cpp
new file mode 100644 (file)
index 0000000..e9470da
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_DifferentShapes.cpp
+// Created:     2 Feb 2015
+// Author:      Natalia ERMOLAEVA
+
+#include "GeomValidators_DifferentShapes.h"
+
+#include <ModelAPI_AttributeSelection.h>
+#include "ModelAPI_Object.h"
+
+bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute,
+                                      const std::list<std::string>& theArguments,
+                                      std::string& theError) const
+{
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeSelectionPtr aSelectionAttribute = 
+                     std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  GeomShapePtr aShape = aSelectionAttribute->value();
+  if (!aShape.get()) {
+    ResultPtr aResult = aSelectionAttribute->context();
+    if (aResult.get())
+      aShape = aResult->shape();
+  }
+
+  std::string aCurrentAttributeId = theAttribute->id();
+  // get all feature attributes
+  std::list<AttributePtr> anAttrs = 
+      aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
+  if (anAttrs.size() > 0 && aShape.get() != NULL) {
+    std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
+    for(; anAttr != anAttrs.end(); anAttr++) {
+      AttributePtr anAttribute = *anAttr;
+      // take into concideration only other attributes
+      if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
+        aSelectionAttribute = 
+          std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
+        // the shape of the attribute should be not the same
+        if (aSelectionAttribute.get() != NULL) {
+          GeomShapePtr anAttrShape = aSelectionAttribute->value();
+          if (!anAttrShape.get()) {
+            ResultPtr aResult = aSelectionAttribute->context();
+            if (aResult.get())
+              anAttrShape = aResult->shape();
+          }
+          if (aShape->isEqual(anAttrShape)) {
+            theError = "The feature uses equal shapes.";
+            return false;
+          }
+        }
+      }
+    }
+  }
+  return true;
+}
diff --git a/src/GeomValidators/GeomValidators_DifferentShapes.h b/src/GeomValidators/GeomValidators_DifferentShapes.h
new file mode 100644 (file)
index 0000000..1fbb004
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_DifferentShapes.h
+// Created:     2 Feb 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef GeomValidators_DifferentShapes_H
+#define GeomValidators_DifferentShapes_H
+
+#include <ModelAPI.h>
+
+#include <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_Attribute.h>
+
+/**
+ * Generic validator for any attribute of a feature.
+ */
+class GeomValidators_DifferentShapes : public ModelAPI_AttributeValidator
+{
+public:
+  /// returns True if the attribute is valid. It checks whether the feature of the attribute
+  /// does not contain a selection attribute filled with the same shape
+  /// \param theAttribute an attribute to check
+  /// \param theArguments a filter parameters
+  MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                       const std::list<std::string>& theArguments,
+                                       std::string& theError) const;
+};
+
+#endif
index a9fb025aebb3ee10141ea575ba78c9393b19b76f..51a5012cdab7ac5cc292a9478893ac9a9b9f3cb0 100644 (file)
@@ -34,23 +34,20 @@ bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
                                   const std::list<std::string>& theArguments,
                                   std::string& theError) const
 {
-  bool aValid = false;
-
-  GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
-  if (theArguments.size() == 1) {
-    std::string anArgument = theArguments.front();
-    aFaceType = faceType(anArgument);
+  std::string anAttributeType = theAttribute->attributeType();
+  if (anAttributeType != ModelAPI_AttributeSelection::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
   }
 
+  bool aValid = true;
   ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
-  if (anObject.get() != NULL) {
+  if (!anObject.get()) {
+    aValid = true; // an empty face selected is valid.
+  }
+  else {
     AttributeSelectionPtr aSelectionAttr =
-        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
-    if (aSelectionAttr.get() == NULL) {
-      theError = "Is not a selection attribute.";
-      return aValid;
-    }
-
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
     if (!aGeomShape.get()) {
       // if the shape is empty, apply the validator to the shape of result
@@ -59,29 +56,42 @@ bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
     // it is necessary to check whether the shape is face in order to set in selection a value
     // with any type and check the type in this validator
     // It is realized to select any object in OB and filter it in this validator (sketch plane)
-    if (aGeomShape->isFace()) {
+    if (!aGeomShape->isFace()) {
+      aValid = false;
+      theError = "The shape is not a face.";
+    }
+    else {
       std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
-      if (aGeomFace.get() != NULL) {
-        switch(aFaceType) {
-            case GeomAbs_Plane:
-              aValid = aGeomFace->isPlanar();
-              if (!aValid)
-                theError = "The shape is not a plane.";
-              break;
-            case GeomAbs_Cylinder:
-              aValid = aGeomFace->isCylindrical();
-              if (!aValid)
-                theError = "The shape is not a cylinder.";
-              break;
-            default:
-              theError = "The shape is not an available face.";
-              break;
+      if (!aGeomFace.get()) {
+        aValid = false;
+        theError = "The shape is not a face.";
+      }
+      else {
+        GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
+        if (theArguments.size() == 1)
+          aFaceType = faceType(theArguments.front());
+
+        switch (aFaceType) {
+          case GeomAbs_Plane: {
+            aValid = aGeomFace->isPlanar();
+            if (!aValid)
+              theError = "The shape is not a plane.";
+          }
+          break;
+          case GeomAbs_Cylinder:{
+            aValid = aGeomFace->isCylindrical();
+            if (!aValid)
+              theError = "The shape is not a cylinder.";
+          }
+          break;
+          default: {
+            aValid = false;
+            theError = "The shape is not an available face.";
+            break;
+          }
         }
       }
-    } else
-      theError = "The shape is not a face.";
+    }
   }
-  else
-    aValid = true; // an empty face selected is valid.
   return aValid;
 }
index e4f623104adc10b66c2305bd98c3ea3fe0f9c27e..150415cb15428553ea4251af95169b2f0ac99e92 100755 (executable)
@@ -25,6 +25,7 @@ bool GeomValidators_Finite::isValid(const AttributePtr& theAttribute,
         ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
         if (aConstruction.get() && aConstruction->isInfinite()) {
           aValid = false;
+          theError = "Infinite result is selected.";
         }
       }
     }
index 1bb88e0534b613383226db807735549fd896cb18..80e6af9d02cbda14a32a29932da767a012202dae 100644 (file)
 
 typedef std::map<std::string, GeomValidators_ShapeType::TypeOfShape> EdgeTypes;
 
+static EdgeTypes MyShapeTypes;
 GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const std::string& theType)
 {
-  static EdgeTypes MyShapeTypes;
-
   if (MyShapeTypes.size() == 0) {
     MyShapeTypes["empty"]  = Empty;
     MyShapeTypes["vertex"] = Vertex;
@@ -43,6 +42,22 @@ GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const
   return AnyShape;
 }
 
+std::string getShapeTypeDescription(const GeomValidators_ShapeType::TypeOfShape& theType)
+{
+  std::string aValue = "";
+
+  if (MyShapeTypes.size() != 0) {
+    std::map<std::string, GeomValidators_ShapeType::TypeOfShape>::const_iterator anIt = MyShapeTypes.begin(),
+                                                                                 aLast = MyShapeTypes.end();
+    for (; anIt != aLast; anIt++) {
+      if (anIt->second == theType)
+        aValue = anIt->first;
+        break;
+    }
+  }
+  return aValue;
+}
+
 bool GeomValidators_ShapeType::isValid(const AttributePtr& theAttribute,
                                        const std::list<std::string>& theArguments,
                                        std::string& theError) const
@@ -50,105 +65,138 @@ bool GeomValidators_ShapeType::isValid(const AttributePtr& theAttribute,
   bool aValid = false;
 
   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
-  for (; anIt != aLast && !aValid; anIt++) {
-    aValid = isValidArgument(theAttribute, *anIt);
-  }
-
-  return aValid;
-}
-
-bool GeomValidators_ShapeType::isValidArgument(const AttributePtr& theAttribute,
-                                               const std::string& theArgument) const
-{
-  bool aValid = false;
-  TypeOfShape aShapeType = shapeType(theArgument);
-  if (aShapeType == AnyShape)
-    return true;
-
-  AttributeSelectionListPtr aListAttr = 
-           std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-  if (aListAttr.get()) {
-    if(aListAttr->size() == 0 && shapeType(theArgument) == Empty) {
-      return true;
+  // returns true if the attribute satisfies at least one of given arguments
+  for (; anIt != aLast; anIt++) {
+    TypeOfShape aShapeType = shapeType(*anIt);
+    // if arguments contain any shape type value, the validator returns true
+    if (aShapeType == AnyShape) {
+      aValid = true;
+      break;
     }
-    for (int i = 0; i < aListAttr->size(); i++) {
-      aValid = isValidAttribute(aListAttr->value(i), aShapeType);
-      if (!aValid) // if at least one attribute is invalid, the result is false
-        break;
+    if (isValidAttribute(theAttribute, aShapeType, theError)) {
+      aValid = true;
+      break;
     }
   }
-  else {
-    aValid = isValidAttribute(theAttribute, aShapeType);
+  if (!aValid && theError.empty()) {
+    std::string aTypes;
+    std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+    // returns true if the attribute satisfies at least one of given arguments
+    for (; anIt != aLast; anIt++) {
+      if (!aTypes.empty())
+        aTypes += ", ";
+    }
+    theError = "It does not contain element with acceptable shape type. The type should be one of the next: "
+               + aTypes;
   }
+
   return aValid;
 }
 
 bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute,
-                                                const TypeOfShape theShapeType) const
+                                                const TypeOfShape theShapeType,
+                                                std::string& theError) const
 {
-  bool aValid = false;
+  bool aValid = true;
 
   std::string anAttributeType = theAttribute->attributeType();
-
   if (anAttributeType == ModelAPI_AttributeSelection::typeId()) {
     AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     GeomShapePtr aShape = anAttr->value();
     if (aShape.get())
-      aValid = isValidShape(aShape, theShapeType);
+      aValid = isValidShape(aShape, theShapeType, theError);
     else
-      aValid = isValidObject(anAttr->context(), theShapeType);
+      aValid = isValidObject(anAttr->context(), theShapeType, theError);
   }
   else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
     AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-    if (anAttr.get() != NULL) {
-      if (anAttr->isObject()) {
-        aValid = isValidObject(anAttr->object(), theShapeType);
+    if (anAttr->isObject()) {
+      aValid = isValidObject(anAttr->object(), theShapeType, theError);
+    }
+    else if (theShapeType == Vertex) {
+      AttributePtr aRefAttr = anAttr->attr();
+      if (!aRefAttr.get()){
+        aValid = false;
+        theError = "It has reference to an empty attribute";
       }
-      else if (theShapeType == Vertex) {
-        AttributePtr aRefAttr = anAttr->attr();
-        aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::typeId();
+      else {
+        std::string anAttributeType = aRefAttr->attributeType();
+        aValid = anAttributeType == GeomDataAPI_Point2D::typeId();
+        if (!aValid)
+          theError = "Shape type is \"" + anAttributeType +
+                     "\", it should be \"" + getShapeTypeDescription(theShapeType) + "\"";
       }
     }
   }
   else if (anAttributeType == ModelAPI_AttributeReference::typeId()) {
-    AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
-    if (anAttr.get() != NULL)
-      aValid = isValidObject(anAttr->value(), theShapeType);
+    AttributeReferencePtr anAttr =
+                              std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+    aValid = isValidObject(anAttr->value(), theShapeType, theError);
+  }
+  else if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
+    AttributeSelectionListPtr aListAttr =
+                          std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    // the Empty value means that the attribute selection list is valid if it is empty
+    if (aListAttr->size() == 0 && theShapeType == Empty) {
+      return true;
+    }
+    aValid = false; // the list should have elements if the shape type is not Empty
+    for (int i = 0; i < aListAttr->size(); i++) {
+      aValid = isValidAttribute(aListAttr->value(i), theShapeType, theError);
+      if (!aValid) // if at least one attribute is invalid, the result is false
+        break;
+    }
+  }
+  else {
+    aValid = false;
+    theError = "The attribute with the " + anAttributeType  + " type is not processed";
   }
   return aValid;
 }
 
 bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject,
-                                             const TypeOfShape theShapeType) const
+                                             const TypeOfShape theShapeType,
+                                             std::string& theError) const
 {
-  bool aValid = false;
-  if (theObject.get() != NULL) {
-    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+  bool aValid = true;
+  if (!theObject.get()) {
+    aValid = false;
+    theError = "The object is empty";
+  }
+  else {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
     if( theShapeType==Plane )
     {
       ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);
+      FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
       const std::string& aKind = aFeature->getKind();
       return aResult.get() != NULL && aKind == "Plane";
     }
-
-    if (aResult.get() != NULL) {
-      GeomShapePtr aShape = aResult->shape();
-      aValid = isValidShape(aShape, theShapeType);
+    if (!aResult.get()) {
+      aValid = false;
+      theError = "The result is empty";
+    }
+    else {
+      aValid = isValidShape(aResult->shape(), theShapeType, theError);
     }
   }
   return aValid;
 }
 
 bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape,
-                                            const TypeOfShape theShapeType) const
+                                            const TypeOfShape theShapeType,
+                                            std::string& theError) const
 {
-  bool aValid = false;
+  bool aValid = true;
 
-  if (theShape.get() != NULL) {
+  if (!theShape.get()) {
+    aValid = false;
+    theError = "The shape is empty";
+  }
+  else {
     switch (theShapeType) {
-      case Edge:
-        aValid = theShape->isEdge();
+    case Edge:
+      aValid = theShape->isEdge();
       break;
       case Line:
         aValid = theShape->isEdge() && !GeomAPI_Curve(theShape).isCircle();
@@ -169,7 +217,9 @@ bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape,
       case Compound:
         aValid = theShape->isCompound();
         break;
-      default: break;
+      default:
+        aValid = false;
+        break;
     }
   }
   return aValid;
index 5d30779b107c5c88a3906bb53683fcc5e380ee82..fd6e24e1888cd45f9a81070565c545e977d53497 100644 (file)
@@ -40,7 +40,7 @@ class GeomValidators_ShapeType : public ModelAPI_AttributeValidator
 
  public:
    GEOMVALIDATORS_EXPORT GeomValidators_ShapeType() {}
-  //! returns true if attribute is valid
+  //! Returns true if attribute has shape type listed in the parameter arguments
   //! \param theAttribute the checked attribute
   //! \param theArguments arguments of the attribute
   GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
@@ -51,26 +51,26 @@ protected:
   /// \param theType a string value
   static TypeOfShape shapeType(const std::string& theType);
 
-  bool isValidArgument(const AttributePtr& theAttribute,
-                       const std::string& theArgument) const;
-
   /// Returns true if the attibute's object type satisfies the argument value
   /// \param theAttribute a checked attribute
   /// \param theArgument a parameter
   bool isValidAttribute(const AttributePtr& theAttribute,
-                        const TypeOfShape theShapeType) const;
+                        const TypeOfShape theShapeType,
+                        std::string& theError) const;
 
   /// Returns true if the attibute's object type satisfies the argument value
   /// \param theAttribute a checked object
   /// \param theShapeType a shape type
   bool isValidObject(const ObjectPtr& theObject,
-                     const TypeOfShape theShapeType) const;
+                     const TypeOfShape theShapeType,
+                     std::string& theError) const;
 
   /// Returns true if the attibute's object type satisfies the argument value
   /// \param theShape a checked shape
   /// \param theShapeType a shape type
   bool isValidShape(const GeomShapePtr theShape,
-                    const TypeOfShape theShapeType) const;
+                    const TypeOfShape theShapeType,
+                    std::string& theError) const;
 
 };
 
index e0c9dbb40f2151af751a9fae5c64ee28200dcfa8..70d61ff25bb1b41c58448213e14dfdc541c8c97a 100644 (file)
@@ -39,7 +39,6 @@ SET(PROJECT_HEADERS
     ModelAPI_ResultPart.h
     ModelAPI_Session.h
     ModelAPI_Tools.h
-    ModelAPI_ShapeValidator.h
     ModelAPI_Validator.h
        ModelAPI_Entity.h
 )
@@ -75,7 +74,6 @@ SET(PROJECT_SOURCES
     ModelAPI_ResultPart.cpp
     ModelAPI_ResultParameter.cpp
     ModelAPI_Session.cpp
-    ModelAPI_ShapeValidator.cpp
     ModelAPI_Tools.cpp
     ModelAPI_AttributeValidator.cpp
 )
diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.cpp b/src/ModelAPI/ModelAPI_ShapeValidator.cpp
deleted file mode 100644 (file)
index 2348819..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModelAPI_ShapeValidator.cpp
-// Created:     2 Feb 2015
-// Author:      Natalia ERMOLAEVA
-
-#include "ModelAPI_ShapeValidator.h"
-
-#include <ModelAPI_AttributeSelection.h>
-#include "ModelAPI_Object.h"
-
-bool ModelAPI_ShapeValidator::isValid(const AttributePtr& theAttribute,
-                                      const std::list<std::string>& theArguments,
-                                      std::string& theError) const
-{
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
-  AttributeSelectionPtr aSelectionAttribute = 
-                     std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
-  GeomShapePtr aShape = aSelectionAttribute->value();
-  if (!aShape.get()) {
-    ResultPtr aResult = aSelectionAttribute->context();
-    if (aResult.get())
-      aShape = aResult->shape();
-  }
-
-  std::string aCurrentAttributeId = theAttribute->id();
-  // get all feature attributes
-  std::list<AttributePtr> anAttrs = 
-      aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
-  if (anAttrs.size() > 0 && aShape.get() != NULL) {
-    std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
-    for(; anAttr != anAttrs.end(); anAttr++) {
-      AttributePtr anAttribute = *anAttr;
-      // take into concideration only other attributes
-      if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
-        aSelectionAttribute = 
-          std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
-        // the shape of the attribute should be not the same
-        if (aSelectionAttribute.get() != NULL) {
-          GeomShapePtr anAttrShape = aSelectionAttribute->value();
-          if (!anAttrShape.get()) {
-            ResultPtr aResult = aSelectionAttribute->context();
-            if (aResult.get())
-              anAttrShape = aResult->shape();
-            }
-            if (aShape->isEqual(anAttrShape)) {
-            return false;
-          }
-        }
-      }
-    }
-  }
-  return true;
-}
diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.h b/src/ModelAPI/ModelAPI_ShapeValidator.h
deleted file mode 100644 (file)
index 878ad80..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModelAPI_ShapeValidator.h
-// Created:     2 Feb 2015
-// Author:      Natalia ERMOLAEVA
-
-#ifndef ModelAPI_ShapeValidator_H
-#define ModelAPI_ShapeValidator_H
-
-#include <ModelAPI.h>
-
-#include <ModelAPI_AttributeValidator.h>
-#include <ModelAPI_Attribute.h>
-
-/**
- * Generic validator for any attribute of a feature.
- */
-class ModelAPI_ShapeValidator : public ModelAPI_AttributeValidator
-{
-public:
-  /// returns True if the attribute is valid. It checks whether the feature of the attribute
-  /// does not contain a selection attribute filled with the same shape
-  /// \param theAttribute an attribute to check
-  /// \param theArguments a filter parameters
-  MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                       const std::list<std::string>& theArguments,
-                                       std::string& theError) const;
-};
-
-#endif
index 6ee563fc72214f1f39e9033cc1abd2cdd4a342c2..d2009ac41fc63f31006a51439d9916eb51e71362 100755 (executable)
@@ -18,6 +18,8 @@
 #include <GeomDataAPI_Point2D.h>
 #include <Events_Error.h>
 
+#include <Config_PropManager.h>
+
 #include <QWidget>
 #include <QLayout>
 #include <QPainter>
@@ -256,6 +258,14 @@ void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
     theDrawer->SetDeviationCoefficient(1.e-4);
 }
 
+Quantity_Color color(const std::string& theSection,
+                     const std::string& theName,
+                     const std::string& theDefault)
+{
+  std::vector<int> aColor = Config_PropManager::color(theSection, theName, theDefault);
+  return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
+}
+
 }
 
 
index aa22e46bac300a682abf97c41310fdc318ff72db..600a5334f8852f5e34b3ecfe98e39821d0eed325 100755 (executable)
@@ -15,6 +15,8 @@
 #include <TopoDS_Shape.hxx>
 #include <Prs3d_Drawer.hxx>
 
+#include <Quantity_Color.hxx>
+
 #include <QPixmap>
 
 class QWidget;
@@ -108,6 +110,16 @@ It provides 1.e-4 for a shape withe Edge shape type
 */
 MODULEBASE_EXPORT void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
                                                       const Handle(Prs3d_Drawer)& theDrawer);
+
+/*! Obtains the color from the property manager and converts it to the OCCT color
+\param theSection a property section
+\param theName a property item name
+\param theDefault a default color value
+\return quantity color
+*/
+MODULEBASE_EXPORT Quantity_Color color(const std::string& theSection,
+                                       const std::string& theName,
+                                       const std::string& theDefault);
 }
 
 #endif
index 84c409d5008b2b65b0a8dffd11260f9fd95bce68..113a6113f8b2d73e5059a7826b64f501baf93192 100644 (file)
@@ -35,7 +35,6 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_AttributeValidator.h>
-#include <ModelAPI_ShapeValidator.h>
 
 #include <Config_WidgetAPI.h>
 #include <Events_Error.h>
index 3540797e9868cc43171031a4410ef722b0bf6f3b..6304bd23206f68434c255e5fcc396863b7680d4b 100755 (executable)
@@ -49,7 +49,7 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Session.h>
-#include <ModelAPI_ShapeValidator.h>
+#include <GeomValidators_DifferentShapes.h>
 #include <ModelAPI_ResultBody.h>
 
 #include <GeomDataAPI_Point2D.h>
@@ -200,15 +200,12 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
   aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
   aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
-
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
-  aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
-
   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
 
+  aFactory->registerValidator("GeomValidators_DifferentShapes", new GeomValidators_DifferentShapes);
   aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
   aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
-
   aFactory->registerValidator("GeomValidators_Finite", new GeomValidators_Finite);
 
   aFactory->registerValidator("GeomValidators_ConstructionComposite",
@@ -223,9 +220,6 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_SketchEntityValidator",
                               new PartSet_SketchEntityValidator);
 
-  aFactory->registerValidator("PartSet_SameTypeAttr",
-                              new PartSet_SameTypeAttrValidator);
-
   aFactory->registerValidator("GeomValidators_Different",
                               new GeomValidators_Different);
 }
index d82056999f572f2dea2887eef049b1fad3b3ba78..64e785960305132e53c03b392613b5157a078def 100755 (executable)
@@ -37,6 +37,8 @@ IMPLEMENT_STANDARD_RTTIEXT(PartSet_OperationPrs, ViewerData_AISShape);
 PartSet_OperationPrs::PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop)
   : ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr()), myWorkshop(theWorkshop)
 {
+  myShapeColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "1,1,0");
+  myResultColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "0,1,0");
 }
 
 bool PartSet_OperationPrs::canActivate(const FeaturePtr& theFeature)
index 20078787dcb3fdd358ae85c46dfd816a72847397..ca3eaa2dd36d99cedac7848b63b7b2e8271957fe 100755 (executable)
@@ -21,6 +21,8 @@
 #include <ViewerData_AISShape.hxx>
 #include <Standard_DefineHandle.hxx>
 
+#include <Quantity_Color.hxx>
+
 #include <QMap>
 #include <QList>
 
@@ -98,6 +100,9 @@ private:
   FeaturePtr myFeature; /// Reference to a feature object
   QMap<ObjectPtr, QList<GeomShapePtr> > myFeatureShapes; /// visualized shapes
   std::list<ResultPtr> myFeatureResults; /// visualized feature results
+
+  Quantity_Color myShapeColor; /// color of feature depended shapes
+  Quantity_Color myResultColor; /// color of feature result
 };
 
 
index 6aac447811b27f04442305154d3ddb5068ef5fee..02683b3554db08b7e313b0fcc5aefe045960ac4d 100755 (executable)
@@ -192,6 +192,35 @@ bool PartSet_AngleSelection::isValid(const ModuleBase_ISelection* theSelection)
   return (aCount > 0) && (aCount < 3);
 }
 
+std::string PartSet_DifferentObjectsValidator::errorMessage(
+                         const PartSet_DifferentObjectsValidator::ErrorType& theType,
+                         const std::string& thEqualObject, const std::string& theFirstAttribute,
+                         const std::string& theSecondAttribute) const
+{
+  std::string anError;
+  switch (theType) {
+    case EqualObjects:
+      anError = "The feature uses one " + thEqualObject + " object in " +
+                theFirstAttribute + " and " + theSecondAttribute + " attributes.";
+      break;
+    case EqualAttributes:
+      anError = "The feature uses reference to one " + thEqualObject + " attribute in " +
+                theFirstAttribute + " and " + theSecondAttribute + " attributes.";
+      break;
+    case EqualShapes:
+      anError = "The feature uses one shape in " +
+                theFirstAttribute + " and " + theSecondAttribute + " attributes.";
+      break;
+    case EmptyShapes:
+      anError = "The feature uses empty shapes in " +
+                theFirstAttribute + " and " + theSecondAttribute + " attributes.";
+      break;
+      break;
+    default:
+      break;
+  }
+  return anError;
+}
 
 bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, 
                                                 const std::list<std::string>& theArguments,
@@ -220,12 +249,19 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
           if (aRef->isObject() != isObject)
             continue;
           if (isObject) {
-            if (aRef->object() == anObject)
+            if (aRef->object() == anObject) {
+              theError = errorMessage(EqualObjects, anObject.get() ? anObject->data()->name() : "",
+                                      theAttribute->id(), aRef->id());
               return false;
+            }
           }
           else { // the attribute reference
-            if (aRef->attr() == anAttributeAttr)
+            if (aRef->attr() == anAttributeAttr) {
+              theError = errorMessage(EqualAttributes,
+                                      anAttributeAttr.get() ? anAttributeAttr->id() : "",
+                                      theAttribute->id(), aRef->id());
               return false;
+            }
           }
         }
       }
@@ -247,8 +283,10 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
           // check the object is already presented
           if (aRef->context() == aContext) {
             bool aHasShape = aShape.get() != NULL;
-            if (!aHasShape || aRef->value()->isEqual(aShape))
+            if (!aHasShape || aRef->value()->isEqual(aShape)) {
+              theError = errorMessage(EqualShapes, "", theAttribute->id(), aRef->id());
               return false;
+            }
           }
         }
       }
@@ -266,8 +304,11 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
           std::shared_ptr<ModelAPI_AttributeReference> aRef =
             std::dynamic_pointer_cast<ModelAPI_AttributeReference>(*anAttr);
           // check the object is already presented
-          if (aRef->value() == anObject)
+          if (aRef->value() == anObject) {
+            theError = errorMessage(EqualObjects, anObject.get() ? anObject->data()->name() : "",
+                                    theAttribute->id(), aRef->id());
             return false;
+          }
         }
         return true;
       }
@@ -299,14 +340,22 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
               if(aRefSelCompSolidPtr.get()) {
                 aRefSelCompSolid = aRefSelCompSolidPtr->shape();
               }
-              if((aCurSelCompSolid.get() && aCurSelCompSolid->isEqual(aRefSel->value()))
+              if ((aCurSelCompSolid.get() && aCurSelCompSolid->isEqual(aRefSel->value()))
                 || (aRefSelCompSolid.get() && aRefSelCompSolid->isEqual(aCurSel->value()))) {
+                  theError = errorMessage(EqualShapes, "", theAttribute->id(),
+                                          aRefSel->id());
                   return false;
               }
               if(aCurSelContext == aRefSelContext) {
-                if(aCurSel->value().get() == NULL || aRefSel->value().get() == NULL
-                  || aCurSel->value()->isEqual(aRefSel->value())) {
-                    return false;
+                if (aCurSel->value().get() == NULL || aRefSel->value().get() == NULL) {
+                  theError = errorMessage(EmptyShapes, "", theAttribute->id(),
+                                          aRefSel->id());
+                  return false;
+                }
+                if (aCurSel->value()->isEqual(aRefSel->value())) {
+                  theError = errorMessage(EqualShapes, "", theAttribute->id(),
+                                          aRefSel->id());
+                  return false;
                 }
               }
             }
@@ -329,6 +378,9 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
             ObjectPtr aCurSelObject = aCurSelList->object(i);
             for (int j = 0; j < aRefSelList->size(); j++) {
               if (aCurSelObject == aRefSelList->object(j)) {
+                theError = errorMessage(EqualObjects,
+                              aCurSelObject.get() ? aCurSelObject->data()->name() : "",
+                              theAttribute->id(), aCurSelList->id());
                 return false;
               }
             }
@@ -346,9 +398,13 @@ bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
 {
   bool isSketchEntities = true;
   std::set<std::string> anEntityKinds;
+  std::string anEntityKindsStr;
   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
   for (; anIt != aLast; anIt++) {
     anEntityKinds.insert(*anIt);
+    if (!anEntityKindsStr.empty())
+      anEntityKindsStr += ", ";
+    anEntityKindsStr += *anIt;
   }
 
   std::string anAttributeType = theAttribute->attributeType();
@@ -402,43 +458,22 @@ bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
       }
     }
   }
+  if (!isSketchEntities) {
+    theError = "It refers to feature, which kind is not in the list: " + anEntityKindsStr;
+  }
 
   return isSketchEntities;
 }
 
-
-
-bool PartSet_SameTypeAttrValidator::isValid(const AttributePtr& theAttribute, 
-                                            const std::list<std::string>& theArguments,
-                                            std::string& theError ) const
-{
-  // there is a check whether the feature contains a point and a linear edge or two point values
-  std::string aParamA = theArguments.front();
-  SessionPtr aMgr = ModelAPI_Session::get();
-  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
-  AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  if (!aRefAttr)
-    return false;
-
-  bool isObject = aRefAttr->isObject();
-  ObjectPtr anObject = aRefAttr->object();
-  if (isObject && anObject) {
-    FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
-
-    AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA);
-    ObjectPtr aOtherObject = aOtherAttr->object();
-    FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
-    return aRefFea->getKind() == aOtherFea->getKind();
-  }
-  return false;
-}
-
 bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute, 
                                      const std::list<std::string>& theArguments,
                                      std::string& theError) const
 {
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+
   // there is a check whether the feature contains a point and a linear edge or two point values
   std::string aParamA = theArguments.front();
   SessionPtr aMgr = ModelAPI_Session::get();
@@ -446,9 +481,6 @@ bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute,
 
   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  if (!aRefAttr)
-    return false;
-
   QList<FeaturePtr> aCoinsideLines;
 
   bool isObject = aRefAttr->isObject();
@@ -482,17 +514,17 @@ bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute,
       }
     }
     // if there is no coincidence then it is not valid
-    if (aCoinList.size() == 0)
-      return false;
-
-    QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(), aLast = aCoinsideLines.end();
-    bool aValid = false;
-    for (; anIt != aLast && !aValid; anIt++) {
-      aValid = *anIt == aOtherFea;
+    if (aCoinList.size() > 0) {
+      QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(), aLast = aCoinsideLines.end();
+      bool aValid = false;
+      for (; anIt != aLast && !aValid; anIt++) {
+        aValid = *anIt == aOtherFea;
+      }
+      if (aValid)
+        return true;
     }
-    if (aValid)
-      return true;
   }
+  theError = "There is no a common coincident point.";
   return false;
 }
 
index 6ba2896afa755eb293542d36752dcb7e519f2683..0e02a0e9fcbb1bfb861b010cf2ecaadde8e4c1f3 100644 (file)
@@ -115,6 +115,13 @@ class PartSet_AngleSelection : public ModuleBase_SelectionValidator
 */
 class PartSet_DifferentObjectsValidator : public ModelAPI_AttributeValidator
 {
+  //! Validator possible error types
+  enum ErrorType {
+    EqualObjects,
+    EqualAttributes,
+    EqualShapes,
+    EmptyShapes
+  };
  public:
   //! Returns true if the attribute is good for the feature attribute
   //! \param theAttribute an attribute
@@ -122,6 +129,14 @@ class PartSet_DifferentObjectsValidator : public ModelAPI_AttributeValidator
   virtual bool isValid(const AttributePtr& theAttribute,
                        const std::list<std::string>& theArguments,
                        std::string& theError) const;
+private:
+  //! Returns error message for the error type
+  //! \param theType a type of error
+  //! \param thEqualObjectInfo an 
+  std::string errorMessage(const PartSet_DifferentObjectsValidator::ErrorType& theType,
+                           const std::string& thEqualObject, const std::string& theFirstAttribute,
+                           const std::string& theSecondAttribute) const;
+
 };
 
 /**
@@ -139,23 +154,6 @@ class PartSet_SketchEntityValidator : public ModelAPI_AttributeValidator
                        std::string& theError) const;
 };
 
-/**\class PartSet_SameTypeAttrValidator
- * \ingroup Validators
- * \brief Validator for the tangent constraint input.
- *
- * It just checks that distance is greater than zero.
- */
-class PartSet_SameTypeAttrValidator : public ModelAPI_AttributeValidator
-{
- public:
-  //! returns true if attribute is valid
-  //! \param theAttribute the checked attribute
-  //! \param theArguments arguments of the attribute
-  virtual bool isValid(const AttributePtr& theAttribute,
-                       const std::list<std::string>& theArguments,
-                       std::string& theError) const;
-};
-
 /**\class PartSet_CoincidentAttr
  * \ingroup Validators
  * \brief Validator to check whether there is a coincident constraint between
index e67bae3b8b92081c28f7dfd4c1c82a308d3933ec..be53bdcf704862eda784f95a7dc7c9538713fbf0 100755 (executable)
@@ -35,15 +35,17 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribut
                                                  const std::list<std::string>& theArguments,
                                                  std::string& theError) const
 {
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+
   // there is a check whether the feature contains a point and a linear edge or two point values
   std::string aParamA = theArguments.front();
   SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
 
   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  if (!aRefAttr)
-    return false;
-
   bool isObject = aRefAttr->isObject();
   if (!isObject) {
     // an attribute is a point. A point value is valid always for the distance
@@ -59,81 +61,105 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribut
     std::string aCircleError;
     bool aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aCircleError);
     // the circle line is not a valid case
-    if (aShapeValid)
+    if (aShapeValid) {
+      theError = "Circle can not be used in distance constraint";
       return false;
+    }
       
     anArguments.clear();
     anArguments.push_back("line");
     std::string aLineError;
     aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments, aLineError);
     // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
-    if (!aShapeValid)
-      return true;
-
-    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
-    // If it is a line then we have to check that first attribute id not a line
-    std::shared_ptr<SketchPlugin_Feature> aSFeature =
-                            std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
-    SketchPlugin_Sketch* aSketch = aSFeature->sketch();
-    std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
-    std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
-                                                               aFeature->data(), aParamA, aPlane);
-    if (aPoint)
-      return true;
+    if (aShapeValid) {
+      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+      // If it is a line then we have to check that first attribute id not a line
+      std::shared_ptr<SketchPlugin_Feature> aSFeature =
+        std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
+      SketchPlugin_Sketch* aSketch = aSFeature->sketch();
+      std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
+      std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
+        aFeature->data(), aParamA, aPlane);
+      if (!aPoint.get()) {
+        theError = "One of parameters of distance constraint should be a point";
+        return false;
+      }
+    }
   }
-  return false;
+  return true;
 }
 
 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute, 
                                                 const std::list<std::string>& theArguments,
                                                 std::string& theError) const
 {
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+
   // there is a check whether the feature contains a point and a linear edge or two point values
   std::string aParamA = theArguments.front();
   SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
 
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  FeaturePtr anAttributeFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  if (!aRefAttr)
-    return false;
 
   bool isObject = aRefAttr->isObject();
   ObjectPtr anObject = aRefAttr->object();
-  if (isObject && anObject) {
+  if (isObject && anObject.get()) {
     FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
 
-    AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA);
+    AttributeRefAttrPtr aOtherAttr = anAttributeFeature->data()->refattr(aParamA);
     ObjectPtr aOtherObject = aOtherAttr->object();
     FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
 
     if (aRefFea->getKind() == SketchPlugin_Line::ID()) {
-      if (aOtherFea->getKind() != SketchPlugin_Arc::ID())
+      if (aOtherFea->getKind() != SketchPlugin_Arc::ID()) {
+        theError = "It refers to a " + SketchPlugin_Line::ID() + ", but " + aParamA + " is not an "
+          + SketchPlugin_Arc::ID();
         return false;
-    } else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
+      }
+    }
+    else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
       if (aOtherFea->getKind() != SketchPlugin_Line::ID() &&
-          aOtherFea->getKind() != SketchPlugin_Arc::ID())
+        aOtherFea->getKind() != SketchPlugin_Arc::ID()) {
+        theError = "It refers to an " + SketchPlugin_Arc::ID() + ", but " + aParamA + " is not a "
+          + SketchPlugin_Line::ID() + " or an " + SketchPlugin_Arc::ID();
         return false;
-    } else
+      }
+    }
+    else {
+      theError = "It refers to " + aRefFea->getKind() + "but should refer to " + SketchPlugin_Line::ID()
+        + " or " + SketchPlugin_Arc::ID();
       return false;
-
+    }
     return true;
   }
-  return false;
+  else {
+    theError = "It uses an empty object";
+    return false;
+  }
+
+  return true;
 }
 
 bool SketchPlugin_NotFixedValidator::isValid(const AttributePtr& theAttribute, 
                                              const std::list<std::string>& theArguments,
                                              std::string& theError) const
 {
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+
   std::shared_ptr<SketchPlugin_Feature> aFeature =
       std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
   if (!aFeature)
     return true;
 
   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  if (!aRefAttr)
-    return false;
 
   SketchPlugin_Sketch* aSketch = aFeature->sketch();
   int aNbFeatures = aSketch->numberOfSubs();
@@ -144,10 +170,19 @@ bool SketchPlugin_NotFixedValidator::isValid(const AttributePtr& theAttribute,
     AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
         aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
     if (aRefAttr->isObject()) {
-      if (aRefAttr->object() == aRAttr->object())
+      if (aRefAttr->object() == aRAttr->object()) {
+        ObjectPtr anObject = aRefAttr->object();
+        std::string aName = anObject.get() ? anObject->data()->name() : "";
+        theError = "The object " + aName + " has been already fixed.";
         return false;
-    } else if (aRefAttr->attr() == aRAttr->attr())
+      }
+    }
+    else if (aRefAttr->attr() == aRAttr->attr()) {
+      AttributePtr anAttribute = aRefAttr->attr();
+      std::string aName = anAttribute.get() ? anAttribute->id() : "";
+      theError = "The attribute " + aName + " has been already fixed.";
       return false;
+    }
   }
   return true;
 }
@@ -156,24 +191,36 @@ bool SketchPlugin_EqualAttrValidator::isValid(const AttributePtr& theAttribute,
                                               const std::list<std::string>& theArguments,
                                               std::string& theError) const
 {
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+
   std::string aParamA = theArguments.front();
   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
   AttributeRefAttrPtr aRefAttr[2];
   aRefAttr[0] = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  if (!aRefAttr)
-    return false;
   aRefAttr[1] = aFeature->data()->refattr(aParamA);
 
-  if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject())
+  if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject()) {
+    theError = "Attributes can not be used in equal constraint";
     return false;
+  }
 
   int aType[2] = {0, 0}; // types of attributes: 0 - incorrect, 1 - line, 2 - circle, 3 - arc
   std::list<std::string> anArguments;
   for (int i = 0; i < 2; i++) {
     ObjectPtr anObject = aRefAttr[i]->object();
+    if (!anObject.get()) {
+      theError = "An empty object is used.";
+      return false;
+    }
+
     aFeature = ModelAPI_Feature::feature(anObject);
-    if (!aFeature)
+    if (!aFeature.get()) {
+      theError = "An empty feature is used.";
       return false;
+    }
 
     if (aFeature->getKind() == SketchPlugin_Line::ID()) {
       aType[i] = 1;
@@ -187,13 +234,19 @@ bool SketchPlugin_EqualAttrValidator::isValid(const AttributePtr& theAttribute,
       aType[i] = 3;
       continue;
     }
+    theError = "The " + aFeature->getKind() + " feature kind of attribute is wrong. It should be " +
+               SketchPlugin_Line::ID() + " or " + SketchPlugin_Circle::ID() + " or " + 
+               SketchPlugin_Arc::ID();
     // wrong type of attribute
     return false;
   }
 
   if ((aType[0] == 1 && aType[1] == 2) ||
-      (aType[0] == 2 && aType[1] == 1))
+      (aType[0] == 2 && aType[1] == 1)) {
+    theError = "Feature with kinds " + SketchPlugin_Line::ID() + " and " +
+               SketchPlugin_Circle::ID() + "can not be equal.";
     return false;
+  }
   return true;
 }
 
@@ -201,11 +254,13 @@ bool SketchPlugin_MirrorAttrValidator::isValid(const AttributePtr& theAttribute,
                                                const std::list<std::string>& theArguments,
                                                std::string& theError) const
 {
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
-  AttributeRefListPtr aSelAttr = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
-  if (!aSelAttr)
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
     return false;
+  }
+
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
 
   AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
       aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
@@ -213,10 +268,13 @@ bool SketchPlugin_MirrorAttrValidator::isValid(const AttributePtr& theAttribute,
 
   for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
     ObjectPtr aSelObject = aSelAttr->object(anInd);
+    std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
     std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
     for (; aMirIter != aMirroredObjects.end(); aMirIter++)
-      if (aSelObject == *aMirIter)
+      if (aSelObject == *aMirIter) {
+        theError = "The object " + aName + " is a result of mirror";
         return false;
+      }
   }
   return true;
 }
@@ -226,6 +284,11 @@ bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttri
                                                     const std::list<std::string>& theArguments,
                                                     std::string& theError) const
 {
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+
   // there is a check whether the feature contains a point and a linear edge or two point values
   std::string aParamA = theArguments.front();
   SessionPtr aMgr = ModelAPI_Session::get();
@@ -233,20 +296,28 @@ bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttri
 
   FeaturePtr aConstraint = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
   AttributeRefAttrPtr aRefAttrA = aConstraint->data()->refattr(aParamA);
-  if (!aRefAttrA)
+  if (!aRefAttrA) {
+    theError = "The " + aParamA + " attribute " + " should be " + ModelAPI_AttributeRefAttr::typeId();
     return false;
+  }
 
   AttributeRefAttrPtr aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  if (!aRefAttrB)
-    return false;
 
   // first attribute is a point, it may coincide with any object
   if (!aRefAttrA->isObject())
     return true;
   else {
+    ObjectPtr anObject = aRefAttrA->object();
+    if (!anObject.get()) {
+      theError = aParamA + " attribute has an empty object";
+      return false;
+    }
     FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrA->object());
-    if (!aFeature)
+    if (!aFeature.get()) {
+      theError = aParamA + " attribute has an empty feature";
       return false;
+    }
+
     if (aFeature->getKind() == SketchPlugin_Point::ID())
       return true;
   }
@@ -256,12 +327,14 @@ bool SketchPlugin_CoincidenceAttrValidator::isValid(const AttributePtr& theAttri
     return true;
   else {
     FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttrB->object());
-    if (!aFeature)
+    if (!aFeature) {
+      theError = theAttribute->id() + " attribute has an empty object";
       return false;
+    }
     if (aFeature->getKind() == SketchPlugin_Point::ID())
       return true;
   }
-
+  theError = "There is no an attribute filled by a point";
   return false;
 }
 
@@ -270,11 +343,14 @@ bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
                                          const std::list<std::string>& theArguments,
                                          std::string& theError) const
 {
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefList::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+
   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
   AttributeRefListPtr aSelAttr = 
     std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
-  if (!aSelAttr)
-    return false;
 
   AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
       aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
@@ -294,8 +370,11 @@ bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
       continue;
     anObjIter = aCopiedObjects.begin();
     for (; anObjIter != aCopiedObjects.end(); anObjIter++)
-      if (aSelObject == *anObjIter)
+      if (aSelObject == *anObjIter) {
+        std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
+        theError = "The object " + aName + " is a result of copy";
         return false;
+      }
   }
   return true;
 }