From: nds Date: Thu, 21 Apr 2016 06:00:31 +0000 (+0300) Subject: #1404 Random crash with Shaper: AIS presentations: length dimension correction X-Git-Tag: V_2.3.0~164 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a49ed1bc5c4745f07d1aabbaf465f25f00ff1040;p=modules%2Fshaper.git #1404 Random crash with Shaper: AIS presentations: length dimension correction --- diff --git a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp index ffb2a8d4c..e8b950f38 100755 --- a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp +++ b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp @@ -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); } } + diff --git a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h index 03e92957c..3ff9696b7 100755 --- a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h +++ b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h @@ -15,6 +15,8 @@ #include +#include + /** * \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; diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index 018f47b01..5a3e2a07f 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -42,18 +43,19 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo const std::shared_ptr& 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_Pnt aPnt1, aPnt2; - getPoints(myConstraint, myPlane, aPnt1, aPnt2); - - // compute flyout distance - SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint)); - SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl()); - - // 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 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); +} diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.h b/src/SketcherPrs/SketcherPrs_LengthDimension.h index 59d302ae5..bfb443354 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.h +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.h @@ -13,7 +13,9 @@ #include #include -#include +#include +#include +#include class SketcherPrs_DimensionStyleListener; @@ -58,16 +60,26 @@ private: const std::shared_ptr& 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 myPlane; + std::shared_ptr 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