From: nds Date: Sat, 21 Jun 2014 09:20:01 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~270 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=84d7edd55c6fdecf20b843fec3e75d10ef23983c;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc 1. Radius constraint for an arc. --- diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp index 216f800fe..70e6ba7b2 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp @@ -69,11 +69,7 @@ bool PartSet_ConstraintRadiusPrs::setFeature(FeaturePtr theFeature, const PartSe aLength = PartSet_Tools::featureValue(theFeature, CIRCLE_ATTR_RADIUS, isValid); } else if (aKind == SKETCH_ARC_KIND) { - boost::shared_ptr aCenterAttr = - boost::dynamic_pointer_cast(theFeature->data()->attribute(ARC_ATTR_CENTER)); - boost::shared_ptr aStartAttr = - boost::dynamic_pointer_cast(theFeature->data()->attribute(ARC_ATTR_START)); - aLength = aCenterAttr->pnt()->distance(aStartAttr->pnt()); + aLength = PartSet_FeatureArcPrs::radius(theFeature); } PartSet_Tools::setFeatureValue(feature(), aLength, CONSTRAINT_ATTR_VALUE); @@ -124,10 +120,10 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintRadiusPrs::createPresentation(Fe if (!anAttr) return anAIS; FeaturePtr aFeature = anAttr->feature(); - if (!aFeature || aFeature->getKind() != SKETCH_CIRCLE_KIND) + std::string aKind = aFeature ? aFeature->getKind() : ""; + if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND) return anAIS; - //boost::shared_ptr aFlyoutAttr = // boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); //double aFlyout = aFlyoutAttr->value(); @@ -135,38 +131,42 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintRadiusPrs::createPresentation(Fe boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); double aValue = aValueAttr->value(); - gp_Circ aCircle; - gp_Pnt anAnchorPoint; + // an anchor point + boost::shared_ptr aAnchorAttr = + boost::dynamic_pointer_cast(theFeature->data()->attribute + (SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT)); + boost::shared_ptr anAnchor2D = aAnchorAttr->pnt(); + boost::shared_ptr anAnchor = PartSet_Tools::point3D(anAnchor2D, theSketch); + gp_Pnt anAnchorPoint = anAnchor->impl(); + + std::string aCenterArgument; double aRadius; - //boost::shared_ptr aShape; - if (aFeature->getKind() == SKETCH_CIRCLE_KIND) { - boost::shared_ptr aData = aFeature->data(); - // a circle - boost::shared_ptr aCenterAttr = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); - boost::shared_ptr aCenter2D = aCenterAttr->pnt(); - - boost::shared_ptr aCenter = PartSet_Tools::point3D(aCenter2D, theSketch); - - boost::shared_ptr aNDir = - boost::dynamic_pointer_cast(theSketch->data()->attribute(SKETCH_ATTR_NORM)); - boost::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); - const gp_Dir& aDir = aNormal->impl(); + if (aKind == SKETCH_CIRCLE_KIND) { + aCenterArgument = CIRCLE_ATTR_CENTER; bool isValid; aRadius = PartSet_Tools::featureValue(aFeature, CIRCLE_ATTR_RADIUS, isValid); - aCircle = gp_Circ(gp_Ax2(aCenter->impl(), aDir), aRadius); - - // an anchor point - boost::shared_ptr aAnchorAttr = - boost::dynamic_pointer_cast(theFeature->data()->attribute - (SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT)); - boost::shared_ptr anAnchor2D = aAnchorAttr->pnt(); - boost::shared_ptr anAnchor = PartSet_Tools::point3D(anAnchor2D, theSketch); - anAnchorPoint = anAnchor->impl(); - - //aShape = GeomAlgoAPI_EdgeBuilder::line(aCenter, anAnchor); - //boost::shared_ptr theStart, boost::shared_ptr theEnd) } + else if (aKind == SKETCH_ARC_KIND) { + aCenterArgument = ARC_ATTR_CENTER; + aRadius = PartSet_FeatureArcPrs::radius(aFeature); + } + + // a circle + boost::shared_ptr aCenterAttr = + boost::dynamic_pointer_cast(aFeature->data()->attribute(aCenterArgument)); + boost::shared_ptr aCenter2D = aCenterAttr->pnt(); + boost::shared_ptr aCenter = PartSet_Tools::point3D(aCenter2D, theSketch); + + boost::shared_ptr aNDir = + boost::dynamic_pointer_cast(theSketch->data()->attribute(SKETCH_ATTR_NORM)); + boost::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); + const gp_Dir& aDir = aNormal->impl(); + + gp_Circ aCircle = gp_Circ(gp_Ax2(aCenter->impl(), aDir), aRadius); + //boost::shared_ptr aShape; + //aShape = GeomAlgoAPI_EdgeBuilder::line(aCenter, anAnchor); + //boost::shared_ptr theStart, boost::shared_ptr theEnd) + if (anAIS.IsNull()) { Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(aCircle, anAnchorPoint); diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp index 29d65a9cf..ea9692edc 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.cpp +++ b/src/PartSet/PartSet_FeatureArcPrs.cpp @@ -217,3 +217,18 @@ boost::shared_ptr PartSet_FeatureArcPrs::featurePoint (aData->attribute(aPointArg)); return aPoint; } + +double PartSet_FeatureArcPrs::radius(FeaturePtr theFeature) +{ + if (!theFeature) + return 0; + + boost::shared_ptr aData = theFeature->data(); + + boost::shared_ptr aCenterAttr = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); + boost::shared_ptr aStartAttr = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + + return aCenterAttr->pnt()->distance(aStartAttr->pnt()); +} diff --git a/src/PartSet/PartSet_FeatureArcPrs.h b/src/PartSet/PartSet_FeatureArcPrs.h index b06e0882b..28d9ab669 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.h +++ b/src/PartSet/PartSet_FeatureArcPrs.h @@ -79,6 +79,11 @@ public: virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, double theY); + /// Computes the feature's radius + /// \param theFeature an arc feature + /// \return the double value + static double radius(FeaturePtr theFeature); + protected: /// Returns the feature point in the selection mode position. /// \param theMode the current operation selection mode. The feature attribute depends on the mode