Salome HOME
#1404 Random crash with Shaper: AIS presentations: avoid IsReadyToDisplay calling...
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Radius.cpp
index 579b36f610f88defdcf253c58241d2ca3fe8ec85..c842033bae9927f7ecde064a84068ee6632197df 100644 (file)
@@ -45,6 +45,17 @@ SketcherPrs_Radius::~SketcherPrs_Radius()
 
 bool SketcherPrs_Radius::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
                                           const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+  gp_Circ aCircle;
+  gp_Pnt anAnchorPoint;
+  double aRadius;
+  return readyToDisplay(theConstraint, thePlane, aCircle, anAnchorPoint, aRadius);
+}
+
+bool SketcherPrs_Radius::readyToDisplay(ModelAPI_Feature* theConstraint,
+                                        const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                                        gp_Circ& theCircle, gp_Pnt& theAnchorPoint,
+                                        double& theRadius)
 {
   bool aReadyToDisplay = false;
 
@@ -66,7 +77,7 @@ bool SketcherPrs_Radius::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
     return aReadyToDisplay;
 
   std::shared_ptr<ModelAPI_Feature> aCyrcFeature = ModelAPI_Feature::feature(anAttr->object());
-  double aRadius = 1;
+  theRadius = 1;
   std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
   // it is possible that circle result becomes zero, in this case the presentation should disappear
   // for example, it happens when circle radius is set to zero
@@ -78,28 +89,26 @@ bool SketcherPrs_Radius::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
     AttributeDoublePtr aCircRadius = 
       std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
       aCyrcFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()));
-    aRadius = aCircRadius->value();
+    theRadius = aCircRadius->value();
   } else { // arc
     aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
         aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
     std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>
       (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
-    aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+    theRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
   }
   std::shared_ptr<GeomAPI_Pnt> aCenter = thePlane->to3D(aCenterAttr->x(), aCenterAttr->y());
   std::shared_ptr<GeomAPI_Dir> aNormal = thePlane->normal();
 
-  GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);
-    
+  GeomAPI_Circ aCircle(aCenter, aNormal, theRadius);
   std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(theConstraint, thePlane);
 
-  gp_Circ aCirc = aCircle.impl<gp_Circ>();
-  gp_Pnt anAncorPnt = anAnchor->impl<gp_Pnt>();
-  // anchor point should not coincide to the location point of the circle
-  // OCCT does not process this case.
+  theCircle = aCircle.impl<gp_Circ>();
+  theAnchorPoint = anAnchor->impl<gp_Pnt>();
+
+  aReadyToDisplay = theAnchorPoint.Distance(theCircle.Location()) > 1e-7;
 
-  aReadyToDisplay = anAncorPnt.Distance(aCirc.Location()) > 1e-7;
   return aReadyToDisplay;
 }
 
@@ -107,55 +116,21 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the
                                  const Handle(Prs3d_Presentation)& thePresentation, 
                                  const Standard_Integer theMode)
 {
-  bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane);
+  gp_Circ aCircle;
+  gp_Pnt anAnchorPoint;
+  double aRadius;
+  bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, aCircle, anAnchorPoint, aRadius);
   if (aReadyToDisplay) {
-    //myDistance = SketcherPrs_Tools::getFlyoutDistance(myConstraint);
-
-    DataPtr aData = myConstraint->data();
-
-    // Flyout point
-    std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>
-      (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-
-    // Get circle
-    std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
-      (aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
-
-    std::shared_ptr<ModelAPI_Feature> aCyrcFeature = ModelAPI_Feature::feature(anAttr->object());
-    myRadius = 1;
-    std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
-    if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle
-      aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-          aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
-      AttributeDoublePtr aCircRadius = 
-        std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
-        aCyrcFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()));
-      myRadius = aCircRadius->value();
-    } else { // arc
-      aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-          aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
-      std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>
-        (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
-      myRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
-    }
-    std::shared_ptr<GeomAPI_Pnt> aCenter = mySketcherPlane->to3D(aCenterAttr->x(), aCenterAttr->y());
-    std::shared_ptr<GeomAPI_Dir> aNormal = mySketcherPlane->normal();
-
-    GeomAPI_Circ aCircle(aCenter, aNormal, myRadius);
-    std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, mySketcherPlane);
-
-    myCircle = aCircle.impl<gp_Circ>();
-    myAncorPnt = anAnchor->impl<gp_Pnt>();
+    myCircle = aCircle;
+    myAnchorPoint = anAnchorPoint;
+    myRadius = aRadius;
 
     AttributeDoublePtr anAttributeValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
     myHasParameters = anAttributeValue->usedParameters().size() > 0;
     myValue = anAttributeValue->text();
   }
 
-  SetMeasuredGeometry(myCircle, myAncorPnt);
+  SetMeasuredGeometry(myCircle, myAnchorPoint);
   SetCustomValue(myRadius);
 
   // Update variable aspect parameters (depending on viewer scale)