data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(SketchPlugin_ConstraintAngle::TYPE_ID(), ModelAPI_AttributeInteger::typeId());
}
return;
AttributeDoublePtr anAttrValue = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
- aData->attribute(SketchPlugin_Constraint::VALUE()));
+ aData->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
if (!anAttrValue->isInitialized()) {
double anAngle = calculateAngle();
anAttrValue->setValue(anAngle);
+ updateAngleValue();
}
// the value should to be computed here, not in the getAISObject in order to change the model value
// inside the object transaction. This is important for creating a constraint by preselection.
if (theID == SketchPlugin_Constraint::ENTITY_A() ||
theID == SketchPlugin_Constraint::ENTITY_B()) {
std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
double anAngle = calculateAngle();
aValueAttr->setValue(anAngle);
+ updateAngleValue();
}
} else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
// Recalculate flyout point in local coordinates
aFlyoutAttr->setValue(aFlyoutAttr->x() + tolerance, aFlyoutAttr->y());
myFlyoutUpdate = false;
}
+ else if (theID == SketchPlugin_ConstraintAngle::TYPE_ID()) {
+ std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
+ double anAngle = calculateAngle();
+ aValueAttr->setValue(anAngle);
+ updateAngleValue();
+ }
+ else if (theID == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()) {
+ updateAngleValue();
+ }
}
double SketchPlugin_ConstraintAngle::calculateAngle()
anAngle = fabs(aDirAngle) * 180.0 / PI;
//anAngle = fabs(aDirA->angle(aDirB)) * 180.0 / PI;
+ std::shared_ptr<ModelAPI_AttributeInteger> aTypeAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeInteger>(aData->attribute(SketchPlugin_ConstraintAngle::TYPE_ID()));
+ SketcherPrs_Tools::AngleType anAngleType = (SketcherPrs_Tools::AngleType)(aTypeAttr->value());
+ switch (anAngleType) {
+ case SketcherPrs_Tools::ANGLE_DIRECT:
+ break;
+ case SketcherPrs_Tools::ANGLE_SUPPLEMENTARY:
+ anAngle = 180 - anAngle;
+ break;
+ case SketcherPrs_Tools::ANGLE_BACKWARD:
+ anAngle = 360 - anAngle;
+ break;
+ default:
+ break;
+ }
return anAngle;
}
+void SketchPlugin_ConstraintAngle::updateAngleValue()
+{
+ std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
+ double anAngle = aValueAttr->value();
+
+ std::shared_ptr<ModelAPI_Data> aData = data();
+ std::shared_ptr<ModelAPI_AttributeInteger> aTypeAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeInteger>(aData->attribute(SketchPlugin_ConstraintAngle::TYPE_ID()));
+ SketcherPrs_Tools::AngleType anAngleType = (SketcherPrs_Tools::AngleType)(aTypeAttr->value());
+ switch (anAngleType) {
+ case SketcherPrs_Tools::ANGLE_DIRECT:
+ break;
+ case SketcherPrs_Tools::ANGLE_SUPPLEMENTARY:
+ anAngle = 180 - anAngle;
+ break;
+ case SketcherPrs_Tools::ANGLE_BACKWARD:
+ anAngle = 360 - anAngle;
+ break;
+ default:
+ break;
+ }
+ aValueAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
+ aValueAttr->setValue(anAngle);
+}
+
void SketchPlugin_ConstraintAngle::move(double theDeltaX, double theDeltaY)
{
std::shared_ptr<ModelAPI_Data> aData = data();
/// attribute name of operation type
inline static const std::string& TYPE_ID()
{
- static const std::string MY_TYPE_ID("angle_type");
+ static const std::string MY_TYPE_ID("AngleType");
return MY_TYPE_ID;
}
+ /// attribute name of operation type
+ inline static const std::string& ANGLE_VALUE_ID()
+ {
+ static const std::string MY_ANGLE_VALUE_ID("AngleValue");
+ return MY_ANGLE_VALUE_ID;
+ }
+
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// Calculate current value of the angle
double calculateAngle();
+ /// Update value of VALUE attribute by the combination of the current angle type and angle value
+ void updateAngleValue();
+
/// \brief Use plugin manager for features creation
SketchPlugin_ConstraintAngle();
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
</sketch_shape_selector>
<sketch-2dpoint_flyout_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
- <doublevalue_editor label="Value" tooltip="Angle" id="ConstraintValue" default="computed" min="0" max="360" />
+ <doublevalue_editor label="Value" tooltip="Angle" id="AngleValue" default="computed" min="0" max="360" />
<validator id="PartSet_AngleSelection"/>
- <module_choice id="angle_type"
+ <module_choice id="AngleType"
widget_type="radiobuttons"
buttons_dir="horizontal"
label="Operation type"
std::shared_ptr<ModelAPI_AttributeInteger> aTypeAttr = std::dynamic_pointer_cast<
ModelAPI_AttributeInteger>(aData->attribute(SketchPlugin_ConstraintAngle::TYPE_ID()));
- AngleType anAngleType = (AngleType)(aTypeAttr->value());
+ SketcherPrs_Tools::AngleType anAngleType = (SketcherPrs_Tools::AngleType)(aTypeAttr->value());
// Flyout point
std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
TopoDS_Edge aEdge2 = TopoDS::Edge(aTEdge2);
switch (anAngleType) {
- case ANGLE_DIRECT: {
+ case SketcherPrs_Tools::ANGLE_DIRECT: {
SetGeometryOrientedAngle(true, false);
SetArrowVisible(Standard_False, Standard_True);
SetMeasuredGeometry(aEdge1, aEdge2);
}
break;
- case ANGLE_SUPPLEMENTARY: {
+ case SketcherPrs_Tools::ANGLE_SUPPLEMENTARY: {
// to calculate center, first and end points
SetGeometryOrientedAngle(false, false);
SetMeasuredGeometry(aEdge1, aEdge2);
SetMeasuredGeometry(aFirstPnt, aCenterPnt, aSecondPnt);
}
break;
- case ANGLE_BACKWARD: {
+ case SketcherPrs_Tools::ANGLE_BACKWARD: {
SetGeometryOrientedAngle(true, true);
SetArrowVisible(Standard_False, Standard_True);
SetMeasuredGeometry(aEdge1, aEdge2);
SetFlyout(aDist);
// Angle value is in degrees
- AttributeDoublePtr aVal = aData->real(SketchPlugin_Constraint::VALUE());
+ AttributeDoublePtr aVal = aData->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID());
SetCustomValue(aVal->value() * PI / 180.0);
myAspect->SetExtensionSize(myAspect->ArrowAspect()->Length());
myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length());
- AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
+ AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID());
SketcherPrs_Tools::setDisplaySpecialSymbol(this, aValue->usedParameters().size() > 0);
AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode);
*/
class SketcherPrs_Angle : public AIS_AngleDimension
{
-public:
- /// Type of angle
- enum AngleType{
- ANGLE_DIRECT, ///< Angle from the first line to the second line
- ANGLE_SUPPLEMENTARY, ///< Additional angle to the angle from first to second line
- ANGLE_BACKWARD ///< Angle from the second line to the first line
- };
-
public:
/// Constructor
/// \param theConstraint a constraint feature
Sel_Dimension_Text
};
+ /// Type of angle
+ enum AngleType{
+ ANGLE_DIRECT, ///< Angle from the first line to the second line
+ ANGLE_SUPPLEMENTARY, ///< Additional angle to the angle from first to second line
+ ANGLE_BACKWARD ///< Angle from the second line to the first line
+ };
+
/// Returns attribute object referenced by feature
/// \param theFeature a feature
/// \param theAttrName an attribute name