aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
+ aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
aFactory->registerValidator("PartSet_MultyTranslationSelection",
new PartSet_MultyTranslationSelection);
#include <ModuleBase_OperationFeature.h>
#include <ModuleBase_ViewerPrs.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2d.h>
+
#include <Events_InfoMessage.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Point.h>
#include <GeomAPI_Edge.h>
#include <list>
return true;
}
+bool PartSet_DifferentPointsValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+
+ // the type of validated attributes should be equal, attributes with
+ // different types are not validated
+ // Check RefAttr attributes
+ std::string anAttrType = theAttribute->attributeType();
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs;
+ if (anAttrType != ModelAPI_AttributeRefAttr::typeId())
+ return true;
+
+ // obtain point of the given attribute
+ AttributePoint2DPtr anAttributePoint = getRefPointAttribute(theAttribute);
+ if (!anAttributePoint.get() || !anAttributePoint->isInitialized())
+ return true;
+
+ // obtain point of the parameter attribute
+ AttributePoint2DPtr anArgumentPoint = getRefPointAttribute
+ (aFeature->attribute(theArguments.front()));
+
+ if (!anArgumentPoint.get() || !anArgumentPoint->isInitialized())
+ return true;
+
+ return !anAttributePoint->pnt()->isEqual(anArgumentPoint->pnt());
+}
+
+AttributePoint2DPtr PartSet_DifferentPointsValidator::getRefPointAttribute
+ (const AttributePtr& theAttribute) const
+{
+ AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+
+ AttributePoint2DPtr aPointAttribute;
+ if (anAttr->isObject()) {
+ ObjectPtr anObject = anAttr->object();
+ if (anObject.get()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ if (aFeature->getKind() == SketchPlugin_Point::ID())
+ aPointAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aFeature->attribute(SketchPlugin_Point::COORD_ID()));
+ }
+ }
+ else {
+ aPointAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ }
+ return aPointAttribute;
+}
+
bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
Events_InfoMessage& theError) const
#include <ModuleBase_ISelection.h>
#include <ModelAPI_AttributeValidator.h>
+class GeomDataAPI_Point2D;
+
/*
* Selector validators
*/
};
+/**
+* \ingroup Validators
+* A validator which checks that Point2D selected for feature attributes are different (not the same)
+* It iterates by the feature ModelAPI_AttributeRefAttr attributes, finds GeomDataAPI_Point2D attribute in
+* value or attribute of the attributes and if the point of the given attribute is geometrical equal to
+* a point of another attribute, returns false
+*/
+class PartSet_DifferentPointsValidator : public ModelAPI_AttributeValidator
+{
+ public:
+ //! Returns true if the attribute is good for the feature attribute
+ //! \param theAttribute an attribute
+ //! \param theArguments a list of arguments (names of attributes to check)
+ //! \param theError an output error string
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+private:
+ //! Finds Point2D attribute by reference attribute. It might be:
+ //! - COORD_ID attribute of SketchPlugin_Point if object
+ //! - Attribute casted to point if attribute
+ //! \param theAttribute an attribute
+ //! \return point 2d attribute or NULL
+ std::shared_ptr<GeomDataAPI_Point2D> getRefPointAttribute
+ (const AttributePtr& theAttribute) const;
+};
+
+
/**\class PartSet_CoincidentAttr
* \ingroup Validators
* \brief Validator to check whether there is a coincident constraint between
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
<validator id="PartSet_DifferentObjects"/>
<validator id="GeomValidators_ShapeType" parameters="vertex,line"/>
+ <validator id="PartSet_DifferentPoints" parameters="ConstraintEntityB"/>
</sketch_shape_selector>
<sketch_shape_selector
id="ConstraintEntityB"
<validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
<validator id="GeomValidators_ShapeType" parameters="vertex,line"/>
+ <validator id="PartSet_DifferentPoints" parameters="ConstraintEntityA"/>
</sketch_shape_selector>
<sketch-2dpoint_flyout_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>