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