1 // File: SketchPlugin_Validators.cpp
2 // Created: 01 Aug 2014
3 // Author: Vitaly SMETANNIKOV
5 #include "SketchPlugin_Validators.h"
6 #include "SketchPlugin_ConstraintDistance.h"
7 #include <ModelAPI_Data.h>
8 #include <ModelAPI_Validator.h>
9 #include <ModelAPI_ResultValidator.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeRefAttr.h>
12 #include <GeomDataAPI_Point2D.h>
14 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
15 const std::list<std::string>& theArguments,
16 const ObjectPtr& theObject) const
18 std::string aParamA = theArguments.front();
19 SessionPtr aMgr = ModelAPI_Session::get();
20 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
22 // If the object is not a line then it is accepted
23 const ModelAPI_ResultValidator* aLineValidator =
24 dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLineValidator"));
25 if (aLineValidator && (!aLineValidator->isValid(theObject)))
28 // If it is a line then we have to check that first attribute id not a line
29 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(theFeature->data(), aParamA);
35 bool SketchPlugin_DistanceAttrValidator::isValid(
36 const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
38 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
39 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
41 const ObjectPtr& anObj = theAttribute->owner();
42 const FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
43 return isValid(aFeature, theArguments, anAttr->object());
45 return true; // it may be not reference attribute, in this case, it is OK
48 bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
49 const std::list<std::string>& theArguments,
50 const ObjectPtr& theObject) const
52 std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttrs =
53 theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
54 std::list<boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
55 for(; anAttr != anAttrs.end(); anAttr++) {
57 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
58 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
59 // check the object is already presented
60 if (aRef->isObject() && aRef->object() == theObject)
67 bool SketchPlugin_DifferentObjectsValidator::isValid(
68 const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
70 boost::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
71 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
72 if (anOrigAttr && anOrigAttr->isObject()) {
73 const ObjectPtr& anObj = theAttribute->owner();
74 const FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
76 std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttrs =
77 aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
78 std::list<boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
79 for(; anAttr != anAttrs.end(); anAttr++) {
80 if (*anAttr && *anAttr != theAttribute) {
81 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
82 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
83 // check the object is already presented
84 if (aRef->isObject() && aRef->object() == anOrigAttr->object())