- //gp_Circ aCircle(gp_Ax2(aCenter->impl<gp_Pnt>(), aNormal->impl<gp_Dir>()), aRadius);
-
- std::shared_ptr<GeomAPI_Pnt> anAnchor = aCircle.project(aFlyoutPnt);
- std::shared_ptr<GeomAPI_XYZ> anAnchorXYZ = anAnchor->xyz();
- anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz());
- std::shared_ptr<GeomAPI_Dir> aDeltaDir(new GeomAPI_Dir(anAnchorXYZ));
- const double aDelta = 1e-3;
- anAnchor->setX(anAnchor->x() + aDelta * aDeltaDir->x());
- anAnchor->setY(anAnchor->y() + aDelta * aDeltaDir->y());
- anAnchor->setZ(anAnchor->z() + aDelta * aDeltaDir->z());
-
- SetMeasuredGeometry(aCircle.impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
- SetCustomValue(aRadius);
-
- myAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
- myAspect->ArrowAspect()->SetLength(CONSTRAINT_TEXT_HEIGHT * 2.);
- AIS_RadiusDimension::Compute(thePresentationManager, thePresentation, theMode);
+ std::shared_ptr<GeomAPI_Pnt> anAnchor =
+ SketcherPrs_Tools::getAnchorPoint(theConstraint, thePlane);
+
+ theCircle = aCircle.impl<gp_Circ>();
+ theAnchorPoint = anAnchor->impl<gp_Pnt>();
+
+ aReadyToDisplay = theAnchorPoint.Distance(theCircle.Location()) > 1e-7;
+
+ return aReadyToDisplay;
+}
+
+void SketcherPrs_Radius::Compute(
+ const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ if (!plane().get())
+ return;
+ gp_Circ aCircle;
+ gp_Pnt anAnchorPoint;
+ bool aReadyToDisplay = readyToDisplay(myConstraint, plane(), aCircle, anAnchorPoint);
+ if (aReadyToDisplay) {
+ myCircle = aCircle;
+ myAnchorPoint = anAnchorPoint;
+
+ DataPtr aData = myConstraint->data();
+ AttributeDoublePtr anAttributeValue = aData->real(SketchPlugin_Constraint::VALUE());
+ myValue.init(anAttributeValue);
+ }
+
+ SetMeasuredGeometry(myCircle, myAnchorPoint);
+ myStyleListener->updateDimensions(this, myValue);
+
+ // Update variable aspect parameters (depending on viewer scale)
+ double aTextSize = 0.0;
+ GetValueString(aTextSize);
+
+ AttributeIntegerPtr aLocAttr = std::dynamic_pointer_cast<ModelAPI_AttributeInteger>
+ (myConstraint->data()->attribute(SketchPlugin_ConstraintRadius::LOCATION_TYPE_ID()));
+ SketcherPrs_Tools::LocationType aLocationType = aLocAttr->isInitialized() ?
+ (SketcherPrs_Tools::LocationType)(aLocAttr->value()) : SketcherPrs_Tools::LOCATION_AUTOMATIC;
+ updateArrows(DimensionAspect(), GetValue(), aTextSize, aLocationType);
+
+ PrsDim_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,
+ const Standard_Integer theMode)
+{
+ // Map the application selection modes to standard ones
+ Standard_Integer aMode;
+ switch (theMode) {
+ case 0: // we should use selection of all objects
+ aMode = 0;
+ break;
+ case SketcherPrs_Tools::Sel_Dimension_All:
+ aMode = 0;
+ break;
+ case SketcherPrs_Tools::Sel_Dimension_Line:
+ aMode = 1;
+ break;
+ case SketcherPrs_Tools::Sel_Dimension_Text:
+ aMode = 2;
+ break;
+ default: {
+ // there are own selection modes, so the others should be ignored
+ // otherwise, the text selection appears in the viewer
+ return;
+ }
+ }
+ SetSelToleranceForText2d(SketcherPrs_Tools::getArrowSize()/5.);
+ PrsDim_RadiusDimension::ComputeSelection(aSelection, aMode);