]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#1404 Random crash with Shaper: AIS presentations: avoid IsReadyToDisplay calling...
authornds <nds@opencascade.com>
Thu, 21 Apr 2016 08:19:02 +0000 (11:19 +0300)
committernds <nds@opencascade.com>
Thu, 21 Apr 2016 08:19:26 +0000 (11:19 +0300)
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/PartSet/PartSet_OperationPrs.cpp
src/PartSet/PartSet_ResultSketchPrs.cpp
src/SketcherPrs/SketcherPrs_Coincident.cpp
src/SketcherPrs/SketcherPrs_Coincident.h
src/SketcherPrs/SketcherPrs_LengthDimension.cpp
src/SketcherPrs/SketcherPrs_LengthDimension.h
src/SketcherPrs/SketcherPrs_Radius.cpp
src/SketcherPrs/SketcherPrs_Radius.h

index 726821ec193a0de02ad7784165f25e81495bafd0..310bb78f87cae91d1c6dd9f67bf5d880ae5bb289 100755 (executable)
@@ -76,19 +76,21 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
                                    const Standard_Integer theMode)
 {
   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
-  if (aShapePtr.get()) {
+  bool aReadyToDisplay = aShapePtr.get();
+  if (aReadyToDisplay) {
     myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
     if (!myOriginalShape.IsNull())
       Set(myOriginalShape);
   }
-  else {
+  // change deviation coefficient to provide more precise circle
+  ModuleBase_Tools::setDefaultDeviationCoefficient(Shape(), Attributes());
+  AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
+
+  if (!aReadyToDisplay) {
     Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
     static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
     ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
   }
-  // change deviation coefficient to provide more precise circle
-  ModuleBase_Tools::setDefaultDeviationCoefficient(Shape(), Attributes());
-  AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
 }
 
 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
index 3858042e3c4524a7e506f33bda0d7ed4b7e41d86..a749611f5cc9d841f9f90acf8d331495f32c8663 100755 (executable)
@@ -82,10 +82,12 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
   NCollection_DataMap<TopoDS_Shape, Handle(AIS_InteractiveObject)> aShapeToPrsMap;
   fillShapeList(myFeatureShapes, aShapeToPrsMap);
 
-  if (!aShapeToPrsMap.IsEmpty()) {
+  bool aReadyToDisplay = !myShapeToPrsMap.IsEmpty();
+  if (aReadyToDisplay) {
     myShapeToPrsMap.Clear();
     myShapeToPrsMap.Assign(aShapeToPrsMap);
   }
+
   XGUI_Displayer* aDisplayer = XGUI_Tools::workshop(myWorkshop)->displayer();
   Handle(Prs3d_Drawer) aDrawer = Attributes();
   // create presentations on the base of the shapes
@@ -110,9 +112,8 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
     StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer);
   }
 
-  if (myShapeToPrsMap.IsEmpty()) {
+  if (!aReadyToDisplay) {
     Events_Error::throwException("An empty AIS presentation: PartSet_OperationPrs");
-
     //std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
     //            new Events_Message(Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)));
     //Events_Loop::loop()->send(aMsg);
index 04d9318eabb70215e7688025b63059ad978b19ed..0e7319f8f25c14b411aaf0e64de9ef8dd4048730 100755 (executable)
@@ -84,20 +84,20 @@ void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)
   NCollection_List<TopoDS_Shape> aFaceList;
   fillShapes(aResultShape, anAuxiliaryCompound, mySketchFaceList);
 
-  bool isEmptyPresentation = aResultShape.IsNull() && anAuxiliaryCompound.IsNull();
+  bool aReadyToDisplay = !aResultShape.IsNull() || !anAuxiliaryCompound.IsNull();
 
-  if (!aResultShape.IsNull()) {
-    myOriginalShape = aResultShape;
-    if (!myOriginalShape.IsNull())
-      Set(myOriginalShape);
-  }
-
-  if (!anAuxiliaryCompound.IsNull())
+  if (aReadyToDisplay) {
+    if (!aResultShape.IsNull()) {
+      myOriginalShape = aResultShape;
+      if (!myOriginalShape.IsNull())
+        Set(myOriginalShape);
+    }
     myAuxiliaryCompound = anAuxiliaryCompound;
+  }
 
   setAuxiliaryPresentationStyle(false);
 
-    // change deviation coefficient to provide more precise circle
+  // change deviation coefficient to provide more precise circle
   ModuleBase_Tools::setDefaultDeviationCoefficient(Shape(), Attributes());
   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
 
@@ -108,7 +108,7 @@ void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)
     StdPrs_WFDeflectionShape::Add(thePresentation, myAuxiliaryCompound, aDrawer);
   }
 
