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 <ModuleBase_ValidatorLinearEdge.h>
17 #include <GeomDataAPI_Point2D.h>
19 bool SketchPlugin_DistanceAttrValidator::isValid(
20 const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
22 // there is a check whether the feature contains a point and a linear edge or two point values
23 std::string aParamA = theArguments.front();
24 SessionPtr aMgr = ModelAPI_Session::get();
25 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
27 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
31 bool isObject = aRefAttr->isObject();
33 // an attribute is a point. A point value is valid always for the distance
36 // 1. check whether the references object is a linear
37 ObjectPtr anObject = aRefAttr->object();
39 const ModelAPI_AttributeValidator* aCircleValidator =
40 dynamic_cast<ModuleBase_ValidatorLinearEdge*>(aFactory->validator("ModuleBase_ValidatorLinearEdge"));
41 std::list<std::string> anArguments;
42 anArguments.push_back("circle");
43 bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments);
48 anArguments.push_back("line");
49 bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments);
53 /*const ModelAPI_ResultValidator* anArcValidator = aFactory->validator("ModuleBase_ValidatorLinearEdge");
54 //dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
55 bool anArcValid = anArcValidator->isValid(anObject);
59 // If the object is not a line then it is accepted. It can be a point feature selected
60 const ModelAPI_ResultValidator* aLineValidator =
61 dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
62 bool aLineValid = aLineValidator->isValid(anObject);
66 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
67 // If it is a line then we have to check that first attribute id not a line
68 std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
75 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
76 // const std::list<std::string>& theArguments,
77 // const ObjectPtr& theObject) const
79 // std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
80 // theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
81 // std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
82 // for(; anAttr != anAttrs.end(); anAttr++) {
84 // std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
85 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
86 // // check the object is already presented
87 // if (aRef->isObject() && aRef->object() == theObject)
94 //bool SketchPlugin_DifferentObjectsValidator::isValid(
95 // const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
97 // std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
98 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
99 // if (anOrigAttr && anOrigAttr->isObject()) {
100 // const ObjectPtr& anObj = theAttribute->owner();
101 // const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
103 // std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
104 // aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
105 // std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
106 // for(; anAttr != anAttrs.end(); anAttr++) {
107 // if (*anAttr && *anAttr != theAttribute) {
108 // std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
109 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
110 // // check the object is already presented
111 // if (aRef->isObject() && aRef->object() == anOrigAttr->object())
119 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
120 // const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
122 // std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
123 // theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
124 // std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
125 // for(; anAttr != anAttrs.end(); anAttr++) {
127 // std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
128 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
129 // // check the object is already presented
130 // if (!aRef->isObject() && aRef->attr() == theAttribute)