]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 16:48:11 +0000 (20:48 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 16:48:11 +0000 (20:48 +0400)
Radius constraint initalization of constraint value.

src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp
src/SketchPlugin/plugin-Sketch.xml

index 8cdb822ae78104175a33a1aa66c1f2eb4662e29a..b6a32df9476e9849ff205ecbabf33bf76d2f7e77 100644 (file)
@@ -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<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(
@@ -59,6 +80,8 @@ 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());
 
@@ -87,6 +110,22 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
 
   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 = 
index c4bbaab49988c4ce18ba31730355ea68b429227e..fc4b9d6b556e1f2a189042725f518a03d3fc8ddd 100644 (file)
@@ -37,7 +37,7 @@
       </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>