From: nds Date: Thu, 30 Apr 2015 14:19:02 +0000 (+0300) Subject: An angle widget for the rotation operation. X-Git-Tag: V_1.2.0~177^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3b25b196c3d1fdd9bd14cfdc2dd06d3db2055c48;p=modules%2Fshaper.git An angle widget for the rotation operation. --- diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index d25419296..0f15c076d 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -13,6 +13,7 @@ SET(PROJECT_HEADERS PartSet_WidgetSketchLabel.h PartSet_Validators.h PartSet_WidgetPoint2d.h + PartSet_WidgetPoint2dAngle.h PartSet_WidgetEditor.h PartSet_WidgetMultiSelector.h PartSet_WidgetPoint2dDistance.h @@ -31,6 +32,7 @@ SET(PROJECT_SOURCES PartSet_WidgetEditor.cpp PartSet_WidgetMultiSelector.cpp PartSet_WidgetPoint2d.cpp + PartSet_WidgetPoint2dAngle.cpp PartSet_WidgetPoint2dDistance.cpp PartSet_WidgetShapeSelector.cpp PartSet_Filters.cpp diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 662e3d1bc..74ca6f834 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -462,7 +463,13 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th aDistanceWgt->setWorkshop(aWorkshop); aDistanceWgt->setSketch(mySketchMgr->activeSketch()); aWgt = aDistanceWgt; - } if (theType == "sketch_shape_selector") { + } if(theType == "point2dangle") { + PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent, theWidgetApi, theParentId); + anAngleWgt->setWorkshop(aWorkshop); + anAngleWgt->setSketch(mySketchMgr->activeSketch()); + aWgt = anAngleWgt; + } + if (theType == "sketch_shape_selector") { PartSet_WidgetShapeSelector* aShapeSelectorWgt = new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId); aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch()); diff --git a/src/PartSet/PartSet_WidgetPoint2dAngle.cpp b/src/PartSet/PartSet_WidgetPoint2dAngle.cpp new file mode 100644 index 000000000..b014d34b4 --- /dev/null +++ b/src/PartSet/PartSet_WidgetPoint2dAngle.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_WidgetPoint2dAngle.h +// Created: 23 June 2014 +// Author: Vitaly Smetannikov + +#include "PartSet_WidgetPoint2dAngle.h" + +#include + +#include + +#include +#include + +#include +#include + +#include + +#include +#include + +#define PI 3.1415926535897932 + +PartSet_WidgetPoint2dAngle::PartSet_WidgetPoint2dAngle(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) +: PartSet_WidgetPoint2dDistance(theParent, theData, theParentId) +{ +} + +PartSet_WidgetPoint2dAngle::~PartSet_WidgetPoint2dAngle() +{ +} + +double PartSet_WidgetPoint2dAngle::computeValue(const std::shared_ptr& theFirstPnt, + const std::shared_ptr& theCurrentPnt) +{ + std::shared_ptr aHorizontalDir(new GeomAPI_Dir2d(1, 0)); + std::shared_ptr aStartPnt = theFirstPnt->xy(); + std::shared_ptr aEndPnt = theCurrentPnt->xy(); + + std::shared_ptr aLineDir(new GeomAPI_Dir2d(aEndPnt->decreased(aStartPnt))); + + double aValue = aHorizontalDir->angle(aLineDir); + aValue *= 180.0 / PI; + + return aValue; +} diff --git a/src/PartSet/PartSet_WidgetPoint2dAngle.h b/src/PartSet/PartSet_WidgetPoint2dAngle.h new file mode 100644 index 000000000..6dac991b2 --- /dev/null +++ b/src/PartSet/PartSet_WidgetPoint2dAngle.h @@ -0,0 +1,44 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_WidgetPoint2dAngle.h +// Created: 30 Apr 2015 +// Author: Natalia Ermolaeva + +#ifndef PartSet_WidgetPoint2dAngle_H +#define PartSet_WidgetPoint2dAngle_H + +#include "PartSet.h" +#include "PartSet_WidgetPoint2dDistance.h" + +#include + +class GeomAPI_Pnt2d; + +/** +* \ingroup Modules +* Implementation of model widget for widget which provides input of an anble between two points +* The XML definion is the same as the parent one. +*/ +class PARTSET_EXPORT PartSet_WidgetPoint2dAngle : public PartSet_WidgetPoint2dDistance +{ +Q_OBJECT + public: + /// Constructor + /// \param theParent the parent object + /// \param theData the widget configuation. The attribute of the model widget is obtained from + /// \param theParentId is Id of a parent of the current attribute + PartSet_WidgetPoint2dAngle(QWidget* theParent, const Config_WidgetAPI* theData, + const std::string& theParentId); + + virtual ~PartSet_WidgetPoint2dAngle(); + +protected: + /// Compute an angle between points + /// \param theFirstPnt a point value of the out point attribute + /// \param theCurrentPnt a point of the current widget + /// \return a double value + virtual double computeValue(const std::shared_ptr& theFirstPnt, + const std::shared_ptr& theCurrentPnt); +}; + +#endif diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index e20186a26..07cf1877b 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -60,16 +60,22 @@ void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, if (!aPoint) return; - double aRadius = thePnt->distance(aPoint->pnt()); + double aValue = computeValue(aPoint->pnt(), thePnt); AttributeDoublePtr aReal = aData->real(attributeID()); - if (aReal && (aReal->value() != aRadius)) { - aReal->setValue(aRadius); + if (aReal && (aReal->value() != aValue)) { + aReal->setValue(aValue); - ModuleBase_Tools::setSpinValue(mySpinBox, aRadius); + ModuleBase_Tools::setSpinValue(mySpinBox, aValue); storeValue(); } } +double PartSet_WidgetPoint2dDistance::computeValue(const std::shared_ptr& theFirstPnt, + const std::shared_ptr& theCurrentPnt) +{ + return theCurrentPnt->distance(theFirstPnt); +} + void PartSet_WidgetPoint2dDistance::activateCustom() { XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index 95fc0ed19..c3020e3a9 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -85,11 +85,18 @@ protected: /// Set the second point which defines a value in the widget as a distance with a first point defined by feature void setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt); + /// Compute the distance between points + /// \param theFirstPnt a point value of the out point attribute + /// \param theCurrentPnt a point of the current widget + /// \return a double value + virtual double computeValue(const std::shared_ptr& theFirstPnt, + const std::shared_ptr& theCurrentPnt); + private slots: /// Process values changed event void onValuesChanged(); - private: +protected: XGUI_Workshop* myWorkshop; std::string myFirstPntName; diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index e42c826c8..82377a7f6 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -301,9 +301,11 @@ id="MultiRotationCenter" title="Center of rotation" tooltip="Center of rotation"/> - +