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 <ModelAPI_Session.h>
13 #include <GeomDataAPI_Point2D.h>
15 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
16 const std::list<std::string>& theArguments,
17 const ObjectPtr& theObject) const
19 std::string aParamA = theArguments.front();
20 SessionPtr aMgr = ModelAPI_Session::get();
21 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
23 // If the object is not a line then it is accepted
24 const ModelAPI_ResultValidator* aLineValidator =
25 dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
26 if (!aLineValidator->isValid(theObject))
29 // If it is a line then we have to check that first attribute id not a line
30 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(theFeature->data(), aParamA);
36 bool SketchPlugin_DistanceAttrValidator::isValid(
37 const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
39 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
40 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
42 const ObjectPtr& anObj = theAttribute->owner();
43 const FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
44 return isValid(aFeature, theArguments, anAttr->object());
46 return true; // it may be not reference attribute, in this case, it is OK
49 bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
50 const std::list<std::string>& theArguments,
51 const ObjectPtr& theObject) const
53 std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttrs =
54 theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
55 std::list<boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
56 for(; anAttr != anAttrs.end(); anAttr++) {
58 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
59 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
60 // check the object is already presented
61 if (aRef->isObject() && aRef->object() == theObject)
68 bool SketchPlugin_DifferentObjectsValidator::isValid(
69 const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
71 boost::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
72 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
73 if (anOrigAttr && anOrigAttr->isObject()) {
74 const ObjectPtr& anObj = theAttribute->owner();
75 const FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
77 std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttrs =
78 aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
79 std::list<boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
80 for(; anAttr != anAttrs.end(); anAttr++) {
81 if (*anAttr && *anAttr != theAttribute) {
82 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
83 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
84 // check the object is already presented
85 if (aRef->isObject() && aRef->object() == anOrigAttr->object())