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
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* anEdgeValidator =
40 dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
41 std::list<std::string> anArguments;
42 anArguments.push_back("circle");
43 bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
44 // the circle line is not a valid case
49 anArguments.push_back("line");
50 anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
51 // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
55 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
56 // If it is a line then we have to check that first attribute id not a line
57 std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);