Salome HOME
Union of validator and filter functionalities.
[modules/shaper.git] / src / GeomValidators / GeomValidators_EdgeOrVertex.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3
4 #include "GeomValidators_EdgeOrVertex.h"
5 #include "GeomValidators_Tools.h"
6 #include "GeomValidators_Edge.h"
7
8 #include "ModelAPI_AttributeRefAttr.h"
9 #include "ModelAPI_Result.h"
10
11 #include <ModelAPI_Session.h>
12
13 #include <GeomAPI_Curve.h>
14 #include <GeomDataAPI_Point2D.h>
15
16 #include <Events_Error.h>
17
18 #include <StdSelect_TypeOfEdge.hxx>
19
20 #include <QString>
21 #include <QMap>
22
23
24 bool GeomValidators_EdgeOrVertex::isValid(const AttributePtr& theAttribute,
25                                           const std::list<std::string>& theArguments) const
26 {
27   bool aValid = false;
28
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();
33
34   const GeomValidators_Edge* aLinearEdgeValidator =
35     dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
36
37   std::list<std::string> anArguments;
38   anArguments.push_back("line");
39   aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments);
40   if (!aValid) {
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();
50         }
51       }
52     }
53     else {
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();
58       }
59     }
60   }
61   return aValid;
62 }