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_WidgetValueFeature.h>
9 #include <ModuleBase_DoubleSpinBox.h>
10 #include <ModuleBase_IViewWindow.h>
12 #include <XGUI_ViewerProxy.h>
13 #include <XGUI_Workshop.h>
15 #include <GeomAPI_Pnt2d.h>
16 #include <Config_WidgetAPI.h>
17 #include <GeomDataAPI_Point2D.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_AttributeDouble.h>
22 #include <QMouseEvent>
24 PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
25 const Config_WidgetAPI* theData,
26 const std::string& theParentId)
27 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
29 myFirstPntName = theData->getProperty("first_point");
32 PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
36 //bool PartSet_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue)
38 // bool isDone = false;
41 // ModuleBase_WidgetValueFeature* aFeatureValue =
42 // dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
43 // if (aFeatureValue) {
44 // std::shared_ptr<GeomAPI_Pnt2d> aPnt = aFeatureValue->point();
45 // ObjectPtr aObject = aFeatureValue->object();
46 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
47 // if (aFeature && aPnt) {
48 // setPoint(aFeature, aPnt);
56 void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
57 const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
59 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
60 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
61 aData->attribute(myFirstPntName));
65 double aRadius = thePnt->distance(aPoint->pnt());
66 AttributeDoublePtr aReal = aData->real(attributeID());
67 if (aReal && (aReal->value() != aRadius)) {
68 aReal->setValue(aRadius);
69 mySpinBox->setValue(aRadius);
73 void PartSet_WidgetPoint2dDistance::activate()
75 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
76 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
77 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
78 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
79 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
82 void PartSet_WidgetPoint2dDistance::deactivate()
84 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
85 disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
86 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
87 disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
88 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
91 void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
93 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
96 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
98 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
99 setPoint(feature(), aPnt);
100 emit focusOutWidget(this);
103 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
105 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
108 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
110 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
111 setPoint(feature(), aPnt);