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_ResultValidator.h>
12 #include <ModelAPI_AttributeDouble.h>
13 #include <ModelAPI_AttributeRefAttr.h>
14 #include <ModelAPI_Session.h>
15 #include <GeomDataAPI_Point2D.h>
17 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
18 const std::list<std::string>& theArguments,
19 const ObjectPtr& theObject,
20 const GeomShapePtr& theShape) const
22 std::string aParamA = theArguments.front();
23 SessionPtr aMgr = ModelAPI_Session::get();
24 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
26 const ModelAPI_ResultValidator* anArcValidator =
27 dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
28 bool anArcValid = anArcValidator->isValid(theObject);
33 // If the object is not a line then it is accepted
34 const ModelAPI_ResultValidator* aLineValidator =
35 dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
36 bool aLineValid = aLineValidator->isValid(theObject);
40 // If it is a line then we have to check that first attribute id not a line
41 std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(theFeature->data(), aParamA);
47 bool SketchPlugin_DistanceAttrValidator::isValid(
48 const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
50 // any point attribute is acceptable for the distance operation
54 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
55 const std::list<std::string>& theArguments,
56 const AttributePtr& theAttribute) const
58 return isValid(theAttribute, theArguments);
61 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
62 // const std::list<std::string>& theArguments,
63 // const ObjectPtr& theObject) const
65 // std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
66 // theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
67 // std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
68 // for(; anAttr != anAttrs.end(); anAttr++) {
70 // std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
71 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
72 // // check the object is already presented
73 // if (aRef->isObject() && aRef->object() == theObject)
80 //bool SketchPlugin_DifferentObjectsValidator::isValid(
81 // const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
83 // std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
84 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
85 // if (anOrigAttr && anOrigAttr->isObject()) {
86 // const ObjectPtr& anObj = theAttribute->owner();
87 // const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
89 // std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
90 // aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
91 // std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
92 // for(; anAttr != anAttrs.end(); anAttr++) {
93 // if (*anAttr && *anAttr != theAttribute) {
94 // std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
95 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
96 // // check the object is already presented
97 // if (aRef->isObject() && aRef->object() == anOrigAttr->object())
105 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
106 // const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
108 // std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
109 // theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
110 // std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
111 // for(; anAttr != anAttrs.end(); anAttr++) {
113 // std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
114 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
115 // // check the object is already presented
116 // if (!aRef->isObject() && aRef->attr() == theAttribute)