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