1 // File: SketchPlugin_ConstraintLength.cpp
2 // Created: 30 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_ConstraintLength.h"
6 #include <SketchPlugin_Line.h>
8 #include <ModelAPI_AttributeDouble.h>
9 #include <ModelAPI_Data.h>
11 #include <GeomDataAPI_Point2D.h>
13 #include <AIS_LengthDimension.hxx>
17 SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength()
21 void SketchPlugin_ConstraintLength::initAttributes()
23 data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type());
24 data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
25 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
28 void SketchPlugin_ConstraintLength::execute()
32 Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape(
33 Handle_AIS_InteractiveObject thePrevious)
38 boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
40 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
41 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
44 FeaturePtr aFeature = anAttr->feature();
45 if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
48 boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr =
49 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
50 double aFlyout = aFlyoutAttr->value();
52 boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
53 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
54 double aValue = aValueAttr->value();
56 boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
57 if (!aData->isValid())
60 boost::shared_ptr<GeomDataAPI_Point2D> aPointStart =
61 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
62 boost::shared_ptr<GeomDataAPI_Point2D> aPointEnd =
63 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
65 //Build dimension here
66 boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPointStart->x(), aPointStart->y());
67 boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPointEnd->x(), aPointEnd->y());
69 aPoint1.swap(aPoint2);
71 Handle(AIS_InteractiveObject) anAIS = thePrevious;
74 Handle(AIS_LengthDimension) aDimAIS =
75 new AIS_LengthDimension(aPoint1->impl<gp_Pnt>(), aPoint2->impl<gp_Pnt>(), aPlane->impl<gp_Pln>());
76 aDimAIS->SetCustomValue(aValue);
78 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
79 anAspect->MakeArrows3d (Standard_False);
80 anAspect->MakeText3d(false/*is text 3d*/);
81 anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
82 anAspect->MakeTextShaded(false/*is test shaded*/);
83 aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/);
84 /*if (isUnitsDisplayed)
86 aDimAIS->SetDisplayUnits (aDimDlg->GetUnits ());
88 aDimAIS->SetDimensionAspect (anAspect);
89 aDimAIS->SetFlyout(aFlyout);
90 aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
96 // update presentation
97 Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
98 if (!aDimAIS.IsNull())
100 aDimAIS->SetMeasuredGeometry(aPoint1->impl<gp_Pnt>(), aPoint2->impl<gp_Pnt>(), aPlane->impl<gp_Pln>());
101 aDimAIS->SetCustomValue(aValue);
102 aDimAIS->SetFlyout(aFlyout);
104 aDimAIS->Redisplay(Standard_True);