1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 #include "GeomValidators_EdgeOrVertex.h"
5 #include "GeomValidators_Tools.h"
6 #include "GeomValidators_Edge.h"
8 #include "ModelAPI_AttributeRefAttr.h"
9 #include "ModelAPI_Result.h"
11 #include <ModelAPI_Session.h>
13 #include <GeomAPI_Curve.h>
14 #include <GeomDataAPI_Point2D.h>
16 #include <Events_Error.h>
18 #include <StdSelect_TypeOfEdge.hxx>
24 bool GeomValidators_EdgeOrVertex::isValid(const AttributePtr& theAttribute,
25 const std::list<std::string>& theArguments) const
29 // 1. check whether the attribute is a linear edge
30 // there is a check whether the feature contains a point and a linear edge or two point values
31 SessionPtr aMgr = ModelAPI_Session::get();
32 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
34 const GeomValidators_Edge* aLinearEdgeValidator =
35 dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
37 std::list<std::string> anArguments;
38 anArguments.push_back("line");
39 aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments);
41 //2. check whether the attribute is a vertex
42 ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
43 if (anObject.get() != NULL) {
44 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
45 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
46 if (aResult.get() != NULL) {
47 GeomShapePtr aShape = aResult->shape();
48 if (aShape.get() != NULL) {
49 aValid = aShape->isVertex();
54 AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
55 if (anAttr.get() != NULL) {
56 AttributePtr aRefAttr = anAttr->attr();
57 aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type();