]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketcherPrs/SketcherPrs_LengthDimension.cpp
Salome HOME
empty AIS presentation should not be visualized in the viewer. It is caused by OCCT...
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_LengthDimension.cpp
index 49415d7bbfbb5ffa2c03f690aa75a29d23c2b818..b6df9e517274bfc4ccec6a73535835ae3da0baad 100644 (file)
@@ -53,16 +53,29 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo
   SetDimensionAspect(myAspect);
 }
 
+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;
+}
+
 void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                                  const Handle(Prs3d_Presentation)& thePresentation, 
                                  const Standard_Integer theMode)
 {
-  gp_Pnt aPnt1, aPnt2;
-  if (!getPoints(aPnt1, aPnt2)) {
+  if (!SketcherPrs_LengthDimension::IsReadyToDisplay(myConstraint, myPlane)) {
     Events_Error::throwException("An empty AIS presentation: SketcherPrs_LengthDimension");
     return;
   }
 
+  gp_Pnt aPnt1, aPnt2;
+  getPoints(myConstraint, myPlane, aPnt1, aPnt2);
+
   // compute flyout distance
   SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint));
   SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl<gp_Ax3>());
@@ -94,10 +107,12 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage
   AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
 }
 
-bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2)
+bool SketcherPrs_LengthDimension::getPoints(ModelAPI_Feature* theConstraint,
+                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                                            gp_Pnt& thePnt1, gp_Pnt& thePnt2)
 {
-  DataPtr aData = myConstraint->data();
-  if (myConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
+  DataPtr aData = theConstraint->data();
+  if (theConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
     // The constraint is length
     std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
       std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
@@ -117,16 +132,16 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2)
     std::shared_ptr<GeomDataAPI_Point2D> aEndPoint = 
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>
       (aLineData->attribute(SketchPlugin_Line::END_ID()));
-    thePnt1 = myPlane->to3D(aStartPoint->x(), aStartPoint->y())->impl<gp_Pnt>();
-    thePnt2 = myPlane->to3D(aEndPoint->x(), aEndPoint->y())->impl<gp_Pnt>();
+    thePnt1 = thePlane->to3D(aStartPoint->x(), aStartPoint->y())->impl<gp_Pnt>();
+    thePnt2 = thePlane->to3D(aEndPoint->x(), aEndPoint->y())->impl<gp_Pnt>();
     return true;
 
-  } else if (myConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
+  } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
     // The constraint is distance
     std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
-        aData, SketchPlugin_Constraint::ENTITY_A(), myPlane);
+        aData, SketchPlugin_Constraint::ENTITY_A(), thePlane);
     std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
-        aData, SketchPlugin_Constraint::ENTITY_B(), myPlane);
+        aData, SketchPlugin_Constraint::ENTITY_B(), thePlane);
 
     std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
     std::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
@@ -154,9 +169,9 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2)
     if (!aPnt_A || !aPnt_B) // Objects not found
       return false;
 
-    // Get points from these objects
-    std::shared_ptr<GeomAPI_Pnt> aPoint1 = myPlane->to3D(aPnt_A->x(), aPnt_A->y());
-    std::shared_ptr<GeomAPI_Pnt> aPoint2 = myPlane->to3D(aPnt_B->x(), aPnt_B->y());
+    // Get points from these object
+    std::shared_ptr<GeomAPI_Pnt> aPoint1 = thePlane->to3D(aPnt_A->x(), aPnt_A->y());
+    std::shared_ptr<GeomAPI_Pnt> aPoint2 = thePlane->to3D(aPnt_B->x(), aPnt_B->y());
     thePnt1 = aPoint1->impl<gp_Pnt>();
     thePnt2 = aPoint2->impl<gp_Pnt>();
     return true;