1 // File: PartSet_Validators.cpp
2 // Created: 09 July 2014
3 // Author: Vitaly SMETANNIKOV
5 #include "PartSet_Validators.h"
8 #include <TopoDS_Edge.hxx>
9 #include <BRep_Tool.hxx>
10 #include <GeomAdaptor_Curve.hxx>
11 #include <GeomAbs_CurveType.hxx>
12 #include <ModuleBase_ISelection.h>
14 #include <ModelAPI_AttributeRefAttr.h>
15 #include <ModelAPI_AttributeSelection.h>
16 #include <ModelAPI_AttributeReference.h>
20 int shapesNbPoints(const ModuleBase_ISelection* theSelection)
22 QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
24 foreach (ModuleBase_ViewerPrs aPrs, aList) {
25 const TopoDS_Shape& aShape = aPrs.shape();
26 if (!aShape.IsNull()) {
27 if (aShape.ShapeType() == TopAbs_VERTEX)
34 int shapesNbLines(const ModuleBase_ISelection* theSelection)
36 QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
38 foreach(ModuleBase_ViewerPrs aPrs, aList) {
39 const TopoDS_Shape& aShape = aPrs.shape();
40 if (!aShape.IsNull()) {
41 if (aShape.ShapeType() == TopAbs_EDGE) {
42 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
43 Standard_Real aStart, aEnd;
44 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
45 GeomAdaptor_Curve aAdaptor(aCurve);
46 if (aAdaptor.GetType() == GeomAbs_Line)
54 bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
56 int aCount = shapesNbPoints(theSelection);
57 return (aCount > 0) && (aCount < 3);
60 bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const
62 int aCount = shapesNbLines(theSelection);
63 return (aCount > 0) && (aCount < 2);
66 bool PartSet_PerpendicularValidator::isValid(const ModuleBase_ISelection* theSelection) const
68 int aCount = shapesNbLines(theSelection);
69 return (aCount > 0) && (aCount < 3);
72 bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelection) const
74 int aCount = shapesNbLines(theSelection);
75 return (aCount > 0) && (aCount < 3);
78 bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const
80 QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
81 ModuleBase_ViewerPrs aPrs;
83 foreach (ModuleBase_ViewerPrs aPrs, aList) {
84 const TopoDS_Shape& aShape = aPrs.shape();
85 if (!aShape.IsNull()) {
86 if (aShape.ShapeType() == TopAbs_EDGE) {
87 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
88 Standard_Real aStart, aEnd;
89 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
90 GeomAdaptor_Curve aAdaptor(aCurve);
91 if (aAdaptor.GetType() == GeomAbs_Circle)
96 return (aCount > 0) && (aCount < 2);
101 bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
102 const std::list<std::string>& theArguments,
103 const ObjectPtr& theObject) const
105 // Check RefAttr attributes
106 std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
107 theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
108 if (anAttrs.size() > 0) {
109 std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
110 for(; anAttr != anAttrs.end(); anAttr++) {
112 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
113 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
114 // check the object is already presented
115 if (aRef->isObject() && aRef->object() == theObject)
120 // Check selection attributes
121 anAttrs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
122 if (anAttrs.size() > 0) {
123 std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
124 for(; anAttr != anAttrs.end(); anAttr++) {
126 std::shared_ptr<ModelAPI_AttributeSelection> aRef =
127 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*anAttr);
128 // check the object is already presented
129 if (aRef->isInitialized() && aRef->context() == theObject)
134 // Check selection attributes
135 anAttrs = theFeature->data()->attributes(ModelAPI_AttributeReference::type());
136 if (anAttrs.size() > 0) {
137 std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
138 for(; anAttr != anAttrs.end(); anAttr++) {
140 std::shared_ptr<ModelAPI_AttributeReference> aRef =
141 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(*anAttr);
142 // check the object is already presented
143 if (aRef->isInitialized() && aRef->value() == theObject)
151 bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
152 const std::list<std::string>& theArguments,
153 const AttributePtr& theAttribute) const
159 bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute,
160 const std::list<std::string>& theArguments) const