1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetPoint2dDistance.h
4 // Created: 23 June 2014
5 // Author: Vitaly Smetannikov
7 #include "PartSet_WidgetPoint2dDistance.h"
8 #include "PartSet_Tools.h"
10 #include <ModuleBase_DoubleSpinBox.h>
11 #include <ModuleBase_IViewWindow.h>
13 #include <XGUI_ViewerProxy.h>
14 #include <XGUI_Workshop.h>
16 #include <GeomAPI_Pnt2d.h>
17 #include <Config_WidgetAPI.h>
18 #include <GeomDataAPI_Point2D.h>
20 #include <ModelAPI_Data.h>
21 #include <ModelAPI_AttributeDouble.h>
23 #include <QMouseEvent>
25 PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
26 const Config_WidgetAPI* theData,
27 const std::string& theParentId)
28 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
30 myFirstPntName = theData->getProperty("first_point");
33 PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
37 //bool PartSet_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue)
39 // bool isDone = false;
42 // ModuleBase_WidgetValueFeature* aFeatureValue =
43 // dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
44 // if (aFeatureValue) {
45 // std::shared_ptr<GeomAPI_Pnt2d> aPnt = aFeatureValue->point();
46 // ObjectPtr aObject = aFeatureValue->object();
47 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
48 // if (aFeature && aPnt) {
49 // setPoint(aFeature, aPnt);
57 void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
58 const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
60 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
61 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
62 aData->attribute(myFirstPntName));
66 double aRadius = thePnt->distance(aPoint->pnt());
67 AttributeDoublePtr aReal = aData->real(attributeID());
68 if (aReal && (aReal->value() != aRadius)) {
69 aReal->setValue(aRadius);
70 mySpinBox->setValue(aRadius);
74 void PartSet_WidgetPoint2dDistance::activate()
76 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
77 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
78 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
79 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
80 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
83 void PartSet_WidgetPoint2dDistance::deactivate()
85 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
86 disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
87 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
88 disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
89 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
92 void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
94 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
97 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
99 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
100 setPoint(feature(), aPnt);
101 emit focusOutWidget(this);
104 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
106 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
109 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
111 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
112 setPoint(feature(), aPnt);