new SketchPlugin_ExternalValidator);
aFactory->registerValidator("SketchPlugin_TangentAttr",
new SketchPlugin_TangentAttrValidator);
+ aFactory->registerValidator("SketchPlugin_CoincidentAttr",
+ new SketchPlugin_CoincidentAttr);
aFactory->registerValidator("SketchPlugin_NotFixed",
new SketchPlugin_NotFixedValidator);
aFactory->registerValidator("SketchPlugin_EqualAttr",
}
return false;
}
-bool SketchPlugin_TangentAttrValidator::isValid(
+
+bool SketchPlugin_CoincidentAttr::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
ObjectPtr anObject = aRefAttr->object();
if (isObject && anObject) {
FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
-
AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA);
ObjectPtr aOtherObject = aOtherAttr->object();
+ // if the other attribute is not filled still, the result is true
+ if (!aOtherObject.get())
+ return true;
FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
- if (aRefFea->getKind() == SketchPlugin_Line::ID()) {
- if (aOtherFea->getKind() != SketchPlugin_Arc::ID())
- return false;
- } else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
- if (aOtherFea->getKind() != SketchPlugin_Line::ID() &&
- aOtherFea->getKind() != SketchPlugin_Arc::ID())
- return false;
- } else
- return false;
-
// check that both have coincidence
FeaturePtr aConstrFeature;
std::set<FeaturePtr> aCoinList;
return false;
}
+bool SketchPlugin_TangentAttrValidator::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);
+
+ if (aRefFea->getKind() == SketchPlugin_Line::ID()) {
+ if (aOtherFea->getKind() != SketchPlugin_Arc::ID())
+ return false;
+ } else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
+ if (aOtherFea->getKind() != SketchPlugin_Line::ID() &&
+ aOtherFea->getKind() != SketchPlugin_Arc::ID())
+ return false;
+ } else
+ return false;
+
+ return true;
+ }
+ return false;
+}
+
bool SketchPlugin_NotFixedValidator::isValid(
const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
{
const std::list<std::string>& theArguments) const;
};
+/**\class SketchPlugin_CoincidentAttr
+ * \ingroup Validators
+ * \brief Validator to check whether there is a coincident constraint between
+ * the attribute and attribute of argument.
+ */
+class SketchPlugin_CoincidentAttr : 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;
+};
/**\class SketchPlugin_TangentAttrValidator
* \ingroup Validators
<feature id="SketchConstraintTangent" title="Tangent" tooltip="Create constraint defining tangency of two objects" icon=":icons/tangent.png">
<sketch_shape_selector id="ConstraintEntityA"
label="First object" tooltip="Select line or arc" shape_types="edge">
+ <validator id="SketchPlugin_CoincidentAttr" parameters="ConstraintEntityB"/>
<validator id="PartSet_DifferentObjects"/>
</sketch_shape_selector>
<sketch_shape_selector id="ConstraintEntityB"
label="Second object" tooltip="Select line or arc" shape_types="edge">
- <validator id="SketchPlugin_TangentAttr" parameters="ConstraintEntityA"/>
- <validator id="PartSet_DifferentObjects"/>
+ <validator id="SketchPlugin_CoincidentAttr" parameters="ConstraintEntityA"/>
+ <validator id="SketchPlugin_TangentAttr" parameters="ConstraintEntityA"/>
+ <validator id="PartSet_DifferentObjects"/>
</sketch_shape_selector>
<validator id="PartSet_TangentSelection"/>
</feature>
<sketch_shape_selector id="ConstraintEntityA"
label="First object" tooltip="Select line or arc" shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
+ <validator id="SketchPlugin_CoincidentAttr" parameters="ConstraintEntityB"/>
</sketch_shape_selector>
<sketch_shape_selector id="ConstraintEntityB"
label="Second object" tooltip="Select line or arc" shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
+ <validator id="SketchPlugin_CoincidentAttr" parameters="ConstraintEntityA"/>
</sketch_shape_selector>
<doublevalue label="Value" tooltip="Fillet radius" id="ConstraintValue" min="0" default="1" use_reset="false">