protected:
// accessible from the attributes
bool myIsInitialized;
- bool myIsComputedDefault;
bool myIsArgument;
public:
myIsInitialized = true;
}
- /// Returns true if attribute's default value was computed
- MODELAPI_EXPORT bool isComputedDefault()
- {
- return myIsComputedDefault;
- }
-
- /// Tells that attribute's default value was computed
- MODELAPI_EXPORT void setComputedDefault()
- {
- myIsComputedDefault = true;
- myIsInitialized = false;
- }
-
/// Set this attribute is argument for result (change of this attribute requires update of result).
/// By default it is true.
MODELAPI_EXPORT void setIsArgument(const bool theFlag)
ModelAPI_Attribute()
{
myIsInitialized = false;
- myIsComputedDefault = false;
myIsArgument = true;
}
return theObject->data()->attribute(attributeID())->isInitialized();
}
-void ModuleBase_ModelWidget::setAttributeComputedState(ObjectPtr theObject) const
-{
- if(myIsComputedDefault)
- theObject->data()->attribute(attributeID())->setComputedDefault();
-}
-
bool ModuleBase_ModelWidget::focusTo()
{
QList<QWidget*> aControls = getControls();
/// \return the boolean result
bool isInitialized(ObjectPtr theObject) const;
- void setAttributeComputedState(ObjectPtr theObject) const;
-
bool isComputedDefault()
{
return myIsComputedDefault;
void setFeature(const FeaturePtr& theFeature)
{
myFeature = theFeature;
- if(theFeature)
- setAttributeComputedState(theFeature);
}
signals:
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = boost::dynamic_pointer_cast<
ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
- ObjectPtr aObj = aRef->object();
- FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
- if (aFeature) {
- myObject = aFeature;
+ ObjectPtr anObjPtr = aRef->object();
+ if (anObjPtr) {
+ myObject = anObjPtr;
myEditor->setText(myObject ? myObject->data()->name().c_str() : "");
return true;
}
#include <QHBoxLayout>
#include <QLabel>
-ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(
- QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId)
+ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId)
: ModuleBase_WidgetFeature(theParent, theData, theParentId)
{
}
void SketchPlugin_ConstraintDistance::execute()
{
boost::shared_ptr<ModelAPI_Data> aData = data();
- AttributeDoublePtr anAttr_Value = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+ AttributeDoublePtr anAttrValue = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
aData->attribute(SketchPlugin_Constraint::VALUE()));
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_A());
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_B());
-
- if (aPoint_A && aPoint_B) { // both points
- anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt()));
+ if(anAttrValue->isInitialized())
+ return;
+ boost::shared_ptr<GeomDataAPI_Point2D> aPointA =
+ getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+ boost::shared_ptr<GeomDataAPI_Point2D> aPointB =
+ getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
+
+ double aDistance = -1.;
+ if (aPointA && aPointB) { // both points
+ aDistance = aPointA->pnt()->distance(aPointB->pnt());
} else {
- if (!aPoint_A && aPoint_B) { //Line and point
- boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
- aData, SketchPlugin_Constraint::ENTITY_A());
- if (aLine)
- anAttr_Value->setValue(aLine->distanceToPoint(aPoint_B->pnt()));
- } else if (aPoint_A && !aPoint_B) { // Point and line
- boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
- aData, SketchPlugin_Constraint::ENTITY_B());
- if (aLine)
- anAttr_Value->setValue(aLine->distanceToPoint(aPoint_A->pnt()));
+ if (!aPointA && aPointB) { //Line and point
+ boost::shared_ptr<SketchPlugin_Line> aLine =
+ getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
+ if (aLine) {
+ aDistance = aLine->distanceToPoint(aPointB->pnt());
+ }
+ } else if (aPointA && !aPointB) { // Point and line
+ boost::shared_ptr<SketchPlugin_Line> aLine =
+ getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
+ if (aLine) {
+ aDistance = aLine->distanceToPoint(aPointA->pnt());
+ }
}
}
+ if(aDistance >= 0) {
+ anAttrValue->setValue(aDistance);
+ }
}
//*************************************************************************************
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = boost::dynamic_pointer_cast<
ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
- aValueAttr->setValue(aLenght);
+ if(!aValueAttr->isInitialized()) {
+ aValueAttr->setValue(aLenght);
+ }
}
}
}
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = boost::dynamic_pointer_cast<
ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
- aValueAttr->setValue(aRadius);
+ if(!aValueAttr->isInitialized()) {
+ aValueAttr->setValue(aRadius);
+ }
}
}
<validator id="SketchPlugin_DistanceAttrValidator" parameters="ConstraintEntityA"/>
</feature_or_attribute_selector>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
- <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
+ <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
<validator id="PartSet_DistanceValidator"/>
</feature>
<validator id="SketchPlugin_ResultLineValidator"/>
</feature_selector>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
- <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
+ <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
<validator id="PartSet_LengthValidator"/>
</feature>