1 // File: ModuleBase_WidgetPoint2dDistance.h
2 // Created: 23 June 2014
3 // Author: Vitaly Smetannikov
5 #include <ModuleBase_WidgetPoint2dDistance.h>
6 #include <ModuleBase_WidgetValueFeature.h>
7 #include <ModuleBase_DoubleSpinBox.h>
9 #include <GeomAPI_Pnt2d.h>
10 #include <Config_WidgetAPI.h>
11 #include <GeomDataAPI_Point2D.h>
13 #include <ModelAPI_Data.h>
14 #include <ModelAPI_AttributeDouble.h>
16 ModuleBase_WidgetPoint2dDistance::ModuleBase_WidgetPoint2dDistance(QWidget* theParent,
17 const Config_WidgetAPI* theData,
18 const std::string& theParentId)
19 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
21 myFirstPntName = theData->getProperty("first_point");
24 ModuleBase_WidgetPoint2dDistance::~ModuleBase_WidgetPoint2dDistance()
28 bool ModuleBase_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue)
33 ModuleBase_WidgetValueFeature* aFeatureValue =
34 dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
36 boost::shared_ptr<GeomAPI_Pnt2d> aPnt = aFeatureValue->point();
37 ObjectPtr aObject = aFeatureValue->object();
38 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
39 if (aFeature && aPnt) {
40 setPoint(aFeature, aPnt);
48 void ModuleBase_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
49 const boost::shared_ptr<GeomAPI_Pnt2d>& thePnt)
51 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
52 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
53 aData->attribute(myFirstPntName));
57 double aRadius = thePnt->distance(aPoint->pnt());
58 AttributeDoublePtr aReal = aData->real(attributeID());
59 if (aReal && (aReal->value() != aRadius)) {
60 aReal->setValue(aRadius);
61 mySpinBox->setValue(aRadius);