Salome HOME
Merge remote-tracking branch 'remotes/origin/HighLevelDump'
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_LengthDimension.cpp
index 5a3e2a07f5ed359ff48d26b50c0e3bfc3454a63c..3253d2716a790b26e7b31a9fe9a2310657364885 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>
@@ -16,9 +15,6 @@
 #include <SketchPlugin_Point.h>
 #include <SketchPlugin_Circle.h>
 
-#include <Events_Error.h>
-#include <Events_Loop.h>
-
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_XYZ.h>
@@ -26,7 +22,6 @@
 #include <GeomAPI_Lin2d.h>
 
 #include <ModelAPI_Data.h>
-#include <ModelAPI_Events.h>
 #include <ModelAPI_AttributeDouble.h>
 
 #include <AIS_DisplaySpecialSymbol.hxx>
@@ -43,19 +38,15 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo
                                                          const std::shared_ptr<GeomAPI_Ax3>& thePlane)
 : AIS_LengthDimension(MyDefStart, MyDefEnd, MyDefPln),
   myConstraint(theConstraint),
-  mySketcherPlane(thePlane)
+  mySketcherPlane(thePlane),
+  myFirstPoint(MyDefStart),
+  mySecondPoint(MyDefEnd),
+  myPlane(MyDefPln),
+  myDistance(1),
+  myValue(0., false, "")
 {
-  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();
 }
@@ -68,28 +59,26 @@ 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)
+                                          const Handle(Prs3d_Presentation)& thePresentation, 
+                                          const Standard_Integer theMode)
 {
-  bool aReadyToDisplay = SketcherPrs_LengthDimension::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());
-
-    myHasParameters = anAttributeValue->usedParameters().size() > 0;
-    myValue = anAttributeValue->text();
+    DataPtr aData = myConstraint->data();
+    AttributeDoublePtr anAttributeValue = aData->real(SketchPlugin_Constraint::VALUE());
+    myValue.init(anAttributeValue);
   }
 
   // compute flyout distance
@@ -97,23 +86,23 @@ 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);
 
-  myStyleListener->updateDimensions(this, myHasParameters, myValue);
+  // Update text visualization: parameter value or parameter text
+  myStyleListener->updateDimensions(this, 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,
-                                            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()) {
@@ -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);
-}