1 // File: PartSet_WidgetPoint2dDistance.h
2 // Created: 23 June 2014
3 // Author: Vitaly Smetannikov
5 #include "PartSet_WidgetPoint2dDistance.h"
6 #include "PartSet_Tools.h"
8 #include <ModuleBase_DoubleSpinBox.h>
9 #include <ModuleBase_IViewWindow.h>
11 #include <XGUI_ViewerProxy.h>
12 #include <XGUI_Workshop.h>
14 #include <GeomAPI_Pnt2d.h>
15 #include <Config_WidgetAPI.h>
16 #include <GeomDataAPI_Point2D.h>
18 #include <ModelAPI_Data.h>
19 #include <ModelAPI_AttributeDouble.h>
21 #include <QMouseEvent>
23 PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
24 const Config_WidgetAPI* theData,
25 const std::string& theParentId)
26 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
28 myFirstPntName = theData->getProperty("first_point");
31 PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
35 //bool PartSet_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue)
37 // bool isDone = false;
40 // ModuleBase_WidgetValueFeature* aFeatureValue =
41 // dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
42 // if (aFeatureValue) {
43 // std::shared_ptr<GeomAPI_Pnt2d> aPnt = aFeatureValue->point();
44 // ObjectPtr aObject = aFeatureValue->object();
45 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
46 // if (aFeature && aPnt) {
47 // setPoint(aFeature, aPnt);
55 void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
56 const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
58 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
59 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
60 aData->attribute(myFirstPntName));
64 double aRadius = thePnt->distance(aPoint->pnt());
65 AttributeDoublePtr aReal = aData->real(attributeID());
66 if (aReal && (aReal->value() != aRadius)) {
67 aReal->setValue(aRadius);
68 mySpinBox->setValue(aRadius);
72 void PartSet_WidgetPoint2dDistance::activate()
74 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
75 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
76 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
77 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
78 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
81 void PartSet_WidgetPoint2dDistance::deactivate()
83 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
84 disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
85 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
86 disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
87 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
90 void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
92 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
95 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
97 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
98 setPoint(feature(), aPnt);
99 emit focusOutWidget(this);
102 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
104 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
107 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
109 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
110 setPoint(feature(), aPnt);