Salome HOME
Make the correct order in the searching of shape by name algorithm
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchPlugin_Validators.cpp
4 // Created:     01 Aug 2014
5 // Author:      Vitaly SMETANNIKOV
6
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>
16
17 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
18                                                  const std::list<std::string>& theArguments,
19                                                  const ObjectPtr& theObject,
20                                                  const GeomShapePtr& theShape) const
21 {
22   std::string aParamA = theArguments.front();
23   SessionPtr aMgr = ModelAPI_Session::get();
24   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
25
26   const ModelAPI_ResultValidator* anArcValidator =
27       dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
28   bool anArcValid = anArcValidator->isValid(theObject);
29   if (anArcValid)
30     return false;
31
32
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);
37   if (!aLineValid)
38     return true;
39
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);
42   if (aPoint)
43     return true;
44   return false;
45 }
46
47 bool SketchPlugin_DistanceAttrValidator::isValid(
48   const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
49 {
50   // any point attribute is acceptable for the distance operation
51   return true;
52 }
53
54 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
55                                                  const std::list<std::string>& theArguments,
56                                                  const AttributePtr& theAttribute) const
57 {
58   return isValid(theAttribute, theArguments);
59 }
60
61 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
62 //                                                 const std::list<std::string>& theArguments,
63 //                                                 const ObjectPtr& theObject) const
64 //{
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++) {
69 //    if (*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)
74 //        return false;
75 //    }
76 //  }
77 //  return true;
78 //}
79
80 //bool SketchPlugin_DifferentObjectsValidator::isValid(
81 //  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
82 //{
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);
88 //
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())
98 //          return false;
99 //      }
100 //    }
101 //  }
102 //  return true;
103 //}
104
105 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
106 //  const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
107 //{
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++) {
112 //    if (*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)
117 //        return false;
118 //    }
119 //  }
120 //  return true;
121 //}