X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_Radius.cpp;h=579b36f610f88defdcf253c58241d2ca3fe8ec85;hb=4a230167f3242b22231d699f5c5a2a1787a51e71;hp=d26d3e539463d0e0992e7b96c9291b7674961b42;hpb=5cd5c63e95c048ef98621e15929c1e95ad580b24;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index d26d3e539..579b36f61 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -6,6 +6,7 @@ #include "SketcherPrs_Radius.h" #include "SketcherPrs_Tools.h" +#include "SketcherPrs_DimensionStyleListener.h" #include #include @@ -29,41 +30,40 @@ 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(); } -void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode) +SketcherPrs_Radius::~SketcherPrs_Radius() { - DataPtr aData = myConstraint->data(); + delete myStyleListener; +} + +bool SketcherPrs_Radius::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane) +{ + bool aReadyToDisplay = false; + + DataPtr aData = theConstraint->data(); // Flyout point std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); if (!aFlyoutAttr->isInitialized()) { - Events_Error::throwException("An empty AIS presentation: SketcherPrs_Radius"); - return; // can not create a good presentation + return aReadyToDisplay; // can not create a good presentation } // Get circle std::shared_ptr anAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - if (!anAttr) return; + if (!anAttr) + return aReadyToDisplay; std::shared_ptr aCyrcFeature = ModelAPI_Feature::feature(anAttr->object()); double aRadius = 1; @@ -71,7 +71,7 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the // it is possible that circle result becomes zero, in this case the presentation should disappear // for example, it happens when circle radius is set to zero if (!aCyrcFeature) - return; + return aReadyToDisplay; if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle aCenterAttr = std::dynamic_pointer_cast( aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); @@ -87,47 +87,89 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID())); aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); } - std::shared_ptr aCenter = myPlane->to3D(aCenterAttr->x(), aCenterAttr->y()); - std::shared_ptr aNormal = myPlane->normal(); + std::shared_ptr aCenter = thePlane->to3D(aCenterAttr->x(), aCenterAttr->y()); + std::shared_ptr aNormal = thePlane->normal(); GeomAPI_Circ aCircle(aCenter, aNormal, aRadius); - std::shared_ptr anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, myPlane); + std::shared_ptr anAnchor = SketcherPrs_Tools::getAnchorPoint(theConstraint, thePlane); gp_Circ aCirc = aCircle.impl(); gp_Pnt anAncorPnt = anAnchor->impl(); // anchor point should not coincide to the location point of the circle // OCCT does not process this case. - if (anAncorPnt.Distance(aCirc.Location()) < 1e-7) - return; - SetMeasuredGeometry(aCirc, anAncorPnt); - SetCustomValue(aRadius); - // 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); + aReadyToDisplay = anAncorPnt.Distance(aCirc.Location()) > 1e-7; + return aReadyToDisplay; +} - 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); +void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane); + if (aReadyToDisplay) { + //myDistance = SketcherPrs_Tools::getFlyoutDistance(myConstraint); + + 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()); + 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(); } - myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length()); - // The value of vertical aligment is sometimes changed - myAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER); + SetMeasuredGeometry(myCircle, myAncorPnt); + SetCustomValue(myRadius); - AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE()); - SketcherPrs_Tools::setDisplaySpecialSymbol(this, aValue->usedParameters().size() > 0); + // Update variable aspect parameters (depending on viewer scale) + double aTextSize = 0.0; + GetValueString(aTextSize); + SketcherPrs_Tools::updateArrows(DimensionAspect(), GetValue(), aTextSize); + 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,