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>
15 #include <XGUI_PropertyPanel.h>
16 #include <XGUI_OperationMgr.h>
18 #include <GeomAPI_Pnt2d.h>
19 #include <Config_WidgetAPI.h>
20 #include <GeomDataAPI_Point2D.h>
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_AttributeDouble.h>
25 #include <QMouseEvent>
27 PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
28 const Config_WidgetAPI* theData,
29 const std::string& theParentId)
30 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
32 myFirstPntName = theData->getProperty("first_point");
34 // Reconnect to local slot
35 disconnect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
36 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged()));
39 PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
43 void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
44 const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
46 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
47 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
48 aData->attribute(myFirstPntName));
52 double aRadius = thePnt->distance(aPoint->pnt());
53 AttributeDoublePtr aReal = aData->real(attributeID());
54 if (aReal && (aReal->value() != aRadius)) {
55 aReal->setValue(aRadius);
56 mySpinBox->blockSignals(true);
57 mySpinBox->setValue(aRadius);
58 mySpinBox->blockSignals(false);
63 void PartSet_WidgetPoint2dDistance::activateCustom()
65 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
66 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
67 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
68 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
69 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
72 void PartSet_WidgetPoint2dDistance::deactivate()
74 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
75 disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
76 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
77 disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
78 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
79 myWorkshop->operationMgr()->setLockValidating(false);
82 void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
84 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
87 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
89 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
90 setPoint(feature(), aPnt);
91 emit focusOutWidget(this);
94 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
96 myWorkshop->operationMgr()->setLockValidating(true);
97 myWorkshop->operationMgr()->setApplyEnabled(false);
99 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
102 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
104 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
105 setPoint(feature(), aPnt);
108 void PartSet_WidgetPoint2dDistance::onValuesChanged()
110 myWorkshop->operationMgr()->setLockValidating(false);
111 emit valuesChanged();