1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Radius.cpp
4 // Created: 26 March 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "SketcherPrs_Radius.h"
8 #include "SketcherPrs_Tools.h"
10 #include <SketchPlugin_ConstraintRadius.h>
11 #include <SketchPlugin_Constraint.h>
12 #include <SketchPlugin_Circle.h>
13 #include <SketchPlugin_Arc.h>
15 #include <GeomDataAPI_Point2D.h>
16 #include <GeomAPI_Pnt2d.h>
17 #include <GeomAPI_Circ.h>
18 #include <GeomAPI_XYZ.h>
19 #include <ModelAPI_AttributeDouble.h>
21 static const gp_Circ MyDefCirc(gp_Ax2(gp_Pnt(0,0,0), gp_Dir(0,0,1)), 1);
23 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Radius, AIS_RadiusDimension);
24 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Radius, AIS_RadiusDimension);
26 SketcherPrs_Radius::SketcherPrs_Radius(ModelAPI_Feature* theConstraint,
27 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
28 : AIS_RadiusDimension(MyDefCirc), myConstraint(theConstraint), myPlane(thePlane)
30 myAspect = new Prs3d_DimensionAspect();
31 myAspect->MakeArrows3d(false);
32 myAspect->MakeText3d(false);
33 myAspect->MakeTextShaded(false);
34 myAspect->MakeUnitsDisplayed(false);
35 myAspect->TextAspect()->SetHeight(MyTextHeight);
36 myAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
38 SetDimensionAspect(myAspect);
39 SetSelToleranceForText2d(MyTextHeight);
43 void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
44 const Handle(Prs3d_Presentation)& thePresentation,
45 const Standard_Integer theMode)
47 DataPtr aData = myConstraint->data();
50 std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
51 std::dynamic_pointer_cast<GeomDataAPI_Point2D>
52 (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
53 if (!aFlyoutAttr->isInitialized())
54 return; // can not create a good presentation
56 std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
59 std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
60 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
61 (aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
64 std::shared_ptr<ModelAPI_Feature> aCyrcFeature = ModelAPI_Feature::feature(anAttr->object());
66 std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
67 if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle
68 aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
69 aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
70 AttributeDoublePtr aCircRadius =
71 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
72 aCyrcFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()));
73 aRadius = aCircRadius->value();
75 aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
76 aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
77 std::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
78 std::dynamic_pointer_cast<GeomDataAPI_Point2D>
79 (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
80 aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
82 std::shared_ptr<GeomAPI_Pnt> aCenter = myPlane->to3D(aCenterAttr->x(), aCenterAttr->y());
83 std::shared_ptr<GeomAPI_Dir> aNormal = myPlane->norm();
85 GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);
87 std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, myPlane);
88 //std::shared_ptr<GeomAPI_Pnt> anAnchor = aCircle.project(aFlyoutPnt);
89 //std::shared_ptr<GeomAPI_XYZ> anAnchorXYZ = anAnchor->xyz();
90 //anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz());
91 //std::shared_ptr<GeomAPI_Dir> aDeltaDir(new GeomAPI_Dir(anAnchorXYZ));
92 //const double aDelta = 1e-3;
93 //anAnchor->setX(anAnchor->x() + aDelta * aDeltaDir->x());
94 //anAnchor->setY(anAnchor->y() + aDelta * aDeltaDir->y());
95 //anAnchor->setZ(anAnchor->z() + aDelta * aDeltaDir->z());
97 SetMeasuredGeometry(aCircle.impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
98 SetCustomValue(aRadius);
100 AIS_RadiusDimension::Compute(thePresentationManager, thePresentation, theMode);
103 void SketcherPrs_Radius::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
104 const Standard_Integer theMode)
106 Standard_Integer aMode;
108 case 0: // we should use selection of all objects
111 case SketcherPrs_Tools::Sel_Dimension_All:
114 case SketcherPrs_Tools::Sel_Dimension_Line:
117 case SketcherPrs_Tools::Sel_Dimension_Text:
121 // there are own selection modes, so the others should be ignored
122 // otherwise, the text selection appears in the viewer
126 AIS_RadiusDimension::ComputeSelection(aSelection, aMode);