From b434d0563f486f2f0439c3850ad18c027c68579c Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 24 Jun 2014 20:48:11 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Radius constraint initalization of constraint value. --- .../SketchPlugin_ConstraintRadius.cpp | 41 ++++++++++++++++++- src/SketchPlugin/plugin-Sketch.xml | 2 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 8cdb822ae..b6a32df94 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -32,7 +32,28 @@ void SketchPlugin_ConstraintRadius::initAttributes() void SketchPlugin_ConstraintRadius::execute() { - + if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() && + !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) { + + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(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 + (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 aValueAttr = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); + aValueAttr->setValue(aRadius); + } + } } Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( @@ -59,6 +80,8 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( // an anchor point boost::shared_ptr aAnchorAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + if (!aAnchorAttr->isInitialized()) + return anAIS; boost::shared_ptr anAnchor2D = aAnchorAttr->pnt(); boost::shared_ptr anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y()); @@ -87,6 +110,22 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( boost::shared_ptr 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(); + 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 = diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index c4bbaab49..fc4b9d6b5 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -37,7 +37,7 @@ -- 2.39.2