const static char* DOUBLE_WDG_DEFAULT_COMPUTED = "computed";
const static char* DOUBLE_WDG_ACCEPT_EXPRESSIONS = "accept_expressions";
const static char* DOUBLE_WDG_ENABLE_VALUE = "enable_value";
+
+const static char* DOUBLE_WDG_ENABLE_VALUE_BY_PREFERENCES = "enable_by_preferences";
+
// WDG_TOOLBOX/WDG_SWITCH properties
const static char* CONTAINER_PAGE_NAME = "title";
const static char* CONTAINER_PAGE_ICON = "icon";
myAttributeID = theData ? theData->widgetId() : "";
myIsObligatory = theData->getBooleanAttribute(ATTR_OBLIGATORY, true);
- myIsValueEnabled = theData->getBooleanAttribute(DOUBLE_WDG_ENABLE_VALUE, true);
+ myIsValueEnabled = On; // not defined or "true"
+ std::string anEnableValue = theData->getProperty(DOUBLE_WDG_ENABLE_VALUE);
+ if (anEnableValue == "false")
+ myIsValueEnabled = Off;
+ if (anEnableValue == DOUBLE_WDG_ENABLE_VALUE_BY_PREFERENCES)
+ myIsValueEnabled = DefinedInPreferences;
connect(this, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
connect(this, SIGNAL(valuesModified()), this, SLOT(onWidgetValuesModified()));
bool ModuleBase_ModelWidget::isValueEnabled() const
{
bool anEnabled = true;
- bool aCanDisable = Config_PropManager::boolean("Sketch planes", "disable_input_fields", "true");
- if (aCanDisable)
- anEnabled = myIsValueEnabled;
+ if (myIsValueEnabled == DefinedInPreferences) {
+ bool aCanDisable = Config_PropManager::boolean("Sketch planes", "disable_input_fields", "true");
+ if (aCanDisable)
+ anEnabled = false;
+ }
+ else if (myIsValueEnabled == Off)
+ anEnabled = false;
return anEnabled;
}
ModifiedInViewer, /// modification performed by viewer events
Reset }; /// the value is reset
+ enum EnableState { On, /// the widget value is always enabled
+ Off, /// the widget value is always disabled
+ DefinedInPreferences }; /// the widget value enable state is defined in preferences
+
/// Constructor
/// \param theParent the parent object
/// \param theData the widget configuration. The attribute of the model widget is obtained from
bool myIsObligatory;
/// Flag about value of the control is enabled (can be modified)
- bool myIsValueEnabled;
+ EnableState myIsValueEnabled;
/// The widget value state
ValueState myState;
tooltip="Create rectangle"
icon="icons/Addons/rectangle.png">
<sketch-2dpoint_selector id="RectStartPoint" accept_expressions="0" title="Start point" tooltip="Start point coordinates"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<sketch-2dpoint_selector id="RectEndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"
enable_value="false"/>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
std::shared_ptr<GeomDataAPI_Point2D> anEndAttr =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_ID()));
anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint()));
+ updateLenghtValue();
}
}
+ else if (theID == START_ID() || theID == END_ID()) {
+ updateLenghtValue();
+ }
+}
+
+void SketchPlugin_Line::updateLenghtValue()
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(START_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(END_ID()));
+ if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) {
+ double aDistance = aStartAttr->pnt()->distance(anEndAttr->pnt());
+ data()->real(LENGTH_ID())->setValue(aDistance);
+ }
}
return MY_END_ID;
}
+ /// Line length.
+ static const std::string& LENGTH_ID()
+ {
+ static const std::string MY_LENGTH("LineLength");
+ return MY_LENGTH;
+ }
+
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind();
/// Use plugin manager for features creation
SketchPlugin_Line();
+private:
+ /// Calculates the lenght of the line and fill the lenght attribute with the value
+ void updateLenghtValue();
+
protected:
/// \brief Initializes attributes of derived class.
virtual void initDerivedClassAttributes();
<!-- SketchPoint -->
<feature id="SketchPoint" title="Point" tooltip="Create point" icon="icons/Sketch/point.png">
<sketch-2dpoint_selector id="PointCoordindates" accept_expressions="0" title="Point" tooltip="Point coordinates"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
</feature>
<!-- SketchLine -->
<feature id="SketchLine" title="Line" tooltip="Create line" icon="icons/Sketch/line.png">
<sketch-2dpoint_selector id="StartPoint" accept_expressions="0" title="Start point" tooltip="Start point coordinates"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<sketch-2dpoint_selector id="EndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
+ <doublevalue id="LineLength" accept_expressions="0" label="Length:" default="computed" icon="icons/Sketch/distance_value.png"
+ tooltip="Line length" obligatory="0" enable_value="false"/>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
<validator id="GeomValidators_Different" parameters="StartPoint,EndPoint"/>
</feature>
<toolbox id="CircleType">
<box id="CenterRadius" title="Center and radius" icon="icons/Sketch/circle_pt_rad_32x32.png">
<sketch-2dpoint_selector id="CircleCenter" accept_expressions="0" title="Center" tooltip="Center coordinates"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0"
default="0" icon="icons/Sketch/radius.png" tooltip="Set radius"
- enable_value="false">
+ enable_value="enable_by_preferences">
<validator id="GeomValidators_Positive"/>
</point2ddistance>
</box>
<box id="ThreePoints" title="Three points" icon="icons/Sketch/circle_3pt_32x32.png">
<sketch-2dpoint_selector id="FirstPoint" accept_expressions="0" title="First point" tooltip="First point"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<sketch-2dpoint_selector id="SecondPoint" accept_expressions="0" title="Second point" tooltip="Second point"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<sketch-2dpoint_selector id="ThirdPoint" accept_expressions="0" title="Third point" tooltip="Third point"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
</box>
</toolbox>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
<toolbox id="ArcType">
<box id="CenterStartEnd" title="Center and two points" icon="icons/Sketch/arc_base_32x32.png">
<sketch-2dpoint_selector id="ArcCenter" accept_expressions="0" title="Center" tooltip="Center of a circle"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<validator id="GeomValidators_Different" parameters="ArcCenter,ArcStartPoint,ArcEndPoint"/>
</box>
<box id="ThreePoints" title="Three points on arc" icon="icons/Sketch/arc_3pt_32x32.png">
<sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<sketch-2dpoint_selector id="ArcPassedPoint" accept_expressions="0" title="Passed point" tooltip="Passed point"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<validator id="GeomValidators_Different" parameters="ArcStartPoint,ArcEndPoint,ArcPassedPoint"/>
</box>
<box id="Tangent" title="Tangent with edge" icon="icons/Sketch/arc_tang_32x32.png">
<validator id="SketchPlugin_ArcTangentPoint" parameters="" />
</sketch_shape_selector>
<sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
</box>
</toolbox>
<doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon="icons/Sketch/radius.png"
- tooltip="Set radius" obligatory="0" enable_value="false">
+ tooltip="Set radius" obligatory="0" enable_value="enable_by_preferences">
<validator id="GeomValidators_Positive"/>
</doublevalue>
<doublevalue id="ArcAngle" label="Angle:" icon="icons/Sketch/angle.png" tooltip="Set angle" default="90" use_reset="false" obligatory="0"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"
- enable_value="false"/>
+ enable_value="enable_by_preferences"/>
</feature>
<!-- SketchConstraintFillet -->
<validator id="SketchPlugin_FilletVertexValidator"/>
</sketch_multi_selector>
<doublevalue label="Radius" tooltip="Fillet arc radius" id="ConstraintValue" accept_expressions="0" min="0" use_reset="false"
- enable_value="false">
+ enable_value="enable_by_preferences">
<validator id="GeomValidators_Positive"/>
</doublevalue>
<validator id="PartSet_FilletSelection"/>