X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_ShapeType.cpp;h=b8012aedfbe741faef85d0ccb70d0c2e3093ce54;hb=2452f6e679a2c0a4f261dac25e4b6592f0a540c1;hp=f5ce2fd0b396d52b27544c5ef3657d4028281391;hpb=c135d354a2431bd8edcef0750add2f354d0fba4a;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index f5ce2fd0b..b8012aedf 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -8,7 +8,9 @@ #include #include -#include "ModelAPI_AttributeRefAttr.h" +#include +#include +#include #include @@ -23,14 +25,17 @@ GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const { if (MyEdgeTypes.size() == 0) { MyEdgeTypes["vertex"] = Vertex; + MyEdgeTypes["edge"] = Edge; MyEdgeTypes["line"] = Line; MyEdgeTypes["circle"] = Circle; + MyEdgeTypes["solid"] = Solid; + MyEdgeTypes["face"] = Face; } std::string aType = std::string(theType.c_str()); if (MyEdgeTypes.find(aType) != MyEdgeTypes.end()) return MyEdgeTypes[aType]; - Events_Error::send("Edge type defined in XML is not implemented!"); + Events_Error::send("Shape type defined in XML is not implemented!"); return AnyShape; } @@ -55,36 +60,98 @@ bool GeomValidators_ShapeType::isValidArgument(const AttributePtr& theAttribute, if (aShapeType == AnyShape) return true; - ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute); - if (anObject.get() != NULL) { - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get() != NULL) { - GeomShapePtr aShape = aResult->shape(); - if (aShape.get() != NULL) { - switch (aShapeType) { - case Line: - aValid = aShape->isEdge() && !GeomAPI_Curve(aShape).isCircle(); - break; - case Circle: - aValid = aShape->isEdge() && GeomAPI_Curve(aShape).isCircle(); - break; - case Vertex: - aValid = aShape->isVertex(); - break; - default: break; - } - } + AttributeSelectionListPtr aListAttr = + std::dynamic_pointer_cast(theAttribute); + if (aListAttr.get()) { + 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; } } else { + aValid = isValidAttribute(theAttribute, aShapeType); + } + return aValid; +} + +bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute, + const TypeOfShape theShapeType) const +{ + bool aValid = false; + + 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); + else + aValid = isValidObject(anAttr->context(), theShapeType); + } + else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) { AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); if (anAttr.get() != NULL) { - if (aShapeType == Vertex) { + if (anAttr->isObject()) { + aValid = isValidObject(anAttr->object(), theShapeType); + } + else if (theShapeType == Vertex) { AttributePtr aRefAttr = anAttr->attr(); aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::typeId(); } } } + else if (anAttributeType == ModelAPI_AttributeReference::typeId()) { + AttributeReferencePtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr.get() != NULL) + aValid = isValidObject(anAttr->value(), theShapeType); + } + return aValid; +} + +bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject, + const TypeOfShape theShapeType) const +{ + bool aValid = false; + if (theObject.get() != NULL) { + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get() != NULL) { + GeomShapePtr aShape = aResult->shape(); + aValid = isValidShape(aShape, theShapeType); + } + } + return aValid; +} + +bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape, + const TypeOfShape theShapeType) const +{ + bool aValid = false; + + if (theShape.get() != NULL) { + switch (theShapeType) { + case Edge: + aValid = theShape->isEdge(); + break; + case Line: + aValid = theShape->isEdge() && !GeomAPI_Curve(theShape).isCircle(); + break; + case Circle: + aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isCircle(); + break; + case Vertex: + aValid = theShape->isVertex(); + break; + case Solid: + aValid = theShape->isSolid(); + break; + case Face: + aValid = theShape->isFace(); + break; + default: break; + } + } return aValid; }