{
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- aFactory->registerValidator("SketchPlugin_DistanceAttrValidator",
+ aFactory->registerValidator("SketchPlugin_DistanceAttr",
new SketchPlugin_DistanceAttrValidator);
- aFactory->registerValidator("SketchPlugin_ResultPointValidator", new SketchPlugin_ResultPointValidator);
- aFactory->registerValidator("SketchPlugin_ResultLineValidator", new SketchPlugin_ResultLineValidator);
- aFactory->registerValidator("SketchPlugin_ResultArcValidator", new SketchPlugin_ResultArcValidator);
+ aFactory->registerValidator("SketchPlugin_DifferentObjects",
+ new SketchPlugin_DifferentObjectsValidator);
+ aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
+ aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator);
+ aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
#include <ModelAPI_Validator.h>
#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeRefAttr.h>
#include <GeomDataAPI_Point2D.h>
bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
}
return true; // it may be not reference attribute, in this case, it is OK
}
+
+bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
+ const std::list<std::string>& theArguments,
+ const ObjectPtr& theObject) const
+{
+ std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttrs =
+ theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+ std::list<boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++) {
+ if (*anAttr) {
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+ // check the object is already presented
+ if (aRef->isObject() && aRef->object() == theObject)
+ return false;
+ }
+ }
+ return true;
+}
+
+bool SketchPlugin_DifferentObjectsValidator::isValid(
+ const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (anOrigAttr && anOrigAttr->isObject()) {
+ const ObjectPtr& anObj = theAttribute->owner();
+ const FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+
+ std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttrs =
+ aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+ std::list<boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++) {
+ if (*anAttr && *anAttr != theAttribute) {
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+ // check the object is already presented
+ if (aRef->isObject() && aRef->object() == anOrigAttr->object())
+ return false;
+ }
+ }
+ }
+ return true;
+}
};
+/**
+ * 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.
+ */
+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;
+
+};
+
#endif
<feature id="SketchConstraintDistance" title="Distance" tooltip="Create constraint for the distance from a point to an object" icon=":icons/distance.png">
<label title="Select objects for distance difinition. Following objects can be accepted: point, line end point, line, center of circle or arc."/>
<feature_or_attribute_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc.">
- <validator id="SketchPlugin_ResultPointValidator"/>
- <validator id="SketchPlugin_ResultLineValidator"/>
+ <validator id="SketchPlugin_ResultPoint"/>
+ <validator id="SketchPlugin_ResultLine"/>
</feature_or_attribute_selector>
<feature_or_attribute_selector id="ConstraintEntityB" label="Last object" tooltip="Select point, line end point, line, center of circle or arc.">
- <validator id="SketchPlugin_ResultPointValidator"/>
- <validator id="SketchPlugin_ResultLineValidator"/>
- <validator id="SketchPlugin_DistanceAttrValidator" parameters="ConstraintEntityA"/>
+ <validator id="SketchPlugin_ResultPoint"/>
+ <validator id="SketchPlugin_ResultLine"/>
+ <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
</feature_or_attribute_selector>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
<feature id="SketchConstraintLength" title="Length" tooltip="Create constraint for the given length of a line segment" icon=":icons/length.png">
<label title="Select a line on which to calculate lenght" tooltip="Select a line on which to calculate lenght"/>
<feature_selector id="ConstraintEntityA" label="Line" tooltip="Select an line in the viewer">
- <validator id="SketchPlugin_ResultLineValidator"/>
+ <validator id="SketchPlugin_ResultLine"/>
</feature_selector>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
<feature id="SketchConstraintRadius" title="Radius" tooltip="Create constraint for the given radius of a circle or an arc" icon=":icons/radius_constr.png">
<label title="Select a circle or an arc on which to calculate radius" tooltip="Select a circle or an arc on which to calculate radius"/>
<feature_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc in the viewer">
- <validator id="SketchPlugin_ResultArcValidator"/>
+ <validator id="SketchPlugin_ResultArc"/>
</feature_selector>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
<feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
<feature_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer">
- <validator id="SketchPlugin_ResultLineValidator"/>
+ <validator id="SketchPlugin_ResultLine"/>
+ <validator id="SketchPlugin_DifferentObjects"/>
</feature_selector>
<feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer">
- <validator id="SketchPlugin_ResultLineValidator"/>
+ <validator id="SketchPlugin_ResultLine"/>
+ <validator id="SketchPlugin_DifferentObjects"/>
</feature_selector>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<validator id="PartSet_ParallelValidator"/>
<feature id="SketchConstraintPerpendicular" title="Perpendicular" tooltip="Create constraint defining two perpendicular lines" icon=":icons/perpendicular.png">
<feature_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer">
- <validator id="SketchPlugin_ResultLineValidator"/>
+ <validator id="SketchPlugin_ResultLine"/>
+ <validator id="SketchPlugin_DifferentObjects"/>
</feature_selector>
<feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer">
- <validator id="SketchPlugin_ResultLineValidator"/>
+ <validator id="SketchPlugin_ResultLine"/>
+ <validator id="SketchPlugin_DifferentObjects"/>
</feature_selector>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<validator id="PartSet_PerpendicularValidator"/>