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());
31 data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
32 data()->addAttribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT, GeomDataAPI_Point2D::type());
35 void SketchPlugin_ConstraintRadius::execute()
39 Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
40 Handle_AIS_InteractiveObject thePrevious)
42 Handle(AIS_InteractiveObject) anAIS = thePrevious;
46 boost::shared_ptr<ModelAPI_Data> aData = data();
47 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
48 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
51 FeaturePtr aFeature = anAttr->feature();
52 std::string aKind = aFeature ? aFeature->getKind() : "";
53 if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND)
56 boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
57 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
58 double aValue = aValueAttr->value();
61 boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr =
62 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT));
63 boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
64 boost::shared_ptr<GeomAPI_Pnt> anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y());
66 aData = aFeature->data();
67 boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
69 if (aKind == SKETCH_CIRCLE_KIND) {
70 aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
71 AttributeDoublePtr aCircRadius =
72 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CIRCLE_ATTR_RADIUS));
73 aRadius = aCircRadius->value();
75 else if (aKind == SKETCH_ARC_KIND) {
76 aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
77 boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
78 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
79 aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
83 boost::shared_ptr<GeomAPI_Pnt> aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y());
85 boost::shared_ptr<GeomDataAPI_Dir> aNDir =
86 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(sketch()->data()->attribute(SKETCH_ATTR_NORM));
87 boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
89 boost::shared_ptr<GeomAPI_Circ> aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius));
93 Handle(AIS_RadiusDimension) aDimAIS =
94 new AIS_RadiusDimension(aCircle->impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
95 aDimAIS->SetCustomValue(aValue);
97 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
98 anAspect->MakeArrows3d (Standard_False);
99 anAspect->MakeText3d(false);
100 anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
101 anAspect->MakeTextShaded(false);
102 aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
103 aDimAIS->SetDimensionAspect (anAspect);
104 aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
110 // update presentation
111 Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS);
112 if (!aDimAIS.IsNull())
114 aDimAIS->SetMeasuredGeometry(aCircle->impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
115 aDimAIS->SetCustomValue(aValue);
116 aDimAIS->Redisplay(Standard_True);