]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#1404 Random crash with Shaper: AIS presentations: coincidence/radius constraints...
authornds <nds@opencascade.com>
Thu, 21 Apr 2016 06:58:30 +0000 (09:58 +0300)
committernds <nds@opencascade.com>
Thu, 21 Apr 2016 06:58:30 +0000 (09:58 +0300)
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
src/SketcherPrs/SketcherPrs_Tools.cpp
src/SketcherPrs/SketcherPrs_Tools.h

index 5c011bf5c9bd3b1b9d20e3baf5015e9188198796..1dbf3e73b047c23595f921036aeed30b5efb9ce1 100644 (file)
@@ -8,6 +8,8 @@
 #include "SketcherPrs_Tools.h"
 
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Events.h>
+
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point.h>
@@ -34,7 +36,7 @@ IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
 
 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint, 
                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
- : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
+ : AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane)
 {
   
 }  
@@ -59,19 +61,17 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)&
                                    const Handle(Prs3d_Presentation)& thePresentation, 
                                    const Standard_Integer theMode)
 {
-  if (!IsReadyToDisplay(myConstraint, myPlane)) {
-    Events_Error::throwException("An empty AIS presentation: SketcherPrs_Coincident");
-    return;
+  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>();
   }
 
   // Get point of the presentation
-  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 = myPlane->to3D(aPnt->x(), aPnt->y());
-  myPoint = aPoint->impl<gp_Pnt>();
-
   static Handle(Graphic3d_AspectMarker3d) aPtA;
   if (aPtA.IsNull()) {
     aPtA = new Graphic3d_AspectMarker3d ();
@@ -86,7 +86,7 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)&
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
   aGroup->SetPrimitivesAspect(aPtA);
   Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
-  aPntArray->AddVertex (aPoint->x(), aPoint->y(), aPoint->z());
+  aPntArray->AddVertex (myPoint.X(), myPoint.Y(), myPoint.Z());
   aGroup->AddPrimitiveArray (aPntArray);
 
   // Make a black mid ring
@@ -101,6 +101,10 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)&
   aPtA->SetScale(5.);
   aGroup->SetPrimitivesAspect(aPtA);
   aGroup->AddPrimitiveArray (aPntArray);
+
+  if (!aReadyToDisplay)
+    SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
+                              "An empty AIS presentation: SketcherPrs_Coincident");
 }
 
 
index 88d08fe525e25755cb511e00d5c5f1b4e2985926..baad5e7fd71671fe6549be75f9d840ab2d252726 100644 (file)
@@ -57,7 +57,7 @@ protected:
 
 private:
   ModelAPI_Feature* myConstraint;
-  std::shared_ptr<GeomAPI_Ax3> myPlane;
+  std::shared_ptr<GeomAPI_Ax3> mySketcherPlane;
   gp_Pnt myPoint;
 };
 
index 5a3e2a07f5ed359ff48d26b50c0e3bfc3454a63c..d1bbd0cfd54c284882ee6cf81fd1cf484ae81ec7 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "SketcherPrs_LengthDimension.h"
 #include "SketcherPrs_Tools.h"
-#include "SketcherPrs_Tools.h"
 #include "SketcherPrs_DimensionStyleListener.h"
 
 #include <SketchPlugin_Constraint.h>
@@ -17,7 +16,6 @@
 #include <SketchPlugin_Circle.h>
 
 #include <Events_Error.h>
-#include <Events_Loop.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Pnt.h>
@@ -26,7 +24,6 @@
 #include <GeomAPI_Lin2d.h>
 
 #include <ModelAPI_Data.h>
-#include <ModelAPI_Events.h>
 #include <ModelAPI_AttributeDouble.h>
 
 #include <AIS_DisplaySpecialSymbol.hxx>
@@ -45,17 +42,8 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo
   myConstraint(theConstraint),
   mySketcherPlane(thePlane)
 {
-  Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
-
-  anAspect->MakeArrows3d(false);
-  anAspect->MakeText3d(false);
-  anAspect->MakeTextShaded(false);
-  anAspect->MakeUnitsDisplayed(false);
-  anAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
-  anAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
-
+  SetDimensionAspect(SketcherPrs_Tools::createDimensionAspect());
   SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight());
-  SetDimensionAspect(anAspect);
 
   myStyleListener = new SketcherPrs_DimensionStyleListener();
 }
@@ -77,10 +65,10 @@ bool SketcherPrs_LengthDimension::IsReadyToDisplay(ModelAPI_Feature* theConstrai
 }
 
 void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-                                 const Handle(Prs3d_Presentation)& thePresentation, 