-  if (isEmptyPresentation) {
+  if (!aReadyToDisplay) {
     Events_Error::throwException("An empty AIS presentation: PartSet_ResultSketchPrs");
     static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
     ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
index 1dbf3e73b047c23595f921036aeed30b5efb9ce1..d8cb88cb21b3d905873a5a68d87a12172459faf8 100644 (file)
@@ -42,17 +42,26 @@ SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
 }  
 
 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
-                                              const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
+                                              const std::shared_ptr<GeomAPI_Ax3>& thePlane)
 {
-  bool aReadyToDisplay = false;
+  gp_Pnt aPoint;
+  return readyToDisplay(theConstraint, thePlane, aPoint);
+}
 
+bool SketcherPrs_Coincident::readyToDisplay(ModelAPI_Feature* theConstraint,
+                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                                            gp_Pnt& thePoint)
+{
+  bool aReadyToDisplay = false;
   // Get point of the presentation
   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
                                                               SketchPlugin_Constraint::ENTITY_A());
-  if (aPnt.get() == NULL)
+  if (aPnt.get() == NULL) {
     aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
-  
-  aReadyToDisplay = aPnt.get() != NULL;
+    aReadyToDisplay = aPnt.get() != NULL;
+    if (aReadyToDisplay)
+      thePoint = aPnt->impl<gp_Pnt>();
+  }
   return aReadyToDisplay;
 }
 
@@ -61,15 +70,10 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)&
                                    const Handle(Prs3d_Presentation)& thePresentation, 
                                    const Standard_Integer theMode)
 {
-  bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane);
-  if (aReadyToDisplay) {
-    std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint, 
-                                                                      SketchPlugin_Constraint::ENTITY_A());
-    if (aPnt.get() == NULL)
-      aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_B());
-    std::shared_ptr<GeomAPI_Pnt> aPoint = mySketcherPlane->to3D(aPnt->x(), aPnt->y());
-    myPoint = aPoint->impl<gp_Pnt>();
-  }
+  gp_Pnt aPoint;
+  bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, aPoint);
+  if (aReadyToDisplay)
+    myPoint = aPoint;
 
   // Get point of the presentation
   static Handle(Graphic3d_AspectMarker3d) aPtA;
index baad5e7fd71671fe6549be75f9d840ab2d252726..082016c81b7ae69347531ee13db790898e419eb5 100644 (file)
@@ -55,6 +55,11 @@ protected:
   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
     const Standard_Integer aMode) ;
 
+private:
+  static bool readyToDisplay(ModelAPI_Feature* theConstraint,
+                      const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                      gp_Pnt& thePoint);
+
 private:
   ModelAPI_Feature* myConstraint;
   std::shared_ptr<GeomAPI_Ax3> mySketcherPlane;
