Salome HOME
e43f341e5797432d8542ee3d4f7d9eb5eb7c478e
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetPoint2dDistance.cpp
1 // File:        ModuleBase_WidgetPoint2dDistance.h
2 // Created:     23 June 2014
3 // Author:      Vitaly Smetannikov
4
5 #include "ModuleBase_WidgetPoint2dDistance.h"
6 #include "ModuleBase_WidgetValueFeature.h"
7
8 #include <GeomAPI_Pnt2d.h>
9 #include <Config_WidgetAPI.h>
10 #include <GeomDataAPI_Point2D.h>
11
12 #include <ModelAPI_Data.h>
13 #include <ModelAPI_AttributeDouble.h>
14
15 #include <QDoubleSpinBox>
16
17 ModuleBase_WidgetPoint2dDistance::ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData)
18   : ModuleBase_WidgetDoubleValue(theParent, theData)
19 {
20   myFirstPntName = theData->getProperty("first_point");
21 }
22
23 ModuleBase_WidgetPoint2dDistance::~ModuleBase_WidgetPoint2dDistance()
24 {
25 }
26
27 bool ModuleBase_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue)
28 {
29   bool isDone = false;
30
31   if (theValue) {
32     ModuleBase_WidgetValueFeature* aFeatureValue = 
33                          dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
34     if (aFeatureValue) {
35       boost::shared_ptr<GeomAPI_Pnt2d> aPnt = aFeatureValue->point();
36       // TODO
37       /*FeaturePtr aFeature = aFeatureValue->feature();
38       if (aFeature && aPnt) {
39         setPoint(aFeature, aPnt);
40         isDone = true;
41       }*/
42     }
43   }
44   return isDone;
45 }
46
47 void ModuleBase_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const boost::shared_ptr<GeomAPI_Pnt2d>& thePnt)
48 {
49   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
50   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
51                                                               (aData->attribute(myFirstPntName));
52   if (!aPoint) return;
53
54   double aRadius = thePnt->distance(aPoint->pnt());
55   AttributeDoublePtr aReal = aData->real(attributeID());
56   if (aReal && (aReal->value() != aRadius)) {
57     aReal->setValue(aRadius);
58     mySpinBox->setValue(aRadius);
59   }
60 }