-                                 const Standard_Integer theMode)
+                                          const Handle(Prs3d_Presentation)& thePresentation, 
+                                          const Standard_Integer theMode)
 {
-  bool aReadyToDisplay = SketcherPrs_LengthDimension::IsReadyToDisplay(myConstraint, mySketcherPlane);
+  bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane);
   if (aReadyToDisplay) {
     myDistance = SketcherPrs_Tools::getFlyoutDistance(myConstraint);
     getPoints(myConstraint, mySketcherPlane, myFirstPoint, mySecondPoint);
@@ -97,18 +85,19 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage
   SetMeasuredGeometry(myFirstPoint, mySecondPoint, myPlane);
 
   // Update variable aspect parameters (depending on viewer scale)
-  updateArrows();
+  double aTextSize = 0.0;
+  GetValueString(aTextSize);
+  SketcherPrs_Tools::updateArrows(DimensionAspect(), GetValue(), aTextSize);
 
+  // Update text visualization: parameter value or parameter text
   myStyleListener->updateDimensions(this, myHasParameters, myValue);
 
   AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
 
-  if (!aReadyToDisplay) {
-    Events_Error::throwException("An empty AIS presentation: SketcherPrs_LengthDimension");
-    static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
-    std::shared_ptr<ModelAPI_Object> aConstraintPtr(myConstraint);
-    ModelAPI_EventCreator::get()->sendUpdated(aConstraintPtr, anEvent);
-  }
+  if (!aReadyToDisplay)
+    SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
+                              "An empty AIS presentation: SketcherPrs_LengthDimension");
+
 }
 
 bool SketcherPrs_LengthDimension::getPoints(ModelAPI_Feature* theConstraint,
@@ -212,27 +201,3 @@ void SketcherPrs_LengthDimension::ComputeSelection(const Handle(SelectMgr_Select
   SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight());
   AIS_LengthDimension::ComputeSelection(aSelection, aMode);
 }
-
-void SketcherPrs_LengthDimension::updateArrows()
-{
-  Handle(Prs3d_DimensionAspect) anAspect = DimensionAspect();
-
-  double anArrowLength = anAspect->ArrowAspect()->Length();
-   // This is not realy correct way to get viewer scale.
-  double aViewerScale = (double) SketcherPrs_Tools::getDefaultArrowSize() / anArrowLength;
-  double aDimensionValue = GetValue();
-  double aTextSize = 0.0;
-  GetValueString(aTextSize);
-
-  if(aTextSize > ((aDimensionValue - 3 * SketcherPrs_Tools::getArrowSize()) * aViewerScale)) {
-    anAspect->SetTextHorizontalPosition(Prs3d_DTHP_Left);
-    anAspect->SetArrowOrientation(Prs3d_DAO_External);
-    anAspect->SetExtensionSize(aTextSize / aViewerScale - SketcherPrs_Tools::getArrowSize() / 2.0);
-  } else {
-    anAspect->SetTextHorizontalPosition(Prs3d_DTHP_Center);
-    anAspect->SetArrowOrientation(Prs3d_DAO_Internal);
-  }
-  anAspect->SetArrowTailSize(anAspect->ArrowAspect()->Length());
-  // The value of vertical aligment is sometimes changed
-  anAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER);
-}
index bfb4433542811aa46b0d3a5135a883228e25d10e..97bd39a83e025089f19d986cc2cfa3b659956484 100644 (file)
@@ -60,9 +60,6 @@ private:
                  const std::shared_ptr<GeomAPI_Ax3>& thePlane,
                  gp_Pnt& thePnt1, gp_Pnt& thePnt2);
 
-  /// Update variable aspect parameters (depending on viewer scale)
-  void updateArrows();
-
   /// Constraint feature
   ModelAPI_Feature* myConstraint;
 
@@ -74,6 +71,7 @@ private:
   /// Listener to update dimension visualization style
   SketcherPrs_DimensionStyleListener* myStyleListener;
 
+  /// container of values obtained from the constraint, which are necessary to fill the presentation
   double myDistance; ///< the flyout distance
   gp_Pnt myFirstPoint; ///< the dimension first point for measured geometry
   gp_Pnt mySecondPoint; ///< the dimension first point for measured geometry
index aeabe0eae97ca416eac8d5251ab8ef0b159a2416..579b36f610f88defdcf253c58241d2ca3fe8ec85 100644 (file)
@@ -30,18 +30,9 @@ IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Radius, AIS_RadiusDimension);
 
 SketcherPrs_Radius::SketcherPrs_Radius(ModelAPI_Feature* theConstraint, 
                                        const std::shared_ptr<GeomAPI_Ax3>& thePlane)
