new SketchPlugin_ArcEndPointValidator);
aFactory->registerValidator("SketchPlugin_ArcEndPointIntersectionValidator",
new SketchPlugin_ArcEndPointIntersectionValidator);
+ aFactory->registerValidator("SketchPlugin_HasNoConstraint", new SketchPlugin_HasNoConstraint);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
return false;
}
+
+bool SketchPlugin_HasNoConstraint::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ std::set<std::string> aFeatureKinds;
+ for (std::list<std::string>::const_iterator anArgIt = theArguments.begin();
+ anArgIt != theArguments.end(); anArgIt++) {
+ aFeatureKinds.insert(*anArgIt);
+ }
+
+ if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+ theError = "The attribute with the %1 type is not processed";
+ theError.arg(theAttribute->attributeType());
+ return false;
+ }
+
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
+ (theAttribute);
+ bool isObject = aRefAttr->isObject();
+ if (!isObject) {
+ theError = "It uses an empty object";
+ return false;
+ }
+ ObjectPtr anObject = aRefAttr->object();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ if (!aFeature.get()) {
+ theError = "The feature of the checked attribute is empty";
+ return false;
+ }
+
+ FeaturePtr aCurrentFeature = ModelAPI_Feature::feature(aRefAttr->owner());
+
+ std::set<AttributePtr> aRefsList = anObject->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator anIt = aRefsList.begin();
+ for (; anIt != aRefsList.end(); anIt++) {
+ FeaturePtr aRefFeature = ModelAPI_Feature::feature((*anIt)->owner());
+ if (aRefFeature.get() && aCurrentFeature != aRefFeature &&
+ aFeatureKinds.find(aRefFeature->getKind()) != aFeatureKinds.end())
+ return false; // constraint is found, that means that the check is not valid
+ }
+ return true;
+}
Events_InfoMessage& theError) const;
};
+/**\class SketchPlugin_HasNoConstraint
+ * \ingroup Validators
+ * \brief Validator for checking whether the feature has constraint.
+ *
+ * Checks that feature of the attribute does not have constraint with some kinds.
+ * The kinds of constraints should be described in parameters of the validator
+ * Validator processes the ModelAPI_AttributeRefAttr attribute kind
+ */
+class SketchPlugin_HasNoConstraint: public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ //! \param theError error message
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
#endif
<sketch_shape_selector id="ConstraintEntityA"
label="Line" tooltip="Select a line" shape_types="edge" use_external="false">
<validator id="GeomValidators_ShapeType" parameters="line"/>
+ <validator id="SketchPlugin_HasNoConstraint" parameters="SketchConstraintHorizontal, SketchConstraintVertical"/>
</sketch_shape_selector>
<validator id="PartSet_HVDirSelection"/>
</feature>
<sketch_shape_selector id="ConstraintEntityA"
label="Line" tooltip="Select a line" shape_types="edge" use_external="false">
<validator id="GeomValidators_ShapeType" parameters="line"/>
+ <validator id="SketchPlugin_HasNoConstraint" parameters="SketchConstraintHorizontal, SketchConstraintVertical"/>
</sketch_shape_selector>
<validator id="PartSet_HVDirSelection"/>
</feature>