]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_Validators.cpp
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[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_AttributeDouble.h>
12 #include <ModelAPI_AttributeRefAttr.h>
13 #include <ModelAPI_Session.h>
14
15 #include <GeomValidators_Edge.h>
16
17 #include <GeomDataAPI_Point2D.h>
18
19 bool SketchPlugin_DistanceAttrValidator::isValid(
20   const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
21 //bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
22 //                                                 const std::list<std::string>& theArguments,
23 //                                                 const ObjectPtr& theObject,
24 //                                                 const GeomShapePtr& theShape) const
25 // ======= end of todo master
26 {
27   // there is a check whether the feature contains a point and a linear edge or two point values
28   std::string aParamA = theArguments.front();
29   SessionPtr aMgr = ModelAPI_Session::get();
30   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
31
32   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
33   if (!aRefAttr)
34     return false;
35
36   bool isObject = aRefAttr->isObject();
37   if (!isObject) {
38     // an attribute is a point. A point value is valid always for the distance
39     return true;
40   } else {
41     // 1. check whether the references object is a linear
42     ObjectPtr anObject = aRefAttr->object();
43
44     const ModelAPI_AttributeValidator* anEdgeValidator = 
45       dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
46     std::list<std::string> anArguments;
47     anArguments.push_back("circle");
48     bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
49     // the circle line is not a valid case
50     if (anEdgeValid)
51       return false;
52       
53     anArguments.clear();
54     anArguments.push_back("line");
55     anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
56     // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
57     if (!anEdgeValid)
58       return true;
59
60     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
61     // If it is a line then we have to check that first attribute id not a line
62     std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
63     if (aPoint)
64       return true;
65   }
66   return false;
67 }
68 // TODO(nds) v1.0.2, master
69 //  return false;
70 //}
71
72 //bool SketchPlugin_DistanceAttrValidator::isValid(
73 //  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
74 //{
75 //  // any point attribute is acceptable for the distance operation
76 //  return true;
77 //}
78 //
79 //bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
80 //                                                 const std::list<std::string>& theArguments,
81 //                                                 const AttributePtr& theAttribute) const
82 //{
83 //  return isValid(theAttribute, theArguments);
84 //}
85
86 // commented in v1.0.2, master:
87 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
88 //                                                 const std::list<std::string>& theArguments,
89 //                                                 const ObjectPtr& theObject) const
90 //{
91 //  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
92 //    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
93 //  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
94 //  for(; anAttr != anAttrs.end(); anAttr++) {
95 //    if (*anAttr) {
96 //      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
97 //        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
98 //      // check the object is already presented
99 //      if (aRef->isObject() && aRef->object() == theObject)
100 //        return false;
101 //    }
102 //  }
103 //  return true;
104 //}
105
106 //bool SketchPlugin_DifferentObjectsValidator::isValid(
107 //  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
108 //{
109 //  std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr = 
110 //    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
111 //  if (anOrigAttr && anOrigAttr->isObject()) {
112 //    const ObjectPtr& anObj = theAttribute->owner();
113 //    const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
114 //
115 //    std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
116 //      aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
117 //    std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
118 //    for(; anAttr != anAttrs.end(); anAttr++) {
119 //      if (*anAttr && *anAttr != theAttribute) {
120 //        std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
121 //          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
122 //        // check the object is already presented
123 //        if (aRef->isObject() && aRef->object() == anOrigAttr->object())
124 //          return false;
125 //      }
126 //    }
127 //  }
128 //  return true;
129 //}
130
131 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
132 //  const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
133 //{
134 //  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
135 //    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
136 //  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
137 //  for(; anAttr != anAttrs.end(); anAttr++) {
138 //    if (*anAttr) {
139 //      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
140 //        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
141 //      // check the object is already presented
142 //      if (!aRef->isObject() && aRef->attr() == theAttribute)
143 //        return false;
144 //    }
145 //  }
146 //  return true;
147 //}
148 // =========== end of todo