index d1bbd0cfd54c284882ee6cf81fd1cf484ae81ec7..f17a22dd1ee5ef54f9e231a9469c695ad99ac1ff 100644 (file)
@@ -56,22 +56,21 @@ SketcherPrs_LengthDimension::~SketcherPrs_LengthDimension()
 bool SketcherPrs_LengthDimension::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
                                          const std::shared_ptr<GeomAPI_Ax3>& thePlane)
 {
-  bool aReadyToDisplay = false;
-
   gp_Pnt aPnt1, aPnt2;
-  aReadyToDisplay = getPoints(theConstraint, thePlane, aPnt1, aPnt2);
-
-  return aReadyToDisplay;
+  return readyToDisplay(theConstraint, thePlane, aPnt1, aPnt2);
 }
 
 void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                                           const Handle(Prs3d_Presentation)& thePresentation, 
                                           const Standard_Integer theMode)
 {
-  bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane);
+  gp_Pnt aPnt1, aPnt2;
+  bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, aPnt1, aPnt2);
   if (aReadyToDisplay) {
+    myFirstPoint = aPnt1;
+    mySecondPoint = aPnt2;
+
     myDistance = SketcherPrs_Tools::getFlyoutDistance(myConstraint);
-    getPoints(myConstraint, mySketcherPlane, myFirstPoint, mySecondPoint);
     myPlane = gp_Pln(mySketcherPlane->impl<gp_Ax3>());
 
     AttributeDoublePtr anAttributeValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
@@ -97,12 +96,11 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage
   if (!aReadyToDisplay)
     SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
                               "An empty AIS presentation: SketcherPrs_LengthDimension");
-
 }
 
-bool SketcherPrs_LengthDimension::getPoints(ModelAPI_Feature* theConstraint,
-                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane,
-                                            gp_Pnt& thePnt1, gp_Pnt& thePnt2)
+bool SketcherPrs_LengthDimension::readyToDisplay(ModelAPI_Feature* theConstraint,
+                                                 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                                                 gp_Pnt& thePnt1, gp_Pnt& thePnt2)
 {
   DataPtr aData = theConstraint->data();
   if (theConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
index 97bd39a83e025089f19d986cc2cfa3b659956484..75d5aa4c6373cd6cf153123856709ed1c6a50255 100644 (file)
@@ -56,9 +56,9 @@ protected:
     const Standard_Integer aMode);
 
 private:
-  static bool getPoints(ModelAPI_Feature* theConstraint,
-                 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
-                 gp_Pnt& thePnt1, gp_Pnt& thePnt2);
+  static bool readyToDisplay(ModelAPI_Feature* theConstraint,
+                             const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                             gp_Pnt& thePnt1, gp_Pnt& thePnt2);
 
   /// Constraint feature
   ModelAPI_Feature* myConstraint;
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)
index 2c940061bb08cca2b3f355ab7cb9e02332cd0f5c..3ba60e08306b7a630bfec9745e6036d812b8f978 100644 (file)
@@ -42,6 +42,18 @@ public:
   /// \return boolean result value
   static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
                                const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+private:
+  /// Fills the constraint parameters by constraint and plane
+  /// \param theConstraint a constraint feature
+  /// \param thePlane a coordinate plane of current sketch
+  /// \param theCircle a circle build on the constraint values
+  /// \param thePoint an anchor point to show text value
+  /// \param theRadius a circle custom radius value to be visualized
+  /// \return boolean result value
+  static bool readyToDisplay(ModelAPI_Feature* theConstraint,
+                             const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                             gp_Circ& theCircle, gp_Pnt& theAnchorPoint,
+                             double& theRadius);
 protected:
   /// Redefinition of virtual function
   Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
@@ -64,7 +76,7 @@ private:
   /// container of values obtained from the constraint, which are necessary to fill the presentation
   double myRadius; ///< the radius custom value
   gp_Circ myCircle; ///< the radius circle
-  gp_Pnt myAncorPnt; ///< an ancor for the radius value visualization
+  gp_Pnt myAnchorPoint; ///< an ancor for the radius value visualization
 
   bool myHasParameters; ///< true if the atrribute value has used parameters
   std::string myValue; ///< dimension value