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>
12 #include <ModuleBase_Tools.h>
14 #include <XGUI_ViewerProxy.h>
15 #include <XGUI_Workshop.h>
16 #include <XGUI_PropertyPanel.h>
17 #include <XGUI_OperationMgr.h>
19 #include <GeomAPI_Pnt2d.h>
20 #include <Config_WidgetAPI.h>
21 #include <GeomDataAPI_Point2D.h>
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_AttributeDouble.h>
26 #include <QMouseEvent>
28 PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
29 const Config_WidgetAPI* theData,
30 const std::string& theParentId)
31 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
33 myFirstPntName = theData->getProperty("first_point");
35 // Reconnect to local slot
36 disconnect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
37 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged()));
40 PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
44 void PartSet_WidgetPoint2dDistance::reset()
47 double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
49 ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
53 void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
54 const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
56 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
57 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
58 aData->attribute(myFirstPntName));
62 double aRadius = thePnt->distance(aPoint->pnt());
63 AttributeDoublePtr aReal = aData->real(attributeID());
64 if (aReal && (aReal->value() != aRadius)) {
65 aReal->setValue(aRadius);
67 ModuleBase_Tools::setSpinValue(mySpinBox, aRadius);
72 void PartSet_WidgetPoint2dDistance::activateCustom()
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*)));
88 myWorkshop->operationMgr()->setLockValidating(false);
91 void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
93 // the contex menu release by the right button should not be processed by this widget
94 if (theEvent->button() != Qt::LeftButton)
97 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
100 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
102 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
103 setPoint(feature(), aPnt);
104 emit focusOutWidget(this);
107 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
109 myWorkshop->operationMgr()->setLockValidating(true);
110 myWorkshop->operationMgr()->setApplyEnabled(false);
112 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
115 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
117 std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
118 setPoint(feature(), aPnt);
121 void PartSet_WidgetPoint2dDistance::onValuesChanged()
123 myWorkshop->operationMgr()->setLockValidating(false);
124 emit valuesChanged();