1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_Validators.cpp
4 // Created: 01 Aug 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "SketchPlugin_Validators.h"
8 #include "SketchPlugin_ConstraintDistance.h"
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Validator.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeRefAttr.h>
13 #include <ModelAPI_Session.h>
15 #include <GeomValidators_Edge.h>
17 #include <GeomDataAPI_Point2D.h>
19 bool SketchPlugin_DistanceAttrValidator::isValid(
20 const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
21 //bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
22 // const std::list<std::string>& theArguments,
23 // const ObjectPtr& theObject,
24 // const GeomShapePtr& theShape) const
25 // ======= end of todo master
27 // there is a check whether the feature contains a point and a linear edge or two point values
28 std::string aParamA = theArguments.front();
29 SessionPtr aMgr = ModelAPI_Session::get();
30 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
32 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
36 bool isObject = aRefAttr->isObject();
38 // an attribute is a point. A point value is valid always for the distance
41 // 1. check whether the references object is a linear
42 ObjectPtr anObject = aRefAttr->object();
44 const ModelAPI_AttributeValidator* anEdgeValidator =
45 dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
46 std::list<std::string> anArguments;
47 anArguments.push_back("circle");
48 bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
49 // the circle line is not a valid case
54 anArguments.push_back("line");
55 anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
56 // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
60 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
61 // If it is a line then we have to check that first attribute id not a line
62 std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
68 // TODO(nds) v1.0.2, master
72 //bool SketchPlugin_DistanceAttrValidator::isValid(
73 // const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
75 // // any point attribute is acceptable for the distance operation
79 //bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
80 // const std::list<std::string>& theArguments,
81 // const AttributePtr& theAttribute) const
83 // return isValid(theAttribute, theArguments);
86 // commented in v1.0.2, master:
87 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
88 // const std::list<std::string>& theArguments,
89 // const ObjectPtr& theObject) const
91 // std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
92 // theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
93 // std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
94 // for(; anAttr != anAttrs.end(); anAttr++) {
96 // std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
97 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
98 // // check the object is already presented
99 // if (aRef->isObject() && aRef->object() == theObject)
106 //bool SketchPlugin_DifferentObjectsValidator::isValid(
107 // const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
109 // std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
110 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
111 // if (anOrigAttr && anOrigAttr->isObject()) {
112 // const ObjectPtr& anObj = theAttribute->owner();
113 // const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
115 // std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
116 // aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
117 // std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
118 // for(; anAttr != anAttrs.end(); anAttr++) {
119 // if (*anAttr && *anAttr != theAttribute) {
120 // std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
121 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
122 // // check the object is already presented
123 // if (aRef->isObject() && aRef->object() == anOrigAttr->object())
131 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
132 // const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
134 // std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
135 // theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
136 // std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
137 // for(; anAttr != anAttrs.end(); anAttr++) {
139 // std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
140 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
141 // // check the object is already presented
142 // if (!aRef->isObject() && aRef->attr() == theAttribute)
148 // =========== end of todo