-: AIS_RadiusDimension(MyDefCirc), myConstraint(theConstraint), myPlane(thePlane)
+: AIS_RadiusDimension(MyDefCirc), myConstraint(theConstraint), mySketcherPlane(thePlane)
 {
-  // Set default values of the presentation
-  myAspect = new Prs3d_DimensionAspect();
-  myAspect->MakeArrows3d(false);
-  myAspect->MakeText3d(false);
-  myAspect->MakeTextShaded(false);
-  myAspect->MakeUnitsDisplayed(false);
-  myAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
-  myAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
-  
-  SetDimensionAspect(myAspect);
+  SetDimensionAspect(SketcherPrs_Tools::createDimensionAspect());
   SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight());
 
   myStyleListener = new SketcherPrs_DimensionStyleListener();
@@ -116,81 +107,69 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the
                                  const Handle(Prs3d_Presentation)& thePresentation, 
                                  const Standard_Integer theMode)
 {
-  if (!IsReadyToDisplay(myConstraint, myPlane)) {
-    Events_Error::throwException("An empty AIS presentation: SketcherPrs_Radius");
-    return;
-  }
+  bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane);
+  if (aReadyToDisplay) {
+    //myDistance = SketcherPrs_Tools::getFlyoutDistance(myConstraint);
 
-  DataPtr aData = myConstraint->data();
+    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());
-  double aRadius = 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()));
-    aRadius = aCircRadius->value();
-  } else { // arc
-    aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
+    // Flyout point
+    std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>
-      (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
-    aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+      (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>();
+
+    AttributeDoublePtr anAttributeValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
+    myHasParameters = anAttributeValue->usedParameters().size() > 0;
+    myValue = anAttributeValue->text();
   }
-  std::shared_ptr<GeomAPI_Pnt> aCenter = myPlane->to3D(aCenterAttr->x(), aCenterAttr->y());
-  std::shared_ptr<GeomAPI_Dir> aNormal = myPlane->normal();
-
-  GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);
-    
-  std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, myPlane);
 
-  gp_Circ aCirc = aCircle.impl<gp_Circ>();
-  gp_Pnt anAncorPnt = anAnchor->impl<gp_Pnt>();
-
-  SetMeasuredGeometry(aCirc, anAncorPnt);
-  SetCustomValue(aRadius);
+  SetMeasuredGeometry(myCircle, myAncorPnt);
+  SetCustomValue(myRadius);
 
   // Update variable aspect parameters (depending on viewer scale)
-  double anArrowLength = myAspect->ArrowAspect()->Length();
-   // This is not realy correct way to get viewer scale.
-  double aViewerScale = (double) SketcherPrs_Tools::getDefaultArrowSize() / anArrowLength;
-  double aDimensionValue = GetValue();
   double aTextSize = 0.0;
   GetValueString(aTextSize);
+  SketcherPrs_Tools::updateArrows(DimensionAspect(), GetValue(), aTextSize);
 
-  if(aTextSize > ((aDimensionValue - 2 * SketcherPrs_Tools::getArrowSize()) * aViewerScale)) {
-    myAspect->SetTextHorizontalPosition(Prs3d_DTHP_Left);
-    myAspect->SetArrowOrientation(Prs3d_DAO_External);
-    myAspect->SetExtensionSize(aTextSize / aViewerScale - SketcherPrs_Tools::getArrowSize() / 2.0);
-  } else {
-    myAspect->SetTextHorizontalPosition(Prs3d_DTHP_Center);
-    myAspect->SetArrowOrientation(Prs3d_DAO_Internal);
-  }
-  myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length());
-
-  // The value of vertical aligment is sometimes changed
-  myAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER);
-
-  AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
-  SketcherPrs_Tools::setDisplaySpecialSymbol(this, aValue->usedParameters().size() > 0);
-
-  myStyleListener->updateDimensions(this, aValue);
-
+  myStyleListener->updateDimensions(this, myHasParameters, myValue);
+  
   AIS_RadiusDimension::Compute(thePresentationManager, thePresentation, theMode);
+
+  if (!aReadyToDisplay)
+    SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
+                              "An empty AIS presentation: SketcherPrs_Radius");
 }
 
 void SketcherPrs_Radius::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
index 348eafdcfaf5b6209f3ff5fe20361f9ded6c9ebf..2c940061bb08cca2b3f355ab7cb9e02332cd0f5c 100644 (file)
@@ -56,12 +56,18 @@ private:
   ModelAPI_Feature* myConstraint;
 
   /// Plane of the current sketcher
