]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_Validators.cpp
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom 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 <ModuleBase_ValidatorLinearEdge.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 {
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();
26
27   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
28   if (!aRefAttr)
29     return false;
30
31   bool isObject = aRefAttr->isObject();
32   if (!isObject) {
33     // an attribute is a point. A point value is valid always for the distance
34     return true;
35   } else {
36     // 1. check whether the references object is a linear
37     ObjectPtr anObject = aRefAttr->object();
38     /*
39     const ModelAPI_AttributeValidator* aCircleValidator = 
40       dynamic_cast<ModuleBase_ValidatorLinearEdge*>(aFactory->validator("ModuleBase_ValidatorLinearEdge"));
41     std::list<std::string> anArguments;
42     anArguments.push_back("circle");
43     bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments);
44     if (anEdgeValid)
45       return false;
46       
47     anArguments.clear();
48     anArguments.push_back("line");
49     bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments);
50     if (!anEdgeValid)
51       return true;*/
52
53     /*const ModelAPI_ResultValidator* anArcValidator = aFactory->validator("ModuleBase_ValidatorLinearEdge");
54     //dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
55     bool anArcValid = anArcValidator->isValid(anObject);
56     if (anArcValid)
57       return false;
58
59     // If the object is not a line then it is accepted. It can be a point feature selected
60     const ModelAPI_ResultValidator* aLineValidator =
61         dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
62     bool aLineValid = aLineValidator->isValid(anObject);
63     if (!aLineValid)
64       return true;*/
65
66     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
67     // If it is a line then we have to check that first attribute id not a line
68     std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
69     if (aPoint)
70       return true;
71   }
72   return false;
73 }
74
75 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
76 //                                                 const std::list<std::string>& theArguments,
77 //                                                 const ObjectPtr& theObject) const
78 //{
79 //  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
80 //    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
81 //  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
82 //  for(; anAttr != anAttrs.end(); anAttr++) {
83 //    if (*anAttr) {
84 //      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
85 //        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
86 //      // check the object is already presented
87 //      if (aRef->isObject() && aRef->object() == theObject)
88 //        return false;
89 //    }
90 //  }
91 //  return true;
92 //}
93
94 //bool SketchPlugin_DifferentObjectsValidator::isValid(
95 //  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
96 //{
97 //  std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr = 
98 //    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
99 //  if (anOrigAttr && anOrigAttr->isObject()) {
100 //    const ObjectPtr& anObj = theAttribute->owner();
101 //    const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
102 //
103 //    std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
104 //      aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
105 //    std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
106 //    for(; anAttr != anAttrs.end(); anAttr++) {
107 //      if (*anAttr && *anAttr != theAttribute) {
108 //        std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
109 //          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
110 //        // check the object is already presented
111 //        if (aRef->isObject() && aRef->object() == anOrigAttr->object())
112 //          return false;
113 //      }
114 //    }
115 //  }
116 //  return true;
117 //}
118
119 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
120 //  const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
121 //{
122 //  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
123 //    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
124 //  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
125 //  for(; anAttr != anAttrs.end(); anAttr++) {
126 //    if (*anAttr) {
127 //      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
128 //        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
129 //      // check the object is already presented
130 //      if (!aRef->isObject() && aRef->attr() == theAttribute)
131 //        return false;
132 //    }
133 //  }
134 //  return true;
135 //}