aFactory->registerValidator("PartSet_SketchEntityValidator",
new PartSet_SketchEntityValidator);
+
+ aFactory->registerValidator("PartSet_SameTypeAttr",
+ new PartSet_SameTypeAttrValidator);
}
void PartSet_Module::registerFilters()
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Object.h>
+#include <ModelAPI_Session.h>
#include <SketchPlugin_Sketch.h>
return isSketchEntities;
}
+
+
+
+bool PartSet_SameTypeAttrValidator::isValid(
+ const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+ // there is a check whether the feature contains a point and a linear edge or two point values
+ std::string aParamA = theArguments.front();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (!aRefAttr)
+ return false;
+
+ bool isObject = aRefAttr->isObject();
+ ObjectPtr anObject = aRefAttr->object();
+ if (isObject && anObject) {
+ FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
+
+ AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA);
+ ObjectPtr aOtherObject = aOtherAttr->object();
+ FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
+ return aRefFea->getKind() == aOtherFea->getKind();
+ }
+ return false;
+}
+
const std::list<std::string>& theArguments) const;
};
+/**\class PartSet_SameTypeAttrValidator
+ * \ingroup Validators
+ * \brief Validator for the tangent constraint input.
+ *
+ * It just checks that distance is greater than zero.
+ */
+class PartSet_SameTypeAttrValidator : public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+};
+
+
#endif
virtual bool isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const;
};
-// virtual bool isValid(const AttributePtr& theAttribute,
-// const std::list<std::string>& theArguments) const;
-//
-// //! Returns true if object is good for the feature attribute
-// virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-// const ObjectPtr& theObject, const GeomShapePtr& theShape) const;
-//
-// //! Returns true if the attribute is good for the feature attribute
-// virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-// const AttributePtr& theAttribute) const;
-//};
-
-// commented in v1.0.2, master:
-/**\class SketchPlugin_DifferentObjectsValidator
- * \ingroup Validators
- *
- * Check that there is no same object was already selected in the feature.
- * For an example: to avoid perpendicularity on line and the same line.
- */
-// Use PartSet_DifferentObjectsValidator instead
-//class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
-//{
-// public:
-// //! returns true if attribute is valid
-// //! \param theAttribute the checked attribute
-// //! \param theArguments arguments of the attribute
-// virtual bool isValid(
-// const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
-// //! Returns true if object is good for the feature attribute
-// virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-// const ObjectPtr& theObject) const;
-// //! Returns true if the attribute is good for the feature attribute
-// virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-// const AttributePtr& theAttribute) const;
-//};
-// ======= end of todo
/**\class SketchPlugin_TangentAttrValidator
const std::list<std::string>& theArguments) const;
};
+
#endif
<sketch_constraint_shape_selector id="ConstraintEntityB"
label="Last object" tooltip="Select line, circle or arc" shape_types="edge">
+ <validator id="PartSet_SameTypeAttr" parameters="ConstraintEntityA"/>
+ <validator id="PartSet_DifferentObjects"/>
</sketch_constraint_shape_selector>
</feature>