]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_Validators.cpp
Salome HOME
Make general validation mechanism also for attributes the validate method for feature...
[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 <GeomDataAPI_Point2D.h>
11
12 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
13                                                  const std::list<std::string>& theArguments,
14                                                  const ObjectPtr& theObject) const
15 {
16   std::string aParamA = theArguments.front();
17   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
18   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
19
20   // If the object is not a line then it is accepted
21   const ModelAPI_ResultValidator* aLineValidator =
22       dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("Model_ResultLineValidator"));
23   if (!aLineValidator->isValid(theObject))
24     return true;
25
26   // If it is a line then we have to check that first attribute id not a line
27   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(theFeature->data(), aParamA);
28   if (aPoint)
29     return true;
30   return false;
31 }
32
33 bool SketchPlugin_DistanceAttrValidator::isValid(
34   const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
35 {
36   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
37     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
38   if (anAttr) {
39     const ObjectPtr& anObj = theAttribute->owner();
40     const FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
41     return isValid(aFeature, theArguments, anAttr->object());
42   }
43   return true; // it may be not reference attribute, in this case, it is OK
44 }