]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#1404 Random crash with Shaper: AIS presentations: length dimension correction
authornds <nds@opencascade.com>
Thu, 21 Apr 2016 06:00:31 +0000 (09:00 +0300)
committernds <nds@opencascade.com>
Thu, 21 Apr 2016 06:00:56 +0000 (09:00 +0300)
src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp
src/SketcherPrs/SketcherPrs_DimensionStyleListener.h
src/SketcherPrs/SketcherPrs_LengthDimension.cpp
src/SketcherPrs/SketcherPrs_LengthDimension.h

index ffb2a8d4c7d99fe241bd9b41e6bc0b6728210a4d..e8b950f383b72facb28039ec2b96c0164b3da744 100755 (executable)
@@ -39,15 +39,25 @@ void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDime
 {
   if (!theDimension || !theAttributeValue.get())
     return;
+  updateDimensions(theDimension, theAttributeValue->usedParameters().size() > 0,
+                   theAttributeValue->text());
+}
+
+void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
+                                                          const bool theHasParameters,
+                                                          const std::string& theValue)
+{
+  if (!theDimension)
+    return;
 
-  bool aHasParameters = theAttributeValue->usedParameters().size() > 0;
-  if (aHasParameters) {
+  if (theHasParameters) {
     bool isParameterValueStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterValue;
     SketcherPrs_Tools::setDisplaySpecialSymbol(theDimension, isParameterValueStyle);
-    SketcherPrs_Tools::setDisplayParameter(theDimension, theAttributeValue->text(), !isParameterValueStyle);
+    SketcherPrs_Tools::setDisplayParameter(theDimension, theValue, !isParameterValueStyle);
   }
   else {
     SketcherPrs_Tools::setDisplaySpecialSymbol(theDimension, false);
-    SketcherPrs_Tools::setDisplayParameter(theDimension, theAttributeValue->text(), false);
+    SketcherPrs_Tools::setDisplayParameter(theDimension, theValue, false);
   }
 }
+
index 03e92957c007b9d270e7917b92038b1e3af30253..3ff9696b7415bb2566edebece96820a366c6242f 100755 (executable)
@@ -15,6 +15,8 @@
 
 #include <Standard.hxx>
 
+#include <string>
+
 /**
 * \ingroup GUI
 * A class for representation of linear dimension constraint.
@@ -39,6 +41,14 @@ public:
   Standard_EXPORT void updateDimensions(AIS_Dimension* theDimension,
                                         const AttributeDoublePtr& theAttributeValue);
 
+  /// Visualizes the dimension text or dimension value depending on the has parameters state
+  /// \param theDimension a modified dimension
+  /// \param theHasParameters if true, the text is shown, else digit
+  /// \param theValue a dimension value
+  Standard_EXPORT void updateDimensions(AIS_Dimension* theDimension,
+                                        const bool theHasParameters,
+                                        const std::string& theValue);
+
 private:
   /// Style how the parameter of dimension should be visualized
   SketcherPrs_ParameterStyleMessage::ParameterStyle myStyle;
index 018f47b017d4d87bbf681b991e07cbf8cb2f34e6..5a3e2a07f5ed359ff48d26b50c0e3bfc3454a63c 100644 (file)
@@ -26,6 +26,7 @@
 #include <GeomAPI_Lin2d.h>
 
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Events.h>
 #include <ModelAPI_AttributeDouble.h>
 
 #include <AIS_DisplaySpecialSymbol.hxx>
@@ -42,18 +43,19 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo
                                                          const std::shared_ptr<GeomAPI_Ax3>& thePlane)
 : AIS_LengthDimension(MyDefStart, MyDefEnd, MyDefPln),
   myConstraint(theConstraint),
-  myPlane(thePlane),
-  myAspect(new Prs3d_DimensionAspect())
+  mySketcherPlane(thePlane)
 {
-  myAspect->MakeArrows3d(false);
-  myAspect->MakeText3d(false);
-  myAspect->MakeTextShaded(false);
-  myAspect->MakeUnitsDisplayed(false);
-  myAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
-  myAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
+  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());
 
   SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight());
-  SetDimensionAspect(myAspect);
+  SetDimensionAspect(anAspect);
 
   myStyleListener = new SketcherPrs_DimensionStyleListener();
 }
@@ -78,44 +80,35 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage
                                  const Handle(Prs3d_Presentation)& thePresentation, 
                                  const Standard_Integer theMode)
 {
-  if (!SketcherPrs_LengthDimension::IsReadyToDisplay(myConstraint, myPlane)) {
-    Events_Error::throwException("An empty AIS presentation: SketcherPrs_LengthDimension");
-    return;
-  }
+  bool aReadyToDisplay = SketcherPrs_LengthDimension::IsReadyToDisplay(myConstraint, mySketcherPlane);
+  if (aReadyToDisplay) {
+    myDistance = SketcherPrs_Tools::getFlyoutDistance(myConstraint);
+    getPoints(myConstraint, mySketcherPlane, myFirstPoint, mySecondPoint);
+    myPlane = gp_Pln(mySketcherPlane->impl<gp_Ax3>());
 
-  gp_Pnt aPnt1, aPnt2;
-  getPoints(myConstraint, myPlane, aPnt1, aPnt2);
-
-  // compute flyout distance
-  SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint));
-  SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl<gp_Ax3>());
-
-  // 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);
+    AttributeDoublePtr anAttributeValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
 
-  if(aTextSize > ((aDimensionValue - 3 * 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);
+    myHasParameters = anAttributeValue->usedParameters().size() > 0;
+    myValue = anAttributeValue->text();
   }
-  myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length());
 
-  // The value of vertical aligment is sometimes changed
-  myAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER);
+  // compute flyout distance
+  SetFlyout(myDistance);
+  SetMeasuredGeometry(myFirstPoint, mySecondPoint, myPlane);
 
-  AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
+  // Update variable aspect parameters (depending on viewer scale)
+  updateArrows();
 
-  myStyleListener->updateDimensions(this, aValue);
+  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);
+  }
 }
 
 bool SketcherPrs_LengthDimension::getPoints(ModelAPI_Feature* theConstraint,
@@ -219,3 +212,27 @@ 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 59d302ae52d1660d526bbd3032823f3da481c19d..bfb4433542811aa46b0d3a5135a883228e25d10e 100644 (file)
@@ -13,7 +13,9 @@
 #include <AIS_LengthDimension.hxx>
 #include <Standard_DefineHandle.hxx>
 
-#include <SketcherPrs_Tools.h>
+#include <gp_Pnt.hxx>
+#include <gp_Pln.hxx>
+#include <string>
 
 class SketcherPrs_DimensionStyleListener;
 
@@ -58,16 +60,26 @@ 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;
 
   /// Plane of the current sketcher
-  std::shared_ptr<GeomAPI_Ax3> myPlane;
+  std::shared_ptr<GeomAPI_Ax3> mySketcherPlane;
 
-  Handle(Prs3d_DimensionAspect) myAspect;
+  //Handle(Prs3d_DimensionAspect) myAspect;
 
   /// Listener to update dimension visualization style
   SketcherPrs_DimensionStyleListener* myStyleListener;
+
+  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
+  gp_Pln myPlane; ///< the plane(plane of the sketch) for measured geometry
+  bool myHasParameters; ///< true if the atrribute value has used parameters
+  std::string myValue; ///< dimension value
 };
 
 #endif
\ No newline at end of file