new SketchPlugin_ExternalValidator);
aFactory->registerValidator("SketchPlugin_TangentAttr",
new SketchPlugin_TangentAttrValidator);
+ aFactory->registerValidator("SketchPlugin_NotFixed",
+ new SketchPlugin_NotFixedValidator);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
#include "SketchPlugin_Validators.h"
#include "SketchPlugin_ConstraintDistance.h"
#include "SketchPlugin_ConstraintCoincidence.h"
+#include "SketchPlugin_ConstraintRigid.h"
#include "SketchPlugin_Line.h"
#include "SketchPlugin_Arc.h"
return false;
}
+bool SketchPlugin_NotFixedValidator::isValid(
+ const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
+{
+ std::shared_ptr<SketchPlugin_Feature> aFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
+ if (!aFeature)
+ return true;
+
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (!aRefAttr)
+ return false;
+
+ SketchPlugin_Sketch* aSketch = aFeature->sketch();
+ int aNbFeatures = aSketch->numberOfSubs();
+ for (int anInd = 0; anInd < aNbFeatures; anInd++) {
+ FeaturePtr aSubFeature = aSketch->subFeature(anInd);
+ if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
+ continue;
+ AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
+ if (aRefAttr->isObject()) {
+ if (aRefAttr->object() == aRAttr->object())
+ return false;
+ } else if (aRefAttr->attr() == aRAttr->attr())
+ return false;
+ }
+ return true;
+}
};
+/**\class SketchPlugin_NotFixed
+ * \ingroup Validators
+ * \brief Validator for the rigid constraint input.
+ *
+ * It just checks there is no rigid constraint for the current feature.
+ */
+class SketchPlugin_NotFixedValidator : public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is not used in another rigid constraint
+ //! \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
<shape_selector id="ConstraintEntityA" label="Object" tooltip="Select an object"
shape_types="edge vertex">
<validator id="PartSet_SketchEntityValidator" parameters="SketchPoint,SketchLine,SketchCircle,SketchArc"/>
+ <validator id="SketchPlugin_NotFixed"/>
</shape_selector>
<validator id="PartSet_RigidValidator"/>
</feature>