From: nds Date: Thu, 21 Apr 2016 06:58:30 +0000 (+0300) Subject: #1404 Random crash with Shaper: AIS presentations: coincidence/radius constraints... X-Git-Tag: V_2.3.0~163 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4a230167f3242b22231d699f5c5a2a1787a51e71;p=modules%2Fshaper.git #1404 Random crash with Shaper: AIS presentations: coincidence/radius constraints correction --- diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index 5c011bf5c..1dbf3e73b 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -8,6 +8,8 @@ #include "SketcherPrs_Tools.h" #include +#include + #include #include #include @@ -34,7 +36,7 @@ IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject); SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint, const std::shared_ptr& 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 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 aPoint = mySketcherPlane->to3D(aPnt->x(), aPnt->y()); + myPoint = aPoint->impl(); } // Get point of the presentation - std::shared_ptr 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 aPoint = myPlane->to3D(aPnt->x(), aPnt->y()); - myPoint = aPoint->impl(); - 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"); } diff --git a/src/SketcherPrs/SketcherPrs_Coincident.h b/src/SketcherPrs/SketcherPrs_Coincident.h index 88d08fe52..baad5e7fd 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.h +++ b/src/SketcherPrs/SketcherPrs_Coincident.h @@ -57,7 +57,7 @@ protected: private: ModelAPI_Feature* myConstraint; - std::shared_ptr myPlane; + std::shared_ptr mySketcherPlane; gp_Pnt myPoint; }; diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index 5a3e2a07f..d1bbd0cfd 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -6,7 +6,6 @@ #include "SketcherPrs_LengthDimension.h" #include "SketcherPrs_Tools.h" -#include "SketcherPrs_Tools.h" #include "SketcherPrs_DimensionStyleListener.h" #include @@ -17,7 +16,6 @@ #include #include -#include #include #include @@ -26,7 +24,6 @@ #include #include -#include #include #include @@ -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 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); -} diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.h b/src/SketcherPrs/SketcherPrs_LengthDimension.h index bfb443354..97bd39a83 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.h +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.h @@ -60,9 +60,6 @@ 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; @@ -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 diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index aeabe0eae..579b36f61 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -30,18 +30,9 @@ IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Radius, AIS_RadiusDimension); SketcherPrs_Radius::SketcherPrs_Radius(ModelAPI_Feature* theConstraint, const std::shared_ptr& 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 aFlyoutAttr = - std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - - // Get circle - std::shared_ptr anAttr = - std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - - std::shared_ptr aCyrcFeature = ModelAPI_Feature::feature(anAttr->object()); - double aRadius = 1; - std::shared_ptr aCenterAttr; - if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle - aCenterAttr = std::dynamic_pointer_cast( - aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); - AttributeDoublePtr aCircRadius = - std::dynamic_pointer_cast( - aCyrcFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID())); - aRadius = aCircRadius->value(); - } else { // arc - aCenterAttr = std::dynamic_pointer_cast( - aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID())); - std::shared_ptr aStartAttr = + // Flyout point + std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast - (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 anAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Constraint::ENTITY_A())); + + std::shared_ptr aCyrcFeature = ModelAPI_Feature::feature(anAttr->object()); + myRadius = 1; + std::shared_ptr aCenterAttr; + if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle + aCenterAttr = std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); + AttributeDoublePtr aCircRadius = + std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID())); + myRadius = aCircRadius->value(); + } else { // arc + aCenterAttr = std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID())); + std::shared_ptr aStartAttr = + std::dynamic_pointer_cast + (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID())); + myRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); + } + std::shared_ptr aCenter = mySketcherPlane->to3D(aCenterAttr->x(), aCenterAttr->y()); + std::shared_ptr aNormal = mySketcherPlane->normal(); + + GeomAPI_Circ aCircle(aCenter, aNormal, myRadius); + std::shared_ptr anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, mySketcherPlane); + + myCircle = aCircle.impl(); + myAncorPnt = anAnchor->impl(); + + AttributeDoublePtr anAttributeValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE()); + myHasParameters = anAttributeValue->usedParameters().size() > 0; + myValue = anAttributeValue->text(); } - std::shared_ptr aCenter = myPlane->to3D(aCenterAttr->x(), aCenterAttr->y()); - std::shared_ptr aNormal = myPlane->normal(); - - GeomAPI_Circ aCircle(aCenter, aNormal, aRadius); - - std::shared_ptr anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, myPlane); - gp_Circ aCirc = aCircle.impl(); - gp_Pnt anAncorPnt = anAnchor->impl(); - - 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, diff --git a/src/SketcherPrs/SketcherPrs_Radius.h b/src/SketcherPrs/SketcherPrs_Radius.h index 348eafdcf..2c940061b 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.h +++ b/src/SketcherPrs/SketcherPrs_Radius.h @@ -56,12 +56,18 @@ private: ModelAPI_Feature* myConstraint; /// Plane of the current sketcher - std::shared_ptr myPlane; - - Handle(Prs3d_DimensionAspect) myAspect; + std::shared_ptr 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 diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index ab4b33023..1bd65d407 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -15,6 +15,9 @@ #include #include #include +#include + +#include #include #include @@ -23,6 +26,8 @@ #include #include +#include + #include #include @@ -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 aConstraintPtr(theFeature); + ModelAPI_EventCreator::get()->sendUpdated(aConstraintPtr, anEvent); +} }; diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index b41d8b498..d2b22d386 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -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