1 // File: SketchPlugin_ConstraintRadius.cpp
2 // Created: 26 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_ConstraintRadius.h"
7 #include <SketchPlugin_Arc.h>
8 #include <SketchPlugin_Circle.h>
9 #include <SketchPlugin_Point.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_Data.h>
14 #include <GeomAPI_Pnt2d.h>
15 #include <GeomAPI_Circ.h>
16 #include <GeomDataAPI_Point2D.h>
17 #include <GeomDataAPI_Dir.h>
19 #include <AIS_InteractiveObject.hxx>
20 #include <AIS_RadiusDimension.hxx>
22 SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius()
26 void SketchPlugin_ConstraintRadius::initAttributes()
28 data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type());
29 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
30 data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
33 void SketchPlugin_ConstraintRadius::execute()
38 Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
39 Handle_AIS_InteractiveObject thePrevious)
41 Handle(AIS_InteractiveObject) anAIS = thePrevious;
45 boost::shared_ptr<ModelAPI_Data> aData = data();
46 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
47 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
50 FeaturePtr aFeature = anAttr->feature();
51 std::string aKind = aFeature ? aFeature->getKind() : "";
52 if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND)
55 boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
56 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
57 double aValue = aValueAttr->value();
60 boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr =
61 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
62 boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
63 boost::shared_ptr<GeomAPI_Pnt> anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y());
65 aData = aFeature->data();
66 boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
68 if (aKind == SKETCH_CIRCLE_KIND) {
69 aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
70 AttributeDoublePtr aCircRadius =
71 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CIRCLE_ATTR_RADIUS));
72 aRadius = aCircRadius->value();
74 else if (aKind == SKETCH_ARC_KIND) {
75 aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
76 boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
77 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
78 aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
82 boost::shared_ptr<GeomAPI_Pnt> aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y());
84 boost::shared_ptr<GeomDataAPI_Dir> aNDir =
85 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(sketch()->data()->attribute(SKETCH_ATTR_NORM));
86 boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
88 boost::shared_ptr<GeomAPI_Circ> aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius));
92 Handle(AIS_RadiusDimension) aDimAIS =
93 new AIS_RadiusDimension(aCircle->impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
94 aDimAIS->SetCustomValue(aValue);
96 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
97 anAspect->MakeArrows3d (Standard_False);
98 anAspect->MakeText3d(false);
99 anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
100 anAspect->MakeTextShaded(false);
101 aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
102 aDimAIS->SetDimensionAspect (anAspect);
103 aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
109 // update presentation
110 Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS);
111 if (!aDimAIS.IsNull())
113 aDimAIS->SetMeasuredGeometry(aCircle->impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
114 aDimAIS->SetCustomValue(aValue);
115 aDimAIS->Redisplay(Standard_True);