-  std::shared_ptr<GeomAPI_Ax3> myPlane;
-
-  Handle(Prs3d_DimensionAspect) myAspect;
+  std::shared_ptr<GeomAPI_Ax3> mySketcherPlane;
 
   /// Listener to update dimension visualization style
   SketcherPrs_DimensionStyleListener* myStyleListener;
+
+  /// 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
+
+  bool myHasParameters; ///< true if the atrribute value has used parameters
+  std::string myValue; ///< dimension value
 };
 
 #endif
\ No newline at end of file
index ab4b33023372d92a1b4d0ebe93ad5ed3590eb418..1bd65d40703a5f2d89cb4ce90c07bc4a8dbfdeab 100644 (file)
@@ -15,6 +15,9 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Events.h>
+
+#include <Events_Error.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Lin2d.h>
@@ -23,6 +26,8 @@
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Vertex.hxx>
 
+#include <Prs3d_DimensionAspect.hxx>
+
 #include <BRep_Tool.hxx>
 #include <Precision.hxx>
 
@@ -319,4 +324,43 @@ void sendExpressionShownEvent(const bool& theState)
   Events_Loop::loop()->flush(anId);
 }
 
+Handle(Prs3d_DimensionAspect) createDimensionAspect()
+{
+  Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
+  anAspect->MakeArrows3d(false);
+  anAspect->MakeText3d(false);
+  anAspect->MakeTextShaded(false);
+  anAspect->MakeUnitsDisplayed(false);
+  anAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
+  anAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
+
+  return anAspect;
+}
+
+void updateArrows(Handle(Prs3d_DimensionAspect) theDimAspect, double theDimValue, double theTextSize)
+{
+  double anArrowLength = theDimAspect->ArrowAspect()->Length();
+   // This is not realy correct way to get viewer scale.
+  double aViewerScale = (double) SketcherPrs_Tools::getDefaultArrowSize() / anArrowLength;
+
+  if(theTextSize > ((theDimValue - 3 * SketcherPrs_Tools::getArrowSize()) * aViewerScale)) {
+    theDimAspect->SetTextHorizontalPosition(Prs3d_DTHP_Left);
+    theDimAspect->SetArrowOrientation(Prs3d_DAO_External);
+    theDimAspect->SetExtensionSize(theTextSize / aViewerScale - SketcherPrs_Tools::getArrowSize() / 2.0);
+  } else {
+    theDimAspect->SetTextHorizontalPosition(Prs3d_DTHP_Center);
+    theDimAspect->SetArrowOrientation(Prs3d_DAO_Internal);
+  }
+  theDimAspect->SetArrowTailSize(theDimAspect->ArrowAspect()->Length());
+  // The value of vertical aligment is sometimes changed
+  theDimAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER);
+}
+
+void sendEmptyPresentationError(ModelAPI_Feature* theFeature, const std::string theError)
+{
+  Events_Error::throwException("An empty AIS presentation: SketcherPrs_LengthDimension");
+  static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
+  std::shared_ptr<ModelAPI_Object> aConstraintPtr(theFeature);
+  ModelAPI_EventCreator::get()->sendUpdated(aConstraintPtr, anEvent);
+}
 };
index b41d8b4982d46787554225e5fb53ac307b5f5e5f..d2b22d386afb296d7e45f38ac368e00d6b181401 100644 (file)
@@ -21,6 +21,7 @@
 
 class GeomDataAPI_Point2D;
 class AIS_Dimension;
+class Handle_Prs3d_DimensionAspect;
 
 //#define MyTextHeight 20
 
@@ -174,6 +175,22 @@ namespace SketcherPrs_Tools {
   /// \param theState a new state
   SKETCHERPRS_EXPORT void sendExpressionShownEvent(const bool& theState);
 
+  /// Creates an aspect to be shown in length/radius dimension presentations
+  /// \return an instance of aspect
+  SKETCHERPRS_EXPORT Handle_Prs3d_DimensionAspect createDimensionAspect();
+
+  /// Update variable aspect parameters (depending on viewer scale)
+  /// \param theDimAspect an aspect to be changed
+  /// \param theDimValue an arrow value
+  /// \param theTextSize an arrow value
+  SKETCHERPRS_EXPORT void updateArrows(Handle_Prs3d_DimensionAspect theDimAspect,
+                                       double theDimValue, double theTextSize);
+
+  /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object
+  /// \param theFeature a feature where AIS presentation is empty
+  /// \param theError a debug error information
+  SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature,
+                                                     const std::string theError);
 };
 
 #endif