#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_Result.h>
-#include "ModelAPI_AttributeRefAttr.h"
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeReference.h>
#include <Events_Error.h>
{
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;
}
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<ModelAPI_Result>(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<ModelAPI_AttributeSelectionList>(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<ModelAPI_AttributeSelection>(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<ModelAPI_AttributeRefAttr>(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<ModelAPI_AttributeReference>(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<ModelAPI_Result>(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;
}