void SketchPlugin_ConstraintRadius::execute()
{
-
+ if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() &&
+ !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) {
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ FeaturePtr aFeature = aRef->feature();
+ if (aFeature) {
+ double aRadius = 0;
+ if (aFeature->getKind() == SKETCH_CIRCLE_KIND) {
+ AttributeDoublePtr anAttribute = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>
+ (aFeature->data()->attribute(CIRCLE_ATTR_RADIUS));
+ if (anAttribute)
+ aRadius = anAttribute->value();
+ }
+ else if (aFeature->getKind() == SKETCH_ARC_KIND) {
+ //aLength = PartSet_FeatureArcPrs::radius(theFeature);
+ }
+ boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
+ aValueAttr->setValue(aRadius);
+ }
+ }
}
Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
// an anchor point
boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ if (!aAnchorAttr->isInitialized())
+ return anAIS;
boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
boost::shared_ptr<GeomAPI_Pnt> anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y());
boost::shared_ptr<GeomAPI_Circ> aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius));
+ anAnchor = aCircle->project(anAnchor);
+ // TODO: a bug in AIS_RadiusDimension:
+ // The anchor point can't be myCirc.Location() - an exception is raised.
+ // But we need exactly this case...
+ // We want to show a radius dimension starting from the circle centre and
+ // ending at the user-defined point.
+ // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all.
+ gp_Pnt anAPnt = anAnchor->impl<gp_Pnt>();
+ double aDelta = 1/1000.0;
+ if (anAnchor->x() != 0)
+ anAnchor->setX(anAnchor->x() + aDelta);
+ if (anAnchor->y() != 0)
+ anAnchor->setY(anAnchor->y() + aDelta);
+ if (anAnchor->z() != 0)
+ anAnchor->setZ(anAnchor->z() + aDelta);
+
if (anAIS.IsNull())
{
Handle(AIS_RadiusDimension) aDimAIS =
</feature>
<feature id="SketchConstraintRadius" title="Radius of a circle or an arc" tooltip="Create constraint for the given radius of a circle or an arc">
<label title="Select two points on a circle or an arc of circle on which to calculate radius" tooltip="Select two points on a circle or an arc of circle on which to calculate radius"/>
- <feature_selector id="ConstraintEntityA" keysequence="SketchPoint" internal="1"/>
+ <feature_selector id="ConstraintEntityA" keysequence="SketchCircle SketchArc" internal="1"/>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<doublevalue_editor id="ConstraintValue"/>
</feature>