Salome HOME
Constraint icons added
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
1 // File:        SketchPlugin_Validators.cpp
2 // Created:     01 Aug 2014
3 // Author:      Vitaly SMETANNIKOV
4
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 <GeomDataAPI_Point2D.h>
12
13 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
14                                                  const std::list<std::string>& theArguments,
15                                                  const ObjectPtr& theObject) const
16 {
17   std::string aParamA = theArguments.front();
18   SessionPtr aMgr = ModelAPI_Session::get();
19   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
20
21   // If the object is not a line then it is accepted
22   const ModelAPI_ResultValidator* aLineValidator =
23       dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLineValidator"));
24   if (!aLineValidator->isValid(theObject))
25     return true;
26
27   // If it is a line then we have to check that first attribute id not a line
28   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(theFeature->data(), aParamA);
29   if (aPoint)
30     return true;
31   return false;
32 }
33
34 bool SketchPlugin_DistanceAttrValidator::isValid(
35   const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
36 {
37   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
38     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
39   if (anAttr) {
40     const ObjectPtr& anObj = theAttribute->owner();
41     const FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
42     return isValid(aFeature, theArguments, anAttr->object());
43   }
44   return true; // it may be not reference attribute, in this case, it is OK
45 }
46
47 bool SketchPlugin_RadiusValidator::isValid(
48     const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
49 {
50   boost::shared_ptr<ModelAPI_AttributeDouble> aDouble = 
51     boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
52   return aDouble->isInitialized() && aDouble->value() > 1.e-5;
53 }