new SketchPlugin_FilletVertexValidator);
aFactory->registerValidator("SketchPlugin_MiddlePointAttr",
new SketchPlugin_MiddlePointAttrValidator);
+ aFactory->registerValidator("SketchPlugin_ArcTangentPoint",
+ new SketchPlugin_ArcTangentPointValidator);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintCollinear::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintVertical::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintEqual::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintTangent::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintMiddle::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintMirror::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintFillet::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintAngle::ID(), aHasSketchPlane);
}
return true;
}
+
+bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& /*theArguments*/,
+ std::string& theError) const
+{
+ if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+ theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+ return false;
+ }
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ AttributePtr anAttr = aRefAttr->attr();
+ if (!anAttr) {
+ theError = "The attribute " + theAttribute->id() + " should be a point";
+ return false;
+ }
+
+ FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
+ const std::string& aFeatureType = anAttrFeature->getKind();
+ if (aFeatureType == SketchPlugin_Arc::ID()) {
+ // selected point should not be a center of arc
+ const std::string& aPntId = anAttr->id();
+ if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
+ theError = "The attribute " + aPntId + " is not supported";
+ return false;
+ }
+ }
+ else if (aFeatureType == SketchPlugin_Line::ID()) {
+ // selected point should be bound point of line
+ const std::string& aPntId = anAttr->id();
+ if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
+ theError = "The attribute " + aPntId + " is not supported";
+ return false;
+ }
+ }
+ else {
+ theError = "Unable to build tangent arc on " + anAttrFeature->getKind();
+ return false;
+ }
+
+ return true;
+}
std::string& theError) const;
};
+
+/**\class SketchPlugin_ArcTangentPointValidator
+ * \ingroup Validators
+ * \brief Validator for the point where the tangent arc is building.
+ *
+ * Checks that the point is a start or end point just on line or arc.
+ */
+class SketchPlugin_ArcTangentPointValidator : 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,
+ std::string& theError) const;
+};
+
#endif
<validator id="GeomValidators_Different" parameters="ArcStartPoint,ArcEndPoint,ArcPassedPoint"/>
</box>
<box id="Tangent" title="Tangent with edge" icon=":icons/arc_tang_32x32.png">
- <sketch_shape_selector id="ArcTangentPoint" label="Start point" tooltip="Select point on line" shape_types="vertex" />
+ <sketch_shape_selector id="ArcTangentPoint" label="Start point" tooltip="Select point on line" shape_types="vertex">
+ <validator id="SketchPlugin_ArcTangentPoint" parameters="" />
+ </sketch_shape_selector>
<sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"/>
<doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon=":icons/radius.png" tooltip="Set radius" obligatory="1">
<validator id="GeomValidators_Positive"/>