From: nds Date: Mon, 7 Sep 2015 12:07:20 +0000 (+0300) Subject: It provides error messages for validators. X-Git-Tag: V_1.4.0_beta4~90 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e98f5ede19029ac09ae9fe78061a4485bd6b86b5;p=modules%2Fshaper.git It provides error messages for validators. --- diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index 72d12f740..74284b8d5 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -18,7 +18,7 @@ shape_types="vertex"> - + diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index 6cf5f5379..c23f5aa40 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -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 diff --git a/src/GeomValidators/GeomValidators_ConstructionComposite.cpp b/src/GeomValidators/GeomValidators_ConstructionComposite.cpp index 25e2565ee..b19719831 100644 --- a/src/GeomValidators/GeomValidators_ConstructionComposite.cpp +++ b/src/GeomValidators/GeomValidators_ConstructionComposite.cpp @@ -10,48 +10,57 @@ bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttrib const std::list& theArguments, std::string& theError) const { - bool aValid = false; - AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast - (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 + (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(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(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(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(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(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 index 000000000..e9470daf4 --- /dev/null +++ b/src/GeomValidators/GeomValidators_DifferentShapes.cpp @@ -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 +#include "ModelAPI_Object.h" + +bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeSelectionPtr aSelectionAttribute = + std::dynamic_pointer_cast(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 anAttrs = + aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId()); + if (anAttrs.size() > 0 && aShape.get() != NULL) { + std::list::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(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 index 000000000..1fbb004e0 --- /dev/null +++ b/src/GeomValidators/GeomValidators_DifferentShapes.h @@ -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 + +#include +#include + +/** + * 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& theArguments, + std::string& theError) const; +}; + +#endif diff --git a/src/GeomValidators/GeomValidators_Face.cpp b/src/GeomValidators/GeomValidators_Face.cpp index a9fb025ae..51a5012cd 100644 --- a/src/GeomValidators/GeomValidators_Face.cpp +++ b/src/GeomValidators/GeomValidators_Face.cpp @@ -34,23 +34,20 @@ bool GeomValidators_Face::isValid(const AttributePtr& theAttribute, const std::list& 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(theAttribute); - if (aSelectionAttr.get() == NULL) { - theError = "Is not a selection attribute."; - return aValid; - } - + std::dynamic_pointer_cast(theAttribute); std::shared_ptr 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 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; } diff --git a/src/GeomValidators/GeomValidators_Finite.cpp b/src/GeomValidators/GeomValidators_Finite.cpp index e4f623104..150415cb1 100755 --- a/src/GeomValidators/GeomValidators_Finite.cpp +++ b/src/GeomValidators/GeomValidators_Finite.cpp @@ -25,6 +25,7 @@ bool GeomValidators_Finite::isValid(const AttributePtr& theAttribute, ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aResult); if (aConstruction.get() && aConstruction->isInfinite()) { aValid = false; + theError = "Infinite result is selected."; } } } diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index 1bb88e053..80e6af9d0 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -21,10 +21,9 @@ typedef std::map 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::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& theArguments, std::string& theError) const @@ -50,105 +65,138 @@ bool GeomValidators_ShapeType::isValid(const AttributePtr& theAttribute, bool aValid = false; std::list::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(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::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(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(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(theAttribute); - if (anAttr.get() != NULL) - aValid = isValidObject(anAttr->value(), theShapeType); + AttributeReferencePtr anAttr = + std::dynamic_pointer_cast(theAttribute); + aValid = isValidObject(anAttr->value(), theShapeType, theError); + } + else if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aListAttr = + std::dynamic_pointer_cast(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(theObject); if( theShapeType==Plane ) { ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast(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; diff --git a/src/GeomValidators/GeomValidators_ShapeType.h b/src/GeomValidators/GeomValidators_ShapeType.h index 5d30779b1..fd6e24e18 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.h +++ b/src/GeomValidators/GeomValidators_ShapeType.h @@ -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; }; diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index e0c9dbb40..70d61ff25 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -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 index 2348819b0..000000000 --- a/src/ModelAPI/ModelAPI_ShapeValidator.cpp +++ /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 -#include "ModelAPI_Object.h" - -bool ModelAPI_ShapeValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const -{ - FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); - AttributeSelectionPtr aSelectionAttribute = - std::dynamic_pointer_cast(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 anAttrs = - aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId()); - if (anAttrs.size() > 0 && aShape.get() != NULL) { - std::list::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(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 index 878ad80e6..000000000 --- a/src/ModelAPI/ModelAPI_ShapeValidator.h +++ /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 - -#include -#include - -/** - * 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& theArguments, - std::string& theError) const; -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 6ee563fc7..d2009ac41 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -18,6 +18,8 @@ #include #include +#include + #include #include #include @@ -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 aColor = Config_PropManager::color(theSection, theName, theDefault); + return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB); +} + } diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index aa22e46ba..600a5334f 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -15,6 +15,8 @@ #include #include +#include + #include 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 diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 84c409d50..113a6113f 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 3540797e9..6304bd232 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include @@ -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); } diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index d82056999..64e785960 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -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) diff --git a/src/PartSet/PartSet_OperationPrs.h b/src/PartSet/PartSet_OperationPrs.h index 20078787d..ca3eaa2dd 100755 --- a/src/PartSet/PartSet_OperationPrs.h +++ b/src/PartSet/PartSet_OperationPrs.h @@ -21,6 +21,8 @@ #include #include +#include + #include #include @@ -98,6 +100,9 @@ private: FeaturePtr myFeature; /// Reference to a feature object QMap > myFeatureShapes; /// visualized shapes std::list myFeatureResults; /// visualized feature results + + Quantity_Color myShapeColor; /// color of feature depended shapes + Quantity_Color myResultColor; /// color of feature result }; diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 6aac44781..02683b355 100755 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -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& 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 aRef = std::dynamic_pointer_cast(*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 anEntityKinds; + std::string anEntityKindsStr; std::list::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& 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(theAttribute->owner()); - AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(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& 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(theAttribute->owner()); AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); - if (!aRefAttr) - return false; - QList 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::const_iterator anIt = aCoinsideLines.begin(), aLast = aCoinsideLines.end(); - bool aValid = false; - for (; anIt != aLast && !aValid; anIt++) { - aValid = *anIt == aOtherFea; + if (aCoinList.size() > 0) { + QList::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; } diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index 6ba2896af..0e02a0e9f 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -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& 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& theArguments, - std::string& theError) const; -}; - /**\class PartSet_CoincidentAttr * \ingroup Validators * \brief Validator to check whether there is a coincident constraint between diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index e67bae3b8..be53bdcf7 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -35,15 +35,17 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribut const std::list& 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(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(theAttribute->owner()); - // If it is a line then we have to check that first attribute id not a line - std::shared_ptr aSFeature = - std::dynamic_pointer_cast(theAttribute->owner()); - SketchPlugin_Sketch* aSketch = aSFeature->sketch(); - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(aSketch); - std::shared_ptr aPoint = SketcherPrs_Tools::getFeaturePoint( - aFeature->data(), aParamA, aPlane); - if (aPoint) - return true; + if (aShapeValid) { + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + // If it is a line then we have to check that first attribute id not a line + std::shared_ptr aSFeature = + std::dynamic_pointer_cast(theAttribute->owner()); + SketchPlugin_Sketch* aSketch = aSFeature->sketch(); + std::shared_ptr aPlane = SketchPlugin_Sketch::plane(aSketch); + std::shared_ptr 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& 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(theAttribute->owner()); + FeaturePtr anAttributeFeature = std::dynamic_pointer_cast(theAttribute->owner()); AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(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& 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 aFeature = std::dynamic_pointer_cast(theAttribute->owner()); if (!aFeature) return true; AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(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( 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& 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(theAttribute->owner()); AttributeRefAttrPtr aRefAttr[2]; aRefAttr[0] = std::dynamic_pointer_cast(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 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& theArguments, std::string& theError) const { - FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); - AttributeRefListPtr aSelAttr = - std::dynamic_pointer_cast(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(theAttribute->owner()); + AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast(theAttribute); AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast( 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::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& 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(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(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& 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(theAttribute->owner()); AttributeRefListPtr aSelAttr = std::dynamic_pointer_cast(theAttribute); - if (!aSelAttr) - return false; AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast( 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; }