#include <ModuleBase_WidgetValueFeature.h>
#include <ModuleBase_WidgetValue.h>
+#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_Session.h>
+
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
ModuleBase_WidgetValueFeature* aFeatureValue =
dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
if (aFeatureValue) {
- boost::shared_ptr<GeomAPI_Pnt2d> aValuePoint = aFeatureValue->point();
ObjectPtr aObject = aFeatureValue->object();
- if (aObject) {
- isDone = setObject(aObject, false);
+
+ boost::shared_ptr<ModelAPI_Attribute> anAttribute = findAttribute(aFeatureValue);
+ if (anAttribute) {
+ isDone = setAttribute(anAttribute, false);
}
- if (aValuePoint) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
- if (aFeature) {
- // find the given point in the feature attributes
- std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes = aFeature->data()
- ->attributes(GeomDataAPI_Point2D::type());
- std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes
- .begin(), aLast = anAttiributes.end();
- boost::shared_ptr<GeomDataAPI_Point2D> aFPoint;
- for (; anIt != aLast && !aFPoint; anIt++) {
- boost::shared_ptr<GeomDataAPI_Point2D> aCurPoint = boost::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(*anIt);
- if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion())
- aFPoint = aCurPoint;
- }
- if (aFPoint)
- isDone = setAttribute(aFPoint, false);
- }
+ else if (aObject) {
+ isDone = setObject(aObject, false);
}
+
if (isDone)
emit valuesChanged();
}
return false;
}
+boost::shared_ptr<ModelAPI_Attribute> ModuleBase_WidgetFeatureOrAttribute::findAttribute(
+ ModuleBase_WidgetValue* theValue)
+{
+ boost::shared_ptr<ModelAPI_Attribute> anAttribute;
+ ModuleBase_WidgetValueFeature* aFeatureValue =
+ dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
+ if (!aFeatureValue)
+ return anAttribute;
+
+ boost::shared_ptr<GeomAPI_Pnt2d> aValuePoint = aFeatureValue->point();
+ if (aValuePoint) {
+ ObjectPtr aObject = aFeatureValue->object();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
+ if (aFeature) {
+ // find the given point in the feature attributes
+ std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes = aFeature->data()
+ ->attributes(GeomDataAPI_Point2D::type());
+ std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes
+ .begin(), aLast = anAttiributes.end();
+ for (; anIt != aLast && !anAttribute; anIt++) {
+ boost::shared_ptr<GeomDataAPI_Point2D> aCurPoint = boost::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(*anIt);
+ if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion())
+ anAttribute = aCurPoint;
+ }
+ }
+ }
+ return anAttribute;
+}
+
bool ModuleBase_WidgetFeatureOrAttribute::setAttribute(
const boost::shared_ptr<ModelAPI_Attribute>& theAttribute, bool theSendEvent)
{
if (!theAttribute) // || !featureKinds().contains(theAttribute->attributeType().c_str()))
return false;
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ std::list<ModelAPI_Validator*> aValidators;
+ std::list<std::list<std::string> > anArguments;
+ aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
+
+ // Check the acceptability of the attribute
+ std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
+ int aSize = aValidators.size();
+ std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
+ for (; aValidator != aValidators.end(); aValidator++, aArgs++) {
+ const ModelAPI_RefAttrValidator* aAttrValidator =
+ dynamic_cast<const ModelAPI_RefAttrValidator*>(*aValidator);
+ if (aAttrValidator) {
+ if (!aAttrValidator->isValid(myFeature, *aArgs, theAttribute)) {
+ return false;
+ }
+ }
+ }
+
myAttribute = theAttribute;
editor()->setText(theAttribute ? theAttribute->attributeType().c_str() : "");
if (theSendEvent)
virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
const ObjectPtr& theObject) const;
+ //! Returns true if the attribute is good for the feature attribute
+ virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
+ const AttributePtr& theAttribute) const { return true; };
};
/**
//! 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;
-
+ //! Returns true if the attribute is good for the feature attribute
+ virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
+ const AttributePtr& theAttribute) const;
};
#endif
<feature_or_attribute_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc.">
<validator id="SketchPlugin_ResultPoint"/>
<validator id="SketchPlugin_ResultLine"/>
+ <validator id="SketchPlugin_DifferentObjects"/>
</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_ResultPoint"/>
<validator id="SketchPlugin_ResultLine"/>
<validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
+ <validator id="SketchPlugin_DifferentObjects"/>
</feature_or_attribute_selector>
<point_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
- <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed">
+ <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed" min="0">
<validator id="GeomValidators_Positive"/>
</doublevalue_editor>
<validator id="PartSet_DistanceValidator"/>